Exemplo n.º 1
0
        public void TestNameFormat2()
        {
            var plan   = new TestPlan();
            var repeat = new RepeatStep {
                Count = 10, Action = RepeatStep.RepeatStepAction.Fixed_Count
            };

            repeat.Name = "Repeat : {Iteration}";
            plan.ChildTestSteps.Add(repeat);
            var logStep = new LogStep();

            repeat.ChildTestSteps.Add(logStep);
            var log = new TestTraceListener();

            Log.AddListener(log);
            var run = plan.Execute();

            Assert.AreEqual(Verdict.NotSet, run.Verdict);
            Log.RemoveListener(log);
            var thelog = log.GetLog();

            for (int i = 0; i < repeat.Count; i++)
            {
                var str = string.Format("Repeat : {0} of {1}", i, repeat.Count);
                Assert.IsTrue(thelog.Contains(str));
            }
        }
Exemplo n.º 2
0
        public void BeforeOpenExceptionTest(Type managerType, Type exceptionType, Verdict expectedVerdict, bool withParallel)
        {
            EngineSettings.Current.ResourceManagerType = (IResourceManager)Activator.CreateInstance(managerType);
            IInstrument instr1 = new SomeInstrument()
            {
                Name = "INSTR1"
            };

            InstrumentSettings.Current.Add(instr1);
            try
            {
                TestPlan  plan  = new TestPlan();
                ITestStep step1 = new InstrumentTestStep()
                {
                    Instrument = instr1
                };
                if (withParallel)
                {
                    var par = new ParallelStep();
                    par.ChildTestSteps.Add(step1);
                    step1 = par;
                }
                plan.Steps.Add(step1);
                ITestStep lastStep = new LogStep()
                {
                    Name = "Last Step", LogMessage = "Last Step Ran"
                };
                plan.Steps.Add(lastStep);
                UnitTestingLockManager.Enable();
                UnitTestingLockManager.BeforeOpenEffect = r => throw (Exception)Activator.CreateInstance(exceptionType, new string[] { "Custom exception message" });
                var logListener = new TestTraceListener();
                Log.AddListener(logListener);
                //string logFileName = Path.Combine(Path.GetDirectoryName(PluginManager.GetOpenTapAssembly().Location), $"BeforeOpenExceptionTest({managerType},{exceptionType},{withParallel}).txt");
                //if (File.Exists(logFileName)) File.Delete(logFileName);
                //var fileListener = new FileTraceListener(logFileName);
                //Log.AddListener(fileListener);
                try
                {
                    var run = plan.Execute();
                    Assert.AreEqual(expectedVerdict, run.Verdict);
                }
                finally
                {
                    Log.RemoveListener(logListener);
                    //Log.RemoveListener(fileListener);
                    UnitTestingLockManager.Disable();
                }

                // We should have the custom exception message in the log
                StringAssert.Contains("Custom exception message", logListener.GetLog());

                if (expectedVerdict == Verdict.Error)
                {
                    StringAssert.IsMatch(": Error .+Custom exception message", logListener.GetLog());
                }
                else
                {
                    StringAssert.IsMatch(": Warning .+Custom exception message", logListener.GetLog());
                }

                // The last step should not have run:
                if (exceptionType == typeof(OperationCanceledException))
                {
                    StringAssert.DoesNotContain("Last Step Ran", logListener.GetLog());
                }
            }
            finally
            {
                InstrumentSettings.Current.Remove(instr1);
            }
        }