예제 #1
0
        public void GetCountryName_RetrievesCountryNameFromAttributeIfPresent(countryType country, string countryName)
        {
            var builder = new GenerateFromXmlBuilder();
            var result  = builder.Build().GetCountryName(country);

            Assert.Equal(countryName, result);
        }
예제 #2
0
        private static producerType SetUpProducer(countryType countryType, eeePlacedOnMarketBandType eeePlacedOnMarketBandType, annualTurnoverBandType annualTurnoverBandType, bool vatRegistered)
        {
            var producerCompany = new companyType()
            {
                companyName      = "Test company",
                companyNumber    = "Test CRN",
                registeredOffice = new contactDetailsContainerType()
                {
                    contactDetails = new contactDetailsType()
                    {
                        address = new addressType()
                        {
                            country = countryType
                        }
                    }
                }
            };

            var producerBusiness = new producerBusinessType()
            {
                Item = producerCompany
            };

            var producer = new producerType
            {
                annualTurnoverBand    = annualTurnoverBandType,
                VATRegistered         = vatRegistered,
                eeePlacedOnMarketBand = eeePlacedOnMarketBandType,
                producerBusiness      = producerBusiness
            };

            return(producer);
        }
예제 #3
0
        public async void GetProducerChargeBand_UKEngland_Morethanorequalto5TEEEplacedonmarket_VATRegistered_ChargeBandA2ShouldBeRetrieved()
        {
            //Arrange
            var countryType = new countryType();
            var eeePlacedOnMarketBandType = new eeePlacedOnMarketBandType();
            var annualTurnoverBandType    = new annualTurnoverBandType();

            var producer = SetUpProducer(countryType, eeePlacedOnMarketBandType, annualTurnoverBandType, true);

            // Act
            var result = await environmentAgencyProducerChargeBandCalculator.GetProducerChargeBand(A.Dummy <schemeType>(), producer);

            // Assert
            A.CallTo(() => fetchProducerCharge.GetCharge(ChargeBand.A2)).MustHaveHappened(Repeated.Exactly.Once);
        }
        public void AuthorisedRepresentativeOfficeCountryIsInUnitedKingdom_PassesValidation(countryType someUkCountry)
        {
            var producer = new producerType
            {
                authorisedRepresentative = new authorisedRepresentativeType
                {
                    overseasProducer = new overseasProducerType()
                },
                producerBusiness = MakeProducerBusinessTypeInCountry(someUkCountry)
            };

            var result = Rule().Evaluate(producer);

            Assert.True(result.IsValid);
        }
        public void NotAnAuthorisedRepresentativeButIsInNonUkCountry_PassesValidation()
        {
            const countryType SomeNonUkCountry = countryType.TURKEY;

            var producer = new producerType
            {
                authorisedRepresentative = new authorisedRepresentativeType {
                    overseasProducer = null
                },
                producerBusiness = MakeProducerBusinessTypeInCountry(SomeNonUkCountry)
            };

            var validationResult = Rule().Evaluate(producer);

            Assert.True(validationResult.IsValid);
        }
예제 #6
0
        public async void GetProducerChargeBand_UKNorthernIreland_Morethanorequalto5TEEEplacedonmarket_GreaterthanonemillionpoundsTurnover_NotVATRegistered_ChargeBandDShouldBeRetrieved()
        {
            //Arrange
            var countryType = new countryType();
            var eeePlacedOnMarketBandType = new eeePlacedOnMarketBandType();
            var annualTurnoverBandType    = new annualTurnoverBandType();

            countryType            = countryType.UKNORTHERNIRELAND;
            annualTurnoverBandType = annualTurnoverBandType.Greaterthanonemillionpounds;
            var producer = SetUpProducer(countryType, eeePlacedOnMarketBandType, annualTurnoverBandType, false);

            // Act
            var result = await environmentAgencyProducerChargeBandCalculator.GetProducerChargeBand(A.Dummy <schemeType>(), producer);

            // Assert
            A.CallTo(() => fetchProducerCharge.GetCharge(ChargeBand.D)).MustHaveHappened(Repeated.Exactly.Once);
        }
