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);

        }
Beispiel #2
0
        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);
        }
        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);
        }
Beispiel #4
0
        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]);
        }
        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();
            }
        }
        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);
        }
        public void Union_Should_Removed_Duplicate_Emails()
        {
            // Arrange + Act
            UserViewModel user1 = new UserViewModel();
            user1.ExistingEmail = "*****@*****.**";

            UserViewModel user2 = new UserViewModel();
            user2.ExistingEmail = "*****@*****.**";

            UserViewModel user2Again = new UserViewModel();
            user2Again.ExistingEmail = "*****@*****.**";

            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));
        }
        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);
        }
Beispiel #9
0
        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();
            }
        }
Beispiel #10
0
 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" } ));
 }
Beispiel #11
0
        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);
        }