public void CheckStringsDeclared()
        {
            var names = new List<string>();
            checker.GetAllResourceReferences(names);
            Assert.Greater(names.Count, 600, "Должно быть много ресурсных строчек");
            // убрать исключения и повторы
            names = names.Distinct().Where(n => !exceptionString.Contains(n)).ToList();

            // проверить, есть ли они в файлах ресурсов
            var errorsInFile = new Dictionary<string, List<string>>();
            var resxFileNames = Directory.GetFiles(codeBase + @"\TradeSharp.Localisation\Properties", "*.resx");
            
            foreach (var resxFileName in resxFileNames)
            {
                if (excludedResourcesFiles.Contains(resxFileName.Split('\\').Last())) continue;

                var errors = checker.GetNamesLackInResxFile(resxFileName, names);
                if (errors.Count > 0)
                    errorsInFile.Add(Path.GetFileName(resxFileName), errors);
            }

            if (errorsInFile.Count > 0)
            {
                var errorStr = string.Join("\n", errorsInFile.Select(e => e.Key + ": " + string.Join(", ", e.Value)));
                Assert.Fail(errorStr);
            }
        }
        public void ShouldProcessOnMultipleThreads()
        {
            // Arrange
            var breaker = new CircuitBreaker();
            var source = Enumerable.Range(0, 100).ToArray();

            // Act
            var usedThreadIds = new List<int>();
            Reliable.ParallelForEach(
                breaker,
                source,
                elements => usedThreadIds.Add(Thread.CurrentThread.ManagedThreadId),
                new RetryOptions
                {
                    AllowedRetries = 5,
                    RetryInterval = TimeSpan.Zero
                },
                new ParallelOptions
                {
                    MaxDegreeOfParallelism = 100
                });

            // Assert
            if (usedThreadIds.Distinct().Count() == 1)
                Assert.Inconclusive("This test relies on multiple threads, however only one was ever spawned.");
        }
 public void ShouldIterateOverEveryPixel()
 {
     var image = new Bitmap(100, 100);
     var pixels = new List<Tuple<int,int>>();
     image.ForEachPixel((x, y) => pixels.Add(Tuple.Create(x, y)));
     pixels.Distinct().Should().HaveCount(100 * 100);
 }
        public void CheckStringsDeclared()
        {
            var names = new List<string>();
            checker.GetAllResourceReferences(names);
            Assert.Greater(names.Count, 400, "Должно быть много ресурсных строчек");

            // убрать исключения и повторы
            names = names.Distinct().ToList();
            names.Remove("ResourceManager");

            // проверить, есть ли они в файлах ресурсов
            var errorsInFile = new Dictionary<string, List<string>>();
            var resxFileNames = Directory.GetFiles(codeBase + @"\TradeSharp.AdminSite\App_GlobalResources", "*.resx");

            foreach (var resxFileName in resxFileNames)
            {
                var errors = checker.GetNamesLackInResxFile(resxFileName, names);
                if (errors.Count > 0)
                    errorsInFile.Add(Path.GetFileName(resxFileName), errors);
            }

            if (errorsInFile.Count > 0)
            {
                var errorStr = string.Join("\n", errorsInFile.Select(e => e.Key + ": " + string.Join(", ", e.Value)));
                Assert.Fail(errorStr);
            }
        }
