当前位置: 首页>>代码示例>>C#>>正文


C# Message.Init方法代码示例

本文整理汇总了C#中Message.Init方法的典型用法代码示例。如果您正苦于以下问题:C# Message.Init方法的具体用法?C# Message.Init怎么用?C# Message.Init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Message的用法示例。


在下文中一共展示了Message.Init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FullModeRemove

        public void FullModeRemove()
        {
            var keep = new MessageKeep();
            keep.QuickMode = false;

            var message = new Message("Test");
            message.Init("Field", 1, 2, 3);

            message.Commit(this);

            Assert.IsFalse(message.IsEmpty);

            keep.Add(message);

            Assert.IsFalse(message.IsChanged);
            Assert.IsTrue(keep.IsChanged); // message was added

            keep.Sync();

            message.Remove("Field");

            Assert.IsTrue(message.IsChanged);
            Assert.IsTrue(keep.IsChanged);

            IEnumerable<int> changedIndices;
            var change = keep.Sync(out changedIndices);
            var diff = change.First();

            Assert.IsFalse(message.IsChanged);
            Assert.IsFalse(keep.IsChanged);

            Assert.IsTrue(diff.IsEmpty);
        }
开发者ID:velcrome,项目名称:vvvv-Message,代码行数:33,代码来源:Keep.cs

示例2: FullModeInit

        public void FullModeInit()
        {
            var keep = new MessageKeep();
            keep.QuickMode = false;

            var message = new Message("Test");
            keep.Add(message);
            keep.Sync();

            Assert.IsFalse(message.IsChanged);
            Assert.IsFalse(keep.IsChanged);

            message.Init("Field", 1, 2, 3);

            Assert.IsTrue(message.IsChanged);
            Assert.IsTrue(keep.IsChanged);

            IEnumerable<int> changedIndices;
            var change = keep.Sync(out changedIndices);
            var diff = change.First();

            Assert.IsFalse(message.IsChanged);
            Assert.IsFalse(keep.IsChanged);

            Assert.AreEqual(message.Topic, diff.Topic);
            Assert.AreEqual(message["Field"], diff["Field"]);
        }
开发者ID:velcrome,项目名称:vvvv-Message,代码行数:27,代码来源:Keep.cs

示例3: WithDetails

        public void WithDetails()
        {
            var message = new Message("Test");

            List<Message> diffs = new List<Message>();

            // will be notified on sync only
            message.Init("Field", 1, 2, 3);

            // set up anonymous watcher, simply recording all changes
            message.ChangedWithDetails += (orig, diff) => { diffs.Add(diff); };

            Assert.IsTrue(message.IsChanged);
            Assert.AreEqual(0, diffs.Count);

            var hasChanged = message.Commit(this);
            Assert.IsTrue(hasChanged);

            // notification received
            Assert.AreEqual(1, diffs.Count);

            // change corresponds
            Assert.AreEqual(message.Topic, diffs.First().Topic);
            Assert.AreEqual((Bin<int>)message["Field"], diffs.First()["Field"]);

            Assert.IsFalse(message.IsChanged);

            // sync again, should stay silent this time
            hasChanged = message.Commit(this);
            Assert.IsFalse(hasChanged);
            Assert.AreEqual(1, diffs.Count);

            message.Topic = "ChangedTopic";
            message.Init("Other", 1.68, 3.14);

            // sync again, check changes
            hasChanged = message.Commit(this);
            Assert.IsTrue(hasChanged);
            Assert.AreEqual(2, diffs.Count);

            // change corresponds
            Assert.AreEqual(message.Topic, diffs.Last().Topic);
            Assert.AreEqual((Bin<double>)message["Other"], diffs.Last()["Other"]);

            // really only "Other"
            Assert.AreEqual(1, diffs.Last().Fields.Count());
        }
开发者ID:velcrome,项目名称:vvvv-Message,代码行数:47,代码来源:ChangeEvents.cs

