Example #1
0
            public void PrintReturnRecipientFromNorwegianAddress()
            {
                //Arrange
                var source = new PrintReturnRecipient(
                    "Name",
                    new NorwegianAddress("0001", "Oslo", "Addr1", "Addr2", "Addr3"));

                var expectedDto = new printrecipient
                {
                    name = source.Name,
                    Item = new norwegianaddress
                    {
                        zipcode      = ((NorwegianAddress)source.Address).PostalCode,
                        city         = ((NorwegianAddress)source.Address).City,
                        addressline1 = source.Address.AddressLine1,
                        addressline2 = source.Address.AddressLine2,
                        addressline3 = source.Address.AddressLine3
                    }
                };

                //Act
                var actualDto = DataTransferObjectConverter.ToDataTransferObject(source);

                //Assert
                Comparator.AssertEqual(expectedDto, actualDto);
            }
Example #2
0
            public void PrintReturnRecipientFromForeignAddress()
            {
                //Arrange
                var source = new PrintReturnRecipient(
                    "Name",
                    new ForeignAddress(
                        CountryIdentifier.Country,
                        "NORGE",
                        "Adresselinje1",
                        "Adresselinje2",
                        "Adresselinje3",
                        "Adresselinje4"
                        ));

                var expectedDto = new printrecipient
                {
                    name = source.Name,
                    Item = new foreignaddress
                    {
                        ItemElementName = ItemChoiceType2.country,
                        Item            = ((ForeignAddress)source.Address).CountryIdentifierValue,
                        addressline1    = source.Address.AddressLine1,
                        addressline2    = source.Address.AddressLine2,
                        addressline3    = source.Address.AddressLine3,
                        addressline4    = ((ForeignAddress)source.Address).Addressline4
                    }
                };

                //Act
                var actualDto = DataTransferObjectConverter.ToDataTransferObject(source);

                //Assert
                Comparator.AssertEqual(expectedDto, actualDto);
            }
        private static printrecipient ToDataTransferObject(IPrint recipient)
        {
            var printRecipientDto = new printrecipient
            {
                name = recipient.Name
            };

            if (recipient.Address is INorwegianAddress)
            {
                printRecipientDto.Item = ToDataTransferObject((INorwegianAddress)recipient.Address);
            }
            else
            {
                printRecipientDto.Item = ToDataTransferObject((IForeignAddress)recipient.Address);
            }

            return(printRecipientDto);
        }
        public static printrecipient ToDataTransferObject(Print.Print printOrPrintReturnRecipient)
        {
            var printRecipientDataTransferObject = new printrecipient
            {
                name = printOrPrintReturnRecipient.Name
            };

            var addressType = printOrPrintReturnRecipient.Address.GetType();

            if (typeof(INorwegianAddress).IsAssignableFrom(addressType))
            {
                var address = printOrPrintReturnRecipient.Address as NorwegianAddress;
                printRecipientDataTransferObject.Item = ToDataTransferObject(address);
            }
            else
            {
                var address = printOrPrintReturnRecipient.Address as ForeignAddress;
                printRecipientDataTransferObject.Item = ToDataTransferObject(address);
            }

            return(printRecipientDataTransferObject);
        }