예제 #5
0
        public void AssertThatDistinctWorks()
        {
            // Just a quick test of the de-duplication of a list of objects based on an object property value.
            // See JsModuleViewModel.Equals() override.
            // Without the override the items below wouldn't be considered duplicates because by default the equality is based on reference to objects.

            // Arrange
            List<JsModuleViewModel> totalRazorLines = new List<JsModuleViewModel>
            {
                new JsModuleViewModel {OriginalRazorText = "'@serverVariable1'", JavaScriptName = "serverVariable1"},
                new JsModuleViewModel {OriginalRazorText = "'@serverVariable1'", JavaScriptName = "serverVariable1"},
                new JsModuleViewModel {OriginalRazorText = "'@serverVariable2'", JavaScriptName = "serverVariable2"},
                new JsModuleViewModel {OriginalRazorText = "'@serverVariable3'", JavaScriptName = "serverVariable3"},
                new JsModuleViewModel {OriginalRazorText = "'@serverVariable2'", JavaScriptName = "serverVariable2"}
            };

            // Act
            totalRazorLines = totalRazorLines.Distinct().ToList();

            // Assert
            // To illustrate, without the equals override, this wouldn't work because although the values match they are different objects.
            Assert.IsTrue(totalRazorLines.Contains(new JsModuleViewModel { OriginalRazorText = "'@serverVariable2'", JavaScriptName = "serverVariable2" }));

            Assert.AreEqual(3, totalRazorLines.Count);
            Assert.AreEqual(totalRazorLines[0].JavaScriptName, "serverVariable1");
            Assert.AreEqual(totalRazorLines[1].JavaScriptName, "serverVariable2");
            Assert.AreEqual(totalRazorLines[2].JavaScriptName, "serverVariable3");
        }
        public void RandomizedQueueTest()
        {
            for (var k = 0; k < 9; k++)
            {
                var q = new RandomizedQueue<string>();

                var items = new List<string>
                {
                    "0",
                    "1",
                    "2",
                    "3",
                    "4",
                    "5",
                    "6",
                    "7",
                    "8",
                    "9"
                };

                foreach (var item in items)
                {
                    q.Enqueue(item);
                }

                var array = new List<string>();
                for (var i = 0; i < k; i++)
                {
                    array.Add(q.Dequeue());
                }

                Assert.AreEqual(k, array.Distinct().Count());
            }
        }
예제 #7
0
 public void can_shuffle()
 {
     var ints = new List<int>();
     1.UpTo(500, ints.Add);
     ints.Shuffle();
     (ints[0] == 1 && ints[1] == 2 && ints.Last() == 500).ShouldBeFalse();
     ints.Distinct().Count().ShouldEqual(500);
 }
예제 #8
0
        public void DistinctOnTwoCardsReturnsLenghtOf1()
        {
            var cards = new List<Card>() { new Card(CardSuit.Diamond, CardType.King), new Card(CardSuit.Diamond, CardType.King) };
            var comparer = new CardComparer();
            cards = cards.Distinct(comparer).ToList();

            Assert.AreEqual(1, cards.Count);
        }
        public void ShouldIterateOverEveryPixelThatIsNotIgnored()
        {
            var image = new Bitmap(100, 100);
            var pixels = new List<Tuple<int, int>>();
            image.ForEachPixel(
                (x, y) => pixels.Add(Tuple.Create(x, y)),
                new[] { new IgnoreMask(0, 0, 9, 9) });

            pixels.Distinct().Should().HaveCount((100 * 100) - (10 * 10));
        }
예제 #10
0
        public void TestRandomStringSuccess()
        {
            List<string> generated = new List<string>();

            for (var count = 0; count < 20; count++) {
                generated.Add(Shared.Utils.StringExtensions.RandomString(30));
            }

            Assert.AreEqual(20, generated.Distinct().Count());
        }
        public void TestDifferentDiceRolls()
        {
            var input = "1d6";
            var results = new List<double>();

            for (var i = 0; i < 100; i++)
                results.Add(evaluator.Calculate(input));

            Assert.That(results.Distinct().Count(), Is.GreaterThan(1));
        }
예제 #12
0
        public void DistinctQueryReuse()
        {
            List<int> data = new List<int> { 1, 2, 2 };
            IEnumerable<int> enumerable = data.Distinct();

            enumerable.AssertEqual(1, 2);

            data.Add(3);
            enumerable.AssertEqual(1, 2, 3);
        }
        public void UpdateSelectedFilesAtErrorTest() {
            IOpenFileDialogService dialog = new TestFileDialogService();
            var selectedFilesList = new List<string>();

            int retryCount = 2;
            var dialogResult = dialog.ShowDialog(e => {
                selectedFilesList.Add(dialog.File.Name);
                e.Cancel = retryCount-- > 0;
            });
            Assert.AreEqual(3, selectedFilesList.Distinct().Count());
        }
