Exemplo n.º 1
0
        public async Task CreateAsync_DepartmentValidationFailed_ThrowsError()
        {
            // Arrange
            var fixture  = new Fixture();
            var task     = new TaskUpdateModel();
            var expected = fixture.Create <string>();

            var categoryGetService = new Mock <ICategoryGetService>();

            categoryGetService
            .Setup(x => x.ValidateAsync(task))
            .Throws(new InvalidOperationException(expected));

            var taskDataAccess = new Mock <ITaskDataAccess>();

            var taskGetService = new TaskCreateService(taskDataAccess.Object, categoryGetService.Object);

            // Act
            var action = new Func <Task>(() => taskGetService.CreateAsync(task));

            // Assert
            await action.Should().ThrowAsync <InvalidOperationException>().WithMessage(expected);

            taskDataAccess.Verify(x => x.InsertAsync(task), Times.Never);
        }
Exemplo n.º 2
0
        public async Task CreateAsync_DepartmentValidationSucceed_CreatesTask()
        {
            // Arrange
            var task     = new TaskUpdateModel();
            var expected = new Domain.Task();

            var categoryGetService = new Mock <ICategoryGetService>();

            categoryGetService.Setup(x => x.ValidateAsync(task));

            var taskDataAccess = new Mock <ITaskDataAccess>();

            taskDataAccess.Setup(x => x.InsertAsync(task)).ReturnsAsync(expected);

            var taskGetService = new TaskCreateService(taskDataAccess.Object, categoryGetService.Object);

            // Act
            var result = await taskGetService.CreateAsync(task);

            // Assert
            result.Should().Be(expected);
        }