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


C# List.Intersect方法代码示例

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


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

示例1: CanBeUsedByLinqSetOperatorsSuchAsIntersect

        public void CanBeUsedByLinqSetOperatorsSuchAsIntersect()
        {
            IList<ConcreteEntityWithDomainSignatureProperties> objects1 =
                new List<ConcreteEntityWithDomainSignatureProperties>();
            var object1 = new ConcreteEntityWithDomainSignatureProperties
                              {
                                  Name = "Billy McCafferty",
                              };
            EntityIdSetter.SetIdOf(object1, 2);
            objects1.Add(object1);

            IList<ConcreteEntityWithDomainSignatureProperties> objects2 =
                new List<ConcreteEntityWithDomainSignatureProperties>();
            var object2 = new ConcreteEntityWithDomainSignatureProperties
                              {
                                  Name = "Jimi Hendrix",
                              };
            EntityIdSetter.SetIdOf(object2, 1);
            objects2.Add(object2);
            var object3 = new ConcreteEntityWithDomainSignatureProperties
                              {
                                  Name =
                                      "Doesn't Matter since the Id will match and the presedence of the domain signature will go overridden",
                              };
            EntityIdSetter.SetIdOf(object3, 2);
            objects2.Add(object3);

            Assert.AreEqual(1, objects1.Intersect(objects2,
                                                  new BaseObjectEqualityComparer
                                                      <ConcreteEntityWithDomainSignatureProperties>()).Count());
            Assert.AreEqual(objects1.Intersect(objects2,
                                               new BaseObjectEqualityComparer
                                                   <ConcreteEntityWithDomainSignatureProperties>()).First(), object1);
            Assert.AreEqual(objects1.Intersect(objects2,
                                               new BaseObjectEqualityComparer
                                                   <ConcreteEntityWithDomainSignatureProperties>()).First(), object3);
        }
开发者ID:emhenn,项目名称:UCDArch,代码行数:37,代码来源:BaseObjectEqualityComparerTests.cs

示例2: MakeAssertions

 private void MakeAssertions(ICollection<string> searchResults, List<int> expectedSearchResultIndexValues, int expectedCount)
 {
     Assert.IsNotNull(searchResults);
     Assert.IsTrue(searchResults.Count == expectedCount);
     ICollection<int> actualSearchResultIndexValues =
         searchResults.Select(searchResult => _fileData.IndexOf(searchResult)).ToList();
     Assert.IsTrue(expectedSearchResultIndexValues.Intersect(actualSearchResultIndexValues).Count() ==
                   expectedSearchResultIndexValues.Count);
 }
开发者ID:initialspark,项目名称:hscic-news-search,代码行数:9,代码来源:DocumentSearchEngineTests.cs

示例3: TestIntersectAdd_WithComparer_NullDestination_Throws

 public void TestIntersectAdd_WithComparer_NullDestination_Throws()
 {
     IReadOnlySublist<List<int>, int> list1 = new List<int>().ToSublist();
     IExpandableSublist<List<int>, int> list2 = new List<int>().ToSublist();
     IExpandableSublist<List<int>, int> destination = null;
     IComparer<int> comparer = Comparer<int>.Default;
     list1.Intersect(list2, comparer).AddTo(destination);
 }
开发者ID:jehugaleahsa,项目名称:NDex,代码行数:8,代码来源:IntersectAddTester.cs

示例4: TestIntersectAdd_WithComparison_NullList2_Throws

 public void TestIntersectAdd_WithComparison_NullList2_Throws()
 {
     IReadOnlySublist<List<int>, int> list1 = new List<int>().ToSublist();
     IExpandableSublist<List<int>, int> list2 = null;
     Func<int, int, int> comparison = Comparer<int>.Default.Compare;
     list1.Intersect(list2, comparison);
 }
开发者ID:jehugaleahsa,项目名称:NDex,代码行数:7,代码来源:IntersectAddTester.cs

示例5: TestIntersectAdd_NullDestination_Throws

 public void TestIntersectAdd_NullDestination_Throws()
 {
     IReadOnlySublist<List<int>, int> list1 = new List<int>().ToSublist();
     IExpandableSublist<List<int>, int> list2 = new List<int>().ToSublist();
     IExpandableSublist<List<int>, int> destination = null;
     list1.Intersect(list2).AddTo(destination);
 }
开发者ID:jehugaleahsa,项目名称:NDex,代码行数:7,代码来源:IntersectAddTester.cs

示例6: TestIntersectAdd_NullList2_Throws

 public void TestIntersectAdd_NullList2_Throws()
 {
     IReadOnlySublist<List<int>, int> list1 = new List<int>().ToSublist();
     IExpandableSublist<List<int>, int> list2 = null;
     list1.Intersect(list2);
 }
开发者ID:jehugaleahsa,项目名称:NDex,代码行数:6,代码来源:IntersectAddTester.cs