예제 #14
0
		public void Distinct_LinqExt ()
		{
			// Distinct group of numbers

			var numbers = new List<int> (){ 1,1,2,2,3,4,5 };

			var distinctNumbers = numbers.Distinct ();

			Assert.AreEqual (5, distinctNumbers.Count ());
			Assert.AreEqual (1, distinctNumbers.First ());
			Assert.AreEqual (5, distinctNumbers.Last ());
		}
예제 #15
0
 public void GetDistinctBranchesViaLinq()
 {
     IList<Branch> branches = new List<Branch>();
     var branch1 = new Branch
     {
         Geometry = GeometryFromWKT.Parse("LINESTRING (0 0, 100 0)")
     };
     branches.Add(branch1);
     branches.Add(branch1);
     Assert.AreEqual(2, branches.Count);
     Assert.AreEqual(1, branches.Distinct().Count());
 }
예제 #16
0
        public void DistinctReturnsDistinctValuesWhenUsedWithObjectsUsingComparisonExpression()
        {
            var data = new List<OHLCBar>
            {
                new OHLCBar {DT = new DateTime(2000, 1, 1), Open = 100, High = 105, Low = 95, Close = 100},
                new OHLCBar {DT = new DateTime(2000, 1, 2), Open = 99, High = 107, Low = 90, Close = 99},
                new OHLCBar {DT = new DateTime(2000, 1, 1), Open = 100, High = 105, Low = 95, Close = 100},
                new OHLCBar {DT = new DateTime(2000, 1, 2), Open = 99, High = 107, Low = 90, Close = 99},
            };

            data = data.Distinct((x, y) => x.DT == y.DT).ToList();
            Assert.AreEqual(2, data.Count);
        }
예제 #17
0
        public void DistinctReturnsDistinctValues()
        {
            var data = new List<int> { 5, 6, 6, 5, 4, 1, 2 };
            data = data.Distinct((x, y) => x == y).ToList();

            var targetData = new List<int> { 5, 6, 4, 1, 2 };

            Assert.AreEqual(targetData.Count, data.Count);
            for (int i = 0; i < targetData.Count; i++)
            {
                Assert.AreEqual(targetData[i], data[i]);
            }
        }
        public void CreateSecretSantaPairs_NoDuplicateReceivers()
        {
            List<Person> list1 = new List<Person>()
            {
                new Person("Curtis Thibault", "Email"),
                new Person("Kara Thibault", "Email"),
                new Person("Jake Gamble", "Email"),
                new Person("Jessica Gamble", "Email")
            };
            var pairs = list1.CreatePairs();
            var receivers = pairs.Select(p => p);

            Assert.AreEqual(list1.Distinct().Count(), receivers.Distinct().Count());
        }
예제 #19
0
        public void ExpectedDeckToReturnNDifferentCards(int count)
        {
            var deck = new Deck();
            var cards = new List<Card>();

            for (int card = 0; card < count; card++)
            {
                cards.Add(deck.GetNextCard());
            }

            var comparer = new CardComparer();
            cards = cards.Distinct(comparer).ToList();

            Assert.AreEqual(count, cards.Count);
        }
        public void TestDistinctBoolean()
        {
            var list = new List<DistinctTestClass>
            {
                new DistinctTestClass {Boolean = false},
                new DistinctTestClass {Boolean = false},
                new DistinctTestClass {Boolean = true}
            };

            var results = list.Distinct(l => l.Boolean).ToList();

            Assert.AreEqual(2, results.Count);
            Assert.False(results[0].Boolean);
            Assert.True(results[1].Boolean);
        }
