Пример #1
0
        public void TestProperties()
        {
            Assert.That(typeof(BaseVehicle).IsAbstract);
            BaseVehicle baseVehicle = new Revenger("MPO", 20, 13, 12, 13, 14, new VehicleAssembler());

            Assert.AreEqual(baseVehicle.Model, "MPO");
            Assert.AreEqual(baseVehicle.Weight, 20);
            Assert.AreEqual(baseVehicle.Price, 13);
            Assert.AreEqual(baseVehicle.Attack, 12);
            Assert.AreEqual(baseVehicle.Defense, 13);
            Assert.AreEqual(baseVehicle.HitPoints, 14);

            baseVehicle.AddArsenalPart(new ArsenalPart("Model", 12, 13, 4));
            baseVehicle.AddEndurancePart(new EndurancePart("Model2", 14, 15, 6));
            baseVehicle.AddShellPart(new ShellPart("Model3", 17, 18, 9));

            baseVehicle.AddArsenalPart(new ArsenalPart("Model", 12, 13, 4));
            baseVehicle.AddEndurancePart(new EndurancePart("Model2", 14, 15, 6));
            baseVehicle.AddShellPart(new ShellPart("Model3", 17, 18, 9));

            string actualValue = baseVehicle.ToString();

            string[] lines = actualValue.Split(Environment.NewLine);
            actualValue = string.Join(Environment.NewLine, lines.Skip(1));

            string expectedValue =
                "Total Weight: 106,000\r\n" +
                "Total Price: 105,000\r\n" +
                "Attack: 20\r\n" +
                "Defense: 31\r\n" +
                "HitPoints: 26\r\n" +
                "Parts: Model, Model2, Model3, Model, Model2, Model3";

            Assert.AreEqual(expectedValue, actualValue);

            FieldInfo      fieldInfo = typeof(BaseVehicle).GetField("orderedParts", BindingFlags.Instance | BindingFlags.NonPublic);
            IList <string> val       = (IList <string>)fieldInfo.GetValue(baseVehicle);

            Assert.AreEqual("Model, Model, Model3, Model3, Model2, Model2", string.Join(", ", baseVehicle.Parts.Select(p => p.Model)));

            Assert.AreEqual(106.000, baseVehicle.TotalWeight);
            Assert.AreEqual(105.000, baseVehicle.TotalPrice);
            Assert.AreEqual(20, baseVehicle.TotalAttack);
            Assert.AreEqual(31, baseVehicle.TotalDefense);
            Assert.AreEqual(26, baseVehicle.TotalHitPoints);
            //Assert.AreEqual("Model, Model2, Model3, Model, Model2, Model3", baseVehicle.);

            BaseVehicle baseVehicle2 = new Revenger("s", 1, 1, 1, 1, 1, new VehicleAssembler());

            Assert.That(() => baseVehicle2 = new Revenger("", 1, 1, 1, 1, 1, new VehicleAssembler()), Throws.ArgumentException);
            Assert.That(() => baseVehicle2 = new Revenger("d", 0, 1, 1, 1, 1, new VehicleAssembler()), Throws.ArgumentException);
            Assert.That(() => baseVehicle2 = new Revenger("d", 1, 0, 1, 1, 1, new VehicleAssembler()), Throws.ArgumentException);
            Assert.That(() => baseVehicle2 = new Revenger("d", 1, 1, -1, 1, 1, new VehicleAssembler()), Throws.ArgumentException);
            Assert.That(() => baseVehicle2 = new Revenger("d", 1, 1, 1, -1, 1, new VehicleAssembler()), Throws.ArgumentException);
            Assert.That(() => baseVehicle2 = new Revenger("d", 1, 1, 1, 1, -1, new VehicleAssembler()), Throws.ArgumentException);
            Assert.AreEqual(true, baseVehicle2.ToString().Contains("None"));
        }
