public void CanCreateTerritory() { Region region = new RegionWithPublicConstructor("Midwest"); Territory territory = new Territory("Cincinnati", region); territory.Description.ShouldEqual("Cincinnati"); territory.RegionBelongingTo.ShouldEqual(region); territory.Id.ShouldBeNull(); territory.SetAssignedIdTo("ABRACADABRA"); territory.Id.ShouldEqual("ABRACADABRA"); }
/// <summary> /// This creates "shallow" territories; there's no need to build out the remainder of the /// model as there are other tests which confirm the DTO creation process. /// </summary> private List<Territory> CreateTerritories() { List<Territory> territories = new List<Territory>(); Territory territory1 = new Territory(); EntityIdSetter.SetIdOf<string>(territory1, "08837"); territory1.Description = "Edison"; territories.Add(territory1); Territory territory2 = new Territory(); EntityIdSetter.SetIdOf<string>(territory2, "00042"); territory2.Description = "Galactic"; territories.Add(territory2); return territories; }
public void CannotHaveValidTerritoryWithoutDescriptionAndRegion() { // Register the IValidator service ServiceLocatorInitializer.Init(); Territory territory = new Territory(null, null); territory.IsValid().ShouldBeFalse(); territory.ValidationResults().Count.ShouldEqual(2); territory.RegionBelongingTo = new RegionWithPublicConstructor("South"); territory.IsValid().ShouldBeFalse(); territory.ValidationResults().Count.ShouldEqual(1); territory.Description = "Wherever"; territory.IsValid().ShouldBeTrue(); }
/// <summary> /// Transfers the territory entity's property values to the DTO. /// Strongly consider Jimmy Bogard's AutoMapper (http://automapper.codeplex.com/) /// for doing this kind of work in a more automated fashion. /// </summary> public static TerritoryDto Create(Territory territory) { if (territory == null) return null; TerritoryDto territoryDto = new TerritoryDto(); territoryDto.Id = territory.Id; territoryDto.RegionBelongingTo = RegionDto.Create(territory.RegionBelongingTo); territoryDto.Description = territory.Description; foreach (Employee employee in territory.Employees) { territoryDto.Employees.Add(EmployeeDto.Create(employee)); } return territoryDto; }
protected override void LoadTestData() { Region region = new Region("Northern"); region.SetAssignedIdTo(1); regionRepository.Save(region); FlushSessionAndEvict(region); Territory territory = new Territory("Troy", region); territory.SetAssignedIdTo("48084"); territoryRepository.Save(territory); FlushSessionAndEvict(territory); Employee employee = new Employee("Joe", "Smith"); employee.Territories.Add(territory); employeeRepository.SaveOrUpdate(employee); FlushSessionAndEvict(employee); }
private Territory CreateTerritory() { Territory territory = new Territory(); EntityIdSetter.SetIdOf<string>(territory, "08837"); territory.Description = "Edison"; territory.RegionBelongingTo = new Region("Eastern"); territory.RegionBelongingTo.SetAssignedIdTo(1); Employee employee1 = new Employee(); EntityIdSetter.SetIdOf<int>(employee1, 5); territory.Employees.Add(employee1); Employee employee2 = new Employee(); EntityIdSetter.SetIdOf<int>(employee2, 10); territory.Employees.Add(employee2); return territory; }