public async Task CreateObjectAsync_Success_CreatedObjectReturned(Dto dto) { //Act var actualResult = await section.InsertAsync(dto); await section.DeleteAsync(actualResult.Id); //Clear database dto.Id = actualResult.Id; var expectedResult = dto.ToExpectedObject(); //Assert expectedResult.ShouldEqual(actualResult); }
public async Task DeleteObjectAsync_Success_NotFoundReturned(Dto dto) { //Arrange var temporaryCreatedObject = await section.InsertAsync(dto); //Act await section.DeleteAsync(temporaryCreatedObject.Id); Func <Task <Dto> > act = () => section.GetAsync(temporaryCreatedObject.Id); //Assert var ex = await Assert.ThrowsAsync <HttpRequestException>(act); Assert.Equal("Response status code does not indicate success: 404 (Not Found).", ex.Message); }
public async Task PatchObjectAsync_Success_PatchedObjectReturned(Dto dto, string property) { //Arrange var result = await section.InsertAsync(new Dto { Name = "TestAirlineEx3", Iata = "TSA3" }); //Act var patchedObject = await section.PatchRecordAsync(result.Id, property, dto); await section.DeleteAsync(result.Id); //Clear database var actualResult = GetPropertyValue <string>(patchedObject, property); var expectedResult = GetPropertyValue <string>(dto, property); //Assert Assert.Equal(expectedResult, actualResult); }
public async Task UpdateObjectAsync_Success_UpdatedObjectReturned(Dto dto) { //Arrange var result = await section.InsertAsync(new Dto { Name = "TestAirlineEx1", Iata = "TSA1" }); //Act var actualResult = await section.UpdateAsync(result.Id, dto); await section.DeleteAsync(actualResult.Id); //Clear database dto.Id = actualResult.Id; var expectedResult = dto.ToExpectedObject(); //Assert expectedResult.ShouldEqual(actualResult); }
public async Task CreateObjectAsync_Fail_BadRequestReturned(Dto dto) { //Act Func <Task <Dto> > act = () => section.InsertAsync(dto); //Assert var ex = await Assert.ThrowsAnyAsync <Exception>(() => { var result = act.Invoke(); if (result.Result.GetType().Equals(typeof(Dto))) { section.DeleteAsync(result.Result.Id); //Clear database return(result); } return(result); }); Assert.Equal("Response status code does not indicate success: 400 (Bad Request).", ex.InnerException.Message); }
public async Task PatchObjectAsync_Fail_BadRequestReturned(Dto dto, string property) { //Arrange var newObjectId = (await section.InsertAsync(new Dto { Name = "TestAirlineEx4", Iata = "TSA4" })).Id; //Act Func <Task <Dto> > act = () => section.PatchRecordAsync(newObjectId, property, dto); //Assert var ex = await Assert.ThrowsAnyAsync <Exception>(() => { var result = act.Invoke(); section.DeleteAsync(newObjectId); //Clear database return(result); }); Assert.Equal("Response status code does not indicate success: 400 (Bad Request).", ex.Message); }