public async Task ExecuteAsync_WhenCalledAndNoCreatedContactWasReturnedFromMicrosoftGraphRepository_AssertCreateOrUpdateContactSupplementAsyncWasNotCalledOnContactRepository()
        {
            CommandHandler sut = CreateSut(false);

            ICreateContactCommand command = CreateCreateContactCommandMock().Object;
            await sut.ExecuteAsync(command);

            _contactRepositoryMock.Verify(m => m.CreateOrUpdateContactSupplementAsync(It.IsAny <IContact>(), It.IsAny <string>()), Times.Never);
        }
        public async Task ExecuteAsync_WhenCalledAndNoCreatedContactWasReturnedFromMicrosoftGraphRepository_AssertExternalIdentifierSetterWasNotCalledOnContactFromToDomainOnCommand()
        {
            CommandHandler sut = CreateSut(false);

            Mock <IContact>       contactMock = _fixture.BuildContactMock();
            ICreateContactCommand command     = CreateCreateContactCommandMock(contact: contactMock.Object).Object;
            await sut.ExecuteAsync(command);

            contactMock.VerifySet(m => m.ExternalIdentifier = It.IsAny <string>(), Times.Never);
        }
        public async Task ExecuteAsync_WhenCalledAndNoCreatedContactWasReturnedFromMicrosoftGraphRepository_AssertExternalIdentifierWasNotCalledOnCreatedContactFromMicrosoftGraphRepository()
        {
            Mock <IContact> createdMicrosoftGraphContactMock = _fixture.BuildContactMock();
            CommandHandler  sut = CreateSut(false, createdMicrosoftGraphContactMock.Object);

            ICreateContactCommand command = CreateCreateContactCommandMock().Object;
            await sut.ExecuteAsync(command);

            createdMicrosoftGraphContactMock.Verify(m => m.ExternalIdentifier, Times.Never);
        }
        public async Task ExecuteAsync_WhenCalledAndCreatedContactWasReturnedFromMicrosoftGraphRepository_AssertCreateOrUpdateContactSupplementAsyncWasCalledOnContactRepositoryWithContactFromToDomainOnCommand()
        {
            CommandHandler sut = CreateSut();

            IContact contact = _fixture.BuildContactMock().Object;
            ICreateContactCommand command = CreateCreateContactCommandMock(contact: contact).Object;
            await sut.ExecuteAsync(command);

            _contactRepositoryMock.Verify(m => m.CreateOrUpdateContactSupplementAsync(It.Is <IContact>(value => value == contact), It.Is <string>(value => value == null)), Times.Once);
        }
        public async Task ExecuteAsync_WhenCalled_AssertToDomainWasCalledOnCommand()
        {
            CommandHandler sut = CreateSut();

            Mock <ICreateContactCommand> commandMock = CreateCreateContactCommandMock();
            await sut.ExecuteAsync(commandMock.Object);

            commandMock.Verify(m => m.ToDomain(
                                   It.Is <IContactRepository>(value => value == _contactRepositoryMock.Object),
                                   It.Is <IAccountingRepository>(value => value == _accountingRepositoryMock.Object)),
                               Times.Once);
        }
        public async Task ExecuteAsync_WhenCalledAndCreatedContactWasReturnedFromMicrosoftGraphRepository_AssertExternalIdentifierSetterWasCalledOnContactFromToDomainOnCommandExternalIdentifierFromCreatedContactFromMicrosoftGraphRepository()
        {
            string         externalIdentifier           = _fixture.Create <string>();
            IContact       createdMicrosoftGraphContact = _fixture.BuildContactMock(externalIdentifier: externalIdentifier).Object;
            CommandHandler sut = CreateSut(createdMicrosoftGraphContact: createdMicrosoftGraphContact);

            Mock <IContact>       contactMock = _fixture.BuildContactMock();
            ICreateContactCommand command     = CreateCreateContactCommandMock(contact: contactMock.Object).Object;
            await sut.ExecuteAsync(command);

            contactMock.VerifySet(m => m.ExternalIdentifier = It.Is <string>(value => string.CompareOrdinal(value, externalIdentifier) == 0), Times.Once);
        }
        public async Task ExecuteAsync_WhenCalled_AssertCreateContactAsyncWasCalledOnMicrosoftGraphRepository()
        {
            CommandHandler sut = CreateSut();

            IRefreshableToken     refreshableToken = _fixture.BuildRefreshableTokenMock().Object;
            IContact              contact          = _fixture.BuildContactMock().Object;
            ICreateContactCommand command          = CreateCreateContactCommandMock(refreshableToken, contact).Object;
            await sut.ExecuteAsync(command);

            _microsoftGraphRepositoryMock.Verify(m => m.CreateContactAsync(
                                                     It.Is <IRefreshableToken>(value => value == refreshableToken),
                                                     It.Is <IContact>(value => value == contact)),
                                                 Times.Once);
        }
        public void ExecuteAsync_WhenCommandIsNull_ThrowsArgumentNullException()
        {
            CommandHandler sut = CreateSut();

            ArgumentNullException result = Assert.ThrowsAsync <ArgumentNullException>(async() => await sut.ExecuteAsync(null));

            Assert.That(result.ParamName, Is.EqualTo("command"));
        }