public void FactoryMethodWillCreateShellRoutes() {
            var builder = new ContainerBuilder();
            builder.RegisterType<ShellRoute>().InstancePerDependency();
            builder.RegisterAutoMocking();

            var container = builder.Build();
            var buildShellRoute = new Func<RouteBase, ShellRoute>(routeBase => 
                    new ShellRoute(
                        routeBase, 
                        _settingsA,
                        container.Resolve<IWorkContextAccessor>(),
                        container.Resolve<IRunningShellTable>(), 
                        objects => { return null; }));

            var routeA = new Route("foo", new MvcRouteHandler());
            var route1 = buildShellRoute(routeA);

            var routeB = new Route("bar", new MvcRouteHandler()) {
                DataTokens = new RouteValueDictionary { { "area", _settingsB.Name } }
            };
            var route2 = buildShellRoute(routeB);

            Assert.That(route1, Is.Not.SameAs(route2));

            Assert.That(route1.ShellSettingsName, Is.EqualTo(_settingsA.Name));
            Assert.That(route1.Area, Is.Null);

            Assert.That(route2.ShellSettingsName, Is.EqualTo(_settingsA.Name));
            Assert.That(route2.Area, Is.EqualTo(_settingsB.Name));
        }
 protected override void Register(ContainerBuilder builder)
 {
     builder.RegisterAutoMocking(MockBehavior.Loose);
     builder.RegisterModule(new WorkContextModule());
     builder.RegisterType<WorkContextAccessor>().As<IWorkContextAccessor>();
     builder.RegisterType<SweepGenerator>();
 }
        public void Init() {
            var builder = new ContainerBuilder();
            //builder.RegisterModule(new ImplicitCollectionSupportModule());
            builder.RegisterType<MembershipService>().As<IMembershipService>();
            builder.RegisterType<DefaultContentQuery>().As<IContentQuery>();
            builder.RegisterType<DefaultContentManager>().As<IContentManager>();
            builder.RegisterType<StubCacheManager>().As<ICacheManager>();
            builder.RegisterType<Signals>().As<ISignals>();
            builder.RegisterType(typeof(SettingsFormatter)).As<ISettingsFormatter>();
            builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
            builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
            builder.RegisterInstance(new ShellSettings { Name = ShellSettings.DefaultName, DataProvider = "SqlCe" });
            builder.RegisterType<UserPartHandler>().As<IContentHandler>();
            builder.RegisterType<StubWorkContextAccessor>().As<IWorkContextAccessor>();
            builder.RegisterType<OrchardServices>().As<IOrchardServices>();
            builder.RegisterAutoMocking(MockBehavior.Loose);
            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
            builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
            builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
            builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
            builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
            builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
            builder.RegisterType<InfosetHandler>().As<IContentHandler>();

            _session = _sessionFactory.OpenSession();
            builder.RegisterInstance(new TestTransactionManager(_session)).As<ITransactionManager>();

            _container = builder.Build();
            _membershipService = _container.Resolve<IMembershipService>();
        }
        public void Init() {
            var builder = new ContainerBuilder();
            //builder.RegisterModule(new ImplicitCollectionSupportModule());
            builder.RegisterType<MembershipService>().As<IMembershipService>();
            builder.RegisterType<DefaultContentQuery>().As<IContentQuery>();
            builder.RegisterType<DefaultContentManager>().As<IContentManager>();
            builder.RegisterType(typeof(SettingsFormatter))
                .As(typeof(IMapper<XElement, SettingsDictionary>))
                .As(typeof(IMapper<SettingsDictionary, XElement>));
            builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
            builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
            builder.RegisterType<UserPartHandler>().As<IContentHandler>();
            builder.RegisterType<StubWorkContextAccessor>().As<IWorkContextAccessor>();
            builder.RegisterType<OrchardServices>().As<IOrchardServices>();
            builder.RegisterAutoMocking(MockBehavior.Loose);
            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
            builder.RegisterInstance(new Mock<IMessageEventHandler>().Object);
            builder.RegisterType<DefaultMessageManager>().As<IMessageManager>();
            builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
            builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
            builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
            builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();

            _session = _sessionFactory.OpenSession();
            builder.RegisterInstance(new TestSessionLocator(_session)).As<ISessionLocator>();
            _container = builder.Build();
            _membershipService = _container.Resolve<IMembershipService>();
        }
        public void Init() {
            var builder = new ContainerBuilder();
            builder.RegisterAutoMocking();
            builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
            builder.RegisterType(typeof(SettingsFormatter))
                .As(typeof(IMapper<XElement, SettingsDictionary>))
                .As(typeof(IMapper<SettingsDictionary, XElement>));
            builder.RegisterType<Signals>().As<ISignals>();
            builder.RegisterType<StubCacheManager>().As<ICacheManager>();
            builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();

            _container = builder.Build();

            _container.Mock<ISessionLocator>()
                .Setup(x => x.For(It.IsAny<Type>()))
                .Returns(() => _session);

            _session = _sessionFactory.OpenSession();
            foreach (var killType in new[] { typeof(ContentTypeDefinitionRecord), typeof(ContentPartDefinitionRecord), typeof(ContentFieldDefinitionRecord) }) {
                foreach (var killRecord in _session.CreateCriteria(killType).List()) {
                    _session.Delete(killRecord);
                }
            }
            _session.Flush();
        }
        public void Init() {
            _session = _sessionFactory.OpenSession();
            foreach (var killType in new[] { typeof(ContentTypeDefinitionRecord), typeof(ContentPartDefinitionRecord), typeof(ContentFieldDefinitionRecord) }) {
                foreach (var killRecord in _session.CreateCriteria(killType).List()) {
                    _session.Delete(killRecord);
                }
            }
            _session.Flush();
            _session.Close();
            _session.Dispose();
            _session = _sessionFactory.OpenSession();

            var builder = new ContainerBuilder();
            builder.RegisterAutoMocking();
            builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
            builder.RegisterType(typeof(SettingsFormatter)).As(typeof(ISettingsFormatter));
            builder.RegisterType<Signals>().As<ISignals>();
            builder.RegisterType<StubCacheManager>().As<ICacheManager>();
            builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();

            _session = _sessionFactory.OpenSession();
            builder.RegisterInstance(_transactionManager = new TestTransactionManager(_session)).As<ITransactionManager>();

            _container = builder.Build();

        }
