Exemplo n.º 1
0
        public void WriteOffsetTest(Type type, int numBytes, object variableValue, VADataTypes typeToGet)
        {
            const int    address   = 0x1234;
            const String sourceVar = "mySourceVar";

            var mockFsuipc        = new Mock <IFSUIPC>();
            var mockOffsetFactory = new Mock <IOffsetFactory>();
            var mockProxy         = new Mock <MyVAProxy>();

            var mockedOffset = new Mock <IOffset>();

            mockOffsetFactory.Setup(x => x.createOffset(It.IsAny <int>(),
                                                        It.Is <int>(i => i.Equals(numBytes)), true)).Returns(
                mockedOffset.Object);

            mockProxy.Setup(x => x.GetInt(It.IsAny <string>())).Returns(Convert.ToInt64(variableValue));
            mockProxy.Setup(x => x.GetBoolean(It.IsAny <string>())).Returns(Convert.ToBoolean(variableValue));
            mockProxy.Setup(x => x.GetDecimal(It.IsAny <string>())).Returns(Convert.ToDecimal(variableValue));

            FSUIPCInterface fsuipcInterface = new FSUIPCInterface(mockFsuipc.Object, mockOffsetFactory.Object);

            fsuipcInterface.initialise(mockProxy.Object);

            fsuipcInterface.writeOffset(address, type, sourceVar);

            mockFsuipc.Verify(x => x.Process(), Times.Exactly(1));
            mockOffsetFactory.Verify(x => x.createOffset(address, numBytes, true), Times.Exactly(1));

            if (typeToGet == VADataTypes.Int)
            {
                mockProxy.Verify(x => x.GetInt(sourceVar), Times.Once());
                mockedOffset.Verify(x => x.SetValue(Convert.ToInt64(variableValue)));
            }
            else if (typeToGet == VADataTypes.Decimal)
            {
                mockProxy.Verify(x => x.GetDecimal(sourceVar), Times.Once());
                mockedOffset.Verify(x => x.SetValue(Convert.ToDecimal(variableValue)));
            }
            else if (typeToGet == VADataTypes.Bool)
            {
                mockProxy.Verify(x => x.GetBoolean(sourceVar), Times.Once());
                mockedOffset.Verify(x => x.SetValue(Convert.ToBoolean(variableValue)));
            }
            else
            {
                throw new Exception("Invalid data type to test!");
            }
        }
Exemplo n.º 2
0
        public void ReadOffsetTest(Type type, int numBytes, object variableValue, VADataTypes typeToSet, Type typeToRead)
        {
            const int    address = 0x1234;
            const String destVar = "myVar";

            var mockFsuipc        = new Mock <IFSUIPC>();
            var mockOffsetFactory = new Mock <IOffsetFactory>();
            var mockProxy         = new Mock <MyVAProxy>();

            var mockedOffset = new Mock <IOffset>();

            mockedOffset.Setup(x => x.GetValue(It.Is <Type>(t => t.Equals(typeToRead)))).Returns(variableValue);

            mockOffsetFactory.Setup(x => x.createOffset(It.IsAny <int>(), It.IsAny <int>())).Returns(
                mockedOffset.Object);

            FSUIPCInterface fsuipcInterface = new FSUIPCInterface(mockFsuipc.Object, mockOffsetFactory.Object);

            fsuipcInterface.initialise(mockProxy.Object);

            fsuipcInterface.readOffset(address, type, destVar);

            mockProxy.Verify(x => x.WriteToLog(It.IsAny <string>(), It.Is <string>(s => s.Equals("red"))), Times.Never);
            mockFsuipc.Verify(x => x.Process(), Times.Exactly(1));
            mockOffsetFactory.Verify(x => x.createOffset(address, numBytes), Times.Exactly(1));
            mockedOffset.Verify(x => x.GetValue(It.Is <Type>(t => t.Equals(typeToRead))));
            if (typeToSet == VADataTypes.Int)
            {
                mockProxy.Verify(x => x.SetInt(destVar, Convert.ToInt64(variableValue)), Times.Once());
            }
            else if (typeToSet == VADataTypes.Decimal)
            {
                mockProxy.Verify(x => x.SetDecimal(destVar, Convert.ToDecimal(variableValue)), Times.Once());
            }
            else if (typeToSet == VADataTypes.Bool)
            {
                mockProxy.Verify(x => x.SetBoolean(destVar, Convert.ToBoolean(variableValue)), Times.Once());
            }
            else
            {
                throw new Exception("Invalid data type to test!");
            }
        }