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 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 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 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); }