![]() ![]() Other assert methods can be added similar to AssertParameterAssertCondition that also call into CodeAnnotationsCache in order to assert annotations are applied. Var actual = cache.GetParameterAssertionCondition(parameter) Public IEnumerable GetAnnotationsFiles(AssemblyNameInfo assemblyName = null, FileSystemPath assemblyLocation = null)ĬachedBaseTestDataPath = TestUtil.GetTestDataPathBase(GetType().Assembly) Private FileSystemPath cachedBaseTestDataPath Īnnotations = new OneToSetMap(StringComparer.OrdinalIgnoreCase) įoreach (var file in location.GetChildFiles("*.xml"))Īnnotations.Add(file.NameWithoutExtension, file) įoreach (var directory in location.GetChildDirectories())įoreach (var file in directory.GetChildFiles("*.xml", PathSearchFlags.RecurseIntoSubdirectories))Īnnotations.Add(, file) Private readonly OneToSetMap annotations Public class TestExternalAnnotationsProvider : IExternalAnnotationsFileProvider This is the same folder structure and naming scheme used when annotations are distributed inside an extension package. Either the directory should be named after the assembly, in which case all files in that directory apply to the assembly, or the file should be named after the assembly. It will also recursively look for any XML files in child directories. myAssembly.dll would need a myAssembly.xml file in the root location. ![]() These are expected to be named after the assembly, e.g. This provider will load all XML files that are immediate children of the file location. Or you can completely replace BaseTestDataPath to return any location you want. The following class will load all annotations stored in a specific folder, which, in this example will be test\data\annotations, but by replacing the implementation of RelativeTestDataPath you can change it to another location relative to test\data, even outside of the test\data folder structure. Instead, they have to be loaded explicitly by the test assembly, by implementing IExternalAnnotationsFileProvider and marking the component with the attribute. ReSharper doesn't do this by default, it only loads annotations that are installed with the product, or as extensions. Loading the annotationsīefore any tests can run, the annotations need to be loaded by the test environment. The first approach requires some helper methods, and an example base class is provided below, while the second approach is a normal highlighting test. ReSharper doesn't prescribe a specific approach there are no base classes or helper methods specifically for testing external annotations. The first approach tests that the external annotations are correctly applied, while the second asserts the expected result of applying the annotations. For example, an element marked with the attribute will cause ReSharper to highlight a null check as unnecessary. The second is to assert the highlights and warnings that are affected by annotations. The first is to use the CodeAnnotationsCache class to assert that annotations are applied to specific code elements in the compiled assemblies. There are two approaches to testing External Annotations. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |