public async Task Update_Should_Return_NotFound_If_Todo_Item_Does_Not_Exist_Anymore()
    {
        // Arrange
        var context = Host.Services.GetRequiredService <DatabaseContext>();

        var user = await context.Users.Where(u => u.Email == UserConstants.DefaultUserDb.Email).FirstOrDefaultAsync();

        var todoListFromDatabase = Builder <TodoList> .CreateNew().With(tl => tl.Id = Guid.NewGuid())
                                   .With(tl => tl.CreatedBy = user.Id).Build();

        await context.TodoLists.AddAsync(todoListFromDatabase);

        await context.SaveChangesAsync();

        var updateTodoItemModel = Builder <UpdateTodoItemModel> .CreateNew()
                                  .With(cti => cti.TodoListId = todoListFromDatabase.Id).Build();

        // Act
        var apiResponse =
            await Client.PutAsync($"/api/todoItems/{Guid.NewGuid()}", new JsonContent(updateTodoItemModel));

        // Assert
        var response = JsonConvert.DeserializeObject <ApiResult <string> >(await apiResponse.Content.ReadAsStringAsync());

        apiResponse.StatusCode.Should().Be(HttpStatusCode.NotFound);
        CheckResponse.Failure(response);
    }
        public async Task ConfirmEmail_Should_Return_UnprocessableEntity_If_Token_Or_UserId_Are_Incorrect()
        {
            // Arrange
            var user = Builder <ApplicationUser> .CreateNew()
                       .With(u => u.UserName = "******")
                       .With(u => u.Email    = "*****@*****.**")
                       .Build();

            var userManager = _host.Services.GetRequiredService <UserManager <ApplicationUser> >();

            await userManager.CreateAsync(user, "Password.1!");

            var confirmEmailModel = Builder <ConfirmEmailModel> .CreateNew()
                                    .With(ce => ce.UserId = user.Id)
                                    .With(ce => ce.Token  = "InvalidToken")
                                    .Build();

            // Act
            var apiResponse = await _client.PostAsync("/api/users/confirmEmail", new JsonContent(confirmEmailModel));

            // Assert
            apiResponse.StatusCode.Should().Be(HttpStatusCode.UnprocessableEntity);
            var response = JsonConvert.DeserializeObject <ApiResult <string> >(await apiResponse.Content.ReadAsStringAsync());

            CheckResponse.Failure(response, 422);
        }
Exemple #3
0
    public async Task Update_Should_Return_BadRequest_If_Todo_List_Does_Not_Belong_To_User()
    {
        // Arrange
        var context = Host.Services.GetRequiredService <DatabaseContext>();

        var todoList = Builder <TodoList> .CreateNew()
                       .With(tl => tl.Id = Guid.NewGuid())
                       .Build();

        var todoListFromDatabase = (await context.TodoLists.AddAsync(todoList)).Entity;

        await context.SaveChangesAsync();

        var updateTodoListModel = Builder <UpdateTodoListModel> .CreateNew().Build();

        // Act
        var apiResponse = await Client.PutAsync($"/api/todoLists/{todoListFromDatabase.Id}",
                                                new JsonContent(updateTodoListModel));

        // Assert
        var response = await ResponseHelper.GetApiResultAsync <string>(apiResponse);

        var updatedTodoListFromDatabase = await context.TodoLists.Where(tl => tl.Title == updateTodoListModel.Title)
                                          .FirstOrDefaultAsync();

        apiResponse.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        CheckResponse.Failure(response);
        updatedTodoListFromDatabase.Should().NotBeNull();
        updatedTodoListFromDatabase.Title.Should().Be(todoListFromDatabase.Title);
    }