示例4: TopicWithDetails

        public void TopicWithDetails()
        {
            var message = new Message("Test");

            List<Message> diffs = new List<Message>();

            message.Init("Field", 1, 2, 3);
            message.Commit(this); // clear now

            // set up anonymous watcher, simply recording all changes
            message.ChangedWithDetails += (orig, diff) => { diffs.Add(diff); };

            Assert.IsFalse(message.IsChanged);

            message.Topic = "OtherTopic";

            var hasChanged = message.Commit(this);
            Assert.IsTrue(hasChanged);

            // notification received
            Assert.AreEqual(1, diffs.Count);

            // change corresponds
            Assert.AreEqual(message.Topic, diffs.First().Topic);

            Assert.IsTrue(diffs.Last().IsEmpty);
            Assert.IsFalse(message.IsChanged);

            message.Topic = "  OtherTopic   "; // adding whitespaces should not matter
            Assert.AreEqual("OtherTopic", message.Topic);

            Assert.IsFalse(message.IsChanged);

            // sync again, should stay silent this time
            hasChanged = message.Commit(this);
            Assert.IsFalse(hasChanged);
            Assert.AreEqual(1, diffs.Count);
        }
开发者ID:velcrome,项目名称:vvvv-Message,代码行数:38,代码来源:ChangeEvents.cs

示例5: TestInjectWithNew

        public void TestInjectWithNew()
        {
            var a = new Message("Topic");
            a.Init("Field", 1, 2);

            var b = new Message("Topic");
            b.Init("Field", 1, 2);
            b.Init("Other", 1, 2);

            a.Commit(this);

            a.InjectWith(b, true);

            Assert.IsTrue(a.IsChanged);
            Assert.IsFalse(a["Field"].IsChanged);

            Assert.AreEqual(a["Field"], b["Field"]);
            Assert.AreEqual(a["Other"], b["Other"]);
        }
开发者ID:velcrome,项目名称:vvvv-Message,代码行数:19,代码来源:MessageTest.cs

示例6: TestInjectDeepWithDifference

        public void TestInjectDeepWithDifference()
        {
            var a = new Message("Topic");
            a.Init("Field", 1, 2);

            var b = new Message("Topic");
            b.Init("Field", 1, 2, 3); // slightly different

            a.Commit(this);

            a.InjectWith(b, true);

            Assert.IsTrue(a.IsChanged);
            Assert.AreEqual(a["Field"], b["Field"]);
        }
开发者ID:velcrome,项目名称:vvvv-Message,代码行数:15,代码来源:MessageTest.cs

示例7: RenameTestOverwriteFalse

        public void RenameTestOverwriteFalse()
        {
            var name = "field";
            var newName = "newName";
            var m = new Message("topic");
            m.Init(newName, 1);
            m.Init(name, 4);

            try
            {
                m.Rename(name, newName); // overwrite = false
                Assert.Fail("Overwriting Field should be illegal.");
            } catch (DuplicateFieldException)
            {
                //ok
            }
        }
开发者ID:velcrome,项目名称:vvvv-Message,代码行数:17,代码来源:MessageTest.cs

示例8: RenameTestOverwrite

        public void RenameTestOverwrite()
        {
            var name = "field";
            var newName = "newName";
            var m = new Message("topic");
            m.Init(newName, 1);
            m.Init(name, 4,4,4,4);
            m.Commit(this);

            Assert.IsFalse(m.IsChanged);
            m.Rename(name, newName, true);

            Assert.IsTrue(m.IsChanged);
            Assert.AreEqual(m[newName], BinFactory.New(4, 4, 4, 4));
            Assert.AreEqual(m[newName].Count, 4);
        }
开发者ID:velcrome,项目名称:vvvv-Message,代码行数:16,代码来源:MessageTest.cs

示例9: RenameTestIllegalName

        public void RenameTestIllegalName()
        {
            var name = "field";
            var newName = "new Name";
            var m = new Message("topic");
            m.Init(name, 4);

            try
            {
                m.Rename(name, newName);
                Assert.Fail("Illegal Field name should throw exception");
            }
            catch (ParseFormularException)
            {
                //ok
            }
        }
开发者ID:velcrome,项目名称:vvvv-Message,代码行数:17,代码来源:MessageTest.cs

