예제 #1
0
        public async Task HandleAsync_EverythingCorrectButWithNewOrganisation_CreateSchemeCallsSaveAndReturnsSuccess_CompleteOrgCalled()
        {
            Organisation organisation = A.Fake <Organisation>();

            organisation.OrganisationStatus = Domain.Organisation.OrganisationStatus.Incomplete;

            // Act
            CreateScheme request = new CreateScheme(
                organisation.Id,
                "New scheme name",
                "WEE/AB8888CD/SCH",
                "WEE7453956",
                ObligationType.B2B,
                new Guid("559B69CE-865C-465F-89ED-D6A58AA8B0B9"),
                SchemeStatus.Approved);

            A.CallTo(() => organisationDataAccess.FetchOrganisationAsync(organisation.Id)).Returns(organisation);

            CreateOrUpdateSchemeInformationResult result = await handler.HandleAsync(request);

            A.CallTo(() => dataAccess.SaveAsync()).MustHaveHappened();
            A.CallTo(() => organisationDataAccess.SaveAsync()).MustHaveHappened();

            Assert.NotNull(result);
            Assert.Equal(CreateOrUpdateSchemeInformationResult.ResultType.Success, result.Result);
        }
예제 #2
0
        public async Task HandleAsync_WhereApprovalNumberIsAValueThatAlreadyExists_ReturnsFailureResult()
        {
            // Arrange
            UKCompetentAuthority environmentAgency = A.Dummy <UKCompetentAuthority>();

            typeof(UKCompetentAuthority).GetProperty("Id").SetValue(environmentAgency, new Guid("42D3130C-4CDB-4F74-866A-BFF839A347B5"));

            A.CallTo(() => dataAccess.CheckSchemeApprovalNumberInUseAsync("WEE/ZZ9999ZZ/SCH")).Returns(true);

            // Act
            CreateScheme request = new CreateScheme(
                A.Dummy <Guid>(),
                "New scheme name",
                "WEE/ZZ9999ZZ/SCH",
                "WEE7453956",
                ObligationType.B2B,
                new Guid("559B69CE-865C-465F-89ED-D6A58AA8B0B9"),
                SchemeStatus.Approved);

            CreateOrUpdateSchemeInformationResult result = await handler.HandleAsync(request);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(CreateOrUpdateSchemeInformationResult.ResultType.ApprovalNumberUniquenessFailure, result.Result);
        }
예제 #3
0
        public async Task HandleAsync_SettingEASchemeIbisCustomerReferenceNumberToAValueThatAlreadyExistsForAnotherNonEAScheme_ReturnsSuccessResult()
        {
            // Arrange
            UKCompetentAuthority environmentAgency = A.Dummy <UKCompetentAuthority>();

            typeof(UKCompetentAuthority).GetProperty("Id").SetValue(environmentAgency, new Guid("42D3130C-4CDB-4F74-866A-BFF839A347B5"));

            UKCompetentAuthority devlovedAgency = A.Dummy <UKCompetentAuthority>();

            typeof(UKCompetentAuthority).GetProperty("Id").SetValue(devlovedAgency, new Guid("76BE711C-191D-4648-AFE7-4404D287535C"));

            Scheme scheme = new Scheme(A.Dummy <Organisation>());

            typeof(Entity).GetProperty("Id").SetValue(scheme, new Guid("5AE25C37-88C8-4646-8793-DB4C2F4EF0E5"));
            scheme.UpdateScheme(
                "Scheme 1",
                "WEE/AA0000AA/SCH",
                "WEE7453846",
                Domain.Obligation.ObligationType.B2C,
                environmentAgency);
            scheme.SetStatus(Domain.Scheme.SchemeStatus.Approved);

            Scheme otherScheme = new Scheme(A.Dummy <Organisation>());

            typeof(Entity).GetProperty("Id").SetValue(otherScheme, new Guid("C78D98A9-E33A-4E20-88D3-F1C99D5165B1"));
            otherScheme.UpdateScheme(
                "Scheme 2",
                "WEE/BB1111BB/SCH",
                "WEE8643759",
                Domain.Obligation.ObligationType.B2C,
                devlovedAgency);
            otherScheme.SetStatus(Domain.Scheme.SchemeStatus.Approved);

            A.CallTo(() => dataAccess.FetchSchemeAsync(new Guid("5AE25C37-88C8-4646-8793-DB4C2F4EF0E5"))).Returns(scheme);
            A.CallTo(() => dataAccess.FetchEnvironmentAgencyAsync()).Returns(environmentAgency);
            A.CallTo(() => dataAccess.FetchNonRejectedEnvironmentAgencySchemesAsync())
            .Returns(new List <Scheme>()
            {
                scheme
            });

            // Act
            CreateScheme request = new CreateScheme(
                scheme.Id,
                "Scheme 1",
                "WEE/AA0000AA/SCH",
                "WEE8643759",
                ObligationType.B2C,
                new Guid("42D3130C-4CDB-4F74-866A-BFF839A347B5"),
                SchemeStatus.Approved);

            CreateOrUpdateSchemeInformationResult result = await handler.HandleAsync(request);

            A.CallTo(() => dataAccess.SaveAsync()).MustHaveHappened();

            // Assert
            Assert.NotNull(result);
            Assert.Equal(CreateOrUpdateSchemeInformationResult.ResultType.Success, result.Result);
        }
