Beispiel #1
0
        public void StartBackgroundProcessingTest()
        {
            var container = GenerateContainer();
            var agent     = new SampleIOAgent(container);

            agent.Initialize();
            IConfigDll config  = container.Resolve <IConfigDll>("IoAgentSample");
            var        watcher = container.Resolve <SampleDiscoveryWatcher>();
            var        discoveredInterfaceList = new List <string>();

            watcher.WaitingInterval        = 1;
            watcher.RequestDiscoveryAction = i =>
            {
                discoveredInterfaceList.Add(i.VisaInterfaceId);
            };
            var hwconfig = config as HwConfigSample;

            hwconfig.SampleFileName = "sample4.xml";
            agent.BackgroundWaiting = 1;

            var cts = new CancellationTokenSource();

            agent.StartBackgroundProcessing(cts.Token);
            for (int i = 0; i < 2; i++)
            {
                Thread.Sleep(1100);
            }
            cts.Cancel();

            Assert.IsTrue(discoveredInterfaceList.Contains("SAMP0"));
            Assert.IsTrue(discoveredInterfaceList.Count >= 2);
        }
Beispiel #2
0
        public void DoDiscoveryTest_StaticDefined()
        {
            var container1       = GenerateContainer();
            var agent1           = new SampleIOAgent(container1);
            var sampleInterface1 = GenerateSampleInterface("SAMP1", "samp1", "101");
            var model1           = container1.Resolve <AceModelRestricted>();
            var elementList1     = agent1.DoDiscovery(sampleInterface1, model1);

            Assert.IsTrue(elementList1.Where(e =>
            {
                var intfc = e as ModelInterfaceSample;
                return(intfc != null &&
                       intfc.VisaInterfaceId == "SAMP1" &&
                       intfc.SiclInterfaceId == "samp1" &&
                       intfc.LogicalUnit == "101");
            }).FirstOrDefault() == null);

            var container2       = GenerateContainer();
            var agent2           = new SampleIOAgent(container2);
            var sampleInterface2 = GenerateSampleInterface("SAMP1", "samp1", "101", true);
            var model2           = container1.Resolve <AceModelRestricted>();
            var elementList2     = agent2.DoDiscovery(sampleInterface2, model2);

            Assert.IsTrue(elementList2.Where(e =>
            {
                var intfc = e as ModelInterfaceSample;
                return(intfc != null &&
                       intfc.VisaInterfaceId == "SAMP1" &&
                       intfc.SiclInterfaceId == "samp1" &&
                       intfc.LogicalUnit == "101");
            }).FirstOrDefault() != null);
        }
Beispiel #3
0
        public void AutoConfigTest()
        {
            var container = GenerateContainer();
            var agent     = new SampleIOAgent(container);
            var model     = container.Resolve <AceModelRestricted>();
            var intfcs    = agent.AutoConfig(model);

            Assert.IsTrue(intfcs.Count() >= 1);
        }
Beispiel #4
0
        private static ModelInterfaceSample GenerateNewSampleInterface(AceModel model)
        {
            var container               = new UnityContainer();
            var sampleAgent             = new SampleIOAgent(container);
            var getAddingElementsMethod = new PrivateObject(sampleAgent);
            var result = getAddingElementsMethod.Invoke("GetAddingElement", BindingFlags.NonPublic | BindingFlags.Instance, "Sample Interface", model);
            var intfc  = result as ModelInterfaceSample;

            return(intfc);
        }
Beispiel #5
0
        public void DoDiscoveryTest()
        {
            var container       = GenerateContainer();
            var agent           = new SampleIOAgent(container);
            var sampleInterface = GenerateSampleInterface("SAMP0", "samp", "100");
            var model           = container.Resolve <AceModelRestricted>();
            var elementList     = agent.DoDiscovery(sampleInterface, model);
            var intfc           = elementList.Where(e => e is ModelInterfaceSample).Select(i => i as ModelInterfaceSample).FirstOrDefault();
            var device          = elementList.Where(e => e is ModelDeviceSample).Select(d => d as ModelDeviceSample).FirstOrDefault();

            Assert.IsTrue(elementList.Count == 2);
            Assert.IsTrue(intfc != null);
            Assert.IsTrue(device != null);
            Assert.IsTrue(intfc.VisaInterfaceId == "SAMP0");
            Assert.IsTrue(intfc.SiclInterfaceId == "samp");
            Assert.IsTrue(intfc.LogicalUnit == "100");
            Assert.IsTrue(device.Manufacturer == "KT");
            Assert.IsTrue(device.ModelNumber == "DEV001");
            Assert.IsTrue(device.SerialNumber == "X01234");
            Assert.IsTrue(device.FirmwareRevision == "1.0.0.1");
            Assert.IsTrue(device.IPAddress == "192.168.56.128");
            Assert.IsTrue(device.DeviceName == "inst0");
        }
