public void Should_Use_Custom_Boundaries_for_DateTime_Value_Injection()
        {
            //Create an instance of our test class
            var testInstance = new DateTimeTestClass();

            var dateTimeMax = DateTime.UtcNow.AddYears(1);
            var dateTimeMin = DateTime.UtcNow.AddYears(-1);

            //Create an instance of our IntSelector and set some custom bounds
            var selector =
                new DateTimeSelector().SetMax(() => Faker.Generators.DateTimes.GetDateTime(dateTimeMax, dateTimeMax))
                                 .SetMin(() => Faker.Generators.DateTimes.GetDateTime(dateTimeMin, dateTimeMin));

            //Iterate over the test object's properties
            foreach (var property in testInstance.GetType().GetProperties())
            {
                Assert.IsTrue(selector.CanBind(property),
                              string.Format("should have been able to bind to property {0}", property.Name));

                //Inject the value into this property on our test instance class
                selector.Generate(testInstance, property);

                //Get the value out of the property
                var fieldValue = (DateTime)property.GetValue(testInstance, null);
                Assert.IsNotNull(fieldValue);
                Assert.AreNotEqual(fieldValue, default(DateTime));
                Assert.IsTrue(fieldValue <= dateTimeMax && fieldValue >= dateTimeMin, "Custom range should have worked");
            }
        }
        public void Should_Use_Custom_Boundaries_for_DateTime_Value_Injection()
        {
            //Create an instance of our test class
            var testInstance = new DateTimeTestClass();

            var dateTimeMax = DateTime.UtcNow.AddYears(1);
            var dateTimeMin = DateTime.UtcNow.AddYears(-1);

            //Create an instance of our IntSelector and set some custom bounds
            var selector =
                new DateTimeSelector().SetMax(() => Faker.Generators.DateTimes.GetDateTime(dateTimeMax, dateTimeMax))
                .SetMin(() => Faker.Generators.DateTimes.GetDateTime(dateTimeMin, dateTimeMin));

            //Iterate over the test object's properties
            foreach (var property in testInstance.GetType().GetProperties())
            {
                Assert.IsTrue(selector.CanBind(property),
                              string.Format("should have been able to bind to property {0}", property.Name));

                //Inject the value into this property on our test instance class
                selector.Generate(testInstance, property);

                //Get the value out of the property
                var fieldValue = (DateTime)property.GetValue(testInstance, null);
                Assert.IsNotNull(fieldValue);
                Assert.AreNotEqual(fieldValue, default(DateTime));
                Assert.IsTrue(fieldValue <= dateTimeMax && fieldValue >= dateTimeMin, "Custom range should have worked");
            }
        }
Exemple #3
0
        public void DateTime_Selector_Injects_All_DateTime_Values()
        {
            var dateTimeSelector  = new DateTimeSelector();
            var dateTimeTestClass = new DateTimeTestClass();

            //Iterate over all of the properties in the fullNameClass object...
            foreach (var property in dateTimeTestClass.GetType().GetProperties())
            {
                //Inject the value into the property
                dateTimeSelector.Generate(dateTimeTestClass, property);
            }

            //Iterate over all of the properties again
            foreach (var property in dateTimeTestClass.GetType().GetProperties())
            {
                var fieldValue = (DateTime)property.GetValue(dateTimeTestClass, null);

                Assert.IsAssignableFrom <DateTime>(fieldValue, "Should be type of DateTime...");
                Assert.AreNotEqual(fieldValue, default(DateTime));
            }
        }
        public void DateTime_Selector_Injects_All_DateTime_Values()
        {
            var dateTimeSelector = new DateTimeSelector();
            var dateTimeTestClass = new DateTimeTestClass();

            //Iterate over all of the properties in the fullNameClass object...
            foreach (var property in dateTimeTestClass.GetType().GetProperties())
            {
                //Inject the value into the property
                dateTimeSelector.Generate(dateTimeTestClass, property);
            }

            //Iterate over all of the properties again
            foreach (var property in dateTimeTestClass.GetType().GetProperties())
            {
                var fieldValue = (DateTime)property.GetValue(dateTimeTestClass, null);

                Assert.IsAssignableFrom<DateTime>(fieldValue, "Should be type of DateTime...");
                Assert.AreNotEqual(fieldValue, default(DateTime));
            }
        }