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


C# SafeMode.Freeze方法代码示例

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


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

示例1: TestEquals

        public void TestEquals()
        {
            var a1 = new SafeMode(false);
            var a2 = new SafeMode(true) { Enabled = false };
            var a3 = a2;
            var b = new SafeMode(false) { Enabled = true };
            var c = new SafeMode(false) { FSync = true };
            var d = new SafeMode(false) { J = true };
            var e = new SafeMode(false) { W = 2 };
            var f = new SafeMode(false) { WMode = "mode" };
            var g = new SafeMode(false) { WTimeout = TimeSpan.FromMinutes(1) };
            var null1 = (SafeMode)null;
            var null2 = (SafeMode)null;

            Assert.AreNotSame(a1, a2);
            Assert.AreSame(a2, a3);
            Assert.IsTrue(a1.Equals((object)a2));
            Assert.IsFalse(a1.Equals((object)null));
            Assert.IsFalse(a1.Equals((object)"x"));

            Assert.IsTrue(a1 == a2);
            Assert.IsTrue(a2 == a3);
            Assert.IsFalse(a1 == b);
            Assert.IsFalse(a1 == c);
            Assert.IsFalse(a1 == d);
            Assert.IsFalse(a1 == e);
            Assert.IsFalse(a1 == f);
            Assert.IsFalse(a1 == g);
            Assert.IsFalse(a1 == null1);
            Assert.IsFalse(null1 == a1);
            Assert.IsTrue(null1 == null2);

            Assert.IsFalse(a1 != a2);
            Assert.IsFalse(a2 != a3);
            Assert.IsTrue(a1 != b);
            Assert.IsTrue(a1 != c);
            Assert.IsTrue(a1 != d);
            Assert.IsTrue(a1 != e);
            Assert.IsTrue(a1 != f);
            Assert.IsTrue(a1 != g);
            Assert.IsTrue(a1 != null1);
            Assert.IsTrue(null1 != a1);
            Assert.IsFalse(null1 != null2);

            var hash = a1.GetHashCode();
            Assert.AreEqual(hash, a2.GetHashCode());

            // check that all tests still pass after objects are Frozen
            a1.Freeze();
            a2.Freeze();
            a3.Freeze();
            b.Freeze();
            c.Freeze();
            d.Freeze();
            e.Freeze();
            f.Freeze();
            g.Freeze();

            Assert.AreNotSame(a1, a2);
            Assert.AreSame(a2, a3);
            Assert.IsTrue(a1.Equals((object)a2));
            Assert.IsFalse(a1.Equals((object)null));
            Assert.IsFalse(a1.Equals((object)"x"));

            Assert.IsTrue(a1 == a2);
            Assert.IsTrue(a2 == a3);
            Assert.IsFalse(a1 == b);
            Assert.IsFalse(a1 == c);
            Assert.IsFalse(a1 == d);
            Assert.IsFalse(a1 == e);
            Assert.IsFalse(a1 == f);
            Assert.IsFalse(a1 == g);
            Assert.IsFalse(a1 == null1);
            Assert.IsFalse(null1 == a1);
            Assert.IsTrue(null1 == null2);

            Assert.IsFalse(a1 != a2);
            Assert.IsFalse(a2 != a3);
            Assert.IsTrue(a1 != b);
            Assert.IsTrue(a1 != c);
            Assert.IsTrue(a1 != d);
            Assert.IsTrue(a1 != e);
            Assert.IsTrue(a1 != f);
            Assert.IsTrue(a1 != g);
            Assert.IsTrue(a1 != null1);
            Assert.IsTrue(null1 != a1);
            Assert.IsFalse(null1 != null2);

            Assert.AreEqual(hash, a1.GetHashCode());
            Assert.AreEqual(hash, a2.GetHashCode());
        }
开发者ID:ncipollina,项目名称:mongo-csharp-driver,代码行数:91,代码来源:SafeModeTests.cs


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