Exemplo n.º 7
0
        public void FactoryMethodWillCreateShellRoutes() {
            var settings = new ShellSettings { Name = "Alpha" };
            var builder = new ContainerBuilder();
            builder.RegisterType<ShellRoute>().InstancePerDependency();
            builder.RegisterAutoMocking();
            builder.Register(ctx => settings);

            var container = builder.Build();
            var buildShellRoute = container.Resolve<Func<RouteBase, ShellRoute>>();

            var routeA = new Route("foo", new MvcRouteHandler());
            var route1 = buildShellRoute(routeA);

            var routeB = new Route("bar", new MvcRouteHandler()) {
                DataTokens = new RouteValueDictionary { { "area", "Beta" } }
            };
            var route2 = buildShellRoute(routeB);

            Assert.That(route1, Is.Not.SameAs(route2));

            Assert.That(route1.ShellSettingsName, Is.EqualTo("Alpha"));
            Assert.That(route1.Area, Is.Null);

            Assert.That(route2.ShellSettingsName, Is.EqualTo("Alpha"));
            Assert.That(route2.Area, Is.EqualTo("Beta"));
        }
        public void Init() {
            var builder = new ContainerBuilder();
            builder.RegisterType<DefaultProcessingEngine>().As<IProcessingEngine>();
            builder.RegisterModule(new WorkContextModule());
            builder.RegisterType<WorkContextAccessor>().As<IWorkContextAccessor>();
            builder.RegisterAutoMocking(MockBehavior.Loose);
            _container = builder.Build();

            _shellContext = new ShellContext {
                Descriptor = new ShellDescriptor(),
                Settings = new ShellSettings(),
                LifetimeScope = _container.BeginLifetimeScope(),
            };

            var httpContext = new StubHttpContext();

            _container.Mock<IShellContextFactory>()
                .Setup(x => x.CreateDescribedContext(_shellContext.Settings, _shellContext.Descriptor))
                .Returns(_shellContext);
            _container.Mock<IHttpContextAccessor>()
                .Setup(x=>x.Current())
                .Returns(httpContext);
            _container.Mock<IHttpContextAccessor>()
                .Setup(x => x.CreateContext(It.IsAny<ILifetimeScope>()))
                .Returns(httpContext);

        }
 public void Init() {
     var builder = new ContainerBuilder();
     builder.RegisterType<ShellContextFactory>().As<IShellContextFactory>();
     builder.RegisterModule(new WorkContextModule());
     builder.RegisterType<WorkContextAccessor>().As<IWorkContextAccessor>();
     builder.RegisterAutoMocking(Moq.MockBehavior.Strict);
     _container = builder.Build();
 }
        public void Init() {
            _routes = new RouteCollection();

            var builder = new ContainerBuilder();
            builder.RegisterType<RoutePublisher>().As<IRoutePublisher>();
            builder.RegisterType<ShellRoute>().InstancePerDependency();
            builder.Register(ctx => _routes);
            builder.Register(ctx => new ShellSettings { Name = ShellSettings.DefaultName });
            builder.RegisterAutoMocking();
            _container = builder.Build();
        }
        // Building a testing dependency injection container with mocked and stubbed types. See: http://code.google.com/p/moq/
        public override void Register(ContainerBuilder builder)
        {
            // If any unregistered type is requested from the container a dynamic mock will be created for it.
            builder.RegisterAutoMocking(MockBehavior.Loose);

            // Despite that Repository is registered in DatabaseEnabledTestsBase it should be re-registered somehow!
            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
            // Registering a collection. If we would just register an instance the injected IEnumerable<IPersonFilter> would have two items,
            // one mocked, what messes up biography...
            builder.RegisterInstance(new IPersonFilter[] { new StubPersonFilter() }).As<IEnumerable<IPersonFilter>>();

            builder.RegisterType<PersonManager>().As<IPersonManager>();
        }
Exemplo n.º 12
0
        public void Init() {
            var builder = new ContainerBuilder();
            var assetFactoryMock = new Mock<IAssetFactory>();

            _stubAssetRepository = new StubRepository<AssetRecord>();
            assetFactoryMock.Setup(x => x.Create(It.IsAny<string>())).Returns(new VideoAsset());
            
            builder.RegisterInstance(_stubAssetRepository);
            builder.RegisterInstance(assetFactoryMock.Object);
            builder.RegisterType<AssetManager>().As<IAssetManager>();
            builder.RegisterAutoMocking(MockBehavior.Loose);

            _container = builder.Build();
        }
Exemplo n.º 13
0
        public override void Register(ContainerBuilder builder) {
            _authz = new Mock<IAuthorizationService>();

            builder.RegisterAutoMocking(MockBehavior.Loose);
            builder.RegisterInstance(_authz.Object).As<IAuthorizationService>();
            builder.RegisterType<StubWorkContextAccessor>().As<IWorkContextAccessor>();
            builder.RegisterType<TagService>().As<ITagService>();
            builder.RegisterType<Notifier>().As<INotifier>();
            builder.RegisterType<ThingHandler>().As<IContentHandler>();
            builder.RegisterType<TagsPartHandler>().As<IContentHandler>();
            builder.RegisterType<OrchardServices>().As<IOrchardServices>();
            builder.RegisterType<DefaultContentManager>().As<IContentManager>();
            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
        }
