Пример #1
0
        public async Task <Guid> HandleAsync(AddContactPerson message)
        {
            authorization.EnsureOrganisationAccess(message.OrganisationId);

            var contactPerson = ValueObjectInitializer.CreateContact(message.ContactPerson);

            Guid id;

            if (message.ContactId.HasValue)
            {
                var contact = await dataAccess.GetById <Contact>(message.ContactId.Value);

                contact.Overwrite(contactPerson);

                id = contact.Id;
            }
            else
            {
                id = await dataAccess.Add <Contact>(contactPerson);
            }

            await db.SaveChangesAsync();

            return(id);
        }
Пример #2
0
        public async Task HandleAsync_ValidInput_AddsAatf(Core.AatfReturn.FacilityType facilityType)
        {
            var competentAuthority = A.Fake <UKCompetentAuthority>();
            var localarea          = A.Fake <LocalArea>();
            var panarea            = A.Fake <PanArea>();

            var aatf = new AatfData(Guid.NewGuid(), "name", "approval number", 2019, A.Dummy <Core.Shared.UKCompetentAuthorityData>(),
                                    Core.AatfReturn.AatfStatus.Approved, A.Dummy <AatfAddressData>(), Core.AatfReturn.AatfSize.Large, DateTime.Now,
                                    A.Dummy <Core.Shared.PanAreaData>(), A.Dummy <Core.Admin.LocalAreaData>())
            {
                FacilityType = facilityType
            };

            var aatfId = Guid.NewGuid();

            var request = new AddAatf()
            {
                Aatf           = aatf,
                AatfContact    = A.Dummy <AatfContactData>(),
                OrganisationId = Guid.NewGuid()
            };

            var expectedFacilityType = facilityType.ToDomainEnumeration <Domain.AatfReturn.FacilityType>();

            A.CallTo(() => commonDataAccess.FetchCompetentAuthority(aatf.CompetentAuthority.Abbreviation)).Returns(competentAuthority);
            A.CallTo(() => commonDataAccess.FetchLookup <LocalArea>(aatf.LocalAreaData.Id)).Returns(localarea);
            A.CallTo(() => commonDataAccess.FetchLookup <PanArea>(aatf.PanAreaData.Id)).Returns(panarea);

            var result = await handler.HandleAsync(request);

            A.CallTo(() => dataAccess.Add <Domain.AatfReturn.Aatf>(A <Domain.AatfReturn.Aatf> .That.Matches(
                                                                       c => c.Name == aatf.Name &&
                                                                       c.ApprovalNumber == aatf.ApprovalNumber &&
                                                                       c.CompetentAuthority.Equals(competentAuthority) &&
                                                                       c.LocalArea.Equals(localarea) &&
                                                                       c.PanArea.Equals(panarea) &&
                                                                       c.Name == aatf.Name &&
                                                                       c.SiteAddress.Id == aatf.SiteAddress.Id &&
                                                                       Enumeration.FromValue <Domain.AatfReturn.AatfSize>(c.Size.Value) == Enumeration.FromValue <Domain.AatfReturn.AatfSize>(aatf.Size.Value) &&
                                                                       Enumeration.FromValue <Domain.AatfReturn.AatfStatus>(c.AatfStatus.Value) == Enumeration.FromValue <Domain.AatfReturn.AatfStatus>(aatf.AatfStatus.Value) &&
                                                                       c.ApprovalDate == aatf.ApprovalDate &&
                                                                       c.ComplianceYear == aatf.ComplianceYear &&
                                                                       c.FacilityType == expectedFacilityType))).MustHaveHappened(Repeated.Exactly.Once);

            result.Should().Be(true);
        }
