Beispiel #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;
            }
        }
Beispiel #2
0
        public void TestShouldNotBeAbleToAddExistingLaptopPart()
        {
            IPart       laptopPart = new LaptopPart("CD", 10m);
            IRepairable laptop     = new Laptop(makeTest);

            laptop.AddPart(laptopPart);

            Assert.Throws <InvalidOperationException>(() => laptop.AddPart(laptopPart));
        }
Beispiel #3
0
        public void Laptop_AddPartThrowsException_PartExists()
        {
            var laptop = new Laptop("HP");

            laptop.AddPart(laptopPart);

            Assert.Throws <InvalidOperationException>(() => laptop.AddPart(laptopPart))
            .Message.Equals("This part already exists!");
        }
Beispiel #4
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));
        }
Beispiel #5
0
        public void LaptopAddPartShouldThrowExceptionIfPartIsAlreadyExisting()
        {
            var laptop = new Laptop("Dell");

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

            laptop.AddPart(laptopPart);

            Assert.Throws <InvalidOperationException>(() => laptop.AddPart(laptopPart));
        }
Beispiel #6
0
        public void LaptopRemovePartMethodShouldWorkCorrectly()
        {
            var laptop = new Laptop("Dell");
            var part1  = new LaptopPart("LaptopPart1", 7.50m);
            var part2  = new LaptopPart("LaptopPart2", 3.50m);

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

            var expectedCount = 1;

            Assert.AreEqual(expectedCount, laptop.Parts.Count);
        }
Beispiel #7
0
        public void LaptopAddPartShouldWorksCorrectly()
        {
            var laptop = new Laptop("Dell");

            var laptopPart1 = new LaptopPart("LaptopPart1", 3.50m);
            var laptopPart2 = new LaptopPart("LaptopPart2", 3.50m);

            laptop.AddPart(laptopPart1);
            laptop.AddPart(laptopPart2);

            var expectedCount = 2;

            Assert.AreEqual(expectedCount, laptop.Parts.Count);
        }
Beispiel #8
0
        public void Laptop_AddPartTest()
        {
            var laptop = new Laptop("HP");

            laptop.AddPart(laptopPart);

            Assert.AreEqual(1, laptop.Parts.Count);
        }
Beispiel #9
0
        public void LaptopRepairPartMethodCannotRepairNonBrokenPart()
        {
            var laptop = new Laptop("Dell");
            var part   = new LaptopPart("LaptopPart", 5.50m, false);

            laptop.AddPart(part);

            Assert.Throws <InvalidOperationException>(() => laptop.RepairPart("LaptopPart"));
        }
Beispiel #10
0
        public void TestRepairNotBrokenLaptopPart()
        {
            IPart       laptopPart = new LaptopPart("CD", 10m, false);
            IRepairable laptop     = new Laptop(makeTest);

            laptop.AddPart(laptopPart);

            Assert.Throws <InvalidOperationException>(() => laptop.RepairPart("CD"));
        }
Beispiel #11
0
        public void TestRepairLaptopPartWithEmptyName()
        {
            IPart       laptopPart = new LaptopPart("CD", 10m, true);
            IRepairable laptop     = new Laptop(makeTest);

            laptop.AddPart(laptopPart);

            Assert.Throws <ArgumentException>(() => laptop.RepairPart(String.Empty));
        }
Beispiel #12
0
        public void TestShouldBeAbleToAddLaptopPart()
        {
            IPart       laptopPart = new LaptopPart("CD", 10m);
            IRepairable laptop     = new Laptop(makeTest);

            laptop.AddPart(laptopPart);

            Assert.AreEqual(1, laptop.Parts.Count);
        }
Beispiel #13
0
        public void DeviceRepairMethod_InvalidOperationExceptions(string partName, string message)
        {
            var laptop = new Laptop("laptop");

            laptop.AddPart(new LaptopPart("laptopPart", 1.5m, false));

            Assert.Throws <InvalidOperationException>(() => laptop.RepairPart(partName))
            .Message.Equals(message);
        }
Beispiel #14
0
        public void TestRepairLaptopPartWithNotExistingPCPart()
        {
            IPart       laptopPart  = new LaptopPart("CD", 10m);
            IPart       laptopPart2 = new LaptopPart("HDD", 100m);
            IRepairable laptop      = new Laptop(makeTest);

            laptop.AddPart(laptopPart);

            Assert.Throws <InvalidOperationException>(() => laptop.RepairPart("HDD"));
        }
