Example #1
0
        public void Compare_EitherNull_ThrowsException()
        {
            Action act1 = () => _comparer.Compare(null, null);
            Action act2 = () => _comparer.Compare(_left, null);
            Action act3 = () => _comparer.Compare(null, _right);

            act1.ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be("left");
            act2.ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be("right");
            act3.ShouldThrow <ArgumentNullException>().Which.ParamName.Should().Be("left");
        }
Example #2
0
        private SingleServerSearchTask GetCurrent(OrderSelectTask orderSelectTask,
                                                  List <SingleServerSearchTask> searchTasks, OrderType orderType)
        {
            SingleServerSearchTask current = searchTasks.FirstOrDefault(x => !(x.IsAllDataRead && x.Length == 0));

            if (current == null)
            {
                return(null);
            }

            foreach (var searchTask in searchTasks)
            {
                if (searchTask.IsAllDataRead && searchTask.Length == 0)
                {
                    continue;
                }

                if (orderType == OrderType.Desc &&
                    DataComparer.Compare(current.GetData(), searchTask.GetData(), orderSelectTask.ScriptDescription) < 0)
                {
                    current = searchTask;
                }
                if (orderType == OrderType.Asc &&
                    DataComparer.Compare(current.GetData(), searchTask.GetData(), orderSelectTask.ScriptDescription) > 0)
                {
                    current = searchTask;
                }
            }

            return(current);
        }
Example #3
0
        protected override List <SearchData> MergeOrder(OrderSelectTask orderSelectTask,
                                                        List <SingleServerSearchTask> searchTasks, OrderType orderType)
        {
            var ret = new List <SearchData>();

            searchTasks.RemoveAll(x => !x.IsServersAvailbale);

            PreLoadPages(searchTasks);

            while (ret.Count < orderSelectTask.UserPage && !IsFinishMerge(searchTasks))
            {
                var current = GetCurrent(orderSelectTask, searchTasks, orderType);

                if (ret.Count == 0 ||
                    DataComparer.Compare(current.GetData(), ret.Last(), orderSelectTask.ScriptDescription) != 0)
                {
                    ret.Add(current.GetData());
                }

                current.IncrementPosition();

                ReadSameValue(orderSelectTask, searchTasks, ret.Last());

                LoadPages(searchTasks);
                searchTasks.RemoveAll(x => !x.IsServersAvailbale);
            }

            return(ret);
        }
        public void Compare_BothDefault_ResSameTrue()
        {
            var diff = Tables.Default;

            var res1 = _comparer.Compare(left, right);
            var res2 = _comparer.Compare(left, diff);

            res1.Same.Should().HaveCount(2);
            res2.Same.Should().HaveCount(2);
        }
Example #5
0
 private void ReadSameValue(OrderSelectTask orderSelectTask, List <SingleServerSearchTask> searchTasks,
                            SearchData searchData)
 {
     foreach (var searchTask in searchTasks)
     {
         if (!searchTask.IsAllDataRead && searchTask.Length > 0 &&
             DataComparer.Compare(searchTask.GetData(), searchData, orderSelectTask.ScriptDescription) == 0)
         {
             searchTask.IncrementPosition();
         }
     }
 }
Example #6
0
        private CompareResult RunCompare()
        {
            _watch.Restart();

            var res = _comparer.Compare(_left, _right);

            _watch.Stop();

            Console.WriteLine("Total Time: " + _watch.Elapsed);
            Console.WriteLine("Sorting Time: " + _comparer.TimeTakenForSorting);
            Console.WriteLine("Comparing Time: " + _comparer.TimeTakenForComparing);
            return(res);
        }
        public void IntroSample()
        {
            left.Add(2, "Diff1")
            .Add(3, "LeftOnly");

            right.Add(2, "Diff2")
            .Add(4, "RightOnly");

            var res = _subject.Compare(left, right);

            res.Same.Should().HaveCount(2);
            res.Different.Values().Single().ShouldBeEquivalentTo(new[] { "Diff1", "Diff2" });

            res.LeftOnly.Items().ShouldBeEquivalentTo(new[] { new[] { "3", "LeftOnly" } });
            res.RightOnly.Items().ShouldBeEquivalentTo(new[] { new[] { "4", "RightOnly" } });
        }
Example #8
0
        public void Compare_Default_Result_SameCollection_Has2()
        {
            var res = _comparer.Compare(_left, _right);

            res.Same.Should().HaveCount(2);
        }