public async Task User_UpdateAsync_Return_OK()
        {
            // Arrange
            Authenticate();
            var newUser = _userBuilder.CreateUser();

            newUser.Username = "******";
            newUser.Email    = "*****@*****.**";
            StringContent postContentString = JsonSerialize.GenerateStringContent(newUser);
            var           postResponse      = await _client.PostAsync("api/user/", postContentString);

            var user = await postResponse.Content.ReadAsAsync <UserDTO>();

            user.username = "******";
            StringContent putContentString = JsonSerialize.GenerateStringContent(user);

            // Act
            var response = await _client.PutAsync($"api/user/{ user.id }/", putContentString);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var returnedUser = await response.Content.ReadAsAsync <UserDTO>();

            returnedUser.username.Should().Be("theos_sistemas");
        }
Beispiel #2
0
        public async Task Book_Remove_Without_Authentication_Return_Unauthorized()
        {
            // Arrange
            StringContent contentString = JsonSerialize.GenerateStringContent(_bookBuilder.CreateValidBook());
            // Act
            var response = await _client.DeleteAsync("api/book/0");

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
        }
        public async Task User_Update_Without_Authentication_Return_Unauthorized()
        {
            // Arrange
            StringContent contentString = JsonSerialize.GenerateStringContent(_userBuilder.CreateUser());
            // Act
            var response = await _client.PutAsync("api/user/1/", contentString);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
        }
        public async Task User_AddAsync_Return_BadRequest()
        {
            // Arrange
            Authenticate();
            StringContent contentString = JsonSerialize.GenerateStringContent(_userBuilder.CreateUserWithEmptyPassword());
            // Act
            var response = await _client.PostAsync("api/user/", contentString);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
        public async Task User_Update_With_Admin_Authentication_Not_Return_Unauthorized_or_Forbidden()
        {
            // Arrange
            Authenticate();
            StringContent contentString = JsonSerialize.GenerateStringContent(_userBuilder.CreateUser());
            // Act
            var response = await _client.PutAsync($"api/user/{ 1 }/", contentString);

            // Assert
            response.StatusCode.Should().NotBe(HttpStatusCode.Unauthorized);
            response.StatusCode.Should().NotBe(HttpStatusCode.Forbidden);
        }
Beispiel #6
0
        public async Task Book_Post_With_Admin_Authentication_Not_Return_Unauthorized_or_Forbidden()
        {
            // Arrange
            Authenticate();
            StringContent contentString = JsonSerialize.GenerateStringContent(_bookBuilder.CreateValidBook());
            // Act
            var response = await _client.PostAsync($"api/book/", contentString);

            // Assert
            response.StatusCode.Should().NotBe(HttpStatusCode.Unauthorized);
            response.StatusCode.Should().NotBe(HttpStatusCode.Forbidden);
        }
        public async Task User_UpdateAsync_Return_BadRequest()
        {
            // Arrange
            Authenticate();
            var           id            = 99999;
            StringContent contentString = JsonSerialize.GenerateStringContent(_userBuilder.CreateUser());

            // Act
            var response = await _client.PutAsync($"api/user/{ id }/", contentString);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
        public async Task Book_UpdateAsync_Return_BadRequest()
        {
            // Arrange
            Authenticate();
            var           id            = 99999;
            StringContent contentString = JsonSerialize.GenerateStringContent(_bookBuilder.CreateBookWithNonexistentId(id));

            // Act
            var response = await _client.PutAsync($"api/book/{ id }/", contentString);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
        public async Task Book_AddAsync_Return_BadRequest()
        {
            // Arrange
            Authenticate();
            var           bookDTO       = new BookDTO();
            StringContent contentString = JsonSerialize.GenerateStringContent(bookDTO);

            // Act
            var response = await _client.PostAsync("api/book/", contentString);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
Beispiel #10
0
        public async Task Login_Post()
        {
            // Arrange
            StringContent contentString = JsonSerialize.GenerateStringContent(new LoginDTO()
            {
                password = "******", username = "******"
            });
            // Act
            var response = await _client.PostAsync("api/login/", contentString);

            // Assert
            response.StatusCode.Should().NotBe(HttpStatusCode.Unauthorized);
            response.StatusCode.Should().NotBe(HttpStatusCode.Forbidden);
        }
        public async Task Book_AddAsync_Return_OK()
        {
            // Arrange
            Authenticate();
            StringContent postContentString = JsonSerialize.GenerateStringContent(_bookBuilder.CreateValidBook());

            // Act
            var postResponse = await _client.PostAsync("api/book/", postContentString);

            // Assert
            postResponse.StatusCode.Should().Be(HttpStatusCode.Created);
            var createdBook = await postResponse.Content.ReadAsAsync <BookDTO>();

            createdBook.author.Should().Be("Author from Builder");
        }
Beispiel #12
0
        public async Task Book_Stock_Update_Without_Authentication_Return_Unauthorized()
        {
            // Arrange
            var bookUpdateAmount = new BookUpdateAmountDTO();

            bookUpdateAmount.id             = 1;
            bookUpdateAmount.addToAmount    = 5;
            bookUpdateAmount.removeToAmount = 1;
            StringContent contentString = JsonSerialize.GenerateStringContent(bookUpdateAmount);
            // Act
            var response = await _client.PutAsync("api/bookstock/", contentString);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
        }
        public async Task Book_RemoveAsync_Return_Ok()
        {
            // Arrange
            Authenticate();
            StringContent postContentString = JsonSerialize.GenerateStringContent(_bookBuilder.CreateValidBook());
            var           postResponse      = await _client.PostAsync("api/book/", postContentString);

            var bookDTO = postResponse.Content.ReadAsAsync <BookDTO>().Result;

            // Act
            var response = await _client.DeleteAsync($"api/book/{ bookDTO.id }");

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
        }
        public async Task User_AddAsync_Return_OK()
        {
            // Arrange
            Authenticate();
            StringContent contentString = JsonSerialize.GenerateStringContent(_userBuilder.CreateUser());

            // Act
            var response = await _client.PostAsync("api/user/", contentString);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.Created);
            var returnedUser = await response.Content.ReadAsAsync <UserDTO>();

            returnedUser.username.Should().Be("user");
        }
        public async Task User_UpdateAsync_With_Invalid_Parameters_Return_BadRequest()
        {
            // Arrange
            Authenticate();
            StringContent contentString = JsonSerialize.GenerateStringContent(_userBuilder.CreateUser());
            var           postResponse  = await _client.PostAsync("api/user/", contentString);

            var           userDTO          = postResponse.Content.ReadAsAsync <UserDTO>().Result;
            StringContent putContentString = JsonSerialize.GenerateStringContent(userDTO);

            // Act
            var response = await _client.PutAsync("api/user/999/", putContentString);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
        public async Task Book_UpdateAsync_With_Invalid_Parameters_Return_BadRequest()
        {
            // Arrange
            Authenticate();
            StringContent postContentString = JsonSerialize.GenerateStringContent(_bookBuilder.CreateValidBook());
            var           postResponse      = await _client.PostAsync("api/book/", postContentString);

            var           bookDTO          = postResponse.Content.ReadAsAsync <BookDTO>().Result;
            StringContent putContentString = JsonSerialize.GenerateStringContent(bookDTO);

            // Act
            var response = await _client.PutAsync($"api/book/{ 9999 } /", putContentString);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
        public async Task User_GetAllAsync_Return_OK()
        {
            // Arrange
            Authenticate();
            StringContent contentString = JsonSerialize.GenerateStringContent(_userBuilder.CreateUser());
            await _client.PostAsync("api/user/", contentString);

            // Act
            var response = await _client.GetAsync("api/user");

            // Assert
            response.EnsureSuccessStatusCode();
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var returnedUsers = response.Content.ReadAsAsync <List <UserDTO> >();

            returnedUsers.Result.Count.Should().BePositive();
        }
Beispiel #18
0
        public async Task Login_Post_Return_OK()
        {
            // Arrange
            await AuthenticateAsync();

            StringContent userContentString = JsonSerialize.GenerateStringContent(new User("admin", "admin", "*****@*****.**", "admin"));
            await _client.PostAsync("api/user/", userContentString);

            StringContent loginContentString = JsonSerialize.GenerateStringContent(new LoginDTO()
            {
                password = "******", username = "******"
            });
            // Act
            var response = await _client.PostAsync("api/login/", loginContentString);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
        }
        public async Task Book_GetByIdAsync_Return_OK()
        {
            // Arrange
            Authenticate();
            StringContent contentString = JsonSerialize.GenerateStringContent(_bookBuilder.CreateValidBook());
            var           createdBook   = await _client.PostAsync("api/book/", contentString);

            var id = createdBook.Content.ReadAsAsync <BookDTO>().Result.id;

            // Act
            var response = await _client.GetAsync($"api/book/{ id }");

            // Assert
            response.EnsureSuccessStatusCode();
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var returnedBook = await response.Content.ReadAsAsync <BookDTO>();

            returnedBook.author.Should().Be("Author from Builder");
        }
        public async Task User_RemoveAsync_Return_Ok()
        {
            // Arrange
            Authenticate();
            var user = _userBuilder.CreateUser();

            user.Username = "******";
            user.Email    = "*****@*****.**";
            StringContent contentString = JsonSerialize.GenerateStringContent(user);
            var           postResponse  = await _client.PostAsync("api/user/", contentString);

            var userDTO = await postResponse.Content.ReadAsAsync <UserDTO>();

            // Act
            var response = await _client.DeleteAsync($"api/user/{ userDTO.id }");

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
        }
        public async Task Book_UpdateAsync_Return_OK()
        {
            // Arrange
            Authenticate();
            StringContent postContentString = JsonSerialize.GenerateStringContent(_bookBuilder.CreateValidBook());
            var           postResponse      = await _client.PostAsync("api/book/", postContentString);

            var bookDTO = postResponse.Content.ReadAsAsync <BookDTO>().Result;

            bookDTO.title = "titulo editado";
            StringContent putContentString = JsonSerialize.GenerateStringContent(bookDTO);

            // Act
            var response = await _client.PutAsync($"api/book/{ bookDTO.id }/", putContentString);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var returnedBook = await response.Content.ReadAsAsync <BookDTO>();

            returnedBook.title.Should().Be("titulo editado");
        }
        public async Task Book_Store_Update_Amount_Return_BadRequest()
        {
            // Arrange
            Authenticate();
            StringContent postContentString = JsonSerialize.GenerateStringContent(_bookBuilder.CreateValidBook());
            var           postResponse      = await _client.PostAsync("api/book/", postContentString);

            var bookDTO = await postResponse.Content.ReadAsAsync <BookDTO>();

            var bookUpdateAmount = new BookUpdateAmountDTO();

            bookUpdateAmount.id             = bookDTO.id;
            bookUpdateAmount.addToAmount    = -5;
            bookUpdateAmount.removeToAmount = 1;
            StringContent putContentString = JsonSerialize.GenerateStringContent(bookUpdateAmount);

            // Act
            var response = await _client.PutAsync("api/bookstock/", putContentString);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
        public async Task User_GetByIdAsync_Return_OK()
        {
            // Arrange
            Authenticate();
            var user = _userBuilder.CreateUser();

            user.Username = "******";
            user.Email    = "*****@*****.**";
            StringContent contentString = JsonSerialize.GenerateStringContent(user);
            var           createdUser   = await _client.PostAsync("api/user/", contentString);

            var userDTO = await createdUser.Content.ReadAsAsync <UserDTO>();

            // Act
            var response = await _client.GetAsync($"api/user/{ userDTO.id }");

            // Assert
            response.EnsureSuccessStatusCode();
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var returnedUsers = await response.Content.ReadAsAsync <UserDTO>();

            returnedUsers.username.Should().Be("teste_add_async");
        }