Beispiel #15
0
        public void Laptop_RemovePartTest()
        {
            var laptop = new Laptop("HP");
            var part   = new LaptopPart("part", 2);

            laptop.AddPart(part);
            Assert.AreEqual(1, laptop.Parts.Count);
            laptop.RemovePart(part.Name);
            Assert.AreEqual(0, laptop.Parts.Count);
        }
Beispiel #16
0
        public void LaptopRemovePartMethodCannotRemoveNonExistingPart()
        {
            var laptop = new Laptop("Dell");

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

            laptop.AddPart(part);

            Assert.Throws <InvalidOperationException>(() => laptop.RemovePart("PcPart"));
        }
Beispiel #17
0
        public void LaptopRepairPartMethodShouldWorksCorrectly()
        {
            var laptop = new Laptop("Dell");
            var part   = new LaptopPart("LaptopPart", 5.50m, true);

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

            Assert.IsFalse(part.IsBroken);
        }
        public void DeviceRepairPartShoulTurnIsBrokenToFalse()
        {
            var part   = new LaptopPart("RAM", 10m, true);
            var device = new Laptop("Asus");

            device.AddPart(part);

            device.RepairPart(part.Name);

            Assert.IsFalse(device.Parts.FirstOrDefault(p => p.Name == part.Name).IsBroken);
        }
        public void DeviceRemovePartShouldRemoveThePart()
        {
            var device = new Laptop("Asus");
            var part   = new LaptopPart("RAM", 100m);

            device.AddPart(part);

            device.RemovePart(part.Name);

            Assert.IsTrue(device.Parts.FirstOrDefault(p => p.Name == part.Name) == null);
        }
Beispiel #20
0
        public void TestRemoveCorrectlyLaptopPart()
        {
            IPart       laptopPart = new LaptopPart("CD", 10m);
            IRepairable laptop     = new Laptop(makeTest);

            laptop.AddPart(laptopPart);
            laptop.RemovePart("CD");

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

            Assert.AreEqual(expectedCount, actualCount);
        }
Beispiel #21
0
        public void TestCorrectlyRepairLaptopPart()
        {
            IPart       laptopPart = new LaptopPart("CD", 10m, true);
            IRepairable laptop     = new Laptop(makeTest);

            laptop.AddPart(laptopPart);
            laptop.RepairPart("CD");

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

            Assert.AreEqual(expectedIsBroken, actualIsBroken);
        }
Beispiel #22
0
        public void Laptop_RemovePart_ThrowsExceptions()
        {
            var laptop = new Laptop("HP");
            var part   = new LaptopPart("part", 2);

            laptop.AddPart(part);
            Assert.Throws <ArgumentException>(() => laptop.RemovePart(null))
            .Message.Equals("Part name cannot be null or empty!");
            Assert.Throws <ArgumentException>(() => laptop.RemovePart(""))
            .Message.Equals("Part name cannot be null or empty!");
            Assert.Throws <InvalidOperationException>(() => laptop.RemovePart("notExisting"))
            .Message.Equals("You cannot remove part which does not exist!");
        }
Beispiel #23
0
        public void Laptop_PartsGetter()
        {
            var laptop = new Laptop("HP");
            var part   = new LaptopPart("part", 2);

            var parts = new List <LaptopPart>()
            {
                part
            };

            laptop.AddPart(part);

            CollectionAssert.AreEqual(parts, laptop.Parts);
        }
        public void DeviceRepairPartShouldThrowInvalidOperationExceptionWhenPartToRepairIsNotBroken()
        {
            var part   = new LaptopPart("RAM", 100m);
            var device = new Laptop("Asus");

            device.AddPart(part);

            Assert
            .That(
                () => device.RepairPart(part.Name),
                Throws
                .InvalidOperationException
                .With
                .Message
                .EqualTo("You cannot repair part which is not broken!"));
        }
Beispiel #25
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);
        }
Beispiel #26
0
        public void AddPart_Method_Should_Throws_Exception_With_Wrong_Part()
        {
            PCPart part = new PCPart("mouse", 23.3m, false);

            Assert.Throws <InvalidOperationException>(() => laptop.AddPart(part));
        }