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); }
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"); }
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); }
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(); }
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); }
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(); }
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); }
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)); }
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); }
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")); } }
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(); }
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)); }
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); }
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); }
private void AnalyzerOnFailed(RouteAnalyzer sender, string reason) { _sniffer?.Logger?.Log?.Info($"{RouteAnalyerLabel} failed: {reason}"); }
public void ProcessTestCircularDependencyCheck() { var analyzer = new RouteAnalyzer(); var result = analyzer.Process(new string[] { "1 -> 2", "2 -> 3", "3 -> 1" }).ToList(); }
public DemoTests(ServerFixture <Startup> testFixture) { _testFixure = testFixture; _routeAnalyzer = _testFixure.GetService <RouteAnalyzer>(); _randomService = _testFixure.GetService <RandomService>(); }
private void AnalyzerOnStarted(RouteAnalyzer sender) { _sniffer?.Logger?.Log?.Info($"{RouteAnalyerLabel} started"); }
public void ProcessTestInvalidRouteScenario2() { var analyzer = new RouteAnalyzer(); var result = analyzer.Process(new string[] { "1 -> 2", "2", "2 -> 3" }).ToList(); }
private void AnalyzerOnFailedEx(RouteAnalyzer sender, Exception reason) { _sniffer?.Logger?.Log?.Info($"{RouteAnalyerLabel} failed: {reason.Message}"); }