Exemple #1
0
        public async Task DraftFile_GetDraftFile_Returns_A_Valid_DraftAsync()
        {
            // Arrange
            User         mockedUser         = UserHelper.GetNotAdminUserWithVerifiedEmailAddress();
            Organisation mockedOrganisation = OrganisationHelper.GetPublicOrganisation();

            mockedOrganisation.OrganisationId = new Random().Next(1000, 9999);
            UserOrganisation mockedUserOrganisation = UserOrganisationHelper.LinkUserWithOrganisation(mockedUser, mockedOrganisation);
            Return           mockedReturn           = ReturnHelper.GetSubmittedReturnForOrganisationAndYear(mockedUserOrganisation, ConfigHelpers.SharedOptions.FirstReportingYear);

            OrganisationHelper.LinkOrganisationAndReturn(mockedOrganisation, mockedReturn);

            var testDraftFileBL       = new DraftFileBusinessLogic(null, new SystemFileRepository(new StorageOptions()));
            var sharedBusinessLogic   = UiTestHelper.DIContainer.Resolve <ISharedBusinessLogic>();
            var testSubmissionService = new SubmissionService(sharedBusinessLogic, Mock.Of <ISubmissionBusinessLogic>(), Mock.Of <IScopeBusinessLogic>(), testDraftFileBL);
            var testPresenter         = new SubmissionPresenter(testSubmissionService, ConfigHelpers.SubmissionOptions, null);

            // Act
            Draft actualDraft = await testPresenter.GetDraftFileAsync(
                mockedOrganisation.OrganisationId,
                mockedOrganisation.SectorType.GetAccountingStartDate().Year,
                mockedUser.UserId);

            // Assert
            Assert.NotNull(actualDraft);
            Assert.True(actualDraft.IsUserAllowedAccess);
            Assert.AreEqual(mockedUser.UserId, actualDraft.LastWrittenByUserId);

            // Clean up
            await testDraftFileBL.DiscardDraftAsync(actualDraft);
        }
        public async Task SubmitController_DraftComplete_POST_MaleBonusIsZero_ShowsErrors()
        {
            // Arrange
            var user = new User {
                UserId = 1, EmailAddress = "*****@*****.**", EmailVerifiedDate = VirtualDateTime.Now
            };
            var organisation = new Core.Entities.Organisation {
                OrganisationId = 1, SectorType = SectorTypes.Public
            };
            var userOrganisation = new UserOrganisation {
                OrganisationId   = organisation.OrganisationId,
                Organisation     = organisation,
                UserId           = 1,
                PINConfirmedDate = VirtualDateTime.Now,
                PIN = "1"
            };

            //set mock routeData
            var routeData = new RouteData();

            routeData.Values.Add("action", "EnterCalculations");
            routeData.Values.Add("controller", "submit");

            DateTime PrivateAccountingDate = SectorTypeHelper.SnapshotDateHelper.PrivateAccountingDate;

            var returnViewModel = new ReturnViewModel {
                AccountingDate              = PrivateAccountingDate,
                MaleMedianBonusPayPercent   = 0,
                FemaleMedianBonusPayPercent = 50,
                DiffMeanBonusPercent        = -50,
                DiffMedianBonusPercent      = -50,
                DiffMedianHourlyPercent     = 50,
                DiffMeanHourlyPayPercent    = 50,
                FemaleLowerPayBand          = 50,
                FemaleMiddlePayBand         = 50,
                FemaleUpperPayBand          = 50,
                FemaleUpperQuartilePayBand  = 50,
                MaleLowerPayBand            = 50,
                MaleMiddlePayBand           = 50,
                MaleUpperPayBand            = 50,
                MaleUpperQuartilePayBand    = 50,
                SectorType = SectorTypes.Private
            };

            var controller = UiTestHelper.GetController <SubmissionController>(1, routeData, user, organisation, userOrganisation);

            controller.Bind(returnViewModel);

            var sharedBusinessLogic   = UiTestHelper.DIContainer.Resolve <ISharedBusinessLogic>();
            var testDraftFileBL       = new DraftFileBusinessLogic(null, new SystemFileRepository(new StorageOptions()));
            var testSubmissionService = new SubmissionService(sharedBusinessLogic, Mock.Of <ISubmissionBusinessLogic>(), Mock.Of <IScopeBusinessLogic>(), testDraftFileBL);
            var testPresenter         = new SubmissionPresenter(testSubmissionService, ConfigHelpers.SubmissionOptions, null);


            returnViewModel.ReportInfo.Draft = await testPresenter.GetDraftFileAsync(
                organisation.OrganisationId,
                organisation.SectorType.GetAccountingStartDate().Year,
                user.UserId);

            // Act
            controller.StashModel(returnViewModel);
            controller.ReportingOrganisationId = 1;
            var result = await controller.SaveDraftAsync(returnViewModel) as ViewResult;

            // Assert
            Assert.NotNull(result, "Expected ViewResult");
            Assert.Null(result.ViewName, "Incorrect view returned");
            Assert.NotNull(result.Model as ReturnViewModel, "Expected ReturnViewModel");
            Assert.AreEqual(
                "Do not enter a bonus difference if 0% of your male employees received a bonus",
                result.ViewData.ModelState["DiffMedianBonusPercent"].Errors[0].ErrorMessage);
            Assert.AreEqual(
                "Do not enter a bonus difference if 0% of your male employees received a bonus",
                result.ViewData.ModelState["DiffMeanBonusPercent"].Errors[0].ErrorMessage);
        }