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


C# List.Union方法代码示例

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


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

示例1: Equals_EqualityComparisonApplied

        public void Equals_EqualityComparisonApplied()
        {
            List<IntWrapper> source1 = new List<IntWrapper>() {                 
                new IntWrapper(){ Value=5},
                new IntWrapper(){ Value=4},
                new IntWrapper(){ Value=3}
            };
            List<IntWrapper> source2 = new List<IntWrapper>() {                 
                new IntWrapper(){ Value=3},
                new IntWrapper(){ Value=2},
                new IntWrapper(){ Value=1},
                new IntWrapper(){ Value=0}
            };
            List<IntWrapper> result = source1.Union(source2, ProjectedEqualityComparer.Create<IntWrapper, int>(
                (x, y) => { return x == y; },
                s=>s.Value)).ToList();

            for (int i = 0; i < result.Count; i++)
            {
                Assert.IsTrue(result.Where(x => x.Value == i).Count() == 1);
            }

            Assert.IsTrue(result.Count == 6);
            Assert.IsTrue(result.Where(x => x.Value == 3).Count() == 1);

        }
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:26,代码来源:ProjectedEqualityComparerTests.cs

示例2: UnionQueryReuse

        public void UnionQueryReuse()
        {
            List<int> first = new List<int> { 1, 2 };
            List<int> second = new List<int> { 2, 3 };
            IEnumerable<int> enumerable = first.Union(second);

            enumerable.AssertEqual(1, 2, 3);

            first.Insert(0, 0);
            second.Add(4);
            enumerable.AssertEqual(0, 1, 2, 3, 4);
        }
开发者ID:barisertekin,项目名称:LINQlone,代码行数:12,代码来源:UnionTests.cs

示例3: Equals_EqualityComparisonApplied

        public void Equals_EqualityComparisonApplied()
        {
            List<int> source1 = new List<int>() { 5, 4, 3 };
            List<int> source2 = new List<int>() { 3, 2, 1, 0 };
            List<int> result = source1.Union(source2, GenericEqualityComparer.Create<int>((x, y) => { return x == y; })).ToList();

            for (int i = 0; i < result.Count; i++)
            {
                Assert.IsTrue(result.Where(x => x == i).Count() == 1);
            }

            Assert.IsTrue(result.Count == 6);
            Assert.IsTrue(result.Where(x => x == 3).Count() == 1);
        }
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:14,代码来源:GenericEqualityComparerTests.cs

示例4: Union

        public void Union()
        {
            var a = new List<int> { 1, 2, 3 };
            var b = new List<int> { 3, 4, 5, 6 };

            var results = a.Union(b).ToList();

            Assert.AreEqual(6, results.Count());
            Assert.AreEqual(1, results[0]);
            Assert.AreEqual(2, results[1]);
            Assert.AreEqual(3, results[2]);
            Assert.AreEqual(4, results[3]);
            Assert.AreEqual(5, results[4]);
            Assert.AreEqual(6, results[5]);
        }
开发者ID:korz,项目名称:MathIsEverywhere,代码行数:15,代码来源:IntegerTests.cs

示例5: TuningStringsEqualsTest

        public void TuningStringsEqualsTest()
        {
            //Object\regular equality
            var expected = new TuningStrings(new Int16[] { -2, 0, 0, 0, 0, 0 });
            var actual = new TuningStrings(new Int16[] { 0, 0, 0, 0, 0, 0 });
            Assert.AreNotEqual(expected, actual);

            //LINQ equality
            var list = new List<TuningStrings> { expected, expected, actual };
            var distinct = list.Union(new List<TuningStrings> { actual, actual, expected }).ToList();
            if (list.Count == distinct.Count)
            {
                Assert.Fail();
            }
        }
开发者ID:aequitas,项目名称:rocksmith-custom-song-toolkit,代码行数:15,代码来源:TuningDefinitionTests.cs

示例6: Cleanup_InstallationStatusProviderReturnThreePackages_OneIsInstalled_TwoAreNot_DeleteDirectoryIsCalledForEachLegacyPackage_SuccessResultIsReturned

        public void Cleanup_InstallationStatusProviderReturnThreePackages_OneIsInstalled_TwoAreNot_DeleteDirectoryIsCalledForEachLegacyPackage_SuccessResultIsReturned()
        {
            // Arrange
            var installationStatusProvider = new Mock<IInstallationStatusProvider>();
            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            filesystemAccessor.Setup(f => f.DeleteDirectory(It.IsAny<string>())).Returns(true);

            var installedPackages = new List<NuDeployPackageInfo>
                {
                    TestUtilities.GetPackage("Package.A", true)
                };

            var legacyPackages = new List<NuDeployPackageInfo>
                {
                    TestUtilities.GetPackage("Package.B", false),
                    TestUtilities.GetPackage("Package.C", false),
                };

            var packages = installedPackages.Union(legacyPackages).ToList();

            installationStatusProvider.Setup(i => i.GetPackageInfo()).Returns(packages);

            var cleanupService = new CleanupService(installationStatusProvider.Object, filesystemAccessor.Object);

            // Act
            var result = cleanupService.Cleanup();

            // Assert
            foreach (var package in installedPackages)
            {
                string packageFolder = package.Folder;
                filesystemAccessor.Verify(f => f.DeleteDirectory(packageFolder), Times.Never());
            }

            foreach (var package in legacyPackages)
            {
                string packageFolder = package.Folder;
                filesystemAccessor.Verify(f => f.DeleteDirectory(packageFolder), Times.Once());
            }

            Assert.AreEqual(ServiceResultType.Success, result.Status);
        }
开发者ID:andreaskoch,项目名称:NuDeploy,代码行数:42,代码来源:CleanupServiceTests.cs

示例7: Union_Should_Removed_Duplicate_Emails

        public void Union_Should_Removed_Duplicate_Emails()
        {
            // Arrange + Act
            UserViewModel user1 = new UserViewModel();
            user1.ExistingEmail = "[email protected]";

            UserViewModel user2 = new UserViewModel();
            user2.ExistingEmail = "[email protected]";

            UserViewModel user2Again = new UserViewModel();
            user2Again.ExistingEmail = "[email protected]";

            List<UserViewModel> userList1 = new List<UserViewModel>()
            {
                user1, user2, user2Again
            };

            List<UserViewModel> userList2 = new List<UserViewModel>()
            {
                user1, user2, user2Again
            };

            // Assert
            Assert.That(userList1.Union(userList2).Count(), Is.EqualTo(2));
        }
开发者ID:NaseUkolyCZ,项目名称:roadkill,代码行数:25,代码来源:UserViewModelTests.cs

示例8: Cleanup_Parameterized_InstallationStatusProviderReturnThreePackages_OneIsInstalled_TwoAreNot_DeleteFails_FailureResultIsReturned

        public void Cleanup_Parameterized_InstallationStatusProviderReturnThreePackages_OneIsInstalled_TwoAreNot_DeleteFails_FailureResultIsReturned()
        {
            // Arrange
            string packageId = "Package.A";

            var installationStatusProvider = new Mock<IInstallationStatusProvider>();
            var filesystemAccessor = new Mock<IFilesystemAccessor>();
            filesystemAccessor.Setup(f => f.DeleteDirectory(It.IsAny<string>())).Returns(false);

            var installedPackages = new List<NuDeployPackageInfo>
                {
                    TestUtilities.GetPackage("Package.A", true, 9)
                };

            var legacyPackages = new List<NuDeployPackageInfo>
                {
                    TestUtilities.GetPackage("Package.A", false, 8),
                    TestUtilities.GetPackage("Package.A", false, 7),
                };

            var packages = installedPackages.Union(legacyPackages).ToList();

            installationStatusProvider.Setup(i => i.GetPackageInfo()).Returns(packages);

            var cleanupService = new CleanupService(installationStatusProvider.Object, filesystemAccessor.Object);

            // Act
            var result = cleanupService.Cleanup(packageId);

            // Assert
            Assert.AreEqual(ServiceResultType.Failure, result.Status);
        }
开发者ID:andreaskoch,项目名称:NuDeploy,代码行数:32,代码来源:CleanupServiceTests.cs

示例9: GlobalInstanceShouldBeThreadSafe

        public virtual void GlobalInstanceShouldBeThreadSafe()
        {
            var unsubscribeActions = new ConcurrentBag<Action>();

            try
            {
                Exception exception = null;

                var subscribeTasks = new List<Task>();
                var publishTasks = new List<Task>();

                // start many publishers
                for (var i = 0; i < 250; i++)
                {
                    publishTasks.Add(Task.Factory.StartNew(() => Events.Publish(new SystemChecked())).ContinueWith(t => exception = t.Exception, TaskContinuationOptions.None));
                }

                // start many subscribers
                for (var i = 0; i < 200; i++)
                {
                    subscribeTasks.Add(
                        Task.Factory.StartNew(
                            () =>
                            {
                                var unsubscribe = Events.Subscribe<IEvent>(ev => { });
                                unsubscribeActions.Add(unsubscribe.Dispose);
                            }).ContinueWith(t => exception = t.Exception, TaskContinuationOptions.None));
                }

                // start many publishers
                for (var i = 0; i < 250; i++)
                {
                    publishTasks.Add(Task.Factory.StartNew(() => Events.Publish(new ModuleChecked())).ContinueWith(t => exception = t.Exception, TaskContinuationOptions.None));
                }

                Task.WaitAll(subscribeTasks.Union(publishTasks).ToArray());

                exception.Should().Be.Null();

                subscribeTasks.Clear();
                publishTasks.Clear();

                var unsubscribTasks = new List<Task>();

                foreach (var unsubscribeAction in new List<Action>(unsubscribeActions))
                {
                    var action = unsubscribeAction;

                    // start publisher
                    publishTasks.Add(Task.Factory.StartNew(() => Events.Publish(new ModuleChecked())).ContinueWith(t => exception = t.Exception, TaskContinuationOptions.None));

                    // start unsubscriber
                    unsubscribTasks.Add(Task.Factory.StartNew(action).ContinueWith(t => exception = t.Exception, TaskContinuationOptions.None));

                    // start publisher
                    publishTasks.Add(Task.Factory.StartNew(() => Events.Publish(new SystemChecked())).ContinueWith(t => exception = t.Exception, TaskContinuationOptions.None));

                    // start subscriber
                    subscribeTasks.Add(
                        Task.Factory.StartNew(
                            () =>
                            {
                                var unsubscribe = Events.Subscribe<IEvent>(ev => { });
                                unsubscribeActions.Add(unsubscribe.Dispose);
                            }).ContinueWith(t => exception = t.Exception, TaskContinuationOptions.None));
                }

                Task.WaitAll(subscribeTasks.Union(publishTasks).Union(unsubscribTasks).ToArray());

                subscribeTasks.Clear();
                publishTasks.Clear();
                unsubscribTasks.Clear();

                exception.Should().Be.Null();
            }
            finally
            {
                foreach (var action in unsubscribeActions)
                {
                    action();
                }

                Events.Global.Reset();
            }
        }
开发者ID:NikGovorov,项目名称:Taijutsu,代码行数:85,代码来源:EventsFixture.cs

示例10: CategoriesAreAddeViaFeedOrEventMetadict

 public void CategoriesAreAddeViaFeedOrEventMetadict()
 {
     var list = new List<string>() { "a", "B" };
     var metadict = new Dictionary<string,string>() { { "category", "b, X,y, Z" } };  // spaces should be trimmed, caps lowered
     var cat_string = metadict["category"];
     var l = Collector.SplitLowerTrimAndUniqifyCats(cat_string);
     list = list.Union(l).ToList();
     list.Sort();
     list = Collector.LowerTrimAndUniqifyCats(list);
     Assert.IsTrue(list.SequenceEqual( new List<string>() { "a", "b", "x", "y", "z" } ));
 }
开发者ID:judell,项目名称:elmcity,代码行数:11,代码来源:EventCollectorTest.cs

示例11: UnionWithComparerQueryReuse

        public void UnionWithComparerQueryReuse()
        {
            List<int> first = new List<int> { 1, 2 };
            List<int> second = new List<int> { 2, 3 };
            IEnumerable<int> enumerable = first.Union(second, EqualityComparer<int>.Default);

            enumerable.AssertEqual(1, 2, 3);

            first.Insert(0, 0);
            second.Add(4);
            enumerable.AssertEqual(0, 1, 2, 3, 4);
        }
开发者ID:barisertekin,项目名称:LINQlone,代码行数:12,代码来源:UnionTests.cs


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