예제 #4
0
        public async Task HandleAsync_SettingNonEASchemeIbisCustomerReferenceNumberToEmptyString_ReturnsSuccessResult()
        {
            // Arrange
            UKCompetentAuthority environmentAgency = A.Dummy <UKCompetentAuthority>();

            typeof(UKCompetentAuthority).GetProperty("Id").SetValue(environmentAgency, new Guid("42D3130C-4CDB-4F74-866A-BFF839A347B5"));

            Scheme scheme = new Scheme(A.Dummy <Organisation>());

            typeof(Entity).GetProperty("Id").SetValue(scheme, new Guid("5AE25C37-88C8-4646-8793-DB4C2F4EF0E5"));
            scheme.UpdateScheme(
                "Scheme 1",
                "WEE/AA0000AA/SCH",
                "WEE8643759",
                Domain.Obligation.ObligationType.B2C,
                environmentAgency);
            scheme.SetStatus(Domain.Scheme.SchemeStatus.Approved);

            A.CallTo(() => dataAccess.FetchSchemeAsync(new Guid("5AE25C37-88C8-4646-8793-DB4C2F4EF0E5"))).Returns(scheme);
            A.CallTo(() => dataAccess.FetchEnvironmentAgencyAsync()).Returns(environmentAgency);
            A.CallTo(() => dataAccess.FetchNonRejectedEnvironmentAgencySchemesAsync())
            .Returns(new List <Scheme>()
            {
                scheme
            });

            // Act
            CreateScheme request = new CreateScheme(
                scheme.Id,
                "Scheme 1",
                "WEE/AA0000AA/SCH",
                string.Empty,
                ObligationType.B2C,
                new Guid("61D93F16-A478-4F45-AE6B-2A581F0C0648"),
                SchemeStatus.Approved);

            CreateOrUpdateSchemeInformationResult result = await handler.HandleAsync(request);

            A.CallTo(() => dataAccess.SaveAsync()).MustHaveHappened();

            // Assert
            Assert.NotNull(result);
            Assert.Equal(CreateOrUpdateSchemeInformationResult.ResultType.Success, result.Result);
        }
예제 #5
0
        public async Task HandleAsync_EverythingCorrect_CreateSchemeCallsSaveAndReturnsSuccess()
        {
            // Act
            CreateScheme request = new CreateScheme(
                A.Dummy <Guid>(),
                "New scheme name",
                "WEE/AB8888CD/SCH",
                "WEE7453956",
                ObligationType.B2B,
                new Guid("559B69CE-865C-465F-89ED-D6A58AA8B0B9"),
                SchemeStatus.Approved);

            CreateOrUpdateSchemeInformationResult result = await handler.HandleAsync(request);

            A.CallTo(() => dataAccess.SaveAsync()).MustHaveHappened();

            Assert.NotNull(result);
            Assert.Equal(CreateOrUpdateSchemeInformationResult.ResultType.Success, result.Result);
        }