예제 #7
0
        public async void GetProducerChargeBand_UKEngland_Morethanorequalto5TEEEplacedonmarket_VATRegistered__ProducerChargeForChargeBandShouldBeReturned()
        {
            //Arrange
            var countryType = new countryType();
            var eeePlacedOnMarketBandType = new eeePlacedOnMarketBandType();
            var annualTurnoverBandType    = new annualTurnoverBandType();
            var producerCharge            = new ProducerCharge();

            var producer = SetUpProducer(countryType, eeePlacedOnMarketBandType, annualTurnoverBandType, true);

            A.CallTo(() => fetchProducerCharge.GetCharge(ChargeBand.A2)).Returns(producerCharge);

            // Act
            var result = await environmentAgencyProducerChargeBandCalculator.GetProducerChargeBand(A.Dummy <schemeType>(), producer);

            // Assert
            Assert.Equal(producerCharge, result);
        }
예제 #8
0
        public string GetCountryName(countryType country)
        {
            string countryName = null;

            // Read the country name from XML attribute if defined
            var countryFirstOrDefault = typeof(countryType).GetMember(country.ToString()).FirstOrDefault();

            if (countryFirstOrDefault != null)
            {
                var countryEnumAttribute = countryFirstOrDefault
                                           .GetCustomAttributes(false)
                                           .OfType <XmlEnumAttribute>()
                                           .FirstOrDefault();
                countryName = countryEnumAttribute != null ? countryEnumAttribute.Name : countryFirstOrDefault.Name;
            }

            return(countryName);
        }
 private producerBusinessType MakeProducerBusinessTypeInCountry(countryType country)
 {
     return(new producerBusinessType
     {
         Item =
             new partnershipType
         {
             principalPlaceOfBusiness =
                 new contactDetailsContainerType
             {
                 contactDetails =
                     new contactDetailsType {
                     address = new addressType {
                         country = country
                     }
                 }
             }
         }
     });
 }
예제 #10
0
        public async void GetProducerContact_ReturnsContactWithCorrectAddressDetails()
        {
            string      primary            = "Primary";
            string      secondary          = "Secondary";
            string      street             = "Street";
            string      locality           = "Locality";
            string      admimistrativeArea = "Area";
            string      postCode           = "WE3";
            countryType country            = countryType.UKENGLAND;
            string      countryName        = "UK - ENGLAND";

            var contact = new contactDetailsType()
            {
                address = new addressType()
                {
                    primaryName        = primary,
                    secondaryName      = secondary,
                    streetName         = street,
                    locality           = locality,
                    administrativeArea = admimistrativeArea,
                    Item    = postCode,
                    country = country
                }
            };

            var builder = new GenerateFromXmlBuilder();

            A.CallTo(() => builder.DataAccess.GetCountry(A <string> ._)).Returns(new Country(Guid.NewGuid(), countryName));

            var result = await builder.Build().GetProducerContact(contact);

            var resultAddress = result.Address;

            Assert.Equal(primary, resultAddress.PrimaryName);
            Assert.Equal(secondary, resultAddress.SecondaryName);
            Assert.Equal(street, resultAddress.Street);
            Assert.Equal(locality, resultAddress.Locality);
            Assert.Equal(admimistrativeArea, resultAddress.AdministrativeArea);
            Assert.Equal(postCode, resultAddress.PostCode);
            Assert.Equal(countryName, resultAddress.Country.Name);
        }
