public async Task DeclineCandidatureAsync_ShouldBeOfTypeValidationResult() { // Arrange var candidature = new Candidature(new UserId(), new ClanId()); TestMock.ClanRepository.Setup(repository => repository.IsOwnerAsync(It.IsAny <ClanId>(), It.IsAny <UserId>())).ReturnsAsync(true).Verifiable(); TestMock.CandidatureRepository.Setup(repository => repository.Delete(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.DeclineCandidatureAsync(candidature, new UserId()); // Assert result.Should().BeOfType <DomainValidationResult <Candidature> >(); TestMock.ClanRepository.Verify(repository => repository.IsOwnerAsync(It.IsAny <ClanId>(), It.IsAny <UserId>()), Times.Once); TestMock.CandidatureRepository.Verify(repository => repository.Delete(It.IsAny <Candidature>()), Times.Once); TestMock.CandidatureRepository.Verify(repository => repository.UnitOfWork.CommitAsync(It.IsAny <bool>(), It.IsAny <CancellationToken>()), Times.Once); }
public async Task FetchCandidaturesAsync_WithUserId_ShouldBeOfTypeCandidatureList() { // Arrange var userId = new UserId(); TestMock.CandidatureRepository.Setup(repository => repository.FetchAsync(It.IsAny <UserId>())) .ReturnsAsync( new List <Candidature> { new Candidature(userId, new ClanId()), new Candidature(userId, new ClanId()), new Candidature(userId, new ClanId()) }) .Verifiable(); var service = new CandidatureService(TestMock.CandidatureRepository.Object, TestMock.ClanRepository.Object); // Act var result = await service.FetchCandidaturesAsync(new UserId()); // Assert result.Should().BeOfType <List <Candidature> >(); TestMock.CandidatureRepository.Verify(repository => repository.FetchAsync(It.IsAny <UserId>()), Times.Once); }
public async Task DeleteCandidaturesAsync_WithUserId() { // Arrange var userId = new UserId(); TestMock.CandidatureRepository.Setup(repository => repository.FetchAsync(It.IsAny <UserId>())) .ReturnsAsync( new List <Candidature> { new Candidature(userId, new ClanId()), new Candidature(userId, new ClanId()), new Candidature(userId, new ClanId()) }) .Verifiable(); TestMock.CandidatureRepository.Setup(repository => repository.Delete(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 await service.DeleteCandidaturesAsync(new UserId()); // Assert TestMock.CandidatureRepository.Verify(repository => repository.FetchAsync(It.IsAny <UserId>()), Times.Once); TestMock.CandidatureRepository.Verify(repository => repository.Delete(It.IsAny <Candidature>()), Times.Exactly(3)); 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); }
public async Task FindCandidatureAsync_ShouldBeOfTypeCandidature() { // Arrange TestMock.CandidatureRepository.Setup(repository => repository.FindAsync(It.IsAny <CandidatureId>())) .ReturnsAsync(new Candidature(new UserId(), new ClanId())) .Verifiable(); var service = new CandidatureService(TestMock.CandidatureRepository.Object, TestMock.ClanRepository.Object); // Act var result = await service.FindCandidatureAsync(new CandidatureId()); // Assert result.Should().BeOfType <Candidature>(); TestMock.CandidatureRepository.Verify(repository => repository.FindAsync(It.IsAny <CandidatureId>()), Times.Once); }