Exemple #1
0
        public void Test_Update_Json()
        {
            var store = DatabaseHelper.Default.GetStore();

            store.Use(new JsonBindingContractResolver(new JsonSerializerOptions()));

            var json    = "{ \"Id\": 12, \"Title\": \"Hello World!\" }";
            var data1   = new BlogJsonView();
            var data2   = new BlogJsonView();
            var target1 = store.From(data1).Lookup("Blog");
            var target2 = store.From(data2).Lookup("Blog");
            var buffer  = new CommandBuffer(store);

            buffer.Add(new ColumnBinding(target1, "B0"));
            buffer.Add(new ParameterBinding(target2, "P0"));

            var parameters = buffer.Prepare(() => new MockParameter());

            parameters[0].Value = json;

            buffer.Update(json, ("", "B0"));

            data1.Blog.ShouldBeNull();
            data2.Blog.ShouldBeNull();

            buffer.Commit();

            data1.Blog.ShouldNotBeNull();
            data1.Blog.Id.ShouldBe(12);
            data1.Blog.Title.ShouldBe("Hello World!");

            data2.Blog.ShouldNotBeNull();
            data2.Blog.Id.ShouldBe(12);
            data2.Blog.Title.ShouldBe("Hello World!");
        }
Exemple #2
0
        public void CommandBufferAddMultiLine()
        {
            BaseMock      mockEngine = CreateDefaultEngine();
            CommandBuffer buffer     = new CommandBuffer(mockEngine as IEngine);

            mockEngine.AddMethodReturnValues(parseFunctionName, new object[] { false });
            string[] lines = new string[] {
                "Line 1",
                "Line 2",
                "Line 3"
            };
            const string lastLine = "Last Line";

            mockEngine.ResetFunctionCalls(string.Format("{0}.{1}", typeof(IEngine).FullName, "ExecuteToConsole"));
            string expected = string.Empty;

            foreach (string line in lines)
            {
                expected += line;
                buffer.Add(line);
                Assert.AreEqual <string>(expected, buffer.Text);
                Assert.AreEqual <int>(0, mockEngine.FunctionCalls(string.Format("{0}.{1}", typeof(IEngine).FullName, "ExecuteToConsole")));
                expected += System.Environment.NewLine;
            }

            // Now change the return value for ParseInteractiveInput so that the execute
            // function of the engine is called.
            mockEngine.AddMethodReturnValues(parseFunctionName, new object[] { true });
            expected += lastLine;
            buffer.Add(lastLine);
            // Now the buffer should be cleared and the text should be passed to the engine.
            Assert.IsTrue(string.IsNullOrEmpty(buffer.Text));
            Assert.AreEqual <int>(1, mockEngine.FunctionCalls(string.Format("{0}.{1}", typeof(IEngine).FullName, "ExecuteToConsole")));
            Assert.AreEqual <string>(expected, (string)mockEngine["ExecutedCommand"]);
        }