Beispiel #6
0
        public void DoVerifyTest()
        {
            var container        = GenerateContainer();
            var agent            = new SampleIOAgent(container);
            var sampleInterface1 = GenerateSampleInterface("SAMP0", "samp", "100");
            var sampleDevice1    = GenerateSampleDeice("KT", "DEV001", "X01234", "1.0.0.1", "192.168.56.128", "inst0");

            sampleDevice1.ParentId = sampleInterface1.PersistentId;
            sampleDevice1.Parent   = sampleInterface1;
            var model1             = container.Resolve <AceModelRestricted>();
            var verifiedInterface1 = agent.DoVerify(sampleInterface1, model1);
            var verifiedDevice1    = agent.DoVerify(sampleDevice1, model1);

            var sampleInterface2 = GenerateSampleInterface("SAMP0", "samp", "100");
            var sampleDevice2    = GenerateSampleDeice("KT", "DEV002", "X012356", "1.0.0.1", "192.168.56.45", "inst0");

            sampleDevice2.ParentId = sampleInterface2.PersistentId;
            sampleDevice2.Parent   = sampleInterface2;
            var model2             = container.Resolve <AceModelRestricted>();
            var verifiedInterface2 = agent.DoVerify(sampleInterface2, model2);
            var verifiedDevice2    = agent.DoVerify(sampleDevice2, model2);

            var sampleInterface3 = GenerateSampleInterface("SAMP1", "samp1", "101");
            var sampleDevice3    = GenerateSampleDeice("KT", "DEV001", "X01234", "1.0.0.1", "192.168.56.128", "inst0");

            sampleDevice3.ParentId = sampleInterface3.PersistentId;
            sampleDevice3.Parent   = sampleInterface3;
            var model3             = container.Resolve <AceModelRestricted>();
            var verifiedInterface3 = agent.DoVerify(sampleInterface3, model3);
            var verifiedDevice3    = agent.DoVerify(sampleDevice3, model3);

            var sampleInterface4 = GenerateSampleInterface("SAMP1", "samp1", "101");
            var sampleDevice4    = GenerateSampleDeice("KT", "DEV002", "X012356", "1.0.0.1", "192.168.56.45", "inst0");

            sampleDevice4.ParentId = sampleInterface4.PersistentId;
            sampleDevice4.Parent   = sampleInterface4;
            var model4             = container.Resolve <AceModelRestricted>();
            var verifiedInterface4 = agent.DoVerify(sampleInterface4, model4);
            var verifiedDevice4    = agent.DoVerify(sampleDevice4, model4);

            Assert.IsTrue(verifiedInterface1.Verified);
            Assert.IsTrue(!verifiedInterface1.Failed);

            Assert.IsTrue(verifiedInterface2.Verified);
            Assert.IsTrue(!verifiedInterface2.Failed);

            Assert.IsTrue(!verifiedInterface3.Verified);
            Assert.IsTrue(verifiedInterface3.Failed);

            Assert.IsTrue(!verifiedInterface4.Verified);
            Assert.IsTrue(verifiedInterface4.Failed);

            Assert.IsTrue(verifiedDevice1.Verified);
            Assert.IsTrue(!verifiedDevice1.Failed);
            Assert.IsTrue(verifiedDevice1.Parent != null);
            Assert.IsTrue(!string.IsNullOrEmpty(verifiedDevice1.ParentId));

            Assert.IsTrue(!verifiedDevice2.Verified);
            Assert.IsTrue(verifiedDevice2.Failed);
            Assert.IsTrue(verifiedDevice2.Parent != null);
            Assert.IsTrue(!string.IsNullOrEmpty(verifiedDevice2.ParentId));

            Assert.IsTrue(!verifiedDevice3.Verified);
            Assert.IsTrue(verifiedDevice3.Failed);
            Assert.IsTrue(verifiedDevice3.Parent != null);
            Assert.IsTrue(!string.IsNullOrEmpty(verifiedDevice3.ParentId));

            Assert.IsTrue(!verifiedDevice4.Verified);
            Assert.IsTrue(verifiedDevice4.Failed);
            Assert.IsTrue(verifiedDevice4.Parent != null);
            Assert.IsTrue(!string.IsNullOrEmpty(verifiedDevice4.ParentId));
        }