コード例 #1
0
        public void FindItemById()
        {
            Mock <IItemRepository> repository = new Mock <IItemRepository>();
            IItemService           subject    = new TodoApi.Services.ItemService(repository.Object);

            TodoList todoList = new TodoList();

            todoList.Name       = "TestList";
            todoList.TodoListId = 2;

            Item item = new Item();

            item.Description = "I am a description";
            item.ItemId      = 1;
            item.TodoListId  = 2;
            item.TodoList    = todoList;

            repository.Setup(repo => repo.GetById(It.IsAny <long>())).Returns(item);

            var result = subject.FindItemById(1);

            Assert.Equal("I am a description", result.Description);
            Assert.Equal(1, result.ItemId);
            Assert.Equal(2, result.TodoListId);

            Assert.Equal(todoList, result.TodoList);
        }
コード例 #2
0
        public void CannotFindTodoListWithIdReturnsNull()
        {
            Mock <IItemRepository> repository = new Mock <IItemRepository>();
            IItemService           subject    = new TodoApi.Services.ItemService(repository.Object);

            repository.Setup(repo => repo.GetById(It.IsAny <long>()));

            var result = subject.FindItemById(1);

            Assert.Null(result);
        }
コード例 #3
0
        public void ToggleCompleted_Id()
        {
            Mock <IItemRepository> repository = new Mock <IItemRepository>();
            IItemService           subject    = new TodoApi.Services.ItemService(repository.Object);

            Item item = new Item();

            item.Description = "I am a description";
            item.ItemId      = 1;
            item.IsComplete  = false;

            repository.Setup(repo => repo.GetById(It.IsAny <long>())).Returns(item);

            subject.ToggleCompleted(item.ItemId);

            Assert.Equal(true, item.IsComplete);
        }