Beispiel #1
0
        public void DoubleResourcePropertyTest()
        {
            EngineSettings.Current.ResourceManagerType = new LazyResourceManager();
            IInstrument instr1 = new SomeInstrument()
            {
                Name = "INSTR1"
            };
            IInstrument instr2 = new SomeInstrument()
            {
                Name = "INSTR2"
            };

            InstrumentSettings.Current.Add(instr1);
            InstrumentSettings.Current.Add(instr2);
            TestPlan  plan  = new TestPlan();
            ITestStep step1 = new DoubleInstrumentTestStep()
            {
                Instrument1 = instr1, Instrument2 = instr1
            };

            plan.Steps.Add(step1);
            ITestStep step2 = new DoubleInstrumentTestStep()
            {
                Instrument1 = instr2, Instrument2 = instr1
            };

            plan.Steps.Add(step2);
            UnitTestingLockManager.Enable();
            var run = plan.Execute();

            UnitTestingLockManager.Disable();

            Assert.IsFalse(run.FailedToStart, "Plan run failed.");
            Assert.AreEqual(2, UnitTestingLockManager.BeforeOpenArgs.Count(), "BeforeOpen hook called an unexpected number of times.");

            IEnumerable <IResourceReferences> arg1 = UnitTestingLockManager.BeforeOpenArgs.First();

            Assert.AreEqual(1, arg1.Count(), "Resources list contain an unexpected number of items.");
            Assert.AreEqual(instr1, arg1.First().Resource, "ResourceReference has unexpected Resource.");
            Assert.AreEqual(2, arg1.First().References.Count(), "ResourceReference has unexpected number of references.");
            Assert.AreEqual(step1, arg1.First().References.First().Instance, "ResourceReference references unexpected object.");
            Assert.AreEqual(step1, arg1.First().References.Last().Instance, "ResourceReference references unexpected object.");
            Assert.AreEqual(step1.GetType().GetProperty("Instrument1"), arg1.First().References.First().Property, "ResourceReference references unexpected property.");
            Assert.AreEqual(TypeData.GetTypeData(step1).GetMember("Instrument1"), arg1.First().References.First().Member, "ResourceReference references unexpected property.");
            Assert.AreEqual(TypeData.GetTypeData(step1).GetMember("Instrument2"), arg1.First().References.Last().Member, "ResourceReference references unexpected property.");

            IEnumerable <IResourceReferences> arg2 = UnitTestingLockManager.BeforeOpenArgs.Last();

            Assert.AreEqual(2, arg2.Count(), "Resources list contain an unexpected number of items.");
            Assert.IsTrue(arg2.Any(rr => rr.Resource == instr1), "ResourceReference has unexpected Resource.");
            Assert.IsTrue(arg2.Any(rr => rr.Resource == instr2), "ResourceReference has unexpected Resource.");
            Assert.AreEqual(1, arg2.First().References.Count(), "ResourceReference has unexpected number of references.");
            Assert.AreEqual(step2, arg2.First().References.First().Instance, "ResourceReference references unexpected object.");
            Assert.AreEqual(step2.GetType().GetProperty("Instrument1"), arg2.First().References.First().Property, "ResourceReference references unexpected property.");
        }
Beispiel #2
0
        public void BeforeOpenAfterCloseCallCountTest(Type managerType, int expectedCount)
        {
            EngineSettings.Current.ResourceManagerType = (IResourceManager)Activator.CreateInstance(managerType);
            IInstrument instr1 = new SomeInstrument()
            {
                Name = "INSTR1"
            };
            IInstrument instr2 = new SomeInstrument()
            {
                Name = "INSTR2"
            };

            InstrumentSettings.Current.Add(instr1);
            InstrumentSettings.Current.Add(instr2);
            Log.AddListener(new DiagnosticTraceListener());
            TestPlan  plan  = new TestPlan();
            ITestStep step1 = new DoubleInstrumentTestStep()
            {
                Instrument1 = instr1, Instrument2 = instr2
            };

            plan.Steps.Add(step1);
            ITestStep step2 = new InstrumentTestStep()
            {
                Instrument = instr1
            };

            plan.Steps.Add(step2);
            ITestStep step4 = new InstrumentTestStep()
            {
                Instrument = instr1
            };                                                                  // a step uses the same instrument as another step to test that this

            plan.Steps.Add(step4);
            ITestStep step3 = new DelayStep()
            {
                DelaySecs = 0
            };                                                   // a step without any Resource properties. To check that this does not create a call to BeforeOpen

            plan.Steps.Add(step3);
            UnitTestingLockManager.Enable();
            UnitTestingLockManager.BeforeOpenEffect = SetNullResources;
            var run = plan.Execute();

            UnitTestingLockManager.Disable();

            Assert.IsFalse(run.FailedToStart, "Plan run failed.");
            Assert.AreEqual(Verdict.NotSet, run.Verdict);
            Assert.AreEqual(expectedCount, UnitTestingLockManager.BeforeOpenArgs.Count(), "BeforeOpen hook called an unexpected number of times.");
            Assert.AreEqual(expectedCount, UnitTestingLockManager.AfterCloseArgs.Count(), "AfterClose hook called an unexpected number of times.");
        }
Beispiel #3
0
        public void DoubleResourceNullPropertyTest()
        {
            // Tests the special case where two properties use null resources (= placeholders) on the same step.
            // Normally only one IResourceReferences item is given to ILockManager.BeforeOpen() for each Resource used.
            // But for null Resources, we want one IResourceReferences item per property, so BeforeOpen can set each prop
            // to different Resource instances when replacing the null values.
            EngineSettings.Current.ResourceManagerType = new LazyResourceManager();
            IInstrument instr1 = new SomeInstrument()
            {
                Name = "INSTR1"
            };
            IInstrument instr2 = new SomeInstrument()
            {
                Name = "INSTR2"
            };

            InstrumentSettings.Current.Add(instr1);
            InstrumentSettings.Current.Add(instr2);
            TestPlan  plan  = new TestPlan();
            ITestStep step1 = new DoubleInstrumentTestStep()
            {
                Instrument1 = null, Instrument2 = null
            };

            plan.Steps.Add(step1);
            UnitTestingLockManager.Enable();
            UnitTestingLockManager.BeforeOpenEffect = SetNullResources;
            var run = plan.Execute();

            UnitTestingLockManager.Disable();

            Assert.IsFalse(run.FailedToStart, "Plan run failed.");
            Assert.AreEqual(Verdict.NotSet, run.Verdict);
            Assert.AreEqual(1, UnitTestingLockManager.BeforeOpenArgs.Count(), "BeforeOpen hook called an unexpected number of times.");

            IEnumerable <IResourceReferences> arg1 = UnitTestingLockManager.BeforeOpenArgs.First();

            Assert.AreEqual(2, arg1.Count(), "Resources list contain an unexpected number of items.");
            Assert.AreEqual(1, arg1.First().References.Count(), "ResourceReference has unexpected number of references.");
            Assert.AreEqual(1, arg1.Last().References.Count(), "ResourceReference has unexpected number of references.");
            Assert.AreEqual(step1, arg1.First().References.First().Instance, "ResourceReference references unexpected object.");
            Assert.AreEqual(step1, arg1.Last().References.First().Instance, "ResourceReference references unexpected object.");
            Assert.AreEqual(step1.GetType().GetProperty("Instrument1"), arg1.First().References.First().Property, "ResourceReference references unexpected property.");
            Assert.AreEqual(step1.GetType().GetProperty("Instrument2"), arg1.Last().References.First().Property, "ResourceReference references unexpected property.");
        }