Exemplo n.º 1
0
        public void TestInit()
        {
            di = new UnityRegistrar();
            di.ConnectToServiceLocator();

            var context = Ax.FakeContext <IExampleDomainContext>();

            di.RegisterAsSingleInstance(context);

            examples = new List <ExampleModel>();
            Ax.UseList(() => context.Examples, examples);

            A.CallTo(() => context.Examples.Update(A <ExampleModel> .Ignored)).Invokes(call =>
            {
                var example = (ExampleModel)call.Arguments[0];
                examples.RemoveAll(x => x.Id == example.Id);
                examples.Add(example);
            });

            A.CallTo(() => context.Examples.Delete(A <Expression <Func <ExampleModel, bool> > > .Ignored)).Invokes(
                call =>
            {
                var predicate = (Expression <Func <ExampleModel, bool> >)call.Arguments[0];
                examples.RemoveAll(x => predicate.Compile()(x));
            });

            service = new ExampleService();
        }
        public void SetupDi(HttpConfiguration httpConfig, IAppBuilder app)
        {
            //Set up Autofac for DI
            var builder = new ContainerBuilder();

            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            DiRegistrar.RegisterRepositories(builder);
            DiRegistrar.RegisterServices(builder);
            DiRegistrar.RegisterMapper(builder);
            var container = builder.Build();

            httpConfig.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
Exemplo n.º 3
0
        public void Setup()
        {
            var iConfig  = TestsHelpers.GetConfigurationRoot(TestContext.CurrentContext.TestDirectory);
            var config   = TestsHelpers.GetApplicationConfiguration(TestContext.CurrentContext.TestDirectory);
            var services = new ServiceCollection();

            services.AddSingleton(iConfig);
            services.AddSingleton(config);
            services.AddDbContext <SageX3Context>(builder =>
            {
                builder.UseSqlServer(config.SageX3ConnectionString, opt =>
                {
                    opt.EnableRetryOnFailure();
                    opt.CommandTimeout(15);
                });
            }, ServiceLifetime.Transient);

            services.AddDbContext <X3SageDbContext>(builder =>
            {
                builder.UseSqlServer(config.SageX3ConnectionString, opt =>
                {
                    opt.EnableRetryOnFailure();
                    opt.CommandTimeout(15);
                });
            }, ServiceLifetime.Transient);


            services.AddDbContext <OfApiDbContext>(builder =>
            {
                builder.UseSqlServer(config.OfApiConnectionString, opt =>
                {
                    opt.EnableRetryOnFailure();
                    opt.CommandTimeout(15);
                });
            }, ServiceLifetime.Transient);

            DiRegistrar.InjectDependencies(services, iConfig);
            ServiceProvider = services.BuildServiceProvider();
        }
Exemplo n.º 4
0
 private static void RegisterDbContexts(DiRegistrar di)
 {
     di.RegisterAsTransient <IUnitOfWork>(() => new UnitOfWork());
     //di.RegisterAsTransient<IDictionariesEntities, DictionariesEntities>();
     di.RegisterAsTransient <IHotelContext, HotelContext>();
 }
Exemplo n.º 5
0
 private static void RegisterHealthMonitors(DiRegistrar di)
 {
     HealthMonitorAggregator.RegisterHealthMonitor <SqlHealthMonitor>(di);
 }