public async Task InvokeAsync(HttpContext context, RequestDelegate next) { if (context.Request.Method != HttpMethods.Get) { await next(context); return; } var routeMatcher = new RouteMatcher(); if (!routeMatcher.TryMatch(CreateRouteTemplate(), context.Request.Path, out RouteValueDictionary routeValues)) { await next(context); return; } var schema = routeValues["schema"].ToString(); var xsdFileInformationByUriSegment = _xsdFileInformationProvider.XsdFileInformationByUriSegment(schema); if (xsdFileInformationByUriSegment == default) { context.Response.StatusCode = StatusCodes.Status404NotFound; return; } string assemblyName = xsdFileInformationByUriSegment.AssemblyName; string fullQualifiedFileName = $"Artifacts/Schemas/{routeValues["file"]}.xsd"; var embeddedFileProvider = _embeddedFileProviderByAssemblyName.GetOrAdd( assemblyName, key => new EmbeddedFileProvider(_assembliesProvider.Get(assemblyName))); context.Response.ContentType = "application/xml"; context.Response.StatusCode = StatusCodes.Status200OK; await context.Response.SendFileAsync(embeddedFileProvider.GetFileInfo(fullQualifiedFileName)); string CreateRouteTemplate() { string template = $"metadata/"; if (_apiSettings.GetApiMode() == ApiMode.YearSpecific) { template += RouteConstants.SchoolYearFromRoute; } if (_apiSettings.GetApiMode() == ApiMode.InstanceYearSpecific) { template += RouteConstants.InstanceIdFromRoute; template += RouteConstants.SchoolYearFromRoute; } return(template + "xsd/{schema}/{file}.xsd"); } }
protected override void Arrange() { _assembliesProvider = Stub <IAssembliesProvider>(); A.CallTo(() => _assembliesProvider.Get(A <string> ._)) .Returns( AppDomain.CurrentDomain.GetAssemblies() .FirstOrDefault(x => x.GetName().Name.EqualsIgnoreCase(EdFiOdsStandard))); _ormMappingFileDataProvider = new OrmMappingFileDataProvider(_assembliesProvider, DatabaseEngine.Postgres, EdFiOdsStandard); }
public void SetUp() { _xsdFileInformationProvider = A.Fake <IXsdFileInformationProvider>(); _assembliesProvider = A.Fake <IAssembliesProvider>(); A.CallTo(() => _assembliesProvider.Get(A <string> ._)) .Returns(Assembly.GetAssembly(typeof(Marker_EdFi_Ods_Standard))); A.CallTo(() => _xsdFileInformationProvider.XsdFileInformationByUriSegment("ed-fi")) .Returns( new XsdFileInformation( "EdFi.Ods.Standard", "3.2.0-c", new SchemaNameMap("Ed-Fi", "edfi", "ed-fi", "EdFi"), new[] { "Ed-Fi-Core.xsd" })); A.CallTo(() => _xsdFileInformationProvider.XsdFileInformationByUriSegment("notfound")) .Returns(default);
public OrmMappingFileDataProvider(IAssembliesProvider assembliesProvider, DatabaseEngine databaseEngine, string assemblyName) { Preconditions.ThrowIfNull(assemblyName, nameof(assemblyName)); Preconditions.ThrowIfNull(assembliesProvider, nameof(assembliesProvider)); Preconditions.ThrowIfNull(databaseEngine, nameof(databaseEngine)); _ormMappingFileData = new Lazy <OrmMappingFileData>( () => { return(new OrmMappingFileData { Assembly = assembliesProvider.Get(assemblyName), MappingFileFullNames = new[] { $"{assemblyName}.{OrmMappingFileConventions.EntityOrmMappings}.{databaseEngine.ScriptsFolderName}.{OrmMappingFileConventions.EntityOrmMappingsGeneratedHbm}", $"{assemblyName}.{OrmMappingFileConventions.EntityOrmMappings}.{databaseEngine.ScriptsFolderName}.{OrmMappingFileConventions.EntityOrmMappingsForQueriesGeneratedHbm}", $"{assemblyName}.{OrmMappingFileConventions.EntityOrmMappings}.{databaseEngine.ScriptsFolderName}.{OrmMappingFileConventions.EntityOrmMappingsForViewsGeneratedHbm}" } }); }); }
public void Should_find_the_assembly_in_the_current_app_domain() => A.CallTo(() => _assembliesProvider.Get(A <string> .That.IsEqualTo(EdFiOdsStandard))).MustHaveHappened();