コード例 #1
0
        public void TestPCAddPartWithInvalidPart()
        {
            PC    pc        = new PC("Toshiba");
            IPart phonePart = new PhonePart("Keyboard", 85);

            Assert.Throws <InvalidOperationException>(() => pc.AddPart(phonePart));
        }
コード例 #2
0
        public void Test_Repair()
        {
            var newPhonePart = new PhonePart("valid", 2, true);

            newPhonePart.Repair();
            Assert.AreEqual(false, newPhonePart.IsBroken);
        }
コード例 #3
0
ファイル: PartTests.cs プロジェクト: astanchev/CSharp-OOP
        public void TestRepairPhonePartShouldFixBrokenPart()
        {
            IPart phonePart = new PhonePart(PartName, PartCost);

            phonePart.Repair();

            Assert.IsTrue(phonePart.IsBroken == false);
        }
コード例 #4
0
        public void PhonePartRepairShouldTurnIsBrokenToFalse()
        {
            var phonePart = new PhonePart("ram", 100m, true);

            phonePart.Repair();

            Assert.IsFalse(phonePart.IsBroken);
        }
コード例 #5
0
ファイル: PartTests.cs プロジェクト: astanchev/CSharp-OOP
        public void TestPhonePartShouldBeInstantiatedWith3parameters()
        {
            IPart phonePart = new PhonePart(PartName, PartCost, PartIsBroken);

            Assert.AreEqual(PartName, phonePart.Name);
            Assert.AreEqual((PartCost * multiplierPhonePart), phonePart.Cost);
            Assert.AreEqual(PartIsBroken, phonePart.IsBroken);
        }
コード例 #6
0
        public void PhonePartReportShouldReturnStringContainingNameCostAndIsBrokenPropertiesAsPartOfIt()
        {
            var phonePart = new PhonePart("ram", 100m, true);

            StringAssert.Contains($"{phonePart.Name}", phonePart.Report(), "Report string doesn't contain Name property");
            StringAssert.Contains($"{phonePart.Cost}", phonePart.Report(), "Report string doesn't contain Cost property");
            StringAssert.Contains($"{phonePart.IsBroken}", phonePart.Report(), "Report string doesn't contain IsBroken property");
        }
コード例 #7
0
 public void NameSetter_ShouldThrow_ExceptionIfNullOrEmpty()
 {
     //Assert
     Assert.Throws <ArgumentException>(() =>
     {
         PhonePart itemPart = new PhonePart("", 10m);
     });
 }
コード例 #8
0
        public void PhonePartConstructorWithThreeParametersShouldSetIsBrokenCorrectly()
        {
            var PhonePart = new PhonePart("ram", 100m, true);

            bool actualIsBroken = PhonePart.IsBroken;

            Assert.IsTrue(actualIsBroken);
        }
コード例 #9
0
 public void CostSetter_ShouldThrow_ExceptionIfNegative()
 {
     //Assert
     Assert.Throws <ArgumentException>(() =>
     {
         PhonePart itemPart = new PhonePart("Button", -1m);
     });
 }
コード例 #10
0
        public void PhonePartRepairShouldWorksCorrectly()
        {
            var part = new PhonePart("JustLaptopPart", 2.50M, true);

            part.Repair();

            Assert.IsFalse(part.IsBroken);
        }
コード例 #11
0
        public void Test_Report()
        {
            var    newPhonePart = new PhonePart("valid", 2, true);
            string report       = $"{newPhonePart.Name} - {newPhonePart.Cost:f2}$" + Environment.NewLine +
                                  $"Broken: {newPhonePart.IsBroken}";

            Assert.AreEqual(report, newPhonePart.Report());
        }
コード例 #12
0
        public void PhonePartConstructorWithThreeParametersShouldSetNameCorrectly()
        {
            var    PhonePart    = new PhonePart("Ram", 100m, true);
            string expectedName = "Ram";

            string actualName = PhonePart.Name;

            Assert.AreEqual(expectedName, actualName);
        }
コード例 #13
0
        public void PhonePartConstructorWithThreeParametersShouldSetCostCorrectly()
        {
            var     PhonePart    = new PhonePart("ram", 100m, true);
            decimal expectedCost = 100m * 1.3m;

            decimal actualCost = PhonePart.Cost;

            Assert.AreEqual(expectedCost, actualCost);
        }
コード例 #14
0
        public void TestAddPartPCeWithNonPCPart()
        {
            IPart part = new PhonePart("GPU", 150, false);
            PC    pc   = new PC("Asus");

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

            Assert.That(() => pc.AddPart(part), Throws.InvalidOperationException.With.Message.EqualTo(expectedExceptionMessage));
        }
コード例 #15
0
ファイル: DeviceTests.cs プロジェクト: astanchev/CSharp-OOP
        public void TestRepairNotBrokenPhonePart()
        {
            IPart       phonePart = new PhonePart("CD", 10m, false);
            IRepairable phone     = new Phone(makeTest);

            phone.AddPart(phonePart);

            Assert.Throws <InvalidOperationException>(() => phone.RepairPart("CD"));
        }
