public void TestTrivialActivityCoverage()
        {
            var configuration = Configuration.Create();

            configuration.ReportActivityCoverage = true;

            TestingEngine testingEngine = this.Test(r =>
            {
                r.CreateActor(typeof(M0));
            },
                                                    configuration);

            string result;
            var    activityCoverageReporter = new ActivityCoverageReporter(testingEngine.TestReport.CoverageInfo);

            using (var writer = new StringWriter())
            {
                activityCoverageReporter.WriteCoverageText(writer);
                result = RemoveNamespaceReferencesFromReport(writer.ToString());
                result = RemoveExcessiveEmptySpaceFromReport(result);
            }

            var expected = @"Total event coverage: 100.0%
============================
StateMachine: M0
========================================================================================
Event coverage: 100.0%

	State: Init
		State has no expected events, so coverage is 100%
";

            expected = RemoveExcessiveEmptySpaceFromReport(expected);
            Assert.Equal(expected, result);
        }
예제 #2
0
        public void TestCoverageOnMultipleTests()
        {
            var configuration = Configuration.Create().WithVerbosityEnabled();

            configuration.ReportActivityCoverage = true;

            ITestingEngine testingEngine1 = this.Test(r =>
            {
                var m = r.CreateMachine(typeof(M4));
                r.SendEvent(m, new E());
            },
                                                      configuration);

            // Assert that the coverage is as expected.
            var coverage1 = testingEngine1.TestReport.CoverageInfo;

            Assert.Contains(typeof(M4).FullName, coverage1.MachinesToStates.Keys);
            Assert.Contains(typeof(M4.Init).Name, coverage1.MachinesToStates[typeof(M4).FullName]);
            Assert.Contains(typeof(M4.Done).Name, coverage1.MachinesToStates[typeof(M4).FullName]);
            Assert.Contains(coverage1.RegisteredEvents, tup => tup.Item3 == typeof(E).FullName);

            ITestingEngine testingEngine2 = this.Test(r =>
            {
                var m = r.CreateMachine(typeof(M4));
                r.SendEvent(m, new E());
            },
                                                      configuration);

            // Assert that the coverage is the same as before.
            var coverage2 = testingEngine2.TestReport.CoverageInfo;

            Assert.Contains(typeof(M4).FullName, coverage2.MachinesToStates.Keys);
            Assert.Contains(typeof(M4.Init).Name, coverage2.MachinesToStates[typeof(M4).FullName]);
            Assert.Contains(typeof(M4.Done).Name, coverage2.MachinesToStates[typeof(M4).FullName]);
            Assert.Contains(coverage2.RegisteredEvents, tup => tup.Item3 == typeof(E).FullName);

            string coverageReport1, coverageReport2;

            var activityCoverageReporter = new ActivityCoverageReporter(coverage1);

            using (var writer = new StringWriter())
            {
                activityCoverageReporter.WriteCoverageText(writer);
                coverageReport1 = writer.ToString();
            }

            activityCoverageReporter = new ActivityCoverageReporter(coverage2);
            using (var writer = new StringWriter())
            {
                activityCoverageReporter.WriteCoverageText(writer);
                coverageReport2 = writer.ToString();
            }

            Assert.Equal(coverageReport1, coverageReport2);
        }
