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); }
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); }
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); }
public void Fail() { Assert.ThrowsAny <Exception>(() => Assumes.Fail("some message", new InvalidOperationException())); }
public override bool TryRead(out ReadResult result) => throw Assumes.Fail(UnownedObject);
public override ValueTask <ReadResult> ReadAsync(CancellationToken cancellationToken = default) => throw Assumes.Fail(UnownedObject);
public override ValueTask CompleteAsync(Exception?exception = null) => throw Assumes.Fail(UnownedObject);
public override void Complete(Exception?exception = null) => throw Assumes.Fail(UnownedObject);
public override void AdvanceTo(SequencePosition consumed, SequencePosition examined) => throw Assumes.Fail(UnownedObject);
public override void SetValue(object component, object value) => Assumes.Fail("This method should not get called!");
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!");
public void Fail() { ExceptionAssert.Throws <AssumptionException>(() => { Assumes.Fail(String.Empty); }).WithMessage("Assumption failed."); ExceptionAssert.Throws <AssumptionException>(() => { Assumes.Fail("test."); }).WithMessage("Assumption failed. test."); }