Exemple #3
0
        public void Test_Update_Parameter_Propagation()
        {
            var store   = DatabaseHelper.Default.Store;
            var data1   = new Blog();
            var data2   = new Blog();
            var target1 = store.From(data1).Lookup("Id");
            var target2 = store.From(data2).Lookup("Id");
            var buffer  = new CommandBuffer(store);

            buffer.Add(new ColumnBinding(target1, "C1"));
            buffer.Add(new Parameter("P2", target2), target2);
            buffer.Update(10, ("", "C1"));

            var parameters1 = buffer.Prepare(() => new MockParameter());

            parameters1[0].Value = 20;

            buffer.Add(new Parameter("P1", target1));
            buffer.Add(new Parameter("P2", target2));

            var parameters2 = buffer.Prepare(() => new MockParameter());

            parameters2.Count.ShouldBe(2);
            parameters2[0].Value.ShouldBe(10);
            parameters2[1].Value.ShouldBe(20);
        }
        public static void SendActiveEndpointRequest(ushort address, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZdoConstants.ZdoProfileId, ZdoClusterIds.ActiveEndpointRequest, 0, 0, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add((byte)0x00); // Sequence
            buffer.Add(address);

            ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, 0, buffer.ToArray());
        }
        public static void SendOnOffBroadcast(byte command, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZclConstants.HomeAutomationProfileId, ClusterIds.OnOffCluster, 1, 1, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add(ZclConstants.ZclFrameControlClusterSpecificBit);
            buffer.Add((byte)0x00);
            buffer.Add(command);

            ezspService.SendBroadcast(ZclConstants.BroadcastRoutersAndCoordinators, frame, 10, 0, buffer.ToArray());
        }
        public static void SendFirmwareVersionRequest(ushort address, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZclConstants.HomeAutomationProfileId, ClusterIds.OtaUpgradeCluster, 1, 1, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);
            var b     = new CommandBuffer();

            b.Add(ZclConstants.ZclFrameControlClusterServerToClientBit);
            b.Add((byte)0x00); // Sequence Number
            b.Add(CommandIds.Global.ReadAttributes);
            b.Add(AttributeIds.OtaServer.CurrentFileVersion);

            ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, 0, b.ToArray());
        }
        public static void SendModelStringRequest(ushort address, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZclConstants.HomeAutomationProfileId, ClusterIds.BasicCluster, 1, 1, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);
            var b     = new CommandBuffer();

            b.Add((byte)0x00); // Frame Control
            b.Add((byte)0x00); // Sequence Number
            b.Add(CommandIds.Global.ReadAttributes);
            b.Add(AttributeIds.BasicServer.ModelIdentifier);

            ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, 0, b.ToArray());
        }
        public static void SendDefaultCommand(ushort address, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZclConstants.HomeAutomationProfileId, ClusterIds.BasicCluster, 1, 1, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add(ZclConstants.ZclFrameControlClusterSpecificBit);
            buffer.Add((byte)0x00); // Sequence
            buffer.Add(CommandIds.Global.ReadAttributes);

            ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, 0, buffer.ToArray());
        }
        public static void SendPermitJoiningBroadcast(byte duration, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZdoConstants.ZdoProfileId, ZdoClusterIds.PermitJoiningRequest, 0, 0, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add((byte)0x00); // Sequence
            buffer.Add(duration);
            buffer.Add((byte)0x00); // Trust Center Significance

            ezspService.SendBroadcast(ZclConstants.BroadcastRoutersAndCoordinators, frame, 10, 0, buffer.ToArray());
        }
        public static void SendReadOccupancyStatus(ushort address, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZclConstants.HomeAutomationProfileId, ClusterIds.OccupancySensing, 1, 1, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add((byte)0x00);
            buffer.Add((byte)0x00);
            buffer.Add(CommandIds.Global.ReadAttributes);
            buffer.Add(AttributeIds.OccupancySensingServer.MotionStatus);

            ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, 0, buffer.ToArray());
        }
        public static void SendPowerMeasurementRequest(ushort address, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZclConstants.HomeAutomationProfileId, ClusterIds.ElectricalMeasurement, 1, 1, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add((byte)0x00);
            buffer.Add((byte)0x00);
            buffer.Add(CommandIds.Global.ReadAttributes);
            buffer.Add(AttributeIds.ElectricalMeasurement.ActivePower);

            ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, 0, buffer.ToArray());
        }
        public static void SendProximityCalibrateRequest(ushort address, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZclConstants.HomeAutomationProfileId, ClusterIds.BasicCluster, 1, 1, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add((byte)(ZclConstants.ZclFrameControlClusterSpecificBit | ZclConstants.ZclFrameControlManufacturerSpecificBit));
            buffer.Add(ZclConstants.CentraliteManufacturerId);
            buffer.Add((byte)0x00);
            buffer.Add(CommandIds.Keypad.CheckCalibration);

            ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, 0, buffer.ToArray());
        }
        public static void SendSelfTestCommand(ushort address, ushort cluster, ushort manufacturingCode, byte selfTestCommand, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZclConstants.HomeAutomationProfileId, cluster, 1, 1, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add((byte)(ZclConstants.ZclFrameControlClusterSpecificBit | ZclConstants.ZclFrameControlManufacturerSpecificBit | ZclConstants.ZclFrameControlDisableDefaultResponseBit));
            buffer.Add(manufacturingCode);
            buffer.Add((byte)0x00); // Sequence
            buffer.Add(selfTestCommand);

            ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, 0, buffer.ToArray());
        }
        public static void SendTemperatureRequest(ushort address, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZclConstants.HomeAutomationProfileId, ClusterIds.TemperatureMeasurement, 1, 1, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add((byte)0x00); // Frame Control
            buffer.Add((byte)0x00); // Sequence
            buffer.Add(CommandIds.Global.ReadAttributes);
            buffer.Add(AttributeIds.TemperatureMeasurementServer.MeasuredValue);

            ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, 0, buffer.ToArray());
        }
        public static void SendOnOffCommand(ushort address, byte command, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZclConstants.HomeAutomationProfileId, ClusterIds.OnOffCluster, 1, 1, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add(ZclConstants.ZclFrameControlClusterSpecificBit);
            buffer.Add((byte)0xb0);
            buffer.Add(command);
            buffer.AddArray(new byte[] { });

            ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, 0, buffer.ToArray());
        }
        public static void SendIEEEAddressRequest(ushort address, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZdoConstants.ZdoProfileId, ZdoClusterIds.IEEEAddressRequest, 0, 0, EmberApsOption.EMBER_APS_OPTION_NONE, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add((byte)0x00); // Sequence
            buffer.Add(address);    // Network Address
            buffer.Add((byte)0x00); // Request Type 0x00 = Single Device Response 0x01 = Extended Response
            buffer.Add((byte)0x00); // Start Index (Used if Extended Response)

            ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, 0, buffer.ToArray());
        }
        public static void SetLongPollRate(ushort address, uint quarterSeconds, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZclConstants.HomeAutomationProfileId, ClusterIds.PollControl, 1, 1, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add(ZclConstants.ZclFrameControlClusterSpecificBit); // Frame Control
            buffer.Add((byte)0x00);                                     // Sequence
            buffer.Add(CommandIds.PollControl.SetLongPollIntervalRate); // Command
            buffer.Add(quarterSeconds);                                 // Attribute Identifier

            ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, 0, buffer.ToArray());
        }
        public static void RequestLongPollInvtervalMin(ushort address, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZclConstants.HomeAutomationProfileId, ClusterIds.PollControl, 1, 1, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add((byte)0x00); // Control
            buffer.Add((byte)0x00); // Sequence
            buffer.Add(CommandIds.Global.ReadAttributes);
            buffer.Add(AttributeIds.PollControl.LongPollIntervalMin);

            ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, 0, buffer.ToArray());
        }
        public static void SendImageNotifyBroadcast(IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZclConstants.HomeAutomationProfileId, ClusterIds.OtaUpgradeCluster, 1, 1, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add((byte)(ZclConstants.ZclFrameControlClusterServerToClientBit | ZclConstants.ZclFrameControlDisableDefaultResponseBit | ZclConstants.ZclFrameControlClusterSpecificBit));
            buffer.Add((byte)0x00); // Sequence
            buffer.Add(CommandIds.OtaUpgrade.ImageNotify);
            buffer.Add(ImageNotifyPayloadType.QueryJitter);
            buffer.Add((byte)100); // Query Jitter (0 - 100) Max Value should insure device responds

            ezspService.SendBroadcast(ZclConstants.BroadcastAllDevices, frame, 10, 0, buffer.ToArray());
        }
        public static void SendIasEnrollResponse(ushort address, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZclConstants.HomeAutomationProfileId, ClusterIds.IasZone, 1, 1, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add(ZclConstants.ZclFrameControlClusterSpecificBit);
            buffer.Add((byte)0x00); // Sequence
            buffer.Add(CommandIds.IasZoneClient.ZoneEnrollResponse);
            buffer.Add(ZCLStatus.ZclStatusSuccess);
            buffer.Add((byte)0x01); // Zone ID

            ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, 0, buffer.ToArray());
        }
        public static void SendHumidityRequest(ushort address, uint manufacturingCode, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZclConstants.HomeAutomationProfileId, ClusterIds.CentraliteHumidity, 1, 1, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add(ZclConstants.ZclFrameControlManufacturerSpecificBit); // Header
            buffer.Add(manufacturingCode);                                   // MFG Code
            buffer.Add((byte)0x00);                                          // Sequence
            buffer.Add(CommandIds.Global.ReadAttributes);                    // Command
            buffer.Add(AttributeIds.RelativeHumidityServer.MeasuredValue);   // Attribute ID

            ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, 0, buffer.ToArray());
        }
        public static void SendImageNotify(ushort address, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZclConstants.HomeAutomationProfileId, ClusterIds.OtaUpgradeCluster, 1, 1, EmberApsOption.EMBER_APS_OPTION_STANDARD, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add((byte)(ZclConstants.ZclFrameControlClusterServerToClientBit | ZclConstants.ZclFrameControlClusterSpecificBit));
            buffer.Add((byte)0x00); // Sequence
            buffer.Add(CommandIds.OtaUpgrade.ImageNotify);
            buffer.Add(ImageNotifyPayloadType.QueryJitter);
            buffer.Add((byte)100); // Query Jitter (0 - 100) Max Value should insure device responds

            ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, 0, buffer.ToArray());
        }