示例7: TestIntersectAdd_NullComparison_Throws

 public void TestIntersectAdd_NullComparison_Throws()
 {
     IReadOnlySublist<List<int>, int> list1 = new List<int>().ToSublist();
     IExpandableSublist<List<int>, int> list2 = new List<int>().ToSublist();
     Func<int, int, int> comparison = null;
     list1.Intersect(list2, comparison);
 }
开发者ID:jehugaleahsa,项目名称:NDex,代码行数:7,代码来源:IntersectAddTester.cs

示例8: TestIntersectCopy_WithComparer_NullList2_Throws

 public void TestIntersectCopy_WithComparer_NullList2_Throws()
 {
     IReadOnlySublist<List<int>, int> list1 = new List<int>().ToSublist();
     IExpandableSublist<List<int>, int> list2 = null;
     IComparer<int> comparer = Comparer<int>.Default;
     list1.Intersect(list2, comparer);
 }
开发者ID:jehugaleahsa,项目名称:NDex,代码行数:7,代码来源:IntersectCopyTester.cs

示例9: Intersect_abnormal

        public void Intersect_abnormal()
        {
            // arrange
            List<int> first = new List<int>() { 1, 2, 3 };

            // act and assert
            try
            {
                first.Intersect(null);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is ArgumentNullException);
            }
        }
开发者ID:jlinqer,项目名称:jLinqer,代码行数:16,代码来源:EnumerableAbnormalTest.cs

示例10: Intersect

        public void Intersect()
        {
            // arrange
            List<int> first = new List<int>() { 1, 2, 3 };
            List<int> second = new List<int>() { 1, 3 };

            // act
            List<int> actual = first.Intersect(second).ToList();

            // assert
            Assert.AreEqual(2, actual.Count());
            Assert.AreEqual(1, actual[0]);
            Assert.AreEqual(3, actual[1]);
        }
开发者ID:jlinqer,项目名称:jLinqer,代码行数:14,代码来源:EnumerableTest.cs

示例11: Serialization

        [Ignore()] // This test seems totally broken
        public void Serialization()
        {
            Assembly twitterizerAssembly = Assembly.GetAssembly(typeof(TwitterUser));
            var objectTypesToCheck = from t in twitterizerAssembly.GetExportedTypes()
                                     where !t.IsAbstract &&
                                     !t.IsInterface &&
                                     (
                                      t.GetInterfaces().Contains(twitterizerAssembly.GetType("Twitterizer.Core.ITwitterObject")) ||
                                      t.IsSubclassOf(twitterizerAssembly.GetType("Twitterizer.Entities.TwitterEntity"))
                                     )
                                     select t;

            var interfacesToImplement = new List<Type>();
            interfacesToImplement.Add(twitterizerAssembly.GetType("Twitterizer.Core.ICommand`1"));
            //interfacesToImplement.Add(twitterizerAssembly.GetType("Twitterizer.Core.ITwitterCommand`1"));
            Assert.AreEqual(0, interfacesToImplement.Where(x => x == null).Count(), "interfacesToImplement contains null values");

            var baseClassesToInherit = new List<Type>();
            baseClassesToInherit.Add(twitterizerAssembly.GetType("Twitterizer.Commands.PagedTimelineCommand`1"));
            Assert.AreEqual(0, baseClassesToInherit.Where(x => x == null).Count(), "baseClassesToInherit contains null values");

            var commandTypesToCheck =
                (from t in twitterizerAssembly.GetTypes()
                 where
                     (
                         interfacesToImplement.Intersect(t.GetInterfaces()).Count() > 0 ||
                         baseClassesToInherit.Any(t.IsSubclassOf)
                     )
                 select t)
                    .ToList();
            Assert.AreEqual(0, commandTypesToCheck.Where(x => x == null).Count(), "commandTypesToCheck contains null values");

            var objects = objectTypesToCheck.Union(commandTypesToCheck).ToList();
            Assert.AreEqual(0, objects.Where(x => x == null).Count(), "objects contains null values");

            foreach (Type type in objects)
            {
                Console.WriteLine(string.Format("Inspecting: {0}", type.FullName));

                // Check that the object itself is marked as serializable
                Assert.IsTrue(type.IsSerializable, string.Format("{0} is not marked as Serializable", type.Name));

                // Get the parameter-less constructor, if there is one
                ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);

                if (constructor == null)
                    Assert.Fail(string.Format("{0} does not have a public ctor", type.FullName));

                // Instantiate the type by invoking the constructor
                object objectToSerialize = constructor.Invoke(null);

                try
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        // Serialize the object
                        new BinaryFormatter().Serialize(ms, objectToSerialize);
                    }
                }
                catch (Exception) // Catch any exceptions and assert a failure
                {
                    Assert.Fail(string.Format("{0} could not be serialized", type.FullName));
                }
            }
        }
开发者ID:paulduran,项目名称:Twitterizer,代码行数:66,代码来源:CoreTests.cs


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