public void TestSteelProtector()
        {
            //Arrange
            Init();
            SteelProtector steel = new SteelProtector(_testoutput);

            //Act
            steel.Put(null);

            //Assert
            string expected = "Phone is covered with SteelProtector";

            Assert.AreEqual(_testoutput.CapturedOutput, expected);
        }
Esempio n. 2
0
        private void ApplyButton_Click(object sender, EventArgs e)
        {
            _clickNum++;
            switch (_clickNum)
            {
            case 1:
                IPlayback playback;
                if (Option1.Checked)
                {
                    playback = new MeizuHeadset(output);
                }
                else if (Option2.Checked)
                {
                    playback = new SamsungHeadset(output);
                }
                else if (Option3.Checked)
                {
                    playback = new UnofficialiPhoneHeadset(output);
                }
                else if (Option4.Checked)
                {
                    playback = new PortableSpeaker(output);
                }
                else
                {
                    throw new ArgumentOutOfRangeException();
                }
                phone.PlaybackComponent = playback;
                output.WriteLine($"{playback.GetType().Name} playback selected");
                output.WriteLine("Set playback to Mobile...");
                output.WriteLine("Play sound in Mobile:");
                phone.Play("Song");
                FormTopLabel    = "Select charger component (specify index):";
                FormOption1     = "1 - SamsungCharger";
                FormOption2     = "2 - MeizuCharger";
                FormOption3     = "3 - OfficialiPhoneCharger";
                FormOption4     = "";
                Option1.Checked = true;
                break;

            case 2:
                output.WriteLine("");
                ICharger charger;
                if (Option1.Checked)
                {
                    charger = new SamsungCharger(output);
                }
                else if (Option2.Checked)
                {
                    charger = new MeizuCharger(output);
                }
                else if (Option3.Checked)
                {
                    charger = new OfficialiPhoneCharger(output);
                }
                else
                {
                    throw new ArgumentOutOfRangeException();
                }
                phone.ChargerComponent = charger;
                output.WriteLine($"{charger.GetType().Name} selected");
                output.WriteLine("Plug in charger to Mobile:");
                phone.InnerCharge(null);
                FormTopLabel    = "Select protector component (specify index):";
                FormOption1     = "1 - LeatherProtector";
                FormOption2     = "2 - SteelProtector";
                FormOption3     = "";
                FormOption4     = "";
                Option1.Checked = true;
                break;

            case 3:
                output.WriteLine("");
                IProtector protector;
                if (Option1.Checked)
                {
                    protector = new LeatherProtector(output);
                }
                else if (Option2.Checked)
                {
                    protector = new SteelProtector(output);
                }
                else
                {
                    throw new ArgumentOutOfRangeException();
                }
                phone.ProtectorComponent = protector;
                output.WriteLine($"{protector.GetType().Name} selected");
                output.WriteLine("Put protector on Mobile:");
                phone.Put(protector);
                break;
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            IOutput output = new ConsoleOutput();

            MobilePhone phone;

            phone = new SimCorpMobile();
            output.WriteLine(phone.GetDescription());

            output.WriteLine("");
            output.WriteLine("Select playback component (specify index):");
            output.WriteLine("1 - MeizuHeadset");
            output.WriteLine("2 - SamsungHeadset");
            output.WriteLine("3 - UnofficialiPhoneHeadset");
            output.WriteLine("4 - PortableSpeaker");

            int  value;
            bool isBadInput;

            do
            {
                isBadInput = !int.TryParse(Console.ReadLine(), out value);
                if (isBadInput || value > 4 || value < 1)
                {
                    output.WriteLine("Wrong value, please try again: ");
                    isBadInput = true;
                }
            } while (isBadInput);

            IPlayback playback;

            switch (value)
            {
            case 1:
                playback = new MeizuHeadset(output);
                break;

            case 2:
                playback = new SamsungHeadset(output);
                break;

            case 3:
                playback = new UnofficialiPhoneHeadset(output);
                break;

            case 4:
                playback = new PortableSpeaker(output);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            phone.PlaybackComponent = playback;
            output.WriteLine($"{playback.GetType().Name} playback selected");
            output.WriteLine("Set playback to Mobile...");
            output.WriteLine("Play sound in Mobile:");
            phone.Play("Song");

            //next

            output.WriteLine("");
            output.WriteLine("Select charger component (specify index):");
            output.WriteLine("1 - SamsungCharger");
            output.WriteLine("2 - MeizuCharger");
            output.WriteLine("3 - OfficialiPhoneCharger");

            do
            {
                isBadInput = !int.TryParse(Console.ReadLine(), out value);
                if (isBadInput || value > 3 || value < 1)
                {
                    output.WriteLine("Wrong value, please try again: ");
                    isBadInput = true;
                }
            } while (isBadInput);

            ICharger charger;

            switch (value)
            {
            case 1:
                charger = new SamsungCharger(output);
                break;

            case 2:
                charger = new MeizuCharger(output);
                break;

            case 3:
                charger = new OfficialiPhoneCharger(output);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            phone.ChargerComponent = charger;
            output.WriteLine($"{charger.GetType().Name} selected");
            output.WriteLine("Plug in charger to Mobile:");
            phone.Charge(null);

            //next

            output.WriteLine("");
            output.WriteLine("Select protector component (specify index):");
            output.WriteLine("1 - LeatherProtector");
            output.WriteLine("2 - SteelProtector");

            do
            {
                isBadInput = !int.TryParse(Console.ReadLine(), out value);
                if (isBadInput || value > 2 || value < 1)
                {
                    output.WriteLine("Wrong value, please try again: ");
                    isBadInput = true;
                }
            } while (isBadInput);

            IProtector protector;

            switch (value)
            {
            case 1:
                protector = new LeatherProtector(output);
                break;

            case 2:
                protector = new SteelProtector(output);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            phone.ProtectorComponent = protector;
            output.WriteLine($"{protector.GetType().Name} selected");
            output.WriteLine("Put protector on Mobile:");
            phone.Put(protector);

            Console.ReadLine();
        }