Exemple #1
0
        public void Create_valid_MailPersonInformation_must_succeed()
        {
            //Arrange & Act
            var mailPersonInformation = new MailPersonInformation(_validIsCompany, _validName, _validAddress);

            //Assert
            Assert.NotNull(mailPersonInformation);
        }
Exemple #2
0
        public static (List <Parcel>, List <string>) ToDomainModelList(string encodedBase64)
        {
            var        parcelsDomain    = new List <Parcel>();
            var        convertionErrors = new List <string>();
            XNamespace ns            = "http://www.w3.org/2001/XMLSchema-instance";
            var        decodedBase64 = new Base64Converter().DecodeFromBase64(encodedBase64);
            var        xmlParcel     = new XMLConverter().CreateXML(decodedBase64);
            var        parcels       = xmlParcel.Descendants("Parcel");

            var count = 0;

            foreach (var parcel in parcels)
            {
                try
                {
                    var sender            = parcel.Element("Sender");
                    var receipient        = parcel.Element("Receipient");
                    var senderAddress     = sender.Element("Address");
                    var receipientAddress = receipient.Element("Address");
                    var isCompany         = sender.HasAttributes ? sender.Attribute(ns + "type")?.Value == "Company" : false;

                    var senderMailInformation = new MailPersonInformation(
                        isCompany,
                        sender.Element("Name").Value,
                        new Address(senderAddress.Element("Street").Value,
                                    senderAddress.Element("HouseNumber").Value,
                                    senderAddress.Element("PostalCode").Value,
                                    senderAddress.Element("City").Value)
                        );
                    var receipientMailInformation = new MailPersonInformation(
                        isCompany,
                        receipient.Element("Name").Value,
                        new Address(receipientAddress.Element("Street").Value,
                                    receipientAddress.Element("HouseNumber").Value,
                                    receipientAddress.Element("PostalCode").Value,
                                    receipientAddress.Element("City").Value)
                        );

                    var parcelDomain = new Parcel(
                        Convert.ToDouble(parcel.Element("Weight").Value),
                        Convert.ToDouble(parcel.Element("Value").Value),
                        senderMailInformation,
                        receipientMailInformation
                        );

                    parcelsDomain.Add(parcelDomain);
                }
                catch (System.Exception ex)
                {
                    convertionErrors.Add($"Error converting parcel on index {count}: {ex.Message}");
                }

                count++;
            }

            return(parcelsDomain, convertionErrors);
        }