예제 #3
0
        protected string TestCoverage(Action <IActorRuntime> test, Configuration configuration)
        {
            var engine = this.InternalTest(test, configuration);

            using var writer = new StringWriter();
            var activityCoverageReporter = new ActivityCoverageReporter(engine.TestReport.CoverageInfo);

            activityCoverageReporter.WriteCoverageText(writer);
            string result = writer.ToString().RemoveNamespaceReferences();

            return(result);
        }
        private void TestPushStateActivityCoverage()
        {
            var configuration = Configuration.Create();

            configuration.ReportActivityCoverage = true;

            TestingEngine testingEngine = this.Test(r =>
            {
                var actor = r.CreateActor(typeof(M6));
                r.SendEvent(actor, new E1());  // even though Ready state is pushed E1 can still be handled by Init state because Init state is still active.
                r.SendEvent(actor, new E2());  // and that handling does not pop the Ready state, so Ready can still handle E2.
            },
                                                    configuration);

            string result;
            var    activityCoverageReporter = new ActivityCoverageReporter(testingEngine.TestReport.CoverageInfo);

            using (var writer = new StringWriter())
            {
                activityCoverageReporter.WriteCoverageText(writer);
                result = RemoveNamespaceReferencesFromReport(writer.ToString());
                result = RemoveExcessiveEmptySpaceFromReport(result);
            }

            var expected = @"Total event coverage: 100.0%
============================
StateMachine: M6
========================================================================================
Event coverage: 100.0%

	State: Init
		State event coverage: 100.0%
		Events received: E1
		Next states: Ready

	State: Ready
		State event coverage: 100.0%
		Events received: E2
		Previous states: Init

StateMachine: ExternalCode
==========================
Event coverage: 100.0%

	State: ExternalState
		State has no expected events, so coverage is 100%
		Events sent: E1, E2
";

            expected = RemoveExcessiveEmptySpaceFromReport(expected);
            Assert.Equal(expected, result);
        }
        public void TestUncoveredEvents()
        {
            var configuration = Configuration.Create();

            configuration.ReportActivityCoverage = true;

            TestingEngine testingEngine = this.Test(r =>
            {
                var m = r.CreateActor(typeof(M5));
                r.SendEvent(m, new E1());
            },
                                                    configuration);

            string result;
            var    activityCoverageReporter = new ActivityCoverageReporter(testingEngine.TestReport.CoverageInfo);

            using (var writer = new StringWriter())
            {
                activityCoverageReporter.WriteCoverageText(writer);
                result = RemoveNamespaceReferencesFromReport(writer.ToString());
                result = RemoveExcessiveEmptySpaceFromReport(result);
            }

            var expected = @"Total event coverage: 50.0%
===========================
StateMachine: M5
========================================================================================
Event coverage: 50.0%

	State: Init
		State event coverage: 50.0%
		Events received: E1
		Events not covered: E2
		Next states: Done

	State: Done
		State has no expected events, so coverage is 100%
		Previous states: Init

StateMachine: ExternalCode
==========================
Event coverage: 100.0%

	State: ExternalState
		State has no expected events, so coverage is 100%
		Events sent: E1
";

            expected = RemoveExcessiveEmptySpaceFromReport(expected);
            Assert.Equal(expected, result);
        }
        public void TestMachineSendEventActivityCoverage()
        {
            var configuration = Configuration.Create();

            configuration.ReportActivityCoverage = true;

            TestingEngine testingEngine = this.Test(r =>
            {
                r.CreateActor(typeof(M3A));
            },
                                                    configuration);

            string result;
            var    activityCoverageReporter = new ActivityCoverageReporter(testingEngine.TestReport.CoverageInfo);

            using (var writer = new StringWriter())
            {
                activityCoverageReporter.WriteCoverageText(writer);
                result = RemoveNamespaceReferencesFromReport(writer.ToString());
                result = RemoveExcessiveEmptySpaceFromReport(result);
            }

            var expected = @"Total event coverage: 100.0%
============================
StateMachine: M3A
=========================================================================================
Event coverage: 100.0%

	State: Init
		State event coverage: 100.0%
		Events received: HelloEvent, Events.UnitEvent
		Next states: Done

	State: Done
		State has no expected events, so coverage is 100%
		Previous states: Init

StateMachine: M3B
=========================================================================================
Event coverage: 100.0%

	State: Init
		State has no expected events, so coverage is 100%
		Events sent: HelloEvent, Events.UnitEvent
";

            expected = RemoveExcessiveEmptySpaceFromReport(expected);
            Assert.Equal(expected, result);
        }
예제 #7
0
        public void TestMachineSendEventActivityCoverage()
        {
            var configuration = Configuration.Create().WithVerbosityEnabled();

            configuration.ReportActivityCoverage = true;

            ITestingEngine testingEngine = this.Test(r =>
            {
                r.CreateMachine(typeof(M3A));
            },
                                                     configuration);

            string result;
            var    activityCoverageReporter = new ActivityCoverageReporter(testingEngine.TestReport.CoverageInfo);

            using (var writer = new StringWriter())
            {
                activityCoverageReporter.WriteCoverageText(writer);
                result = RemoveNamespaceReferencesFromReport(writer.ToString());
                result = RemoveExcessiveEmptySpaceFromReport(result);
            }

            var expected = @"Total event coverage: 100.0%
Machine: M3A
***************
Machine event coverage: 100.0%
        State: Init
                State event coverage: 100.0%
                Events received: E
                Next states: Done
        State: Done
                State event coverage: 100.0%
                Previous states: Init

Machine: M3B
***************
Machine event coverage: 100.0%
        State: Init
                State event coverage: 100.0%
                Events sent: E
";

            expected = RemoveExcessiveEmptySpaceFromReport(expected);
            Assert.Equal(expected, result);
        }
        public void TestMonitorActivityCoverage()
        {
            var configuration = Configuration.Create();

            configuration.ReportActivityCoverage = true;

            TestingEngine testingEngine = this.Test(r =>
            {
                r.RegisterMonitor <Monitor1>();
                var actor = r.CreateActor(typeof(M7));
                r.SendEvent(actor, new E1());
                r.SendEvent(actor, new E2());
            },
                                                    configuration);

            string result;
            var    activityCoverageReporter = new ActivityCoverageReporter(testingEngine.TestReport.CoverageInfo);

            using (var writer = new StringWriter())
            {
                activityCoverageReporter.WriteCoverageText(writer);
                result = RemoveNamespaceReferencesFromReport(writer.ToString());
            }

            var expected = @"Total event coverage: 100.0%
============================
StateMachine: M7
========================================================================================
Event coverage: 100.0%

	State: Init
		State event coverage: 100.0%
		Events received: E1
		Next states: Ready

	State: Ready
		State event coverage: 100.0%
		Events received: E2
		Previous states: Init

Monitor: Monitor1
=========================================================================================
Event coverage: 100.0%

	State: Idle
		State event coverage: 100.0%
		Events received: E1
		Next states: Busy[hot]

	State: Busy
		State event coverage: 100.0%
		Events received: E2
		Next states: Idle[cold]

StateMachine: ExternalCode
==========================
Event coverage: 100.0%

	State: ExternalState
		State has no expected events, so coverage is 100%
		Events sent: E1, E2
";

            result   = RemoveExcessiveEmptySpaceFromReport(result);
            expected = RemoveExcessiveEmptySpaceFromReport(expected);
            Assert.Equal(expected, result);
        }