本文整理汇总了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));
}
示例2: Register
protected override void Register(ContainerBuilder builder)
{
builder.RegisterAutoMocking(MockBehavior.Loose);
builder.RegisterModule(new WorkContextModule());
builder.RegisterType<WorkContextAccessor>().As<IWorkContextAccessor>();
builder.RegisterType<SweepGenerator>();
}
示例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>();
}
示例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>();
}
示例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();
}
示例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();
}
示例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"));
}
示例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);
}
示例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();
}
示例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();
}
示例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>();
}
示例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();
}
示例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<>));
}
示例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>();
}
示例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));
}