Пример #1
0
        public void Generic_CanGetSingleSimpleCustomer()
        {
            var customer = hydrator.GetSingle() as SimpleCustomer;

            Assert.IsTrue(!String.IsNullOrEmpty(customer.Description), "Customer Description should exist.");
            TestUtilities.DumpSimpleCustomer(customer);
        }
        public void Test_Covariance()
        {
            var hy   = new Hydrator <PetShop>();
            var shop = hy.GetSingle();

            Assert.IsNotNull(shop);
            //By default, no instantiation for interfaces and abstract types
            Assert.IsNull(shop.AnimalEnumerable);
            Assert.IsNull(shop.AnimalList);
            Assert.IsNull(shop.CatEnumerable);

            //Dog list should be initialized as it is type of generic List
            Assert.IsNotNull(shop.DogList);
            CollectionAssert.IsEmpty(shop.DogList);

            //setup generators
            hy = hy.With(x => x.AnimalEnumerable, new ListGenerator <Dog>(2)) //Can setup as IEnumerable supports covariance
                 .With(x => x.CatEnumerable, new ListGenerator <Cat>(2))      //Can setup as no covariance required
                 .With(x => x.CatList, new ListGenerator <Cat>(3));           //Can setup List type as no covarinace required
                                                                              //.With(x=>x.AnimalList, new ListGenerator<Cat>(2)) --Cannot setup as IList type doesn't support covariance
                                                                              //.With(x=>x.DogList, new ListGenerator<Dog>(2)) --Cannot setup as List type doesn't support covariance

            shop = hy.GetSingle();

            Assert.IsNotNull(shop);

            //Ienumerable types must be instantiated
            Assert.IsNotNull(shop.AnimalEnumerable);
            Assert.AreEqual(2, shop.AnimalEnumerable.Count());
            CollectionAssert.AllItemsAreInstancesOfType(shop.AnimalEnumerable, typeof(Dog));
            Assert.IsNotNull(shop.CatEnumerable);
            Assert.AreEqual(2, shop.CatEnumerable.Count());
            CollectionAssert.AllItemsAreInstancesOfType(shop.CatEnumerable, typeof(Cat));

            //List type with no covariance should be instantiated
            Assert.IsNotNull(shop.CatList);
            Assert.AreEqual(3, shop.CatList.Count);
            CollectionAssert.AllItemsAreInstancesOfType(shop.CatList, typeof(Cat));

            //As we have seen that we cannot setup IList and List types in case of covariance
            //We can use the following apporach for such types
            shop.AnimalList = new List <Animal>(new Hydrator <Cat>().GetList(2));
            shop.DogList    = new List <Animal>(new Hydrator <Dog>().GetList(2));

            Assert.IsNotNull(shop.DogList);
            Assert.AreEqual(2, shop.DogList.Count);
            CollectionAssert.AllItemsAreInstancesOfType(shop.DogList, typeof(Dog));
            Assert.IsNotNull(shop.AnimalList);
            Assert.AreEqual(2, shop.AnimalList.Count);
            CollectionAssert.AllItemsAreInstancesOfType(shop.AnimalList, typeof(Cat));
        }
Пример #3
0
        public void CanGetTrackingNumberByInference()
        {
            var hydrator = new Hydrator <SimpleCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.TrackingNumber);
        }
Пример #4
0
        public void CreditCardTypeTest()
        {
            var hydrator = new Hydrator <SimpleCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.creditcardtype);
        }
Пример #5
0
        public void GenderTest()
        {
            var hydrator = new Hydrator <SimpleCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.gender);
        }
Пример #6
0
        public UserModel GetSingle()
        {
            Hydrator <UserModel> hydrator = new Hydrator <UserModel>();
            UserModel            theUser  = hydrator.GetSingle();

            return(theUser);
        }
        public void SimpleTest()
        {
            var hydrator = new Hydrator<Address>().WithCustomGenerator(x=>x.State, new InjectedGenerator());

            var checkme = hydrator.GetSingle();
            Assert.IsNotNull(checkme);
        }
        public void StateTest()
        {
            var hydrator = new Hydrator<Address>();

            var checkme = hydrator.GetSingle();
            Assert.IsNotNull(checkme);
        }
 public void BooleanGenerator()
 {
     var hydrator = new Hydrator<SimpleCustomer>();
     var customer = hydrator.GetSingle();
     Assert.IsNotNull(customer.IsActive);
     Assert.IsInstanceOfType(typeof (bool), customer.IsActive);
     TestUtilities.DumpSimpleCustomer(customer);
 }
 public void AlphaNumericWithLength()
 {
     var hydrator = new Hydrator<SimpleCustomer>()
         .WithAlphaNumeric(x => x.placeholderstring, 10);
     var customer = hydrator.GetSingle();
     Assert.IsNotNull(customer.placeholderstring);
     Assert.AreEqual(10, customer.placeholderstring.Length);
 }
Пример #11
0
        public void StateTest()
        {
            var hydrator = new Hydrator <Address>();

            var checkme = hydrator.GetSingle();

            Assert.IsNotNull(checkme);
        }
        public void SimpleTest()
        {
            var hydrator = new Hydrator <Address>().WithCustomGenerator(x => x.State, new InjectedGenerator());

            var checkme = hydrator.GetSingle();

            Assert.IsNotNull(checkme);
        }
Пример #13
0
        public void WithUnitedKingdomPostCodeTest()
        {
            var hydrator = new Hydrator <SimpleCustomer>()
                           .WithUnitedKingdomPostCode(x => x.placeholderstring);
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.placeholderstring);
        }
Пример #14
0
        public void WithAmericanAddressTest()
        {
            var hydrator = new Hydrator <SimpleCustomer>()
                           .WithAmericanAddress(x => x.placeholderstring);
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.placeholderstring);
        }
Пример #15
0
        public void TestWebsiteAddress()
        {
            var hydrator = new Hydrator <SimpleCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.homepage);
            Assert.IsTrue(IsWebsiteAddressValid(customer.homepage));
        }
Пример #16
0
        public void CountryCodeTest()
        {
            var hydrator = new Hydrator <SimpleCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.Country);
            Assert.IsTrue(customer.Country.Length == 2);
        }
Пример #17
0
        public void WithWebsite()
        {
            var hydrator = new Hydrator <SimpleCustomer>()
                           .WithWebsite(x => x.placeholderstring);
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.placeholderstring);
        }
Пример #18
0
        public void PasswordWithInferenceDefaultLength()
        {
            var hydrator = new Hydrator <SimpleCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.Password);
            Assert.AreEqual(10, customer.Password.Length);
        }
Пример #19
0
        public void EmailAddressTest()
        {
            var hydrator = new Hydrator <SimpleCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.EmailAddress);
            Assert.IsTrue(IsEmailAddressValid(customer.EmailAddress));
        }
Пример #20
0
        public void CanGetTrackingNumberBySpecification()
        {
            var hydrator = new Hydrator <SimpleCustomer>()
                           .WithTrackingNumber(x => x.TrackingNumber, "usps");
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.TrackingNumber);
        }
Пример #21
0
        public void PasswordUsingWithAndDefaultLength()
        {
            var hydrator = new Hydrator <SimpleCustomer>()
                           .WithPassword(x => x.placeholderstring);
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.placeholderstring);
            Assert.AreEqual(10, customer.placeholderstring.Length);
        }
Пример #22
0
        public void CanGetSingleRestrictedDescriptionCustomer()
        {
            var hydrator = new Hydrator <RestrictedDescriptionCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsTrue(!String.IsNullOrEmpty(customer.Description), "Customer Description should exist.");
            Assert.IsTrue(customer.Description.Length <= 5, "Length not restricted");
            DumpSimpleCustomer(customer);
        }
Пример #23
0
        public void CanGetCCV()
        {
            var hydrator = new Hydrator <SimpleCustomer>()
                           .WithCCV(x => x.CCV, "visa");
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.CCV);
            Assert.IsTrue(customer.CCV.Length == 3);
        }
Пример #24
0
        public void WithPhoneTest()
        {
            var hydrator = new Hydrator <SimpleCustomer>()
                           .WithAmericanPhone(x => x.placeholderstring);
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.placeholderstring);
            Assert.IsTrue(CheckPhone(customer.placeholderstring));
        }
Пример #25
0
        public void WithPostalCodeTest()
        {
            var hydrator = new Hydrator <SimpleCustomer>()
                           .WithAmericanPostalCode(x => x.placeholderstring, 1);
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.placeholderstring);
            Assert.IsTrue(IsAmericanPostalCodeValid(customer.placeholderstring));
        }
Пример #26
0
        public void CanGetDescription()
        {
            var hydrator = new Hydrator <SimpleCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsTrue(!String.IsNullOrEmpty(customer.Description), "Customer Description should exist.");

            DumpSimpleCustomer(customer);
        }
Пример #27
0
        public void CanLoadSingleComplexCustomerWithAbstractTypeMapper()
        {
            var hy = new Hydrator <ComplexCustomer>();

            var customer = hy.GetSingle();

            Assert.IsNotNull(customer);

            //As Animal is an abstract class, it will not be instantiate by default
            Assert.IsNull(customer.Pet, "Abstract class cannot be instantiate");

            //Set up the generator for abstract type
            hy       = hy.With(x => x.Pet, new TypeGenerator <Dog>());
            customer = hy.GetSingle();

            Assert.IsNotNull(customer.Pet);
            Assert.IsInstanceOf <Dog>(customer.Pet);
        }
Пример #28
0
        public void AlphaNumericWithLength()
        {
            var hydrator = new Hydrator <SimpleCustomer>()
                           .WithAlphaNumeric(x => x.placeholderstring, 10);
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.placeholderstring);
            Assert.AreEqual(10, customer.placeholderstring.Length);
        }
        public void BooleanGenerator()
        {
            var hydrator = new Hydrator <SimpleCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.IsActive);
            Assert.IsInstanceOfType(typeof(bool), customer.IsActive);
            TestUtilities.DumpSimpleCustomer(customer);
        }
Пример #30
0
        public void CanOverrideGenerator()
        {
            var hydrator = new Hydrator <SimpleCustomer>()
                           .With(x => x.FirstName, "Bob");
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer);
            Assert.IsTrue(customer.FirstName == "Bob");
        }
Пример #31
0
        public void CanGetDouble()
        {
            var hydrator = new Hydrator <SimpleCustomer>();

            var customer = hydrator.GetSingle();

            Assert.IsTrue(customer.Revenue >= 0, String.Format("Customer Revenue is expected."));

            DumpSimpleCustomer(customer);
        }
 public void CanLoadSingleComplexCustomer()
 {
     int[] values = {1, 2, 3};
     var args = new object[] {values};
     var hydrator = new Hydrator<ComplexCustomer>()
         .With(x => x.HomeAddress, new TypeGenerator<Address>());
     var customer = hydrator.GetSingle();
     Assert.IsNotNull(customer);
     Assert.IsNotNull(customer.HomeAddress, "CustomerAddress is null");
 }
Пример #33
0
        public void CanGetNullableFields()
        {
            var hydrator = new Hydrator <SimpleCustomer>(false);
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.RewardPoints);
            Assert.IsInstanceOf <int?>(customer.RewardPoints);

            DumpSimpleCustomer(customer);
        }
Пример #34
0
        public void CanGetInteger()
        {
            var hydrator = new Hydrator <SimpleCustomer>();

            var customer = hydrator.GetSingle();

            Assert.IsTrue(customer.Locations >= 0, String.Format("Customer Locations is expected."));

            DumpSimpleCustomer(customer);
        }
Пример #35
0
        public void BooleanGenerator()
        {
            var hydrator = new Hydrator <SimpleCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.IsActive);
            Assert.IsInstanceOf <bool>(customer.IsActive);

            DumpSimpleCustomer(customer);
        }
        public void CanConstrainDoubleDecimalPlaces()
        {
            var decimalPlaces = 3;

            var hydrator = new Hydrator<SimpleCustomer>()
                .WithDouble(x => x.Revenue, decimalPlaces);
            var customer = hydrator.GetSingle();

            var decimalPart = customer.Revenue - (int) customer.Revenue;
            Assert.IsTrue(decimalPart >= 0, String.Format("Customer Revenue decimal part is expected."));

            TestUtilities.DumpSimpleCustomer(customer);
        }
Пример #37
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         Hydrator<Customer> hydrator = new Hydrator<Customer>();
         Customer startwithme = hydrator.GetSingle();
         txtFirstName.Text = startwithme.FirstName;
         txtLastName.Text = startwithme.LastName;
         txtStreetAddress.Text = startwithme.StreetAddress;
         txtCity.Text = startwithme.City;
         txtState.Text = startwithme.State;
         txtZip.Text = startwithme.Zip;
     }
 }
        public void CanConstrainDates()
        {
            var minimumValue = new DateTime(2009, 01, 01);
            var maximumValue = new DateTime(2009, 01, 10);

            var hydrator = new Hydrator<SimpleCustomer>()
                .With(x => x.IncorporatedOn, new DateTimeGenerator(minimumValue, maximumValue));

            var customer = hydrator.GetSingle();

            Assert.That(customer.IncorporatedOn, Is.InRange(minimumValue, maximumValue),
                String.Format("Customer IncorporatedOn [{0}] is outside expected range [{1}, {2}].", customer.IncorporatedOn,
                    minimumValue, maximumValue));
            TestUtilities.DumpSimpleCustomer(customer);
        }
        public void CanChainWithDefaultDescription()
        {
            var defaultValue = "Testing123";
            var minimumValue = 65;
            var maximumValue = 75;

            var hydrator = new Hydrator<SimpleCustomer>()
                .With(x => x.Description, defaultValue)
                .With(x => x.Locations, new IntegerGenerator(minimumValue, maximumValue));

            var customer = hydrator.GetSingle();

            Assert.IsTrue(defaultValue == customer.Description, String.Format("Default value is not as expected[{0}]", defaultValue));

            Assert.That(customer.Locations, Is.InRange(minimumValue, maximumValue),
                String.Format("Customer Locations [{0}] is outside expected range [{1},{2}].", customer.Locations, minimumValue,
                    maximumValue));
            TestUtilities.DumpSimpleCustomer(customer);
        }
