コード例 #1
0
        GetViewModelForSubmission_Given_a_new_submission_Then_returns_empty_model_with_org_id_and_reporting_date_onlyAsync()
        {
            var testUserId = 123;
            int testYear   = VirtualDateTime.Now.AddYears(-1).Year;

            // Mocks
            var testOrganisation = new Organisation {
                OrganisationId = 524124, SectorType = SectorTypes.Private
            };

            mockDataRepo.Setup(dr => dr.GetAll <UserOrganisation>())
            .Returns(
                new[] {
                new UserOrganisation {
                    UserId = testUserId, OrganisationId = testOrganisation.OrganisationId, Organisation = testOrganisation
                }
            }.AsQueryable()
                .BuildMock()
                .Object);

            mockDataRepo.Setup(dr => dr.GetAll <Return>())
            .Returns(new Return[] { }.AsQueryable().BuildMock().Object);

            var   testDraftFileFileBusinessLogic = new DraftFileBusinessLogic(null, new SystemFileRepository(new StorageOptions()));
            Draft actualDraftFile = await testDraftFileFileBusinessLogic.GetExistingOrNewAsync(
                testOrganisation.OrganisationId,
                testYear,
                testUserId);

            var sharedBusinessLogic = UiTestHelper.DIContainer.Resolve <ISharedBusinessLogic>();

            var testSubmissionService = new SubmissionService(sharedBusinessLogic, Mock.Of <ISubmissionBusinessLogic>(), Mock.Of <IScopeBusinessLogic>(), testDraftFileFileBusinessLogic);
            var testPresenter         = new SubmissionPresenter(testSubmissionService, ConfigHelpers.SubmissionOptions, null);

            // Test
            ReturnViewModel actualModel = await testPresenter.GetReturnViewModelAsync(testOrganisation.OrganisationId, testYear, testUserId);

            // Assert
            Assert.NotNull(actualModel);
            Assert.AreEqual(testOrganisation.OrganisationId, actualModel.OrganisationId);
            Assert.AreEqual(testYear, actualModel.AccountingDate.Year);

            await testDraftFileFileBusinessLogic.DiscardDraftAsync(actualDraftFile);
        }
コード例 #2
0
        public void GetViewModelForSubmission_Throws_AuthenticationException_when_the_user_organisation_isnt_found()
        {
            var testUserId         = 123;
            var testOrganisationId = 524124;

            // Mocks
            mockDataRepo.Setup(dr => dr.GetAll <UserOrganisation>()).Returns(new UserOrganisation[] { }.AsQueryable().BuildMock().Object);

            var sharedBusinessLogic = UiTestHelper.DIContainer.Resolve <ISharedBusinessLogic>();

            var testSubmissionService = new SubmissionService(sharedBusinessLogic, Mock.Of <ISubmissionBusinessLogic>(), Mock.Of <IScopeBusinessLogic>(), Mock.Of <IDraftFileBusinessLogic>());
            var testPresenter         = new SubmissionPresenter(testSubmissionService, ConfigHelpers.SubmissionOptions, null);
            // Test
            var ex = Assert.ThrowsAsync <AuthenticationException>(
                () => testPresenter.GetReturnViewModelAsync(testOrganisationId, 2001, testUserId));

            // Assert
            Assert.That(
                ex.Message.Contains(
                    $"GetViewModelForSubmission: Failed to find the UserOrganisation for userId {testUserId} and organisationId {testOrganisationId}"));
        }
