public void EditTodoViewModel_AllFieldsValid_NoErrors()
        {
            // Arrange
            var model = MockEditTodoViewModel.Get(1);

            // Act
            var validation = ModelValidator.ValidateModel(model);

            // Assert
            Assert.Equal(0, validation.Count);
        }
Example #2
0
        public void TodoViewModelEdit_Getter_Matches()
        {
            // Arrange
            var viewModel = MockEditTodoViewModel.Get(0);

            // Act
            var todo = MockTodos.Get(3);

            todo.Edit(viewModel);

            // Assert
            Assert.Equal(viewModel.Id, todo.Id);
            Assert.Equal(viewModel.Due, todo.Due);
            Assert.Equal(viewModel.Description, todo.Description);
        }
        public void EditTodoViewModel_Setter_Modifies()
        {
            // Arrange
            var viewModel = MockEditTodoViewModel.Get(1);

            // Act
            viewModel.Id          = 1551;
            viewModel.Description = "Make Love, Not Warcraft";
            viewModel.Due         = new DateTime(2022, 1, 1, 12, 25, 0);

            // Assert
            Assert.Equal(1551, viewModel.Id);
            Assert.Equal("Make Love, Not Warcraft", viewModel.Description);
            Assert.Equal(new DateTime(2022, 1, 1, 12, 25, 0), viewModel.Due);
        }
Example #4
0
        public async Task Edit_NoToken_Unauthorized()
        {
            // Arrange
            var model = MockEditTodoViewModel.Get(0);
            var body  = JsonStringBuilder.EditTodoJsonBody(
                model.Description, model.Due.ToString(), model.Id.ToString());
            var          content = new StringContent(body);
            const string path    = Routes.TodoRoute;

            // Act
            var response = await _endSystems.Put(path, content);

            // Assert
            Assert.Equal(HttpStatusCode.Unauthorized, response.Code);

            // Tear down
            _endSystems.Dispose();
        }
        public async Task EditTodo_ValidUserAndTodo_Ok()
        {
            // Arrange
            var service = new MockTodoService
            {
                MEditTodoAsync = (model, userId) => { }
            };
            var controller = new TodoController(service);

            MockClaims.AddUserIdClaim(controller, MockApplicationUsers.Get(0).Id);

            // Act
            var result = await controller.EditTodo(MockEditTodoViewModel.Get(0)) as OkResult;

            // Assert
            Assert.NotNull(result);
            Assert.Equal(200, result.StatusCode);
        }
        public async Task EditTodo_InvalidTodo_TodoNotFoundException()
        {
            // Arrange
            var service = new MockTodoService
            {
                MEditTodoAsync = (model, userId) => throw new TodoNotFoundException()
            };
            var controller = new TodoController(service);

            MockClaims.AddUserIdClaim(controller, MockApplicationUsers.Get(0).Id);

            // Act
            var result = await controller.EditTodo(MockEditTodoViewModel.Get(0)) as NotFoundResult;

            // Assert
            Assert.NotNull(result);
            Assert.Equal(404, result.StatusCode);
        }
        public async Task EditTodo_InvalidModel_BadRequest()
        {
            // Arrange
            const string field        = "required";
            const string errorMessage = "something is required";
            var          service      = new MockTodoService();
            var          controller   = new TodoController(service);

            controller.ModelState.AddModelError(field, errorMessage);
            var model = MockEditTodoViewModel.Get(0);

            // Act
            var result = await controller.EditTodo(model) as BadRequestObjectResult;

            var error = result?.Value as SerializableError;

            // Assert
            Assert.NotNull(error);
            Assert.Equal(400, result.StatusCode);
            Assert.Single(error.Keys);
            Assert.True(error.ContainsKey(field));
            Assert.Equal(new[] { errorMessage }, error.GetValueOrDefault(field));
        }