public Form_Request_EffortExtra() { InitializeComponent(); var data = new Effort.DataLoaders.ObjectData(); var entitySimples = data.Table <EntitySimple>(); entitySimples.Add(new EntitySimple { ID = 1, ColumnInt = -1 }); entitySimples.Add(new EntitySimple { ID = 2, ColumnInt = -2 }); var objectDataLoader = new ObjectDataLoader(data); var connection = Effort.DbConnectionFactory.CreateTransient(objectDataLoader); //var connection = Effort.DbConnectionFactory.CreateTransient(); //// CLEAN //using (var context = new EntityContext(connection)) //{ // context.EntitySimples.RemoveRange(context.EntitySimples); // context.SaveChanges(); //} // SEED using (var context = new EntityContext(connection)) { context.Database.CreateIfNotExists(); connection.CreateRestorePoint(); context.EntitySimples.Add(new EntitySimple { ColumnInt = 1 }); var list = context.EntitySimples.ToList(); context.SaveChanges(); connection.CreateRestorePoint(); context.EntitySimples.Add(new EntitySimple { ColumnInt = 2 }); context.EntitySimples.Add(new EntitySimple { ColumnInt = 3 }); context.SaveChanges(); connection.RollbackToRestorePoint(); } // TEST using (var context = new EntityContext(connection)) { var list = context.EntitySimples.ToList(); } }
/// <summary> /// Builds a controller of the required type using any data previously supplied (or defaults). /// </summary> /// <returns>An initialized controller of type <typeparamref name="TController" />.</returns> /// <exception cref="SpecificationException">Thrown if the controller cannot be built.</exception> public TController Build() { var dataLoader = new ObjectDataLoader(data); UnitOfWork = uowBuilder.WithData(dataLoader).Build(); var mapperConfiguration = new MapperConfiguration(cfg => { cfg.AddProfile <ViewModelMappingProfile>(); }); mapperConfiguration.AssertConfigurationIsValid(); Mapper = mapperConfiguration.CreateMapper(); var notifier = new FakeNotificationService(); RulesService = new GameRulesService(UnitOfWork, Mapper, notifier); HttpContextBase httpContext; if (postedFile == null) { httpContext = new FakeHttpContext(requestPath, requestMethod.ToString("G")); } else { var filesCollection = new FakeHttpFileCollection(postedFile); httpContext = new FakeHttpContext(requestPath, filesCollection); } var fakeIdentity = new FakeIdentity(requestUsername); var fakePrincipal = new FakePrincipal(fakeIdentity, requestUserRoles); httpContext.User = fakePrincipal; var context = new ControllerContext { HttpContext = httpContext }; /* * Use Ninject to create the controller, as we don't know in advance what * type of controller or how many constructor parameters it has. */ var kernel = BuildNinjectKernel(fakeIdentity, requestUserId, RulesService); var controller = kernel.Get <TController>(); if (controller == null) { throw new SpecificationException( $"ControllerContextBuilder: Unable to create controller instance of type {nameof(TController)}"); } controller.ControllerContext = context; controller.TempData = tempdata; return(controller); }
public YourCustomDataContext GetNewDbContext() { var data = new ObjectData(); data.Table <SimpleDataEntity>("SimpleDataEntities").Add(new SimpleDataEntity { Id = 1, Name = "Test 1", UpdateUser = "******", Updated = new DateTimeOffset(2017, 1, 22, 5, 32, 23, 0, new TimeSpan(3, 0, 0)) }); data.Table <SimpleDataEntity>("SimpleDataEntities").Add(new SimpleDataEntity { Id = 2, Name = "Test 2", UpdateUser = "******", Updated = new DateTimeOffset(2017, 1, 22, 5, 32, 23, 0, new TimeSpan(3, 0, 0)) }); data.Table <SimpleDataEntity>("SimpleDataEntities").Add(new SimpleDataEntity { Id = 3, Name = "Test 3", UpdateUser = "******", Updated = new DateTimeOffset(2017, 1, 22, 5, 32, 23, 0, new TimeSpan(3, 0, 0)) }); data.Table <SimpleDataEntity>("SimpleDataEntities").Add(new SimpleDataEntity { Id = 4, Name = "Test 4", UpdateUser = "******", Updated = new DateTimeOffset(2017, 1, 22, 5, 32, 23, 0, new TimeSpan(3, 0, 0)) }); data.Table <SimpleDataEntity>("SimpleDataEntities").Add(new SimpleDataEntity { Id = 5, Name = "Test 5", UpdateUser = "******", Updated = new DateTimeOffset(2017, 1, 22, 5, 32, 23, 0, new TimeSpan(3, 0, 0)) }); data.Table <SimpleCompositeKeyEntity>("SimpleCompositeKeyEntities").Add(new SimpleCompositeKeyEntity { Id = 1, Name = "Another Key" }); var dataLoader = new ObjectDataLoader(data); var connection = Effort.DbConnectionFactory.CreateTransient(dataLoader); var _context = new YourCustomDataContext(connection); _context.Database.CreateIfNotExists(); _context.Database.Initialize(true); if (Logging != null) { _context.Database.Log = Logging; } return(_context); }
public YourCustomDataContext GetNewDbContext() { var data = new ObjectData(); data.Table <SimpleDataEntity>("SimpleDataEntities").Add(new SimpleDataEntity { Id = 1, Name = "Test 1" }); data.Table <SimpleDataEntity>("SimpleDataEntities").Add(new SimpleDataEntity { Id = 2, Name = "Test 2" }); data.Table <SimpleDataEntity>("SimpleDataEntities").Add(new SimpleDataEntity { Id = 3, Name = "Test 3" }); data.Table <SimpleDataEntity>("SimpleDataEntities").Add(new SimpleDataEntity { Id = 4, Name = "Test 4" }); data.Table <SimpleDataEntity>("SimpleDataEntities").Add(new SimpleDataEntity { Id = 5, Name = "Test 5" }); data.Table <SimpleCompositeKeyEntity>("SimpleCompositeKeyEntities").Add(new SimpleCompositeKeyEntity { Id = 1, Name = "Another Key" }); var dataLoader = new ObjectDataLoader(data); var connection = Effort.DbConnectionFactory.CreateTransient(dataLoader); var _context = new YourCustomDataContext(connection); _context.Database.CreateIfNotExists(); _context.Database.Initialize(true); if (Logging != null) { _context.Database.Log = Logging; } return(_context); }
public Form_Request_EffortExtra() { InitializeComponent(); var data = new ObjectData(); var entitySimples = data.Table <EntitySimple>(); entitySimples.Add(new EntitySimple { ID = 1, ColumnInt = -1 }); entitySimples.Add(new EntitySimple { ID = 2, ColumnInt = -2 }); var objectDataLoader = new ObjectDataLoader(data); var connection = DbConnectionFactory.CreateTransient(objectDataLoader); // SEED using (var context = new EntityContext(connection)) { context.Database.CreateIfNotExists(); context.EntitySimples.Add(new EntitySimple { ColumnInt = 1 }); context.EntitySimples.Add(new EntitySimple { ColumnInt = 2 }); context.EntitySimples.Add(new EntitySimple { ColumnInt = 3 }); context.SaveChanges(); var entity = context.EntitySimples.Where(x => x.ColumnInt == 2).First(); context.EntitySimples.Remove(entity); context.EntitySimples.Add(new EntitySimple { ColumnInt = 4 }); context.SaveChanges(); var entity2 = context.EntitySimples.Where(x => x.ColumnInt == 4).First(); connection.CreateRestorePoint(); context.EntitySimples.Add(new EntitySimple { ColumnInt = 5 }); context.SaveChanges(); var list2 = context.EntitySimples.ToList(); connection.RollbackToRestorePoint(context); context.EntitySimples.Add(new EntitySimple { ColumnInt = 9 }); context.SaveChanges(); var list3 = context.EntitySimples.ToList(); var entity3 = context.EntitySimples.Where(x => x.ColumnInt == 4).First(); } // TEST using (var context = new EntityContext(connection)) { var list = context.EntitySimples.ToList(); } }
public Form_General_Mik() { InitializeComponent(); { var data = new ObjectData(); // with [Table("TableTest")] on EntitySimple ==> not insert because not EntitySimples. // but without [Table("TableTest")] on EntitySimple ==> insert because name is EntitySimples. data.Table <EntitySimple>("EntitySimples").Add(new EntitySimple { ID = 1, ColumnInt = 55 }); data.Table <EntitySimple>("EntitySimples").Add(new EntitySimple { ID = 2, ColumnInt = 55 }); data.Table <EntitySimple>("EntitySimples").Add(new EntitySimple { ID = 3, ColumnInt = 55 }); data.Table <EntitySimple>().Add(new EntitySimple { ID = 1, ColumnInt = 55 }); data.Table <EntitySimple>().Add(new EntitySimple { ID = 2, ColumnInt = 55 }); data.Table <EntitySimple>().Add(new EntitySimple { ID = 3, ColumnInt = 55 }); //data.Table<EntitySimple>("EntitySimples").Add(new EntitySimple { ColumnInt = 55 }); //data.Table<EntitySimple>("EntitySimples").Add(new EntitySimple { ColumnInt = 55 }); //data.Table<EntitySimple>("EntitySimples").Add(new EntitySimple { ColumnInt = 55 }); data.Table <EntitySimple2>().Add(new EntitySimple2 { ColumnInt = 55 }); data.Table <Entity>().Add(new Entity { ColumnInt = 55 }); data.Table <Customer>().Add(new Customer { ColumnInt = 55 }); // data.Table<Entity>().Add(new Entity { ColumnInt = 55 }); var dataLoader = new ObjectDataLoader(data); var connection = Effort.DbConnectionFactory.CreateTransient(dataLoader); // var connection = Effort.DbConnectionFactory.CreateTransient(); // SEED using (var context = new EntityContext(connection)) { context.EntitySimples.Add(new EntitySimple { ColumnInt = 1 }); context.EntitySimples.Add(new EntitySimple { ColumnInt = 2 }); context.EntitySimples.Add(new EntitySimple { ColumnInt = 3 }); context.EntitySimples2.Add(new EntitySimple2 { ColumnInt = 1 }); context.EntitySimples2.Add(new EntitySimple2 { ColumnInt = 2 }); context.EntitySimples2.Add(new EntitySimple2 { ColumnInt = 3 }); context.Entities.Add(new Entity { ColumnInt = 1 }); context.Entities.Add(new Entity { ColumnInt = 2 }); context.Entities.Add(new Entity { ColumnInt = 3 }); context.Customers.Add(new Customer() { ColumnInt = 1 }); context.Customers.Add(new Customer { ColumnInt = 2 }); context.Customers.Add(new Customer { ColumnInt = 3 }); context.SaveChanges(); } // TEST using (var context = new EntityContext(connection)) { var list1 = context.EntitySimples.ToList(); // 6 var list2 = context.EntitySimples2.ToList(); //4 var list3 = context.Entities.ToList(); // need 4 var list4 = context.Customers.ToList(); // need 4 } } }