Example #1
0
 public void canAddTodo()
 {
     using (var context = new TodosContext(_options))
     {
         var c = new TodosController(new TodosRepo(context));
         var list = c.Get();
         var newid = list.Last().ID + 1;
         var newitem = new Todos { ID = newid, Description = $"New item {newid}", IsComplete = false };
         c.Put(newid, newitem);
         int newcount = c.Get().Count();
         Assert.AreEqual(newid, newcount);
     }
 }
Example #2
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);
     }
 }
Example #3
0
    public async Task Get_All_Is_Ok()
    {
        // Arrange
        var mockTodoService = new Mock <ITodoService>();
        var mockTodoMapper  = new Mock <ITodoModelDtoMapper>();

        _ = mockTodoService.Setup(s => s.GetTodos())
            .ReturnsAsync(new List <TodoDto> {
            new TodoDto()
        }.AsEnumerable());
        _ = mockTodoMapper.Setup(s => s.Map(It.IsAny <List <TodoDto> >()))
            .Returns(new List <TodoResponseModel> {
            new TodoResponseModel()
        }.AsEnumerable());

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

        // Act
        var result = await controller.Get();

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

        _ = resultObject.Should().BeOfType <List <TodoResponseModel> >();
        _ = resultObject.Should().HaveCount(1);

        mockTodoService.Verify(c => c.GetTodos(), Times.Once);
        mockTodoMapper.Verify(c => c.Map(It.IsAny <List <TodoDto> >()), Times.Once);
    }
