Beispiel #1
0
        public void UpdateDiameterTest()
        {
            Snaredrum SnareTest = new Snaredrum("Wood", 38.6M, "cm", "pinned");

            SnareTest.UpdateDiameter(22M, "inch");
            Assert.IsTrue(SnareTest.Unit == "inch");
            Assert.IsTrue(SnareTest.Diameter == 22M);
        }
Beispiel #2
0
        public void UpdateDiameterNegativeDiameterTest()
        {
            Snaredrum SnareTest = new Snaredrum("Wood", 38.6M, "cm", "pinned");
            //"Diameter must not be negative" is parameter of Exception --> test parameter
            var excpt = Assert.Throws <ArgumentOutOfRangeException>(() => SnareTest.UpdateDiameter(-22M, "inch"));

            Assert.That(excpt.ParamName, Is.EqualTo("Diameter must not be negative"));
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            //create objects with 'new'-operator
            Snaredrum SnareJazzset = new Snaredrum("Wood", 38.6M, "cm", "pinned");
            Basedrum  BaseRockset  = new Basedrum("   Wood", 22M, "inch", "single");
            Basedrum  BaseMetalset = new Basedrum("Wood", 24M, "inch", "double");

            //print properties of objects to console using Console.Writeline
            Console.WriteLine(SnareJazzset.ToString());
            Console.WriteLine(BaseRockset.ToString());
            Console.WriteLine(BaseMetalset.ToString());

            //call methods on objects an print effects to console
            SnareJazzset.UpdateDiameter(14, "inch");
            Console.WriteLine("");
            Console.WriteLine("Changed part: " + SnareJazzset.ToString());

            //Create an array containing a mix of instances of all your classes which implement this interface
            var parts = new IDrumParts[]
            {
                new Snaredrum("Metal", 18M, "inch", "pinned"),
                //new Basedrum ("Wood", 22M, "inch", "double"),
                new Snaredrum("Wood", 16M, "inch", "loosened"),
                new Snaredrum("Metal", 56M, "cm", "loosened"),
            };

            Console.WriteLine("");

            //add some test code similar to the lesson3 example (e.g. a loop which prints properties or returns values of method calls)
            foreach (var x in parts)
            {
                Console.WriteLine(x.ToString());
            }

            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.TypeNameHandling = TypeNameHandling.Auto;
            settings.Formatting       = Formatting.Indented;

            using (System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(System.IO.File.Open(@"C:\Users\Lara\Documents\FH Technikum\2. Semester\Objektorientierte Methoden\oom\tasks\Task4\parts.json", System.IO.FileMode.Create)))
            {
                streamWriter.Write(JsonConvert.SerializeObject(parts, settings));
                streamWriter.Flush();
            }

            string json = System.IO.File.ReadAllText(@"C:\Users\Lara\Documents\FH Technikum\2. Semester\Objektorientierte Methoden\oom\tasks\Task4\parts.json");

            Snaredrum[] readParts = JsonConvert.DeserializeObject <Snaredrum[]>(json, settings);
            Console.WriteLine(json);
        }