Exemple #1
0
        public void ResolvesInstanceOfConcreteConstructorParameter()
        {
            var resolver = new OnDemandResolver();
            var result   = (OnDemandResolverTests.ITestClassMultipleCtor)resolver.Resolve(typeof(OnDemandResolverTests.ITestClassMultipleCtor));

            result.TestClassInst.Should().NotBeNull();
        }
Exemple #2
0
        public void UsesDefaultConstructorIfNecessary()
        {
            var resolver = new OnDemandResolver();
            var result   = (OnDemandResolverTests.ITestClassDefaultCtor)resolver.Resolve(typeof(OnDemandResolverTests.ITestClassDefaultCtor));

            result.CtorCalled.Should().BeTrue();
        }
Exemple #3
0
        public void UsesParameterizedConstructorOverDefaultConstructor()
        {
            var resolver = new OnDemandResolver();
            var result   = (OnDemandResolverTests.ITestClassMultipleCtor)resolver.Resolve(typeof(OnDemandResolverTests.ITestClassMultipleCtor));

            result.CtorCalled.Should().Be(2);
        }
Exemple #4
0
        public void DoesNotResolveInterfaceWithMultipleImplementations()
        {
            var resolver = new OnDemandResolver();
            var result   = resolver.Resolve(typeof(OnDemandResolverTests.ITestClassMultipleImpl));

            result.Should().BeNull();
        }
Exemple #5
0
        public void ResolvesInterfaceToDefaultType()
        {
            var resolver = new OnDemandResolver();
            var result   = resolver.Resolve(typeof(OnDemandResolverTests.ITestClass));

            result.Should().NotBeNull();
            result.Should().BeOfType <OnDemandResolverTests.TestClass>();
        }
Exemple #6
0
        public void CanResolveTypeWithoutConstructor()
        {
            var resolver = new OnDemandResolver();
            var result   = resolver.Resolve(typeof(OnDemandResolverTests.ITestClassNoCtor));

            result.Should().NotBeNull();
            result.Should().BeOfType <OnDemandResolverTests.TestClassNoCtor>();
        }
Exemple #7
0
        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);
        }