/* Uses single database for host and all tenants. */ private void UseSingleDatabase() { _hostDb = DbConnectionFactory.CreateTransient(); LocalIocManager.IocContainer.Register( Component.For <DbConnection>() .UsingFactoryMethod(() => _hostDb) .LifestyleSingleton() ); }
public EmptyContext() { var clockMock = new Mock <IClock>(); clockMock.Setup(c => c.Now()).Returns(25.December(2020).At(4, 20)); var connection = DbConnectionFactory.CreateTransient(); _context = new AppDbContext(connection, clockMock.Object); _context.Database.CreateIfNotExists(); }
public void Initialize() { this.connection = (EffortConnection)DbConnectionFactory.CreateTransient(); this.context = new FeatureDbContext( connection, CompiledModels.GetModel <RequiredFieldEntity>()); this.context.Configuration.ValidateOnSaveEnabled = false; }
public Form_Request_GuidSetIdentityFields() { InitializeComponent(); var connection = (EffortConnection)DbConnectionFactory.CreateTransient(); // MUST initialize first with the context with identity (Required for SetIdentityFields(false) using (var context = new EntityContext(connection)) { context.Database.CreateIfNotExists(); } // MUST open connection first (Required for SetIdentityFields(false) connection.Open(); connection.DbManager.SetIdentityFields(false); connection.Close(); // SEED using (var context = new EntityContextNoIdentity(connection)) { //context.EntitySimples.Add(new EntitySimple { Id = 10, ColumnInt = 1 }); //context.EntitySimples.Add(new EntitySimple { Id = 11, ColumnInt = 2 }); //context.EntitySimples.Add(new EntitySimple { Id = 12, ColumnInt = 3 }); context.EntitySimples.Add(new EntitySimple { Id = new Guid("0FA0F3D7-57CB-42BB-819A-BB9C4D0645CC"), ColumnInt = 1 }); context.EntitySimples.Add(new EntitySimple { Id = new Guid("C3E9517D-B444-4F56-B459-5B9804C03FE1"), ColumnInt = 2 }); context.EntitySimples.Add(new EntitySimple { Id = new Guid("A02E175C-C050-4996-AD42-B722BE1E7FF1"), ColumnInt = 3 }); context.SaveChanges(); } // MUST open connection first (Required for SetIdentityFields(false) connection.Open(); connection.DbManager.SetIdentityFields(true); connection.Close(); // TEST using (var context = new EntityContext(connection)) { context.EntitySimples.Add(new EntitySimple() { ColumnInt = 4 }); context.SaveChanges(); var list = context.EntitySimples.ToList(); } }
private void UseInMemoryDb(IServiceProvider serviceProvider) { var _hostDb = DbConnectionFactory.CreateTransient(); var iocManager = serviceProvider.GetRequiredService <IIocManager>(); iocManager.IocContainer.Register( Component.For <DbConnection>() .UsingFactoryMethod(() => _hostDb) .LifestyleSingleton() ); }
public DbConnection CreateConnection(string nameOrConnectionString) { lock (_lock) { if (_connection == null) { _connection = DbConnectionFactory.CreateTransient(); } return(_connection); } }
public void Setup() { // TODO: Test if this prevents the first test from running really long DbConnection connection = DbConnectionFactory.CreateTransient(); using (var context = new GwintContext(connection)) { context.Cards.Add(new Card()); context.SaveChanges(); } }
public void Initialize() { //Creates a DbConnection object that rely on an in-memory database instance that //lives during the connection object lifecycle. If the connection object is disposed //or garbage collected, then underlying database will be garbage collected too. //var connection = DbConnectionFactory.CreateTransient(); var connection = DbConnectionFactory.CreateTransient(SetupTestData()); _context = new LibraryContext(connection); _recipeRepository = new Repository <Recipe>(_context); }
public void Initialize() { DbConnection connection = DbConnectionFactory.CreateTransient(); InitializeData(connection); this.context = new FeatureDbContext( connection, CompiledModels.GetModel <NumberFieldEntity>()); }
public void SetupTest() { var connection = DbConnectionFactory.CreateTransient(); _context = new PHSContext(connection); _unitOfWork = new MockUnitOfWork(_context); _formManager = new MockFormManager(_unitOfWork); _formAccessManager = new MockFormAccessManager(_unitOfWork); _target = new MockFormExportManager(_unitOfWork); }
public void BrowseGames() { DbConnection connection = DbConnectionFactory.CreateTransient(); var game = new Game { Id = 1, IsActive = true, State = new LobbyState(), Players = { new Player() } }; using (var gwintContext = new GwintContext(connection)) { gwintContext.Games.Add(game); gwintContext.SaveChanges(); } var scopeMock = new Mock <ILifetimeScope>(); scopeMock.SetupResolve <ILifetimeScope, IGwintContext>(new GwintContext(connection)); var userConnectionMapMock = new Mock <IUserConnectionMap>(); userConnectionMapMock.SetupMapping(); scopeMock.SetupResolve <ILifetimeScope, IUserConnectionMap>(userConnectionMapMock.Object); var rootScopeMock = new Mock <ILifetimeScope>(); rootScopeMock.Setup(s => s.BeginLifetimeScope()).Returns(scopeMock.Object); var clientsMock = new Mock <IHubCallerConnectionContext <dynamic> >(); clientsMock.SetupClients(); var userName = "******"; var userId = "1"; var connectionID = "13245"; var hubCallerContextMock = CreateHubCallerContextMock(userName, userId, connectionID); GameHub hub = new GameHub(rootScopeMock.Object) { Context = hubCallerContextMock.Object, Clients = clientsMock.Object }; var result = hub.BrowseGames(); Assert.Null(result.Error); var gameBrowseDtos = result.Data; Assert.NotNull(gameBrowseDtos); Assert.Equal(1, gameBrowseDtos.Count); Assert.Contains(gameBrowseDtos, g => g.Id == game.Id && g.State == game.State.Name && g.PlayerCount == game.Players.Count); }
public static void testBit() { var transit = DbConnectionFactory.CreateTransient(); using (var context = new ExampleModelA(transit)) { MyEntity test = new MyEntity(); test.Columnnboolean = false; test.Columnnsbit = false; test.Columnnuniqueidentifier = Guid.NewGuid(); test.Columnnuniqueiguid = Guid.NewGuid(); test.Columnnbyte = Byte.MaxValue; test.Columnnstinyint = Byte.MinValue; test.Columnnsbyte = SByte.MinValue; context.MyEntities.Add(test); context.SaveChanges(); } using (var context = new ExampleModelA(transit)) { var find1 = context.MyEntities.FirstOrDefault(); } var transit2 = DbConnectionFactory.CreateTransient(); using (var context = new ExampleModelA(transit2)) { MyEntity test = new MyEntity(); test.Columnnboolean = false; test.Columnnsbit = false; test.Columnnuniqueidentifier = Guid.NewGuid(); test.Columnnuniqueiguid = Guid.NewGuid(); test.Columnnbyte = Byte.MaxValue; test.Columnnstinyint = Byte.MinValue; test.Columnnsbyte = SByte.MinValue; context.MyEntities.Add(test); context.BulkSaveChanges(); } using (var context = new ExampleModelA(transit2)) { var find1 = context.MyEntities.FirstOrDefault(); } }
public void SetUp() { string connStr = ConfigurationManager.ConnectionStrings["BrewTodoDb"].ConnectionString; var connection = DbConnectionFactory.CreateTransient(); _context = new DbContext(connection); _userBeerTriedRepository = new UserBeerTriedRepository(_context); _breweryRepository = new BreweryRepository(_context); _userRepository = new UserRepository(_context); _beerRepository = new BeerRepository(_context); }
public void DbContext_Create() { DbConnection connection = DbConnectionFactory.CreateTransient(); FeatureDbContext context = new FeatureDbContext(connection); bool created1 = context.Database.CreateIfNotExists(); bool created2 = context.Database.CreateIfNotExists(); Assert.IsTrue(created1); Assert.IsFalse(created2); }
public void MyTestInitialize() { #if NET35 || NET40 _context = new BlogContext(DbConnectionFactory.CreateTransient()); #elif NETCORE var options = new DbContextOptionsBuilder <BlogContext>() .UseInMemoryDatabase(databaseName: this.TestContext.TestName) .Options; _context = new BlogContext(options); #endif }
public FullContext() { var clockMock = new Mock <IClock>(); clockMock.Setup(c => c.Now()).Returns(25.December(2020).At(4, 20)); var loader = new CsvDataLoader(@".\CsvFiles"); var connection = DbConnectionFactory.CreateTransient(loader); _context = new AppDbContext(connection, clockMock.Object); _context.Database.CreateIfNotExists(); }
public void LargePrimaryKeyCreation() { var connection = DbConnectionFactory.CreateTransient(); var context = new FeatureDbContext( connection, CompiledModels.GetModel <LargePrimaryKeyEntity>()); context.Database.CreateIfNotExists(); }
public void SetUp() { Effort.Provider.EffortProviderConfiguration.RegisterProvider(); var connection = DbConnectionFactory.CreateTransient(); _context = new SampleEntities(connection); _context.Fill(); _repo = new DataSourceRepository(); _repo.AddSource(_context.Things); }
public void DbContext_Insert() { DbConnection connection = DbConnectionFactory.CreateTransient(); FeatureDbContext context = new FeatureDbContext(connection); context.StringFieldEntities.Add(new StringFieldEntity { Value = "Foo" }); int count = context.SaveChanges(); Assert.AreEqual(1, count); }
public void Setup() { inMemoryConnection = DbConnectionFactory.CreateTransient(); using var context = new MarketDbContext(inMemoryConnection); context.Init(); storeHandler = new StoreHandler(); RegisteredUser owner = new RegisteredUser("OWNER", new byte[] { }); context.Users.Add(owner); context.SaveChanges(); Owner = owner.ID; }
public static CFAContext GetContext() { //EffortProviderConfiguration.RegisterProvider(); var connection = DbConnectionFactory.CreateTransient(); CFAContext context = new CFAContext(connection, true); Database.SetInitializer(new DropCreateDatabaseAlways <CFAContext>()); DataSeeder.SeedData(context); return(context); }
public void GetAllStudents() { var connection = DbConnectionFactory.CreateTransient(); var context = new StudentHostelContext(connection); StudentListViewModel viewModel = new StudentListViewModel(context); var groupsInVM = viewModel.StudentList; var groupsInContext = context.Students.Where(p => !p.SoftDeleted); // Проверяем, что количествозаписей во VM = количеству неудаленных записей в контексте Assert.AreEqual(groupsInContext.Count(), groupsInVM.Count); }
public void Setup() { inMemoryConnection = DbConnectionFactory.CreateTransient(); using var context = new MarketDbContext(inMemoryConnection); context.Init(); manager = new UserManager("Admin", "Admin", context); guestUser = manager.NewSession(Guid.NewGuid(), context); manager.Register(guestUser, TEST_USERNAME, TEST_PASSWORD, context); manager.Register(guestUser, "TEST_2", "1111", context); registeredUser = manager.NewSession(Guid.NewGuid(), context); SESSIONID = Guid.NewGuid(); }
/// <summary> /// Initializes the test. /// </summary> public virtual void InitializeTest() { this.AuthenticationProvider = new MockAuthenticationProvider(); this.Logger = new MockLoggingProvider(); this.MessageProvider = new BaseMessageProvider(this.Logger); this.EventDispatcher = new DomainEventDispatcher(); var assembly = Assembly.GetExecutingAssembly(); var basePath = Path.GetDirectoryName(assembly.Location); var csvPath = Path.Combine(basePath, CSVFolder); this.Connection = DbConnectionFactory.CreateTransient(new CsvDataLoader(csvPath)); }
public Form_Request_Identity() { InitializeComponent(); var connection = (EffortConnection)DbConnectionFactory.CreateTransient(); // MUST initialize first with the context with identity (Required for SetIdentityFields(false) using (var context = new EntityContext(connection)) { context.Database.CreateIfNotExists(); } // MUST open connection first (Required for SetIdentityFields(false) connection.Open(); connection.DbManager.SetIdentityFields(false); connection.Close(); // SEED using (var context = new EntityContextNoIdentity(connection)) { context.EntitySimples.Add(new EntitySimple { ID = -44, ColumnInt = 1 }); context.EntitySimples.Add(new EntitySimple { ID = -4, ColumnInt = 2 }); context.EntitySimples.Add(new EntitySimple { ID = -5, ColumnInt = 3 }); context.SaveChanges(); } // MUST open connection first (Required for SetIdentityFields(false) connection.Open(); connection.DbManager.SetIdentityFields(true); connection.Close(); // TEST using (var context = new EntityContext(connection)) { context.EntitySimples.Add(new EntitySimple() { ColumnInt = 4 }); context.EntitySimples.Add(new EntitySimple() { ColumnInt = 4 }); context.SaveChanges(); var list = context.EntitySimples.ToList(); } }
public BaseRepositoryTests() { DbConnection connection = DbConnectionFactory.CreateTransient(); _context = new FooContext(connection); var repository = new BaseRepository <Foo>(new Ef6UnitOfWork(_context, IsolationLevel.Unspecified)); _repositoryWriter = repository; _repositoryReader = repository; _repositoryWriterAsync = repository; _repositoryReaderAsync = repository; }
protected override void Load(ContainerBuilder builder) { base.Load(builder); var dbConnection = DbConnectionFactory.CreateTransient(); builder.Register(context => { var pocContext = new PocContext(dbConnection); TestsSeed.Seed(pocContext); return(pocContext); }).As <PocContext>().AsSelf(); }
public static IContext RetornarContextEffort() { if (_ctx != null) { return(_ctx); } DbConnection connection = DbConnectionFactory.CreateTransient(); _ctx = new Context(connection); return(_ctx); }
public static TestDB Create() { if (cachingDataLoader == null) { var csvDataLoader = new CsvDataLoader("res://WMIT.DataServices.Tests/Fixtures/Data/"); cachingDataLoader = new CachingDataLoader(csvDataLoader); } var connection = DbConnectionFactory.CreateTransient(cachingDataLoader); var db = new TestDB(connection); return(db); }
public void oneTimeSetUp() { var connection = DbConnectionFactory.CreateTransient(); this.ctx = new ApplicationDbContext(connection); this.serv = new AdministratorService(new AdministratorRepository(ctx), new ApplicationUserRepository(ctx)); var seeder = new DatabaseSeeder(); seeder.CreateDependenciesAndSeed(ctx);//heavy duty this.userManager = seeder.userManager; this.roleManager = seeder.roleManager; }