public void BadEggValidationInvalidRequestDelegate() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); TestHttpRequest httpRequest = new TestHttpRequest(); TestHttpResponse httpResponse = new TestHttpResponse(); IPluginClassesService pluginServices = new pm.PluginServices(_testPluginBadEgg) as IPluginClassesService; IPluginHelperService pluginHelperServices = _testPluginBadEgg.GetRequiredService <IPluginHelperService>(); IPluginTypesService pluginTypesService = _testPluginBadEgg.GetRequiredService <IPluginTypesService>(); INotificationService notificationService = _testPluginBadEgg.GetRequiredService <INotificationService>(); IIpValidation iPValidation = new TestIPValidation(); TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse); httpRequest.SetContext(httpContext); MockLoginProvider loginProvider = new MockLoginProvider(); MockClaimsProvider claimsProvider = new MockClaimsProvider(pluginServices); TestAuthenticationService authenticationService = new TestAuthenticationService(); ActionDescriptorCollection actionDescriptorCollection = new ActionDescriptorCollection(new List <ActionDescriptor>(), 1); TestActionDescriptorCollectionProvider testActionDescriptorCollectionProvider = new TestActionDescriptorCollectionProvider(actionDescriptorCollection); RouteDataServices routeDataServices = new RouteDataServices(); BadEggMiddleware badEgg = new BadEggMiddleware(null, testActionDescriptorCollectionProvider, routeDataServices, pluginHelperServices, pluginTypesService, iPValidation, settingsProvider, notificationService); }
public async Task BadEggValidationSuccess() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); TestHttpRequest httpRequest = new TestHttpRequest(); TestHttpResponse httpResponse = new TestHttpResponse(); IPluginClassesService pluginServices = new pm.PluginServices(_testPluginBadEgg) as IPluginClassesService; IPluginHelperService pluginHelperServices = _testPluginBadEgg.GetRequiredService <IPluginHelperService>(); IPluginTypesService pluginTypesService = _testPluginBadEgg.GetRequiredService <IPluginTypesService>(); INotificationService notificationService = _testPluginBadEgg.GetRequiredService <INotificationService>(); IIpValidation iPValidation = new TestIPValidation(); TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse); httpRequest.SetContext(httpContext); MockLoginProvider loginProvider = new MockLoginProvider(); MockClaimsProvider claimsProvider = new MockClaimsProvider(pluginServices); TestAuthenticationService authenticationService = new TestAuthenticationService(); bool nextDelegateCalled = false; RequestDelegate requestDelegate = async(context) => { nextDelegateCalled = true; await Task.Delay(0); }; ActionDescriptorCollection actionDescriptorCollection = new ActionDescriptorCollection(new List <ActionDescriptor>(), 1); TestActionDescriptorCollectionProvider testActionDescriptorCollectionProvider = new TestActionDescriptorCollectionProvider(actionDescriptorCollection); RouteDataServices routeDataServices = new RouteDataServices(); BadEggMiddleware badEgg = new BadEggMiddleware(requestDelegate, testActionDescriptorCollectionProvider, routeDataServices, pluginHelperServices, pluginTypesService, iPValidation, settingsProvider, notificationService); await badEgg.Invoke(httpContext); Assert.IsTrue(nextDelegateCalled); }
private static IServiceProvider CreateServices(params ActionDescriptor[] actions) { var collection = new ActionDescriptorCollection(actions, version: 0); var actionDescriptorProvider = new Mock <IActionDescriptorCollectionProvider>(); actionDescriptorProvider .Setup(a => a.ActionDescriptors) .Returns(collection); var routeOptions = new Mock <IOptions <RouteOptions> >(); routeOptions .SetupGet(o => o.Value) .Returns(new RouteOptions()); #pragma warning disable CS0618 // Type or member is obsolete var inlineConstraintResolver = new DefaultInlineConstraintResolver(routeOptions.Object); #pragma warning restore CS0618 // Type or member is obsolete var services = new ServiceCollection() .AddSingleton <IInlineConstraintResolver>(inlineConstraintResolver); services.AddRouting(); services.AddOptions(); services.AddLogging(); return(services.AddSingleton(actionDescriptorProvider.Object) .AddSingleton <ILoggerFactory>(NullLoggerFactory.Instance) .BuildServiceProvider()); }
public void GivenTwoMethodsWithTheSameNameAndDifferentAuditEvents_WhenMappingIsCreated_ThenDuplicateActionForAuditEventExceptionShouldBeThrown() { Type mockControllerType = typeof(MockController); var actionDescriptors = new List <ActionDescriptor>() { new ControllerActionDescriptor() { ControllerName = ControllerName, ActionName = SameNameMethodName, MethodInfo = mockControllerType.GetMethod(SameNameMethodName, new Type[] { typeof(int) }), }, new ControllerActionDescriptor() { ControllerName = ControllerName, ActionName = SameNameMethodName, MethodInfo = mockControllerType.GetMethod(SameNameMethodName, new Type[] { typeof(string) }), }, }; var actionDescriptorCollection = new ActionDescriptorCollection(actionDescriptors, 1); _actionDescriptorCollectionProvider.ActionDescriptors.Returns(actionDescriptorCollection); var eventTypeMapping = new AuditEventTypeMapping(_actionDescriptorCollectionProvider); Assert.ThrowsAsync <DuplicateActionForAuditEventException>(() => ((IHostedService)eventTypeMapping).StartAsync(CancellationToken.None)); }
// internal for testing internal void AddEntries(TreeRouteBuilder builder, ActionDescriptorCollection actions) { var routeInfos = GetRouteInfos(actions.Items); // We're creating one TreeRouteLinkGenerationEntry per action. This allows us to match the intended // action by expected route values, and then use the TemplateBinder to generate the link. foreach (var routeInfo in routeInfos) { if (routeInfo.SuppressLinkGeneration) { continue; } var defaults = new RouteValueDictionary(); foreach (var kvp in routeInfo.ActionDescriptor.RouteValues) { defaults.Add(kvp.Key, kvp.Value); } try { // We use the `NullRouter` as the route handler because we don't need to do anything for link // generations. The TreeRouter does it all for us. builder.MapOutbound( NullRouter.Instance, routeInfo.RouteTemplate, defaults, routeInfo.RouteName, routeInfo.Order); } catch (RouteCreationException routeCreationException) { throw new RouteCreationException( "An error occurred while adding a route to the route builder. " + $"Route name '{routeInfo.RouteName}' and template '{routeInfo.RouteTemplate!.TemplateText}'.", routeCreationException); } } // We're creating one AttributeRouteMatchingEntry per group, so we need to identify the distinct set of // groups. It's guaranteed that all members of the group have the same template and precedence, // so we only need to hang on to a single instance of the RouteInfo for each group. var groups = GetInboundRouteGroups(routeInfos); foreach (var group in groups) { var handler = _handlerFactory(group.ToArray()); // Note that because we only support 'inline' defaults, each routeInfo group also has the same // set of defaults. // // We then inject the route group as a default for the matcher so it gets passed back to MVC // for use in action selection. builder.MapInbound( handler, group.Key.RouteTemplate, group.Key.RouteName, group.Key.Order); } }
public AuditEventTypeMappingTests() { Type mockControllerType = typeof(MockController); var actionDescriptors = new List <ActionDescriptor>() { new ControllerActionDescriptor() { ControllerName = ControllerName, ActionName = AnonymousMethodName, MethodInfo = mockControllerType.GetMethod(AnonymousMethodName), }, new ControllerActionDescriptor() { ControllerName = ControllerName, ActionName = AudittedMethodName, MethodInfo = mockControllerType.GetMethod(AudittedMethodName), }, new ControllerActionDescriptor() { ControllerName = ControllerName, ActionName = NoAttributeMethodName, MethodInfo = mockControllerType.GetMethod(NoAttributeMethodName), }, new PageActionDescriptor() { }, }; var actionDescriptorCollection = new ActionDescriptorCollection(actionDescriptors, 1); _actionDescriptorCollectionProvider.ActionDescriptors.Returns(actionDescriptorCollection); _auditEventTypeMapping = new AuditEventTypeMapping(_actionDescriptorCollectionProvider); }
public OeRouter(IActionInvokerFactory actionInvokerFactory, IActionDescriptorCollectionProvider actionDescriptorCollectionProvider, IEdmModel edmModel) { _actionInvokerFactory = actionInvokerFactory; _actionDescriptors = actionDescriptorCollectionProvider.ActionDescriptors; _edmModel = edmModel; }
public void RouteAsyncLoadsRouteContextOntoRouteData() { var request = new HttpRequestFeature(); SetupRequestBody(request, "{\"method\": \"GET\"}"); var context = new RouteContext(this.PrepareDefaultHttpContext(request)); RouteContext callback = null; this.inner.Setup(i => i.RouteAsync(It.IsAny <RouteContext>())) .Callback <RouteContext>((r) => { callback = r; }) .Returns(Task.FromResult(0)); var desciptors = new ActionDescriptorCollection(new List <ControllerActionDescriptor> { new ControllerActionDescriptor { ActionName = "GET", ControllerName = "RPCController" } }, 1); this.actionDescriptor.Setup(a => a.ActionDescriptors) .Returns(desciptors); Task task = this.handler.RouteAsync(context); task.Wait(); Assert.Equal("GET", callback.RouteData.Values["action"]); Assert.Equal("RPCController", callback.RouteData.Values["controller"]); Assert.True(callback.RouteData.Values["req"].GetType() == typeof(JObject)); }
private string[] GetAndCacheAllMatchingValues(string routeKey, ActionDescriptorCollection actionDescriptors) { var version = actionDescriptors.Version; var valuesCollection = _cachedValuesCollection; if (valuesCollection == null || version != valuesCollection.Version) { var values = new HashSet <string>(StringComparer.OrdinalIgnoreCase); for (var i = 0; i < actionDescriptors.Items.Count; i++) { var action = actionDescriptors.Items[i]; if (action.RouteValues.TryGetValue(routeKey, out var value) && !string.IsNullOrEmpty(value)) { values.Add(value); } } valuesCollection = new RouteValuesCollection(version, values.ToArray()); _cachedValuesCollection = valuesCollection; } return(valuesCollection.Items); }
void BuildOrderedSetOfKeysForRouteValues(ActionDescriptorCollection actions) { Contract.Requires(actions != null); for (var i = 0; i < actions.Items.Count; i++) { var action = actions.Items[i]; if (action.AttributeRouteInfo != null) { continue; } var routeValues = new string[RouteKeys.Length]; for (var j = 0; j < RouteKeys.Length; j++) { action.RouteValues.TryGetValue(RouteKeys[j], out routeValues[j]); } if (!OrdinalIgnoreCaseEntries.TryGetValue(routeValues, out var entries)) { entries = new List <ActionDescriptor>(); OrdinalIgnoreCaseEntries.Add(routeValues, entries); } entries.Add(action); if (!OrdinalEntries.ContainsKey(routeValues)) { OrdinalEntries.Add(routeValues, entries); } } }
private static IServiceProvider CreateServices(params ActionDescriptor[] actions) { var collection = new ActionDescriptorCollection(actions, version: 0); var actionDescriptorProvider = new Mock <IActionDescriptorCollectionProvider>(); actionDescriptorProvider .Setup(a => a.ActionDescriptors) .Returns(collection); var routeOptions = new Mock <IOptions <RouteOptions> >(); routeOptions .SetupGet(o => o.Value) .Returns(new RouteOptions()); var services = new ServiceCollection() .AddSingleton <IInlineConstraintResolver>(new DefaultInlineConstraintResolver(routeOptions.Object)) .AddSingleton <ObjectPoolProvider, DefaultObjectPoolProvider>() .AddSingleton <UrlEncoder>(new UrlTestEncoder()); services.AddSingleton <ObjectPoolProvider, DefaultObjectPoolProvider>(); services.AddRouting(); services.AddOptions(); services.AddLogging(); return(services.AddSingleton(actionDescriptorProvider.Object) .AddSingleton <ILoggerFactory>(NullLoggerFactory.Instance) .BuildServiceProvider()); }
public OeRouter(IActionInvokerFactory actionInvokerFactory, IActionDescriptorCollectionProvider actionDescriptorCollectionProvider, IEdmModel edmModel, OeDataAdapter dataAdapter, IUrlHelperFactory urlHelperFactory) { _actionInvokerFactory = actionInvokerFactory; _actionDescriptors = actionDescriptorCollectionProvider.ActionDescriptors; _edmModel = edmModel; _dataAdapter = dataAdapter; }
/// <summary> /// Creates a new <see cref="ActionSelectionDecisionTree"/>. /// </summary> /// <param name="actions">The <see cref="ActionDescriptorCollection"/>.</param> public ActionSelectionDecisionTree(ActionDescriptorCollection actions) { Version = actions.Version; _root = DecisionTreeBuilder <ActionDescriptor> .GenerateTree( actions.Items, new ActionDescriptorClassifier()); }
public Cache(ActionDescriptorCollection actions) { Contract.Requires(actions != null); Version = actions.Version; RouteKeys = IdentifyRouteKeysForActionSelection(actions); BuildOrderedSetOfKeysForRouteValues(actions); }
public Cache(ActionDescriptorCollection actions) { Contract.Requires(actions != null); Version = actions.Version; OrdinalEntries = new Dictionary <string[], List <ActionDescriptor> >(StringArrayComparer.Ordinal); OrdinalIgnoreCaseEntries = new Dictionary <string[], List <ActionDescriptor> >(StringArrayComparer.OrdinalIgnoreCase); RouteKeys = IdentifyRouteKeysForActionSelection(actions); BuildOrderedSetOfKeysForRouteValues(actions); }
/// <summary> /// Creates a new <see cref="ActionSelectionDecisionTree"/>. /// </summary> /// <param name="actions">The <see cref="ActionDescriptorCollection"/>.</param> public ActionSelectionDecisionTree(ActionDescriptorCollection actions) { Version = actions.Version; var conventionalRoutedActions = actions.Items.Where(a => a.AttributeRouteInfo?.Template == null).ToArray(); _root = DecisionTreeBuilder <ActionDescriptor> .GenerateTree( conventionalRoutedActions, new ActionDescriptorClassifier()); }
// internal for testing internal AttributeRouteEntries GetEntries(ActionDescriptorCollection actions) { var entries = new AttributeRouteEntries(); var routeInfos = GetRouteInfos(_constraintResolver, actions.Items); // We're creating one TreeRouteLinkGenerationEntry per action. This allows us to match the intended // action by expected route values, and then use the TemplateBinder to generate the link. foreach (var routeInfo in routeInfos) { entries.LinkGenerationEntries.Add(new TreeRouteLinkGenerationEntry() { // Using routeInfo.Defaults here WITHOUT adding the RouteGroupKey. We don't want to impact the // behavior of link generation. Binder = new TemplateBinder(_urlEncoder, _contextPool, routeInfo.ParsedTemplate, routeInfo.Defaults), Defaults = routeInfo.Defaults, Constraints = routeInfo.Constraints, Order = routeInfo.Order, GenerationPrecedence = routeInfo.GenerationPrecedence, RequiredLinkValues = routeInfo.ActionDescriptor.RouteValueDefaults, RouteGroup = routeInfo.RouteGroup, Template = routeInfo.ParsedTemplate, Name = routeInfo.Name, }); } // We're creating one AttributeRouteMatchingEntry per group, so we need to identify the distinct set of // groups. It's guaranteed that all members of the group have the same template and precedence, // so we only need to hang on to a single instance of the RouteInfo for each group. var distinctRouteInfosByGroup = GroupRouteInfosByGroupId(routeInfos); foreach (var routeInfo in distinctRouteInfosByGroup) { // Note that because we only support 'inline' defaults, each routeInfo group also has the same // set of defaults. // // We then inject the route group as a default for the matcher so it gets passed back to MVC // for use in action selection. var defaults = new RouteValueDictionary(routeInfo.Defaults); defaults[TreeRouter.RouteGroupKey] = routeInfo.RouteGroup; entries.MatchingEntries.Add(new TreeRouteMatchingEntry() { Order = routeInfo.Order, Precedence = routeInfo.MatchPrecedence, Target = _target, RouteName = routeInfo.Name, RouteTemplate = routeInfo.ParsedTemplate, TemplateMatcher = new TemplateMatcher(routeInfo.ParsedTemplate, defaults), Constraints = routeInfo.Constraints, }); } return(entries); }
public void OnProvidersExecuting_UpdatesEntriesWhenActionDescriptorProviderCollectionIsUpdated() { // Arrange var descriptor = new PageActionDescriptor { RelativePath = "Path1", FilterDescriptors = new FilterDescriptor[0], }; var descriptorCollection1 = new ActionDescriptorCollection(new[] { descriptor }, version: 1); var descriptorCollection2 = new ActionDescriptorCollection(new[] { descriptor }, version: 2); var actionDescriptorProvider = new Mock <IActionDescriptorCollectionProvider>(); actionDescriptorProvider .SetupSequence(p => p.ActionDescriptors) .Returns(descriptorCollection1) .Returns(descriptorCollection2); var loader = new Mock <IPageLoader>(); loader .Setup(l => l.Load(It.IsAny <PageActionDescriptor>())) .Returns(CreateCompiledPageActionDescriptor(descriptor)); var invokerProvider = CreateInvokerProvider( loader.Object, actionDescriptorProvider.Object); var context = new ActionInvokerProviderContext(new ActionContext() { ActionDescriptor = descriptor, HttpContext = new DefaultHttpContext(), RouteData = new RouteData(), }); // Act - 1 invokerProvider.OnProvidersExecuting(context); // Assert - 1 Assert.NotNull(context.Result); var actionInvoker = Assert.IsType <PageActionInvoker>(context.Result); var entry1 = actionInvoker.CacheEntry; // Act - 2 invokerProvider.OnProvidersExecuting(context); // Assert Assert.NotNull(context.Result); actionInvoker = Assert.IsType <PageActionInvoker>(context.Result); var entry2 = actionInvoker.CacheEntry; Assert.NotSame(entry1, entry2); }
private IActionDescriptorCollectionProvider CreateActionDescriptorCollection(PageActionDescriptor descriptor) { var descriptorCollection = new ActionDescriptorCollection(new[] { descriptor }, version: 1); var actionDescriptorProvider = new Mock <IActionDescriptorCollectionProvider>(); actionDescriptorProvider .Setup(p => p.ActionDescriptors) .Returns(descriptorCollection); return(actionDescriptorProvider.Object); }
public static ActionSelectionTable <ActionDescriptor> Create(ActionDescriptorCollection actions) { return(CreateCore( version: actions.Version, items: actions.Items.Where(a => a.AttributeRouteInfo == null), getRouteKeys: a => a.RouteValues.Keys, getRouteValue: (a, key) => { a.RouteValues.TryGetValue(key, out var value); return value ?? string.Empty; })); }
public CustomActionDescriptorCollectionProvider() { var actionDescriptor = new ControllerActionDescriptor(); actionDescriptor.MethodInfo = typeof(ConventionalRouteController).GetMethod(nameof(ConventionalRouteController.Index)); actionDescriptor.ActionName = nameof(ConventionalRouteController.Index); _actionDescriptors = new List <ActionDescriptor>(); _actionDescriptors.Add(actionDescriptor); ActionDescriptors = new ActionDescriptorCollection(_actionDescriptors.AsReadOnly(), 1); }
private void UpdateCollection() { // Using the lock to initialize writes means that we serialize changes. This eliminates // the potential for changes to be processed out of order - the risk is that newer data // could be overwritten by older data. lock (_lock) { var context = new ActionDescriptorProviderContext(); for (var i = 0; i < _actionDescriptorProviders.Length; i++) { _actionDescriptorProviders[i].OnProvidersExecuting(context); } for (var i = _actionDescriptorProviders.Length - 1; i >= 0; i--) { _actionDescriptorProviders[i].OnProvidersExecuted(context); } // The sequence for an update is important because we don't want anyone to obtain // the new change token but the old action descriptor collection. // 1. Obtain the old cancellation token source (don't trigger it yet) // 2. Set the new action descriptor collection // 3. Set the new change token // 4. Trigger the old cancellation token source // // Consumers who poll will observe a new action descriptor collection at step 2 - they will see // the new collection and ignore the change token. // // Consumers who listen to the change token will re-query at step 4 - they will see the new collection // and new change token. // // Anyone who acquires the collection and change token between steps 2 and 3 will be notified of // a no-op change at step 4. // Step 1. var oldCancellationTokenSource = _cancellationTokenSource; // Step 2. _collection = new ActionDescriptorCollection( new ReadOnlyCollection <ActionDescriptor>(context.Results), _version++); // Step 3. _cancellationTokenSource = new CancellationTokenSource(); _changeToken = new CancellationChangeToken(_cancellationTokenSource.Token); // Step 4 - might be null if it's the first time. oldCancellationTokenSource?.Cancel(); } }
public XmlDocument GenerateSitemap(ActionDescriptorCollection actionDescriptorCollection, UrlConfig urlConfig) { HostString host = GetHost(urlConfig); List <SitemapEntry> entries = new List <SitemapEntry>(); actionDescriptorCollection.Items.ToList().ForEach(ad => { if (ad.AttributeRouteInfo != null && !ad.AttributeRouteInfo.Template.Contains("{") && !ad.AttributeRouteInfo.Template.Contains("}")) { entries.Add(new SitemapEntry(UriHelper.BuildAbsolute(urlConfig.HttpsPort.HasValue && urlConfig.HttpsPort > 0 ? "https" : "http", host, path: "/" + ad.AttributeRouteInfo.Template))); } }); return(CreateSitemap(entries)); }
private TreeRouter BuildRoute(ActionDescriptorCollection actions) { var routeBuilder = new TreeRouteBuilder(_target, _loggerFactory); var routeInfos = GetRouteInfos(_constraintResolver, actions.Items); // We're creating one AttributeRouteGenerationEntry per action. This allows us to match the intended // action by expected route values, and then use the TemplateBinder to generate the link. foreach (var routeInfo in routeInfos) { routeBuilder.Add(new TreeRouteLinkGenerationEntry() { Binder = new TemplateBinder(_urlEncoder, _contextPool, routeInfo.ParsedTemplate, routeInfo.Defaults), Defaults = routeInfo.Defaults, Constraints = routeInfo.Constraints, Order = routeInfo.Order, GenerationPrecedence = routeInfo.GenerationPrecedence, RequiredLinkValues = routeInfo.ActionDescriptor.RouteValueDefaults, RouteGroup = routeInfo.RouteGroup, Template = routeInfo.ParsedTemplate, Name = routeInfo.Name, }); } // We're creating one AttributeRouteMatchingEntry per group, so we need to identify the distinct set of // groups. It's guaranteed that all members of the group have the same template and precedence, // so we only need to hang on to a single instance of the RouteInfo for each group. var distinctRouteInfosByGroup = GroupRouteInfosByGroupId(routeInfos); foreach (var routeInfo in distinctRouteInfosByGroup) { routeBuilder.Add(new TreeRouteMatchingEntry() { Order = routeInfo.Order, Precedence = routeInfo.MatchPrecedence, Target = _target, RouteName = routeInfo.Name, RouteTemplate = TemplateParser.Parse(routeInfo.RouteTemplate), TemplateMatcher = new TemplateMatcher( routeInfo.ParsedTemplate, new RouteValueDictionary(StringComparer.OrdinalIgnoreCase) { { TreeRouter.RouteGroupKey, routeInfo.RouteGroup } }), Constraints = routeInfo.Constraints }); } return(routeBuilder.Build(actions.Version)); }
public RuntimeRazorPageLoaderTests() { var actionDescriptors = new ActionDescriptorCollection(Array.Empty <ActionDescriptor>(), 1); ActionDescriptorCollectionProvider = Mock.Of <IActionDescriptorCollectionProvider>(v => v.ActionDescriptors == actionDescriptors); // The f*cking constructor is internal.. var conventions = Activator.CreateInstance(typeof(PageConventionCollection), BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { Mock.Of <IServiceProvider>() }, null); // so is the property setter FFS. var options = new RazorPagesOptions(); typeof(RazorPagesOptions).GetProperty("Conventions", BindingFlags.Public | BindingFlags.Instance).SetValue(options, conventions); RazorPagesOptions = Options.Create(options); }
public AuditHelperTests() { Type mockControllerType = typeof(MockController); var actionDescriptors = new List <ActionDescriptor>() { new ControllerActionDescriptor() { ControllerName = ControllerName, ActionName = AnonymousMethodName, MethodInfo = mockControllerType.GetMethod(AnonymousMethodName), }, new ControllerActionDescriptor() { ControllerName = ControllerName, ActionName = AudittedMethodName, MethodInfo = mockControllerType.GetMethod(AudittedMethodName), }, new ControllerActionDescriptor() { ControllerName = ControllerName, ActionName = NoAttributeMethodName, MethodInfo = mockControllerType.GetMethod(NoAttributeMethodName), }, new PageActionDescriptor() { }, }; var actionDescriptorCollection = new ActionDescriptorCollection(actionDescriptors, 1); _actionDescriptorCollectionProvider.ActionDescriptors.Returns(actionDescriptorCollection); _fhirRequestContext.Uri.Returns(Uri); _fhirRequestContext.CorrelationId.Returns(CorrelationId); _fhirRequestContextAccessor.FhirRequestContext = _fhirRequestContext; _httpContext.Connection.RemoteIpAddress = CallerIpAddress; _claimsExtractor.Extract().Returns(Claims); _auditHelper = new AuditHelper(_actionDescriptorCollectionProvider, _fhirRequestContextAccessor, _auditLogger, NullLogger <AuditHelper> .Instance); ((IStartable)_auditHelper).Start(); }
private void UpdateCollection() { var context = new ActionDescriptorProviderContext(); for (var i = 0; i < _actionDescriptorProviders.Length; i++) { _actionDescriptorProviders[i].OnProvidersExecuting(context); } for (var i = _actionDescriptorProviders.Length - 1; i >= 0; i--) { _actionDescriptorProviders[i].OnProvidersExecuted(context); } _collection = new ActionDescriptorCollection( new ReadOnlyCollection <ActionDescriptor>(context.Results), Interlocked.Increment(ref _version)); }
public static ActionSelectionTable <ActionDescriptor> Create(ActionDescriptorCollection actions) { return(CreateCore <ActionDescriptor>( // We need to store the version so the cache can be invalidated if the actions change. version: actions.Version, // For action selection, ignore attribute routed actions items: actions.Items.Where(a => a.AttributeRouteInfo == null), getRouteKeys: a => a.RouteValues?.Keys, getRouteValue: (a, key) => { string?value = null; a.RouteValues?.TryGetValue(key, out value); return value ?? string.Empty; })); }
public Cache(ActionDescriptorCollection actions) { this.Version = actions.Version; this.OrdinalEntries = new Dictionary <string[], List <ActionDescriptor> >((IEqualityComparer <string[]>)DefaultActionSelector.StringArrayComparer.Ordinal); this.OrdinalIgnoreCaseEntries = new Dictionary <string[], List <ActionDescriptor> >((IEqualityComparer <string[]>)DefaultActionSelector.StringArrayComparer.OrdinalIgnoreCase); HashSet <string> source = new HashSet <string>((IEqualityComparer <string>)StringComparer.OrdinalIgnoreCase); for (int index = 0; index < actions.Items.Count; ++index) { ActionDescriptor actionDescriptor = actions.Items[index]; if (actionDescriptor.AttributeRouteInfo == null) { foreach (KeyValuePair <string, string> routeValue in (IEnumerable <KeyValuePair <string, string> >)actionDescriptor.RouteValues) { source.Add(routeValue.Key); } } } this.RouteKeys = source.ToArray <string>(); for (int index1 = 0; index1 < actions.Items.Count; ++index1) { ActionDescriptor actionDescriptor = actions.Items[index1]; if (actionDescriptor.AttributeRouteInfo == null) { string[] key = new string[this.RouteKeys.Length]; for (int index2 = 0; index2 < this.RouteKeys.Length; ++index2) { actionDescriptor.RouteValues.TryGetValue(this.RouteKeys[index2], out key[index2]); } List <ActionDescriptor> actionDescriptorList; if (!this.OrdinalIgnoreCaseEntries.TryGetValue(key, out actionDescriptorList)) { actionDescriptorList = new List <ActionDescriptor>(); this.OrdinalIgnoreCaseEntries.Add(key, actionDescriptorList); } actionDescriptorList.Add(actionDescriptor); if (!this.OrdinalEntries.ContainsKey(key)) { this.OrdinalEntries.Add(key, actionDescriptorList); } } } }
static string[] IdentifyRouteKeysForActionSelection(ActionDescriptorCollection actions) { var routeKeys = new HashSet <string>(StringComparer.OrdinalIgnoreCase); for (var i = 0; i < actions.Items.Count; i++) { var action = actions.Items[i]; if (action.AttributeRouteInfo == null) { foreach (var kvp in action.RouteValues) { routeKeys.Add(kvp.Key); } } } return(routeKeys.ToArray()); }