예제 #6
0
        public async Task <ActionResult> AddScheme(AddSchemeViewModel model)
        {
            using (var client = apiClient())
            {
                if (!ModelState.IsValid)
                {
                    model.CompetentAuthorities = await GetCompetentAuthorities();

                    model.ComplianceYears = await client.SendAsync(User.GetAccessToken(), new GetComplianceYears(model.OrganisationId));

                    model.OrganisationAddress.Countries = await client.SendAsync(User.GetAccessToken(), new GetCountries(false));
                    await SetBreadcrumb(null, InternalUserActivity.ManageScheme);

                    return(View(model));
                }

                CreateScheme request = new CreateScheme(
                    model.OrganisationId,
                    model.SchemeName,
                    model.ApprovalNumber,
                    model.IbisCustomerReference,
                    model.ObligationType.Value,
                    model.CompetentAuthorityId,
                    SchemeStatus.Approved);

                CreateOrUpdateSchemeInformationResult result = await client.SendAsync(User.GetAccessToken(), request);

                await cache.InvalidateOrganisationSearch();

                switch (result.Result)
                {
                case CreateOrUpdateSchemeInformationResult.ResultType.Success:

                    SchemeData orgData = new SchemeData()
                    {
                        OrganisationId = model.OrganisationId,
                        Contact        = model.Contact,
                        Address        = model.OrganisationAddress,
                    };

                    await client.SendAsync(User.GetAccessToken(), new UpdateSchemeContactDetails(orgData));

                    return(RedirectToAction("ManageSchemes"));

                case CreateOrUpdateSchemeInformationResult.ResultType.ApprovalNumberUniquenessFailure:
                {
                    ModelState.AddModelError("ApprovalNumber", "Approval number already exists");

                    await SetBreadcrumb(null, InternalUserActivity.ManageScheme);

                    model.CompetentAuthorities = await GetCompetentAuthorities();

                    model.ComplianceYears = await client.SendAsync(User.GetAccessToken(), new GetComplianceYears(model.OrganisationId));

                    model.OrganisationAddress.Countries = await client.SendAsync(User.GetAccessToken(), new GetCountries(false));

                    return(View(model));
                }

                case CreateOrUpdateSchemeInformationResult.ResultType.IbisCustomerReferenceUniquenessFailure:
                {
                    string errorMessage = string.Format(
                        "Billing reference \"{0}\" already exists for scheme \"{1}\" ({2})",
                        result.IbisCustomerReferenceUniquenessFailure.IbisCustomerReference,
                        result.IbisCustomerReferenceUniquenessFailure.OtherSchemeName,
                        result.IbisCustomerReferenceUniquenessFailure.OtherSchemeApprovalNumber);

                    ModelState.AddModelError("IbisCustomerReference", errorMessage);

                    await SetBreadcrumb(null, InternalUserActivity.ManageScheme);

                    model.CompetentAuthorities = await GetCompetentAuthorities();

                    model.ComplianceYears = await client.SendAsync(User.GetAccessToken(), new GetComplianceYears(model.OrganisationId));

                    model.OrganisationAddress.Countries = await client.SendAsync(User.GetAccessToken(), new GetCountries(false));

                    return(View(model));
                }

                case CreateOrUpdateSchemeInformationResult.ResultType.IbisCustomerReferenceMandatoryForEAFailure:
                    ModelState.AddModelError("IbisCustomerReference", "Enter a customer billing reference");

                    await SetBreadcrumb(null, InternalUserActivity.ManageScheme);

                    model.CompetentAuthorities = await GetCompetentAuthorities();

                    model.ComplianceYears = await client.SendAsync(User.GetAccessToken(), new GetComplianceYears(model.OrganisationId));

                    model.OrganisationAddress.Countries = await client.SendAsync(User.GetAccessToken(), new GetCountries(false));

                    return(View(model));

                default:
                    throw new NotSupportedException();
                }
            }
        }