Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }