當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。