public async Task AuthAndCreateViewModel_When_Previous_Scope_Submission_Exists_Then_HasPreviousSubmission_Should_Be_TrueAsync()
        {
            // Arrange
            var testOrganisationId = 412;
            var testSnapshotYear   = 2017;
            var testModel          = new EnterCodesViewModel {
                EmployerReference = "ABCDEFG", SecurityToken = "BBBBSSSS"
            };

            //mockScopeBL.CallBase = false;
            mockScopeBL.Setup(r => r.GetScopeByEmployerReferenceAsync(It.IsIn(testModel.EmployerReference), It.IsIn(testSnapshotYear)))
            .ReturnsAsync(new OrganisationScope {
                OrganisationScopeId = 12, ScopeStatus = ScopeStatuses.OutOfScope
            });

            var testUser = new User {
                UserId = 1
            };

            // Act
            ScopingViewModel actualState = await testScopePresenter.CreateScopingViewModelAsync(testModel, testUser);

            // Assert
            //Expect(actualState.HasPrevScope == true, "Expected HasPrevScope to be true");
            //Expect(actualState.PrevOrgScopeId > 0, "Expected PrevOrgScopeId to NOT be null");
            //Expect(actualState.PrevOrgScopeStatus == ScopeStatuses.OutOfScope, "Expected PrevOrgScopeStatus to be OutOfScope");
            Expect(
                actualState.EnterCodes.EmployerReference == testModel.EmployerReference,
                "Expected EmployerReference to be testEmployerRef");
        }
Beispiel #2
0
        public virtual async Task <OrganisationViewModel> CreateOrganisationViewModelAsync(
            EnterCodesViewModel enterCodes, User currentUser)
        {
            var org = await _organisationBusinessLogic.GetOrganisationByEmployerReferenceAndSecurityCodeAsync(
                enterCodes.EmployerReference,
                enterCodes.SecurityToken);

            if (org == null)
            {
                return(null);
            }

            var model = new OrganisationViewModel();

            // when SecurityToken is expired then model.SecurityCodeExpired should be true
            model.IsSecurityCodeExpired = org.HasSecurityCodeExpired();

            model.Employers         = new PagedResult <EmployerRecord>();
            model.Employers.Results = new List <EmployerRecord> {
                _organisationBusinessLogic.CreateEmployerRecord(org)
            };
            model.SelectedEmployerIndex = 0;

            //Mark the organisation as authorised
            model.SelectedAuthorised    = true;
            model.IsFastTrackAuthorised = true;

            return(model);
        }
        public async Task AuthAndCreateViewModel_When_Successfull_Then_Return_DUNS_OrgName_AddressAsync()
        {
            // Arrange
            var testEmployerRef = "ABCDEFG";
            var testSecurityTok = "11113333";
            var testModel       = new EnterCodesViewModel {
                EmployerReference = testEmployerRef, SecurityToken = testSecurityTok
            };

            var    testAddress1       = "Address1";
            var    testAddress2       = "Address2";
            var    testAddress3       = "testAddress3";
            var    testCity           = "testCity";
            var    testPOBox          = "testPOBox";
            var    testPostalCode     = "testPostalCode";
            var    expectedDUNSNumber = "1234567890";
            var    expectedOrgName    = "Test Org Name";
            string expectedAddress    = $"{testAddress1}, {testAddress2}, {testAddress3}, {testCity}, {testPostalCode}, {testPOBox}";

            //Always returns an organisation and scope
            mockDataRepo.SetupGetAll(new Organisation(), new OrganisationScope());

            var testUser = new User {
                UserId = 1
            };

            // Act
            ScopingViewModel actualModel = await testScopePresenter.CreateScopingViewModelAsync(testModel, testUser);

            // Assert
            Assert.That(actualModel.DUNSNumber == expectedDUNSNumber, $"Expected DunsCode to be {expectedDUNSNumber}");
            Assert.That(actualModel.OrganisationName == expectedOrgName, $"Expected OrgName to be {expectedOrgName}");
            Assert.That(actualModel.OrganisationAddress == expectedAddress, $"Expected OrgAddress to be {expectedAddress}");
            //Assert.That(actualModel.AccountingDate.Year == VirtualDateTime.Now.Year, $"Expected AccountingDate year to be {VirtualDateTime.Now.Year}");
        }
        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");
        }
        public void AuthAndCreateViewModel_When_No_Previous_Scope_Submission_Exists_Then_HasPreviousSubmission_Should_Be_False()
        {
            // Arrange
            var testEmployerRef = "ABCDEFG";
            var testSecurityTok = "11113333";
            var testModel       = new EnterCodesViewModel {
                EmployerReference = testEmployerRef, SecurityToken = testSecurityTok
            };

            mockDataRepo.SetupGetAll(new Organisation());

            var testUser = new User {
                UserId = 1
            };

            // Act
            Task <ScopingViewModel> actualModel = testScopePresenter.CreateScopingViewModelAsync(testModel, testUser);

            // Assert
            //Assert.That(actualModel.HasPrevScope == false, "Expected HasPrevScope to be false");
            //Assert.That(actualModel.PrevOrgScopeId == -1, "Expected PrevOrgScopeId to be -1");
        }
        public void AuthAndCreateViewModel_When_Organisation_doesnt_exist_then_throw_ArgumentOutOfRangeException()
        {
            // Arrange
            var testModel = new EnterCodesViewModel {
                EmployerReference = "ABCDEFG", SecurityToken = ""
            };

            var testUser = new User {
                UserId = 1
            };

            // Act
            TestDelegate testDelegate = async() => await testScopePresenter.CreateScopingViewModelAsync(testModel, testUser);

            // Assert
            Assert.That(
                testDelegate,
                Throws.TypeOf <ArgumentOutOfRangeException>()
                .With
                .Message
                .Contains($"Cannot find organisation with EmployerReference: {testModel.EmployerReference}"));
        }
        public async Task AuthAndCreateViewModel_When_SecurityToken_Is_Active_Then_SecurityCodeExpired_Should_Be_FalseAsync()
        {
            // Arrange
            var testEmployerRef = "ABCDEFG";
            var testSecurityTok = "11113333";
            var testModel       = new EnterCodesViewModel {
                EmployerReference = testEmployerRef, SecurityToken = testSecurityTok
            };

            DateTime testExpiredDate = VirtualDateTime.Now.AddDays(-(ConfigHelpers.SharedOptions.SecurityCodeExpiryDays - 1));

            //Always returns an organisation and scope
            mockDataRepo.SetupGetAll(new Organisation(), new OrganisationScope());

            var testUser = new User {
                UserId = 1
            };

            // Act
            ScopingViewModel actualModel = await testScopePresenter.CreateScopingViewModelAsync(testModel, testUser);

            // Assert
            Assert.That(actualModel.IsSecurityCodeExpired == false, "Expected SecurityCodeExpired to be false");
        }
