public void CanCreateDtoWithEntity() { Territory territory = CreateTerritory(); TerritoryDto territoryDto = TerritoryDto.Create(territory); territoryDto.Id.ShouldEqual("08837"); territoryDto.Description.ShouldEqual("Edison"); territoryDto.RegionBelongingTo.ShouldNotBeNull(); territoryDto.RegionBelongingTo.Id.ShouldEqual(1);; territoryDto.Employees.Count.ShouldEqual(2); territoryDto.Employees[0].Id.ShouldEqual(5); territoryDto.Employees[1].Id.ShouldEqual(10); }
public IList <TerritoryDto> GetTerritories() { // I'd rather have the transaction begun via an attribute, like with a controller action, // or within a service object, but this works for the current example. this.territoryRepository.DbContext.BeginTransaction(); var territories = this.territoryRepository.GetAll(); var territoryDtos = new List <TerritoryDto>(); foreach (var territory in territories) { territoryDtos.Add(TerritoryDto.Create(territory)); } // Since we're certainly not going to require lazy loading, commit the transcation // before returning the data. this.territoryRepository.DbContext.CommitTransaction(); return(territoryDtos); }