Ejemplo n.º 1
0
        public void Process_DifferentInputOrders_ReturnSameResult()
        {
            var input = new string[]
            {
                "/start -> /second",
                "/a -> /b",
                "/b -> /c",
                "/second -> /another",
                "/about"
            };

            var analyzer       = new RouteAnalyzer();
            var result         = analyzer.Process(input).ToList();
            var reversedResult = analyzer.Process(input.Reverse()).ToList();

            var expected = new[]
            {
                "/start -> /second -> /another",
                "/a -> /b -> /c",
                "/about"
            };

            CollectionAssert.AreEquivalent(expected, result);
            CollectionAssert.AreEquivalent(expected, reversedResult);
        }
Ejemplo n.º 2
0
        public void ProcessTestHappyPathScenario1()
        {
            var analyzer = new RouteAnalyzer();
            var result   = analyzer.Process(new string[] { "1 -> 2", "2 -> 3", "3 -> 4" }).ToList();

            Assert.IsTrue(result.Count() == 1);
            Assert.AreEqual(result[0], "1 -> 2 -> 3 -> 4");
        }
Ejemplo n.º 3
0
        public void ProcessTestHappyPathScenario3()
        {
            var analyzer = new RouteAnalyzer();
            var result   = analyzer.Process(new string[] { "8 -> 9", "1 -> 3", "3 -> 4", "2 -> 3", "6 -> 7" }).ToList();

            Assert.IsTrue(result.Count() == 4);
            Assert.AreEqual(result[0], "8 -> 9");
            Assert.AreEqual(result[1], "1 -> 3 -> 4");
            Assert.AreEqual(result[2], "2 -> 3 -> 4");
            Assert.AreEqual(result[3], "6 -> 7");
        }
        public void TestRouteParser()
        {
            RouteAnalyzer routeAnalyzer = new RouteAnalyzer();

            sourceCode = sourceCode.Replace("\"", "");
            var tree = CSharpSyntaxTree.ParseText(sourceCode);

            routeAnalyzer.Visit(tree.GetRoot());

            var routeList = routeAnalyzer.routeList;

            Assert.Equal(2, routeList.Count);
        }
Ejemplo n.º 5
0
        public void OverwroteRoute_NodeUnReachable()
        {
            var sampleInput = new List <string>()
            {
                "/our-ceo.html -> /about-us.html",
                "/about-us.html -> /about",
                "/about-us.html -> //about-us"
            };

            var output = new RouteAnalyzer().Process(sampleInput);

            Assert.Fail();
        }
Ejemplo n.º 6
0
        private void AnalyzerOnFinished(RouteAnalyzer sender)
        {
            _sniffer?.Logger?.Log?.Info($"{RouteAnalyerLabel} finished");

            lock (_metadataLock)
            {
                _metadata.LoadRoutes(Globals.GetCfgDataPath("Routes"));
            }

            SendModelToClients(ModelType.UpdateRoutes);
            SendModelToClients(ModelType.UpdateOcc);
            SendModelToClients(ModelType.UpdateFeedbacks);
        }
Ejemplo n.º 7
0
        public void CircularRefNoRoot()
        {
            var sampleInput = new List <string>()
            {
                "/our-ceo.html -> /about-us.html",
                "/about-us.html -> /about",
                "/about -> /our-ceo.html"
            };

            var output = new RouteAnalyzer().Process(sampleInput);

            Assert.Fail();
        }
Ejemplo n.º 8
0
        private async void InitializeRouteAnalyzerHandler()
        {
            var analyzer = new RouteAnalyzer(this);

            analyzer.Started  += AnalyzerOnStarted;
            analyzer.Finished += AnalyzerOnFinished;
            analyzer.Failed   += AnalyzerOnFailed;
            analyzer.FailedEx += AnalyzerOnFailedEx;
            analyzer.Progress += AnalyzerOnProgress;

            var metamodelFilePath = Globals.GetCfgDataPath("Metamodel");
            var routeFilePath     = Globals.GetCfgDataPath("Routes");
            await analyzer.Start(metamodelFilePath, routeFilePath);
        }
Ejemplo n.º 9
0
        public void RedirectToSelf()
        {
            var sampleInput = new List <string>()
            {
                "/home -> /home"
            };

            var output   = new RouteAnalyzer().Process(sampleInput);
            var expected = new List <string>()
            {
                "/home"
            };

            Assert.IsTrue(output.SequenceEqual(expected));
        }
Ejemplo n.º 10
0
        public void Process_LongRedirectChain_ConsolidatesToSingleResult()
        {
            var input = new string[]
            {
                "/home",
                "/one.html -> /two.html",
                "/two.html -> /three.html",
                "/three.html -> /home"
            };

            var analyzer = new RouteAnalyzer();
            var result   = analyzer.Process(input).ToList();

            var expected = new[] { "/one.html -> /two.html -> /three.html -> /home" };

            CollectionAssert.AreEquivalent(expected, result);
        }
Ejemplo n.º 11
0
        public void Process_SingleCircularRedirectPath_ThrowsExceptionWithMessage()
        {
            var failureInput = new string[]
            {
                "/about-us.html -> /about",
                "/about -> /about-us.html"
            };
            var analyzer = new RouteAnalyzer();

            try
            {
                var result = analyzer.Process(failureInput).ToList();
                Assert.Fail("Expected to throw");
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.Message.Contains("Circular route found"));
            }
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            var input = new List <string>
            {
                "/home",
                "/one.html -> /two.html",
                "/two.html -> /three.html",
                "/three.html -> /home"
            };

            var analyzer = new RouteAnalyzer();

            Console.WriteLine("Processing...");
            input.ForEach(Console.WriteLine);
            var results = analyzer.Process(input).ToList();

            Console.WriteLine("Resulting paths:");
            results.ForEach(Console.WriteLine);
            Console.ReadLine();
        }
Ejemplo n.º 13
0
        public void SimpleRedirects()
        {
            var sampleInput = new List <string>()
            {
                "/home",
                "/our-ceo.html -> /about-us.html",
                "/about-us.html -> /about",
                "/product-1.html -> /seo"
            };

            var output   = new RouteAnalyzer().Process(sampleInput);
            var expected = new List <string>()
            {
                "/home",
                "/our-ceo.html -> /about-us.html -> /about",
                "/product-1.html -> /seo"
            };

            Assert.IsTrue(output.SequenceEqual(expected));
        }
Ejemplo n.º 14
0
        public void Process_MultipleEntryPointsRedirectToSameDestination_ReturnsBothResults()
        {
            var input = new string[]
            {
                "/a.html -> /home",
                "/b.html -> /home",
                "/c.html -> /home"
            };

            var analyzer = new RouteAnalyzer();
            var result   = analyzer.Process(input).ToList();

            var expected = new[]
            {
                "/a.html -> /home",
                "/b.html -> /home",
                "/c.html -> /home"
            };

            CollectionAssert.AreEquivalent(expected, result);
        }
Ejemplo n.º 15
0
        public void Process_SampleInput_MatchesOutput()
        {
            var input = new string[]
            {
                "/home",
                "/our-ceo.html -> /about-us.html",
                "/about-us.html -> /about",
                "/product-1.html -> /seo"
            };
            var analyzer = new RouteAnalyzer();
            var result   = analyzer.Process(input).ToList();

            var expected = new[]
            {
                "/home",
                "/product-1.html -> /seo",
                "/our-ceo.html -> /about-us.html -> /about",
            };

            CollectionAssert.AreEquivalent(expected, result);
        }
Ejemplo n.º 16
0
 private void AnalyzerOnFailed(RouteAnalyzer sender, string reason)
 {
     _sniffer?.Logger?.Log?.Info($"{RouteAnalyerLabel} failed: {reason}");
 }
Ejemplo n.º 17
0
 public void ProcessTestCircularDependencyCheck()
 {
     var analyzer = new RouteAnalyzer();
     var result   = analyzer.Process(new string[] { "1 -> 2", "2 -> 3", "3 -> 1" }).ToList();
 }
Ejemplo n.º 18
0
 public DemoTests(ServerFixture <Startup> testFixture)
 {
     _testFixure    = testFixture;
     _routeAnalyzer = _testFixure.GetService <RouteAnalyzer>();
     _randomService = _testFixure.GetService <RandomService>();
 }
Ejemplo n.º 19
0
 private void AnalyzerOnStarted(RouteAnalyzer sender)
 {
     _sniffer?.Logger?.Log?.Info($"{RouteAnalyerLabel} started");
 }
Ejemplo n.º 20
0
 public void ProcessTestInvalidRouteScenario2()
 {
     var analyzer = new RouteAnalyzer();
     var result   = analyzer.Process(new string[] { "1 -> 2", "2", "2 -> 3" }).ToList();
 }
Ejemplo n.º 21
0
 private void AnalyzerOnFailedEx(RouteAnalyzer sender, Exception reason)
 {
     _sniffer?.Logger?.Log?.Info($"{RouteAnalyerLabel} failed: {reason.Message}");
 }