public void TestCustomerCreation() { //Creating customer var Customer = new Customer() { CustomerName = "Customer 1", Telephome = "78-676-121212", Sites = new List<Site>() }; Customer.Sites.Add(new Site() { Address = "Site 1", PostCode = "001", SiteNumber = "ST01" }); Customer.Sites.Add(new Site() { Address = "Site 2", PostCode = "002", SiteNumber = "ST02" }); iocCtxFactory = iocContainer.Resolve<IDbContextFactory>(); var iocDBContext = iocCtxFactory.GetContext(); //adding customer to database var sotredCustomer = iocDBContext.Set<Customer>().Add(Customer); iocDBContext.SaveChanges(); var customerId = sotredCustomer.Id; //Test var nonIoCContext = new DbContextFactory().GetContext(); var customerFrom_IOC_Context = iocCtxFactory.GetContext().Set<Customer>().Where(c => c.Id == customerId).SingleOrDefault(); var customerNon_IOC_Context = nonIoCContext.Set<Customer>().Where(c => c.Id == customerId).SingleOrDefault(); Assert.IsNull(customerNon_IOC_Context.Sites); //Expecting empty but having values if IOC lifestyle is singleton or PerWebRequest :( //transient is working as expected Assert.IsNull(customerFrom_IOC_Context.Sites); }
public void TestAddChild() { IStore store = new ThreadStaticStore(); IDbContextFactory contextFactory = new DbContextFactory(); using (UnitOfWork unitwork = new UnitOfWork(store, contextFactory)) { IRepository<Demo, Guid> demoRepository = new Repository<Demo, Guid>(store); IRepository<DemoChild, Guid> demoChildRepository = new Repository<DemoChild, Guid>(store); IRepository<DemoBrother, Guid> demoBrotherRepository = new Repository<DemoBrother, Guid>(store); Demo demo = new Demo() { Name = "C" }; DemoChild child = new DemoChild(); demo.Children.Add(child); DemoBrother brother = new DemoBrother(); demo.Brothers.Add(brother); demoRepository.SaveOrUpdate(demo); demoChildRepository.SaveOrUpdate(child); demoBrotherRepository.SaveOrUpdate(brother); unitwork.SaveChanges(); } }
private void PopulateGenres(DbContextFactory dbContextFactory) { using (var dbContext = dbContextFactory.Create()) { dbContext.Genres.Add(new Genre() { Name = "Pop", Description = "Test 1" }); dbContext.Genres.Add(new Genre() { Name = "Rock", Description = "Test 2" }); dbContext.Genres.Add(new Genre() { Name = "Rap", Description = "Test 3" }); dbContext.SaveChanges(); } }
public static void ConfigureIdentity() { var dbContextCreator = new DbContextFactory<IdentityDbContext>(); Secrets = new EFUserSecretStore<UserSecret>(dbContextCreator); Logins = new EFUserLoginStore<UserLogin>(dbContextCreator); Users = new EFUserStore<User>(dbContextCreator); Roles = new EFRoleStore<Role, UserRole>(dbContextCreator); RoleClaimType = ClaimsIdentity.DefaultRoleClaimType; UserIdClaimType = "http://schemas.microsoft.com/aspnet/userid"; UserNameClaimType = "http://schemas.microsoft.com/aspnet/username"; ClaimsIssuer = ClaimsIdentity.DefaultIssuer; //AntiForgeryConfig.UniqueClaimTypeIdentifier = IdentityConfig.UserIdClaimType; }
public ConcurrentRepositoryEfTest() { ILogger logger = LogManager.GetCurrentClassLogger(); IDbContextFactory contextFactory = new DbContextFactory( new DatabaseInitializer<EntitiesContext>(), new TestContextConfig(), logger); var uofWFactory = new UnitOfWorkFactoryEf(contextFactory); this._repositoryDepartment = new ConcurrentRepositoryEf<Guid, Department>(uofWFactory); }
public void TestData() { IStore store = new ThreadStaticStore(); IDbContextFactory contextFactory = new DbContextFactory(); using (UnitOfWork unitwork = new UnitOfWork(store, contextFactory)) { IRepository<Demo,Guid> demoRepository = new Repository<Demo,Guid>(store); Demo demo = new Demo() { Name = "B"}; demoRepository.SaveOrUpdate(demo); unitwork.SaveChanges(); } }
public void TestGetChild() { IStore store = new ThreadStaticStore(); IDbContextFactory contextFactory = new DbContextFactory(); using (UnitOfWork unitwork = new UnitOfWork(store, contextFactory)) { IRepository<Demo, Guid> demoRepository = new Repository<Demo, Guid>(store); demoRepository.Include(i => i.Children); //這兩個做eager Load demoRepository.Include(i => i.Brothers); var demos = demoRepository.Query(q => q.Name == "C"); Assert.AreEqual(1, demos.Count()); Assert.AreEqual(1, demos.First().Children.Count()); Assert.AreEqual(1, demos.First().Brothers.Count()); } }
public void EntityValidation_should_be_injectable() { // arrange var injection = new TestEntityValidationInjection(); var injectionSet = new InjectionSet(injection, new TestModelCreationInjection()); var factory = new DbContextFactory(); // act using (var context = Create(factory, injectionSet)) { context.ActionTypes.Add(new ActionType()); context.GetValidationErrors(); } // assert Assert.That(injection.Entries.Count, Is.EqualTo(1)); }
public void SaveChanges_should_be_injectable() { // arrange var injection = new TestSaveChangesInjection(); var injectionSet = new InjectionSet(injection); var factory = new DbContextFactory(); int count; // act using (var context = Create(factory, injectionSet)) { count = context.SaveChanges(); } // assert Assert.That(injection.BeforeList.Count, Is.EqualTo(1)); Assert.That(injection.AfterList.Count, Is.EqualTo(1)); Assert.That(injection.AfterList[0], Is.EqualTo(injection.BeforeList[0])); Assert.That(count, Is.EqualTo(0)); }
private void PopulateAlbums(DbContextFactory dbContextFactory) { this.PopulateGenres(dbContextFactory); using (var dbContext = dbContextFactory.Create()) { var pop = dbContext.Genres.FirstOrDefault(g => g.Name == "Pop"); var rock = dbContext.Genres.FirstOrDefault(g => g.Name == "Rock"); var rap = dbContext.Genres.FirstOrDefault(g => g.Name == "Rap"); dbContext.Albums.Add(this.CreateTestAlbum(pop)); dbContext.Albums.Add(this.CreateTestAlbum(pop)); dbContext.Albums.Add(this.CreateTestAlbum(rock)); dbContext.Albums.Add(this.CreateTestAlbum(rock)); dbContext.Albums.Add(this.CreateTestAlbum(rock)); dbContext.Albums.Add(this.CreateTestAlbum(rock)); dbContext.Albums.Add(this.CreateTestAlbum(rock)); dbContext.Albums.Add(this.CreateTestAlbum(rap)); dbContext.Albums.Add(this.CreateTestAlbum(rap)); dbContext.SaveChanges(); } }
public void ModelCreation_should_be_injectable_and_called_once() { // ReSharper disable ReturnValueOfPureMethodIsNotUsed // arrange var injection = new TestModelCreationInjection(); var injectionSet = new InjectionSet(injection); var factory = new DbContextFactory(); // act using (var context1 = Create(factory, injectionSet)) { context1.ActionTypes.Count(); } using (var context2 = Create(factory, injectionSet)) { context2.ActionTypes.Count(); } // assert Assert.That(injection.ModelBuilders.Count, Is.EqualTo(1)); // ReSharper restore ReturnValueOfPureMethodIsNotUsed }
public void TestSpecifications() { IStore store = new ThreadStaticStore(); IDbContextFactory contextFactory = new DbContextFactory(); Specification<Demo> specify = new Specification<Demo>(o => o.Name == "A"); Specification<Demo> specify1 = new Specification<Demo>(o => o.Name == "B"); Specification<Demo> specify2 = specify | specify1; using (UnitOfWork unitwork = new UnitOfWork(store, contextFactory)) { IRepository<Demo,Guid> demoRepository = new Repository<Demo,Guid>(store); IList<Demo> demos = demoRepository.Query(specify2); Assert.AreEqual(2, demos.Count()); } }
public BaseService(DbContextFactory contextFactory) { _userRepo = new UserRepository(contextFactory); _userExperienceRepository = new UserExperienceRepository(contextFactory); _hardCodeRepository = new HardCodeRepository(contextFactory); }
public DeleteCustomerCommandHandler(DbContextFactory dbContextFactory) { this.dbContextFactory = dbContextFactory; }
public TeamCommandRepository(DbContextFactory dbContextFactory) : base(dbContextFactory) { }
/// <summary> /// 负责将对象同步至数据库 /// </summary> private void UpdateBetDetail(object param) { /****初始化开始**/ IDbContextFactory factory = new DbContextFactory(); Ytg.Comm.IHasher hasher = new Ytg.Comm.Hasher(); var sysUser = new SysUserService(new Repo <SysUser>(factory), hasher); var sysUserBalanceService = new SysUserBalanceService(new Repo <SysUserBalance>(factory), hasher, sysUser); var sysUserBalanceDetailService = new SysUserBalanceDetailService(new Repo <SysUserBalanceDetail>(factory), sysUserBalanceService); var rebateHelper = new Service.Logic.RebateHelper(sysUser, sysUserBalanceService, sysUserBalanceDetailService); var buyTogetherService = new BuyTogetherService(new Repo <BuyTogether>(factory)); /****初始化结束**/ while (true) { var betDetail = this.Dequeue(); try { if (null == betDetail) { LogManager.Info("同步数据队列中暂无数据,开始休眠一秒!"); System.Threading.Thread.Sleep(1000);//休眠一秒 continue; } if (betDetail.IsMatch) { if (betDetail.IsBuyTogether == 0) { //代购,使用原来方式进行处理 rebateHelper.UpdateUserBanance(betDetail.UserId, betDetail.WinMoney, TradeType.奖金派送, betDetail.BetCode, 0); } else { var source = buyTogetherService.GetForBettid(betDetail.Id); if (source != null && source.Count > 0) { var winMonery = betDetail.WinMoney;//总中奖总金额 var totalMonery = betDetail.TotalAmt; decimal bili = 0m; Console.WriteLine("处理合买/投注期数=" + betDetail.BetCode + "中奖金额=" + winMonery + " 投注金额=" + totalMonery); foreach (var item in source) { var subscription = item.Subscription; bili = subscription / totalMonery; var itemWinMonery = bili * winMonery; LogManager.Info("认购金额:" + subscription + "分配奖金:" + itemWinMonery); rebateHelper.UpdateUserBanance(betDetail.UserId, itemWinMonery, TradeType.奖金派送, item.BuyTogetherCode, 0); System.Threading.Thread.Sleep(1); //修改中奖金额和状态 item.WinMonery = itemWinMonery; item.Stauts = BetResultType.Winning; LotteryIssuesData.UpdateBuyTogerher(betDetail.Id, 1, itemWinMonery); } //处理自身用户奖金 bili = betDetail.Subscription / totalMonery; var usWinMonery = bili * winMonery; rebateHelper.UpdateUserBanance(betDetail.UserId, usWinMonery, TradeType.奖金派送, betDetail.BetCode, 0); } } } //线程同步计算返点 rebateHelper.BettingCalculate(betDetail.PrizeType, betDetail.UserId, betDetail.TotalAmt, betDetail.BetCode, rebateHelper.GetRadioMaxRemo(betDetail.PalyRadioCode, betDetail.BonusLevel)); LogManager.Info("修改投注信息成功!" + betDetail.ToString()); } catch (Exception ex) { LogManager.Error("修改投注用户信息异常,投注信息:" + betDetail.ToString() + "\n", ex); } } }
public void MyTestInitialize() { _dbContextFactory = new DbContextFactory <FakeEcDbContext>(); }
public UserCreator(DbContextFactory dbContextFactory) { _dbContextFactory = dbContextFactory; }
/// <summary> /// 初始化一个<see cref="RepositoryBase{TEntity,TKey}"/>类型的实例 /// </summary> /// <param name="factory">数据上下文工厂</param> protected RepositoryBase(DbContextFactory factory) : base(factory) { }
/// <summary> /// Creates a new instance of the <see cref="ContactRepository"/> class. /// </summary> /// <param name="factory"> /// The <see cref="DbContextFactory{ContactContext}"/> /// to use. /// </param> public ContactRepository(DbContextFactory <ContactContext> factory) { _factory = factory; }
public OrderRepository(DbContextFactory context) : base(context) { UseQuerySplittingBehavior = true; }
protected void Application_End() { DbContextFactory.Dispose(); //UnityConfig.RegisterComponents(); }
} // protected BaseDal() { this.Context = DbContextFactory.CreateDbContext(); }
public PetsRepository() : base(DbContextFactory.CreateContext()) { }
public EfAuditStore(DbContextFactory dbContextFactory) { _dbContext = dbContextFactory.GetDbContext <AuditOperation>(); }
static void Main(string[] args) { Database.SetInitializer <MyDbContext>(new MigrateDatabaseToLatestVersion <MyDbContext, Configuration>()); EntityBuilder entityBuilder = new EntityBuilder(); var Employees = new Model.DynamicEntity { BaseType = typeof(EntityBase), Id = 1, IsDetailedEntity = false, MasterId = 1, Name = "Employees", TableName = "Employees", UniqueId = Guid.NewGuid() }; Employees.Properties.Add(new Model.DynamicProperty { IsForignKey = false, PropertyType = typeof(System.String), PrropertyName = "FirstName", MaxStringSize = 200 }); Employees.Properties.Add(new Model.DynamicProperty { IsForignKey = false, PropertyType = typeof(System.String), PrropertyName = "LastName", MaxStringSize = 200 }); Employees.EntityType = entityBuilder.BuildEntityType(Employees); var Addresses = new Model.DynamicEntity { BaseType = typeof(EntityBase), Id = 2, IsDetailedEntity = false, MasterId = 1, Name = "Addresses", TableName = "Addresses", UniqueId = Guid.NewGuid() }; Addresses.Properties.Add(new Model.DynamicProperty { PropertyType = typeof(System.String), PrropertyName = "City", MaxStringSize = 200, IsForignKey = false, }); //add Forign key and nested table Addresses.Properties.Add(new Model.DynamicProperty { PropertyType = Employees.EntityType, PrropertyName = "Employee", IsVirtual = true, }); Addresses.Properties.Add(new Model.DynamicProperty { PropertyType = typeof(System.Int32), PrropertyName = "EmployeeId", MaxStringSize = 200, IsForignKey = true, ForignKey = "Employee" }); Addresses.EntityType = entityBuilder.BuildEntityType(Addresses); DynamicAssembly.Entities = new ObservableCollection <Model.DynamicEntity>(); DynamicAssembly.Entities.Add(Employees); DynamicAssembly.Entities.Add(Addresses); DynamicAssembly._Context = DbContextFactory.CreateDBContext <MyDbContext>(); DbContextFactory.UpdateDynamicDataBase <Configuration>(new Configuration()); var exmployeesEntityType = DynamicAssembly.Entities.SingleOrDefault(x => x.Id == 1).EntityType; var employees = DynamicAssembly._Context.Set(exmployeesEntityType); dynamic newRecord = (Activator.CreateInstance(exmployeesEntityType)); newRecord.FirstName = "Ibrahim"; newRecord.LastName = "Abulubad"; employees.Add(newRecord); DynamicAssembly._Context.SaveChanges(); List <CustomDynamicExpression> dynamicFilter = new List <CustomDynamicExpression>(); dynamicFilter.Add(new CustomDynamicExpression { DynamicCondition = new DynamicCondition { Column = "FirstName", Value = "Ibrahim", WhereOperation = DynamicHelper.Enums.WhereOperation.Equal } } ); var query = employees.Where(dynamicFilter); var list = query.OrderBy("Id", SortDirection.Asc).Skip(0).Take(10).ToListAsync().GetAwaiter().GetResult(); }
public UserReader(DbContextFactory dbContextFactory) { _dbContextFactory = dbContextFactory; }
public AvatarServiceTests() { DbContextFactory.Init(); }
public override void Setup() { DbContext = DbContextFactory.CreateSqlServerContext(ConnectionStrings.GetSqlServer()); base.Setup(); }
public CreateTests( CustomWebApplicationFactory <Startup> factory, DbContextFactory dbContextFactory ) : base(factory, dbContextFactory) { }
protected TDbContext CreateDbContext(bool readWrite = false) => DbContextFactory.CreateDbContext().ReadWrite(readWrite);
/// <inheritdoc /> /// <summary> /// For creating migrations /// </summary> /// <param name="args"></param> /// <returns></returns> public CountriesDbContext CreateDbContext(string[] args) { return(DbContextFactory <CountriesDbContext, CountriesDbContext> .CreateFactoryDbContext()); }
//public FluentContext() //{} protected FluentContext(DbContextFactory dbContext) { }
public CustomerRepository(DbContextFactory contextFactory) : base(contextFactory) { _contextFactory = contextFactory; }
public void TestGetData() { IStore store = new ThreadStaticStore(); IDbContextFactory contextFactory = new DbContextFactory(); using (UnitOfWork unitwork = new UnitOfWork(store, contextFactory)) { IRepository<Demo,Guid> demoRepository = new Repository<Demo,Guid>(store); var list = demoRepository.GetAll(); Assert.AreEqual(1, list.Count); } }
/// <inheritdoc /> /// <summary> /// For creating migrations /// </summary> /// <param name="args"></param> /// <returns></returns> public FileDbContext CreateDbContext(string[] args) { return(DbContextFactory <FileDbContext, FileDbContext> .CreateFactoryDbContext()); }
public void Update() { using (var context = DbContextFactory.GetDbContext()) { var row = context.From <Student>().Update(s => new Student() { Age = 99, Name = "favv", Id = 10 }); //reset where context.From <Student>() .Where(a => a.Version == "12" && a.Id == 12) .Update(new Student() { Version = "14", Age = 20, Id = 14 }); //param var age = 20; DateTime?time = null; var sid = 1; //subquery var subquery = new SubQuery <School>() .Where(a => a.Id == sid) .Select(s => s.Name); var row1 = context.From <Student>() .Set(a => a.Age, a => a.Age + age) .Set(a => a.Name, subquery) .Set(a => a.CreateTime, time, time != null) .Where(a => a.Id == 16) .Update(); //function context.From <Student>() .Set(a => a.Name, a => MysqlFun.REPLACE(a.Name, "a", "b")) .Where(a => a.Id == 14) .Update(); //lock var student = context.From <Student>() .Where(a => a.Id == 16) .Single(); var row2 = context.From <Student>() .Set(a => a.Age, 80) .Set(a => a.Version, Guid.NewGuid().ToString()) .Where(a => a.Id == 16 && a.Version == student.Version) .Update(); //entity var row3 = context.From <Student>() .Filter(a => a.SchoolId) .Update(new Student() { Id = 2, CreateTime = DateTime.Now }); } }
public void TestSimpleQuery() { IStore store = new ThreadStaticStore(); IDbContextFactory contextFactory = new DbContextFactory(); using (UnitOfWork unitwork = new UnitOfWork(store, contextFactory)) { IRepository<Demo, Guid> demoRepository = new Repository<Demo, Guid>(store); IList<Demo> demos = demoRepository.Query(q => q.Name== "A" || q.Name == "B"); Assert.AreEqual(2, demos.Count()); } }
public CategoriesControllerPostTests(ITestOutputHelper output, Request <Startup> request, DbContextFactory contextFactory) { this.output = output; this.request = request; this.context = contextFactory.Context; Description = "Valid Category"; var user = new User() { Email = "", Name = "", Lastname = "", Id = 1 }; Token = request.Jwt.GenerateToken(user); }
public OrdinaryScenarioProvider() { var contextFactory = new DbContextFactory<RepositoryAggregateRoot<Book>>(MsSqlHelper.EfConnectionStringName); Session = new RepositorySession(contextFactory); }
public WaterLevelLocationRespositoryTests() { _dbContextFactory = new DbContextFactory(); }
/// <summary> /// 保存EF的修改,映射到数据库中去 /// </summary> /// <returns>执行结果</returns> public int SaveChange() { return(DbContextFactory.GetEF_DbContext().SaveChanges()); }
public void SetContextFactory(TblConnectionConfig connectionStrings) { DbContextFactory.AddChildContext(connectionStrings); }
public DetailsAuthTests( CustomWebApplicationFactory <Startup> factory, DbContextFactory dbContextFactory ) : base(factory, dbContextFactory) { }
public void Should_be_only_one_type_for_one_injection_set() { // arrange var injectionSet = new InjectionSet(new TestModelCreationInjection()); var factory = new DbContextFactory(); Type type1; Type type2; // act using (var context1 = Create(factory, injectionSet)) { type1 = context1.GetType(); } using (var context2 = Create(factory, injectionSet)) { type2 = context2.GetType(); } // assert Assert.That(type1, Is.EqualTo(type2)); }
public static DbContextFactory CreateDbContextFactory() { var dbContextFactory = new DbContextFactory(ServiceProviderFactory.Create()); return dbContextFactory; }
public RolesControllerGetByIdTests(ITestOutputHelper output, Request <Startup> request, DbContextFactory contextFactory) { this.output = output; this.request = request; this.nieuweStroomPocDbContext = contextFactory.nieuweStroomPocDbContext; }
public TaskItemService() { _taskManageContext = DbContextFactory.GetCurrentDbContext() as TaskManageContext; }
private static BasicDbContext Create(DbContextFactory factory, InjectionSet injectionSet) { return factory.Create<BasicDbContext>(injectionSet, "EntityFrameworkInject"); }