Exemple #4
0
    public async Task ChangePassword_Should_Return_BadRequest_If_OldPassword_Does_Not_Match_User_Password()
    {
        // Arrange
        var user = Builder <ApplicationUser> .CreateNew()
                   .With(u => u.UserName = "******")
                   .With(u => u.Email    = "*****@*****.**")
                   .Build();

        var userManager = Host.Services.GetRequiredService <UserManager <ApplicationUser> >();

        var createdUser = await userManager.CreateAsync(user, "Password.1!");

        var changePasswordModel = Builder <ChangePasswordModel> .CreateNew()
                                  .With(cu => cu.OldPassword = "******")
                                  .With(cu => cu.NewPassword = "******")
                                  .Build();

        // Act
        var apiResponse =
            await Client.PutAsync($"/api/users/{user.Id}/changePassword", new JsonContent(changePasswordModel));

        // Assert
        apiResponse.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        var response = await ResponseHelper.GetApiResultAsync <string>(apiResponse);

        CheckResponse.Failure(response);
    }
        public async Task ChangePassword_Should_Return_BadRequest_If_NewPassword_Does_Not_Follow_The_Rules()
        {
            // Arrange
            var user = Builder <ApplicationUser> .CreateNew()
                       .With(u => u.UserName = "******")
                       .With(u => u.Email    = "*****@*****.**")
                       .Build();

            var context = (await GetNewHostAsync()).Services.GetRequiredService <DatabaseContext>();

            var userManager = _host.Services.GetRequiredService <UserManager <ApplicationUser> >();

            var createdUser = await userManager.CreateAsync(user, "Password.1!");

            var changePasswordModel = Builder <ChangePasswordModel> .CreateNew()
                                      .With(cu => cu.OldPassword = "******")
                                      .With(cu => cu.NewPassword = "******")
                                      .Build();

            // Act
            var apiResponse = await _client.PutAsync($"/api/users/{user.Id}/changePassword", new JsonContent(changePasswordModel));

            // Assert
            apiResponse.StatusCode.Should().Be(HttpStatusCode.BadRequest);
            var response = JsonConvert.DeserializeObject <ApiResult <string> >(await apiResponse.Content.ReadAsStringAsync());

            CheckResponse.Failure(response, 400);
        }
        public async Task Delete_Should_Return_NotFound_If_Item_Does_Not_Exist_Anymore()
        {
            // Arrange

            // Act
            var apiResponse = await _client.DeleteAsync($"/api/todoItems/{Guid.NewGuid()}");

            // Assert
            var response = JsonConvert.DeserializeObject <ApiResult <string> >(await apiResponse.Content.ReadAsStringAsync());

            apiResponse.StatusCode.Should().Be(HttpStatusCode.NotFound);
            CheckResponse.Failure(response, 404);
        }
Exemple #7
0
    public async Task Delete_Should_Return_NotFound_If_Todo_List_Does_Not_Exist_Anymore()
    {
        // Arrange
        var randomId = Guid.NewGuid();

        // Act
        var apiResponse = await Client.DeleteAsync($"/api/todoLists/{randomId}");

        // Assert
        var response = await ResponseHelper.GetApiResultAsync <string>(apiResponse);

        apiResponse.StatusCode.Should().Be(HttpStatusCode.NotFound);
        CheckResponse.Failure(response);
    }
        public async Task Update_Should_Return_NotFound_If_Todo_List_Does_Not_Exist_Anymore()
        {
            // Arrange
            var updateTodoItemModel = Builder <UpdateTodoItemModel> .CreateNew().Build();

            // Act
            var apiResponse = await _client.PutAsync($"/api/todoItems/{Guid.NewGuid()}", new JsonContent(updateTodoItemModel));

            // Assert
            var response = JsonConvert.DeserializeObject <ApiResult <string> >(await apiResponse.Content.ReadAsStringAsync());

            apiResponse.StatusCode.Should().Be(HttpStatusCode.NotFound);
            CheckResponse.Failure(response, 404);
        }
Exemple #9
0
    public async Task Create_User_Should_Return_BadRequest_If_The_Email_Is_Incorrect()
    {
        // Arrange
        var createModel = Builder <CreateUserModel> .CreateNew()
                          .With(cu => cu.Email = "BadEmail")
                          .Build();

        // Act
        var apiResponse = await Client.PostAsync("/api/users", new JsonContent(createModel));

        // Assert
        apiResponse.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        var response = await ResponseHelper.GetApiResultAsync <string>(apiResponse);

        CheckResponse.Failure(response);
    }
        public async Task Create_Should_Return_Not_Found_If_Todo_List_Does_Not_Exist_Anymore()
        {
            // Arrange
            var context = _host.Services.GetRequiredService <DatabaseContext>();

            var createTodoItemModel = Builder <CreateTodoItemModel> .CreateNew().With(cti => cti.TodoListId = Guid.NewGuid()).Build();

            // Act
            var apiResponse = await _client.PostAsync("/api/todoItems", new JsonContent(createTodoItemModel));

            // Assert
            var response = JsonConvert.DeserializeObject <ApiResult <string> >(await apiResponse.Content.ReadAsStringAsync());

            apiResponse.StatusCode.Should().Be(HttpStatusCode.NotFound);
            CheckResponse.Failure(response, 404);
        }
        public async Task Create_User_Should_Return_BadRequest_If_The_Email_Is_Incorrect()
        {
            // Arrange
            var createModel = Builder <CreateUserModel> .CreateNew()
                              .With(cu => cu.Email = "BadEmail")
                              .Build();

            // Act
            var apiResponse = await _client.PostAsync("/api/users", new JsonContent(createModel));

            // Assert
            apiResponse.StatusCode.Should().Be(HttpStatusCode.BadRequest);
            var response = JsonConvert.DeserializeObject <ApiResult <string> >(await apiResponse.Content.ReadAsStringAsync());

            CheckResponse.Failure(response, 400);
        }
