public static void Dummies___Should_return_list_with_MinRandomNumberOfElements_to_MaxRandomNumberOfElements_elements___When_parameter_numberOfElements_is_negative() { // Arrange, Act var result1 = Some.Dummies <double>(A.Dummy <NegativeInteger>(), CreateWith.NoNulls); var result2 = Some.Dummies <double>(A.Dummy <NegativeInteger>(), CreateWith.ZeroOrMoreNulls); var result3 = Some.Dummies <int?>(A.Dummy <NegativeInteger>(), CreateWith.NoNulls); var result4 = Some.Dummies <int?>(A.Dummy <NegativeInteger>(), CreateWith.ZeroOrMoreNulls); var result5 = Some.Dummies <int?>(A.Dummy <NegativeInteger>(), CreateWith.OneOrMoreNulls); var result6 = Some.Dummies <string>(A.Dummy <NegativeInteger>(), CreateWith.NoNulls); var result7 = Some.Dummies <string>(A.Dummy <NegativeInteger>(), CreateWith.ZeroOrMoreNulls); var result8 = Some.Dummies <string>(A.Dummy <NegativeInteger>(), CreateWith.OneOrMoreNulls); var result9 = Some.Dummies <object>(A.Dummy <NegativeInteger>(), CreateWith.NoNulls); var result10 = Some.Dummies <object>(A.Dummy <NegativeInteger>(), CreateWith.ZeroOrMoreNulls); var result11 = Some.Dummies <object>(A.Dummy <NegativeInteger>(), CreateWith.OneOrMoreNulls); // Assert result1.Count.Should().BeGreaterOrEqualTo(Some.MinRandomNumberOfElements).And.BeLessOrEqualTo(Some.MaxRandomNumberOfElements); result2.Count.Should().BeGreaterOrEqualTo(Some.MinRandomNumberOfElements).And.BeLessOrEqualTo(Some.MaxRandomNumberOfElements); result3.Count.Should().BeGreaterOrEqualTo(Some.MinRandomNumberOfElements).And.BeLessOrEqualTo(Some.MaxRandomNumberOfElements); result4.Count.Should().BeGreaterOrEqualTo(Some.MinRandomNumberOfElements).And.BeLessOrEqualTo(Some.MaxRandomNumberOfElements); result5.Count.Should().BeGreaterOrEqualTo(Some.MinRandomNumberOfElements).And.BeLessOrEqualTo(Some.MaxRandomNumberOfElements); result6.Count.Should().BeGreaterOrEqualTo(Some.MinRandomNumberOfElements).And.BeLessOrEqualTo(Some.MaxRandomNumberOfElements); result7.Count.Should().BeGreaterOrEqualTo(Some.MinRandomNumberOfElements).And.BeLessOrEqualTo(Some.MaxRandomNumberOfElements); result8.Count.Should().BeGreaterOrEqualTo(Some.MinRandomNumberOfElements).And.BeLessOrEqualTo(Some.MaxRandomNumberOfElements); result9.Count.Should().BeGreaterOrEqualTo(Some.MinRandomNumberOfElements).And.BeLessOrEqualTo(Some.MaxRandomNumberOfElements); result10.Count.Should().BeGreaterOrEqualTo(Some.MinRandomNumberOfElements).And.BeLessOrEqualTo(Some.MaxRandomNumberOfElements); result11.Count.Should().BeGreaterOrEqualTo(Some.MinRandomNumberOfElements).And.BeLessOrEqualTo(Some.MaxRandomNumberOfElements); }
public static void Dummies___Should_return_object_of_type_SomeDummiesList_with_parameters_numberOfElements_and_createWith_stored_in_the_object_under_properties_of_the_same_name___When_called() { // Arrange // note: can't test numberOfElements = 0 with random createWith, because some combinations are not permitted (like creating a list with one or more nulls) var numberOfElements1 = ThreadSafeRandom.Next(-100000, -1); var numberOfElements2 = ThreadSafeRandom.Next(1, 100000); var createWith = (CreateWith)ThreadSafeRandom.Next(0, Enum.GetNames(typeof(CreateWith)).Length); // Act var result1 = Some.Dummies <object>(numberOfElements1, createWith); var result2 = Some.Dummies <object>(numberOfElements2, createWith); var result3 = Some.Dummies <object>(0, CreateWith.ZeroOrMoreNulls); // Assert var result1AsSomeDummiesList = result1 as SomeDummiesList <object>; var result2AsSomeDummiesList = result2 as SomeDummiesList <object>; var result3AsSomeDummiesList = result3 as SomeDummiesList <object>; result1AsSomeDummiesList.Should().NotBeNull(); result2AsSomeDummiesList.Should().NotBeNull(); result3AsSomeDummiesList.Should().NotBeNull(); result1AsSomeDummiesList.NumberOfElementsSpecifiedInCallToSomeDummies.Should().Be(numberOfElements1); result1AsSomeDummiesList.CreateWithSpecifiedInCallToSomeDummies.Should().Be(createWith); result2AsSomeDummiesList.NumberOfElementsSpecifiedInCallToSomeDummies.Should().Be(numberOfElements2); result2AsSomeDummiesList.CreateWithSpecifiedInCallToSomeDummies.Should().Be(createWith); result3AsSomeDummiesList.NumberOfElementsSpecifiedInCallToSomeDummies.Should().Be(0); result3AsSomeDummiesList.CreateWithSpecifiedInCallToSomeDummies.Should().Be(CreateWith.ZeroOrMoreNulls); }
public static void Dummies___Should_return_random_list_with_specified_number_of_elements_and_one_or_more_nulls___When_parameter_createWith_is_OneOrMoreNulls() { // Arrange, Act const int numberOfElements = 3; var result1 = Some.Dummies <int?>(numberOfElements, CreateWith.OneOrMoreNulls); var result2 = Some.Dummies <string>(numberOfElements, CreateWith.OneOrMoreNulls); var result3 = Some.Dummies <object>(numberOfElements, CreateWith.OneOrMoreNulls); var result4 = Some.Dummies <int?>(1, CreateWith.OneOrMoreNulls); var result5 = Some.Dummies <string>(1, CreateWith.OneOrMoreNulls); var result6 = Some.Dummies <object>(1, CreateWith.OneOrMoreNulls); // Assert result1.Should().HaveCount(numberOfElements).And.Contain((int?)null); result1.Where(_ => _ != null).Should().OnlyHaveUniqueItems(); result2.Should().HaveCount(numberOfElements).And.Contain((string)null); result2.Where(_ => _ != null).Should().OnlyHaveUniqueItems(); result3.Should().HaveCount(numberOfElements).And.Contain((object)null); result3.Where(_ => _ != null).Should().OnlyHaveUniqueItems(); result4.Should().ContainSingle().And.Contain((int?)null); result5.Should().ContainSingle().And.Contain((string)null); result6.Should().ContainSingle().And.Contain((object)null); }
public static void Dummies___Should_throw_ArgumentException___When_parameter_createWith_is_OneOrMoreNulls_and_type_to_create_is_a_value_type() { // Arrange, Act var ex1 = Record.Exception(() => Some.Dummies <CreateWith>(3, CreateWith.OneOrMoreNulls)); var ex2 = Record.Exception(() => Some.Dummies <bool>(3, CreateWith.OneOrMoreNulls)); var ex3 = Record.Exception(() => Some.Dummies <byte>(3, CreateWith.OneOrMoreNulls)); var ex4 = Record.Exception(() => Some.Dummies <char>(3, CreateWith.OneOrMoreNulls)); var ex5 = Record.Exception(() => Some.Dummies <decimal>(3, CreateWith.OneOrMoreNulls)); var ex6 = Record.Exception(() => Some.Dummies <double>(3, CreateWith.OneOrMoreNulls)); var ex7 = Record.Exception(() => Some.Dummies <float>(3, CreateWith.OneOrMoreNulls)); var ex8 = Record.Exception(() => Some.Dummies <int>(3, CreateWith.OneOrMoreNulls)); var ex9 = Record.Exception(() => Some.Dummies <long>(3, CreateWith.OneOrMoreNulls)); var ex10 = Record.Exception(() => Some.Dummies <sbyte>(3, CreateWith.OneOrMoreNulls)); var ex11 = Record.Exception(() => Some.Dummies <short>(3, CreateWith.OneOrMoreNulls)); // Assert ex1.Should().BeOfType <ArgumentException>(); ex2.Should().BeOfType <ArgumentException>(); ex3.Should().BeOfType <ArgumentException>(); ex4.Should().BeOfType <ArgumentException>(); ex5.Should().BeOfType <ArgumentException>(); ex6.Should().BeOfType <ArgumentException>(); ex7.Should().BeOfType <ArgumentException>(); ex8.Should().BeOfType <ArgumentException>(); ex9.Should().BeOfType <ArgumentException>(); ex10.Should().BeOfType <ArgumentException>(); ex11.Should().BeOfType <ArgumentException>(); }
public static void Dummies___Should_not_throw___When_parameter_createWith_is_OneOrMoreNulls_and_type_to_create_is_not_a_value_type() { // Arrange, Act var ex1 = Record.Exception(() => Some.Dummies <CreateWith?>(3, CreateWith.OneOrMoreNulls)); var ex2 = Record.Exception(() => Some.Dummies <bool?>(3, CreateWith.OneOrMoreNulls)); var ex3 = Record.Exception(() => Some.Dummies <byte?>(3, CreateWith.OneOrMoreNulls)); var ex4 = Record.Exception(() => Some.Dummies <char?>(3, CreateWith.OneOrMoreNulls)); var ex5 = Record.Exception(() => Some.Dummies <decimal?>(3, CreateWith.OneOrMoreNulls)); var ex6 = Record.Exception(() => Some.Dummies <double?>(3, CreateWith.OneOrMoreNulls)); var ex7 = Record.Exception(() => Some.Dummies <float?>(3, CreateWith.OneOrMoreNulls)); var ex8 = Record.Exception(() => Some.Dummies <int?>(3, CreateWith.OneOrMoreNulls)); var ex9 = Record.Exception(() => Some.Dummies <long?>(3, CreateWith.OneOrMoreNulls)); var ex10 = Record.Exception(() => Some.Dummies <sbyte?>(3, CreateWith.OneOrMoreNulls)); var ex11 = Record.Exception(() => Some.Dummies <short?>(3, CreateWith.OneOrMoreNulls)); var ex12 = Record.Exception(() => Some.Dummies <string>(3, CreateWith.OneOrMoreNulls)); var ex13 = Record.Exception(() => Some.Dummies <object>(3, CreateWith.OneOrMoreNulls)); // Assert ex1.Should().BeNull(); ex2.Should().BeNull(); ex3.Should().BeNull(); ex4.Should().BeNull(); ex5.Should().BeNull(); ex6.Should().BeNull(); ex7.Should().BeNull(); ex8.Should().BeNull(); ex9.Should().BeNull(); ex10.Should().BeNull(); ex11.Should().BeNull(); ex12.Should().BeNull(); ex13.Should().BeNull(); }
public static void GetHashCode___Should_return_different_hash_code___For_different_byte_arrays() { // Arrange var byteArray1a = Some.Dummies <byte>().ToArray(); var byteArray1b = byteArray1a.Concat(new[] { A.Dummy <byte>() }).ToArray(); var byteArray2a = Some.Dummies <byte>().ToArray(); var byteArray2b = new[] { A.Dummy <byte>() }.Concat(byteArray2a).ToArray(); var byteArray3a = Some.Dummies <byte>(5).ToArray(); var byteArray3b = Some.Dummies <byte>(5).ToArray(); var systemUnderTest = new ByteArrayEqualityComparer(); // Act var hash1a = systemUnderTest.GetHashCode(byteArray1a); var hash1b = systemUnderTest.GetHashCode(byteArray1b); var hash2a = systemUnderTest.GetHashCode(byteArray2a); var hash2b = systemUnderTest.GetHashCode(byteArray2b); var hash3a = systemUnderTest.GetHashCode(byteArray3a); var hash3b = systemUnderTest.GetHashCode(byteArray3b); // Assert hash1a.Should().NotBe(hash1b); hash2a.Should().NotBe(hash2b); hash3a.Should().NotBe(hash3b); }
public static void Dummies___Should_throw_ArgumentException___When_parameter_createWith_is_OneOrMoreNulls_and_parameter_numberOfElements_is_zero() { // Arrange, Act var ex1 = Record.Exception(() => Some.Dummies <double>(0, CreateWith.OneOrMoreNulls)); var ex2 = Record.Exception(() => Some.Dummies <string>(0, CreateWith.OneOrMoreNulls)); var ex3 = Record.Exception(() => Some.Dummies <object>(0, CreateWith.OneOrMoreNulls)); // Assert ex1.Should().BeOfType <ArgumentException>(); ex2.Should().BeOfType <ArgumentException>(); ex3.Should().BeOfType <ArgumentException>(); }
public static void Equals___Should_return_true___When_both_bytes_arrays_are_the_same_object_reference() { // Arrange var byteArray = Some.Dummies <byte>().ToArray(); var systemUnderTest = new ByteArrayEqualityComparer(); // Act var actual = systemUnderTest.Equals(byteArray, byteArray); // Assert actual.Should().BeTrue(); }
public static void Equals___Should_return_true___When_both_objects_are_the_same_reference() { // Arrange var item = Some.Dummies <byte>().ToArray(); var systemUnderTest = new ReferenceEqualityComparer <byte[]>(); // Act var actual = systemUnderTest.Equals(item, item); // Assert actual.Should().BeTrue(); }
public static void GetHashCode___Should_return_same_hash_code___When_called_twice_on_same_object_reference() { // Arrange var byteArray = Some.Dummies <byte>().ToArray(); var systemUnderTest = new ByteArrayEqualityComparer(); // Act var hash1 = systemUnderTest.GetHashCode(byteArray); var hash2 = systemUnderTest.GetHashCode(byteArray); // Assert hash1.Should().Be(hash2); }
public static void Equals___Should_return_false___When_one_byte_array_is_null_and_the_other_is_not_null() { // Arrange byte[] byteArray1 = null; var byteArray2 = Some.Dummies <byte>().ToArray(); var systemUnderTest = new ByteArrayEqualityComparer(); // Act var actual1 = systemUnderTest.Equals(byteArray1, byteArray2); var actual2 = systemUnderTest.Equals(byteArray2, byteArray1); // Assert actual1.Should().BeFalse(); actual2.Should().BeFalse(); }
public static void Dummies___Should_return_random_list_with_specified_number_of_elements_and_no_nulls___When_parameter_createWith_is_NoNulls() { // Arrange, Act const int numberOfElements = 100; var result1 = Some.Dummies <double>(numberOfElements, CreateWith.NoNulls); var result2 = Some.Dummies <int?>(numberOfElements, CreateWith.NoNulls); var result3 = Some.Dummies <string>(numberOfElements, CreateWith.NoNulls); var result4 = Some.Dummies <object>(numberOfElements, CreateWith.NoNulls); // Assert result1.Should().HaveCount(numberOfElements).And.OnlyHaveUniqueItems(); result2.Should().HaveCount(numberOfElements).And.OnlyHaveUniqueItems().And.NotContainNulls(); result3.Should().HaveCount(numberOfElements).And.OnlyHaveUniqueItems().And.NotContainNulls(); result4.Should().HaveCount(numberOfElements).And.OnlyHaveUniqueItems().And.NotContainNulls(); }
public static void Equals___Should_return_true___When_byte_arrays_are_equal_but_not_the_same_object_reference() { // Arrange var byteArray1 = Some.Dummies <byte>().ToArray(); var byteArray2 = new byte[byteArray1.Length]; Buffer.BlockCopy(byteArray1, 0, byteArray2, 0, byteArray1.Length); var systemUnderTest = new ByteArrayEqualityComparer(); // Act var actual = systemUnderTest.Equals(byteArray1, byteArray2); // Assert actual.Should().BeTrue(); }
public static void Equals___Should_return_false___When_objects_have_different_runtime_types() { // Arrange object item1 = Some.Dummies <byte>().ToArray(); object item2 = new object(); var systemUnderTest = new ObjectEqualityComparer(); // Act var actual1 = systemUnderTest.Equals(item1, item2); var actual2 = systemUnderTest.Equals(item2, item1); // Assert actual1.Should().BeFalse(); actual2.Should().BeFalse(); }
public static void GetHashCode___Should_return_same_hash_code___For_two_byte_arrays_that_are_equal() { // Arrange var byteArray1 = Some.Dummies <byte>().ToArray(); var byteArray2 = new byte[byteArray1.Length]; Buffer.BlockCopy(byteArray1, 0, byteArray2, 0, byteArray1.Length); var systemUnderTest = new ByteArrayEqualityComparer(); // Act var hash1 = systemUnderTest.GetHashCode(byteArray1); var hash2 = systemUnderTest.GetHashCode(byteArray2); // Assert hash1.Should().Be(hash2); }
public static void Dummies___Should_return_empty_list___When_parameter_numberOfElements_is_0() { // Arrange, Act var result1 = Some.Dummies <double>(0, CreateWith.NoNulls); var result2 = Some.Dummies <double>(0, CreateWith.ZeroOrMoreNulls); var result3 = Some.Dummies <int?>(0, CreateWith.NoNulls); var result4 = Some.Dummies <int?>(0, CreateWith.ZeroOrMoreNulls); var result5 = Some.Dummies <string>(0, CreateWith.NoNulls); var result6 = Some.Dummies <string>(0, CreateWith.ZeroOrMoreNulls); var result7 = Some.Dummies <object>(0, CreateWith.NoNulls); var result8 = Some.Dummies <object>(0, CreateWith.ZeroOrMoreNulls); // Assert result1.Should().BeEmpty(); result2.Should().BeEmpty(); result3.Should().BeEmpty(); result4.Should().BeEmpty(); result5.Should().BeEmpty(); result6.Should().BeEmpty(); result7.Should().BeEmpty(); result8.Should().BeEmpty(); }
public static void Equals___Should_return_false___When_byte_arrays_are_different() { // Arrange var byteArray1a = Some.Dummies <byte>().ToArray(); var byteArray1b = byteArray1a.Concat(new[] { A.Dummy <byte>() }).ToArray(); var byteArray2a = Some.Dummies <byte>().ToArray(); var byteArray2b = new[] { A.Dummy <byte>() }.Concat(byteArray2a).ToArray(); var byteArray3a = Some.Dummies <byte>(5).ToArray(); var byteArray3b = Some.Dummies <byte>(5).ToArray(); var systemUnderTest = new ByteArrayEqualityComparer(); // Act var actual1 = systemUnderTest.Equals(byteArray1a, byteArray1b); var actual2 = systemUnderTest.Equals(byteArray2a, byteArray2b); var actual3 = systemUnderTest.Equals(byteArray3a, byteArray3b); // Assert actual1.Should().BeFalse(); actual2.Should().BeFalse(); actual3.Should().BeFalse(); }
public CronDummyFactory() { AutoFixtureBackedDummyFactory.UseRandomConcreteSubclassForDummy <ScheduleBase>(); AutoFixtureBackedDummyFactory.AddDummyCreator( () => { var result = new DailyScheduleInUtc { Hour = A.Dummy <int>().ThatIsInRange(0, 23), Minute = A.Dummy <int>().ThatIsInRange(0, 59), }; return(result); }); AutoFixtureBackedDummyFactory.AddDummyCreator( () => { var result = new ExpressionSchedule { CronExpression = "*/" + A.Dummy <int>().ThatIsInRange(1, 4) + " * * * *", }; return(result); }); AutoFixtureBackedDummyFactory.AddDummyCreator( () => { var result = new HourlySchedule { Minute = A.Dummy <int>().ThatIsInRange(0, 59), }; return(result); }); AutoFixtureBackedDummyFactory.AddDummyCreator( () => { var result = new IntervalSchedule() { Interval = new TimeSpan(A.Dummy <long>().ThatIsInRange(0, 10000)) }; return(result); }); AutoFixtureBackedDummyFactory.AddDummyCreator( () => { var result = new MonthlyScheduleInUtc() { DaysOfMonth = new[] { A.Dummy <int>().ThatIsInRange(0, 28), A.Dummy <int>().ThatIsInRange(0, 28), A.Dummy <int>().ThatIsInRange(0, 28), A.Dummy <int>().ThatIsInRange(0, 28), A.Dummy <int>().ThatIsInRange(0, 28), }.Distinct().ToArray(), Hour = A.Dummy <int>().ThatIsInRange(0, 23), Minute = A.Dummy <int>().ThatIsInRange(0, 59), }; return(result); }); AutoFixtureBackedDummyFactory.AddDummyCreator( () => { var result = new WeeklyScheduleInUtc() { DaysOfWeek = Some.Dummies <DayOfWeek>(3).ToArray(), Hour = A.Dummy <int>().ThatIsInRange(0, 23), Minute = A.Dummy <int>().ThatIsInRange(0, 59), }; return(result); }); AutoFixtureBackedDummyFactory.AddDummyCreator( () => { var result = new YearlyScheduleInUtc() { MonthsOfYear = Some.Dummies <MonthOfYear>(4).ToArray(), DaysOfMonth = new[] { A.Dummy <int>().ThatIsInRange(0, 28), A.Dummy <int>().ThatIsInRange(0, 28), A.Dummy <int>().ThatIsInRange(0, 28), A.Dummy <int>().ThatIsInRange(0, 28), A.Dummy <int>().ThatIsInRange(0, 28), }.Distinct().ToArray(), Hour = A.Dummy <int>().ThatIsInRange(0, 23), Minute = A.Dummy <int>().ThatIsInRange(0, 59), }; return(result); }); }