예제 #21
0
        public virtual void Start()
        {
            var assemblyPath = Assembly.GetExecutingAssembly().Location;
            preloader = new Preloader(Path.GetDirectoryName(assemblyPath));
            preloader.Preload();
            CreateTemporaryFolder();

            // Setup Temp PreferenceSetting Location for testing
            PreferenceSettings.DynamoTestPath = Path.Combine(TempFolder, "UserPreferenceTest.xml");

            TestPathResolver pathResolver = null;
            var preloadedLibraries = new List<string>();
            GetLibrariesToPreload(preloadedLibraries);

            if (preloadedLibraries.Any())
            {
                // Only when any library needs preloading will a path resolver be 
                // created, otherwise DynamoModel gets created without preloading 
                // any library.
                // 
                pathResolver = new TestPathResolver();
                foreach (var preloadedLibrary in preloadedLibraries.Distinct())
                {
                    pathResolver.AddPreloadLibraryPath(preloadedLibrary);
                }
            }

            Model = DynamoModel.Start(
                new DynamoModel.DefaultStartConfiguration()
                {
                    StartInTestMode = true,
                    PathResolver = pathResolver,
                    GeometryFactoryPath = preloader.GeometryFactoryPath,
                    ProcessMode = TaskProcessMode.Synchronous
                });

            ViewModel = DynamoViewModel.Start(
                new DynamoViewModel.StartConfiguration()
                {
                    DynamoModel = Model
                });

            //create the view
            View = new DynamoView(ViewModel);
            View.Show();

            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
        }
예제 #22
0
        public void Run_on_separate_thread()
        {
            var frc = new FlowRuntimeConfiguration();
            frc.AddStream(new Stream(".in", "parNop"));
            frc.AddStream(new Stream("parNop", ".out"));

            var cont = new FlowRuntimeConfiguration();

            var asyncThreadIds = new List<long>();
            cont.AddFunc<string, string>("parNop", _ =>
                                                    {
                                                        lock (asyncThreadIds)
                                                        {
                                                            Console.WriteLine("{0} on {1}", _, Thread.CurrentThread.GetHashCode());
                                                            asyncThreadIds.Add(Thread.CurrentThread.GetHashCode());
                                                        }
                                                        Thread.Sleep((DateTime.Now.Millisecond % 100 + 1) * 50);
                                                        return _;
                                                    }).MakeParallel();
            frc.AddOperations(cont.Operations);

            using (var sut = new FlowRuntime(frc, new Schedule_for_async_breadthfirst_processing()))
            {
                const int N = 5;
                var results = new List<IMessage>();
                long runtimeThreadId = 0;
                var are = new AutoResetEvent(false);
                sut.Result += _ =>
                                  {
                                      lock (results)
                                      {
                                          Console.WriteLine("res {0} on {1}", _.Data, Thread.CurrentThread.GetHashCode());
                                          runtimeThreadId = Thread.CurrentThread.GetHashCode();
                                          results.Add(_);
                                          if (results.Count == N) are.Set();
                                      }
                                  };

                for (var i = 0; i < N; i++ )
                    sut.Process(new Message(".in", "x" + i));

                Assert.IsTrue(are.WaitOne(10000));
                Assert.AreEqual(N, results.Count);
                Assert.That(results.Select(r => r.Data.ToString()).ToArray(), Is.EquivalentTo(new[]{"x0", "x1", "x2", "x3", "x4"}));
                Assert.IsFalse(asyncThreadIds.Contains(runtimeThreadId));
                Assert.IsTrue(asyncThreadIds.Distinct().Count() > 1);
            }
        }
예제 #23
0
        public void PickRandomItemShouldReturnRandomItems()
        {
            var itemList = new List<string>();

            for (int i = 0; i < 100; i++)
                itemList.Add("string"+i);

            var results = new List<string>();

            for (int i = 0; i < 100; i++)
                results.Add(Pick<string>.RandomItemFrom(itemList));

            var distinctItems = results.Distinct();

            Assert.That(distinctItems.Count(), Is.GreaterThan(1));
        }
        public void CreateReference_CalledMillionTimes_NoCollisions()
        {
            //arrange
            const int size = 10;
            var referenceGenerator = new CryptographicReferenceGenerator();
            var ids = new List<string>();

            //act
            for (var i = 0; i < 1000000; i++)
            {
                ids.Add(referenceGenerator.CreateReference(size));
            }

            //assert
            var uniqueIds = ids.Distinct();
            uniqueIds.Count().Should().Be(ids.Count);
        }