Beispiel #9
0
 public virtual async Task <ScopingViewModel> CreateScopingViewModelAsync(EnterCodesViewModel enterCodes,
                                                                          User currentUser)
 {
     // when NonStarterOrg doesn't exist then return
     return(null);
 }
        public async Task <IActionResult> OutOfScope(EnterCodesViewModel model)
        {
            // When User is Admin then redirect to Admin\Home
            if (CurrentUser != null && _sharedBusinessLogic.AuthorisationBusinessLogic.IsAdministrator(CurrentUser))
            {
                return(RedirectToAction("Home", "Admin"));
            }

            // When Spamlocked then return a CustomError view
            var remainingTime =
                await GetRetryLockRemainingTimeAsync("lastScopeCode", SharedBusinessLogic.SharedOptions.LockoutMinutes);

            if (remainingTime > TimeSpan.Zero)
            {
                return(View("CustomError",
                            WebService.ErrorViewModelFactory.Create(1125,
                                                                    new { remainingTime = remainingTime.ToFriendly(maxParts: 2) })));
            }

            // the following fields are validatable at this stage
            ModelState.Include(
                nameof(EnterCodesViewModel.EmployerReference),
                nameof(EnterCodesViewModel.SecurityToken));

            // When ModelState is Not Valid Then Return the EnterCodes View
            if (!ModelState.IsValid)
            {
                this.CleanModelErrors <EnterCodesViewModel>();
                return(View("EnterCodes", model));
            }

            // Generate the state model
            var stateModel = await ScopePresentation.CreateScopingViewModelAsync(model, CurrentUser);

            if (stateModel == null)
            {
                await IncrementRetryCountAsync("lastScopeCode", SharedBusinessLogic.SharedOptions.LockoutMinutes);

                ModelState.AddModelError(3027);
                this.CleanModelErrors <EnterCodesViewModel>();
                return(View("EnterCodes", model));
            }


            //Clear the retry locks
            await ClearRetryLocksAsync("lastScopeCode");

            // set the back link
            stateModel.StartUrl = Url.Action("OutOfScope");

            // set the journey to out-of-scope
            stateModel.IsOutOfScopeJourney = true;

            // save the state to the session cache
            StashModel(stateModel);

            // when security code has expired then redirect to the CodeExpired action
            if (stateModel.IsSecurityCodeExpired)
            {
                return(View("CodeExpired", stateModel));
            }


            //When on out-of-scope journey and any previous explicit scope then tell user scope is known
            if (!stateModel.IsChangeJourney &&
                (
                    stateModel.LastScope != null &&
                    stateModel.LastScope.ScopeStatus.IsAny(ScopeStatuses.InScope, ScopeStatuses.OutOfScope) ||
                    stateModel.ThisScope != null &&
                    stateModel.ThisScope.ScopeStatus.IsAny(ScopeStatuses.InScope, ScopeStatuses.OutOfScope)
                )
                )
            {
                return(View("ScopeKnown", stateModel));
            }

            // redirect to next step
            return(RedirectToAction("ConfirmOutOfScopeDetails"));
        }