Exemple #12
0
    public async Task Login_Should_Return_BadRequest_If_Password_Is_Incorrect()
    {
        // Arrange
        var loginUserModel = Builder <LoginUserModel> .CreateNew()
                             .With(cu => cu.Username = UserConstants.DefaultUserDb.Username)
                             .With(cu => cu.Password = "******")
                             .Build();

        // Act
        var apiResponse = await Client.PostAsync("/api/users/authenticate", new JsonContent(loginUserModel));

        // Assert
        apiResponse.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        var response = await ResponseHelper.GetApiResultAsync <string>(apiResponse);

        CheckResponse.Failure(response);
    }
        public async Task ChangePassword_Should_Return_NotFoundException_If_User_Does_Not_Exists_In_Database()
        {
            // Arrange
            var changePasswordModel = Builder <ChangePasswordModel> .CreateNew()
                                      .With(cu => cu.OldPassword = "******")
                                      .With(cu => cu.NewPassword = "******")
                                      .Build();

            // Act
            var apiResponse = await _client.PutAsync($"/api/users/{Guid.NewGuid()}/changePassword", new JsonContent(changePasswordModel));

            // Assert
            apiResponse.StatusCode.Should().Be(HttpStatusCode.NotFound);
            var response = JsonConvert.DeserializeObject <ApiResult <string> >(await apiResponse.Content.ReadAsStringAsync());

            CheckResponse.Failure(response, 404);
        }
        public async Task Login_Should_Return_BadRequest_If_Password_Is_Incorrect()
        {
            // Arrange
            var loginUserModel = Builder <LoginUserModel> .CreateNew()
                                 .With(cu => cu.Username = "******")
                                 .With(cu => cu.Password = "******")
                                 .Build();

            // Act
            var apiResponse = await _client.PostAsync("/api/users/authenticate", new JsonContent(loginUserModel));

            // Assert
            apiResponse.StatusCode.Should().Be(HttpStatusCode.BadRequest);
            var response = JsonConvert.DeserializeObject <ApiResult <string> >(await apiResponse.Content.ReadAsStringAsync());

            CheckResponse.Failure(response, 400);
        }
        public async Task Login_Should_Return_NotFoundException_If_Username_Does_Not_Exists_In_Database()
        {
            // Arrange
            var loginUserModel = Builder <LoginUserModel> .CreateNew()
                                 .With(cu => cu.Username = "******")
                                 .With(cu => cu.Password = "******")
                                 .Build();

            // Act
            var apiResponse = await _client.PostAsync("/api/users/authenticate", new JsonContent(loginUserModel));

            // Assert
            apiResponse.StatusCode.Should().Be(HttpStatusCode.NotFound);
            var response = JsonConvert.DeserializeObject <ApiResult <string> >(await apiResponse.Content.ReadAsStringAsync());

            CheckResponse.Failure(response, 404);
        }
        public async Task Create_Should_Return_BadRequest_If_Title_Is_Incorrect()
        {
            // Arrange
            var context = _host.Services.GetRequiredService <DatabaseContext>();

            var createTodoListModel = Builder <CreateTodoListModel> .CreateNew().With(ctl => ctl.Title = "1").Build();

            // Act
            var apiResponse = await _client.PostAsync("/api/todoLists", new JsonContent(createTodoListModel));

            // Assert
            var response             = JsonConvert.DeserializeObject <ApiResult <string> >(await apiResponse.Content.ReadAsStringAsync());
            var todoListFromDatabase = await context.TodoLists.Where(tl => tl.Title == createTodoListModel.Title).FirstOrDefaultAsync();

            apiResponse.StatusCode.Should().Be(HttpStatusCode.BadRequest);
            CheckResponse.Failure(response, 400);
            todoListFromDatabase.Should().BeNull();
        }
        public async Task Update_Should_Return_NotFound_If_Todo_List_Does_Not_Exist_Anymore()
        {
            // Arrange
            var context = _host.Services.GetRequiredService <DatabaseContext>();

            var updateTodoListModel = Builder <UpdateTodoListModel> .CreateNew().With(utl => utl.Title = "UpdateTodoListIntegration").Build();

            // Act
            var apiResponse = await _client.PutAsync($"/api/todoLists/{Guid.NewGuid()}", new JsonContent(updateTodoListModel));

            // Assert
            var response = JsonConvert.DeserializeObject <ApiResult <string> >(await apiResponse.Content.ReadAsStringAsync());
            var updatedTodoListFromDatabase = await context.TodoLists.Where(tl => tl.Title == updateTodoListModel.Title).FirstOrDefaultAsync();

            apiResponse.StatusCode.Should().Be(HttpStatusCode.NotFound);
            CheckResponse.Failure(response, 404);
            updatedTodoListFromDatabase.Should().BeNull();
        }