Exemple #23
0
        public void CommandBufferAddWithThrowingExecute()
        {
            // Create the mock engine.
            BaseMock mockEngine = MockFactories.EngineFactory.GetInstance();

            // Set the callback function for the ExecuteToConsole method of the engine to the throwing one.
            mockEngine.AddMethodCallback(
                string.Format("{0}.{1}", typeof(IEngine).FullName, "ExecuteToConsole"),
                new EventHandler <CallbackArgs>(ThrowingExecuteCallback));
            // Make sure that the execute is called.
            mockEngine.AddMethodReturnValues(parseFunctionName, new object[] { true });
            CommandBuffer buffer          = new CommandBuffer(mockEngine as IEngine);
            bool          exceptionThrown = false;

            try
            {
                buffer.Add("Test Line");
            }
            catch (ExecuteException)
            {
                exceptionThrown = true;
            }
            Assert.IsTrue(exceptionThrown);
            Assert.IsTrue(string.IsNullOrEmpty(buffer.Text));
        }
Exemple #24
0
        public void Test_Update_Priority()
        {
            var store  = DatabaseHelper.Default.Store;
            var data   = new Blog();
            var target = store.From(data).Lookup("Id");

            var buffer = new CommandBuffer(store);

            buffer.Add(new Parameter("P0", target), target);
            buffer.Add(new ColumnBinding(target, "C0"));

            var parameters = buffer.Prepare(() => new MockParameter());

            parameters.Count.ShouldBe(1);
            parameters[0].Direction.ShouldBe(ParameterDirection.Input);
        }
