Ejemplo n.º 1
0
        private Learner DataOrArchive(ILearnerDataService dataService, int learnerId)
        {
            LearnerResponse response = dataService.GetLearner(learnerId);

            return(response.IsArchived
                ? _archiveService.GetLearner(learnerId)
                : response.Learner);
        }
Ejemplo n.º 2
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();
            }
        }