コード例 #1
0
        public async Task UpdateApiTest()
        {
            //arrange
            var user = new ReqresUserBuilder().HasNonEnglishUnicodeCharacter().Build();

            UserResponse createdUserResponse = null;

            try
            {
                createdUserResponse = await Reqres.CreateUserAsync(user);

                Assert.That(createdUserResponse.StatusCode, Is.EqualTo(HttpStatusCode.Created), "Status code was wrong.  Expected Created but was {0}", createdUserResponse.StatusCode);

                // act
                user.LastName = user.LastName + "123";
                var updatedUserResponse = await Reqres.UpdateUserAsync(createdUserResponse.User.Id, user);

                // assert
                Assert.That(updatedUserResponse.StatusCode, Is.EqualTo(HttpStatusCode.OK), "Status code was wrong.  Expected OK but was {0}", updatedUserResponse.StatusCode);
                Assert.That(updatedUserResponse.User.LastName, Is.EqualTo(user.LastName), "last name was wrong");
                Assert.That(updatedUserResponse.User.FirstName, Is.EqualTo(user.FirstName), "first name was wrong");
            }
            finally
            {
                // clean up
                if (createdUserResponse != null)
                {
                    await Reqres.DeleteUserAsync(createdUserResponse.User.Id);
                }
            }
        }
コード例 #2
0
        public async Task CreateApiTest()
        {
            // arrange
            var user = new ReqresUserBuilder().HasNonEnglishUnicodeCharacter().Build();

            UserResponse createdUserResponse = null;

            try
            {
                // act
                createdUserResponse = await Reqres.CreateUserAsync(user);

                // assert
                Assert.That(createdUserResponse.StatusCode, Is.EqualTo(HttpStatusCode.Created), "Status code was wrong.  Expected OK but was {0}", createdUserResponse.StatusCode);
                Assert.That(createdUserResponse.User.FirstName, Is.EqualTo(user.FirstName), "createdUserResponse.first_name was wrong.");
                Assert.That(createdUserResponse.User.Id, Is.Not.EqualTo(user.Id), "createdUserResponse.id was not set.");
            }
            finally
            {
                // clean up
                if (createdUserResponse != null)
                {
                    await Reqres.DeleteUserAsync(createdUserResponse.User.Id);
                }
            }
        }
コード例 #3
0
        public async Task DeleteApiTest()
        {
            // arrange
            var user = new ReqresUserBuilder().HasNonEnglishUnicodeCharacter().Build();

            var createdUserResponse = await Reqres.CreateUserAsync(user);

            Assert.That(createdUserResponse.StatusCode, Is.EqualTo(HttpStatusCode.Created), "Status code was wrong.  Expected Created but was {0}", createdUserResponse.StatusCode);

            // act
            var deletedUserResponse = await Reqres.DeleteUserAsync(createdUserResponse.User.Id);

            // assert
            Assert.That(deletedUserResponse.StatusCode, Is.EqualTo(HttpStatusCode.NotFound), "Status code was wrong.  Expected 404 Not Found but was {0}", deletedUserResponse.StatusCode);

            var userResponse = await Reqres.GetUserAsync(createdUserResponse.User.Id);

            Assert.That(userResponse.StatusCode, Is.EqualTo(HttpStatusCode.NotFound), "Status code was wrong.  Expected 404 Not Found but was {0}", userResponse.StatusCode);
        }