Пример #40
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            //Normally I wouldn't put code like this here
            //But I'm just doing this for simplicity
            //Ryan
            Hydrator<Customer> hydrator = new Hydrator<Customer>()
            .With(x=>x.FirstName, txtFirstName.Text)
            .With(x => x.LastName, txtLastName.Text)
            .With(x=>x.StreetAddress,txtStreetAddress.Text)
            .With(x=>x.City,txtCity.Text)
            .With(x=>x.State,txtState.Text)
            .With(x=>x.Zip,txtZip.Text);

            Customer savethis = hydrator.GetSingle();

            CustomerRepository cr = new CustomerRepository();
            cr.SaveCustomer(savethis);
            Response.Redirect("/");
        }
 public void CreditCardTypeTest()
 {
     var hydrator = new Hydrator<SimpleCustomer>();
     var customer = hydrator.GetSingle();
     Assert.IsNotNull(customer.creditcardtype);
 }
 public void FromListTest()
 {
     IList<string> mylist = new List<string>() {"red", "green", "blue", "orange"};
     var hydrator = new Hydrator<SimpleCustomer>()
         .FromList(x => x.placeholderstring, mylist);
     var customer = hydrator.GetSingle();
     Assert.IsNotNull(customer.placeholderstring);
     Assert.IsTrue(mylist.Contains(customer.placeholderstring));
 }
 public void GenderTest()
 {
     var hydrator = new Hydrator<SimpleCustomer>();
     var customer = hydrator.GetSingle();
     Assert.IsNotNull(customer.gender);
 }
        public void CanGetSingleSimpleCustomer()
        {
            var hydrator = new Hydrator<SimpleCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsTrue(!String.IsNullOrEmpty(customer.Description), "Customer Description should exist.");

            TestUtilities.DumpSimpleCustomer(customer);
        }
 public void CanGetTrackingNumberBySpecification()
 {
     var hydrator = new Hydrator<SimpleCustomer>()
         .WithTrackingNumber(x => x.TrackingNumber, "usps");
     var customer = hydrator.GetSingle();
     Assert.IsNotNull(customer.TrackingNumber);
 }
 public void TestWebsiteAddress()
 {
     var hydrator = new Hydrator<SimpleCustomer>();
     var customer = hydrator.GetSingle();
     Assert.IsNotNull(customer.homepage);
     Assert.IsTrue(IsWebsiteAddressValid(customer.homepage));
 }
        public void WithGenderTest()
        {
            var hydrator = new Hydrator<SimpleCustomer>()
                .WithGender(x => x.placeholderstring);

            var customer = hydrator.GetSingle();
            Assert.IsNotNull(customer.placeholderstring);
            Assert.IsTrue(customer.placeholderstring.ToLower().Contains("male") ||
                          customer.placeholderstring.ToLower().Contains("female"));
        }
 public void WithIPAddressTest()
 {
     var hydrator = new Hydrator<SimpleCustomer>()
         .WithIPAddress(x => x.placeholderstring);
     var customer = hydrator.GetSingle();
     Assert.IsNotNull(customer.placeholderstring);
     Assert.IsTrue(IsValidIPAddress(customer.placeholderstring));
 }
 public void WithPhoneTest()
 {
     var hydrator = new Hydrator<SimpleCustomer>()
         .WithAmericanPhone(x => x.placeholderstring);
     var customer = hydrator.GetSingle();
     Assert.IsNotNull(customer.placeholderstring);
     Assert.IsTrue(CheckPhone(customer.placeholderstring));
 }
 public void WithPostalCodeTest()
 {
     var hydrator = new Hydrator<SimpleCustomer>()
         .WithAmericanPostalCode(x => x.placeholderstring, 1);
     var customer = hydrator.GetSingle();
     Assert.IsNotNull(customer.placeholderstring);
     Assert.IsTrue(IsAmericanPostalCodeValid(customer.placeholderstring));
 }
 public void WithUnitedKingdomPostCodeTest()
 {
     var hydrator = new Hydrator<SimpleCustomer>()
         .WithUnitedKingdomPostCode(x => x.placeholderstring);
     var customer = hydrator.GetSingle();
     Assert.IsNotNull(customer.placeholderstring);
 }
 public void CountryCodeTest()
 {
     var hydrator = new Hydrator<SimpleCustomer>();
     var customer = hydrator.GetSingle();
     Assert.IsNotNull(customer.Country);
     Assert.IsTrue(customer.Country.Length == 2);
 }
        public void CanOverrideGenerator()
        {
            var hydrator = new Hydrator<SimpleCustomer>()
                .With(x => x.FirstName, "Bob");
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer);
            Assert.IsTrue(customer.FirstName == "Bob");
        }
 public void PasswordWithInferenceDefaultLength()
 {
     var hydrator = new Hydrator<SimpleCustomer>();
     var customer = hydrator.GetSingle();
     Assert.IsNotNull(customer.Password);
     Assert.AreEqual(10, customer.Password.Length);
 }
 public void CanGetTrackingNumberByInference()
 {
     var hydrator = new Hydrator<SimpleCustomer>();
     var customer = hydrator.GetSingle();
     Assert.IsNotNull(customer.TrackingNumber);
 }
 public void PasswordUsingWithAndDefaultLength()
 {
     var hydrator = new Hydrator<SimpleCustomer>()
         .WithPassword(x => x.placeholderstring);
     var customer = hydrator.GetSingle();
     Assert.IsNotNull(customer.placeholderstring);
     Assert.AreEqual(10, customer.placeholderstring.Length);
 }
        public void CanGetInteger()
        {
            var hydrator = new Hydrator<SimpleCustomer>();

            var customer = hydrator.GetSingle();

            Assert.IsTrue(customer.Locations >= 0, String.Format("Customer Locations is expected."));

            TestUtilities.DumpSimpleCustomer(customer);
        }
 public void IPAddressTest()
 {
     var hydrator = new Hydrator<SimpleCustomer>();
     var customer = hydrator.GetSingle();
     Assert.IsNotNull(customer.ipaddress);
     Assert.IsTrue(IsValidIPAddress(customer.ipaddress));
 }
 public void WithWebsite()
 {
     var hydrator = new Hydrator<SimpleCustomer>()
         .WithWebsite(x => x.placeholderstring);
     var customer = hydrator.GetSingle();
     Assert.IsNotNull(customer.placeholderstring);
 }
        public void CanConstrainDoubleRange()
        {
            var minimum = 15.76;
            var maximum = 76.43;

            var hydrator = new Hydrator<SimpleCustomer>()
                .WithDouble(x => x.Revenue, minimum, maximum);

            var customer = hydrator.GetSingle();
            Assert.That(customer.Revenue, Is.InRange(minimum, maximum));
            TestUtilities.DumpSimpleCustomer(customer);
        }