public async Task ExecuteAsync_WhenCalled_AssertIdentifierWasCalledOnCommand()
        {
            CommandHandler sut = CreateSut();

            Mock <IUpdateClientSecretIdentityCommand> commandMock = CreateCommandMock();
            await sut.ExecuteAsync(commandMock.Object);

            commandMock.Verify(m => m.Identifier, Times.Once);
        }
        public async Task ExecuteAsync_WhenCalledAndExistingClientIdentifierExists_AssertToDomainWithoutClientIdAndClientSecretWasNotCalledOnCommand()
        {
            CommandHandler sut = CreateSut();

            Mock <IUpdateClientSecretIdentityCommand> commandMock = CreateCommandMock();
            await sut.ExecuteAsync(commandMock.Object);

            commandMock.Verify(m => m.ToDomain(), Times.Never);
        }
        public async Task ExecuteAsync_WhenCalledAndExistingClientIdentifierExists_AssertClientSecretWasCalledOnExistingClientSecretIdentity()
        {
            Mock <IClientSecretIdentity> existingClientSecretIdentityMock = _fixture.BuildClientSecretIdentityMock();
            CommandHandler sut = CreateSut(existingClientSecretIdentity: existingClientSecretIdentityMock.Object);

            IUpdateClientSecretIdentityCommand command = CreateCommandMock().Object;
            await sut.ExecuteAsync(command);

            existingClientSecretIdentityMock.Verify(m => m.ClientSecret, Times.Once);
        }
        public async Task ExecuteAsync_WhenCalled_AssertGetClientSecretIdentityAsyncWasCalledOnSecurityRepository()
        {
            CommandHandler sut = CreateSut();

            int identifier = _fixture.Create <int>();
            IUpdateClientSecretIdentityCommand command = CreateCommandMock(identifier).Object;
            await sut.ExecuteAsync(command);

            _securityRepositoryMock.Verify(m => m.GetClientSecretIdentityAsync(It.Is <int>(value => value == identifier)), Times.Once);
        }
        public async Task ExecuteAsync_WhenCalledAndExistingClientIdentifierExists_AssertUpdateClientSecretIdentityAsyncWasCalledOnSecurityRepository()
        {
            CommandHandler sut = CreateSut();

            IClientSecretIdentity clientSecretIdentity = _fixture.BuildClientSecretIdentityMock().Object;
            IUpdateClientSecretIdentityCommand command = CreateCommandMock(clientSecretIdentity: clientSecretIdentity).Object;
            await sut.ExecuteAsync(command);

            _securityRepositoryMock.Verify(m => m.UpdateClientSecretIdentityAsync(It.Is <IClientSecretIdentity>(value => value == clientSecretIdentity)), Times.Once);
        }
        public void ExecuteAsync_WhenCalledAndExistingClientIdentifierDoesNotExist_ThrowsIntranetSystemException()
        {
            CommandHandler sut = CreateSut(false);

            IUpdateClientSecretIdentityCommand command = CreateCommandMock().Object;
            IntranetSystemException            result  = Assert.ThrowsAsync <IntranetSystemException>(async() => await sut.ExecuteAsync(command));

            Assert.That(result.Message.Contains("existingClientSecretIdentity"), Is.True);
            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ObjectIsNull));
            Assert.That(result.InnerException, Is.Null);
        }
        public async Task ExecuteAsync_WhenCalledAndExistingClientIdentifierExists_AssertToDomainWithClientIdAndClientSecretWasCalledOnCommand()
        {
            string clientId     = _fixture.Create <string>();
            string clientSecret = _fixture.Create <string>();
            IClientSecretIdentity existingClientSecretIdentity = _fixture.BuildClientSecretIdentityMock(clientId, clientSecret).Object;
            CommandHandler        sut = CreateSut(existingClientSecretIdentity: existingClientSecretIdentity);

            Mock <IUpdateClientSecretIdentityCommand> commandMock = CreateCommandMock();
            await sut.ExecuteAsync(commandMock.Object);

            commandMock.Verify(m => m.ToDomain(
                                   It.Is <string>(value => string.CompareOrdinal(value, clientId) == 0),
                                   It.Is <string>(value => string.CompareOrdinal(value, clientSecret) == 0)),
                               Times.Once);
        }