Exemplo n.º 14
0
        public virtual void Init()
        {
            var builder = new ContainerBuilder();

            builder.RegisterAutoMocking(MockBehavior.Loose);

            builder.RegisterInstance(new StubVirtualPathProvider(new StubFileSystem(new StubClock()))).As<IVirtualPathProvider>();
            builder.RegisterType<ResourceFileService>().As<IResourceFileService>();

            CombinatorResourceHelper.Register(builder);

            _container = builder.Build();

            _resourceRepository = new ResourceRepository(_container);
            _resourceFileService = _container.Resolve<IResourceFileService>();
        }
        public void Init() {
            var builder = new ContainerBuilder();
            builder.RegisterType<CompositionStrategy>().As<ICompositionStrategy>();
            builder.RegisterAutoMocking(MockBehavior.Strict);
            _container = builder.Build();

            _extensionDescriptors = Enumerable.Empty<ExtensionDescriptor>();
            _featureTypes = new Dictionary<string, IEnumerable<Type>>();

            _container.Mock<IExtensionManager>()
                .Setup(x => x.AvailableExtensions())
                .Returns(() => _extensionDescriptors);

            _container.Mock<IExtensionManager>()
                .Setup(x => x.LoadFeatures(It.IsAny<IEnumerable<FeatureDescriptor>>()))
                .Returns((IEnumerable<FeatureDescriptor> x) => StubLoadFeatures(x));
        }
        public virtual void Init()
        {
            var builder = new ContainerBuilder();

            builder.RegisterAutoMocking(MockBehavior.Loose);

            builder.RegisterInstance(new StubMinificationService()).As<IMinificationService>();
            builder.RegisterType<ResourceProcessingService>().As<IResourceProcessingService>();

            _container = builder.Build();

            _resourceRepository = new ResourceRepository(_container);

            builder = new ContainerBuilder();
            builder.RegisterInstance(new StubResourceFileService(_resourceRepository)).As<IResourceFileService>();
            builder.Update(_container);

            _resourceProcessingService = _container.Resolve<IResourceProcessingService>();
        }
 protected override void Register(ContainerBuilder builder) {
     if (builder == null) {
         throw new ArgumentNullException("builder");
     }
     builder.RegisterAutoMocking();
     _testFeature = new Feature {
         Descriptor = new FeatureDescriptor {
             Id = "Testing",
             Extension = new ExtensionDescriptor {
                 Id = "Testing",
                 ExtensionType = DefaultExtensionTypes.Module,
             }
         }
     };
     builder.RegisterType<ShapeAttributeBindingStrategy>().As<IShapeTableProvider>();
     builder.RegisterInstance(new TestProvider()).WithMetadata("Feature", _testFeature);
     builder.RegisterInstance(new RouteCollection());
     builder.RegisterModule(new ShapeAttributeBindingModule());
 }
Exemplo n.º 18
0
        public override void Register(ContainerBuilder builder)
        {
            builder.RegisterAutoMocking(MockBehavior.Loose);

            builder.RegisterInstance(new StubStorageProvider(new ShellSettings { Name = ShellSettings.DefaultName })).As<IStorageProvider>();
            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
            builder.RegisterInstance(_clock).As<IClock>();
            builder.RegisterInstance(new Mock<UrlHelper>().Object).As<UrlHelper>();
            builder.RegisterType<StubCacheService>().As<ICacheService>();

            builder.Register(c =>
                {
                    var mock = new Mock<CombinatorResource>();
                    mock.SetupProperty(r => r.Content);
                    mock.SetupProperty(r => r.Type);
                    return mock.Object;
                }).As<CombinatorResource>();

            builder.RegisterType<CacheFileService>().As<ICacheFileService>();
        }
        public virtual void Init()
        {
            var builder = new ContainerBuilder();

            builder.RegisterAutoMocking(MockBehavior.Loose);

            builder.RegisterType<StubCacheManager>().As<ICacheManager>();
            builder.RegisterType<DefaultContentManager>().As<IContentManager>();
            builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
            builder.RegisterType<ContentDefinitionWriter>().As<IContentDefinitionWriter>();
            builder.RegisterType<StubOrchardServices>().As<IOrchardServices>();
            builder.RegisterType<StubAppDataFolder>().As<IAppDataFolder>();
            builder.RegisterType<Signals>().As<ISignals>();
            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
            builder.RegisterInstance(new ShellSettings { Name = "Default" }).As<ShellSettings>();
            builder.RegisterInstance(new Mock<ISettingsFormatter>().Object);
            _session = _sessionFactory.OpenSession();
            builder.RegisterInstance(new DefaultContentManagerTests.TestSessionLocator(_session)).As<ISessionLocator>();

            _container = builder.Build();
        }
