コード例 #1
0
ファイル: FundamentTest.cs プロジェクト: hnjm/mathnet-yttrium
        public void PropertyTriggerTest()
        {
            MathIdentifier propertyId = new MathIdentifier("T2_PT", "FundamentTest");

            NodeEvent clearEvent      = NodeEvent.Register(propertyId.DerivePostfix("ClearTrigger"), typeof(EventHandler), typeof(FundamentTest));
            NodeEvent clear2Event     = NodeEvent.Register(propertyId.DerivePostfix("Clear2Trigger"), typeof(EventHandler), typeof(FundamentTest));
            NodeEvent clear3Event     = NodeEvent.Register(propertyId.DerivePostfix("Clear3Trigger"), typeof(EventHandler), typeof(FundamentTest));
            NodeEvent reevaluateEvent = NodeEvent.Register(propertyId.DerivePostfix("ReevaluateTrigger"), typeof(EventHandler), typeof(FundamentTest));

            NodeProperty property = NodeProperty.Register(propertyId, typeof(string), typeof(FundamentTest),
                                                          new NodeEventTrigger(EventTriggerAction.Clear, clearEvent, clear2Event),
                                                          new NodeEventTrigger(EventTriggerAction.Clear, clear3Event),
                                                          new NodeEventTrigger(EventTriggerAction.Reevaluate, reevaluateEvent));

            NodeObject n = new NodeObject();

            Assert.IsFalse(n.IsPropertySet(property), "A01");

            n.SetProperty(property, "test");
            Assert.IsTrue(n.IsPropertySet(property), "B01");

            n.RaiseEvent(clearEvent, EventArgs.Empty);
            Assert.IsFalse(n.IsPropertySet(property), "C01");

            n.SetProperty(property, "test2");
            Assert.IsTrue(n.IsPropertySet(property), "D01");
            Assert.AreEqual("test2", n.GetProperty(property), "D02");

            n.RaiseEvent(reevaluateEvent, EventArgs.Empty);
            Assert.IsTrue(n.IsPropertySet(property), "E01");
            Assert.AreEqual("test2", n.GetProperty(property), "E02");

            n.RaiseEvent(clear2Event, EventArgs.Empty);
            Assert.IsFalse(n.IsPropertySet(property), "F01");

            n.SetProperty(property, "test3");
            Assert.IsTrue(n.IsPropertySet(property), "G01");

            n.RaiseEvent(clear3Event, EventArgs.Empty);
            Assert.IsFalse(n.IsPropertySet(property), "H01");
        }
コード例 #2
0
ファイル: FundamentTest.cs プロジェクト: hnjm/mathnet-yttrium
        public void FlagTriggerTest()
        {
            MathIdentifier flagId = new MathIdentifier("T3_FT", "FundamentTest");

            NodeEvent clearEvent      = NodeEvent.Register(flagId.DerivePostfix("ClearTrigger"), typeof(EventHandler), typeof(FundamentTest));
            NodeEvent enableEvent     = NodeEvent.Register(flagId.DerivePostfix("EnableTrigger"), typeof(EventHandler), typeof(FundamentTest));
            NodeEvent disableEvent    = NodeEvent.Register(flagId.DerivePostfix("DisableTrigger"), typeof(EventHandler), typeof(FundamentTest));
            NodeEvent disable2Event   = NodeEvent.Register(flagId.DerivePostfix("Disable2Trigger"), typeof(EventHandler), typeof(FundamentTest));
            NodeEvent reevaluateEvent = NodeEvent.Register(flagId.DerivePostfix("ReevaluateTrigger"), typeof(EventHandler), typeof(FundamentTest));

            NodeFlag flag = NodeFlag.Register(flagId, typeof(FundamentTest), FlagKind.Default,
                                              new NodeEventTrigger(EventTriggerAction.Clear, clearEvent),
                                              new NodeEventTrigger(EventTriggerAction.Enable, enableEvent),
                                              new NodeEventTrigger(EventTriggerAction.Disable, disableEvent, disable2Event),
                                              new NodeEventTrigger(EventTriggerAction.Reevaluate, reevaluateEvent));

            NodeObject n = new NodeObject();

            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flag), "A01");

            n.EnableFlag(flag);
            Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flag), "B01");

            n.RaiseEvent(disableEvent, EventArgs.Empty);
            Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flag), "C01");

            n.RaiseEvent(enableEvent, EventArgs.Empty);
            Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flag), "D01");

            n.RaiseEvent(reevaluateEvent, EventArgs.Empty);
            Assert.AreEqual(FlagState.Enabled, n.GetFlagState(flag), "E01");

            n.RaiseEvent(disable2Event, EventArgs.Empty);
            Assert.AreEqual(FlagState.Disabled, n.GetFlagState(flag), "F01");

            n.RaiseEvent(clearEvent, EventArgs.Empty);
            Assert.AreEqual(FlagState.Unknown, n.GetFlagState(flag), "G01");
        }