public async void CreateWorkTest( Status expectedStatus, DateTime startTime, DateTime endTime, bool withProject = false, bool withDeveloper = false ) { var developer = EntitiesFactory.NewDeveloper().Get(); var project = EntitiesFactory.NewProject(developerIds: new[] { developer.Id }).Save(); var workDto = new WorkCreateDto { DeveloperId = developer.Id, ProjectId = project.Id, StartTime = startTime, EndTime = endTime, Comment = RandomHelper.RandomString(180), Hours = 10 }; var worksPersisted = new List <Work>(); _projectRepository.Setup(p => p.ExistAsync(project.Id)).ReturnsAsync(withProject); _projectRepository.Setup(p => p.GetDeveloperProjectIdAsync(project.Id, developer.Id)) .ReturnsAsync(project.DeveloperProjects.Single().Id); _projectRepository.Setup(p => p.ExistDeveloperVinculatedAsync(project.Id, developer.Id)) .ReturnsAsync(expectedStatus != Status.NotAllowed); _developerRepository.Setup(p => p.ExistAsync(developer.Id)).ReturnsAsync(withDeveloper); _workRepository.Setup(d => d.CreateAsync(Capture.In(worksPersisted))); _mockyRepository.Setup(m => m.SendNotificationAsync(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(new Result <bool>(expectedStatus != Status.Error)); var service = new WorkService( _workRepository.Object, _developerRepository.Object, _projectRepository.Object, _mockyRepository.Object ); var result = await service.CreateWorkAsync(workDto); Assert.Equal(expectedStatus, result.Status); if (expectedStatus == Status.Success) { _workRepository.Verify(d => d.CreateAsync(It.IsAny <Work>()), Times.Once); _mockyRepository.Verify(d => d.SendNotificationAsync(It.IsAny <string>(), It.IsAny <string>()), Times.Once); var work = worksPersisted.Single(); Assert.Equal(workDto.Comment, work.Comment); Assert.Equal(workDto.StartTime, work.StartTime); Assert.Equal(workDto.EndTime, work.EndTime); Assert.Equal(workDto.Hours, work.Hours); } }