public void TestPhoneAddPartWithInvalidPart()
        {
            Phone phone  = new Phone("iPhone");
            IPart pcPart = new PCPart("Keyboard", 13);

            Assert.Throws <InvalidOperationException>(() => phone.AddPart(pcPart));
        }
示例#2
0
        public void TestShouldNotBeAbleToAddNonPhonePart()
        {
            IPart       pcPart = new PCPart("CD", 10m);
            IRepairable phone  = new Phone(makeTest);

            Assert.Throws <InvalidOperationException>(() => phone.AddPart(pcPart));
        }
示例#3
0
        public void TestShouldNotBeAbleToAddNonLaptopPart()
        {
            IPart       pcPart = new PCPart("CD", 10m);
            IRepairable laptop = new Laptop(makeTest);

            Assert.Throws <InvalidOperationException>(() => laptop.AddPart(pcPart));
        }
        public void TestAddPartLaptopWithNonLaptopPart()
        {
            IPart  part = new PCPart("GPU", 150, false);
            string expectedExceptionMessage = $"You cannot add {part.GetType().Name} to {this.laptop.GetType().Name}!";

            Assert.That(() => this.laptop.AddPart(part), Throws.InvalidOperationException.With.Message.EqualTo(expectedExceptionMessage));
        }
示例#5
0
        public void PCPartReportShouldReturnStringContainingNameCostAndIsBrokenPropertiesAsPartOfIt()
        {
            var pcPart = new PCPart("ram", 100m, true);

            StringAssert.Contains($"{pcPart.Name}", pcPart.Report(), "Report string doesn't contain Name property");
            StringAssert.Contains($"{pcPart.Cost}", pcPart.Report(), "Report string doesn't contain Cost property");
            StringAssert.Contains($"{pcPart.IsBroken}", pcPart.Report(), "Report string doesn't contain IsBroken property");
        }
示例#6
0
        public void TestPCPartShouldBeInstantiatedWith3parameters()
        {
            IPart pcPart = new PCPart(PartName, PartCost, PartIsBroken);

            Assert.AreEqual(PartName, pcPart.Name);
            Assert.AreEqual((PartCost * multiplierPCPart), pcPart.Cost);
            Assert.AreEqual(PartIsBroken, pcPart.IsBroken);
        }
        public void PcPartRepairShouldWorksCorrectly()
        {
            var part = new PCPart("JustLaptopPart", 2.50M, true);

            part.Repair();

            Assert.IsFalse(part.IsBroken);
        }
示例#8
0
        public void TestRepairPCPartShouldFixBrokenPart()
        {
            IPart pcPart = new PCPart(PartName, PartCost);

            pcPart.Repair();

            Assert.IsTrue(pcPart.IsBroken == false);
        }
示例#9
0
        public void PCPartConstructorWithThreeParametersShouldSetIsBrokenCorrectly()
        {
            var PCPart = new PCPart("ram", 100m, true);

            bool actualIsBroken = PCPart.IsBroken;

            Assert.IsTrue(actualIsBroken);
        }
示例#10
0
        public void PCPartRepairShouldTurnIsBrokenToFalse()
        {
            var PCPart = new PCPart("ram", 100m, true);

            PCPart.Repair();

            Assert.IsFalse(PCPart.IsBroken);
        }
示例#11
0
        public void TestShouldNotBeAbleToAddExistingPCPart()
        {
            IPart       pcPart = new PCPart("CD", 10m);
            IRepairable pc     = new PC(makeTest);

            pc.AddPart(pcPart);

            Assert.Throws <InvalidOperationException>(() => pc.AddPart(pcPart));
        }
示例#12
0
        public void PCPartConstructorWithThreeParametersShouldSetNameCorrectly()
        {
            var    PCPart       = new PCPart("Ram", 100m, true);
            string expectedName = "Ram";

            string actualName = PCPart.Name;

            Assert.AreEqual(expectedName, actualName);
        }
示例#13
0
        public void TestIfPCPartReportWorksCorrectly()
        {
            string expectedResult = $"Fan - {(60 * 1.2m):F2}$" + Environment.NewLine +
                                    $"Broken: True";

            IPart pcPart = new PCPart("Fan", 60, true);

            Assert.AreEqual(expectedResult, pcPart.Report());
        }
示例#14
0
        public void PCPartConstructorWithThreeParametersShouldSetCostCorrectly()
        {
            var     PCPart       = new PCPart("ram", 100m, true);
            decimal expectedCost = 100m * 1.2m;

            decimal actualCost = PCPart.Cost;

            Assert.AreEqual(expectedCost, actualCost);
        }
示例#15
0
        public void TestIfRepairPartWorksCorrectly()
        {
            bool   expectedResult = false;
            PCPart pcPart         = new PCPart("VideoCard", 500m, true);

            pcPart.Repair();

            Assert.AreEqual(expectedResult, pcPart.IsBroken);
        }
示例#16
0
        public void TestRepairNotBrokenPCPart()
        {
            IPart       pcPart = new PCPart("CD", 10m, false);
            IRepairable pc     = new PC(makeTest);

            pc.AddPart(pcPart);

            Assert.Throws <InvalidOperationException>(() => pc.RepairPart("CD"));
        }
