Beispiel #1
0
        #pragma warning disable 1998
        public async Task Broker_Some_Fail ()
        #pragma warning restore 1998
        {
            var succeeded = 0;
            var failed = 0;
            var attempted = 0;

            const int count = 10;
            var failIds = new [] { 3, 5, 7 };

            var broker = new TestServiceBroker ();
            broker.OnNotificationFailed += (notification, exception) =>
                failed++;
            broker.OnNotificationSucceeded += (notification) =>
                succeeded++;

            broker.Start ();
            broker.ChangeScale (1);

            var c = Log.StartCounter ();

            for (int i = 1; i <= count; i++) {
                attempted++;
                broker.QueueNotification (new TestNotification {
                    TestId = i,
                    ShouldFail = failIds.Contains (i)
                });
            }

            broker.Stop ();

            c.StopAndLog ("Test Took {0} ms");

            Assert.AreEqual (attempted - failIds.Length, succeeded);
            Assert.AreEqual (failIds.Length, failed);
        }
        public void Unique_CreationFunctionWithIndex_CreatesUniqueObject()
        {
            IEnumerable<int> current = new[] { 1, 2, 3 };

            Func<int, int> creationFunc = i => i;

            int created = current.CreateUnique(creationFunc);

            Assert.AreEqual(4, created);
            Assert.IsFalse(current.Contains(created));
        }
        public void TestConcurrentAccess() {
            var sourceFiles1 = new[]
                               {
                                   Environment.CurrentDirectory+@"\xyzzy\Example.cs",
                                   Environment.CurrentDirectory+@"\foo\bar\MissingFile.cs",
                                   Environment.CurrentDirectory+@"\zork\Example.cs",
                                   Environment.CurrentDirectory+@"\path\to\file\data.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data1.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data2.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data3.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data4.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data5.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data6.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data7.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data8.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data9.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data10.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data11.c"
                               };
            var sourceFiles2 = new[]
                               {
                                   Environment.CurrentDirectory+@"\foo\bar\Example.cs",
                                   Environment.CurrentDirectory+@"\path\to\file\data.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data1.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data2.cpp",
                                   Environment.CurrentDirectory+@"\foo\bar\ImportantData.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data3.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data4.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data5.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data6.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data7.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data8.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data9.cpp",
                                   Environment.CurrentDirectory+@"\other\dir\Sample.h",
                                   Environment.CurrentDirectory+@"\path\to\file\data10.cpp",
                                   Environment.CurrentDirectory+@"\path\to\file\data11.c"
                               };
            var xmlFiles = new[]
                           {
                               Environment.CurrentDirectory+@"\mappingTest\Example.cs.1.xml",
                               Environment.CurrentDirectory+@"\mappingTest\MissingFile.cs.1.xml",
                               Environment.CurrentDirectory+@"\mappingTest\Example.cs.2.xml",
                               Environment.CurrentDirectory+@"\mappingTest\data.cpp.1.xml",
                               Environment.CurrentDirectory+@"\mappingTest\data1.cpp.1.xml",
                               Environment.CurrentDirectory+@"\mappingTest\data2.cpp.1.xml",
                               Environment.CurrentDirectory+@"\mappingTest\data3.cpp.1.xml",
                               Environment.CurrentDirectory+@"\mappingTest\data4.cpp.1.xml",
                               Environment.CurrentDirectory+@"\mappingTest\data5.cpp.1.xml",
                               Environment.CurrentDirectory+@"\mappingTest\data6.cpp.1.xml",
                               Environment.CurrentDirectory+@"\mappingTest\data7.cpp.1.xml",
                               Environment.CurrentDirectory+@"\mappingTest\data8.cpp.1.xml",
                               Environment.CurrentDirectory+@"\mappingTest\data9.cpp.1.xml",
                               Environment.CurrentDirectory+@"\mappingTest\data10.cpp.1.xml",
                               Environment.CurrentDirectory+@"\mappingTest\data11.c.1.xml",
                               Environment.CurrentDirectory+@"\mappingTest\Example.cs.3.xml",
                               Environment.CurrentDirectory+@"\mappingTest\ImportantData.cpp.1.xml",
                               Environment.CurrentDirectory+@"\mappingTest\Sample.h.1.xml",
                           };

            var map = new SrcMLFileNameMapping("mappingTest");
            var worker = new Thread(() => ConcurrentWorker(map, sourceFiles2));
            worker.Start();
            foreach(var file in sourceFiles1) {
                map.GetTargetPath(file);
            }
            worker.Join(5000);
            map.SaveMapping();

            var obsSourceFiles = new HashSet<string>();
            var obsXmlFiles = new HashSet<string>();
            foreach(var entry in File.ReadAllLines("mappingTest\\mapping.txt")) {
                var fields = entry.Split('|');
                obsSourceFiles.Add(fields[0]);
                obsXmlFiles.Add(fields[1]);
            }
            var sourceFiles = sourceFiles1.Union(sourceFiles2);
            Assert.AreEqual(sourceFiles.Count(), obsSourceFiles.Count);
            Assert.AreEqual(xmlFiles.Count(), obsXmlFiles.Count);
            foreach(var file in obsSourceFiles) {
                Assert.IsTrue(sourceFiles.Contains(file));
            }
            foreach(var file in obsXmlFiles) {
                Assert.IsTrue(xmlFiles.Contains(file));
            }
        }