예제 #1
0
        public void WithRandomProps_SetsRandomValuesForAllProperties()
        {
            //---------------Set up test pack-------------------

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var randomItems = new List <NotAsSimpleClass>();

            for (var i = 0; i < RANDOM_TEST_CYCLES; i++)
            {
                randomItems.Add(NotAsSimpleBuilder.Create().WithRandomProps().Build());
            }

            //---------------Test Result -----------------------
            // look for variance
            VarianceAssert.IsVariant <NotAsSimpleClass, string>(randomItems, "Name");
            VarianceAssert.IsVariant <NotAsSimpleClass, int>(randomItems, "Value");
            VarianceAssert.IsVariant <NotAsSimpleClass, bool>(randomItems, "Flag");
            VarianceAssert.IsVariant <NotAsSimpleClass, DateTime>(randomItems, "Created");
            VarianceAssert.IsVariant <NotAsSimpleClass, decimal>(randomItems, "Cost");
            VarianceAssert.IsVariant <NotAsSimpleClass, double>(randomItems, "DoubleValue");
            VarianceAssert.IsVariant <NotAsSimpleClass, float>(randomItems, "FloatValue");
            VarianceAssert.IsVariant <NotAsSimpleClass, Guid>(randomItems, "GuidValue");
            VarianceAssert.IsVariant <NotAsSimpleClass, decimal?>(randomItems, "NullableDecimalValue");
            VarianceAssert.IsVariant <NotAsSimpleClass, byte[]>(randomItems, "ByteArrayValue");
            VarianceAssert.IsVariant <NotAsSimpleClass, SomeValues>(randomItems, "EnumValue");
        }
예제 #2
0
        public void WithRandomProps_SetsRandomPropertiesForComplexMembersAndTheirProps()
        {
            //---------------Set up test pack-------------------

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var randomItems = new List <ClassWithComplexMembers>();

            for (var i = 0; i < RANDOM_TEST_CYCLES; i++)
            {
                var randomItem = ClassWithComplexMembersBuilder.BuildRandom();
                Assert.IsNotNull(randomItem.ComplexMember1);
                Assert.IsNotNull(randomItem.ComplexMember2);
                randomItems.Add(randomItem);
            }

            //---------------Test Result -----------------------
            Assert.AreEqual(RANDOM_TEST_CYCLES, randomItems.Count);
            VarianceAssert.IsVariant <ClassWithComplexMembers, ComplexMember1>(randomItems, "ComplexMember1");
            VarianceAssert.IsVariant <ClassWithComplexMembers, ComplexMember2>(randomItems, "ComplexMember2");
            var complexMembers1 = randomItems.Select(i => i.ComplexMember1);

            VarianceAssert.IsVariant <ComplexMember1, string>(complexMembers1, "Name");
            var complexMembers2 = randomItems.Select(i => i.ComplexMember2);

            VarianceAssert.IsVariant <ComplexMember2, int>(complexMembers2, "Value");
        }
예제 #3
0
        public void IsVariant_OperatingOnEmptyCollection_ShouldNotThrow()
        {
            //---------------Set up test pack-------------------

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Assert.DoesNotThrow(() => VarianceAssert.IsVariant(new string[] { }));

            //---------------Test Result -----------------------
        }
예제 #4
0
        public void IsVariant_OperatingOnCollectionOfOne_ShouldNotThrow()
        {
            //---------------Set up test pack-------------------

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Assert.DoesNotThrow(() => VarianceAssert.IsVariant(new[] { RandomValueGen.GetRandomString() }));

            //---------------Test Result -----------------------
        }
예제 #5
0
        public void IsVariant_OperatingOnCollectionOfTwo_WhenHaveSameValues_ShouldThrow()
        {
            //---------------Set up test pack-------------------
            var value = RandomValueGen.GetRandomString();
            var input = new[] { value, value };

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Assert.Throws <AssertionException>(() => VarianceAssert.IsVariant(input));

            //---------------Test Result -----------------------
        }
예제 #6
0
        public void IsVariant_OperatingOnCollectionOfTwo_WhenHaveDifferentValues_ShouldNotThrow()
        {
            //---------------Set up test pack-------------------
            var value1 = RandomValueGen.GetRandomString();
            var value2 = RandomValueGen.GetAnother(value1);
            var input  = new[] { value1, value2 };

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Assert.DoesNotThrow(() => VarianceAssert.IsVariant(input));

            //---------------Test Result -----------------------
        }
예제 #7
0
        public void BuildRandom_ShouldSetBooleanEnabledPropertyToTrue()
        {
            // special rule which makes dealing with entities which have an Enabled flag
            //  a little less tedious for the user
            //---------------Set up test pack-------------------
            var items = new List <TestBooleans>();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            for (var i = 0; i < 1000; i++)
            {
                items.Add(TestBooleansBuilder.BuildRandom());
            }

            //---------------Test Result -----------------------
            Assert.IsTrue(items.Select(i => i.Enabled).All(v => v));
            VarianceAssert.IsVariant <TestBooleans, bool>(items, "SomeOtherBoolean");
        }