Exemple #25
0
        public void CommandBufferAddNullLine()
        {
            BaseMock      mockEngine = CreateDefaultEngine();
            CommandBuffer buffer     = new CommandBuffer(mockEngine as IEngine);

            mockEngine.AddMethodReturnValues(parseFunctionName, new object[] { true });
            mockEngine.ResetFunctionCalls(string.Format("{0}.{1}", typeof(IEngine).FullName, "ExecuteToConsole"));
            buffer.Add(null);
            Assert.AreEqual <int>(1, mockEngine.FunctionCalls(string.Format("{0}.{1}", typeof(IEngine).FullName, "ExecuteToConsole")));
            Assert.IsTrue(string.IsNullOrEmpty((string)mockEngine["ExecutedCommand"]));
        }
        public static void SendLeaveRequest(ushort address, bool sleepy, byte tag, IEzspService ezspService)
        {
            var frame = new EmberApsFrame(ZdoConstants.ZdoProfileId, ZdoClusterIds.ManagementLeaveRequest, 0, 0, EmberApsOption.EMBER_APS_OPTION_NONE, 0, 0);

            var buffer = new CommandBuffer();

            buffer.Add((byte)0x00);
            buffer.Add(0);
            buffer.Add(0);
            buffer.Add((byte)0x00);

            var emptySourceRoute = new ushort[0];

            if (!sleepy)
            {
                ezspService.SetSourceRoute(address, emptySourceRoute);
            }

            ezspService.SendUnicast(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, address, frame, tag, buffer.ToArray());
        }
Exemple #27
0
        public void Test_Update_Missing()
        {
            var store  = DatabaseHelper.Default.Store;
            var target = store.From <Blog>(null).Lookup("Id");
            var buffer = new CommandBuffer(store);

            buffer.Add(new ColumnBinding(target, "C0"));
            buffer.Update(10, ("", "c0"));

            Should.Throw <BindingException>(() => buffer.Commit());
        }
Exemple #28
0
        public void Test_Update_FromParameter()
        {
            var store   = DatabaseHelper.Default.Store;
            var data    = new Blog();
            var targets = store.From(data).Lookup("Id", "Title");

            var buffer = new CommandBuffer(store);

            buffer.Add(new Parameter("P0", targets[0]), targets[0]);
            buffer.Add(new ParameterBinding(targets[1], "P1"));

            var parameters = buffer.Prepare(() => new MockParameter());

            parameters[0].Value = 12;
            parameters[1].Value = "Blog!";

            buffer.Commit();

            data.Id.ShouldBe(12);
            data.Title.ShouldBe("Blog!");
        }
Exemple #29
0
        public void Test_Update_Indexer()
        {
            var store = DatabaseHelper.Default.Store;
            var data1 = new List <int>()
            {
                1, 2, 3
            };
            var data2   = new[] { 4, 5, 6 };
            var target1 = store.From(data1).Select("Item").Body.Skip(1).First()[0];
            var target2 = store.From(data2).Select("Item").Body.Skip(1).First()[0];
            var buffer  = new CommandBuffer(store);

            buffer.Add(new ColumnBinding(target1, "C1"));
            buffer.Add(new ColumnBinding(target2, "C2"));
            buffer.Update(50, ("", "C1"));
            buffer.Update(100, ("", "C2"));
            buffer.Commit();

            data1.ShouldBe(new[] { 1, 50, 3 });
            data2.ShouldBe(new[] { 4, 100, 6 });
        }
Exemple #30
0
        public void Test_Update_InvalidDataType()
        {
            var store  = DatabaseHelper.Default.Store;
            var data   = new Blog();
            var target = store.From(data).Lookup("Id");
            var buffer = new CommandBuffer(store);

            buffer.Add(new ColumnBinding(target, "C0"));

            buffer.Update("Text", ("", "C0"));
            buffer.Update((object)"Text", ("", "C0"));
        }