Пример #2
0
        public void CheckOverrideToString()
        {
            string     model     = "Rhino-CE";
            double     weight    = 12;
            decimal    price     = 19;
            int        attack    = 80;
            int        defense   = 11;
            int        hitPoints = 3;
            IAssembler assembler = new VehicleAssembler();

            BaseVehicle testVehicle = new Revenger(model, weight, price, attack, defense, hitPoints, assembler);

            IPart arsenalPart = new ArsenalPart("arse1", 1, 1, 2);

            testVehicle.AddArsenalPart(arsenalPart);


            IPart shellPart = new ShellPart("hel1", 6, 1, 8);

            testVehicle.AddShellPart(shellPart);


            IPart endurancePart = new EndurancePart("end1", 1, 3, 2);

            testVehicle.AddEndurancePart(endurancePart);

            string expectedMessage = "Revenger - Rhino-CE\r\nTotal Weight: 20.000\r\nTotal Price: 24.000\r\nAttack: 82\r\nDefense: 19\r\nHitPoints: 5\r\nParts: arse1, hel1, end1";

            string actualMessage = testVehicle.ToString();

            Assert.AreEqual(expectedMessage, actualMessage);
        }
        public void TatalWeightValidation()
        {
            vehicle.AddArsenalPart(new ArsenalPart("ModelA", 150, 500, 100));
            vehicle.AddEndurancePart(new EndurancePart("ModelE", 200, 250, 100));
            vehicle.AddShellPart(new ShellPart("ModelS", 250, 250, 100));

            Assert.AreEqual(3100, vehicle.TotalWeight);
        }
Пример #4
0
        public void Test2()
        {
            var vehicle = new Revenger("Pesho", 111, 12, 123, 123, 123, new VehicleAssembler());

            vehicle.AddArsenalPart(new ArsenalPart("TestPart1", 12, 12, 12));
            vehicle.AddShellPart(new ShellPart("TestPart2", 2, 2, 2));
            vehicle.AddEndurancePart(new EndurancePart("TestPart3", 1, 1, 1));

            var actual   = vehicle.Parts.Count();
            var expected = 3;

            Assert.That(actual, Is.EqualTo(expected));
        }
Пример #5
0
        public void AddEndurancePartShouldAddThePartToAssembler()
        {
            //Arrange
            var        part      = new EndurancePart("part", 10, 10, 10);
            IAssembler assembler = new VehicleAssembler();
            IVehicle   vehicle   = new Revenger("revenger", 10, 10, 10, 10, 10, assembler);

            //Action
            vehicle.AddEndurancePart(part);
            bool assemblerHasPart = assembler.EnduranceParts.Any(ap => ap.Equals(part));

            //Assert
            Assert.AreEqual(true, assemblerHasPart);
        }
Пример #6
0
        public void ValidateVehiclePartList()
        {
            IVehicle vehicle = new Revenger("Gosho", 112, 12, 12, 12, 12, new VehicleAssembler());

            vehicle.AddArsenalPart(new ArsenalPart("Top", 12, 12, 2));
            vehicle.AddArsenalPart(new ArsenalPart("Test", 22, 1, 3));
            vehicle.AddEndurancePart(new EndurancePart("Hit", 2, 52, 1));
            vehicle.AddShellPart(new ShellPart("Shelche", 2, 52, 1));

            var partsCount     = vehicle.Parts.Count();
            var expectedResult = 4;

            Assert.AreEqual(expectedResult, partsCount);
        }
Пример #7
0
        public void VechileToStringMethodShouldrReturnCorrectString()
        {
            IVehicle vehicle = new Revenger("Gosho", 112, 12, 12, 12, 12, new VehicleAssembler());

            vehicle.AddArsenalPart(new ArsenalPart("Top", 12, 12, 2));
            vehicle.AddArsenalPart(new ArsenalPart("Test", 22, 1, 3));
            vehicle.AddEndurancePart(new EndurancePart("Hit", 2, 52, 1));
            vehicle.AddShellPart(new ShellPart("Shelche", 2, 52, 1));

            var expectedResult = "Revenger - Gosho\r\nTotal Weight: 150,000\r\nTotal Price: 129,000\r\nAttack: 17\r\nDefense: 13\r\nHitPoints: 13\r\nParts: Top, Test, Hit, Shelche";
            var actualResult   = vehicle.ToString();

            Assert.AreEqual(expectedResult, actualResult);
        }
        public void CheckToString()
        {
            IVehicle vehicle   = new Revenger("asd", 1, 3, 1, 3, 4, new VehicleAssembler());
            var      arsenal   = new ArsenalPart("asd", 12, 3, 4);
            var      endurance = new EndurancePart("asd", 3, 3, 4);
            var      shell     = new ShellPart("asd", 3, 3, 4);

            vehicle.AddEndurancePart(endurance);
            vehicle.AddArsenalPart(arsenal);
            vehicle.AddShellPart(shell);

            Assert.That(vehicle.Parts, Has.Member(arsenal));
            Assert.That(vehicle.Parts, Has.Member(endurance));
            Assert.That(vehicle.Parts, Has.Member(shell));
        }
