コード例 #1
0
        public void GetItemTest(bool isExists)
        {
            var rootTask = new Task {
                Id = TaskId
            };

            if (isExists)
            {
                _tasksRepositoryMock.Setup(tasksRepository => tasksRepository.Get(TaskId)).Returns(rootTask);
                _tasksRepositoryMock.Setup(tasksRepository => tasksRepository.GetAll()).Returns(Enumerable.Empty <Task>());
                // TODO: Setup mapper Mock
            }
            else
            {
                _tasksRepositoryMock.Setup(tasksRepository => tasksRepository.Get(TaskId)).Returns((Task)null);
            }

            var actualTask = _tasksService.GetItem(TaskId);

            _tasksRepositoryMock.Verify(tasksRepository => tasksRepository.Get(TaskId), Times.Once);
            if (isExists)
            {
                _tasksRepositoryMock.Verify(tasksRepository => tasksRepository.GetAll(), Times.Once);
                Assert.AreEqual(TaskId, actualTask.Id);
            }
            else
            {
                Assert.AreEqual(null, actualTask);
            }
        }