public async Task GenerateAuthFactorAsync() { // Arrange var userId = new UserId(); var game = Game.LeagueOfLegends; TestMock.AuthenticationGeneratorAdapter.SetupGet(authenticationGeneratorAdapter => authenticationGeneratorAdapter.Game).Returns(game); TestMock.GameAuthenticationGeneratorFactory.Setup(generator => generator.CreateInstance(It.IsAny <Game>())) .Returns(TestMock.AuthenticationGeneratorAdapter.Object) .Verifiable(); var authFactorService = new GameAuthenticationService( TestMock.GameAuthenticationGeneratorFactory.Object, TestMock.GameAuthenticationValidatorFactory.Object, TestMock.GameAuthenticationRepository.Object); // Act await authFactorService.GenerateAuthenticationAsync( userId, Game.LeagueOfLegends, JObject.Parse(JsonConvert.SerializeObject(new LeagueOfLegendsRequest("Test")))); // Assert TestMock.GameAuthenticationGeneratorFactory.Verify(generator => generator.CreateInstance(It.IsAny <Game>()), Times.Once); }
public async Task FindAuthFactorAsync() { // Arrange var userId = new UserId(); var authFactor = new GameAuthentication <LeagueOfLegendsGameAuthenticationFactor>( new PlayerId(), new LeagueOfLegendsGameAuthenticationFactor( 1, string.Empty, 2, string.Empty)); TestMock.GameAuthenticationRepository .Setup(repository => repository.GetAuthenticationAsync <LeagueOfLegendsGameAuthenticationFactor>(It.IsAny <UserId>(), It.IsAny <Game>())) .ReturnsAsync(authFactor) .Verifiable(); var authFactorService = new GameAuthenticationService( TestMock.GameAuthenticationGeneratorFactory.Object, TestMock.GameAuthenticationValidatorFactory.Object, TestMock.GameAuthenticationRepository.Object); // Act await authFactorService.FindAuthenticationAsync <LeagueOfLegendsGameAuthenticationFactor>(userId, Game.LeagueOfLegends); // Assert TestMock.GameAuthenticationRepository.Verify( repository => repository.GetAuthenticationAsync <LeagueOfLegendsGameAuthenticationFactor>(It.IsAny <UserId>(), It.IsAny <Game>()), Times.Once); }
public async Task AuthFactorExistsAsync() { // Arrange var userId = new UserId(); TestMock.GameAuthenticationRepository.Setup(repository => repository.AuthenticationExistsAsync(It.IsAny <UserId>(), It.IsAny <Game>())) .ReturnsAsync(true) .Verifiable(); var authFactorService = new GameAuthenticationService( TestMock.GameAuthenticationGeneratorFactory.Object, TestMock.GameAuthenticationValidatorFactory.Object, TestMock.GameAuthenticationRepository.Object); // Act await authFactorService.AuthenticationExistsAsync(userId, Game.LeagueOfLegends); // Assert TestMock.GameAuthenticationRepository.Verify(repository => repository.AuthenticationExistsAsync(It.IsAny <UserId>(), It.IsAny <Game>()), Times.Once); }
public async Task ValidateAuthFactorAsync() { // Arrange var authFactor = new GameAuthentication <LeagueOfLegendsGameAuthenticationFactor>( new PlayerId(), new LeagueOfLegendsGameAuthenticationFactor( 1, string.Empty, 2, string.Empty)); var summoner = new Summoner { ProfileIconId = 1 }; TestMock.LeagueOfLegendsService.Setup(x => x.Summoner.GetSummonerByAccountIdAsync(It.IsAny <Region>(), It.IsAny <string>())) .ReturnsAsync(summoner) .Verifiable(); var leagueAdapter = new LeagueOfLegendsAuthenticationValidatorAdapter( TestMock.LeagueOfLegendsService.Object, TestMock.GameAuthenticationRepository.Object); TestMock.GameAuthenticationValidatorFactory.Setup(validator => validator.CreateInstance(It.IsAny <Game>())).Returns(leagueAdapter).Verifiable(); var authFactorService = new GameAuthenticationService( TestMock.GameAuthenticationGeneratorFactory.Object, TestMock.GameAuthenticationValidatorFactory.Object, TestMock.GameAuthenticationRepository.Object); // Act await authFactorService.ValidateAuthenticationAsync(new UserId(), Game.LeagueOfLegends, authFactor); // Assert TestMock.GameAuthenticationValidatorFactory.Verify(validator => validator.CreateInstance(It.IsAny <Game>()), Times.Once); }