public async Task SendCandidatureAsync_ShouldBeOfTypeValidationResult() { // Arrange TestMock.ClanRepository.Setup(repository => repository.IsMemberAsync(It.IsAny <UserId>())).ReturnsAsync(false).Verifiable(); TestMock.CandidatureRepository.Setup(repository => repository.ExistsAsync(It.IsAny <UserId>(), It.IsAny <ClanId>())).ReturnsAsync(false).Verifiable(); TestMock.CandidatureRepository.Setup(repository => repository.Create(It.IsAny <Candidature>())).Verifiable(); TestMock.CandidatureRepository.Setup(repository => repository.UnitOfWork.CommitAsync(It.IsAny <bool>(), It.IsAny <CancellationToken>())) .Returns(Task.CompletedTask) .Verifiable(); var service = new CandidatureService(TestMock.CandidatureRepository.Object, TestMock.ClanRepository.Object); // Act var result = await service.SendCandidatureAsync(new UserId(), new ClanId()); // Assert result.Should().BeOfType <DomainValidationResult <Candidature> >(); TestMock.ClanRepository.Verify(repository => repository.IsMemberAsync(It.IsAny <UserId>()), Times.Once); TestMock.CandidatureRepository.Verify(repository => repository.ExistsAsync(It.IsAny <UserId>(), It.IsAny <ClanId>()), Times.Once); TestMock.CandidatureRepository.Verify(repository => repository.Create(It.IsAny <Candidature>()), Times.Once); TestMock.CandidatureRepository.Verify(repository => repository.UnitOfWork.CommitAsync(It.IsAny <bool>(), It.IsAny <CancellationToken>()), Times.Once); }
public async Task SendCandidatureAsync_WhenIsMember_ShouldBeOfTypeValidationResultWithErrors() { // Arrange TestMock.ClanRepository.Setup(repository => repository.IsMemberAsync(It.IsAny <UserId>())).ReturnsAsync(true).Verifiable(); var service = new CandidatureService(TestMock.CandidatureRepository.Object, TestMock.ClanRepository.Object); // Act var result = await service.SendCandidatureAsync(new UserId(), new ClanId()); // Assert result.Should().BeOfType <DomainValidationResult <Candidature> >(); result.Errors.Should().NotBeEmpty(); TestMock.ClanRepository.Verify(repository => repository.IsMemberAsync(It.IsAny <UserId>()), Times.Once); }