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


C# ReadPreference.Equals方法代码示例

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


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

示例1: TestEquals

        public void TestEquals()
        {
            ReadPreference primary = ReadPreference.Primary;
            ReadPreference secondary = ReadPreference.Secondary;
            ReadPreference voidTag = new ReadPreference(new HashSet<string>());
            ReadPreference someTags = new ReadPreference(new HashSet<string>());
            someTags.Tags.Add("new york");
            someTags.Tags.Add("rack 1");

            ReadPreference someTagsBis = new ReadPreference(new HashSet<string>());
            someTagsBis.Tags.Add("rack 1");
            someTagsBis.Tags.Add("new york");

            ReadPreference someTagsAgain = new ReadPreference(new HashSet<string>());
            someTagsAgain.Tags.Add("palo alto");
            someTagsAgain.Tags.Add("rack 1");

            //Equals to self
            Assert.AreEqual(true, primary.Equals(primary));
            Assert.AreEqual(true, secondary.Equals(secondary));
            Assert.AreEqual(true, voidTag.Equals(voidTag));
            Assert.AreEqual(true, someTags.Equals(someTags));
            Assert.AreEqual(true, someTagsAgain.Equals(someTagsAgain));

            //Basic stuff are not equal
            Assert.AreEqual(false, primary.Equals(secondary));
            Assert.AreEqual(false, secondary.Equals(primary));
            Assert.AreEqual(false, primary.Equals(voidTag));
            Assert.AreEqual(false, voidTag.Equals(primary));

            Assert.AreEqual(false, primary.Equals(secondary));
            Assert.AreEqual(false, secondary.Equals(primary));
            Assert.AreEqual(false, primary.Equals(someTags));
            Assert.AreEqual(false, someTags.Equals(primary));
            Assert.AreEqual(false, primary.Equals(someTagsAgain));
            Assert.AreEqual(false, someTagsAgain.Equals(primary));

            Assert.AreEqual(false, someTags.Equals(secondary));
            Assert.AreEqual(false, secondary.Equals(someTags));

            Assert.AreEqual(true, someTags.Equals(someTagsBis));
            Assert.AreEqual(true, someTagsBis.Equals(someTags));

            //two object equals constructed separately are equals
            Assert.AreEqual(true, someTags.Equals(someTagsBis));
            Assert.AreEqual(true, someTagsBis.Equals(someTags));

            //default tagged is not tagged but defaulted to secondary ok
            Assert.AreEqual(true, voidTag.Equals(secondary));
            Assert.AreEqual(true, secondary.Equals(voidTag));
            Assert.AreEqual(false, someTagsAgain.Equals(secondary));
            Assert.AreEqual(false, secondary.Equals(someTagsAgain));
        }
开发者ID:kamaradclimber,项目名称:mongo-csharp-driver,代码行数:53,代码来源:ReadPreferenceTests.cs

示例2: Equals_should_return_true_when_all_fields_are_equal

        public void Equals_should_return_true_when_all_fields_are_equal()
        {
            var mode = ReadPreferenceMode.Secondary;
            var tagSets = new[] { new TagSet(new[] { new Tag("name", "value") }) };
            var subject1 = new ReadPreference(mode, tagSets);
            var subject2 = new ReadPreference(mode, tagSets);

            var result1 = subject1.Equals(subject2);
            var result2 = subject1.Equals((object)subject2);
            var hashCode1 = subject1.GetHashCode();
            var hashCode2 = subject2.GetHashCode();

            result1.Should().BeTrue();
            result2.Should().BeTrue();
            hashCode1.Should().Be(hashCode2);

        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:17,代码来源:ReadPreferenceTests.cs

示例3: Equals_Act_and_Assert

        // private methods
        private void Equals_Act_and_Assert(ReadPreference lhs, ReadPreference rhs, bool expectedResult)
        {
            var result1 = lhs.Equals(rhs);
            var result2 = lhs.Equals((object)rhs);
            var hashCode1 = lhs.GetHashCode();
            var hashCode2 = rhs.GetHashCode();

            result1.Should().Be(expectedResult);
            result2.Should().Be(expectedResult);
            (hashCode1 == hashCode2).Should().Be(expectedResult);
        }
开发者ID:mfidemraizer,项目名称:mongo-csharp-driver,代码行数:12,代码来源:ReadPreferenceTests.cs

示例4: Equals_should_return_false_when_any_field_is_not_equal

        public void Equals_should_return_false_when_any_field_is_not_equal(
            [Values("mode", "tagSets")]
            string notEqualFieldName)
        {
            var mode = ReadPreferenceMode.Secondary;
            var tagSets = new[] { new TagSet(new[] { new Tag("name", "value1") }) };
            var subject1 = new ReadPreference(mode, tagSets);
            switch (notEqualFieldName)
            {
                case "mode": mode = ReadPreferenceMode.SecondaryPreferred; break;
                case "tagSets": tagSets = new[] { new TagSet(new[] { new Tag("name", "value2") }) }; break;
                default: throw new ArgumentException("notEqualFieldName");
            }
            var subject2 = new ReadPreference(mode, tagSets);

            var result1 = subject1.Equals(subject2);
            var result2 = subject1.Equals((object)subject2);
            var hashCode1 = subject1.GetHashCode();
            var hashCode2 = subject2.GetHashCode();

            result1.Should().BeFalse();
            result2.Should().BeFalse();
            hashCode1.Should().NotBe(hashCode2);

        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:25,代码来源:ReadPreferenceTests.cs

示例5: Connect

        internal void Connect(ReadPreference readPreference)
        {
            // Console.WriteLine("MongoServerInstance[{0}]: Connect(slaveOk={1}) called.", sequentialId, slaveOk);
            lock (serverInstanceLock)
            {
                // note: don't check that state is Disconnected here
                // when reconnecting to a replica set state can transition from Connected -> Connecting -> Connected

                SetState(MongoServerState.Connecting);
                connectException = null;
                try
                {
                    endPoint = address.ToIPEndPoint(server.Settings.AddressFamily);

                    try
                    {
                        var connection = connectionPool.AcquireConnection(null);
                        try
                        {
                            VerifyState(connection);
                            if (!isPrimary && readPreference.Equals(ReadPreference.Primary) )
                            {
                                throw new MongoConnectionException("Server is not a primary and readPreference is set to primary");
                            }
                        }
                        finally
                        {
                            connectionPool.ReleaseConnection(connection);
                        }
                    }
                    catch
                    {
                        connectionPool.Clear();
                        throw;
                    }

                    SetState(MongoServerState.Connected);
                }
                catch (Exception ex)
                {
                    SetState(MongoServerState.Disconnected);
                    connectException = ex;
                    throw;
                }
            }
        }
开发者ID:kamaradclimber,项目名称:mongo-csharp-driver,代码行数:46,代码来源:MongoServerInstance.cs


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