예제 #1
0
        public void Open(string filename)
        {
            XmlConfigFile         existingModel   = this.Model;
            UnitTestFileViewModel existingUTModel = this.UnitTestFile;

            try
            {
                ActiveConfig.DB.CanCache = true;
                AcmaSchemaAttribute.MissingAttributeEvent += AcmaSchemaAttribute_MissingAttributeEvent;
                UINotifyPropertyChanges.BeginIgnoreAllChanges();
                this.Model        = ActiveConfig.LoadXml(filename);
                this.unitTestFile = TestEngine.UnitTestFile.LoadXml(this.FileName);
                this.ReloadRootNodes();
                this.ResetChangeState();
            }
            catch
            {
                this.Model        = existingModel;
                this.UnitTestFile = existingUTModel;
                throw;
            }
            finally
            {
                UINotifyPropertyChanges.EndIgnoreAllChanges();
                this.RaisePropertyChanged("DisplayName");
                this.RaisePropertyChanged("ChildNodes");
                AcmaSchemaAttribute.ClearLostFoundCache();
                AcmaSchemaAttribute.MissingAttributeEvent -= AcmaSchemaAttribute_MissingAttributeEvent;
                ActiveConfig.DB.CanCache = false;
            }
        }
예제 #2
0
        public void New()
        {
            ActiveConfig.DB.CanCache = true;
            UINotifyPropertyChanges.BeginIgnoreAllChanges();
            UniqueIDCache.ClearIdCache();
            this.Model             = new XmlConfigFile();
            this.unitTestFile      = new TestEngine.UnitTestFile();
            ActiveConfig.XmlConfig = this.Model;
            UINotifyPropertyChanges.EndIgnoreAllChanges();
            this.ReloadRootNodes();

            this.RaisePropertyChanged("DisplayName");
            this.RaisePropertyChanged("ChildNodes");
            this.ResetChangeState();
            ActiveConfig.DB.CanCache = false;
        }
예제 #3
0
        protected override void ProcessRecord()
        {
            Global.ThrowIfNotConnected(this);

            try
            {
                UnitTestFile file = this.LoadUnitTestFile();
                UnitTestFile.BreakOnTestFailure = this.BreakOnTestFailure;

                MAStatistics.StartOperation(MAOperationType.Export);
                Console.WriteLine(string.Empty.PadRight(79, '-'));
                Console.WriteLine("Executing unit tests from: {0}", Path.GetFileName(ActiveConfig.XmlConfig.FileName));
                Console.WriteLine();
                UnitTest.UnitTestStartingEvent            += UnitTest_UnitTestStartingEvent;
                UnitTest.UnitTestCompletedEvent           += UnitTest_UnitTestCompletedEvent;
                UnitTestGroup.UnitTestGroupStartingEvent  += UnitTestGroup_UnitTestGroupStartingEvent;
                UnitTestGroup.UnitTestGroupCompletedEvent += UnitTestGroup_UnitTestGroupCompletedEvent;
                UnitTestOutcomes report = file.Execute();
                MAStatistics.StopOperation();
                Console.WriteLine();

                Console.WriteLine(string.Empty.PadRight(79, '-'));
                if (report.TestCount > 0)
                {
                    Console.WriteLine("Executed {0} tests", report.TestCount);

                    if (report.TestCount == report.TestSuccessfulCount)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                    }

                    Console.WriteLine("{0} ({1}%) successful", report.TestSuccessfulCount, report.TestSuccessfulPercent.ToString("D"));
                    Console.ForegroundColor = ConsoleColor.Gray;

                    if (report.TestFailedCount > 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                    }

                    Console.WriteLine("{0} ({1}%) failed", report.TestFailedCount, report.TestFailedPercent.ToString("D"));
                    Console.ForegroundColor = ConsoleColor.Gray;

                    if (report.TestInconclusiveCount > 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                    }

                    Console.WriteLine("{0} ({1}%) inconclusive", report.TestInconclusiveCount, report.TestInconclusivePercent.ToString("D"));
                    Console.ForegroundColor = ConsoleColor.Gray;


                    if (report.TestErrorCount > 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                    }

                    Console.WriteLine("{0} ({1}%) error{2}", report.TestErrorCount, report.TestErrorPercent.ToString("D"), report.TestErrorCount == 1 ? string.Empty : "s");
                    Console.ForegroundColor = ConsoleColor.Gray;
                }
                else
                {
                    Console.WriteLine("No tests were executed");
                }
                Console.WriteLine(string.Empty.PadRight(79, '-'));

                Console.WriteLine(MAStatistics.ToString());

                Console.WriteLine(string.Empty.PadRight(79, '-'));

                if (!string.IsNullOrWhiteSpace(this.HtmlReportFileName))
                {
                    Console.Write("Writing test results to: {0}... ", this.HtmlReportFileName);
                    report.ToHtml(this.HtmlReportFileName);
                    Console.WriteLine("Done");
                }
            }
            catch (Exception ex)
            {
                ErrorRecord error = new ErrorRecord(ex, "UnknownError", ErrorCategory.NotSpecified, null);
                ThrowTerminatingError(error);
            }
            finally
            {
                UnitTest.UnitTestStartingEvent            -= UnitTest_UnitTestStartingEvent;
                UnitTest.UnitTestCompletedEvent           -= UnitTest_UnitTestCompletedEvent;
                UnitTestGroup.UnitTestGroupStartingEvent  -= UnitTestGroup_UnitTestGroupStartingEvent;
                UnitTestGroup.UnitTestGroupCompletedEvent -= UnitTestGroup_UnitTestGroupCompletedEvent;
            }
        }
