public void ResolveThisClass()
        {
            var assembliesResolver = new Mock<IAssembliesResolver>();

            var typeBuilderStrategy = new Mock<ITypeBuilderStrategy>();

            typeBuilderStrategy.Setup(_ => _.ClassKey(It.IsAny<Type>())).Returns("KK");
            typeBuilderStrategy.Setup(_ => _.Configure(It.IsAny<ITypeBuilderContainer>()))
                .Callback((ITypeBuilderContainer c) => c.AddVisitor(new HypermediaApiControllerConfiguratorVisitor()));

            var typeBuilder = new TypeBuilder(typeof(ModelSample), typeBuilderStrategy.Object);

            typeBuilder.WithInterface(typeof (IHypermediaApiControllerConfigurator));

            var fakeType = typeBuilder.BuildType();

            assembliesResolver.Setup(_ => _.GetAssemblies()).Returns(new List<Assembly>() { new FakeAssembly(fakeType) });

            var resolver = new HypermediaInitializerTypeResolver();

            var collecton = resolver.GetControllerTypes(assembliesResolver.Object);

            Assume.That(collecton, Is.Not.Empty);
            Assume.That(collecton, Has.Member(fakeType));
        }
예제 #2
0
        public static void InitializeHypermedia(this HttpConfiguration configuration)
        {
            configuration.EnsureInitialized();

            IAssembliesResolver assembliesResolver = configuration.Services.GetAssembliesResolver();

            var initResolver = new HypermediaInitializerTypeResolver();

            var resolvedInitializers = initResolver.GetControllerTypes(assembliesResolver);

            resolvedInitializers.ToList().ForEach(t => ((IHypermediaApiControllerConfigurator)Activator.CreateInstance(t)).ConfigureHypermedia(configuration));
        }
        public void ResolveEmptyCollection()
        {
            var assembliesResolver = new Mock<IAssembliesResolver>();

            assembliesResolver.Setup(_ => _.GetAssemblies()).Returns(new List<Assembly>());

            var resolver = new HypermediaInitializerTypeResolver();

            var collecton = resolver.GetControllerTypes(assembliesResolver.Object);

            Assume.That(collecton, Is.Empty);
        }