Exemplo n.º 1
0
        public void Devices_AddPartThrowsException_WhenPartNotCompatible(string type)
        {
            switch (type)
            {
            case "Laptop":
                var laptop = new Laptop("make");

                Assert.Throws <InvalidOperationException>(() => laptop.AddPart(phonePart))
                .Message.Equals($"You cannot add {phonePart.GetType().Name} to {this.GetType().Name}!");

                Assert.Throws <InvalidOperationException>(() => laptop.AddPart(pcPart))
                .Message.Equals($"You cannot add {pcPart.GetType().Name} to {this.GetType().Name}!");
                break;

            case "PC":
                var pc = new PC("make");

                Assert.Throws <InvalidOperationException>(() => pc.AddPart(laptopPart))
                .Message.Equals($"You cannot add {laptopPart.GetType().Name} to {this.GetType().Name}!");

                Assert.Throws <InvalidOperationException>(() => pc.AddPart(phonePart))
                .Message.Equals($"You cannot add {phonePart.GetType().Name} to {this.GetType().Name}!");
                break;

            case "Phone":
                var phone = new Phone("make");

                Assert.Throws <InvalidOperationException>(() => phone.AddPart(pcPart))
                .Message.Equals($"You cannot add {pcPart.GetType().Name} to {this.GetType().Name}!");

                Assert.Throws <InvalidOperationException>(() => phone.AddPart(laptopPart))
                .Message.Equals($"You cannot add {laptopPart.GetType().Name} to {this.GetType().Name}!");
                break;
            }
        }
Exemplo n.º 2
0
        public void TestShouldNotBeAbleToAddExistingPCPart()
        {
            IPart       pcPart = new PCPart("CD", 10m);
            IRepairable pc     = new PC(makeTest);

            pc.AddPart(pcPart);

            Assert.Throws <InvalidOperationException>(() => pc.AddPart(pcPart));
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
0
        public void PcAddPartShouldWorksCorrectly()
        {
            var pc = new PC("Dell");

            var pcPart1 = new PCPart("PcPart1", 3.50m);
            var pcPart2 = new PCPart("PcPart2", 3.50m);

            pc.AddPart(pcPart1);
            pc.AddPart(pcPart2);

            var expectedCount = 2;

            Assert.AreEqual(expectedCount, pc.Parts.Count);
        }
Exemplo n.º 6
0
        public void PcRemovePartMethodShouldWorkCorrectly()
        {
            var pc    = new PC("Dell");
            var part1 = new PCPart("PcPart1", 7.50m);
            var part2 = new PCPart("PcPart2", 3.50m);

            pc.AddPart(part1);
            pc.AddPart(part2);
            pc.RemovePart(part1.Name);

            var expectedCount = 1;

            Assert.AreEqual(expectedCount, pc.Parts.Count);
        }
Exemplo n.º 7
0
        public void TestPCAddPartWithInvalidPart()
        {
            PC    pc        = new PC("Toshiba");
            IPart phonePart = new PhonePart("Keyboard", 85);

            Assert.Throws <InvalidOperationException>(() => pc.AddPart(phonePart));
        }
Exemplo n.º 8
0
        public void TestShouldNotBeAbleToAddNonPCPart()
        {
            IPart       laptopPart = new LaptopPart("CD", 10m);
            IRepairable pc         = new PC(makeTest);

            Assert.Throws <InvalidOperationException>(() => pc.AddPart(laptopPart));
        }
Exemplo n.º 9
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"));
        }
Exemplo n.º 10
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));
        }
Exemplo n.º 11
0
        public void TestShouldBeAbleToAddPCPart()
        {
            IPart       pcPart = new PCPart("CD", 10m);
            IRepairable pc     = new PC(makeTest);

            pc.AddPart(pcPart);

            Assert.AreEqual(1, pc.Parts.Count);
        }
        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));
        }
Exemplo n.º 13
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"));
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
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"));
        }
Exemplo n.º 16
0
        public void TestRepairPCPartWithNotExistingPCPart()
        {
            IPart       pcPart  = new PCPart("CD", 10m);
            IPart       pcPart2 = new PCPart("HDD", 100m);
            IRepairable pc      = new PC(makeTest);

            pc.AddPart(pcPart);

            Assert.Throws <InvalidOperationException>(() => pc.RepairPart("HDD"));
        }
        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));
        }
Exemplo n.º 18
0
        public void TestIfPCAddPartWorksCorrectly()
        {
            int expectedCount = 1;

            PC    pc     = new PC("Toshiba");
            IPart pcPart = new PCPart("Keyboard", 40);

            pc.AddPart(pcPart);

            Assert.AreEqual(expectedCount, pc.Parts.Count);
        }
Exemplo n.º 19
0
        public void TestRemoveCorrectlyPCPart()
        {
            IPart       pcPart = new PCPart("CD", 10m);
            IRepairable pc     = new PC(makeTest);

            pc.AddPart(pcPart);
            pc.RemovePart("CD");

            int expectedCount = 0;
            int actualCount   = pc.Parts.Count;

            Assert.AreEqual(expectedCount, actualCount);
        }
Exemplo n.º 20
0
        public void TestCorrectlyRepairPCPart()
        {
            IPart       pcPart = new PCPart("CD", 10m, true);
            IRepairable pc     = new PC(makeTest);

            pc.AddPart(pcPart);
            pc.RepairPart("CD");

            bool expectedIsBroken = false;
            bool actualIsBroken   = pc.Parts.First(p => p.Name == "CD").IsBroken;

            Assert.AreEqual(expectedIsBroken, actualIsBroken);
        }
Exemplo n.º 21
0
        public void DeviceRepairMethod_Test()
        {
            var pc     = new PC("pc");
            var phone  = new Phone("phone");
            var laptop = new Laptop("laptop");

            pc.AddPart(pcPart);
            phone.AddPart(phonePart);
            laptop.AddPart(laptopPart);

            pc.RepairPart("pcPart");
            phone.RepairPart("phonePart");
            laptop.RepairPart("laptopPart");

            Assert.That(pcPart.IsBroken == false);
            Assert.That(laptopPart.IsBroken == false);
            Assert.That(phonePart.IsBroken == false);
        }