예제 #4
0
 private UnitTestFile LoadUnitTestFile()
 {
     return(UnitTestFile.LoadXml(ActiveConfig.XmlConfig.FileName));
 }
예제 #5
0
        public void TestSerialization()
        {
            UnitTest unitTest1 = new UnitTest();

            unitTest1.Description = "unit test 1";
            unitTest1.ExpectedConstructors.Add("ABC123");
            unitTest1.ExpectedConstructors.Add("123DGS");
            unitTest1.ID = "ID1234";

            UnitTestStepObjectCreation ut1step1 = new UnitTestStepObjectCreation();
            AcmaCSEntryChange          csentry1 = new AcmaCSEntryChange();

            csentry1.ObjectModificationType = ObjectModificationType.Add;
            csentry1.ObjectType             = "person";
            csentry1.DN            = "testDN";
            ut1step1.Name          = "mystep1";
            ut1step1.CSEntryChange = csentry1;
            unitTest1.Steps.Add(ut1step1);


            UnitTestStepObjectEvaluation ut1step2 = new UnitTestStepObjectEvaluation();

            ut1step2.Name = "mystep2";
            ut1step2.ObjectCreationStep = ut1step1;
            ut1step2.SuccessCriteria    = new RuleGroup();
            ut1step2.SuccessCriteria.Items.Add(new ObjectChangeRule()
            {
                Description = "test", TriggerEvents = TriggerEvents.Add
            });
            unitTest1.Steps.Add(ut1step2);

            UnitTest unitTest2 = new UnitTest();

            unitTest2.Description = "unit test 1";
            unitTest2.ExpectedConstructors.Add("ABC123");
            unitTest2.ExpectedConstructors.Add("123DGS");
            unitTest2.ID = "ID1234";

            UnitTestStepObjectModification ut2step1 = new UnitTestStepObjectModification();
            AcmaCSEntryChange csentry2 = new AcmaCSEntryChange();

            csentry2.ObjectModificationType = ObjectModificationType.Update;
            csentry2.ObjectType             = "person";
            csentry2.DN            = "testDN";
            ut2step1.Name          = "mystep1";
            ut2step1.CSEntryChange = csentry2;
            unitTest2.Steps.Add(ut2step1);

            UnitTestStepObjectEvaluation ut2step2 = new UnitTestStepObjectEvaluation();

            ut2step2.Name = "mystep2";
            ut2step2.ObjectCreationStep = ut1step1;
            ut2step2.SuccessCriteria    = new RuleGroup();
            ut2step2.SuccessCriteria.Items.Add(new ObjectChangeRule()
            {
                Description = "test", TriggerEvents = TriggerEvents.Add
            });
            unitTest2.Steps.Add(ut2step2);

            UnitTestFile toSerialize = new UnitTestFile();

            toSerialize.ConfigVersion = "1";
            toSerialize.Description   = "test description";
            toSerialize.UnitTestObjects.Add(unitTest1);
            toSerialize.UnitTestObjects.Add(unitTest2);

            UniqueIDCache.ClearIdCache();
            UnitTestFile deserialized = UnitTestControl.XmlSerializeRoundTrip <UnitTestFile>(toSerialize);

            Assert.AreEqual(toSerialize.Description, deserialized.Description);
            Assert.AreEqual(toSerialize.ConfigVersion, deserialized.ConfigVersion);
            Assert.AreEqual(toSerialize.UnitTestObjects.Count, deserialized.UnitTestObjects.Count);

            UnitTest deserializedUnitTest1 = deserialized.UnitTestObjects[0] as UnitTest;

            Assert.AreEqual(unitTest1.Description, deserializedUnitTest1.Description);
            Assert.AreEqual(unitTest1.ExpectedConstructors[0], deserializedUnitTest1.ExpectedConstructors[0]);
            Assert.AreEqual(unitTest1.ExpectedConstructors[1], deserializedUnitTest1.ExpectedConstructors[1]);
            Assert.AreEqual(unitTest1.ID, deserializedUnitTest1.ID);
            Assert.AreEqual(((UnitTestStepObjectCreation)unitTest1.Steps[0]).Name, ((UnitTestStepObjectCreation)deserializedUnitTest1.Steps[0]).Name);
            Assert.AreEqual(((UnitTestStepObjectCreation)unitTest1.Steps[0]).CSEntryChange.DN, ((UnitTestStepObjectCreation)deserializedUnitTest1.Steps[0]).CSEntryChange.DN);
            Assert.AreEqual(((UnitTestStepObjectCreation)unitTest1.Steps[0]).CSEntryChange.ObjectType, ((UnitTestStepObjectCreation)deserializedUnitTest1.Steps[0]).CSEntryChange.ObjectType);
            Assert.AreEqual(((UnitTestStepObjectCreation)unitTest1.Steps[0]).CSEntryChange.ObjectModificationType, ((UnitTestStepObjectCreation)deserializedUnitTest1.Steps[0]).CSEntryChange.ObjectModificationType);

            Assert.AreEqual(((UnitTestStepObjectEvaluation)unitTest1.Steps[1]).Name, ((UnitTestStepObjectEvaluation)deserializedUnitTest1.Steps[1]).Name);
            Assert.AreEqual(((UnitTestStepObjectEvaluation)unitTest1.Steps[1]).ObjectCreationStepName, ((UnitTestStepObjectEvaluation)deserializedUnitTest1.Steps[1]).ObjectCreationStepName);
            Assert.AreEqual(((UnitTestStepObjectEvaluation)unitTest1.Steps[1]).SuccessCriteria.Items.Count, ((UnitTestStepObjectEvaluation)deserializedUnitTest1.Steps[1]).SuccessCriteria.Items.Count);
        }