Esempio n. 1
0
        public void DolphinsHaveLiveBirths() //inherited from mammal class
        {
            Dolphins dolphins = new Dolphins();
            string   birth    = dolphins.Birth;

            Assert.Equal("live birth", birth);
        }
Esempio n. 2
0
        public void DolphinHasNoLegsOverridesVirtual()
        {
            Dolphins dolphins = new Dolphins();
            bool     cannot   = dolphins.HasLegs;

            Assert.False(cannot);
        }
Esempio n. 3
0
        public void DolphinCanMakeNoise() //inherited from animal class
        {
            Dolphins dolphins = new Dolphins();
            string   gulb     = dolphins.Sound();

            Assert.Equal("I make a GLUB GLUB GLUB sound in the water.", gulb);
        }
Esempio n. 4
0
        public void DolphinCantRunOverridesVirtual()
        {
            Dolphins dolphins = new Dolphins();
            bool     cannot   = dolphins.CanRun();

            Assert.False(cannot);
        }
Esempio n. 5
0
        /// <summary>
        /// This method shows an example of interface methods being implemented
        /// </summary>
        public static void WeCanSwim()
        {
            ISwim[] swim = new ISwim[2];

            // Creating new Hippo Objects
            Hippo hiphop = new Hippo()
            {
                Name = "Hippy the Hippo", HoldBreathAmount = 5
            };
            Dolphins dolphins = new Dolphins()
            {
                Name = "Fin", HoldBreathAmount = 10
            };

            swim[0] = hiphop;
            swim[1] = dolphins;

            // for loop that will loop through the swim array and will call the interface methods that are
            //implemented in the classes
            for (int i = 0; i < swim.Length; i++)
            {
                var aniSwimming = swim[i];

                if (aniSwimming is Hippo)
                {
                    var h = (Hippo)aniSwimming;
                    Console.WriteLine($"My name is {h.Name} and I can hold my breath for {h.HoldBreathAmount} minutes!");
                    Console.WriteLine(h.WiggleBody());
                    Console.WriteLine(h.Float());
                    Console.ReadLine();
                }
                else if (aniSwimming is Dolphins)
                {
                    var d = (Dolphins)aniSwimming;
                    Console.WriteLine();
                    Console.WriteLine($"Hi! My name is {d.Name}!");
                    Console.WriteLine(d.WiggleBody());
                    Console.WriteLine(d.Float());
                    Console.ReadLine();
                }
            }
        }