public void IncluirTerritorioDeUmaRegiao() { using (var uow = CreateTransientUnitOfWork()) { var region = new Region { RegionDescription = "Região de Teste" }; region.GenerateNewIdentity(); var regionRepository = new RegionRepository(uow); regionRepository.Incluir(region); uow.Commit(); } using (var uow = CreateTransientUnitOfWork()) { var territoriesRepository = new TerritoriesRepository(uow); var regionRepository = new RegionRepository(uow); var region = regionRepository.Listar().FirstOrDefault(r => r.Territories.Count.Equals(0)); var qtdOriginalDeRegistrosNaTabelaTerritories = territoriesRepository.Contar(); if (region != null) { var territories = new Territories { TerritoryDescription = "Território de Teste" }; territories.GenerateNewIdentity(); region.Territories = (new List<Territories> { territories }); regionRepository.Alterar(region); uow.Commit(); Assert.AreEqual(qtdOriginalDeRegistrosNaTabelaTerritories + 1 , territoriesRepository.Contar()); Assert.IsNotNull(region.Territories); } else { uow.Rollback(); Assert.IsTrue(false); } } }
public void IncluirAtualizarExcluirTerritorioDeUmaRegiao() { using (var uow = CreateTransientUnitOfWork()) { var regionRepository = new RegionRepository(uow); var region = regionRepository.Listar().FirstOrDefault(r => r.Territories.Count >= 2); if (region != null) { var territories = new Territories {TerritoryDescription = "Território de Teste Novo"}; territories.GenerateNewIdentity(); //var Territories = region.Territories.Last(); region.Territories.First().TerritoryDescription = "Território de Teste"; //region.Territories.Remove(Territories); region.Territories.Add(territories); regionRepository.Alterar(region); uow.Commit(); Assert.AreEqual(region.Territories.First().TerritoryDescription , "Território de Teste"); Assert.AreEqual(region.Territories.Last().TerritoryDescription , "Território de Teste Novo"); } else { uow.Rollback(); Assert.IsTrue(false); } } }