Example #4
0
    public async Task Get_Is_Ok()
    {
        // Arrange
        var mockTodoService = new Mock <ITodoService>();
        var mockTodoMapper  = new Mock <ITodoModelDtoMapper>();

        _ = mockTodoService.Setup(s => s.GetTodo(It.IsAny <Guid>()))
            .ReturnsAsync(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.Get(It.IsAny <Guid>());

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

        _ = resultObject.Should().BeOfType <TodoResponseModel>();
        _ = resultObject.Should().NotBeNull();
        mockTodoService.Verify(c => c.GetTodo(It.IsAny <Guid>()), Times.Once);
        mockTodoMapper.Verify(c => c.Map(It.IsAny <TodoDto>()), Times.Once);
    }
Example #5
0
        public async Task Get_by_id_should_return_a_valid_todo()
        {
            var expectedTodo = DataFactories.TodosFactory.CreateTodo(
                DataFactories.TodosFactory.CreateId(),
                DataFactories.TodosFactory.CreateId(),
                DataFactories.TodosFactory.CreateRandomLorem(20),
                true
                );

            var todoClientMock = new Mock <ITypecodeTodoClient>();

            todoClientMock
            .Setup(client => client.Get(It.IsAny <int>()))
            .ReturnsAsync(expectedTodo);

            var controller = new TodosController(todoClientMock.Object);

            var result = await controller.Get(1) as ObjectResult;

            Assert.IsNotNull(result.Value);

            var actualTodo = result.Value as Todo;

            Assert.AreEqual(expectedTodo.Id, actualTodo.Id);
            Assert.AreEqual(expectedTodo.UserId, actualTodo.UserId);
            Assert.AreEqual(expectedTodo.Title, actualTodo.Title);
            Assert.AreEqual(expectedTodo.Completed, actualTodo.Completed);
        }
        public void Todos_CanGetAllTodos()
        {
            // Arrange
            var todoServiceMock = new Mock <TodosService>();
            var todo            = new Todo {
                Id = 1, Title = "Mocked todo"
            };

            todoServiceMock.Setup(s => s.GetAll())
            .Returns(new List <Todo> {
                todo
            })
            .Verifiable();
            var ctrl = new TodosController(todoServiceMock.Object);

            // Act
            var result = ctrl.Get() as ActionResult <List <Todo> >;
            var data   = result.Value as IEnumerable <Todo>;

            // Assert
            Assert.NotNull(data);
            Assert.True(data.Any());
            Assert.Equal(data.First().Title, todo.Title);
            todoServiceMock.Verify();
        }
        public void GET_Returns_List_Of_Todos()
        {
            var underTest = new TodosController();

            var result = underTest.Get();

            Assert.Equal(3, result.Value.Count());
        }
Example #8
0
 public void canGetListfromController()
 {
     using (var context = new TodosContext(_options))
     {
         var c = new TodosController(new TodosRepo(context));
         var list = c.Get();
         Assert.AreEqual(1, list.Count());
     }
 }
Example #9
0
 public void CanDeleteTodo()
 {
     using (var context = new TodosContext(_options))
     {
         var c = new TodosController(new TodosRepo(context));
         var viewitem = c.Delete(2);
         var item = c.Get(2);
         Assert.True(item is NotFoundResult);
     }
 }
        public void Post_Increases_Todos_Count()
        {
            var underTest = new TodosController();

            underTest.Post("Foo");

            var result = underTest.Get();

            Assert.Equal(4, result.Value.Count());
        }
Example #11
0
        public void Get_Empty_Todos_List()
        {
            const int USER_ID         = 1;;
            var       initialTodos    = new Dictionary <int, IEnumerable <Todo> >();
            var       todosRepository = new InMemoryTodosRepository(initialTodos);
            var       sut             = new TodosController(todosRepository);

            var result = sut.Get(USER_ID);

            result.Result.Should().BeEmpty();
        }
Example #12
0
        public void Get()
        {
            // Arrange
            setupContext();
            TodosController controller = new TodosController(mockContext.Object);

            // Act
            IEnumerable <Todo> result = controller.Get();

            // Assert
            Assert.AreEqual(result.Count(), 3);
        }
Example #13
0
 public void TestTodosController()
 {
     using (var ctx = new mosheaContext(_options)) {
         var c = new TodosController(ctx);
         ctx.Todos.Add(new Todos {
             Id = 1, Description = "test", Iscomplete = false
         });
         ctx.SaveChanges();
         var all = c.Get();
         Assert.AreEqual(1, all.Count());
         Assert.AreEqual("test", all.ToList()[0].Description);
     }
 }
        public void GetTest()
        {
            List <Todo> todos = (List <Todo>)tc.Get();

            for (int i = 0; i < mockTodos.Count; i++)
            {
                Assert.AreEqual(mockTodos[i], todos[i]);
            }
        }
Example #15
0
        public void Get_Todos_List()
        {
            const int          USER_ID = 1;
            IEnumerable <Todo> todos   = new [] { new Todo()
                                                  {
                                                      Id = 1
                                                  } };
            var initialTodos = new Dictionary <int, IEnumerable <Todo> >()
            {
                { USER_ID, todos }
            };
            var todosRepository = new InMemoryTodosRepository(initialTodos);
            var sut             = new TodosController(todosRepository);

            var result = sut.Get(USER_ID);

            result.Result.Should().NotBeEmpty()
            .And.HaveCount(1)
            .And.BeEquivalentTo(new { Id = 1 });
        }
        public void GetAllReturnsAll()
        {
            //Given
            var todosRepository = new TestTodosRepository {
                Todos = new Dictionary <int, Todo> {
                    { 1, new Todo {
                          Id = 1
                      } },
                    { 2, new Todo {
                          Id = 2
                      } }
                }
            };
            var todosController = new TodosController(todosRepository);
            //When
            var rc = todosController.Get();

            //Then
            Assert.Equal(2, rc.Count());
        }
Example #17
0
        public async Task Get_Is_NotFound()
        {
            // Arrange
            var mockTodoService = new Mock <ITodoService>();
            var mockTodoMapper  = new Mock <ITodoModelDtoMapper>();

            mockTodoService.Setup(s => s.GetTodo(It.IsAny <Guid>()))
            .ReturnsAsync((TodoDto)null);
            mockTodoMapper.Setup(s => s.Map(It.IsAny <TodoDto>()))
            .Returns(new TodoResponseModel());

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

            // Act
            var result = await controller.Get(It.IsAny <Guid>());

            // Assert
            result.Result.Should().BeOfType <NotFoundObjectResult>();
            mockTodoService.Verify(c => c.GetTodo(It.IsAny <Guid>()), Times.Once);
            mockTodoMapper.Verify(c => c.Map(It.IsAny <TodoDto>()), Times.Never);
        }
        public void GetReturnsOneAndTheRightOne(int value)
        {
            //Given
            var todosRepository = new TestTodosRepository {
                Todos = new Dictionary <int, Todo> {
                    { 1, new Todo {
                          Id = 1
                      } },
                    { value, new Todo {
                          Id = value
                      } },
                    { 2, new Todo {
                          Id = 2
                      } }
                }
            };
            var todosController = new TodosController(todosRepository);
            //When
            var rc = todosController.Get(value);

            //Then
            Assert.Equal(1, rc.Count());
            Assert.Equal(value, rc.First().Id);
        }
        public void PutStores()
        {
            //Given
            var createDate      = DateTime.Now.ToUniversalTime().Subtract(TimeSpan.FromDays(1.0));
            var todosRepository = new TestTodosRepository {
                Todos = new Dictionary <int, Todo> {
                    { 5, new Todo {
                          Id = 5, Task = "ZZZZ", CreateDate = createDate
                      } }
                }
            };
            var todosController = new TodosController(todosRepository);
            var todo            = todosController.Get(5).First();

            todo.Task = "Task";
            //When
            var rc = todosController.Put(todo);

            //Then
            Assert.True(1 == rc.Count(), "Count is wrong");
            Assert.True(todo.Id == rc.First().Id, "Id is wrong");
            Assert.True(createDate == todo.CreateDate, "CreateDate should not have changed");
            Assert.True("Task" == rc.First().Task, "Task is not correct - was the Put todo stored?");
        }
Example #20
0
        public void It_should_return_a_non_empty_list()
        {
            var result = _sut.Get();

            Assert.That(result, Is.Not.Empty);
        }