internal void InsertAction(AddRowsTest.InsertPosition insertPosition, int count)
        {
            var selValues = new SelectedValues();

            selValues.Values = SelectedValue.CreateNew(count);
            switch (insertPosition)
            {
            case AddRowsTest.InsertPosition.First:
                ActionValues.Insert(0, selValues);
                break;

            case AddRowsTest.InsertPosition.Second:
                ActionValues.Insert(1, selValues);
                break;

            case AddRowsTest.InsertPosition.Last:
                ActionValues.Insert(ActionValues.Count - 1, selValues);
                break;

            case AddRowsTest.InsertPosition.AfterLast:
                ActionValues.Add(selValues);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(insertPosition), insertPosition, null);
            }
        }
        public void TestInsertTestCase(AddRowsTest.InsertPosition insertPosition)
        {
            string firstPath            = Path.Combine(TestSupport.CreatedFilesDirectory, insertPosition + "_first.xml");
            string secondPath           = Path.Combine(TestSupport.CreatedFilesDirectory, insertPosition + "_second.xml");
            TestCasesRootContainer tcrc = new TestCasesRootContainer();

            tcrc.TestCasesRoot.TestCases[0].DisplayIndex = 3;
            tcrc.TestCasesRoot.TestCases[1].DisplayIndex = 4;
            tcrc.TestCasesRoot.TestCases[2].DisplayIndex = 6;
            tcrc.TestCasesRoot.TestCases[3].DisplayIndex = 1;
            tcrc.TestCasesRoot.TestCases[4].DisplayIndex = 5;
            tcrc.TestCasesRoot.TestCases[5].DisplayIndex = 2;

            SaveTestCasesDisplayOrder(tcrc, firstPath);
            SelectedValuesByTestCases selValues = new SelectedValuesByTestCases();

            selValues.CollectValues(tcrc.TestCasesRoot);
            selValues.Check(tcrc.TestCasesRoot);

            int indexWhereToInsert = TestUtils.CalculateIndex(tcrc.TestCasesRoot.TestCases, insertPosition);

            int      testCaseCount = tcrc.TestCasesRoot.TestCases.Count;
            TestCase newTestCase   = tcrc.TestCasesRoot.InsertTestCase(indexWhereToInsert);
            string   testCaseId    = "new test case " + DateTime.Now.ToString("F");

            newTestCase.TestProperty = testCaseId;

            TestUtils.CheckTestCasesAndConditionsAndActions(tcrc.TestCasesRoot);
            Assert.That(tcrc.TestCasesRoot.TestCases.Count == testCaseCount + 1);
            Assert.That(tcrc.TestCasesRoot.TestCases[indexWhereToInsert].TestProperty.Equals(testCaseId));
            Assert.That(tcrc.ConditionChangeCount == 2);
            Assert.That(tcrc.ActionChangeCount == 2);
            selValues.AppendTestCase(newTestCase, tcrc.TestCasesRoot);
            selValues.Check(tcrc.TestCasesRoot);

            SaveTestCasesDisplayOrder(tcrc, secondPath);

            Assert.That(TestSupport.CompareFile(TestSupport.CreatedFilesDirectory, TestSupport.ReferenceFilesDirectory, Path.GetFileName(firstPath)));
            Assert.That(TestSupport.CompareFile(TestSupport.CreatedFilesDirectory, TestSupport.ReferenceFilesDirectory, Path.GetFileName(secondPath)));
            // only for manual check of testcase
            //TestSupport.CompareFile(firstPath, secondPath);
        }
Esempio n. 3
0
        public static int CalculateIndex <TType>(IList <TType> conditionOrAction, AddRowsTest.InsertPosition indexWhereToInsert)
        {
            switch (indexWhereToInsert)
            {
            case AddRowsTest.InsertPosition.First:
                return(0);

            case AddRowsTest.InsertPosition.Second:
                return(1);

            case AddRowsTest.InsertPosition.Last:
                return(conditionOrAction.Count - 1);

            case AddRowsTest.InsertPosition.AfterLast:
                return(conditionOrAction.Count);

            default:
                throw new ArgumentOutOfRangeException(nameof(indexWhereToInsert), indexWhereToInsert, null);
            }
        }
        public void TestDeleteAndAddTestCase(AddRowsTest.DeletePosition deletePosition, int deleteCount, AddRowsTest.InsertPosition insertPosition, int addCount)
        {
            string firstPath            = Path.Combine(TestSupport.CreatedFilesDirectory, "first.xml");
            string secondPath           = Path.Combine(TestSupport.CreatedFilesDirectory, "second.xml");
            TestCasesRootContainer tcrc = new TestCasesRootContainer();

            tcrc.TestCasesRoot.Save(firstPath);
            SelectedValuesByTestCases selValues = new SelectedValuesByTestCases();

            selValues.CollectValues(tcrc.TestCasesRoot);
            selValues.Check(tcrc.TestCasesRoot);

            int testCaseCount = tcrc.TestCasesRoot.TestCases.Count;

            for (int idx = 0; idx < deleteCount; idx++)
            {
                int      indexWhereToDelete = TestUtils.CalculateIndex(tcrc.TestCasesRoot.TestCases, deletePosition);
                TestCase deletedTestCase    = tcrc.TestCasesRoot.TestCases[indexWhereToDelete];
                tcrc.TestCasesRoot.DeleteTestCaseAt(indexWhereToDelete);
                selValues.DeleteTestCase(deletedTestCase, tcrc.TestCasesRoot);
            }

            TestUtils.CheckTestCasesAndConditionsAndActions(tcrc.TestCasesRoot);
            Assert.That(tcrc.TestCasesRoot.TestCases.Count == testCaseCount - deleteCount);
            Assert.That(tcrc.ConditionChangeCount == deleteCount * 2);
            Assert.That(tcrc.ActionChangeCount == deleteCount * 2);
            selValues.Check(tcrc.TestCasesRoot);

            testCaseCount = tcrc.TestCasesRoot.TestCases.Count;
            for (int idx = 0; idx < addCount; idx++)
            {
                int      indexWhereToInsert = TestUtils.CalculateIndex(tcrc.TestCasesRoot.TestCases, insertPosition);
                TestCase newTestCase        = tcrc.TestCasesRoot.InsertTestCase(indexWhereToInsert);
                string   testCaseId         = "new test case " + DateTime.Now.ToString("F");
                newTestCase.TestProperty = testCaseId;
                selValues.AppendTestCase(newTestCase, tcrc.TestCasesRoot);
                Assert.That(tcrc.TestCasesRoot.TestCases[indexWhereToInsert].TestProperty.Equals(testCaseId));
            }

            TestUtils.CheckTestCasesAndConditionsAndActions(tcrc.TestCasesRoot);
            Assert.That(tcrc.TestCasesRoot.TestCases.Count == testCaseCount + addCount);
            Assert.That(tcrc.ConditionChangeCount == (deleteCount + addCount) * 2);
            Assert.That(tcrc.ActionChangeCount == (deleteCount + addCount) * 2);
            selValues.Check(tcrc.TestCasesRoot);

            tcrc.TestCasesRoot.Save(secondPath);
            // only for manual check of testcase
            //TestSupport.CompareFile(firstPath, secondPath);
        }