/Framework/src/Ncqrs.Tests/NcqrsEnvironmentConfigurationExceptionSpecs.cs

http://github.com/ncqrs/ncqrs · C# · 52 lines · 41 code · 11 blank · 0 comment · 0 complexity · 562b88080db18b51063a7759bc6c26e4 MD5 · raw file

  1. using System;
  2. using System.Runtime.Serialization.Formatters.Binary;
  3. using FluentAssertions;
  4. using Xunit;
  5. using System.IO;
  6. namespace Ncqrs.Tests
  7. {
  8. public class NcqrsEnvironmentConfigurationExceptionSpecs
  9. {
  10. [Fact]
  11. public void Constructing_an_instance_should_initialize_the_message()
  12. {
  13. String message = "Hello world";
  14. var target = new NcqrsEnvironmentException(message);
  15. target.Message.Should().Be(message);
  16. }
  17. [Fact]
  18. public void Constructing_an_instance_should_initialize_the_inner_exception()
  19. {
  20. String aMessage = "Hello world";
  21. var theInnerException = new Exception();
  22. var target = new NcqrsEnvironmentException(aMessage, theInnerException);
  23. target.InnerException.Should().Be(theInnerException);
  24. }
  25. [Fact]
  26. public void It_should_be_serializable()
  27. {
  28. var aMessage = "Hello world";
  29. var theException = new NcqrsEnvironmentException(aMessage);
  30. NcqrsEnvironmentException deserializedException = null;
  31. using (var buffer = new MemoryStream())
  32. {
  33. var formatter = new BinaryFormatter();
  34. formatter.Serialize(buffer, theException);
  35. buffer.Seek(0, SeekOrigin.Begin);
  36. deserializedException = (NcqrsEnvironmentException)formatter.Deserialize(buffer);
  37. }
  38. deserializedException.Should().NotBeNull();
  39. }
  40. }
  41. }