Пример #9
0
        public void AddEndurancePart_ShouldAddPartCorrectly(string model,
                                                            double weight, decimal price, int attack, int defense, int hitPoints)
        {
            var vehicle = new Revenger(model, weight, price, attack, defense,
                                       hitPoints, new VehicleAssembler());

            IPart endurancePart = new EndurancePart(model, weight, price, 10);

            vehicle.AddEndurancePart(endurancePart);

            var expected = 1;
            var actual   = vehicle.Parts.Count();

            Assert.AreEqual(expected, actual);
        }
        public void DoesTotalHitPointSumIsCorrest()
        {
            string  model     = "aaa";
            double  weight    = 1;
            decimal price     = 1;
            int     attack    = 1;
            int     defense   = 1;
            int     hitpoint  = 1;
            var     assembler = new VehicleAssembler();
            var     revenger  = new Revenger(model, weight, price, attack, defense, hitpoint, assembler);

            var endurance = new EndurancePart("aaa", 1, 1, 100);

            revenger.AddEndurancePart(endurance);
            Assert.AreEqual(101, revenger.TotalHitPoints);
        }
Пример #11
0
        public void CheckAddingItemsAndModifiengProperties()
        {
            string     model     = "Rhino-CE";
            double     weight    = 10;
            decimal    price     = 10m;
            int        attack    = 10;
            int        defense   = 10;
            int        hitPoints = 10;
            IAssembler assembler = new VehicleAssembler();

            BaseVehicle testVehicle = new Revenger(model, weight, price, attack, defense, hitPoints, assembler);

            IPart arsenalPart = new ArsenalPart("shel1", 1, 1, 2);

            testVehicle.AddArsenalPart(arsenalPart);
            Assert.That(testVehicle.Parts.Count() == 1 && testVehicle.Parts.Contains(arsenalPart), "Arsenal part not added properly");

            IPart shellPart = new ShellPart("shel1", 1, 1, 2);

            testVehicle.AddShellPart(shellPart);
            Assert.That(testVehicle.Parts.Count() == 2 && testVehicle.Parts.Contains(shellPart), "Shell part not added properly");

            IPart endurancePart = new EndurancePart("shel1", 1, 1, 2);

            testVehicle.AddEndurancePart(endurancePart);
            Assert.That(testVehicle.Parts.Count() == 3 && testVehicle.Parts.Contains(endurancePart), "Endurance part not added properly");

            double TotalWeightExpected = 3 + 10;

            Assert.AreEqual(TotalWeightExpected, testVehicle.TotalWeight);

            decimal TotalPriceExpected = 3 + 10;

            Assert.AreEqual(TotalPriceExpected, testVehicle.TotalPrice);

            long TotalAttackExpected = 10 + 2;

            Assert.AreEqual(TotalAttackExpected, testVehicle.TotalAttack);

            long TotalDefenseExpected = 10 + 2;

            Assert.AreEqual(TotalDefenseExpected, testVehicle.TotalDefense);

            long TotalHitPointsExpected = 10 + 2;

            Assert.AreEqual(TotalHitPointsExpected, testVehicle.TotalHitPoints);
        }
Пример #12
0
        public void AddEndurancePartShouldAddThePartToOrderedParts()
        {
            //Arrange
            IPart      part      = new EndurancePart("part", 10, 10, 10);
            IAssembler assembler = new VehicleAssembler();
            IVehicle   vehicle   = new Revenger("revenger", 10, 10, 10, 10, 10, assembler);

            //Action
            vehicle.AddEndurancePart(part);

            FieldInfo orderedPartsField = vehicle.GetType().BaseType.GetField("orderedParts", BindingFlags.NonPublic | BindingFlags.Instance);

            List <string> orderedParts = (List <string>)orderedPartsField.GetValue(vehicle);

            //Assert
            Assert.AreEqual(true, orderedParts[0] == part.Model);
        }
Пример #13
0
        public void TestAddPartCorrectly()
        {
            IAssembler    assembler     = new VehicleAssembler();
            Revenger      revenger      = new Revenger("Test", 100, 100, 100, 100, 100, assembler);
            ArsenalPart   arsenalPart   = new ArsenalPart("Arsenal", 23, 50, 5);
            EndurancePart endurancePart = new EndurancePart("Endurance", 23, 50, 5);
            ShellPart     shellPart     = new ShellPart("Shell", 23, 50, 5);

            Assert.DoesNotThrow(() => revenger.AddArsenalPart(arsenalPart));
            Assert.DoesNotThrow(() => revenger.AddEndurancePart(endurancePart));
            Assert.DoesNotThrow(() => revenger.AddShellPart(shellPart));

            string actualResult   = revenger.ToString();
            string expectedResult = "Revenger - Test\r\nTotal Weight: 169.000\r\nTotal Price: 250.000\r\nAttack: 105\r\nDefense: 105\r\nHitPoints: 105\r\nParts: Arsenal, Endurance, Shell";

            Assert.AreEqual(actualResult, expectedResult);
        }
Пример #14
0
        public void ValidateTotalPropertie_AddPartsMethods_PartsProperty()
        {
            var revenger = new Revenger("Reven", 6d, 6m, 6, 6, 6, new VehicleAssembler());

            var arsenalPart = new ArsenalPart("Ars", 6d, 6m, 6);

            revenger.AddArsenalPart(arsenalPart);

            Assert.AreEqual(revenger.TotalAttack, 12, $"TotalAttack property returns invalid result");
            Assert.AreEqual(revenger.TotalDefense, 6, $"TotalDefense property returns invalid result");
            Assert.AreEqual(revenger.TotalHitPoints, 6, $"TotalHitPoints property returns invalid result");
            Assert.AreEqual(revenger.TotalPrice, 12, $"TotalPrice property returns invalid result");
            Assert.AreEqual(revenger.TotalWeight, 12, $"TotalWeight property returns invalid result");


            var endurancePart = new EndurancePart("End", 6d, 6m, 6);

            revenger.AddEndurancePart(endurancePart);

            Assert.AreEqual(revenger.TotalAttack, 12, $"TotalAttack property returns invalid result");
            Assert.AreEqual(revenger.TotalDefense, 6, $"TotalDefense property returns invalid result");
            Assert.AreEqual(revenger.TotalHitPoints, 12, $"TotalHitPoints property returns invalid result");
            Assert.AreEqual(revenger.TotalPrice, 18, $"TotalPrice property returns invalid result");
            Assert.AreEqual(revenger.TotalWeight, 18, $"TotalWeight property returns invalid result");

            var shellPart = new ShellPart("End", 6d, 6m, 6);

            revenger.AddShellPart(shellPart);

            Assert.AreEqual(revenger.TotalAttack, 12, $"TotalAttack property returns invalid result");
            Assert.AreEqual(revenger.TotalDefense, 12, $"TotalDefense property returns invalid result");
            Assert.AreEqual(revenger.TotalHitPoints, 12, $"TotalHitPoints property returns invalid result");
            Assert.AreEqual(revenger.TotalPrice, 24, $"TotalPrice property returns invalid result");
            Assert.AreEqual(revenger.TotalWeight, 24, $"TotalWeight property returns invalid result");

            var actualParts   = revenger.Parts;
            var expectedParts = new List <IPart>()
            {
                arsenalPart, shellPart, endurancePart
            };

            Assert.AreEqual(actualParts, expectedParts, $"Parts property returns invalid result");
        }
Пример #15
0
        public void Test3()
        {
            var vehicle = new Revenger("Pesho", 111, 12, 123, 123, 123, new VehicleAssembler());

            vehicle.AddArsenalPart(new ArsenalPart("TestPart1", 12, 12, 12));
            vehicle.AddShellPart(new ShellPart("TestPart2", 2, 2, 2));
            vehicle.AddEndurancePart(new EndurancePart("TestPart3", 1, 1, 1));

            var actual   = vehicle.ToString();
            var expected = @"Revenger - Pesho
Total Weight: 126.000
Total Price: 27.000
Attack: 135
Defense: 125
HitPoints: 124
Parts: TestPart1, TestPart2, TestPart3";

            Assert.That(actual, Is.EqualTo(expected));
        }