示例10: InitWithNull

        public void InitWithNull()
        {
            var name = "field";
            var m = new Message("topic");

            try
            {
                m.Init(name, 1, 2, 3, null);
                Assert.Fail("Null elements should throw Exception");
            }
            catch (ArgumentNullException)
            {
                // ok!
            }
        }
开发者ID:velcrome,项目名称:vvvv-Message,代码行数:15,代码来源:MessageTest.cs

示例11: InitWithInvalid

        public void InitWithInvalid()
        {
            var name = "field";
            var m = new Message("topic");

            try
            {
                m.Init(name, 1, 2, 3, "fail");
                Assert.Fail("Invalid elements should throw Exception");
            }
            catch (BinTypeMismatchException)
            {
                // ok!
            }
        }
开发者ID:velcrome,项目名称:vvvv-Message,代码行数:15,代码来源:MessageTest.cs

示例12: InitTest

        public void InitTest()
        {
            var name = "field";
            var m = new Message("topic");
            m.Commit(this);

            Assert.IsFalse(m.IsChanged);
            m.Init(name, 1, 2, 3, 4);
            Assert.IsTrue(m.IsChanged);

            Assert.AreEqual(m[name], BinFactory.New(1, 2, 3, 4));
            Assert.AreEqual(m[name].Count, 4);
        }
开发者ID:velcrome,项目名称:vvvv-Message,代码行数:13,代码来源:MessageTest.cs

示例13: EmptyAndRename

        public void EmptyAndRename()
        {
            var m = new Message("topic");

            Assert.IsTrue(m.IsEmpty);

            m.Init("field", 1, 2);
            var c = m.Commit(this);
            Assert.IsTrue(c);

            Assert.IsFalse(m.IsChanged);
            Assert.IsFalse(m.IsEmpty);

            m.Remove("field");
            Assert.IsTrue(m.IsEmpty);
            Assert.IsTrue(m.IsChanged);

            c = m.Commit(this);
            Assert.IsTrue(c);

            c = m.Commit(this);
            Assert.IsFalse(c);
        }
开发者ID:velcrome,项目名称:vvvv-Message,代码行数:23,代码来源:MessageTest.cs

示例14: Clone

        public void Clone()
        {
            var m = new Message("topic");

            var deep = "field";
            m.Init(deep, 1, 2);

            var mess = "message";
            m.Init(mess, new Message("inner"));

            var n = m.Clone() as Message;

            Assert.AreEqual(m[deep], n[deep]); // same content...
            Assert.AreNotEqual(m[deep].GetHashCode(), n[deep].GetHashCode()); // ...but unique bin...

            m[deep].First = 42;
            Assert.AreNotEqual(m[deep].First, n[deep].First); // ...but unique bin...

            Assert.AreEqual(m[mess], n[mess]); // same content...
            Assert.AreNotEqual(m[mess].GetHashCode(), n[mess].GetHashCode()); // ...but unique bin

            var inner = m[mess].First as Message;
            inner.Topic = "changeIt!"; // only change once

            var innerCopy = n[mess].First as Message;
            Assert.AreEqual(inner.Topic, innerCopy.Topic); // both now have a topic called "changeIt!"
        }
开发者ID:velcrome,项目名称:vvvv-Message,代码行数:27,代码来源:MessageTest.cs

示例15: QuickMode

        public void QuickMode()
        {
            var keep = new MessageKeep();
            keep.QuickMode = true;

            var message = new Message("Test");

            List<Message> diffs = new List<Message>();
            message.ChangedWithDetails += (orig, diff) => { diffs.Add(diff); } ;

            keep.Add(message);
            message.Init("Field", 1, 2, 3);

            Assert.IsTrue(message.IsChanged);
            Assert.IsTrue(keep.IsChanged);
            Assert.AreEqual(0, diffs.Count);

            var change = keep.Sync();

            Assert.AreEqual(1, diffs.Count);
            Assert.AreEqual(message.Topic, diffs.First().Topic);

            Assert.IsFalse(message.IsChanged);
            Assert.IsFalse(keep.IsChanged);

            Assert.IsNull(change); // when in quickmode outputs null

            change = keep.Sync();
        }
开发者ID:velcrome,项目名称:vvvv-Message,代码行数:29,代码来源:Keep.cs


注:本文中的Message.Init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。