Ejemplo n.º 1
0
        public void parcel_with_weight_over_10kg_should_be_routed_via_heavy_department(double parcelWeight)
        {
            var parcelHandler = new ParcelHandler();

            parcelHandler.GetParcelRoutes(new Parcel("someId", "1234AB", "1a", parcelWeight, 0))
            .Single()
            .Departments.Should().BeEquivalentTo("Heavy");
        }
Ejemplo n.º 2
0
        public void parcels_with_weight_up_to_1kg_should_be_routed_via_mail_department(double parcelWeight)
        {
            var parcelHandler = new ParcelHandler();

            parcelHandler.GetParcelRoutes(new Parcel("someId", "1234AB", "1a", parcelWeight, 0))
            .Single()
            .Departments.Should().BeEquivalentTo("Mail");
        }
Ejemplo n.º 3
0
        public void parcel_with_a_declared_value_over_1k_euro_should_be_routed_via_the_insurance_department_first()
        {
            var parcelHandler = new ParcelHandler();

            parcelHandler.GetParcelRoutes(new Parcel("someId", "1234AB", "1a", 10.01, 1000.01))
            .Single()
            .Departments.Should()
            .BeEquivalentTo(new [] { "Insurance", "Heavy" }, opt => opt
                            .WithStrictOrdering());
        }
Ejemplo n.º 4
0
        public void parcel_routes_should_contain_original_parcel_information()
        {
            var parcel = new Parcel("some Id", "1234 AB", "1 a", 0.2, 0);

            var parcelHandler = new ParcelHandler();

            parcelHandler.GetParcelRoutes(parcel)
            .Single()
            .Should().BeEquivalentTo(parcel);
        }
Ejemplo n.º 5
0
 public override void Handle(ParcelHandler pacco)
 {
     if (pacco.Value > 1000 && pacco.Weight > 10)
     {
         Console.WriteLine($"€{pacco.Value} e weight: {pacco.Weight} ----> INSURANCE department and then to HEAVY department");
     }
     else if (pacco.Weight > 10)
     {
         Console.WriteLine($"Weight: {pacco.Weight} ----> HEAVY department");
     }
 }
Ejemplo n.º 6
0
 public override void Handle(ParcelHandler pacco)
 {
     if (pacco.Value > 1000 && pacco.Weight < 10)
     {
         Console.WriteLine($"€{pacco.Value} e weight: {pacco.Weight} ---> INSURANCE department and then to REGULAR department");
     }
     else if (pacco.Weight > 1 && pacco.Weight < 10)
     {
         Console.WriteLine($"Weight: {pacco.Weight} ----> REGULAR department");
     }
     else if (_nextHandler != null)
     {
         _nextHandler.Handle(pacco);
     }
 }
Ejemplo n.º 7
0
        public static void Main(string[] args)
        {
            var parcelStore = new EmbeddedResourceParcelStore();

            var parcelHandler = new ParcelHandler();

            foreach (var parcelRoute in parcelHandler.GetParcelRoutes(parcelStore.GetAll().ToArray()))
            {
                Console.WriteLine("=========================");
                Console.WriteLine($"Parcel: {parcelRoute.PostalCode}-{parcelRoute.HouseNumber}-{parcelRoute.Id}");
                Console.WriteLine($"- weight                         : {parcelRoute.Weight}");
                Console.WriteLine($"- declared value                 : {parcelRoute.DeclaredValue}");
                Console.WriteLine($"- department route (strict order): {string.Join(",", parcelRoute.Departments)}");
                Console.WriteLine();
            }

            Console.WriteLine("Press enter to exit.");
            Console.ReadLine();
        }