Пример #3
0
        public async Task <Guid> HandleAsync(CreateOrganisationAdmin message)
        {
            authorization.EnsureCanAccessInternalArea();
            authorization.EnsureUserInRole(Roles.InternalAdmin);

            Organisation organisation = null;

            switch (message.OrganisationType)
            {
            case Core.Organisations.OrganisationType.Partnership:
                organisation = Organisation.CreatePartnership(message.BusinessName);
                break;

            case Core.Organisations.OrganisationType.RegisteredCompany:
                organisation = Organisation.CreateRegisteredCompany(message.BusinessName, message.RegistrationNumber, message.TradingName);
                break;

            case Core.Organisations.OrganisationType.SoleTraderOrIndividual:
                organisation = Organisation.CreateSoleTrader(message.BusinessName, message.TradingName);
                break;

            default:
                break;
            }

            if (organisation == null)
            {
                throw new NotImplementedException("This organisation type hasn't been implented");
            }

            Country country = await db.Countries.SingleAsync(c => c.Id == message.Address.CountryId);

            Address address = ValueObjectInitializer.CreateAddress(message.Address, country);

            await dataAccess.Add <Address>(address);

            organisation.AddOrUpdateAddress(AddressType.RegisteredOrPPBAddress, address);

            Guid id = await dataAccess.Add <Organisation>(organisation);

            return(id);
        }
Пример #4
0
        public async Task <bool> HandleAsync(AddAatf message)
        {
            authorization.EnsureCanAccessInternalArea();
            authorization.EnsureUserInRole(Roles.InternalAdmin);

            var siteAddress = addressMapper.Map(message.Aatf.SiteAddress);

            var organisation = await dataAccess.GetById <Organisation>(message.OrganisationId);

            var competentAuthority = await commonDataAccess.FetchCompetentAuthority(message.Aatf.CompetentAuthority.Abbreviation);

            var contact = contactMapper.Map(message.AatfContact);

            LocalArea localArea = null;

            PanArea panArea = null;

            if (message.Aatf.LocalAreaData != null)
            {
                localArea = await commonDataAccess.FetchLookup <LocalArea>(message.Aatf.LocalAreaData.Id);
            }

            if (message.Aatf.PanAreaData != null)
            {
                panArea = await commonDataAccess.FetchLookup <PanArea>(message.Aatf.PanAreaData.Id);
            }

            var aatf = new Domain.AatfReturn.Aatf(
                message.Aatf.Name,
                competentAuthority,
                message.Aatf.ApprovalNumber,
                Enumeration.FromValue <Domain.AatfReturn.AatfStatus>(message.Aatf.AatfStatus.Value),
                organisation,
                siteAddress,
                Enumeration.FromValue <Domain.AatfReturn.AatfSize>(message.Aatf.Size.Value),
                message.Aatf.ApprovalDate.GetValueOrDefault(),
                contact,
                message.Aatf.FacilityType.ToDomainEnumeration <Domain.AatfReturn.FacilityType>(),
                message.Aatf.ComplianceYear,
                localArea,
                panArea, message.AatfId);

            await dataAccess.Add <Domain.AatfReturn.Aatf>(aatf);

            return(true);
        }
        public async Task HandleAsync_Partnership_CreatesOrganisation()
        {
            CreateOrganisationAdmin request = new CreateOrganisationAdmin()
            {
                BusinessName     = "Business",
                Address          = CreateAddress(),
                OrganisationType = Core.Organisations.OrganisationType.Partnership
            };

            Guid organisationId = Guid.NewGuid();

            CreateOrganisationAdminHandler handler = new CreateOrganisationAdminHandler(authorization, this.dataAccess, this.context);

            A.CallTo(() => dataAccess.Add <Organisation>(A <Organisation> .That.Matches(p => p.OrganisationName == request.BusinessName))).Returns(organisationId);

            Guid result = await handler.HandleAsync(request);

            A.CallTo(() => dataAccess.Add <Organisation>(A <Organisation> .That.Matches(p => p.OrganisationName == request.BusinessName))).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => dataAccess.Add <Address>(A <Address> .That.Matches(p => p.Address1 == request.Address.Address1))).MustHaveHappened(Repeated.Exactly.Once);

            result.Should().Be(organisationId);
        }