示例#17
0
        public void TestRepairPCPartWithEmptyName()
        {
            IPart       pcPart = new PCPart("CD", 10m, true);
            IRepairable pc     = new PC(makeTest);

            pc.AddPart(pcPart);

            Assert.Throws <ArgumentException>(() => pc.RepairPart(String.Empty));
        }
        public void TestAddPartPhoneWithNonPhonePart()
        {
            IPart part  = new PCPart("GPU", 150, false);
            Phone phone = new Phone("Samsung");

            string expectedExceptionMessage = $"You cannot add {part.GetType().Name} to {phone.GetType().Name}!";

            Assert.That(() => phone.AddPart(part), Throws.InvalidOperationException.With.Message.EqualTo(expectedExceptionMessage));
        }
示例#19
0
        public void TestReportPCPartShouldReturnCorrectMessage()
        {
            IPart pcPart = new PCPart(PartName, PartCost, PartIsBroken);

            string expected = $"{PartName} - {(PartCost*multiplierPCPart):f2}$" + Environment.NewLine + $"Broken: {PartIsBroken}";
            string actual   = pcPart.Report();

            Assert.AreEqual(expected, actual);
        }
示例#20
0
        public void TestShouldBeAbleToAddPCPart()
        {
            IPart       pcPart = new PCPart("CD", 10m);
            IRepairable pc     = new PC(makeTest);

            pc.AddPart(pcPart);

            Assert.AreEqual(1, pc.Parts.Count);
        }
示例#21
0
        public void PcRepairPartMethodCannotRepairNonBrokenPart()
        {
            var pc   = new PC("Dell");
            var part = new PCPart("LaptopPart", 5.50m, false);

            pc.AddPart(part);

            Assert.Throws <InvalidOperationException>(() => pc.RepairPart("LaptopPart"));
        }
        public void PcPartReportShouldGiveCorrectInfo()
        {
            var part = new PCPart("JustLaptopPart", 3.50M, false);

            var expectedReport = $"JustLaptopPart - 4.20$" + Environment.NewLine +
                                 $"Broken: False";

            Assert.AreEqual(expectedReport, part.Report());
        }
示例#23
0
 public void Setup()
 {
     this.laptop      = new Laptop("LaptopMake");
     this.pc          = new PC("PCMake");
     this.phone       = new Phone("PhoneMake");
     this.laptopPart1 = new LaptopPart("RAM", 10, true);
     this.laptopPart2 = new LaptopPart("HDD", 50, false);
     this.pcPart      = new PCPart("SSD", 15);
     this.phonePart   = new PhonePart("Camera", 20);
 }
        public void TestIfPCAddPartWorksCorrectly()
        {
            IPart part = new PCPart("GPU", 150, false);

            PC pc = new PC("Asus");

            pc.AddPart(part);

            Assert.That(pc.Parts, Has.Member(part));
        }
示例#25
0
        public void LaptopAddPartShouldThrowExceptionIfPartIsWrong()
        {
            var laptop = new Laptop("Dell");

            var pcPart    = new PCPart("PcPart", 3.50m);
            var phonePart = new PhonePart("PhonePart", 2.50m);

            Assert.Throws <InvalidOperationException>(() => laptop.AddPart(pcPart));
            Assert.Throws <InvalidOperationException>(() => laptop.AddPart(phonePart));
        }
示例#26
0
        public void PcRepairPartMethodShouldWorksCorrectly()
        {
            var pc   = new PC("Dell");
            var part = new PCPart("PcPart", 3.25m, true);

            pc.AddPart(part);
            pc.RepairPart(part.Name);

            Assert.IsFalse(part.IsBroken);
        }
示例#27
0
        public void PcRemovePartMethodCannotRemoveNonExistingPart()
        {
            var pc = new PC("Dell");

            var part = new PCPart("PcPart", 5.50m);

            pc.AddPart(part);

            Assert.Throws <InvalidOperationException>(() => pc.RemovePart("LaptopPart"));
        }
示例#28
0
        public void PhoneAddPartShouldThrowExceptionIfPartIsWrong()
        {
            var phone = new Phone("iPhone");

            var laptopPart = new LaptopPart("LaptopPart", 3.50m);
            var pcPart     = new PCPart("PcPart", 2.50m);

            Assert.Throws <InvalidOperationException>(() => phone.AddPart(laptopPart));
            Assert.Throws <InvalidOperationException>(() => phone.AddPart(pcPart));
        }
示例#29
0
        public void PcAddPartShouldThrowExceptionIfPartIsAlreadyExisting()
        {
            var pc = new PC("Dell");

            var pcPart = new PCPart("PcPart", 3.50m);

            pc.AddPart(pcPart);

            Assert.Throws <InvalidOperationException>(() => pc.AddPart(pcPart));
        }
示例#30
0
        public void PC_Part_ReportTest()
        {
            var pcPart  = new PCPart("aaa", 100);
            var pcPart2 = new PCPart("bbb", 200, true);

            Assert.AreEqual("aaa - 120.00$" + Environment.NewLine +
                            $"Broken: False", pcPart.Report());
            Assert.AreEqual("bbb - 240.00$" + Environment.NewLine +
                            $"Broken: True", pcPart2.Report());
        }