public async Task HandleDkimEvaluationUpdateCantUpdateDoesNotContinue()
        {
            DkimEntityState dkimEntityState = A.Fake <DkimEntityState>();

            A.CallTo(() => dkimEntityState.Id).Returns(Id);
            A.CallTo(() => dkimEntityState.CanUpdate(A <string> ._, A <DateTime> ._)).Returns(false);

            A.CallTo(() => _dkimEntityDao.Get(Id)).Returns(dkimEntityState);

            await _dkimEntity.Handle(new DkimRecordEvaluationResult(Id, new List <DkimSelectorResult>()));

            A.CallTo(() => _dkimEntityDao.Save(A <DkimEntityState> ._)).MustNotHaveHappened();
            A.CallTo(() => _dispatcher.Dispatch(A <Common.Messaging.Abstractions.Message> ._, A <string> ._)).MustNotHaveHappened();
        }
        public async Task HandleDkimEvaluationUpdateSuccessful()
        {
            DkimEntityState dkimEntityState = A.Fake <DkimEntityState>();

            A.CallTo(() => dkimEntityState.Id).Returns(Id);
            A.CallTo(() => dkimEntityState.CanUpdate(A <string> ._, A <DateTime> ._)).Returns(true);

            A.CallTo(() => _dkimEntityDao.Get(Id)).Returns(dkimEntityState);

            DkimRecordEvaluationResult dkimRecordEvaluationResult = new DkimRecordEvaluationResult(Id, new List <DkimSelectorResult>());
            await _dkimEntity.Handle(dkimRecordEvaluationResult);

            A.CallTo(() => _dkimEntityDao.Save(dkimEntityState)).MustHaveHappened();
            A.CallTo(() => _dispatcher.Dispatch(A <DkimEvaluationUpdated> ._, A <string> ._)).MustHaveHappened();
        }
        public async Task HandleAggregateReportDomainDkimSelectorsStateExistsAndEventCausesUpdate()
        {
            DkimEntityState dkimEntityState = A.Fake <DkimEntityState>();

            A.CallTo(() => dkimEntityState.Id).Returns(Id);
            A.CallTo(() => dkimEntityState.CanUpdate(A <string> ._, A <DateTime> ._)).Returns(true);

            DkimSelectorsUpdated dkimSelectorsUpdated;

            A.CallTo(() => dkimEntityState.UpdateSelectors(null, out dkimSelectorsUpdated)).WithAnyArguments().Returns(true);

            A.CallTo(() => _dkimEntityDao.Get(Id)).Returns(dkimEntityState);

            await _dkimEntity.Handle(new DkimSelectorsSeen("", "", Id, new List <string>()));

            A.CallTo(() => _dkimEntityDao.Save(A <DkimEntityState> ._)).MustHaveHappenedOnceExactly();
            A.CallTo(() => _dkimEntityDao.Save(A <DkimEntityState> ._)).MustHaveHappenedOnceExactly();
        }
        public async Task HandleAggregateReportDomainDkimSelectorsCantUpdateDoesNotContinue()
        {
            DkimEntityState dkimEntityState = A.Fake <DkimEntityState>();

            A.CallTo(() => dkimEntityState.Id).Returns(Id);
            A.CallTo(() => dkimEntityState.CanUpdate(A <string> ._, A <DateTime> ._)).Returns(false);

            DkimSelectorsUpdated dkimSelectorsUpdated;

            A.CallTo(() => dkimEntityState.UpdateSelectors(null, out dkimSelectorsUpdated)).WithAnyArguments().Returns(false);

            A.CallTo(() => _dkimEntityDao.Get(Id)).Returns(dkimEntityState);

            await _dkimEntity.Handle(new DkimSelectorsSeen("", "", Id, new List <string>()));

            A.CallTo(() => _dkimEntityDao.Save(A <DkimEntityState> ._)).MustNotHaveHappened();
            A.CallTo(() => _dispatcher.Dispatch(A <Common.Messaging.Abstractions.Message> ._, A <string> ._)).MustNotHaveHappened();
        }
        public async Task HandleDkimRecordsPolledCantUpdateDoesNotContinue()
        {
            DkimEntityState dkimEntityState = A.Fake <DkimEntityState>();

            A.CallTo(() => dkimEntityState.Id).Returns(Id);
            A.CallTo(() => dkimEntityState.CanUpdate(A <string> ._, A <DateTime> ._)).Returns(false);

            DkimSelectorsUpdated dkimSelectorsUpdated;

            A.CallTo(() => dkimEntityState.UpdateSelectors(null, out dkimSelectorsUpdated)).WithAnyArguments().Returns(false);

            A.CallTo(() => _dkimEntityDao.Get(Id)).Returns(dkimEntityState);

            await _dkimEntity.Handle(new DkimRecordEvaluationResult(Id, new List <DkimSelectorResult>()));

            A.CallTo(() => _changeNotifierComposite.Handle(A <DkimEntityState> ._, A <Message> ._)).MustNotHaveHappened();
            A.CallTo(() => _domainStatusPublisher.Publish(A <DkimRecordEvaluationResult> ._)).MustNotHaveHappened();
            A.CallTo(() => _dkimEntityDao.Save(A <DkimEntityState> ._)).MustNotHaveHappened();
            A.CallTo(() => _dispatcher.Dispatch(A <Common.Messaging.Abstractions.Message> ._, A <string> ._)).MustNotHaveHappened();
        }