public async Task LinkCredentialAsync_CredentialShouldNotExists() { // Arrange var userId = new UserId(); TestMock.GameCredentialRepository.Setup(repository => repository.CredentialExistsAsync(It.IsAny <UserId>(), It.IsAny <Game>())) .ReturnsAsync(true) .Verifiable(); var authFactorService = new GameCredentialService(TestMock.GameCredentialRepository.Object, TestMock.GameAuthenticationService.Object); // Act await authFactorService.LinkCredentialAsync(userId, Game.LeagueOfLegends); // Assert TestMock.GameCredentialRepository.Verify(repository => repository.CredentialExistsAsync(It.IsAny <UserId>(), It.IsAny <Game>()), Times.Once); }
public async Task LinkCredentialAsync() { // Arrange var userId = new UserId(); var userAuthFactor = new GameAuthentication <LeagueOfLegendsGameAuthenticationFactor>( new PlayerId(), new LeagueOfLegendsGameAuthenticationFactor( 1, string.Empty, 2, string.Empty)); TestMock.GameCredentialRepository.Setup(repository => repository.CredentialExistsAsync(It.IsAny <UserId>(), It.IsAny <Game>())) .ReturnsAsync(false) .Verifiable(); TestMock.GameAuthenticationService.Setup(authFactor => authFactor.AuthenticationExistsAsync(It.IsAny <UserId>(), It.IsAny <Game>())) .ReturnsAsync(true) .Verifiable(); TestMock.GameAuthenticationService.Setup(authFactor => authFactor.FindAuthenticationAsync(It.IsAny <UserId>(), It.IsAny <Game>())) .ReturnsAsync(userAuthFactor) .Verifiable(); TestMock.GameAuthenticationService .Setup( authFactor => authFactor.ValidateAuthenticationAsync( It.IsAny <UserId>(), It.IsAny <Game>(), It.IsAny <GameAuthentication <LeagueOfLegendsGameAuthenticationFactor> >())) .ReturnsAsync(new DomainValidationResult <GameAuthentication>()) .Verifiable(); TestMock.GameCredentialRepository.Setup(repository => repository.CreateCredential(It.IsAny <Credential>())).Verifiable(); TestMock.GameCredentialRepository.Setup(repository => repository.UnitOfWork.CommitAsync(It.IsAny <bool>(), It.IsAny <CancellationToken>())) .Returns(Task.CompletedTask) .Verifiable(); var authFactorService = new GameCredentialService(TestMock.GameCredentialRepository.Object, TestMock.GameAuthenticationService.Object); // Act await authFactorService.LinkCredentialAsync(userId, Game.LeagueOfLegends); // Assert TestMock.GameCredentialRepository.Verify(repository => repository.CredentialExistsAsync(It.IsAny <UserId>(), It.IsAny <Game>()), Times.Once); TestMock.GameAuthenticationService.Verify(authFactor => authFactor.AuthenticationExistsAsync(It.IsAny <UserId>(), It.IsAny <Game>()), Times.Once); TestMock.GameAuthenticationService.Verify(authFactor => authFactor.FindAuthenticationAsync(It.IsAny <UserId>(), It.IsAny <Game>()), Times.Once); TestMock.GameAuthenticationService.Verify( authFactor => authFactor.ValidateAuthenticationAsync( It.IsAny <UserId>(), It.IsAny <Game>(), It.IsAny <GameAuthentication <LeagueOfLegendsGameAuthenticationFactor> >()), Times.Once); TestMock.GameCredentialRepository.Verify(repository => repository.CreateCredential(It.IsAny <Credential>()), Times.Once); TestMock.GameCredentialRepository.Verify( repository => repository.UnitOfWork.CommitAsync(It.IsAny <bool>(), It.IsAny <CancellationToken>()), Times.Once); }