public void AssemblyWrapper_LoadFile_ShouldLoadTestAssembly() { var assemblyWrapper = new AssemblyWrapper(); var loadedAssembly = assemblyWrapper.LoadFile(AssemblyPath); Assert.AreEqual("TSQLLint.Tests.dll", loadedAssembly.ManifestModule.ScopeName); }
private void AddModuleToGrid(ModuleWrapper module, GridEXRow row) { AssignNumberValueToCell <uint>(row.Cells[0], module.GetToken()); AssignNumberValueToCell <ulong>(row.Cells[1], module.GetBaseAddress()); AssignNumberValueToCell <uint>(row.Cells[2], module.GetSize()); row.Cells[3].Value = module.IsDynamic(); row.Cells[4].Value = module.IsInMemory(); string moduleName = module.GetName(); try { row.Cells[5].Value = Path.GetFileName(moduleName); } catch { } row.Cells[6].Value = moduleName; AssemblyWrapper assembly = module.GetAssembly(); row.Cells[7].Value = assembly.GetName(); AppDomainWrapper appDomain = assembly.GetAppDomain(); row.Cells[8].Value = appDomain.GetName(); }
public void ActivatePlugins_ThrowErrors_ShouldCatch_ShouldReport() { // arrange var path = Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory, @"UnitTests/PluginHandler/tsqllint-plugin-throws-exception.dll")); var assemblyWrapper = new AssemblyWrapper(); var pluginPaths = new Dictionary <string, string> { { "my-plugin", path } }; var reporter = Substitute.For <IReporter>(); var versionWrapper = Substitute.For <IFileversionWrapper>(); var context = Substitute.For <IPluginContext>(); versionWrapper.GetVersion(Arg.Any <Assembly>()).Returns("1.2.3"); // act var pluginHandler = new Infrastructure.Plugins.PluginHandler(reporter, new FileSystem(), assemblyWrapper, versionWrapper); pluginHandler.ProcessPaths(pluginPaths); pluginHandler.ActivatePlugins(context); // assert Assert.AreEqual(1, pluginHandler.Plugins.Count); reporter.Received().Report(@"There was a problem with plugin: tsqllint_plugin_throws_exception.PluginThatThrows - something bad happened"); }
public void LocatesAllServiceRouteMappers() { var assemblyLocator = new Mock<IAssemblyLocator>(); //including the assembly with object ensures that the assignabliity is done correctly var assembliesToReflect = new IAssembly[2]; assembliesToReflect[0] = new AssemblyWrapper(GetType().Assembly); assembliesToReflect[1] = new AssemblyWrapper(typeof (Object).Assembly); assemblyLocator.Setup(x => x.Assemblies).Returns(assembliesToReflect); var locator = new TypeLocator {AssemblyLocator = assemblyLocator.Object}; List<Type> types = locator.GetAllMatchingTypes(ServicesRoutingManager.IsValidServiceRouteMapper).ToList(); //if new ServiceRouteMapper classes are added to the assembly they willl likely need to be added here CollectionAssert.AreEquivalent( new[] { typeof (FakeServiceRouteMapper), typeof (ReflectedServiceRouteMappers.EmbeddedServiceRouteMapper), typeof (ExceptionOnCreateInstanceServiceRouteMapper), typeof (ExceptionOnRegisterServiceRouteMapper) }, types); }
public void LocatesAllServiceRouteMappers() { var assemblyLocator = new Mock <IAssemblyLocator>(); //including the assembly with object ensures that the assignabliity is done correctly var assembliesToReflect = new IAssembly[2]; assembliesToReflect[0] = new AssemblyWrapper(GetType().Assembly); assembliesToReflect[1] = new AssemblyWrapper(typeof(Object).Assembly); assemblyLocator.Setup(x => x.Assemblies).Returns(assembliesToReflect); var locator = new TypeLocator { AssemblyLocator = assemblyLocator.Object }; List <Type> types = locator.GetAllMatchingTypes(ServicesRoutingManager.IsValidServiceRouteMapper).ToList(); //if new ServiceRouteMapper classes are added to the assembly they willl likely need to be added here CollectionAssert.AreEquivalent( new[] { typeof(FakeServiceRouteMapper), typeof(ReflectedServiceRouteMappers.EmbeddedServiceRouteMapper), typeof(ExceptionOnCreateInstanceServiceRouteMapper), typeof(ExceptionOnRegisterServiceRouteMapper) }, types); }
public void AssemblyWrapper_GetExportedTypes_ShouldReturnTypes() { var assemblyWrapper = new AssemblyWrapper(); var loadedAssembly = assemblyWrapper.LoadFile(AssemblyPath); var loadedTypes = assemblyWrapper.GetExportedTypes(loadedAssembly); Assert.IsTrue(loadedTypes.Length > 0); }
public void AssemblyWrapper_GetReferencedAssemblies_Using_Assembly() { var assemblyLoader = new AssemblyWrapper(); var assembly = assemblyLoader.GetAssembly(typeof(AssemblyWrapper)); var referencedAssembliesload = assemblyLoader.GetReferencedAssemblies(assembly); Assert.IsNotNull(referencedAssembliesload); }
public void AssemblyWrapper_UnsafeLoadFrom_Using_String() { var assemblyLoader = new AssemblyWrapper(); var assembly = assemblyLoader.GetAssembly(typeof(AssemblyWrapper)); var unsafeLoadFrom = assemblyLoader.UnsafeLoadFrom(assembly.Location); Assert.AreEqual("Dev2.Common.dll", unsafeLoadFrom.ManifestModule.Name); }
public void AssemblyWrapper_Load_Using_Assembly() { var assemblyLoader = new AssemblyWrapper(); var assembly = assemblyLoader.GetAssembly(typeof(AssemblyWrapper)); var load = assemblyLoader.Load(assembly.GetName()); Assert.AreEqual("Dev2.Common.dll", load.ManifestModule.Name); }
/// <summary> /// /// </summary> /// <param name="assembly"></param> /// <returns></returns> public IAssembly GetAssembly(Assembly assembly) { object wrapper = null; if (!this.cache.TryGetValue(assembly, out wrapper)) { wrapper = new AssemblyWrapper(this, assembly); this.cache.Add(assembly, wrapper); } return (IAssembly)wrapper; }
public EmbeddedResourceAssembly Create(string basePath, AssemblyWrapper assembly) { return(new EmbeddedResourceAssembly( name: assembly.Assembly.GetName().Name, basePath: basePath, openEmbeddedResourceStream: r => assembly.Assembly.GetManifestResourceStream(r.Name), embeddedResources: assembly.Assembly.GetManifestResourceNames().Select(resourceName => new EmbeddedResource(resourceName)) )); }
public Component(string id, AssemblyWrapper assembly, IEnumerable <string> dependencies, IEnumerable <Controller> controllers, IEnumerable <Script> scripts, IEnumerable <Style> styles) { Id = id; Assembly = assembly; Dependencies = dependencies.ToList().AsReadOnly(); Controllers = controllers.ToList().AsReadOnly(); Scripts = scripts.ToList().AsReadOnly(); Styles = styles.ToList().AsReadOnly(); }
/// <summary> /// Intended for testing purposes only. /// </summary> public ResourceManagerStringLocalizer( [NotNull] ResourceManager resourceManager, [NotNull] AssemblyWrapper resourceAssemblyWrapper, [NotNull] string baseName, [NotNull] IResourceNamesCache resourceNamesCache) { _resourceAssemblyWrapper = resourceAssemblyWrapper; _resourceManager = resourceManager; _resourceBaseName = baseName; _resourceNamesCache = resourceNamesCache; }
/// <summary> /// /// </summary> /// <param name="assembly"></param> /// <returns></returns> public IAssembly GetAssembly(Assembly assembly) { object wrapper = null; if (!this.cache.TryGetValue(assembly, out wrapper)) { wrapper = new AssemblyWrapper(this, assembly); this.cache.Add(assembly, wrapper); } return((IAssembly)wrapper); }
public TestStringLocalizer(ResourceManager resourceManager, AssemblyWrapper resourceAssembly, string baseName, IResourceNamesCache resourceNamesCache, string applicationBasePath) { _resourceAssemblyWrapper = resourceAssembly; _resourceManager = resourceManager; _resourceBaseName = baseName; _resourceNamesCache = resourceNamesCache; _applicationBasePath = applicationBasePath; }
protected override AssemblyWrapper loadAssembly(string assemblyPath) { if (ForceAssemblyNotFound) { throw new System.IO.FileNotFoundException(); } var wrapper = new AssemblyWrapper() { Path = assemblyPath, Assembly = null }; LoadedAssemblies.Add(wrapper); return(wrapper); }
public static string CreateCrossReferenceTagReplacement(AssemblyWrapper assembly, string crefTypeName, FrameworkVersion version) { const string amazonNamespaceRoot = "Amazon."; var target = string.Empty; string url = null; string typeName; if (crefTypeName.Length > 2 && crefTypeName[1] == ':') // cref M:, T:, P:, F: indicators { typeName = crefTypeName.Substring(2); } else { typeName = crefTypeName; } var typeWrapper = assembly.GetType(typeName); if (typeWrapper != null) { url = string.Format("./{0}", FilenameGenerator.GenerateFilename(typeWrapper)); } else if (typeName.StartsWith("system.", StringComparison.OrdinalIgnoreCase)) { url = string.Format(NDocUtilities.MSDN_TYPE_URL_PATTERN, typeName.ToLower()); target = "target=_new"; } // If we couldn't generate a url to use with an anchor tag, make the typename italic+bold so // that it at least stands out. if (url == null) { return(string.Format("<i><b>{0}</b></i>", typeName)); } // If the type is one of ours, strip the namespace from the display text to condense things // a little if (typeName.StartsWith(amazonNamespaceRoot, StringComparison.Ordinal)) { var lastPeriodIndex = typeName.LastIndexOf('.'); typeName = typeName.Substring(lastPeriodIndex + 1); } return(string.Format("<a href=\"{0}\" {2}>{1}</a>", url, typeName, target)); }
public AssemblyLoader(byte[] bytes) { Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence); AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation; AppDomain childDomain = AppDomain.CreateDomain("DiscoveryRegion", evidence, setup); childDomain.AssemblyResolve += ChildDomain_AssemblyResolve; Type proxyType = typeof(AssemblyWrapper); var proxy = (AssemblyWrapper)childDomain.CreateInstanceAndUnwrap( proxyType.Assembly.FullName, proxyType.FullName); proxy.ReadAssembly(bytes); wrapper = proxy; domain = childDomain; }
/// <summary> /// Intended for testing purposes only. /// </summary> internal ResourceManagerStringLocalizer( ResourceManager resourceManager, AssemblyWrapper resourceAssemblyWrapper, string baseName, IResourceNamesCache resourceNamesCache, ILogger logger) : this( resourceManager, new ResourceManagerStringProvider( resourceNamesCache, resourceManager, resourceAssemblyWrapper.Assembly, baseName), baseName, resourceNamesCache, logger) { }
/// <summary> /// Loads the toc snippet file for the specified namespace, adding it to the managed /// collection for later collation into the overall toc file. /// </summary> //void LoadNamespaceToc(string nameSpace) //{ // var filePath = Path.Combine(Options.ComputedContentFolder, tocFilesFolderName); // if (!Directory.Exists(filePath)) // return; // var tocFile = Path.Combine(filePath, nameSpace + extensionPattern); // if (File.Exists(tocFile)) // { // using (var reader = File.OpenText(tocFile)) // { // var tocContent = reader.ReadToEnd(); // _namespaceTocs.Add(nameSpace, tocContent); // } // } //} void WriteNamespaceToc(JsonWriter writer, string ns, AssemblyWrapper sdkAssemblyWrapper) { var tocId = ns.Replace(".", "_"); var nsFilePath = Path.Combine("./" + Options.ContentSubFolderName, GenerationManifest.OutputSubFolderFromNamespace(ns), FilenameGenerator.GenerateNamespaceFilename(ns)).Replace('\\', '/'); writer.WritePropertyName(ns); writer.WriteObjectStart(); writer.WritePropertyName(TocIdFieldName); writer.Write(tocId); writer.WritePropertyName(TocHrefFieldName); writer.Write(nsFilePath); writer.WritePropertyName(TocNodesFieldName); writer.WriteObjectStart(); foreach (var type in sdkAssemblyWrapper.GetTypesForNamespace(ns).OrderBy(x => x.Name)) { var filePath = Path.Combine("./" + Options.ContentSubFolderName, GenerationManifest.OutputSubFolderFromNamespace(type.Namespace), FilenameGenerator.GenerateFilename(type)).Replace('\\', '/'); writer.WritePropertyName(type.GetDisplayName(false)); writer.WriteObjectStart(); writer.WritePropertyName(TocIdFieldName); writer.Write(type.GetDisplayName(true).Replace(".", "_")); writer.WritePropertyName(TocHrefFieldName); writer.Write(filePath); writer.WriteObjectEnd(); } writer.WriteObjectEnd(); writer.WriteObjectEnd(); }
/// <summary> /// Creates or updates a per-namespace json file during generation of docs for types in that /// namespace. These will be added to the _namespaceTocs collection to be collated into /// one single master toc at the end of processing of all namespaces. /// </summary> /// <example> /// An partial and annotated example of what one data file looks like for the /// 'Amazon' namespace: /// { /// "Amazon" : // this is used as the display name of the root for the entries /// { /// "id" : "Amazon", // the unique id assigned to the li element /// "href" : "./items/Amazon/N_.html", // the target of the link /// "nodes": { // collection of child nodes for the namespace /// "AWSConfigs" : { // display name for child node /// "id" : "Amazon_AWSConfigs", // the unique li id /// "href" : "./items/Amazon/TAWSConfigs.html" // the target of the link /// }, /// "LoggingOptions" : { /// "id" : "Amazon_LoggingOptions", /// "href" : "./items/Amazon\TLoggingOptions.html" /// }, /// ... /// } /// } /// } /// </example> public void BuildNamespaceToc(string nameSpace, AssemblyWrapper sdkAssemblyWrapper) { var sb = new StringBuilder(); var jsonWriter = new JsonWriter(sb); jsonWriter.WriteObjectStart(); WriteNamespaceToc(jsonWriter, nameSpace, sdkAssemblyWrapper); jsonWriter.WriteObjectEnd(); var nsTocContents = sb.ToString(); if (_namespaceTocs.ContainsKey(nameSpace)) { _namespaceTocs[nameSpace] = nsTocContents; } else { _namespaceTocs.Add(nameSpace, nsTocContents); } PersistNamespaceToc(nameSpace); }
protected override object createInstanceOfType(AssemblyWrapper assemblyOfType, string namespaceDotType) { AssembliesRequestedToCreateFrom.Add(assemblyOfType); TypesRequestedToCreate.Add(namespaceDotType); return(ForcedCreatedInstance); }
public TestResourceManager(string baseName, AssemblyWrapper assemblyWrapper) : base(baseName, assemblyWrapper.Assembly) { _assemblyWrapper = assemblyWrapper; }
public NamespaceWriter(GenerationManifest artifacts, FrameworkVersion version, string namespaceName) : base(artifacts, version) { this._namespaceName = namespaceName; this._assemblyWrapper = artifacts.ManifestAssemblyContext.SdkAssembly; }
public NamespaceWriter(GenerationManifest artifacts, FrameworkVersion version, string namespaceName) : base(artifacts, version) { this._namespaceName = namespaceName; this._assemblyWrapper = artifacts.AssemblyWrapper; }
public static string CreateCrossReferenceTagReplacement(AssemblyWrapper assembly, string crefTypeName, FrameworkVersion version) { const string amazonNamespaceRoot = "Amazon."; var target = string.Empty; string url = null; string typeName; if (crefTypeName.Length > 2 && crefTypeName[1] == ':') // cref M:, T:, P:, F: indicators typeName = crefTypeName.Substring(2); else typeName = crefTypeName; var typeWrapper = assembly.GetType(typeName); if (typeWrapper != null) url = string.Format("./{0}", FilenameGenerator.GenerateFilename(typeWrapper)); else if (typeName.StartsWith("system.", StringComparison.OrdinalIgnoreCase)) { url = string.Format(NDocUtilities.MSDN_TYPE_URL_PATTERN, typeName.ToLower()); target = "target=_new"; } // If we couldn't generate a url to use with an anchor tag, make the typename italic+bold so // that it at least stands out. if (url == null) return string.Format("<i><b>{0}</b></i>", typeName); // If the type is one of ours, strip the namespace from the display text to condense things // a little if (typeName.StartsWith(amazonNamespaceRoot, StringComparison.Ordinal)) { var lastPeriodIndex = typeName.LastIndexOf('.'); typeName = typeName.Substring(lastPeriodIndex + 1); } return string.Format("<a href=\"{0}\" {2}>{1}</a>", url, typeName, target); }
protected override AssemblyWrapper loadAssembly(string assemblyPath) { if (ForceAssemblyNotFound) throw new System.IO.FileNotFoundException(); var wrapper = new AssemblyWrapper() { Path = assemblyPath, Assembly = null }; LoadedAssemblies.Add(wrapper); return wrapper; }
private void CheckComponent(ComponentWrapper OwnerComponent, string text, ComponentWrapper component) { ComponentMessageObject CMO = new ComponentMessageObject(); CMO.Component = OwnerComponent; ComponentsChecked++; switch (component.ComponentType) { #region Library case ComponentTypeWrapper.Library: if (!CheckComponentGUID(component, text, CMO)) { return; } LibraryWrapper LW = PK.Wrapper.FindLibrary(component.Guid); if (LW == null) { CanTFindComponentsReference(component, text, CMO); return; } CompareComponentName(component, LW.Name, text, CMO); CompareComponentProjectPath(component, LW.ProjectPath, text, CMO); break; #endregion #region Feature case ComponentTypeWrapper.Feature: if (!CheckComponentGUID(component, text, CMO)) { return; } FeatureWrapper FW = PK.Wrapper.FindFeature(component.Guid); if (FW == null) { CanTFindComponentsReference(component, text, CMO); return; } CompareComponentName(component, FW.Name, text, CMO); CompareComponentProjectPath(component, FW.ProjectPath, text, CMO); break; #endregion #region Assembly case ComponentTypeWrapper.MFAssembly: if (!CheckComponentGUID(component, text, CMO)) { return; } AssemblyWrapper AW = PK.Wrapper.FindAssembly(component.Guid); if (AW == null) { CanTFindComponentsReference(component, text, CMO); return; } CompareComponentName(component, AW.Name, text, CMO); CompareComponentProjectPath(component, AW.ProjectPath, text, CMO); break; #endregion case ComponentTypeWrapper.MFSolution: break; #region Processors case ComponentTypeWrapper.Processor: if (!CheckComponentGUID(component, text, CMO)) { return; } ProcessorWrapper PW = PK.Wrapper.FindProcessor(component.Guid); if (PW == null) { CanTFindComponentsReference(component, text, CMO); return; } CompareComponentName(component, PW.Name, text, CMO); CompareComponentProjectPath(component, PW.ProjectPath, text, CMO); break; #endregion case ComponentTypeWrapper.OperatingSystem: break; case ComponentTypeWrapper.BuildTool: break; #region ISA case ComponentTypeWrapper.ISA: if (!CheckComponentGUID(component, text, CMO)) { return; } ISAWrapper IW = PK.Wrapper.FindISA(component.Guid); if (IW == null) { CanTFindComponentsReference(component, text, CMO); return; } CompareComponentName(component, IW.Name, text, CMO); break; #endregion case ComponentTypeWrapper.BuildParameter: break; #region LibraryCategory case ComponentTypeWrapper.LibraryCategory: if (!CheckComponentGUID(component, text, CMO)) { return; } LibraryCategoryWrapper LCW = PK.Wrapper.FindLibraryCategory(component.Guid); if (LCW == null) { CanTFindComponentsReference(component, text, CMO); return; } CompareComponentName(component, LCW.Name, text, CMO); CompareComponentProjectPath(component, LCW.ProjectPath, text, CMO); break; #endregion #region Unknown case ComponentTypeWrapper.Unknown: WEMessage UMessage = new WEMessage(); UMessage.Message = text + "Component with \"Type\": " + GetStringByComponentType(component.ComponentType); UMessage.MessageObject = CMO; this.OnWarning(UMessage); break; #endregion default: break; } }
public ComponentDescriptor(string id, AssemblyWrapper assembly) { Id = id; Assembly = assembly; }
protected override object createInstanceOfType(AssemblyWrapper assemblyOfType, string namespaceDotType) { AssembliesRequestedToCreateFrom.Add(assemblyOfType); TypesRequestedToCreate.Add(namespaceDotType); return ForcedCreatedInstance; }
public void CanRunTestThatWasDiscoveredWithoutReflection() { var typeUnderTest = typeof(ClassUnderTest); var methodUnderTest = typeUnderTest.GetMethod("TestMethod"); var factAttributeUnderTest = CustomAttributeData.GetCustomAttributes(methodUnderTest).Single(a => a.AttributeType == typeof(FactAttribute)); var assembly = new AssemblyWrapper(Reflector.Wrap(typeUnderTest.Assembly)); var type = new TypeWrapper(Reflector.Wrap(typeUnderTest)); var method = new MethodWrapper(Reflector.Wrap(methodUnderTest)); var attribute = new AttributeWrapper(Reflector.Wrap(factAttributeUnderTest)); var testCase = TestableXunitTestCase.Create(assembly, type, method, attribute); testCase.RunTests(); Assert.Collection(testCase.Messages, message => Assert.IsAssignableFrom<ITestStarting>(message), message => Assert.IsAssignableFrom<ITestClassConstructionStarting>(message), message => Assert.IsAssignableFrom<ITestClassConstructionFinished>(message), message => { var failed = Assert.IsAssignableFrom<ITestFailed>(message); Assert.Equal(typeof(TrueException).FullName, failed.ExceptionType); }, message => Assert.IsAssignableFrom<ITestFinished>(message) ); }
protected override List<Type> getAllTypesInsideAssembly(AssemblyWrapper assembly) { return ForcedAllTypesInsideAssembly; }