public void UpdateImagesTestNullData()
        {
            var simSystem = new StubPLCSim()
            {
                ReadOutputImageInt32Int32ImageDataTypeConstantsObjectRef =
                    (int a, int b, ImageDataTypeConstants c, ref object pData) =>
                {
                    pData = null;
                }
            };
            var target = new SimulatedPLC(simSystem);

            simSystem.Connect();
            target.OutputImageOffestRequest(5);
            try
            {
                target.UpdateImages();
            }
            catch (Exception e)
            {
                Assert.Fail("Exception thrown by UpdateImages call\n" + e.ToString());
            }
            finally
            {
                simSystem.Disconnect();
            }


            //Assert.Fail("Exception not found");
        }
        public void OutputImageOffestRequestTest()
        {
            var target = new SimulatedPLC(); // TODO: Initialize to an appropriate value
            int offset = 50;                 // TODO: Initialize to an appropriate value

            target.OutputImageOffestRequest(offset);
            Assert.IsTrue(offset <= target.OutputImageBuffer.Capacity);
        }
        public void UpdateImagesTest()
        {
            var testData  = new Byte[] { 1, 2, 3, 4, 5 };
            var simSystem = new PLCSimConnector.Fakes.StubPLCSim()
            {
                ReadOutputImageInt32Int32ImageDataTypeConstantsObjectRef =
                    (int a, int b, ImageDataTypeConstants c, ref object pData) =>
                {
                    pData = testData;
                }
            };
            var target = new SimulatedPLC(simSystem);

            simSystem.Connect();
            target.OutputImageOffestRequest(5);
            target.UpdateImages();
            simSystem.Disconnect();

            Assert.IsTrue(target.OutputImageBuffer.GetBuffer().SequenceEqual(testData));
        }
        public void AddScaledDataPointTest()
        {
            using (ShimsContext.Create())
            {
                ShimPCS7Project.AllInstances.PCS7SymbolTableGet       = (proj) => new DotNetSiemensPLCToolBoxLibrary.DataTypes.Projectfolders.Step7V5.SymbolTable();
                ShimSymbolTable.AllInstances.GetEntryFromSymbolString = (table, s) => new SymbolTableEntry()
                {
                    Comment    = "Test Point",
                    DataType   = "Real",
                    Operand    = "EW 1001",
                    OperandIEC = "IW 1001",
                    Symbol     = s
                };

                var target = new SimulatedPLC {
                    Project = new PCS7Project()
                };

                string point  = "Test";
                float  engHi  = 100;
                float  engLow = 0;
                float  rawHi  = 4;
                float  rawLow = 20;
                var    actual = (PLCDataPoint)target.AddDataPoint(point);
                var    i      = actual.Offset;
                actual.DataPointScaling(engHi, engLow, rawHi, rawLow);
                var lactual = (PLCDataPoint)target.AddDataPoint("IB 456.1");
                lactual.DataPointScaling(engHi, engLow, rawHi, rawLow);
                i = lactual.Offset;
                Assert.IsNotNull(actual);
                Assert.AreEqual(point, actual.Symbol);

                /*Assert.AreEqual(engHi, actual.ScaleEngHigh);
                *  Assert.AreEqual(engLow, actual.ScaleEngLow);
                *  Assert.AreEqual(rawHi, actual.ScaleRawHigh);
                *  Assert.AreEqual(rawLow, actual.ScaleRawLow);*/
            }
        }
        public void AddScaledDataPointNullTest()
        {
            using (ShimsContext.Create())
            {
                var target = new SimulatedPLC {
                    Project = null
                };

                string point  = "Test";
                float  engHi  = 100;
                float  engLow = 0;
                float  rawHi  = 4;
                float  rawLow = 20;
                var    actual = (PLCDataPoint)target.AddDataPoint(point);
                actual.DataPointScaling(engHi, engLow, rawHi, rawLow);
                Assert.IsNotNull(actual);
                Assert.AreEqual(point, actual.Symbol);

                /*Assert.AreEqual(engHi, actual.ScaleEngHigh);
                *  Assert.AreEqual(engLow, actual.ScaleEngLow);
                *  Assert.AreEqual(rawHi, actual.ScaleRawHigh);
                *  Assert.AreEqual(rawLow, actual.ScaleRawLow);*/
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Sandbox app to test PLCSimConnector.dll");
            var c   = new PLCSim();
            var plc = new SimulatedPLC(c);
            //Console.WriteLine(c.GetState());
            var p = new PCS7Project("C:\\Program Files (x86)\\SIEMENS\\Step7\\S7Proj\\KING_M_1\\MID_CTRL\\MID_CTRL.s7p");

            Console.WriteLine("Press Any Key to Continue...");
            bool loop = true;

            while (loop)
            {
                ConsoleKeyInfo val = Console.ReadKey();
                switch (val.KeyChar)
                {
                case 'g':
                {
                    Console.WriteLine(c.GetState());
                    break;
                }

                case 'r':
                {
                    plc.UpdateImages();
                    object z = c.ReadOutputImage(10, 20);
                    break;
                }

                case 'w':
                {
                    c.Connect();
                    bool   b = true;
                    Object z = b;
                    c.WriteInputPoint(0, 0, ref z);
                    break;
                }

                case 'p':
                {
                    Console.WriteLine(p.Project.ProjectName);
                    Console.WriteLine(p.Project.ProjectDescription);
                    foreach (var te in p.PCS7SymbolTable.SymbolTableEntrys)
                    {
                        Console.WriteLine(te.Symbol + ": " + te.Operand + " " + te.DataType + " - " + te.OperandIEC);
                    }
                    break;
                }

                case 's':
                {
                    Console.WriteLine(p.Project.ProjectName);
                    Console.WriteLine(p.Project.ProjectDescription);
                    var nope = p.GetOutputImageSymbols();
                    foreach (var s in nope)
                    {
                        Console.WriteLine(s);
                    }
                    break;
                }

                case 'z':
                {
                    ValueType i;
                    float     f = 3;
                    i = f;
                    Console.WriteLine("the type of i is {0}", i.GetType());
                    break;
                }

                default:
                    loop = false;
                    break;
                }
            }
        }
        public void SimulatedPLCConstructorTest()
        {
            var target = new SimulatedPLC();

            target.Dispose();
        }