예제 #11
0
        public static countryType GetProducerCountry(this producerType producer)
        {
            countryType countryType = new countryType();

            if (producer.producerBusiness != null && producer.producerBusiness.Item != null)
            {
                var producerItem = producer.producerBusiness.Item;

                if (producerItem.GetType() == typeof(companyType))
                {
                    var producerRegisteredOffice = ((companyType)producerItem).registeredOffice;
                    return(countryType = producerRegisteredOffice.contactDetails.address.country);
                }

                if (producerItem.GetType() == typeof(partnershipType))
                {
                    var producerPrincipalBusiness = ((partnershipType)producerItem).principalPlaceOfBusiness;
                    return(countryType = producerPrincipalBusiness.contactDetails.address.country);
                }
            }
            return(countryType);
        }
        public void AuthorisedRepresentativeOfficeCountryIsNotInUnitedKingdom_FailsValidation_AndIncludesProducerNameInMessage_AndErrorLevelIsError()
        {
            const string validTradingName = "MyCompany";

            const countryType someNonUkCountry = countryType.TURKEY;

            var producer = new producerType
            {
                tradingName = validTradingName,
                authorisedRepresentative = new authorisedRepresentativeType
                {
                    overseasProducer = new overseasProducerType()
                },
                producerBusiness = MakeProducerBusinessTypeInCountry(someNonUkCountry)
            };

            var result = Rule().Evaluate(producer);

            Assert.False(result.IsValid);
            Assert.Contains(producer.GetProducerName(), result.Message);
            Assert.Equal(ErrorLevel.Error, result.ErrorLevel);
        }
 private producerBusinessType MakeProducerBusinessTypeInCountry(countryType country)
 {
     return new producerBusinessType
     {
         Item =
             new partnershipType
             {
                 principalPlaceOfBusiness =
                     new contactDetailsContainerType
                     {
                         contactDetails =
                             new contactDetailsType { address = new addressType { country = country } }
                     }
             }
     };
 }
        public void AuthorisedRepresentativeOfficeCountryIsInUnitedKingdom_PassesValidation(countryType someUkCountry)
        {
            var producer = new producerType
            {
                authorisedRepresentative = new authorisedRepresentativeType
                {
                    overseasProducer = new overseasProducerType()
                },
                producerBusiness = MakeProducerBusinessTypeInCountry(someUkCountry)
            };

            var result = Rule().Evaluate(producer);

            Assert.True(result.IsValid);
        }
