Esempio n. 1
0
        public async Task Post_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.Post(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);
        }
        public void Post_Creates_New_Todo()
        {
            var underTests = new TodosController();

            var result = underTests.Post("I love Trump");

            Assert.True(result.Value);
        }
        public void Post_Creates_New_Todo()
        {
            var underTests = new TodosController();

            var result = underTests.Post("Hello World");

            //  Assert.True(result.Value);
        }
        public void PostTest()
        {
            Todo mockTodo      = new Todo(3, "yet another item", 3, false);
            int  initTodoCount = tc.Get().Count();
            Todo newTodo       = tc.Post(mockTodo);

            Assert.AreEqual(mockTodo, newTodo);
            Assert.AreEqual(initTodoCount + 1, tc.Get().Count());
        }
        public void Post_Increases_Todos_Count()
        {
            var underTest = new TodosController();

            underTest.Post("Foo");

            var result = underTest.Get();

            Assert.Equal(4, result.Value.Count());
        }
Esempio n. 6
0
 public void canUpdateTodo()
 {
     using (var context = new TodosContext(_options))
     {
         var c = new TodosController(new TodosRepo(context));
         var viewitem = (OkObjectResult) c.Get(1);
         var item = (Todos)viewitem.Value;
         item.Description = "updated item";
         c.Post(item);
         var updatedview = (OkObjectResult)c.Get(1);
         var updatedDesc = ((Todos)updatedview.Value).Description;
         Assert.AreEqual(item.Description, updatedDesc);
     }
 }
        public void PostStoresAndSetsDates()
        {
            //Given
            var now             = DateTime.Now;
            var todosRepository = new TestTodosRepository {
                Todos = new Dictionary <int, Todo> {
                }
            };
            var todosController = new TodosController(todosRepository);
            var todo            = new Todo {
                Id           = 5,
                TodoComments = new TodoComment[] {}
            };
            //When
            var rc = todosController.Post(todo);

            //Then
            Assert.True(1 == rc.Count(), "Count is wrong");
            Assert.True(todo.Id == rc.First().Id, "Id is wrong");
            Assert.True(now <= rc.First().CreateDate, "CreateDate should have been set");
            Assert.True(now <= rc.First().DueDate, "DueDate should have been set");
        }
Esempio n. 8
0
        public void Post()
        {
            // Arrange
            setupContext();
            TodosController controller = new TodosController(mockContext.Object);

            var dueDate = DateTime.Now;
            var todo    = new Todo
            {
                Task    = "Task1",
                DueDate = dueDate,
                Details = "Some details"
            };

            // Act
            controller.Post(todo);

            // Assert
            mockSet.Verify(m => m.Add(It.Is <Todo>(t => t.Task.Equals("Task1") &&
                                                   t.DueDate == dueDate &&
                                                   t.Details.Equals("Some details") &&
                                                   t.Completed == false)), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }