public async System.Threading.Tasks.Task AddProjectAttendant_GivenExistingProjectIdAndAttendantIds_ShouldAddAttendantToProject() { var parameters = new PersonInProjectParameterDto { ProjectId = Guid.NewGuid(), AttendantIds = new Guid[] { Guid.NewGuid() } }; mockProjectRepository.Setup(x => x.GetSingleByCondition(It.IsAny <Expression <Func <Project, bool> > >())) .ReturnsAsync(mockProject); mockPersonRepository.Setup(x => x.GetSingleByCondition(It.IsAny <Expression <Func <Person, bool> > >())) .ReturnsAsync(mockPerson); mockPersonInProjectRepository.Setup(s => s.Create(It.IsAny <Domain.Entities.PersonInProject>())) .Returns(System.Threading.Tasks.Task.CompletedTask); mockPersonInProjectRepository.Setup(s => s.SaveChanges()) .ReturnsAsync(true); var personInProjectService = new PersonInProjectService(mapper, mockPersonInProjectRepository.Object, mockPersonRepository.Object, mockProjectRepository.Object); var result = await personInProjectService.AddProjectAttendant(parameters); mockProjectRepository.Verify(v => v.GetSingleByCondition(It.IsAny <Expression <Func <Project, bool> > >()), Times.Once); mockPersonRepository.Verify(v => v.GetSingleByCondition(It.IsAny <Expression <Func <Person, bool> > >()), Times.AtLeastOnce); mockPersonInProjectRepository.Verify(v => v.SaveChanges(), Times.Once); Assert.IsTrue(result); }
public async System.Threading.Tasks.Task AddProjectAttendant_GivenAnUnexistingProjectId_ShouldntAddNewAttendantAndReturnFalse() { var parameters = new PersonInProjectParameterDto { ProjectId = Guid.NewGuid(), AttendantIds = new Guid[] { Guid.NewGuid() } }; mockProjectRepository.Setup(x => x.GetSingleByCondition(It.IsAny <Expression <Func <Project, bool> > >())) .Returns(System.Threading.Tasks.Task.FromResult <Project>(null)); var personInProjectService = new PersonInProjectService(mapper, mockPersonInProjectRepository.Object, mockPersonRepository.Object, mockProjectRepository.Object); var result = await personInProjectService.AddProjectAttendant(parameters); mockProjectRepository.Verify(v => v.GetSingleByCondition(It.IsAny <Expression <Func <Project, bool> > >()), Times.Once); Assert.IsFalse(result); }