Beispiel #1
0
        public void Create_ReturnsViewResult()
        {
            var result     = _todosController.Create();
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Null(viewResult.ViewName);
        }
Beispiel #2
0
    public async Task Create_Is_Ok()
    {
        // Arrange
        var mockTodoService = new Mock <ITodoService>();
        var mockTodoMapper  = new Mock <ITodoModelDtoMapper>();

        _ = mockTodoService.Setup(s => s.CreateTodo(It.IsAny <TodoDto>()))
            .ReturnsAsync(new TodoDto());
        _ = mockTodoMapper.Setup(s => s.Map(It.IsAny <TodoRequestModel>()))
            .Returns(new TodoDto());
        _ = mockTodoMapper.Setup(s => s.Map(It.IsAny <TodoDto>()))
            .Returns(new TodoResponseModel());

        var controller = new TodosController(mockTodoService.Object, mockTodoMapper.Object);

        // Act
        var result = await controller.Create(It.IsAny <TodoRequestModel>());

        // Assert
        _ = result.Result.Should().BeOfType <OkObjectResult>();
        var resultObject = result.GetObjectResult();

        _ = resultObject.Should().BeOfType <TodoResponseModel>();
        _ = resultObject.Should().NotBeNull();
        mockTodoMapper.Verify(c => c.Map(It.IsAny <TodoRequestModel>()), Times.Once);
        mockTodoService.Verify(c => c.CreateTodo(It.IsAny <TodoDto>()), Times.Once);
        mockTodoMapper.Verify(c => c.Map(It.IsAny <TodoDto>()), Times.Once);
    }
Beispiel #3
0
        async Task CreateTodo()
        {
            Cli.DisplayLine("Called CreateTodo()");
            Cli.DisplayLine();
            var categories = await catCtrl.GetAll();

            var todo = new Todo();

            todo.Id          = 0;
            todo.Description = Cli.GetString("Enter description");
            todo.Due         = Cli.GetDateTime("Enter due date");
            todo.Note        = Cli.GetString("Enter note");
            Cli.DisplayLine("Categories:");
            foreach (var c in categories)
            {
                Cli.DisplayLine($" {c.Id} : {c.Name}");
            }

            todo.CategoryId = Cli.GetInt("Select category");
            var newTodo = await todoCtrl.Create(todo);

            Cli.DisplayLine();
            Cli.DisplayLine("Added ...");
            Cli.DisplayLine();
        }
Beispiel #4
0
        public void Create_ValidData_OkResult()
        {
            //Arrange
            var controller = new TodosController(_todoItemService, null, null);
            var item       = new TodoItem()
            {
                Name = "Todo 5", Priority = Priority.CRITICAL, Created = DateTime.Now, Modified = DateTime.Now
            };

            //Act
            var data = controller.Create(item);

            //Assert
            Assert.IsType <OkObjectResult>(data);
        }
Beispiel #5
0
        public void Create_InvalidData_BadRequest()
        {
            //Arrange
            var controller = new TodosController(_todoItemService, null, null);
            var item       = new TodoItem()
            {
                Priority = Priority.CRITICAL, Created = DateTime.Now, Modified = DateTime.Now
            };

            controller.ModelState.AddModelError("Name", "Name is required.");

            //Act
            var data = controller.Create(item);

            //Assert
            Assert.IsType <BadRequestObjectResult>(data);
        }