Пример #1
0
        static void Main(string[] args)
        {
            try
            {
                Mercedes a = new Mercedes("Mercedes", "CLA", 40000);
                a.Print();
                a.newPrice(15555);
                Mercedes b        = new Mercedes("Mercedes", "Vito", 54587);
                Audi     c        = new Audi("Audi", "A4", "Shooting Brake");
                Audi     d        = new Audi("Audi", "R8", "Roadster");
                Car[]    CarArray = { a, b, new Mercedes("Mercedes", "A180", 16734), c, d, new Audi("TestAudi", "TestModel", "TestCarBodyDesign") }; //Task 3.4.1

                foreach (Car Car in CarArray)                                                                                                        //Task 3.4.2
                {
                    Car.Print();
                }

                var jsonsettings = new JsonSerializerSettings()
                {
                    Formatting = Formatting.Indented, TypeNameHandling = TypeNameHandling.Auto
                };                                                                                                                              //Task 4.3
                var json = JsonConvert.SerializeObject(CarArray, jsonsettings);
                Console.WriteLine(json);

                var itemsfromjson = JsonConvert.DeserializeObject <Car[]>(json, jsonsettings); //Task 4.3
                foreach (var Actuator in itemsfromjson)
                {
                    Actuator.Print();
                }
            }
            catch (Exception error)
            {
                Console.WriteLine($"Error({ error.Message})");
            }
        }
Пример #2
0
 public void CannotCreateWithoutMake2()
 {
     Assert.Catch(() =>
     {
         var x = new Audi("", "CLA", "Roadster");
     });
 }
Пример #3
0
 public void CannotCreateWithoutModel2()
 {
     Assert.Catch(() =>
     {
         var x = new Audi("Audi", "", "Roadster");
     });
 }
Пример #4
0
        public void CanCreateAudi()
        {
            var x = new Audi("Audi", "R8", "Roadster");

            Assert.IsTrue(x.Make == "Audi");
            Assert.IsTrue(x.Model == "R8");
            Assert.IsTrue(x.CarBodyDesign == "Roadster");
        }