コード例 #1
0
        public void SamsungCharger_IsInProgress()
        {
            // Arrange / Act
            IOutput  output  = new OutputMock();
            ICharger charger = new SamsungCharger(output);

            charger.Charge(output);

            var expectedString = "SamsungCharger in progress\r\n";

            //Assert
            Assert.AreEqual(expectedString, output.Output.ToString());
        }
コード例 #2
0
        public void TestSamsungCharger()
        {
            //Arrange
            Init();
            SamsungCharger samsung = new SamsungCharger(_testoutput);

            //Act
            samsung.Charge(null);

            //Assert
            string expected = "Phone is charging with SamsungCharger";

            Assert.AreEqual(_testoutput.CapturedOutput, expected);
        }
コード例 #3
0
        public void SamsungChargerTest()
        {
            var     mobile           = new SimCorpMobilePhone();
            var     consoleOutput    = new ConsoleOutput();
            ICharge chargerComponent = new SamsungCharger(consoleOutput);

            mobile.ChargerComponent = chargerComponent;
            var expected1 = "SamsungCharger selected";
            var actual1   = consoleOutput.textTest;

            Assert.AreEqual(expected1, actual1);
            mobile.Charge();
            var expected = "Charging by SamsungCharger";
            var actual   = consoleOutput.textTest;

            Assert.AreEqual(expected, actual);
        }
コード例 #4
0
        private void SetChargeComponentToMobile(WinFormOuput winformOutput)
        {
            ICharge chargeComponent = null;

            if (radioButton1.Checked)
            {
                chargeComponent = new iPhoneCharger(winformOutput);
            }
            else if (radioButton2.Checked)
            {
                chargeComponent = new SamsungCharger(winformOutput);
            }
            else if (radioButton3.Checked)
            {
                chargeComponent = new UnofficialiPhoneCharger(winformOutput);
            }
            mobile.ChargerComponent = chargeComponent;
            winformOutput.WriteLine("Set charger to Mobile...");
            mobile.Charge();
        }
コード例 #5
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;
            }
        }
コード例 #6
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();
        }