예제 #15
0
        public string GetCountryName(countryType country)
        {
            string countryName = null;

            // Read the country name from XML attribute if defined
            var countryFirstOrDefault = typeof(countryType).GetMember(country.ToString()).FirstOrDefault();
            if (countryFirstOrDefault != null)
            {
                var countryEnumAttribute = countryFirstOrDefault
                    .GetCustomAttributes(false)
                    .OfType<XmlEnumAttribute>()
                    .FirstOrDefault();
                countryName = countryEnumAttribute != null ? countryEnumAttribute.Name : countryFirstOrDefault.Name;
            }

            return countryName;
        }
        public void GetCountryName_RetrievesCountryNameFromAttributeIfPresent(countryType country, string countryName)
        {
            var builder = new GenerateFromXmlBuilder();
            var result = builder.Build().GetCountryName(country);

            Assert.Equal(countryName, result);
        }
        public createShipmentResponse CreateShipment(PPLabel labelData)
        {
            shippingAPIPortTypeClient client = GetProxy();

            try
            {
                createShipmentRequest request = new createShipmentRequest();
                request.integrationHeader = GetIntegrationHeader();

                requestedShipment shipment = new requestedShipment();

                // Shipment Type Code (Delivery or Return)
                shipment.shipmentType = new referenceDataType()
                {
                    code = SHIPMENT_TYPE
                };;

                // Service Occurence (Identifies Agreement on Customers Account) Default to 1. Not Required If There Is There Is Only 1 On Account
                shipment.serviceOccurrence = SERVICE_OCCURANCE;

                // Service Type Code (1:24H 1st Class, 2: 48H 2nd Class, D: Special Delivery Guaranteed, H: HM Forces (BFPO), I: International, R: Tracked Returns, T: Tracked Domestic)
                referenceDataType serviceType = new referenceDataType();
                serviceType.code     = labelData.IntegrationCode1;
                shipment.serviceType = serviceType;

                // Service Offering (See Royal Mail Service Offering Type Codes. Too Many To List)
                serviceOfferingType serviceOfferingTypeContainer = new serviceOfferingType();
                referenceDataType   serviceOffering = new referenceDataType()
                {
                    code = labelData.IntegrationCode2
                };
                serviceOfferingTypeContainer.serviceOfferingCode = serviceOffering;
                shipment.serviceOffering = serviceOfferingTypeContainer;

                // Service Format Code
                serviceFormatType serviceFormatTypeContainer = new serviceFormatType();
                referenceDataType serviceFormat = new referenceDataType();
                serviceFormat.code = labelData.IntegrationCode3;
                serviceFormatTypeContainer.serviceFormatCode = serviceFormat;
                shipment.serviceFormat = serviceFormatTypeContainer;

                // Shipping Date
                shipment.shippingDate          = DateTime.ParseExact(labelData.ShippingDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);;
                shipment.shippingDateSpecified = true;

                //Signature Required (Only Available On Tracked Services)
                shipment.signature          = labelData.IntegrationCode4;
                shipment.signatureSpecified = true;

                // Leave In Safe Place (Available On Tracked Non Signature Service Offerings)
                shipment.safePlace = labelData.Address.SafePlace;

                // Sender Reference Number (e.g. Invoice Number or RA Number)
                shipment.senderReference = labelData.OrderReference;

                /*
                 * Service Enhancements
                 */

                //List<serviceEnhancementType> serviceEnhancements = new List<serviceEnhancementType>();

                //List<dataObjects.ServiceEnhancement> selectedEnhancements = shippingForm.GetServiceEnhancements();

                //for (int i = 0; i < selectedEnhancements.Count; i++)
                //{
                //    serviceEnhancementType enhancement = new serviceEnhancementType();
                //    referenceDataType enhancementCode = new referenceDataType();
                //    enhancementCode.code = selectedEnhancements.ElementAt(i).GetEnhancementType().ToString();
                //    enhancement.serviceEnhancementCode = enhancementCode;
                //    serviceEnhancements.Add(enhancement);
                //}

                //shipment.serviceEnhancements = serviceEnhancements.ToArray();


                /*
                 * Recipient Contact Details
                 */

                contact recipientContact = new contact()
                {
                    name = labelData.Address.ContactName,
                    complementaryName = labelData.Address.CompanyName
                };

                if (string.IsNullOrWhiteSpace(labelData.Address.Email) == false)
                {
                    digitalAddress email = new digitalAddress();
                    email.electronicAddress            = labelData.Address.Email;
                    recipientContact.electronicAddress = email;
                }

                if (string.IsNullOrWhiteSpace(labelData.Address.Phone) == false)
                {
                    telephoneNumber tel = new telephoneNumber();

                    Regex phoneRegex = new Regex(@"[^\d]");
                    tel.telephoneNumber1 = phoneRegex.Replace(labelData.Address.Phone, "");
                    // TODOP unhardcode dialing code
                    //tel.countryCode = "00" + shippingForm.GetCountry().GetDialingCode();
                    tel.countryCode = "00" + "44";
                    recipientContact.telephoneNumber = tel;
                }

                shipment.recipientContact = recipientContact;

                /*
                 * Recipient Address
                 *
                 */
                address recipientAddress = new address();
                recipientAddress.addressLine1 = labelData.Address.AddLine1;
                recipientAddress.addressLine2 = labelData.Address.AddLine2;
                //recipientAddress.addressLine3 = shippingForm.GetAddressLine3();
                //recipientAddress.addressLine4 = shippingForm.GetCounty();
                recipientAddress.postTown = labelData.Address.Town;
                countryType       country     = new countryType();
                referenceDataType countryCode = new referenceDataType();
                countryCode.code          = labelData.Address.CountryCodeIso2;
                country.countryCode       = countryCode;
                recipientAddress.country  = country;
                recipientAddress.postcode = labelData.Address.Postcode;

                //recipientAddress.stateOrProvince = new stateOrProvinceType();
                //recipientAddress.stateOrProvince.stateOrProvinceCode = new referenceDataType();

                shipment.recipientAddress = recipientAddress;

                // Shipment Items

                if ("I".Equals(labelData.IntegrationCode1)) // International shipment
                {
                    internationalInfo InternationalInfo = new internationalInfo();
                    InternationalInfo.shipperExporterVatNo = "GB945777273";
                    InternationalInfo.documentsOnly        = false;
                    InternationalInfo.shipmentDescription  = "Invoice Number: " + labelData.OrderReference;
                    InternationalInfo.invoiceDate          = DateTime.Now;
                    //InternationalInfo.termsOfDelivery = "EXW"; // TODOP don't know what it is
                    InternationalInfo.invoiceDateSpecified = true;
                    InternationalInfo.purchaseOrderRef     = labelData.OrderReference;

                    List <parcel> parcels = new List <parcel>();
                    foreach (var i in labelData.Items)
                    {
                        parcel Parcel = new parcel();
                        Parcel.weight               = new dimension();
                        Parcel.weight.value         = (float)(i.Weight);
                        Parcel.weight.unitOfMeasure = new unitOfMeasureType();
                        Parcel.weight.unitOfMeasure.unitOfMeasureCode      = new referenceDataType();
                        Parcel.weight.unitOfMeasure.unitOfMeasureCode.code = "g";

                        Parcel.invoiceNumber          = labelData.OrderReference;
                        Parcel.purposeOfShipment      = new referenceDataType();
                        Parcel.purposeOfShipment.code = "31";

                        List <contentDetail> Contents = new List <contentDetail>();

                        // Harcoded all these values according to my circumstances
                        contentDetail ContentDetail = new contentDetail();
                        ContentDetail.articleReference                      = "O";
                        ContentDetail.countryOfManufacture                  = new countryType();
                        ContentDetail.countryOfManufacture.countryCode      = new referenceDataType();
                        ContentDetail.countryOfManufacture.countryCode.code = "GB";

                        ContentDetail.currencyCode             = new referenceDataType();
                        ContentDetail.currencyCode.code        = "GBP";
                        ContentDetail.description              = "Printed goods";
                        ContentDetail.unitQuantity             = "1";
                        ContentDetail.unitValue                = Convert.ToDecimal(i.Price / 100.00m);
                        ContentDetail.unitWeight               = new dimension();
                        ContentDetail.unitWeight.value         = Convert.ToSingle(i.Weight);
                        ContentDetail.unitWeight.unitOfMeasure = new unitOfMeasureType();
                        ContentDetail.unitWeight.unitOfMeasure.unitOfMeasureCode      = new referenceDataType();
                        ContentDetail.unitWeight.unitOfMeasure.unitOfMeasureCode.code = "g";


                        Contents.Add(ContentDetail);

                        Parcel.contentDetails = Contents.ToArray();

                        parcels.Add(Parcel);
                    }

                    InternationalInfo.parcels = parcels.ToArray();

                    shipment.internationalInfo = InternationalInfo;
                }
                else
                {
                    List <RoyalMailApiWsdl.item> items = new List <RoyalMailApiWsdl.item>();

                    foreach (var i in labelData.Items)
                    {
                        RoyalMailApiWsdl.item item = new RoyalMailApiWsdl.item();
                        item.numberOfItems = "1";
                        item.weight        = new dimension();
                        item.weight.value  = (float)(i.Weight);

                        item.weight.unitOfMeasure = new unitOfMeasureType();
                        item.weight.unitOfMeasure.unitOfMeasureCode      = new referenceDataType();
                        item.weight.unitOfMeasure.unitOfMeasureCode.code = "g";

                        items.Add(item);
                    }
                    shipment.items = items.ToArray();
                }

                request.requestedShipment = shipment;
                // http://stackoverflow.com/questions/897782/how-to-add-custom-http-header-for-c-sharp-web-service-client-consuming-axis-1-4
                //XmlHelper.Serialise<createShipmentRequest>(request, @"C:\test\createShipmentRequest.xml");
                using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
                {
                    var httpRequestProperty = new HttpRequestMessageProperty();
                    httpRequestProperty.Headers.Add(@"X-IBM-Client-Id", _credentials.HttpSecurity.ClientId);
                    httpRequestProperty.Headers.Add(@"X-IBM-Client-Secret", _credentials.HttpSecurity.ClientSecret);
                    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;

                    createShipmentResponse response = client.createShipment(GetSecurityHeaderType(), request);
                    CheckErrorsAndWarnings(response.integrationFooter);
                    //XmlHelper.Serialise(request, @"c:\test\createShipmentRequest.xml");
                    //XmlHelper.Serialise(response, @"c:\test\createShipmentResponse.xml");
                    return(response);
                }
            }
            catch (TimeoutException e)
            {
                client.Abort();
                _log.Error("Request timed out", e);
            }
            catch (FaultException e)
            {
                client.Abort();
                LogSoapException(e);
            }
            catch (CommunicationException e)
            {
                client.Abort();
                _log.Error("A communication error has occured", e);
            }
            catch (Exception e)
            {
                client.Abort();
                _log.Error("Royal Mail Api error", e);
            }

            return(null);
        }