コード例 #3
0
        public async Task GetViewModelForSubmission_Given_an_existing_submission_Then_returns_return_dataAsync()
        {
            var testUserId         = 123;
            var testOrganisationId = 524124;
            var testYear           = 2001;

            var testReturn = new Return {
                AccountingDate              = new DateTime(testYear, 1, 1),
                OrganisationId              = testOrganisationId,
                DiffMeanBonusPercent        = 100,
                DiffMeanHourlyPayPercent    = 99,
                DiffMedianBonusPercent      = 98,
                DiffMedianHourlyPercent     = 97,
                FemaleLowerPayBand          = 96,
                FemaleMedianBonusPayPercent = 95,
                FemaleMiddlePayBand         = 94,
                FemaleUpperPayBand          = 93,
                FemaleUpperQuartilePayBand  = 92,
                MaleLowerPayBand            = 91,
                MaleMedianBonusPayPercent   = 90,
                MaleUpperQuartilePayBand    = 89,
                MaleMiddlePayBand           = 88,
                MaleUpperPayBand            = 87,
                FirstName            = "Test",
                LastName             = "User",
                JobTitle             = "QA",
                CompanyLinkToGPGInfo = "http://unittesting",
                MinEmployees         = 250,
                MaxEmployees         = 499,
                Status       = ReturnStatuses.Submitted,
                Organisation = new Organisation {
                    SectorType = SectorTypes.Private
                }
            };

            // Mocks
            mockDataRepo.Setup(dr => dr.GetAll <UserOrganisation>())
            .Returns(
                new[] {
                new UserOrganisation {
                    UserId = testUserId, OrganisationId = testOrganisationId, Organisation = testReturn.Organisation
                }
            }.AsQueryable()
                .BuildMock()
                .Object);

            mockDataRepo.Setup(dr => dr.GetAll <Return>()).Returns(new[] { testReturn }.AsQueryable().BuildMock().Object);

            var mockService = new Mock <SubmissionPresenter>(
                mockDataRepo.Object,
                mockScopeBL.Object,
                mockFileRepo.Object,
                _mockDraftFileBL.Object,
                null);

            mockService.CallBase = true;
            mockService.Setup(s => s.IsValidSnapshotYear(It.IsIn(testYear))).Returns(true);

            // Test
            SubmissionPresenter testService = mockService.Object;
            ReturnViewModel     actualModel = await testService.GetReturnViewModelAsync(testOrganisationId, testYear, testUserId);

            // Assert
            Expect(actualModel != null);
            Expect(actualModel.OrganisationId == testOrganisationId);
            Expect(actualModel.AccountingDate.Year == testYear);

            var testOrgSizeRange = actualModel.OrganisationSize.GetAttribute <RangeAttribute>();

            Expect(testReturn.CompanyLinkToGPGInfo == actualModel.CompanyLinkToGPGInfo);
            Expect(testReturn.DiffMeanBonusPercent == actualModel.DiffMeanBonusPercent.Value);
            Expect(testReturn.DiffMeanHourlyPayPercent == actualModel.DiffMeanHourlyPayPercent.Value);
            Expect(testReturn.DiffMedianBonusPercent == actualModel.DiffMedianBonusPercent.Value);
            Expect(testReturn.DiffMedianHourlyPercent == actualModel.DiffMedianHourlyPercent.Value);
            Expect(testReturn.FemaleLowerPayBand == actualModel.FemaleLowerPayBand.Value);
            Expect(testReturn.FemaleMedianBonusPayPercent == actualModel.FemaleMedianBonusPayPercent.Value);
            Expect(testReturn.FemaleMiddlePayBand == actualModel.FemaleMiddlePayBand.Value);
            Expect(testReturn.FemaleUpperPayBand == actualModel.FemaleUpperPayBand.Value);
            Expect(testReturn.FemaleUpperQuartilePayBand == actualModel.FemaleUpperQuartilePayBand.Value);
            Expect(testReturn.FirstName == actualModel.FirstName);
            Expect(testReturn.LastName == actualModel.LastName);
            Expect(testReturn.JobTitle == actualModel.JobTitle);
            Expect(testReturn.MaleLowerPayBand == actualModel.MaleLowerPayBand.Value);
            Expect(testReturn.MaleMedianBonusPayPercent == actualModel.MaleMedianBonusPayPercent.Value);
            Expect(testReturn.MaleUpperQuartilePayBand == actualModel.MaleUpperQuartilePayBand.Value);
            Expect(testReturn.MaleMiddlePayBand == actualModel.MaleMiddlePayBand.Value);
            Expect(testReturn.MaleUpperPayBand == actualModel.MaleUpperPayBand.Value);
            Expect(testReturn.MinEmployees == (int)testOrgSizeRange.Minimum);
            Expect(testReturn.MaxEmployees == (int)testOrgSizeRange.Maximum);
        }