Exemplo n.º 20
0
        public void Init() {
            var testFeature = new Feature
            {
                Descriptor = new FeatureDescriptor
                {
                    Id = "Testing",
                    Extension = new ExtensionDescriptor
                    {
                        Id = "Testing",
                        ExtensionType = DefaultExtensionTypes.Module,
                    }
                }
            };

            var workContext = new DefaultDisplayManagerTests.TestWorkContext
            {
                CurrentTheme = new ExtensionDescriptor { Id = "Hello" }
            };

            var builder = new ContainerBuilder();
            builder.RegisterModule(new ShapeAttributeBindingModule());
            builder.RegisterType<ShapeAttributeBindingStrategy>().As<IShapeTableProvider>();
            builder.RegisterType<ShapeTableLocator>().As<IShapeTableLocator>();
            builder.RegisterType<DefaultDisplayManager>().As<IDisplayManager>();
            builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
            builder.RegisterType<DisplayHelperFactory>().As<IDisplayHelperFactory>();
            builder.RegisterInstance(new Work<IEnumerable<IShapeTableEventHandler>>(resolve => _container.Resolve<IEnumerable<IShapeTableEventHandler>>())).AsSelf();
            builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
            builder.RegisterType<StubCacheManager>().As<ICacheManager>();
            builder.RegisterType<StubParallelCacheContext>().As<IParallelCacheContext>();
            builder.RegisterInstance(new DefaultDisplayManagerTests.TestWorkContextAccessor(workContext)).As<IWorkContextAccessor>();
            builder.RegisterInstance(new SimpleShapes()).WithMetadata("Feature", testFeature);
            builder.RegisterInstance(new RouteCollection());
            builder.RegisterAutoMocking(MockBehavior.Loose);

            _container = builder.Build();
            _container.Resolve<Mock<IOrchardHostContainer>>()
                .Setup(x => x.Resolve<IComponentContext>())
                .Returns(_container);
        }
        public void Init()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType<MembershipService>().As<IMembershipService>();
            builder.RegisterType<UserService>().As<IUserService>();
            builder.RegisterInstance(_clock = new StubClock()).As<IClock>();
            builder.RegisterType<DefaultContentQuery>().As<IContentQuery>();
            builder.RegisterType<DefaultContentManager>().As<IContentManager>();
            builder.RegisterType<StubCacheManager>().As<ICacheManager>();
            builder.RegisterType<Signals>().As<ISignals>();
            builder.RegisterType(typeof(SettingsFormatter)).As<ISettingsFormatter>();
            builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
            builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
            builder.RegisterType<UserPartHandler>().As<IContentHandler>();
            builder.RegisterType<StubWorkContextAccessor>().As<IWorkContextAccessor>();
            builder.RegisterType<CoeveryServices>().As<ICoeveryServices>();
            builder.RegisterAutoMocking(MockBehavior.Loose);
            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
            builder.RegisterInstance(new Mock<IMessageEventHandler>().Object);
            builder.RegisterType<DefaultMessageManager>().As<IMessageManager>();
            builder.RegisterInstance(_channel = new MessagingChannelStub()).As<IMessagingChannel>();
            builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
            builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
            builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
            builder.RegisterInstance(new Mock<IPageClassBuilder>().Object);
            builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
            builder.RegisterType<InfosetHandler>().As<IContentHandler>();

            builder.RegisterType<DefaultEncryptionService>().As<IEncryptionService>();
            builder.RegisterInstance(ShellSettingsUtility.CreateEncryptionEnabled());

            _session = _sessionFactory.OpenSession();
            _session.BeginTransaction();

            builder.RegisterInstance(new TestSessionLocator(_session)).As<ISessionLocator>();
            _container = builder.Build();
            _membershipService = _container.Resolve<IMembershipService>();
            _userService = _container.Resolve<IUserService>();
        }
 public void Init() {
     var builder = new ContainerBuilder();
     builder.RegisterType<ShellContextFactory>().As<IShellContextFactory>();
     builder.RegisterAutoMocking(Moq.MockBehavior.Strict);
     _container = builder.Build();
 }
Exemplo n.º 23
0
        public virtual void Init()
        {
            var builder = new ContainerBuilder();

            builder.RegisterAutoMocking(MockBehavior.Loose);

            builder.RegisterType<StubCacheFileService>().As<ICacheFileService>();
            builder.RegisterInstance(new StubResourceProcessingService()).As<IResourceProcessingService>();
            builder.RegisterType<StubCacheService>().As<ICacheService>();

            builder.RegisterType<CombinatorService>().As<ICombinatorService>();

            _container = builder.Build();

            _resourceRepository = new ResourceRepository(_container);

            builder = new ContainerBuilder();
            builder.RegisterInstance(_resourceRepository).As<ResourceRepository>(); // For StubCacheFileService
            builder.Update(_container);

            _combinatorService = _container.Resolve<ICombinatorService>();
        }
Exemplo n.º 24
0
        public void RequestUrlPrefixAdjustsMatchingAndPathGeneration() {
            var settings = new ShellSettings { RequestUrlPrefix = "~/foo" };

            var builder = new ContainerBuilder();
            builder.RegisterType<ShellRoute>().InstancePerDependency();
            builder.RegisterAutoMocking();
            builder.Register(ctx => settings);

            var container = builder.Build();
            container.Mock<IRunningShellTable>()
                .Setup(x => x.Match(It.IsAny<HttpContextBase>()))
                .Returns(settings);


            var shellRouteFactory = container.Resolve<Func<RouteBase, ShellRoute>>();

            var helloRoute = shellRouteFactory(new Route(
                "hello",
                new RouteValueDictionary { { "controller", "foo" }, { "action", "bar" } },
                new MvcRouteHandler()));

            var tagsRoute = shellRouteFactory(new Route(
                "tags/{tagName}",
                new RouteValueDictionary { { "controller", "tags" }, { "action", "show" } },
                new MvcRouteHandler()));

            var defaultRoute = shellRouteFactory(new Route(
                "{controller}/{action}",
                new RouteValueDictionary { { "controller", "home" }, { "action", "index" } },
                new MvcRouteHandler()));

            var routes = new RouteCollection { helloRoute, tagsRoute, defaultRoute };

            var helloRouteData = routes.GetRouteData(new StubHttpContext("~/Foo/Hello"));
            Assert.That(helloRouteData, Is.Not.Null);
            Assert.That(helloRouteData.Values.Count(), Is.EqualTo(2));
            Assert.That(helloRouteData.GetRequiredString("controller"), Is.EqualTo("foo"));
            Assert.That(helloRouteData.GetRequiredString("action"), Is.EqualTo("bar"));

            var tagsRouteData = routes.GetRouteData(new StubHttpContext("~/Foo/Tags/my-tag-name"));
            Assert.That(tagsRouteData, Is.Not.Null);
            Assert.That(tagsRouteData.Values.Count(), Is.EqualTo(3));
            Assert.That(tagsRouteData.GetRequiredString("controller"), Is.EqualTo("tags"));
            Assert.That(tagsRouteData.GetRequiredString("action"), Is.EqualTo("show"));
            Assert.That(tagsRouteData.GetRequiredString("tagName"), Is.EqualTo("my-tag-name"));

            var defaultRouteData = routes.GetRouteData(new StubHttpContext("~/Foo/Alpha/Beta"));
            Assert.That(defaultRouteData, Is.Not.Null);
            Assert.That(defaultRouteData.Values.Count(), Is.EqualTo(2));
            Assert.That(defaultRouteData.GetRequiredString("controller"), Is.EqualTo("Alpha"));
            Assert.That(defaultRouteData.GetRequiredString("action"), Is.EqualTo("Beta"));

            var defaultRouteData2 = routes.GetRouteData(new StubHttpContext("~/Foo/Alpha"));
            Assert.That(defaultRouteData2, Is.Not.Null);
            Assert.That(defaultRouteData2.Values.Count(), Is.EqualTo(2));
            Assert.That(defaultRouteData2.GetRequiredString("controller"), Is.EqualTo("Alpha"));
            Assert.That(defaultRouteData2.GetRequiredString("action"), Is.EqualTo("index"));

            var defaultRouteData3 = routes.GetRouteData(new StubHttpContext("~/Foo/"));
            Assert.That(defaultRouteData3, Is.Not.Null);
            Assert.That(defaultRouteData3.Values.Count(), Is.EqualTo(2));
            Assert.That(defaultRouteData3.GetRequiredString("controller"), Is.EqualTo("home"));
            Assert.That(defaultRouteData3.GetRequiredString("action"), Is.EqualTo("index"));

            var defaultRouteData4 = routes.GetRouteData(new StubHttpContext("~/Foo"));
            Assert.That(defaultRouteData4, Is.Not.Null);
            Assert.That(defaultRouteData4.Values.Count(), Is.EqualTo(2));
            Assert.That(defaultRouteData4.GetRequiredString("controller"), Is.EqualTo("home"));
            Assert.That(defaultRouteData4.GetRequiredString("action"), Is.EqualTo("index"));

            var requestContext = new RequestContext(new StubHttpContext("~/Foo/Alpha/Beta"), defaultRouteData);
            var helloVirtualPath = routes.GetVirtualPath(requestContext, helloRouteData.Values);
            Assert.That(helloVirtualPath, Is.Not.Null);
            Assert.That(helloVirtualPath.VirtualPath, Is.EqualTo("~/foo/hello"));

            var defaultVirtualPath4 = routes.GetVirtualPath(requestContext, defaultRouteData4.Values);
            Assert.That(defaultVirtualPath4, Is.Not.Null);
            Assert.That(defaultVirtualPath4.VirtualPath, Is.EqualTo("~/foo/"));
        }
        public void Init()
        {
            var builder = new ContainerBuilder();

            builder.RegisterAutoMocking(MockBehavior.Loose);
            builder.RegisterInstance(new StubGraphDescriptor()).As<IGraphDescriptor>();
            builder.RegisterInstance(new StubCacheService()).As<ICacheService>();
            builder.RegisterType<MemoryConnectionManager>().As<IMemoryConnectionManager>();

            _container = builder.Build();

            _memoryConnectionManager = _container.Resolve<IMemoryConnectionManager>();

            SetupTestGraph();
        }
Exemplo n.º 26
0
 public void Init() {
     var context = new DynamicProxyContext();
     var builder = new ContainerBuilder();
     builder.RegisterType<StubWorkContextAccessor>().As<IWorkContextAccessor>();
     builder.RegisterType<ThemeService>().EnableDynamicProxy(context).As<IThemeService>();
     builder.RegisterType<SiteService>().As<ISiteService>();
     builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>));
     builder.RegisterType<Orchard.Localization.Text>().As<IText>();
     builder.RegisterType<DefaultContentManager>().As<IContentManager>();
     builder.RegisterType<StubCacheManager>().As<ICacheManager>();
     builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
     builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
     builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
     builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
     builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
     builder.RegisterType<DefaultContentQuery>().As<IContentQuery>();
     builder.RegisterType<SiteSettingsPartHandler>().As<IContentHandler>();
     builder.RegisterType<ThemeSiteSettingsPartHandler>().As<IContentHandler>();
     //builder.RegisterType<ModuleService>().As<IModuleService>();
     builder.RegisterType<ShellDescriptor>();
     builder.RegisterType<OrchardServices>().As<IOrchardServices>();
     builder.RegisterType<StubShellDescriptorManager>().As<IShellDescriptorManager>().InstancePerLifetimeScope();
     builder.RegisterType<TransactionManager>().As<ITransactionManager>();
     builder.RegisterType<Notifier>().As<INotifier>();
     builder.RegisterType<StubAuthorizer>().As<IAuthorizer>();
     builder.RegisterType<DefaultContentDisplay>().As<IContentDisplay>();
     builder.RegisterType(typeof(SettingsFormatter))
         .As(typeof(IMapper<XElement, SettingsDictionary>))
         .As(typeof(IMapper<SettingsDictionary, XElement>));
     _session = _sessionFactory.OpenSession();
     builder.RegisterInstance(new TestSessionLocator(_session)).As<ISessionLocator>();
     builder.RegisterAutoMocking(MockBehavior.Loose);
     _container = builder.Build();
     _themeService = _container.Resolve<IThemeService>();
     _siteThemeService = _container.Resolve<ISiteThemeService>();
     _featureManager = _container.Resolve<IFeatureManager>();
 }
 protected override void Register(ContainerBuilder builder) {
     builder.RegisterModule(new WorkContextModule());
     builder.RegisterType<WorkContextAccessor>().As<IWorkContextAccessor>();
     builder.RegisterAutoMocking();
 }