public void PostOwner() { using (MyProfileDbContext context = new MyProfileDbContext(_dbContextOptions)) { IMapper mapper = CreateMapperConfig(); MyProfileController myProfileController = new MyProfileController(mapper, new OwnerRepository(context), new AddressRepository(context), new ContactRepository(context), new ExperienceRepository(context)); OwnerDto owner = new OwnerDto() { DateBirth = DateTime.Now, FirstName = $"Post", LastName = $"Test" }; IActionResult result = myProfileController.PostOwner(owner); CreatedAtRouteResult createdAtRouteResult = result as CreatedAtRouteResult; OwnerDto ownerDtoResult = createdAtRouteResult.Value as OwnerDto; Assert.Equal("GetOwner", createdAtRouteResult.RouteName); Assert.Equal(201, createdAtRouteResult.StatusCode); Assert.NotNull(ownerDtoResult); Assert.Equal(1, ownerDtoResult.ID); } }
public async void PutOwner() { using (MyProfileDbContext context = new MyProfileDbContext(_dbContextOptions)) { IMapper mapper = CreateMapperConfig(); MyProfileController myProfileController = new MyProfileController(mapper, new OwnerRepository(context), new AddressRepository(context), new ContactRepository(context), new ExperienceRepository(context)); for (int i = 0; i < 10; ++i) { OwnerDto owner = new OwnerDto() { DateBirth = DateTime.Now, FirstName = $"Test{i}", LastName = $"{i}Test" }; myProfileController.PostOwner(owner); } } using (MyProfileDbContext context = new MyProfileDbContext(_dbContextOptions)) { IMapper mapper = CreateMapperConfig(); MyProfileController myProfileController = new MyProfileController(mapper, new OwnerRepository(context), new AddressRepository(context), new ContactRepository(context), new ExperienceRepository(context)); IActionResult getResult = await myProfileController.GetOwner(3); OkObjectResult okResult = getResult as OkObjectResult; OwnerDto ownerDto = okResult.Value as OwnerDto; ownerDto.FirstName += "Updated"; IActionResult result = await myProfileController.PutOwner(3, ownerDto); NoContentResult noContentResult = result as NoContentResult; IActionResult updatedResult = await myProfileController.GetOwner(3); okResult = updatedResult as OkObjectResult; OwnerDto ownerDtoUpdated = okResult.Value as OwnerDto; Assert.NotNull(noContentResult); Assert.Equal(204, noContentResult.StatusCode); Assert.Equal("Test2Updated", ownerDtoUpdated.FirstName); } }
public async void DeleteOwner() { using (MyProfileDbContext context = new MyProfileDbContext(_dbContextOptions)) { IMapper mapper = CreateMapperConfig(); MyProfileController myProfileController = new MyProfileController(mapper, new OwnerRepository(context), new AddressRepository(context), new ContactRepository(context), new ExperienceRepository(context)); for (int i = 0; i < 10; ++i) { OwnerDto owner = new OwnerDto() { DateBirth = DateTime.Now, FirstName = $"Test{i}", LastName = $"{i}Test" }; myProfileController.PostOwner(owner); } } using (MyProfileDbContext context = new MyProfileDbContext(_dbContextOptions)) { IMapper mapper = CreateMapperConfig(); MyProfileController myProfileController = new MyProfileController(mapper, new OwnerRepository(context), new AddressRepository(context), new ContactRepository(context), new ExperienceRepository(context)); IActionResult result = await myProfileController.DeleteOwner(3); NoContentResult noContentResult = result as NoContentResult; IActionResult getResult = await myProfileController.GetOwners(); OkObjectResult okResult = getResult as OkObjectResult; List <OwnerDto> owners = okResult.Value as List <OwnerDto>; Assert.NotNull(noContentResult); Assert.Equal(204, noContentResult.StatusCode); Assert.Equal(9, owners.Count); } }