예제 #1
0
        public void InFailoverModeTests(
            bool failoverEntriesRecent
            , bool failoverEntriesThreshold
            , bool failoverModeEnabled
            )
        {
            var failoverEntries = new List <FailoverEntry>(GenerateFailoverEntries(failoverEntriesRecent, failoverEntriesThreshold));

            A.CallTo(() => _failoverRepository.GetFailOverEntries()).Returns(failoverEntries);

            A.CallTo(() => _configuration.IsFailoverModeEnabled).Returns(failoverModeEnabled);

            bool expectedResult = failoverEntriesRecent && failoverEntriesThreshold && failoverModeEnabled;

            var result = _sut.InFailoverMode();

            Assert.AreEqual(expectedResult, result);

            if (failoverModeEnabled)
            {
                A.CallTo(() => _failoverRepository.GetFailOverEntries()).MustHaveHappenedOnceExactly();
            }
            else
            {
                A.CallTo(() => _failoverRepository.GetFailOverEntries()).MustNotHaveHappened();
            }
        }
예제 #2
0
        public Learner GetLearner(int learnerId, bool isLearnerArchived)
        {
            Func <int, Learner> strategy = GetStrategy(isLearnerArchived, () => _failoverService.InFailoverMode());

            return(strategy(learnerId));
        }
예제 #3
0
        public void GetLearnerTests(
            bool isLearnerArchived
            , bool inFailoverMode
            , bool learnerResponseArchived
            )
        {
            var archiveLearner = new Learner();

            A.CallTo(() => _archiveService.GetLearner(A <int> ._)).Returns(archiveLearner);

            var failoverLearner         = new Learner();
            var failoverLearnerResponse = new LearnerResponse {
                IsArchived = learnerResponseArchived, Learner = failoverLearner
            };

            A.CallTo(() => _failoverDataService.GetLearner(A <int> ._)).Returns(failoverLearnerResponse);

            var liveLearner         = new Learner();
            var liveLearnerResponse = new LearnerResponse {
                IsArchived = learnerResponseArchived, Learner = liveLearner
            };

            A.CallTo(() => _liveDataService.GetLearner(A <int> ._)).Returns(liveLearnerResponse);

            A.CallTo(() => _failoverService.InFailoverMode()).Returns(inFailoverMode);

            LearnerSource learnerSource = isLearnerArchived || learnerResponseArchived ? LearnerSource.Archive :
                                          inFailoverMode ? LearnerSource.Failover :
                                          LearnerSource.Live;

            bool archiveDataAccessed  = isLearnerArchived || learnerResponseArchived;
            bool failoverDataAccessed = !isLearnerArchived && inFailoverMode;
            bool liveDataAccessed     = !isLearnerArchived && !inFailoverMode;

            bool failoverServiceAccessed = !isLearnerArchived;

            var learner = _sut.GetLearner(1, isLearnerArchived);

            Learner expectedLearner;

            switch (learnerSource)
            {
            case LearnerSource.Archive:
                expectedLearner = archiveLearner;
                break;

            case LearnerSource.Failover:
                expectedLearner = failoverLearner;
                break;

            case LearnerSource.Live:
                expectedLearner = liveLearner;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(learnerSource));
            }
            Assert.AreSame(expectedLearner, learner);

            if (archiveDataAccessed)
            {
                A.CallTo(() => _archiveService.GetLearner(A <int> ._)).MustHaveHappenedOnceExactly();
            }
            else
            {
                A.CallTo(() => _archiveService.GetLearner(A <int> ._)).MustNotHaveHappened();
            }

            if (failoverDataAccessed)
            {
                A.CallTo(() => _failoverDataService.GetLearner(A <int> ._)).MustHaveHappenedOnceExactly();
            }
            else
            {
                A.CallTo(() => _failoverDataService.GetLearner(A <int> ._)).MustNotHaveHappened();
            }

            if (liveDataAccessed)
            {
                A.CallTo(() => _liveDataService.GetLearner(A <int> ._)).MustHaveHappenedOnceExactly();
            }
            else
            {
                A.CallTo(() => _liveDataService.GetLearner(A <int> ._)).MustNotHaveHappened();
            }

            if (failoverServiceAccessed)
            {
                A.CallTo(() => _failoverService.InFailoverMode()).MustHaveHappenedOnceExactly();
            }
            else
            {
                A.CallTo(() => _failoverService.InFailoverMode()).MustNotHaveHappened();
            }
        }