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 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); }
private static UnitOfWorkContainer SetUnitOfWorkContainer(IContainer value) { var unitOfWorkInstance = new UnitOfWorkContainer(value); var disposer = _unitOfWorkStorage.Set(unitOfWorkInstance); unitOfWorkInstance.UnitOfWorkDisposer = disposer; return(unitOfWorkInstance); }
public QueryTestFixture() { Context = InPortContextFactory.Create(); UnitOfWork = new UnitOfWorkContainer(Context); var serviceFactory = new ServiceFactory(type => typeof(IEnumerable).IsAssignableFrom(type) ? Array.CreateInstance(type.GetGenericArguments().First(), 0) : null); Bus = new Mediator(serviceFactory); Notifications = new DomainNotificationHandler(); }
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(); }
static void Main(string[] args) { Console.WriteLine("Starting application"); // Create instance of database using (var context = new ApplicationDbContext()) { // Prepare unit Of Work IUnitOfWork uow = new UnitOfWorkContainer(context); // Prepare services IUserService userService = new UserService(uow); // First Test //CreateUserExample(userService); // Second Case PagedUserExample(userService); } Console.WriteLine("Ending application"); Console.Read(); }
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 GenericRepositoryTests(QueryTestFixture fixture) { _context = fixture.Context; _unitOfWork = fixture.UnitOfWork; }
public QueryTestFixture() { Context = InPortContextFactory.Create(); UnitOfWork = new UnitOfWorkContainer(Context); }