Ejemplo n.º 8
0
 public abstract void Handle(ParcelHandler pacco);
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            XmlTextReader reader = new XmlTextReader("Container_1.xml");

            #region
            //while (reader.Read())
            //{
            //    switch (reader.NodeType)
            //    {
            //        case XmlNodeType.Element: // The node is an element.
            //            Console.Write("<" + reader.Name);
            //            Console.WriteLine(">");
            //            break;
            //        case XmlNodeType.Text: //Display the text in each element.
            //            Console.WriteLine(reader.Value);
            //            break;
            //        case XmlNodeType.EndElement: //Display the end of the element.
            //            Console.Write("</" + reader.Name);
            //            Console.WriteLine(">");
            //            break;
            //    }
            //}

            //while (reader.Read())
            //{
            //    switch (reader.NodeType)
            //    {
            //        case XmlNodeType.Element: // The node is an element.
            //            Console.Write("<" + reader.Name);

            //            while (reader.MoveToNextAttribute()) // Read the attributes.
            //                Console.Write(" " + reader.Name + "='" + reader.Value + "'");
            //            Console.WriteLine(">");
            //            break;
            //        case XmlNodeType.Text: //Display the text in each element.
            //            Console.WriteLine(reader.Value);
            //            break;
            //        case XmlNodeType.EndElement: //Display the end of the element.
            //            Console.Write("</" + reader.Name);
            //            Console.WriteLine(">");
            //            break;
            //    }
            //}

            //while (reader.Read())
            //{
            //    switch (reader.NodeType)
            //    {
            //        case XmlNodeType.Element:
            //            Console.WriteLine(reader.Name);
            //
            //            break;
            //        case XmlNodeType.Text:
            //            Console.WriteLine("SECONDO CASE "+ reader.Value);
            //            break;
            //    }
            //}
            #endregion

            Handler mail    = new Mail();
            Handler regular = new Regular();
            Handler heavy   = new Heavy();

            mail.SetNext(regular);
            regular.SetNext(heavy);



            string    path     = @"C:\Git\DeliveryCompany\DeliveryCompany\Container_1.xml";
            XDocument doc      = XDocument.Load(path);
            string    jsonText = JsonConvert.SerializeXNode(doc);

            var rootObj = JsonConvert.DeserializeObject <MyXmlObj.RootObj>(jsonText);



            #region --------------------FOR IF SWITCH-----------------------
            //for (int i = 0; i < 4; i++)
            //{
            //    string peso = rootObj.Container.Parcels.Parcel[i].Weight;
            //    double Peso = Convert.ToDouble(peso, new CultureInfo("en-US"));
            //    string val = rootObj.Container.Parcels.Parcel[i].Value;
            //    double Valore = Convert.ToDouble(val, new CultureInfo("en-US"));
            //    Console.WriteLine("Pacco " + i + ":---> peso: " + Peso + "   valore €: " + Valore);
            //    int X = 4;

            //    if (Valore > 1000)
            //    {
            //        X = 0;
            //    }
            //    else if (Peso < 1)
            //    {
            //        X = 1;
            //    }
            //    else if (Peso > 1 && Peso < 10)
            //    {
            //        X = 2;
            //    }
            //    else if (Peso > 10)
            //    {
            //        X = 3;
            //    }
            //    switch (X)
            //    {
            //        case 0:
            //            if (Peso < 1)
            //            {
            //                Console.WriteLine("Go to INSURANCE department and then to MAIL department");
            //            }
            //            else if (Peso > 1 && Peso < 10)
            //            {
            //                Console.WriteLine("Go to INSURANCE department and then to REGULAR department");
            //            }
            //            else if (Peso > 10)
            //            {
            //                Console.WriteLine("Go to INSURANCE department and then to HEAVY department");
            //            }
            //            break;
            //        case 1:
            //            Console.WriteLine("Go to MAIL department");
            //            break;
            //        case 2:
            //            Console.WriteLine("Go to REGULAR department");
            //            break;
            //        case 3:
            //            Console.WriteLine("Go to HEAVY department");
            //            break;
            //        case 4:
            //            Console.WriteLine("Pacco non accettato");
            //            break;
            //    }
            //}
            #endregion
            int y = rootObj.Container.Parcels.Parcel.Count;
            for (int p = 0; p < y; p++)
            {
                string mittente     = rootObj.Container.Parcels.Parcel[p].Sender.Name;
                string destinatario = rootObj.Container.Parcels.Parcel[p].Receipient.Name;
                double Peso         = Convert.ToDouble(rootObj.Container.Parcels.Parcel[p].Weight, new CultureInfo("en-US"));
                double Valore       = Convert.ToDouble(rootObj.Container.Parcels.Parcel[p].Value, new CultureInfo("en-US"));

                ParcelHandler paccoFile = new ParcelHandler(mittente, destinatario, Peso, Valore);
                mail.Handle(paccoFile);
                Console.WriteLine($"Mittente: {paccoFile.Sender} -- Destinatario: {paccoFile.Receipient}");
                Console.WriteLine("___________________________________________________________________________________________________");
                //regular.Handle(paccoFile);
                //heavy.Handle(paccoFile);
            }
        }