当前位置: 首页>>代码示例>>C#>>正文


C# ContainerBuilder.RegisterAutoMocking方法代码示例

本文整理汇总了C#中Autofac.ContainerBuilder.RegisterAutoMocking方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.RegisterAutoMocking方法的具体用法?C# ContainerBuilder.RegisterAutoMocking怎么用?C# ContainerBuilder.RegisterAutoMocking使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Autofac.ContainerBuilder的用法示例。


在下文中一共展示了ContainerBuilder.RegisterAutoMocking方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FactoryMethodWillCreateShellRoutes

        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));
        }
开发者ID:SunRobin2015,项目名称:RobinWithOrchard,代码行数:30,代码来源:ShellRouteTests.cs

示例2: Register

 protected override void Register(ContainerBuilder builder)
 {
     builder.RegisterAutoMocking(MockBehavior.Loose);
     builder.RegisterModule(new WorkContextModule());
     builder.RegisterType<WorkContextAccessor>().As<IWorkContextAccessor>();
     builder.RegisterType<SweepGenerator>();
 }
开发者ID:gokhandisikara,项目名称:Coevery-Framework,代码行数:7,代码来源:SweepGeneratorTests.cs

示例3: Init

        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>();
        }
开发者ID:SunRobin2015,项目名称:RobinWithOrchard,代码行数:30,代码来源:MembershipServiceTests.cs

示例4: Init

        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>();
        }
开发者ID:juaqaai,项目名称:CompanyGroup,代码行数:28,代码来源:MembershipServiceTests.cs

示例5: Init

        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();
        }
开发者ID:rupertwhitlock,项目名称:IncreasinglyAbsorbing,代码行数:26,代码来源:ContentDefinitionManagerTests.cs

示例6: Init

        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();

        }
开发者ID:Golone,项目名称:Orchard,代码行数:27,代码来源:ContentDefinitionManagerTests.cs

示例7: FactoryMethodWillCreateShellRoutes

        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"));
        }
开发者ID:dioptre,项目名称:nkd,代码行数:26,代码来源:ShellRouteTests.cs

示例8: Init

        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);

        }
开发者ID:killgitbug,项目名称:Orchard,代码行数:27,代码来源:DefaultProcessingEngineTests.cs

示例9: Init

 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();
 }
开发者ID:anycall,项目名称:Orchard,代码行数:8,代码来源:DefaultShellContextFactoryTests.cs

示例10: Init

        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();
        }
开发者ID:jecofang01,项目名称:OrchardNoCMS,代码行数:11,代码来源:RouteCollectionPublisherTests.cs

示例11: Register

        // 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>();
        }
开发者ID:hyrmedia,项目名称:Orchard-Training-Demo-Module,代码行数:14,代码来源:PersonManagerTests.cs

示例12: Init

        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();
        }
开发者ID:RasterImage,项目名称:Orchard,代码行数:14,代码来源:AzureMediaManagerTests.cs

示例13: Register

        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<>));
        }
开发者ID:Vinna,项目名称:DeepInSummer,代码行数:14,代码来源:TagsServiceTests.cs

示例14: Init

        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>();
        }
开发者ID:Timbioz,项目名称:SciGitAzure,代码行数:16,代码来源:ResourceFileServiceTests.cs

示例15: Init

        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));
        }
开发者ID:mofashi2011,项目名称:orchardcms,代码行数:17,代码来源:DefaultCompositionStrategyTests.cs


注:本文中的Autofac.ContainerBuilder.RegisterAutoMocking方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。