Esempio n. 1
0
        public static InPortDbContext Create()
        {
            var options = new DbContextOptionsBuilder <InPortDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var context = new InPortDbContext(options);

            context.Database.EnsureCreated();

            Seed(context);

            context.SaveChanges();

            return(context);
        }
Esempio n. 2
0
        protected static void Seed(InPortDbContext unitOfWork)
        {
            /*
             * Countries agg
             */

            var spainCountry = new Country("Spain", "es-ES");

            spainCountry.ChangeCurrentIdentity(new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C"));

            var usaCountry = new Country("EEUU", "en-US");

            usaCountry.ChangeCurrentIdentity(new Guid("C3C82D06-6A07-41FB-B7EA-903EC456BFC5"));

            unitOfWork.Countries.Add(spainCountry);
            unitOfWork.Countries.Add(usaCountry);

            /*
             * Customers agg
             */

            var customerJhon = CustomerFactory.CreateCustomer("Jhon", "Jhon", "+34617", "company", "*****@*****.**", spainCountry, new Address("Madrid", "280181", "Paseo de La finca", ""));

            customerJhon.ChangeCurrentIdentity(new Guid("43A38AC8-EAA9-4DF0-981F-2685882C7C45"));


            var customerMay = CustomerFactory.CreateCustomer("May", "Garcia", "+34617", "company", "*****@*****.**", usaCountry, new Address("Seatle", "3332", "Alaskan Way", ""));

            customerMay.ChangeCurrentIdentity(new Guid("0CD6618A-9C8E-4D79-9C6B-4AA69CF18AE6"));


            unitOfWork.Customers.Add(customerJhon);
            unitOfWork.Customers.Add(customerMay);


            unitOfWork.SaveChanges();
        }
Esempio n. 3
0
        public void SeedCustomers(InPortDbContext context)
        {
            //Countries
            var spain = new Country("Spain", "ES");

            spain.GenerateNewIdentity();
            context.Countries.Add(spain);

            var us = new Country("U.S.", "US");

            us.GenerateNewIdentity();
            context.Countries.Add(us);

            var uk = new Country("U.K.", "GB");

            uk.GenerateNewIdentity();
            context.Countries.Add(uk);

            var canada = new Country("Canada", "CA");

            canada.GenerateNewIdentity();
            context.Countries.Add(canada);

            var italy = new Country("Italy", "IT");

            italy.GenerateNewIdentity();
            context.Countries.Add(italy);

            var france = new Country("France", "FR");

            france.GenerateNewIdentity();
            context.Countries.Add(france);

            var argentina = new Country("Argentina", "AR");

            argentina.GenerateNewIdentity();
            context.Countries.Add(argentina);

            var russia = new Country("Russian Federation", "RUS");

            russia.GenerateNewIdentity();
            context.Countries.Add(russia);

            var israel = new Country("Israel", "IS");

            israel.GenerateNewIdentity();
            context.Countries.Add(israel);

            var brazil = new Country("Brazil", "BZ");

            brazil.GenerateNewIdentity();
            context.Countries.Add(brazil);

            ////
            //Customers

            //Cesar Torres
            var customer1 = CustomerFactory.CreateCustomer("Cesar", "Torres", "+34 1234567", "Microsoft", "*****@*****.**", spain, new Address("Madrid", "28700", "Calle Club Deportivo 1", "Parque Empresarial La Finca, Edif. 1"));

            customer1.SetTheCountryReference(spain.Id);
            context.Customers.Add(customer1);

            //Unai Zorrilla
            var customer2 = CustomerFactory.CreateCustomer("Unai", "Zorrilla", "+34 1234567", "Plain Concepts", "*****@*****.**", spain, new Address("Madrid", "12345", "Calle Plain", "Barrio San Chinarro"));

            customer2.SetTheCountryReference(spain.Id);
            context.Customers.Add(customer2);

            //Miguel Angel
            var customer3 = CustomerFactory.CreateCustomer("Miguel Angel", "Ramos", "+1 1234567", "Microsoft", "*****@*****.**", us, new Address("Redmond", "12345", "One Microsoft Way", "Building X"));

            customer3.SetTheCountryReference(us.Id);
            context.Customers.Add(customer3);

            //Erica Vansas
            var customer4 = CustomerFactory.CreateCustomer("Erica", "Vansas", "+1 1234567", "Domain Language", "*****@*****.**", us, new Address("City", "12345", "DDD Street", "Building X"));

            customer4.SetTheCountryReference(us.Id);
            context.Customers.Add(customer4);

            //César Castro
            var customer5 = CustomerFactory.CreateCustomer("César", "Castro", "+34 1234567", "Freelance", "*****@*****.**", spain, new Address("Madrid", "12345", "Calle de Madrid", "Barrio de Madrid"));

            customer5.SetTheCountryReference(spain.Id);
            context.Customers.Add(customer5);

            context.SaveChanges();
        }
Esempio n. 4
0
 public bool SaveChanges()
 {
     return(_context.SaveChanges() > 0);
 }