public void ModelFuncExpressionVisitor_Property() { Expression <Func <Route, bool> > test = r => r.Entry != null && r.Entry.Signal == Signal.GO; var visitor = new ModelFuncExpressionVisitor(); var visited = visitor.Visit(test.Body); Assert.AreEqual(0, visitor.ExtractParameters.Count); ParameterAssertions.AssertOnlyParameters(visited, test.Parameters[0]); }
public void ModelFuncExpressionVisitor_NonModelProperty() { Expression <Func <Route, int> > test = r => r.AbsoluteUri.AbsoluteUri.Length; var visitor = new ModelFuncExpressionVisitor(); var visited = visitor.Visit(test.Body); Assert.AreEqual(0, visitor.ExtractParameters.Count); ParameterAssertions.AssertOnlyParameters(visited, test.Parameters[0]); }
public void ModelFuncExpressionVisitor_ModelMethod() { Expression <Func <Route, bool> > test = r => GetEntry(r) != null && GetEntry(r).Signal == Signal.GO; var visitor = new ModelFuncExpressionVisitor(); var visited = visitor.Visit(test.Body); Assert.AreSame(test.Body, visited); Assert.AreEqual(0, visitor.ExtractParameters.Count); ParameterAssertions.AssertOnlyParameters(visited, test.Parameters[0]); }
public void ModelFuncExpressionVisitor_KeepParameterWhenNeeded() { Expression <Func <TestTuple, bool> > test = t => t.Route.Entry != null && t.Route.Entry.Signal == Signal.GO && t.Severity > 0; var visitor = new ModelFuncExpressionVisitor(); var visited = visitor.Visit(test.Body); Assert.AreNotSame(test.Body, visited); Assert.AreEqual(1, visitor.ExtractParameters.Count); ParameterAssertions.AssertOnlyParameters(visited, test.Parameters[0], visitor.ExtractParameters.Single().Parameter); Assert.AreEqual("t.Route", visitor.ExtractParameters.Single().Value.ToString()); }
public void ModelFuncExpressionVisitor_InnerStruct() { Expression <Func <TestTuple2, bool> > test = t => t.Inner.Route.Entry != null && t.Inner.Route.Entry.Signal == Signal.GO; var visitor = new ModelFuncExpressionVisitor(); var visited = visitor.Visit(test.Body); Assert.AreNotSame(test.Body, visited); Assert.AreEqual(1, visitor.ExtractParameters.Count); ParameterAssertions.AssertOnlyParameters(visited, visitor.ExtractParameters.Single().Parameter); Assert.AreEqual("t.Inner.Route", visitor.ExtractParameters.Single().Value.ToString()); }
public void ModelFuncExpressionVisitor_ModelNonModelMethod() { Expression <Func <TestTuple, bool> > test = t => GetEntry(GetRoute(t)) != null && GetEntry(GetRoute(t)).Signal == Signal.GO; var visitor = new ModelFuncExpressionVisitor(); var visited = visitor.Visit(test.Body); Assert.AreNotSame(visited, test.Body); Assert.AreEqual(1, visitor.ExtractParameters.Count); ParameterAssertions.AssertOnlyParameters(visited, visitor.ExtractParameters.Single().Parameter); Assert.AreEqual("GetRoute(t)", visitor.ExtractParameters.Single().Value.ToString()); }
public void PromotionExpressionVisitor_CheckEntrySemaphore() { Expression <Func <Route, bool> > test = r => r.Entry != null && r.Entry.Signal == Signal.GO; var visitor = new PromotionExpressionVisitor(); var visited = visitor.Visit(test); var collectedParameters = visitor.CollectParameterInfos(); Assert.AreEqual(1, visitor.ExtractParameters.Count); ParameterAssertions.AssertOnlyParameters(visited, visitor.ExtractParameters.Single().Parameter); Assert.AreEqual(1, collectedParameters.Count); Assert.AreEqual("Signal", collectedParameters.Single().Value.Properties.Single()); }
public void PromotionExpressionVisitor_CheckSwitchPositionSensor() { Expression <Func <Route, SwitchPosition, bool> > test = (r, swP) => swP.Switch.Sensor != null && !r.DefinedBy.Contains(swP.Switch.Sensor); var visitor = new PromotionExpressionVisitor(); var visited = visitor.Visit(test); var collectedParameters = visitor.CollectParameterInfos(); Assert.AreEqual(1, visitor.ExtractParameters.Count); ParameterAssertions.AssertOnlyParameters(visited, test.Parameters[0], visitor.ExtractParameters.Single().Parameter); Assert.AreEqual(2, collectedParameters.Count); Assert.AreEqual("DefinedBy", collectedParameters[test.Parameters[0]].Properties.Single()); Assert.AreEqual("Sensor", collectedParameters[visitor.ExtractParameters.Single().Parameter].Properties.Single()); }
public void PromotionExpressionVisitor_CheckSwitchPosition() { Expression <Func <SwitchPosition, bool> > test = swP => swP.Switch.CurrentPosition == swP.Position; var visitor = new PromotionExpressionVisitor(); var visited = visitor.Visit(test); var collectedParameters = visitor.CollectParameterInfos(); Assert.AreEqual(1, visitor.ExtractParameters.Count); ParameterAssertions.AssertOnlyParameters(visited, test.Parameters[0], visitor.ExtractParameters.Single().Parameter); Assert.AreEqual(2, collectedParameters.Count); Assert.AreEqual("Position", collectedParameters[test.Parameters.Single()].Properties.Single()); Assert.AreEqual("CurrentPosition", collectedParameters[visitor.ExtractParameters.Single().Parameter].Properties.Single()); }