Пример #16
0
        public void CheckIfReturnCorrectResultAfterBattle()
        {
            var assembler = new VehicleAssembler();

            var tank  = new Vanguard("SA - 203", 100, 300, 1000, 450, 2000, assembler);
            var tank2 = new Revenger("AKU", 1000, 1000, 1000, 1000, 1000, assembler);
            var part1 = new ArsenalPart("Cannon - KA2", 300, 500, 450);
            var part2 = new ShellPart("Shields - PI1", 200, 1000, 750);
            var part3 = new EndurancePart("Shields - PI1", 200, 1000, 750);

            tank.AddArsenalPart(part1);
            tank2.AddShellPart(part2);
            tank2.AddEndurancePart(part3);


            var expectedResult = tank2.ToString();
            var actualResult   = "Revenger - AKU\r\nTotal Weight: 1700.000\r\nTotal Price: 3500.000\r\nAttack: 1450\r\nDefense: 1750\r\nHitPoints: 1750\r\nParts: Shields - PI1, Shields - PI1";

            Assert.AreEqual(expectedResult, actualResult);
        }
Пример #17
0
        public void TestAddingMethods()
        {
            IPart      part      = new ArsenalPart("Arsenal", 2, 2, 2);
            IAssembler assembler = new VehicleAssembler();

            assembler.AddArsenalPart(part);
            assembler.AddArsenalPart(part);

            IVehicle vehicle = new Revenger("Revenger", 22, 22, 22, 22, 22, assembler);

            vehicle.AddArsenalPart(part);

            Assert.That(() => assembler.ArsenalParts.Count, Is.EqualTo(3));

            vehicle.AddEndurancePart(new EndurancePart("Endurance", 2, 2, 2));
            Assert.That(() => assembler.EnduranceParts.Count, Is.EqualTo(1));

            vehicle.AddShellPart(new ShellPart("Shell", 2, 2, 2));
            Assert.That(() => assembler.ShellParts.Count, Is.EqualTo(1));
        }
        public void TestRevenger()
        {
            Revenger      vehicle       = new Revenger("Kolio", 80, 3M, 1, 1, 1, new VehicleAssembler());
            ArsenalPart   arsenalPart   = new ArsenalPart("Ars1", 10, 3M, 10);
            EndurancePart endurancePart = new EndurancePart("End1", 10, 3M, 10);
            ShellPart     shellPart     = new ShellPart("Shell1", 10, 3M, 10);

            vehicle.AddArsenalPart(arsenalPart);
            vehicle.AddEndurancePart(endurancePart);
            vehicle.AddShellPart(shellPart);

            int     expectedAttack    = 11;
            int     expectedEndurance = 11;
            int     expectedDefense   = 11;
            int     expectedWeight    = 110;
            decimal totalPrice        = 12M;

            Assert.AreEqual(expectedAttack, vehicle.TotalAttack);
            Assert.AreEqual(expectedEndurance, vehicle.TotalHitPoints);
            Assert.AreEqual(expectedDefense, vehicle.TotalDefense);
            Assert.AreEqual(expectedWeight, vehicle.TotalWeight);
            Assert.AreEqual(totalPrice, vehicle.TotalPrice);
        }
Пример #19
0
        public void ValidateReturnString()
        {
            var           vehicle = new Revenger("Model1", 100, 100, 10, 10, 10, new VehicleAssembler());
            StringBuilder result  = new StringBuilder();

            result.AppendLine($"Revenger - Model1");
            result.AppendLine($"Total Weight: {100:F3}");
            result.AppendLine($"Total Price: {100:F3}");
            result.AppendLine($"Attack: {10}");
            result.AppendLine($"Defense: {10}");
            result.AppendLine($"HitPoints: {10}");

            result.Append("Parts: None");

            Assert.That(vehicle.ToString(), Is.EqualTo(result.ToString()));

            var attackPart    = new ArsenalPart("ArsenalModel", 1.5, 2.5m, 10);
            var shellPart     = new ShellPart("ShellModel", 1.5, 2.5m, 15);
            var endurancePart = new EndurancePart("EnduranceModel", 1.5, 2.5m, 20);

            vehicle.AddEndurancePart(endurancePart);
            vehicle.AddArsenalPart(attackPart);
            vehicle.AddShellPart(shellPart);

            result.Clear();
            result.AppendLine($"Revenger - Model1");
            result.AppendLine($"Total Weight: {104.5:F3}");
            result.AppendLine($"Total Price: {107.5:F3}");
            result.AppendLine($"Attack: {20}");
            result.AppendLine($"Defense: {25}");
            result.AppendLine($"HitPoints: {30}");

            result.Append("Parts: EnduranceModel, ArsenalModel, ShellModel");

            Assert.That(vehicle.ToString(), Is.EqualTo(result.ToString()));
        }