コード例 #16
0
ファイル: DeviceTests.cs プロジェクト: astanchev/CSharp-OOP
        public void TestRepairPhonePartWithEmptyName()
        {
            IPart       phonePart = new PhonePart("CD", 10m, true);
            IRepairable phone     = new Phone(makeTest);

            phone.AddPart(phonePart);

            Assert.Throws <ArgumentException>(() => phone.RepairPart(String.Empty));
        }
コード例 #17
0
ファイル: DeviceTests.cs プロジェクト: astanchev/CSharp-OOP
        public void TestShouldNotBeAbleToAddExistingPhonePart()
        {
            IPart       phonePart = new PhonePart("CD", 10m);
            IRepairable phone     = new Phone(makeTest);

            phone.AddPart(phonePart);

            Assert.Throws <InvalidOperationException>(() => phone.AddPart(phonePart));
        }
コード例 #18
0
ファイル: DeviceTests.cs プロジェクト: astanchev/CSharp-OOP
        public void TestShouldBeAbleToAddPhonePart()
        {
            IPart       phonePart = new PhonePart("CD", 10m);
            IRepairable phone     = new Phone(makeTest);

            phone.AddPart(phonePart);

            Assert.AreEqual(1, phone.Parts.Count);
        }
コード例 #19
0
    public void AddPart(PhonePart toAdd)
    {
        // TODO check that one unique part can only be added once
        // TODO check that the correct amount of screws is assembled
        var tmp = parts.ToList();

        tmp.Add(toAdd);
        parts = tmp.ToArray();
    }
コード例 #20
0
        public void PhonePartReportShouldGiveCorrectInfo()
        {
            var part = new PhonePart("JustLaptopPart", 5.50M, true);

            var expectedReport = $"JustLaptopPart - 7.15$" + Environment.NewLine +
                                 $"Broken: True";

            Assert.AreEqual(expectedReport, part.Report());
        }
コード例 #21
0
        public void PhoneRepairPartMethodCannotRepairNonBrokenPart()
        {
            var phone = new Phone("iPhone");
            var part  = new PhonePart("PhonePart", 5.50m, false);

            phone.AddPart(part);

            Assert.Throws <InvalidOperationException>(() => phone.RepairPart("PhonePart"));
        }
コード例 #22
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);
 }
コード例 #23
0
ファイル: DeviceTests.cs プロジェクト: astanchev/CSharp-OOP
        public void TestRepairPhonePartWithNotExistingPCPart()
        {
            IPart       phonePart  = new PhonePart("CD", 10m);
            IPart       phonePart2 = new PhonePart("HDD", 100m);
            IRepairable phone      = new Phone(makeTest);

            phone.AddPart(phonePart);

            Assert.Throws <InvalidOperationException>(() => phone.RepairPart("HDD"));
        }
コード例 #24
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));
        }
コード例 #25
0
        public void PhoneRepairPartMethodShouldWorksCorrectly()
        {
            var phone = new Phone("iPhone");
            var part  = new PhonePart("PhonePart", 12.75m, true);

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

            Assert.IsFalse(part.IsBroken);
        }
コード例 #26
0
        public void PhoneRemovePartMethodCannotRemoveNonExistingPart()
        {
            var phone = new Phone("iPhone");

            var part = new PhonePart("PhonePart", 5.50m);

            phone.AddPart(part);

            Assert.Throws <InvalidOperationException>(() => phone.RemovePart("LaptopPart"));
        }
コード例 #27
0
        public void PhoneAddPartShouldThrowExceptionIfPartIsAlreadyExisting()
        {
            var phone = new Phone("iPhone");

            var phonePart = new PhonePart("PhonePart", 3.50m);

            phone.AddPart(phonePart);

            Assert.Throws <InvalidOperationException>(() => phone.AddPart(phonePart));
        }
コード例 #28
0
        public void PcAddPartShouldThrowExceptionIfPartIsWrong()
        {
            var pc = new PC("Acer");

            var laptopPart = new LaptopPart("LaptopPart", 3.50m);
            var phonePart  = new PhonePart("PhonePart", 2.50m);

            Assert.Throws <InvalidOperationException>(() => pc.AddPart(laptopPart));
            Assert.Throws <InvalidOperationException>(() => pc.AddPart(phonePart));
        }
コード例 #29
0
ファイル: PartTests.cs プロジェクト: SvilenD/CSharp-OOP-
        public void Phone_Part_ReportTest()
        {
            var phonePart  = new PhonePart("aaa", 100);
            var phonePart2 = new PhonePart("bbb", 200, true);

            Assert.AreEqual("aaa - 130.00$" + Environment.NewLine +
                            $"Broken: False", phonePart.Report());
            Assert.AreEqual("bbb - 260.00$" + Environment.NewLine +
                            $"Broken: True", phonePart2.Report());
        }
コード例 #30
0
        public void TestIfPhoneAddPartWorksCorrectly()
        {
            IPart part = new PhonePart("GPU", 150, false);

            Phone phone = new Phone("Samsung");

            phone.AddPart(part);

            Assert.That(phone.Parts, Has.Member(part));
        }