PageRenderTime 23ms CodeModel.GetById 4ms RepoModel.GetById 0ms app.codeStats 0ms

/Framework/src/Ncqrs.Tests/InternalExtensionsTests.cs

http://github.com/ncqrs/ncqrs
C# | 175 lines | 141 code | 34 blank | 0 comment | 0 complexity | 7d2349858a4c598d8aa9607553d94360 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, Apache-2.0
  1. using System;
  2. using System.Collections.Generic;
  3. using FluentAssertions;
  4. using Xunit;
  5. using System.IO;
  6. namespace Ncqrs.Tests
  7. {
  8. public class InternalExtensionsTests
  9. {
  10. [Fact]
  11. public void IsEmpty_should_return_true_on_empty_array()
  12. {
  13. var target = new object[0];
  14. var isEmpty = InternalExtensions.IsEmpty(target);
  15. Assert.True(isEmpty);
  16. }
  17. [Fact]
  18. public void IsEmpty_should_return_true_on_empty_list()
  19. {
  20. var target = new List<object>(0);
  21. var isEmpty = InternalExtensions.IsEmpty(target);
  22. Assert.True(isEmpty);
  23. }
  24. [Fact]
  25. public void IsEmpty_should_return_false_on_non_empty_array()
  26. {
  27. var target = new object[1];
  28. var isEmpty = InternalExtensions.IsEmpty(target);
  29. Assert.False(isEmpty);
  30. }
  31. [Fact]
  32. public void IsEmpty_should_return_false_on_non_empty_list()
  33. {
  34. var target = new List<object>();
  35. target.Add(new object());
  36. var isEmpty = InternalExtensions.IsEmpty(target);
  37. Assert.False(isEmpty);
  38. }
  39. [Fact]
  40. public void IsEmpty_should_throw_ArgumentNullException_on_null_reference()
  41. {
  42. List<object> target = null;
  43. Action act = ()=>InternalExtensions.IsEmpty(target);
  44. act.ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("source");
  45. }
  46. [Fact]
  47. public void IsNullOrEmpty_should_return_true_on_null()
  48. {
  49. var result = InternalExtensions.IsNullOrEmpty(null);
  50. result.Should().BeTrue();
  51. }
  52. [Fact]
  53. public void IsNullOrEmpty_should_return_true_on_empty()
  54. {
  55. var result = InternalExtensions.IsNullOrEmpty(string.Empty);
  56. result.Should().BeTrue();
  57. }
  58. [Fact]
  59. public void IsNullOrEmpty_should_return_false_on_string_with_text()
  60. {
  61. var result = InternalExtensions.IsNullOrEmpty("Hello world");
  62. result.Should().BeFalse();
  63. }
  64. [Fact]
  65. public void Clone_should_return_other_instance()
  66. {
  67. var source = new List<object>();
  68. var clone = InternalExtensions.Clone(source);
  69. Assert.NotSame(source, clone);
  70. }
  71. [Fact]
  72. public void Clone_should_return_list_with_same_values()
  73. {
  74. var source = new List<int>{1,2,3,4,5};
  75. var clone = InternalExtensions.Clone(source);
  76. clone.Should().ContainInOrder(source);
  77. }
  78. [Fact]
  79. public void Clone_should_throw_ArgumentNullException_when_source_is_null()
  80. {
  81. List<string> nullTarget = null;
  82. Action act = ()=> InternalExtensions.Clone(nullTarget);
  83. act.ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("source");
  84. }
  85. [Fact]
  86. public void Implements_should_throw_when_source_is_null()
  87. {
  88. var interfaceType = typeof (IDisposable);
  89. Action act = () => InternalExtensions.Implements(null, interfaceType);
  90. act.ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("source");
  91. }
  92. [Fact]
  93. public void Implements_should_throw_when_interfaceType_is_null()
  94. {
  95. var source = typeof(Stream);
  96. Action act = () => InternalExtensions.Implements(source, null);
  97. act.ShouldThrow<ArgumentNullException>().And.ParamName.Should().Be("interfaceType");
  98. }
  99. [Fact]
  100. public void Implements_should_throw_when_interfaceType_is_not_an_interface_type()
  101. {
  102. var source = typeof(Stream);
  103. var wrongInterfaceType = typeof (String);
  104. Action act = () => InternalExtensions.Implements(source, wrongInterfaceType);
  105. act.ShouldThrow<ArgumentException>().And.ParamName.Should().Be("interfaceType");
  106. }
  107. [Fact]
  108. public void Implements_should_return_false_when_source_does_not_implement_the_interface()
  109. {
  110. var source = typeof (Stream);
  111. var interfaceType = typeof (IDisposable);
  112. InternalExtensions.Implements(source, interfaceType).Should().BeTrue();
  113. }
  114. [Fact]
  115. public void Implements_should_return_true_when_source_does_implement_the_interface()
  116. {
  117. var source = typeof(String);
  118. var interfaceType = typeof(IDisposable);
  119. InternalExtensions.Implements(source, interfaceType).Should().BeFalse();
  120. }
  121. [Fact]
  122. public void Implements_generic_should_throw_when_interfaceType_is_not_an_interface_type()
  123. {
  124. var source = typeof(Stream);
  125. Action act = () => InternalExtensions.Implements<String>(source);
  126. act.ShouldThrow<ArgumentException>().And.ParamName.Should().Be("interfaceType");
  127. }
  128. [Fact]
  129. public void Implements_generic_should_return_false_when_source_does_not_implement_the_interface()
  130. {
  131. var source = typeof(Stream);
  132. InternalExtensions.Implements<IDisposable>(source).Should().BeTrue();
  133. }
  134. [Fact]
  135. public void Implements_generic_should_return_true_when_source_does_implement_the_interface()
  136. {
  137. var source = typeof(String);
  138. InternalExtensions.Implements<IDisposable>(source).Should().BeFalse();
  139. }
  140. }
  141. }