Exemplo n.º 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));
        }
Exemplo n.º 3
0
        public void CanGetTrackingNumberByInference()
        {
            var hydrator = new Hydrator <SimpleCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.TrackingNumber);
        }
Exemplo n.º 4
0
        public void CreditCardTypeTest()
        {
            var hydrator = new Hydrator <SimpleCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.creditcardtype);
        }
Exemplo n.º 5
0
        public void GenderTest()
        {
            var hydrator = new Hydrator <SimpleCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.gender);
        }
Exemplo n.º 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);
 }
Exemplo n.º 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);
        }
Exemplo n.º 13
0
        public void WithUnitedKingdomPostCodeTest()
        {
            var hydrator = new Hydrator <SimpleCustomer>()
                           .WithUnitedKingdomPostCode(x => x.placeholderstring);
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.placeholderstring);
        }
Exemplo n.º 14
0
        public void WithAmericanAddressTest()
        {
            var hydrator = new Hydrator <SimpleCustomer>()
                           .WithAmericanAddress(x => x.placeholderstring);
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.placeholderstring);
        }
Exemplo n.º 15
0
        public void TestWebsiteAddress()
        {
            var hydrator = new Hydrator <SimpleCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.homepage);
            Assert.IsTrue(IsWebsiteAddressValid(customer.homepage));
        }
Exemplo n.º 16
0
        public void CountryCodeTest()
        {
            var hydrator = new Hydrator <SimpleCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.Country);
            Assert.IsTrue(customer.Country.Length == 2);
        }
Exemplo n.º 17
0
        public void WithWebsite()
        {
            var hydrator = new Hydrator <SimpleCustomer>()
                           .WithWebsite(x => x.placeholderstring);
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.placeholderstring);
        }
Exemplo n.º 18
0
        public void PasswordWithInferenceDefaultLength()
        {
            var hydrator = new Hydrator <SimpleCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.Password);
            Assert.AreEqual(10, customer.Password.Length);
        }
Exemplo n.º 19
0
        public void EmailAddressTest()
        {
            var hydrator = new Hydrator <SimpleCustomer>();
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.EmailAddress);
            Assert.IsTrue(IsEmailAddressValid(customer.EmailAddress));
        }
Exemplo n.º 20
0
        public void CanGetTrackingNumberBySpecification()
        {
            var hydrator = new Hydrator <SimpleCustomer>()
                           .WithTrackingNumber(x => x.TrackingNumber, "usps");
            var customer = hydrator.GetSingle();

            Assert.IsNotNull(customer.TrackingNumber);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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");
        }
Exemplo n.º 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");
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }