public void ResolvesInstanceOfConcreteConstructorParameter() { var resolver = new OnDemandResolver(); var result = (OnDemandResolverTests.ITestClassMultipleCtor)resolver.Resolve(typeof(OnDemandResolverTests.ITestClassMultipleCtor)); result.TestClassInst.Should().NotBeNull(); }
public void UsesDefaultConstructorIfNecessary() { var resolver = new OnDemandResolver(); var result = (OnDemandResolverTests.ITestClassDefaultCtor)resolver.Resolve(typeof(OnDemandResolverTests.ITestClassDefaultCtor)); result.CtorCalled.Should().BeTrue(); }
public void UsesParameterizedConstructorOverDefaultConstructor() { var resolver = new OnDemandResolver(); var result = (OnDemandResolverTests.ITestClassMultipleCtor)resolver.Resolve(typeof(OnDemandResolverTests.ITestClassMultipleCtor)); result.CtorCalled.Should().Be(2); }
public void DoesNotResolveInterfaceWithMultipleImplementations() { var resolver = new OnDemandResolver(); var result = resolver.Resolve(typeof(OnDemandResolverTests.ITestClassMultipleImpl)); result.Should().BeNull(); }
public void ResolvesInterfaceToDefaultType() { var resolver = new OnDemandResolver(); var result = resolver.Resolve(typeof(OnDemandResolverTests.ITestClass)); result.Should().NotBeNull(); result.Should().BeOfType <OnDemandResolverTests.TestClass>(); }
public void CanResolveTypeWithoutConstructor() { var resolver = new OnDemandResolver(); var result = resolver.Resolve(typeof(OnDemandResolverTests.ITestClassNoCtor)); result.Should().NotBeNull(); result.Should().BeOfType <OnDemandResolverTests.TestClassNoCtor>(); }
protected AssemblyDefinition AssemblyDefinitionFor(Type type) { var assemblyLocation = type.Assembly.Location; var resolver = new OnDemandResolver(); var ad = AssemblyDefinition.ReadAssembly(new MemoryStream(File.ReadAllBytes(assemblyLocation)), new ReaderParameters(ReadingMode.Immediate) { ReadSymbols = true, ThrowIfSymbolsAreNotMatching = true, SymbolReaderProvider = new PortablePdbReaderProvider(), AssemblyResolver = resolver, SymbolStream = PdbStreamFor(assemblyLocation) } ); if (!ad.MainModule.HasSymbols) { throw new Exception("NoSymbols"); } return(ad); }