public string AttachFragment(string[] parameters)
        {
            string type = parameters[0];
            string name = parameters[1];
            int    pressureAffection = int.Parse(parameters[2]);

            try
            {
                if (type != FragmentType.Cooling.ToString() &&
                    type != FragmentType.Nuclear.ToString())
                {
                    throw new ArgumentException();
                }
                IFragment fragment = null;

                switch (type)
                {
                case "Cooling":
                    fragment = new CoolingFragment(type, name, pressureAffection);
                    break;

                case "Nuclear":
                    fragment = new NuclearFragment(type, name, pressureAffection);
                    break;
                }

                return(this.selectedCore.AttachFragment(fragment));
            }
            catch (Exception)
            {
                return($"Failed to attach Fragment {name}!");
            }
        }
Пример #2
0
        public void TestPeek_PeekWithOneElement_ShouldReturnElement()
        {
            IFragment dummyFragment = new NuclearFragment("Test", 1);

            this.testStack.Push(dummyFragment);

            IFragment peekedFragment = this.testStack.Peek();

            Assert.AreEqual(peekedFragment, dummyFragment);
        }
Пример #3
0
        public void TestadditionOfElement_WithOneElement_ShouldWorkFine()
        {
            IFragment dummyFragment = new NuclearFragment("Test", 1);

            this.testStack.Push(dummyFragment);

            foreach (var fragment in this.testStack)
            {
                Assert.AreEqual(dummyFragment, fragment, "The addition of elements in the stack does not work properly!");
            }
        }
Пример #4
0
        public void TestPeek_PeekWithOneElement_ShouldNotDecreaseSizeOfStack()
        {
            IFragment dummyFragment = new NuclearFragment("Test", 1);

            this.testStack.Push(dummyFragment);

            IFragment peekedFragment = this.testStack.Peek();

            int stackSize = this.testStack.Count();

            Assert.AreEqual(1, stackSize);
        }
Пример #5
0
        public void TestElementRemoval_RemoveWithTwoElements_ShouldReturnTopElement()
        {
            IFragment dummyFragment        = new NuclearFragment("Test", 1);
            IFragment anotherDummyFragment = new NuclearFragment("Test2", 1);

            this.testStack.Push(dummyFragment);
            this.testStack.Push(anotherDummyFragment);

            IFragment removedElement = this.testStack.Pop();

            Assert.AreEqual(removedElement, anotherDummyFragment);
        }
Пример #6
0
        public void TestSizeOfStack_WithTwoElements_ShouldReturnCorrectValue()
        {
            IFragment dummyFragment        = new NuclearFragment("Test", 1);
            IFragment anotherDummyFragment = new NuclearFragment("Test2", 1);

            this.testStack.Push(dummyFragment);
            this.testStack.Push(anotherDummyFragment);

            int stackSize = this.testStack.Count();

            Assert.AreEqual(2, stackSize);
        }
Пример #7
0
        public void TestIsEmpty_WithTwoElements_ShouldReturnFalse()
        {
            IFragment dummyFragment        = new NuclearFragment("Test", 1);
            IFragment anotherDummyFragment = new NuclearFragment("Test2", 1);

            this.testStack.Push(dummyFragment);
            this.testStack.Push(anotherDummyFragment);

            bool isEmpty = this.testStack.IsEmpty();

            Assert.AreEqual(false, isEmpty);
        }
Пример #8
0
        public void TestElementRemoval_RemoveWithTwoElements_ShouldDecreaseStackSize()
        {
            IFragment dummyFragment        = new NuclearFragment("Test", 1);
            IFragment anotherDummyFragment = new NuclearFragment("Test2", 1);

            this.testStack.Push(dummyFragment);
            this.testStack.Push(anotherDummyFragment);

            this.testStack.Pop();

            int stackSize = this.testStack.Count();

            Assert.AreEqual(1, stackSize);
        }
        public IFragment CreateFragment(FragmentType fragmentType, string name, int pressureAffection)
        {
            IFragment fragment = null;
            switch (fragmentType)
            {
                case FragmentType.Cooling:
                    fragment = new CoolingFragment(name, pressureAffection);
                    break;
                case FragmentType.Nuclear:
                    fragment = new NuclearFragment(name, pressureAffection);
                    break;
            }

            return fragment;
        }
        public void TestDetach_WithSelectedCore_WithOneFragment_ShouldReturnSuccessMessage()
        {
            ICore     dummyCore     = new SystemCore("A", 100);
            IFragment dummyFragment = new NuclearFragment("Test", 1);

            dummyCore.AttachFragment(dummyFragment);

            this.testNuclearPowerPlant.AttachCore(dummyCore);
            this.testNuclearPowerPlant.SelectCore("A");

            ICommand testCommand   = new DetachFragmentCommand(this.testNuclearPowerPlant);
            String   actualMessage = testCommand.Execute();

            String expectedMessage = "Successfully detached Fragment Test from Core A!";

            Assert.AreEqual(expectedMessage, actualMessage, "DetachFragment command does not work correctly!");
        }