public async Task ShouldRemoveClientSecret() { var clientSecret = EntityClientFaker.GenerateClient(clientSecrets: _faker.Random.Int(1, 3)).Generate(); var command = ClientCommandFaker.GenerateRemoveClientSecretCommand(_faker.PickRandom(clientSecret.ClientSecrets).Id).Generate(); _uow.Setup(s => s.Commit()).ReturnsAsync(true); _clientRepository.Setup(s => s.GetClient(It.Is <string>(a => a == command.ClientId))).ReturnsAsync(clientSecret); var result = await _commandHandler.Handle(command, _tokenSource.Token); result.Should().BeTrue(); }
public async Task ShouldNotAddDuplicatedClientId() { var command = ClientCommandFaker.GenerateSaveClientCommand().Generate(); _clientRepository.Setup(s => s.GetByClientId(It.Is <string>(clientId => clientId.Equals(command.Client.ClientId)))) .ReturnsAsync(EntityClientFaker.GenerateClient().Generate()); var result = await _commandHandler.Handle(command, _tokenSource.Token); result.Should().BeFalse(); _uow.Verify(v => v.Commit(), Times.Never); }
public async Task ShouldRemoveClaim() { var properties = EntityClientFaker.GenerateClient(clientClaim: _faker.Random.Int(1, 3)).Generate(); var command = ClientCommandFaker.GenerateRemoveClaimCommand(_faker.PickRandom(properties.Claims).Id).Generate(); _uow.Setup(s => s.Commit()).ReturnsAsync(true); _clientRepository.Setup(s => s.GetClient(It.Is <string>(a => a == command.ClientId))).ReturnsAsync(properties); _clientClaimRepository.Setup(s => s.Remove(It.Is <int>(a => a == command.Id))); var result = await _commandHandler.Handle(command, _tokenSource.Token); result.Should().BeTrue(); _clientRepository.Verify(s => s.GetClient(It.Is <string>(a => a == command.ClientId)), Times.Once); _clientClaimRepository.Verify(s => s.Remove(It.Is <int>(a => a == command.Id)), Times.Once); }
public async Task ShouldNotCopySecrets() { var command = ClientCommandFaker.GenerateCopyClientCommand().Generate(); var copyClient = EntityClientFaker.GenerateClient().Generate(); _clientRepository.Setup(s => s.GetByClientId(It.Is <string>(clientId => clientId.Equals(command.Client.ClientId)))) .ReturnsAsync(copyClient); _clientRepository.Setup(s => s.Add(It.Is <Client>(c => !c.ClientSecrets.Any()))); var result = await _commandHandler.Handle(command, _tokenSource.Token); result.Should().BeFalse(); }
public async Task Should_Remove_Claim_By_Type_And_Value() { var properties = EntityClientFaker.GenerateClient(clientClaim: _faker.Random.Int(1, 3)).Generate(); var randomClientSecret = _faker.PickRandom(properties.Claims); var command = ClientCommandFaker.GenerateRemoveClaimCommand(randomClientSecret.Type, randomClientSecret.Value).Generate(); _uow.Setup(s => s.Commit()).ReturnsAsync(true); _clientRepository.Setup(s => s.GetClient(It.Is <string>(a => a == command.ClientId))).ReturnsAsync(properties); _clientRepository.Setup(s => s.RemoveClaim(It.Is <string>(q => q == command.ClientId), It.Is <string>(a => a == command.Type), It.Is <string>(s => s == command.Value))); var result = await _commandHandler.Handle(command, _tokenSource.Token); result.Should().BeTrue(); _clientRepository.Verify(s => s.GetClient(It.Is <string>(a => a == command.ClientId)), Times.Once); _clientRepository.Verify(s => s.RemoveClaim(It.Is <string>(q => q == command.ClientId), It.Is <string>(a => a == command.Type), It.Is <string>(s => s == command.Value)), Times.Once); }
public async Task ShouldSaveClaim() { var command = ClientCommandFaker.GenerateSaveClaimCommand().Generate(); _clientRepository.Setup(s => s.GetByClientId(It.Is <string>(q => q == command.ClientId))).ReturnsAsync(EntityClientFaker.GenerateClient().Generate()).Verifiable(); _clientClaimRepository.Setup(s => s.Add(It.IsAny <ClientClaim>())); var result = await _commandHandler.Handle(command, _tokenSource.Token); _clientClaimRepository.Verify(s => s.Add(It.IsAny <ClientClaim>()), Times.Once); _clientRepository.Verify(s => s.GetByClientId(It.Is <string>(q => q == command.ClientId)), Times.Once); result.Should().BeFalse(); }
public async Task ShouldNotRemoveClaimWhenIdIsDifferent() { var command = ClientCommandFaker.GenerateRemoveClaimCommand().Generate(); _clientRepository.Setup(s => s.GetClient(It.Is <string>(a => a == command.ClientId))).ReturnsAsync(EntityClientFaker.GenerateClient().Generate()); var result = await _commandHandler.Handle(command, _tokenSource.Token); result.Should().BeFalse(); _clientRepository.Verify(s => s.GetClient(It.Is <string>(a => a == command.ClientId)), Times.Once); }
public async Task ShouldNotEncryptedValueBeCorrect() { var command = ClientCommandFaker.GenerateSaveClientSecretCommand().Generate(); var valueEncryptedMustBe = command.GetValue(); _clientRepository.Setup(s => s.GetByClientId(It.Is <string>(a => a == command.ClientId))).ReturnsAsync(EntityClientFaker.GenerateClient().Generate()); _clientSecretRepository.Setup(s => s.Add(It.Is <ClientSecret>(cs => cs.Value == valueEncryptedMustBe))); _uow.Setup(s => s.Commit()).ReturnsAsync(true); var result = await _commandHandler.Handle(command, _tokenSource.Token); result.Should().BeTrue(); _clientRepository.Verify(s => s.GetByClientId(It.Is <string>(a => a == command.ClientId)), Times.Once); _clientSecretRepository.Verify(s => s.Add(It.Is <ClientSecret>(cs => cs.Value == valueEncryptedMustBe)), Times.Once); _uow.Verify(s => s.Commit(), Times.Once); }
public async Task ShouldNotSaveClientSecretWhenClientDoesntExist() { var command = ClientCommandFaker.GenerateSaveClientSecretCommand().Generate(); _clientRepository.Setup(s => s.GetClient(It.Is <string>(a => a == command.ClientId))).ReturnsAsync(EntityClientFaker.GenerateClient().Generate()); var result = await _commandHandler.Handle(command, _tokenSource.Token); result.Should().BeFalse(); _clientRepository.Verify(s => s.GetByClientId(It.Is <string>(a => a == command.ClientId)), Times.Once); _uow.Verify(v => v.Commit(), Times.Never); }
public async Task ShouldRemoveClient() { var command = ClientCommandFaker.GenerateRemoveClientCommand().Generate(); _clientRepository.Setup(s => s.Remove(It.Is <Client>(a => a.ClientId == command.Client.ClientId))); _clientRepository.Setup(s => s.GetByClientId(It.Is <string>(a => a == command.Client.ClientId))).ReturnsAsync(EntityClientFaker.GenerateClient().Generate()); _uow.Setup(s => s.Commit()).ReturnsAsync(true); var result = await _commandHandler.Handle(command, _tokenSource.Token); result.Should().BeTrue(); }
public async Task ShouldUpdateClient() { var oldClientId = "my-old-client-name"; var command = ClientCommandFaker.GenerateUpdateClientCommand(oldClientId: oldClientId).Generate(); _clientRepository.Setup(s => s.UpdateWithChildrens(It.Is <Client>(a => a.ClientId == command.Client.ClientId))).Returns(Task.CompletedTask); _clientRepository.Setup(s => s.GetClient(It.Is <string>(a => a == oldClientId))).ReturnsAsync(EntityClientFaker.GenerateClient().Generate()); _uow.Setup(s => s.Commit()).ReturnsAsync(true); var result = await _commandHandler.Handle(command, _tokenSource.Token); _clientRepository.Verify(s => s.UpdateWithChildrens(It.IsAny <Client>()), Times.Once); _clientRepository.Verify(s => s.GetClient(It.Is <string>(q => q == oldClientId)), Times.Once); result.Should().BeTrue(); }
public async Task ShouldNotRemoveSecretWhenSecretIdIsDifferent() { var command = ClientCommandFaker.GenerateRemoveClientSecretCommand().Generate(); _clientRepository.Setup(s => s.GetClient(It.Is <string>(a => a == command.ClientId))).ReturnsAsync(EntityClientFaker.GenerateClient().Generate()); var result = await _commandHandler.Handle(command, _tokenSource.Token); Assert.False(result); _uow.Verify(v => v.Commit(), Times.Never); }
public async Task ShouldUpdateClient() { var command = ClientCommandFaker.GenerateUpdateClientCommand().Generate(); _clientRepository.Setup(s => s.UpdateWithChildrens(It.Is <Client>(a => a.ClientId == command.Client.ClientId))).Returns(Task.CompletedTask); _clientRepository.Setup(s => s.GetClient(It.Is <string>(a => a == command.Client.ClientId))).ReturnsAsync(EntityClientFaker.GenerateClient().Generate()); _uow.Setup(s => s.Commit()).Returns(true); var result = await _commandHandler.Handle(command, _tokenSource.Token); Assert.True(result); }