예제 #25
0
        public void Seed32IsThreadSafe()
        {
            var seed = new Seed32(999);

            var ids = new List<int>();

            Parallel.For(0, 50, delegate(int i)
            {
                ids.Add(seed.Increment());
            });

            Assert.AreEqual(50, ids.Distinct().Count());

            Assert.AreEqual(1050, seed.Increment());

            Assert.AreEqual(1050, seed.LastSeed);
        }
        public void TestDistinctByte()
        {
            var list = new List<DistinctTestClass>
            {
                new DistinctTestClass {Byte = 1},
                new DistinctTestClass {Byte = 1},
                new DistinctTestClass {Byte = 2},
                new DistinctTestClass {Byte = 3},
            };

            var results = list.Distinct(l => l.Byte).ToList();

            Assert.AreEqual(3, results.Count);
            Assert.AreEqual(1, results[0].Byte);
            Assert.AreEqual(2, results[1].Byte);
            Assert.AreEqual(3, results[2].Byte);
        }
        public void TestDistinctChar()
        {
            var list = new List<DistinctTestClass>
            {
                new DistinctTestClass {Char = '1'},
                new DistinctTestClass {Char = '1'},
                new DistinctTestClass {Char = '2'},
                new DistinctTestClass {Char = '3'},
            };

            var results = list.Distinct(l => l.Char).ToList();

            Assert.AreEqual(3, results.Count);
            Assert.AreEqual('1', results[0].Char);
            Assert.AreEqual('2', results[1].Char);
            Assert.AreEqual('3', results[2].Char);
        }
        public void TestDistinctDouble()
        {
            var list = new List<DistinctTestClass>
            {
                new DistinctTestClass {Double = 1.0},
                new DistinctTestClass {Double = 1.0},
                new DistinctTestClass {Double = 2.0},
                new DistinctTestClass {Double = 3.0},
            };

            var results = list.Distinct(l => l.Double).ToList();

            Assert.AreEqual(3, results.Count);
            Assert.AreEqual(1.0, results[0].Double);
            Assert.AreEqual(2.0, results[1].Double);
            Assert.AreEqual(3.0, results[2].Double);
        }
        protected override void StartDynamo(TestSessionConfiguration testConfig)
        {
            var preloader = new Preloader(testConfig.DynamoCorePath, testConfig.RequestedLibraryVersion);
            preloader.Preload();

            var preloadedLibraries = new List<string>();
            GetLibrariesToPreload(preloadedLibraries);

            if (preloadedLibraries.Any())
            {
                if (pathResolver == null)
                    pathResolver = new TestPathResolver();

                var pr = pathResolver as TestPathResolver;
                foreach (var preloadedLibrary in preloadedLibraries.Distinct())
                {
                    pr.AddPreloadLibraryPath(preloadedLibrary);
                }
            }

            Model = DynamoModel.Start(
                new DynamoModel.DefaultStartConfiguration()
                {
                    StartInTestMode = true,
                    PathResolver = pathResolver,
                    GeometryFactoryPath = preloader.GeometryFactoryPath,
                    UpdateManager = this.UpdateManager,
                    ProcessMode = TaskProcessMode.Synchronous
                });

            ViewModel = DynamoViewModel.Start(
                new DynamoViewModel.StartConfiguration()
                {
                    DynamoModel = Model,
                    Watch3DViewModel = HelixWatch3DViewModel.TryCreateHelixWatch3DViewModel(new Watch3DViewModelStartupParams(Model), Model.Logger)
                });

            //create the view
            View = new DynamoView(ViewModel);
            View.Show();

            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
        }
        public void StringExtensionUpdatesHash()
        {
            List<string> hashes = new List<string>();

            for (int i = 0; i < 500; i++)
            {
                string temp = "temp";
                string temp1 = temp.Randomize();
                string temp2 = temp1.Randomize();

                hashes.Add(temp1);
                hashes.Add(temp2);

                Assert.AreEqual(temp1.Substring(0, 23), temp2.Substring(0, 23));
                Assert.AreNotEqual(temp1.Substring(23, 4), temp2.Substring(23, 4), string.Format("temp1:{0} temp2:{1}", temp1, temp2));
            }

            Assert.AreEqual(hashes.Count, hashes.Distinct().Count());
        }