public RouteAction Handle(ICall call) { call.AssignSequenceNumber(_generator.Next()); _callCollection.Add(call); return(RouteAction.Continue()); }
public RouteAction Handle(ICall call) { var methodInfo = call.GetMethodInfo(); var eventInfo = FindEventInfo(methodInfo); if (eventInfo == null) { throw new CouldNotRaiseEventException(); } object?[] eventArguments = _getEventArguments(call); var handlers = _eventHandlerRegistry.GetHandlers(eventInfo.Name); foreach (Delegate handler in handlers) { try { handler.DynamicInvoke(eventArguments); } catch (TargetInvocationException e) { throw e.InnerException !; } } return(RouteAction.Continue());
internal static void GetRouteParameters(RouteAction action, out string actionVerb, out string lowRest, bool isLowRest = true) { lowRest = string.Empty; actionVerb = "get"; switch (action) { case RouteAction.SHOW: case RouteAction.LIST: break; case RouteAction.UPDATE: actionVerb = "update"; if (isLowRest) { lowRest = "_lowrest"; } break; case RouteAction.DELETE: actionVerb = "delete"; if (isLowRest) { lowRest = "_lowrest"; } break; case RouteAction.CREATE: actionVerb = "create"; break; case RouteAction.SEARCH: actionVerb = "search"; break; } }
public RouteAction Handle(ICall call) { var callSpec = _callSpecificationFactory.CreateFrom(call, _matchArgs); _exclusions.Exclude(callSpec); return(RouteAction.Continue()); }
public bool TryGetValue(string localPath, out RouteAction handler, out Dictionary <string, string> data) { handler = null; data = null; if (_pathParser == null) { _pathParser = RebuildParser(); } var match = _pathParser.Match(KeyBase + localPath); if (match.Success) { string routeKey = null; for (int idx = 1; idx <= KeyBase.Length; idx++) { routeKey += match.Groups[$"__c{idx}__"].Value; } var entry = _routes[routeKey]; handler = entry.Handler; if (entry.GroupStart < entry.GroupEnd) { data = new Dictionary <string, string>(); } for (var groupIdx = entry.GroupStart; groupIdx < entry.GroupEnd; groupIdx++) { data[_groupNames[groupIdx]] = match.Groups[groupIdx].Value; } } return(match.Success); }
public void Updated_ref_parameter_doesnt_affect_call_specification() { //arrange var source = Substitute.For <IValueSource>(); var router = SubstitutionContext.Current.GetCallRouterFor(source); //Configure our handler to update "ref" argument value router.RegisterCustomCallHandlerFactory(state => new ActionHandler( call => { if (call.GetMethodInfo().Name != nameof(IValueSource.GetValueWithRef)) { return(RouteAction.Continue()); } var args = call.GetArguments(); args[0] = "refArg"; return(RouteAction.Return("xxx")); })); string refValue = "ref"; source.GetValueWithRef(ref refValue).Returns("42"); //act refValue = "ref"; var result = source.GetValueWithRef(ref refValue); //assert Assert.That(result, Is.EqualTo("42")); }
private static string GetHttpVerb(RouteAction action) { HttpVerbs verb = HttpVerbs.Get; switch (action) { case RouteAction.CREATE: verb = HttpVerbs.Post; break; case RouteAction.UPDATE: verb = HttpVerbs.Put; break; case RouteAction.DELETE: verb = HttpVerbs.Delete; break; case RouteAction.LIST: case RouteAction.SHOW: case RouteAction.SEARCH: verb = HttpVerbs.Get; break; default: verb = HttpVerbs.Get; break; } return(verb.ToString()); }
public static void LogFailure(GameObject routingObject, RouteAction.FailureExplanation explanation, RoutePlanResult planResult, string errorText) { RoutingComponent.mnNumDoRouteFailures += (ulong)0x1L; if (RoutingComponent.mbLogFailures) { Common.StringBuilder msg = new Common.StringBuilder("Explanation: " + explanation); msg += Common.NewLine + "Result: " + planResult; msg += Common.NewLine + "Error: " + errorText; if (routingObject.LotCurrent != null) { msg += Common.NewLine + "Address A: " + routingObject.LotCurrent.Address; } Sim sim = routingObject as Sim; if (sim != null) { InteractionInstance currentInteraction = sim.CurrentInteraction; InteractionInstance nextInteraction = sim.InteractionQueue.GetNextInteraction(); if (((currentInteraction != null) && (currentInteraction.Target != null)) && (currentInteraction.Target.LotCurrent != null)) { msg += Common.NewLine + "Address B: " + currentInteraction.Target.LotCurrent.Address; } if (((nextInteraction != null) && (nextInteraction.Target != null)) && (nextInteraction.Target.LotCurrent != null)) { msg += Common.NewLine + "Address C: " + nextInteraction.Target.LotCurrent.Address; } } Common.DebugNotify(msg, sim); } }
//internal static string GetRoute(string resourceName, RouteAction action, bool isLowRest = true) { // Route route = RouteConfig.RouteNameToRoute[FindRouteName(resourceName, action, isLowRest)] as Route; // if (route != null) { // return route.Url; // } // return null; //} public static string GetRoute <T>(T resource, RouteAction action, bool isLowRest = true) where T : BaseContract { Type resourceType = typeof(T); string resourceName = resourceType.Name; int index = resourceName.LastIndexOf("."); if (index > 0) { resourceName = resourceName.Substring(index + 1); } string routeName = FindRouteName(resourceName, action, isLowRest); string uri = null; Route route = RouteConfiguration.RouteNameToRoute[routeName] as Route; if (route != null) { uri = route.Url; } else { return(null); } uri = uri.Replace("{controller}", resourceName); // Replace the {id} with the id of the resource // uri = ReplaceID(resource, uri, "{id}"); //if (resource.id.HasValue && resource.id.Value > 0) //{ // uri = uri.Replace("{id}", resource.id.ToString()); //} uri = ReplaceID(resource, uri, "{" + resourceName + "Id" + "}"); return(uri); }
public RouteAction Handle(ICall call) { var mockedDbContext = call.Target(); var invokedMethod = call.GetMethodInfo(); var arguments = call.GetArguments(); var modelType = GetModelType(invokedMethod); if (modelType == null) { return(RouteAction.Return(invokedMethod.ReturnType.GetDefaultValue())); } Logger.LogDebug("Setting up model '{type}'", modelType); var modelEntityType = _allModelEntityTypes.SingleOrDefault(x => x.ClrType.Equals(modelType)); if (modelEntityType == null) { throw new InvalidOperationException(string.Format(ExceptionMessages.CannotCreateDbSetTypeNotIncludedInModel, invokedMethod.GetGenericArguments().Single().Name)); } var setUpModelMethod = typeof(NoSetUpHandler <TDbContext>).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic) .Single(x => x.Name.Equals(modelEntityType.FindPrimaryKey() != null ? "SetUpModel" : "SetUpReadOnlyModel")); setUpModelMethod.MakeGenericMethod(modelType).Invoke(this, new[] { mockedDbContext }); return(RouteAction.Return(invokedMethod.Invoke(mockedDbContext, arguments?.ToArray()))); }
public RouteAction Handle(ICall call) { var methodInfo = call.GetMethodInfo(); var eventInfo = methodInfo.DeclaringType.GetEvents().FirstOrDefault( x => (x.GetAddMethod() == methodInfo) || (x.GetRemoveMethod() == methodInfo)); if (eventInfo == null) { throw new CouldNotRaiseEventException(); } var handlers = _eventHandlerRegistry.GetHandlers(eventInfo.Name); var eventArguments = _getEventArguments(call); foreach (Delegate handler in handlers) { try { handler.DynamicInvoke(eventArguments); } catch (TargetInvocationException e) { throw e.InnerException; } } return(RouteAction.Continue()); }
private void LoadControlers(Assembly ass) { foreach (var t in ass.GetTypes()) { if (t.IsSubclassOf(typeof(Controller))) { var length = t.Name.LastIndexOf("controller", StringComparison.OrdinalIgnoreCase); if (length == -1) { continue; } string controllerPrefix = t.Name.Substring(0, length); MethodInfo[] methods = t.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); foreach (var m in methods) { var key = string.Concat(controllerPrefix, "/", m.Name); var routeInfo = new RouteAction() { ControllerType = t.GetType(), CurrentMethod = m, RequestUri = key, OutArgumentType = m.ReturnType }; if (m.GetParameters().Length != 0) { routeInfo.InArgumentType = m.GetParameters()[0].ParameterType; } Mapper.Add(key, routeInfo); } } } }
public void SelectAction(Customer customer) { switch (customer.MessageText) { case "/start": StartMenuAction.Go(customer); break; case "Контакты": ContactMenuAction.Go(customer); break; case "Информация": InformationMenuAction.Go(customer); break; case "Показать курсы НБУ": ExchangeRatesMenuAction.Go(customer); break; case "Рассчитать стоимость растаможки": CalculateTaxMenuAction.Go(customer); break; case "Рассчитать стоимость растаможки евробляхи": CalculateTaxEuroMenuAction.Go(customer); break; default: RouteAction.Go(customer); break; } }
public RouteAction Handle(ICall call) { var callSpec = _callSpecificationFactory.CreateFrom(call, _matchArgs); _callActions.Add(callSpec, _action); return(RouteAction.Continue()); }
public RouteAction Handle(ICall call) { var target = call.Target(); var callSpec = _callSpecificationFactory.CreateFrom(call, MatchArgs.AsSpecifiedInCall); _context.AddToQuery(target, callSpec); return(RouteAction.Continue()); }
public static string GetChildResourceName(string childResourceName, RouteAction act) { if (act == RouteAction.LIST) { childResourceName = Pluralize(childResourceName); } return(childResourceName); }
public RouteAction Handle(ICall call) { var callSpec = _callSpecificationFactory.CreateFrom(call, MatchArgs.AsSpecifiedInCall); _pendingCallSpecification.SetCallSpecification(callSpec); _callActions.Add(callSpec); return(RouteAction.Continue()); }
public RouteAction Handle(ICall call) { if (_callResults.HasResultFor(call)) { return(RouteAction.Return(_callResults.GetResult(call))); } return(RouteAction.Continue()); }
/// <summary> /// Checks the last method invocation on the mock; /// if Add was invoked the unexpected match is set up; /// if GetOrAdd or GetOrAddAsync was invoked the unexpected match is set up and the addItemFactory result will be /// returned; /// otherwise the default value for the specified type will be returned. /// </summary> /// <param name="call"></param> /// <returns> /// if GetOrAdd or GetOrAddAsync was invoked the unexpected match is set up and the addItemFactory result will be /// returned; /// otherwise the default value for the specified type will be returned if the last method invocation has a return /// type. /// </returns> public RouteAction Handle(ICall call) { Logger.LogDebug("NoSetUpHandler invoked"); var methodInfo = call.GetMethodInfo(); var args = call.GetArguments(); if (methodInfo.Name.Equals("Add")) { //We have everything we need to set up a match, so let's do it var key = args[0].ToString(); var value = args[1]; ProjectReflectionShortcuts.SetUpCacheEntryMethod(value.GetType()).Invoke(null, new[] { _mockedCachingService, key, value }); return(RouteAction.Return(null)); } if (methodInfo.Name.Equals("GetOrAdd")) { //We have everything we need to set up a match, so let's do it var key = args[0].ToString(); var value = args[1].GetType().GetMethod("Invoke").Invoke(args[1], new object[] { new CacheEntryFake(key) }); ProjectReflectionShortcuts.SetUpCacheEntryMethod(value.GetType()).Invoke(null, new[] { _mockedCachingService, key, value }); return(RouteAction.Return(value)); } if (methodInfo.Name.Equals("GetOrAddAsync")) { //We have everything we need to set up a match, so let's do it var key = args[0].ToString(); var task = args[1].GetType().GetMethod("Invoke").Invoke(args[1], new object[] { new CacheEntryFake(key) }); var taskResult = task.GetType().GetProperty("Result").GetValue(task); ProjectReflectionShortcuts.SetUpCacheEntryMethod(taskResult.GetType()).Invoke(null, new[] { _mockedCachingService, key, taskResult }); return(RouteAction.Return(task)); } //void method if (methodInfo.ReturnType == typeof(void)) { return(RouteAction.Return(null)); } //Return default values if (methodInfo.ReturnType.IsGenericType && methodInfo.ReturnType.GetGenericTypeDefinition() == typeof(Task <>)) { var genericArgument = methodInfo.ReturnType.GetGenericArguments().Single(); var defaultValue = genericArgument.GetDefaultValue(); return(RouteAction.Return(CoreReflectionShortcuts.TaskFromResultMethod(genericArgument).Invoke(null, new[] { defaultValue }))); } return(RouteAction.Return(methodInfo.ReturnType.GetDefaultValue())); }
public RouteAction Handle(ICall call) { if (_callResults.TryGetResult(call, out var configuredResult)) { return(RouteAction.Return(configuredResult)); } return(RouteAction.Continue()); }
public void the_new_route_should_be_returned() { var route = MailgunClientBuilder.GetClient().CreateRoute(1, "catch all that does nothing test" + " for mailgun", RouteFilter.CatchAll(), RouteAction.Stop()); route.Should().NotBeNull(); route.Id.Should().NotBeEmpty(); }
RouteAction ICallHandler.Handle(ICall call) { if (!this.HasResultFor(call)) { this.action(); } return(RouteAction.Continue()); }
public RouteAction Handle(ICall call) { if (_resultsForType.TryGetResult(call, out var result)) { return(RouteAction.Return(result)); } return(RouteAction.Continue()); }
private Func <IAutoValueProvider, RouteAction> ReturnValueUsingProvider(ICall call, Type type) { return(provider => { var valueToReturn = provider.GetValue(type); ConfigureCall.SetResultForCall(call, new ReturnValue(valueToReturn), MatchArgs.AsSpecifiedInCall); return RouteAction.Return(valueToReturn); }); }
void RouteChatMessageToLocalUser(RouteAction action, SquiggleEndPoint sender, SquiggleEndPoint recipient) { ExceptionMonster.EatTheException(() => { sender = new SquiggleEndPoint(sender.ClientID, bridgeEndPointInternal); IPEndPoint endpoint = routeTable.GetLocalChatEndPoint(recipient.ClientID); action(true, endpoint, sender, new SquiggleEndPoint(recipient.ClientID, endpoint)); }, "routing chat message to local user"); }
public void the_new_route_should_be_returned() { var route = MailgunClientBuilder.GetClient().CreateRoute(1, "catch all that does nothing test for mnailgun", RouteFilter.CatchAll(), RouteAction.InvokeWebHook(new Uri("http://foobar.com/messages")), RouteAction.Stop()); route.Should().NotBeNull(); route.Id.Should().NotBeEmpty(); }
public RouteAction Handle(ICall call) { if (CanBeSubscribeUnsubscribeCall(call)) { If(call, IsEventSubscription, _eventHandlerRegistry.Add); If(call, IsEventUnsubscription, _eventHandlerRegistry.Remove); } return(RouteAction.Continue()); }
public void the_new_route_should_be_deleted() { var client = MailgunClientBuilder.GetClient(); var route = client.CreateRoute(1, "catch all that does nothing test for mnailgun", RouteFilter.CatchAll(), RouteAction.Stop()); var result = client.DeleteRoute(route.Id); result.Should().NotBeNull(); }
public RouteAction Handle(ICall call) { if (_propertyHelper.IsCallToSetAReadWriteProperty(call)) { var callToPropertyGetter = _propertyHelper.CreateCallToPropertyGetterFromSetterCall(call); var valueBeingSetOnProperty = call.GetArguments().Last(); _resultSetter.SetResultForCall(callToPropertyGetter, new ReturnValue(valueBeingSetOnProperty), MatchArgs.AsSpecifiedInCall); } return(RouteAction.Continue()); }
public override void Context() { _call = mock <ICall>(); _firstHandler = mock <ICallHandler>(); _firstHandler.stub(x => x.Handle(_call)).Return(RouteAction.Continue()); _secondHandler = mock <ICallHandler>(); _secondHandler.stub(x => x.Handle(_call)).Return(RouteAction.Return(_valueToReturn)); _handlers = new[] { _firstHandler, _secondHandler }; }
public static string FindRouteName(string resourceName, RouteAction action, bool isLowRest = true) { string resourceRouteName = GetRouteName(resourceName, action, isLowRest); if (!RouteConfiguration.RouteNameToRoute.ContainsKey(resourceRouteName)) { resourceRouteName = GetRouteName(RouteNames.DefaultResource, action, isLowRest); } return(resourceRouteName); }
/// <summary> /// Pendent /// </summary> public void AddFirst(IRoutingRule rule, RouteAction action) { AddFirst(new DecoratedRule(rule, action)); }
public DecoratedRule(IRoutingRule inner, RouteAction selectionAction) : this(inner) { this.selectionAction = selectionAction; }