public Task InitializeAsync(IAsyncServiceProvider asyncServiceProvider)
        {
            // There's no public API registering a trace listener for a
            // non-public trace source, so we need to use reflection
            string assemblyName = typeof(AppliesToAttribute).Assembly.FullName;
            string typeName     = $"Microsoft.VisualStudio.ProjectSystem.TraceUtilities, {assemblyName}";

            var type = Type.GetType(typeName);

            if (type is null)
            {
                Assumes.Fail($"Could not find type '{typeName}'");
            }

            const string sourcePropertyName = "Source";
            PropertyInfo?property           = type.GetProperty(sourcePropertyName, BindingFlags.NonPublic | BindingFlags.Static);

            if (property is null)
            {
                Assumes.Fail($"Could not find property '{sourcePropertyName}' in type '{typeName}'");
            }

            var source = (TraceSource)property.GetValue(null);

            source.Switch.Level = SourceLevels.Warning;
            source.Listeners.Add(this);

            return(Task.CompletedTask);
        }
예제 #2
0
        public static Module ResolveModule(Assembly assembly, int metadataToken)
        {
            Assumes.NotNull(assembly);
            Assumes.IsTrue(metadataToken != 0);

            // TODO: This likely cause all modules in the assembly to be loaded
            // perhaps we should load via file name (how will that work on SL)?
            foreach (Module module in assembly.GetModules())
            {
                if (module.MetadataToken == metadataToken)
                {
                    return(module);
                }
            }

            Assumes.Fail("");
            return(null);
        }
        //todo: very weirdly, after updating StructureMap to version 3, double dispatch via dynamic not works anymore(http://stackoverflow.com/questions/27011810/mystery-with-dynamic-type-double-dispatch)
        private static object ApplyResolver(GenericFamilyExpression builder, IImplementationResolver resolver)
        {
            if (resolver is StaticResolver)
            {
                return(builder.Add(((StaticResolver)resolver).Target));
            }
            if (resolver is InstanceResolver)
            {
                return(builder.Add(((InstanceResolver)resolver).Instance));
            }
            if (resolver is DynamicResolver)
            {
                return(builder.Add(c => ((DynamicResolver)resolver).FactoryFunc()));
            }

            Assumes.Fail("Unsupported IImplementationResolver implementation");
            return(null);
        }
예제 #4
0
 public void Fail()
 {
     ExceptionAssert.Throws(debugAssertException, () => { Assumes.Fail((string)null); }).WithMessage("Assumption failed.", ExceptionMessageComparison.StartsWith);
     ExceptionAssert.Throws(debugAssertException, () => { Assumes.Fail(String.Empty); }).WithMessage("Assumption failed.", ExceptionMessageComparison.StartsWith);
     ExceptionAssert.Throws(debugAssertException, () => { Assumes.Fail("test."); }).WithMessage("Assumption failed. test.", ExceptionMessageComparison.StartsWith);
 }
예제 #5
0
 public void Fail()
 {
     Assert.ThrowsAny <Exception>(() => Assumes.Fail("some message", new InvalidOperationException()));
 }
예제 #6
0
 public override bool TryRead(out ReadResult result) => throw Assumes.Fail(UnownedObject);
예제 #7
0
 public override ValueTask <ReadResult> ReadAsync(CancellationToken cancellationToken = default) => throw Assumes.Fail(UnownedObject);
예제 #8
0
 public override ValueTask CompleteAsync(Exception?exception = null) => throw Assumes.Fail(UnownedObject);
예제 #9
0
 public override void Complete(Exception?exception = null) => throw Assumes.Fail(UnownedObject);
예제 #10
0
 public override void AdvanceTo(SequencePosition consumed, SequencePosition examined) => throw Assumes.Fail(UnownedObject);
예제 #11
0
 public override void SetValue(object component, object value) =>
 Assumes.Fail("This method should not get called!");
예제 #12
0
 public override object GetValue(object component)
 {
     Assumes.Fail("This method should not get called!");
     return(null);
 }
 public override void ResetValue(object component) =>
 Assumes.Fail("This method should not be called!");
예제 #14
0
 public void Fail()
 {
     ExceptionAssert.Throws <AssumptionException>(() => { Assumes.Fail(String.Empty); }).WithMessage("Assumption failed.");
     ExceptionAssert.Throws <AssumptionException>(() => { Assumes.Fail("test."); }).WithMessage("Assumption failed. test.");
 }