public async Task DivisionsWithSubDivisionsShouldBeReturned() { await RunWithinTransactionAndRollBack(async (client) => { var division1 = new CreateSubDivisionDto { Name = "Apple1", OriginalName = "Apple1", Director = "Steve Jobs", ParentDivisionId = 1 }; var division2 = new CreateSubDivisionDto { Name = "Apple2", OriginalName = "Apple2", Director = "Steve Jobs", ParentDivisionId = 1 }; var payload = Serialize(division1); await client.PostAsync("api/divisions/sub", payload); payload = Serialize(division2); await client.PostAsync("api/divisions/sub", payload); var divisionsResponse = await client.GetAsync("api/divisions/1"); var division = await DeserializeAsAsync <DivisionDto>(divisionsResponse.Content); Assert.AreEqual(2, division.SubDivisions.Count); }); }
public async Task <ActionResult <DivisionDto> > CreateSubDivision(CreateSubDivisionDto createSubDivision) { var division = this.mapper.MapTo <Division, CreateSubDivisionDto>(createSubDivision); var newDivision = await this.service.CreateSubDivision(division); var dto = this.mapper.MapTo <DivisionDto, Division>(newDivision); return(Ok(dto)); }
public async Task SubDivisionShouldBeAdded() { await RunWithinTransactionAndRollBack(async (client) => { var divisionToAdd = new CreateSubDivisionDto { Name = "New", OriginalName = "Division", Director = "John Doe", ParentDivisionId = 1 }; var payload = Serialize(divisionToAdd); var divisionAddResponse = await client.PostAsync("api/divisions/sub", payload); var division = await DeserializeAsAsync <DivisionDto>(divisionAddResponse.Content); Assert.AreEqual(divisionToAdd.Name, division.Name); Assert.AreEqual(divisionToAdd.OriginalName, division.OriginalName); Assert.AreEqual(divisionToAdd.Director, division.Director); Assert.AreEqual(1, division.ParentDivisionId); Assert.AreNotEqual(default(int), division.Id); }); }