public async Task AddAsycTest() { //Arrange InPortDbContext context = InPortContextFactory.Create(); UnitOfWorkContainer unitwork = new UnitOfWorkContainer(context); ICountryRepository countryRepository = unitwork.Repository.CountryRepository; Guid countryId = new Guid("A3C82D06-6A07-41FB-B7EA-903EC456BFC5"); Country country2 = new Country("Colombia", "CO"); country2.ChangeCurrentIdentity(countryId); //Act await countryRepository.AddAsync(country2); await unitwork.SaveChangesAsync(); Country country = await countryRepository.SingleAsync(e => e.Id == countryId); //Assert country.ShouldNotBeNull(); country.CountryName.ShouldBe("Colombia"); country.CountryISOCode.ShouldBe("CO"); country.Id.ShouldBe(countryId); }
public UnitOfWorkContainer( InPortDbContext context ) { _context = context; Repository = new UnitOfWorkRepository(_context); }
public void RemoveRangeTest() { //Arrange InPortDbContext context = InPortContextFactory.Create(); UnitOfWorkContainer unitwork = new UnitOfWorkContainer(context); ICountryRepository countryRepository = unitwork.Repository.CountryRepository; Guid countryId1 = new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C"); Guid countryId2 = new Guid("C3C82D06-6A07-41FB-B7EA-903EC456BFC5"); //Act Country country1 = countryRepository.Single(e => e.Id == countryId1); Country country2 = countryRepository.Single(e => e.Id == countryId2); List <Country> list = new List <Country>() { country1, country2 }; countryRepository.Remove(list); unitwork.SaveChanges(); Country countryF1 = countryRepository.SingleOrDefault(e => e.Id == countryId1); Country countryF2 = countryRepository.SingleOrDefault(e => e.Id == countryId2); //Assert countryF1.ShouldBeNull(); countryF2.ShouldBeNull(); }
public void UpdateTest() { //Arrange InPortDbContext context = InPortContextFactory.Create(); UnitOfWorkContainer unitwork = new UnitOfWorkContainer(context); ICountryRepository countryRepository = unitwork.Repository.CountryRepository; Guid countryId = new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C"); // "Spain", "es-ES" //Act Country country = countryRepository.Single(e => e.Id == countryId); country.SetName("Venezuela"); country.SetIsoCode("VZ"); countryRepository.Update(country); unitwork.SaveChanges(); Country countryF = countryRepository.SingleOrDefault(e => e.Id == countryId); //Assert countryF.ShouldNotBeNull(); countryF.CountryName.ShouldBe("Venezuela"); countryF.CountryISOCode.ShouldBe("VZ"); }
public UnitOfWorkRepository(InPortDbContext context) { CustomerRepository = new CustomerRepository(context); CountryRepository = new CountryRepository(context); MeasurentUnitRepository = new MeasurentUnitRepository(context); OrderIncomeRepository = new OrderIncomeRepository(context); ProductRepository = new ProductRepository(context); }
public void SeedEverything(InPortDbContext context) { context.Database.EnsureCreated(); if (context.Customers.Any()) { return; // Db has been seeded } SeedCustomers(context); }
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); }
public async Task AddRangeAsycTest() { //Arrange InPortDbContext context = InPortContextFactory.Create(); UnitOfWorkContainer unitwork = new UnitOfWorkContainer(context); ICountryRepository countryRepository = unitwork.Repository.CountryRepository; Guid countryId1 = new Guid("A3C82D06-6A07-41FB-B7EA-903EC456BFC5"); Country country1 = new Country("Colombia", "CO"); country1.ChangeCurrentIdentity(countryId1); Guid countryId2 = new Guid("B3C82D06-6A07-41FB-B7EA-903EC456BFC5"); Country country2 = new Country("Venezuela", "VZ"); country2.ChangeCurrentIdentity(countryId2); List <Country> list = new List <Country>() { country1, country2 }; //Act await countryRepository.AddAsync(list); await unitwork.SaveChangesAsync(); Country countryF1 = await countryRepository.SingleAsync(e => e.Id == countryId1); Country countryF2 = await countryRepository.SingleAsync(e => e.Id == countryId2); //Assert countryF1.ShouldNotBeNull(); countryF1.CountryName.ShouldBe("Colombia"); countryF1.CountryISOCode.ShouldBe("CO"); countryF1.Id.ShouldBe(countryId1); countryF2.ShouldNotBeNull(); countryF2.CountryName.ShouldBe("Venezuela"); countryF2.CountryISOCode.ShouldBe("VZ"); countryF2.Id.ShouldBe(countryId2); }
public void UpdateRangeTest() { //Arrange InPortDbContext context = InPortContextFactory.Create(); UnitOfWorkContainer unitwork = new UnitOfWorkContainer(context); ICountryRepository countryRepository = unitwork.Repository.CountryRepository; Guid countryId1 = new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C"); // "Spain", "es-ES" Guid countryId2 = new Guid("C3C82D06-6A07-41FB-B7EA-903EC456BFC5"); // "EEUU", "en-US" //Act Country country1 = countryRepository.Single(e => e.Id == countryId1); country1.SetName("Venezuela"); country1.SetIsoCode("VZ"); Country country2 = countryRepository.Single(e => e.Id == countryId2); country2.SetName("Brazil"); country2.SetIsoCode("Br"); List <Country> list = new List <Country>() { country1, country2 }; countryRepository.Update(list); unitwork.SaveChanges(); Country countryF1 = countryRepository.SingleOrDefault(e => e.Id == countryId1); Country countryF2 = countryRepository.SingleOrDefault(e => e.Id == countryId2); //Assert countryF1.ShouldNotBeNull(); countryF1.CountryName.ShouldBe("Venezuela"); countryF1.CountryISOCode.ShouldBe("VZ"); countryF2.ShouldNotBeNull(); countryF2.CountryName.ShouldBe("Brazil"); countryF2.CountryISOCode.ShouldBe("Br"); }
public void RemoveTest() { //Arrange InPortDbContext context = InPortContextFactory.Create(); UnitOfWorkContainer unitwork = new UnitOfWorkContainer(context); ICountryRepository countryRepository = unitwork.Repository.CountryRepository; Guid countryId = new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C"); //Act Country country = countryRepository.Single(e => e.Id == countryId); countryRepository.Remove(country); unitwork.SaveChanges(); Country countryF = countryRepository.SingleOrDefault(e => e.Id == countryId); //Assert countryF.ShouldBeNull(); }
public static void Main(string[] args) { IWebHost host = CreateWebHostBuilder(args).Build(); using (IServiceScope scope = host.Services.CreateScope()) { try { InPortDbContext context = scope.ServiceProvider.GetService <InPortDbContext>(); context.Database.Migrate(); InPortInitializer.Initialize(context); } catch (Exception ex) { ILogger <Program> logger = scope.ServiceProvider.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "Se produjo un error al migrar o inicializar la base de datos."); } } host.Run(); }
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(); }
public void AddTest() { //Arrange InPortDbContext context = InPortContextFactory.Create(); UnitOfWorkContainer unitwork = new UnitOfWorkContainer(context); ICountryRepository countryRepository = unitwork.Repository.CountryRepository; Guid countryId = new Guid("F3C82D06-6A07-41FB-B7EA-903EC456BFC5"); Country country1 = new Country("Colombia", "CO"); country1.ChangeCurrentIdentity(countryId); //Act countryRepository.Add(country1); unitwork.SaveChanges(); Country country = countryRepository.Single(e => e.Id == countryId); //Assert country.ShouldNotBeNull(); country.CountryName.ShouldBe("Colombia"); country.CountryISOCode.ShouldBe("CO"); country.Id.ShouldBe(countryId); }
public GetCustomerDetailQueryHandler(InPortDbContext context) { _context = context; }
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(); }
public GenericRepositoryTests(QueryTestFixture fixture) { _context = fixture.Context; _unitOfWork = fixture.UnitOfWork; }
public static void Initialize(InPortDbContext context) { InPortInitializer initializer = new InPortInitializer(); initializer.SeedEverything(context); }
public ProductRepository(InPortDbContext context) : base(context) { }
public CountryRepository( InPortDbContext context ) : base(context) { }
public CustomerRepository( InPortDbContext context ) : base(context) { }
public static void Destroy(InPortDbContext context) { context.Database.EnsureDeleted(); context.Dispose(); }
protected GenericRepository(InPortDbContext context) { Context = context; }
public MeasurentUnitRepository(InPortDbContext context) : base(context) { }
public OrderIncomeRepository(InPortDbContext context) : base(context) { }
public GetCustomersListQueryHandler(InPortDbContext context, IMapper mapper) { _context = context; _mapper = mapper; }