public void BeforeEach()
        {
            mockDataRepo = MoqHelpers.CreateMockDataRepository();
            ;

            mockFileRepo = new Mock <IFileRepository>();

            testSearchBL = new SearchBusinessLogic(testSearchRepo, Mock.Of <ISearchRepository <SicCodeSearchModel> >(), Mock.Of <IAuditLogger>());

            // setup mocks ans ensures they call their implementations. (We override calls per test when need be!)
            mockScopeBL          = new Mock <ScopeBusinessLogic>(testCommonBL, mockDataRepo.Object, testSearchBL);
            mockScopeBL.CallBase = true;

            mockOrganisationBL = new Mock <OrganisationBusinessLogic>(
                testCommonBL,
                mockDataRepo.Object,
                new Mock <ISubmissionBusinessLogic>().Object,
                new Mock <IScopeBusinessLogic>().Object,
                new Mock <IEncryptionHandler>().Object,
                new Mock <ISecurityCodeBusinessLogic>().Object,
                new Mock <IObfuscator>().Object);

            mockOrganisationBL.CallBase = true;

            // service under test
            testScopePresenter = new ScopePresenter(mockScopeBL.Object, mockDataRepo.Object, mockOrganisationBL.Object, testCommonBL);
        }
        public async Task ScopePresentation_CreateOrganisationViewModel_When_Data_Is_Valid_It_SucceedsAsync()
        {
            // Arrange
            var          employerRef = "6MQP1ETH";
            User         mockUser    = UserHelper.GetNotAdminUserWithVerifiedEmailAddress();
            Organisation mockOrg     = OrganisationHelper.GetPrivateOrganisation(employerRef);

            mockOrg.SetSecurityCode(VirtualDateTime.Now.AddDays(1));
            UserOrganisation mockUserOrg = UserOrganisationHelper.LinkUserWithOrganisation(mockUser, mockOrg);

            var dataRepo = new Mock <IDataRepository>();

            dataRepo.SetupGetAll(mockOrg);

            var organisationBusinessLogic = new OrganisationBusinessLogic(
                testCommonBL,
                dataRepo.Object,
                new Mock <ISubmissionBusinessLogic>().Object,
                new Mock <IScopeBusinessLogic>().Object,
                new Mock <IEncryptionHandler>().Object,
                new Mock <ISecurityCodeBusinessLogic>().Object,
                new Mock <IDnBOrgsRepository>().Object,
                new Mock <IObfuscator>().Object);

            var scopePresenter = new ScopePresenter(
                mockScopeBL.Object,
                dataRepo.Object,
                organisationBusinessLogic,
                testCommonBL);

            var testModel = new EnterCodesViewModel {
                EmployerReference = mockOrg.EmployerReference, SecurityToken = mockOrg.SecurityCode
            };

            // Act
            OrganisationViewModel actual = await scopePresenter.CreateOrganisationViewModelAsync(testModel, mockUser);

            // Assert
            Assert.NotNull(actual, "Expected an organisation view model");
            Assert.AreEqual(employerRef, actual.Employers.Results[0].EmployerReference);
            Assert.False(actual.IsSecurityCodeExpired, "the security code was set to expire tomorrow");
        }
        public async Task ScopePresentation_CreateOrganisationViewModel_When_Record_Not_Found_Returns_NullAsync()
        {
            // Arrange
            var          employerRef = "SomeThatWillBeInDatabase";
            User         mockUser    = UserHelper.GetNotAdminUserWithVerifiedEmailAddress();
            Organisation mockOrg     = OrganisationHelper.GetPrivateOrganisation(employerRef);

            mockOrg.SetSecurityCode(VirtualDateTime.Now.AddDays(1));
            UserOrganisation mockUserOrg = UserOrganisationHelper.LinkUserWithOrganisation(mockUser, mockOrg);

            var dataRepo = new Mock <IDataRepository>();

            dataRepo.SetupGetAll(mockOrg);

            var organisationBusinessLogic = new OrganisationBusinessLogic(
                testCommonBL,
                dataRepo.Object,
                new Mock <ISubmissionBusinessLogic>().Object,
                new Mock <IScopeBusinessLogic>().Object,
                new Mock <IEncryptionHandler>().Object,
                new Mock <ISecurityCodeBusinessLogic>().Object,
                new Mock <IDnBOrgsRepository>().Object,
                new Mock <IObfuscator>().Object);

            var scopePresenter = new ScopePresenter(
                mockScopeBL.Object,
                dataRepo.Object,
                organisationBusinessLogic,
                testCommonBL);

            var testModel = new EnterCodesViewModel {
                EmployerReference = "NotFoundInDB", SecurityToken = mockOrg.SecurityCode
            };

            // Act
            OrganisationViewModel actual = await scopePresenter.CreateOrganisationViewModelAsync(testModel, mockUser);

            // Assert
            Assert.Null(actual, "When the combination EmployerReference/SecurityCode is not found in DB, this method must return null");
        }