public void BatchDeleteTest() { FrameworkUserBase v1 = new FrameworkUserBase(); FrameworkUserBase v2 = new FrameworkUserBase(); using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory)) { v1.ITCode = "itcode"; v1.Name = "name"; v1.Password = "******"; v2.ITCode = "itcode2"; v2.Name = "name2"; v2.Password = "******"; context.Set <FrameworkUserBase>().Add(v1); context.Set <FrameworkUserBase>().Add(v2); context.SaveChanges(); } var rv = _controller.BatchDelete(new Guid[] { v1.ID, v2.ID }); Assert.IsInstanceOfType(rv, typeof(OkObjectResult)); using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory)) { Assert.AreEqual(context.Set <FrameworkUserBase>().Count(), 0); } rv = _controller.BatchDelete(new Guid[] {}); Assert.IsInstanceOfType(rv, typeof(OkResult)); }
/// <summary> /// Handles the disposal of resources. Derived from abstract class <see cref="DisposableObject"/> which handles common required locking logic. /// </summary> protected override void DisposeResources() { Security.IfNotNull(x => x.DisposeIfDisposable()); Settings.IfNotNull(x => x.DisposeIfDisposable()); Hive.IfNotNull(x => x.DisposeIfDisposable()); FrameworkContext.IfNotNull(x => x.Dispose()); }
public void DeleteTest() { FrameworkUserBase v = new FrameworkUserBase(); using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory)) { v.ITCode = "itcode"; v.Name = "name"; v.Password = "******"; context.Set <FrameworkUserBase>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Delete(v.ID); Assert.IsInstanceOfType(rv.Model, typeof(FrameworkUserVM)); FrameworkUserVM vm = rv.Model as FrameworkUserVM; v = new FrameworkUserBase(); v.ID = vm.Entity.ID; vm.Entity = v; _controller.Delete(v.ID, null); using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory)) { Assert.AreEqual(context.Set <FrameworkUserBase>().Count(), 0); } }
public LibraryUnitOfWork(FrameworkContext context, IBookRepository bookRepositroy, IStudentRepository studentRepository, IStudentRegistrationRepository studentRegistrationRepository) : base(context) { StudentRepositroy = studentRepository; BookRepositroy = bookRepositroy; StudentRegistrationRepository = studentRegistrationRepository; }
public static void MyClassInitialize(TestContext testContext) { var frameworkContext = new FrameworkContext( ConfigurationManager.GetSection("rebel.foundation") as IFoundationConfigurationSection); var persistenceConfig = ConfigurationManager.GetSection("hive.persistence") as HiveConfigurationSection; var localConfig = persistenceConfig.AvailableProviders.ReadWriters["rw-nhibernate-01"].GetLocalProviderConfig() as ProviderConfigurationSection; var nhSetup = new NHibernateConfigBuilder("rw-nhibernate-01", localConfig); var config = nhSetup.BuildConfiguration(); // Setup the local provider var dataContextFactory = new DataContextFactory(config.BuildSessionFactory()); var unitOfWorkFactory = new ReadWriteRepositoryUnitOfWorkFactory(dataContextFactory); var reader = new Reader(unitOfWorkFactory); var readWriter = new ReadWriter(unitOfWorkFactory); var uriMatch = new DefaultUriMatch() { MatchType = UriMatchElement.MatchTypes.Wildcard, Uri = "content://*/" }; // Setup hive's provider governor. Normally it takes two uow factories (read and read-write) but we can use the same for both here _mappingGroup = new DefaultPersistenceMappingGroup("rw-nhibernate-01", new[] { unitOfWorkFactory }, new[] { unitOfWorkFactory }, new[] { reader }, new[] { readWriter }, new[] { uriMatch }); }
public void BatchDeleteTest() { FrameworkUserBase v1 = new FrameworkUserBase(); FrameworkUserBase v2 = new FrameworkUserBase(); using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory)) { v1.ITCode = "itcode"; v1.Name = "name"; v1.Password = "******"; v2.ITCode = "itcode2"; v2.Name = "name2"; v2.Password = "******"; context.Set <FrameworkUserBase>().Add(v1); context.Set <FrameworkUserBase>().Add(v2); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.BatchDelete(new string[] { v1.ID.ToString(), v2.ID.ToString() }); Assert.IsInstanceOfType(rv.Model, typeof(FrameworkUserBatchVM)); (rv.Model as FrameworkUserBatchVM).ListVM.DoSearch(); FrameworkUserBatchVM vm = rv.Model as FrameworkUserBatchVM; vm.Ids = new string[] { v1.ID.ToString(), v2.ID.ToString() }; _controller.DoBatchDelete(vm, null); using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory)) { Assert.AreEqual(context.Set <FrameworkUserBase>().Count(), 0); } }
public void LoginTest() { //调用Login ViewResult rv = (ViewResult)_controller.Login(); //测试Login方法返回LoginVM Assert.IsInstanceOfType(rv.Model, typeof(LoginVM)); //在数据库中添加一个用户 FrameworkUserBase v = new FrameworkUserBase(); using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory)) { v.ITCode = "itcode"; v.Name = "name"; v.Password = Utils.GetMD5String("password"); v.IsValid = true; context.Set <FrameworkUserBase>().Add(v); context.SaveChanges(); } //使用添加的用户登陆 LoginVM vm = rv.Model as LoginVM; vm.ITCode = "itcode"; vm.Password = "******"; var rv2 = _controller.Login(vm); //测试当前登陆用户是否正确设定 Assert.AreEqual(_controller.LoginUserInfo.ITCode, "itcode"); //测试是否正确返回 Assert.IsInstanceOfType(rv2, typeof(RedirectResult)); }
public void CreateTest() { PartialViewResult rv = (PartialViewResult)_controller.Create(); Assert.IsInstanceOfType(rv.Model, typeof(FrameworkUserVM)); FrameworkUserVM vm = rv.Model as FrameworkUserVM; FrameworkUserBase v = new FrameworkUserBase(); v.ITCode = "itcode"; v.Name = "name"; v.Password = "******"; vm.Entity = v; _controller.Create(vm); using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <FrameworkUserBase>().FirstOrDefault(); Assert.AreEqual(data.ITCode, "itcode"); Assert.AreEqual(data.Name, "name"); Assert.AreEqual(data.Password, Utils.GetMD5String("password")); Assert.AreEqual(data.CreateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10); } }
private static void InitRoles(FrameworkContext context) { var admin = new Role { Name = Constants.RoleName.Admin, Description = Constants.RoleName.Admin, IsDeleted = false, CreatedDate = DateTimeHelper.UTCNow() }; var moderator = new Role { Name = Constants.RoleName.Moderator, Description = Constants.RoleName.Moderator, IsDeleted = false, CreatedDate = DateTimeHelper.UTCNow() }; var user = new Role { Name = Constants.RoleName.User, Description = Constants.RoleName.User, IsDeleted = false, CreatedDate = DateTimeHelper.UTCNow() }; var customer = new Role { Name = Constants.RoleName.Customer, Description = Constants.RoleName.Customer, IsDeleted = false, CreatedDate = DateTimeHelper.UTCNow() }; context.Role.AddOrUpdate(x => x.Name, admin, moderator, user, customer); context.SaveChanges(); }
public DashboardController(UserManager <ApplicationUser> userManager, ILogger <ApplicationUser> logger, ApplicationDbContext db, FrameworkContext frameworkContext, AppDbConText appDbConText) { _userManager = userManager; _logger = logger; _db = db; _frameworkContext = frameworkContext; _appContext = appDbConText; }
public PostUnitOfWork(FrameworkContext context, IPostRepository postRepository, ICategoryRepository categoryRepository, IBlogCategoryRepository blogCategoryRepository, ICommentRepository commentRepository) : base(context) { PostRepository = postRepository; CategoryRepository = categoryRepository; BlogCategoryRepository = blogCategoryRepository; CommentRepository = commentRepository; }
private void AddXXX() { FrameworkAction v = new FrameworkAction(); using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory)) { v.ActionName = ""; v.Checked = true; context.Set <FrameworkAction>().Add(v); context.SaveChanges(); } }
public void DetailsTest() { ActionLog l = new ActionLog(); using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory)) { context.Set <ActionLog>().Add(l); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Details(l.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof(IBaseCRUDVM <TopBasePoco>)); Assert.AreEqual(l.ID, (rv.Model as IBaseCRUDVM <TopBasePoco>).Entity.ID); }
public void GetTest() { FrameworkUserBase v = new FrameworkUserBase(); using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory)) { v.ITCode = "itcode"; v.Name = "name"; v.Password = "******"; context.Set <FrameworkUserBase>().Add(v); context.SaveChanges(); } var rv = _controller.Get(v.ID); Assert.IsNotNull(rv); Assert.AreEqual(rv.Entity.ITCode, "itcode"); }
public void DetailsTest() { FrameworkUserBase v = new FrameworkUserBase(); using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory)) { v.ITCode = "itcode"; v.Name = "name"; v.Password = "******"; context.Set <FrameworkUserBase>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Details(v.ID); Assert.IsInstanceOfType(rv.Model, typeof(IBaseCRUDVM <TopBasePoco>)); Assert.AreEqual(v.ID, (rv.Model as IBaseCRUDVM <TopBasePoco>).Entity.ID); }
public void ApplyDatabaseMigrations() { //Configuration is the class created by Enable-Migrations DbMigrationsConfiguration dbMgConfig = new Configuration() { //DbContext subclass generated by EF power tools ContextType = typeof(FrameworkContext) }; using (var databaseContext = new FrameworkContext()) { try { var database = databaseContext.Database; var isExistsDatabase = database.Exists(); var migrationConfiguration = dbMgConfig; migrationConfiguration.TargetDatabase = new DbConnectionInfo(database.Connection.ConnectionString, "System.Data.SqlClient"); var migrator = new DbMigrator(migrationConfiguration); // update or create database migrator.Update(); // if database is first initial, then initial data for it if (isExistsDatabase) { return; } InitialData(databaseContext); } catch (AutomaticDataLossException adle) { dbMgConfig.AutomaticMigrationDataLossAllowed = true; var mg = new DbMigrator(dbMgConfig); var scriptor = new MigratorScriptingDecorator(mg); string script = scriptor.ScriptUpdate(null, null); throw new Exception(adle.Message + " : " + script); } } }
public void ChangePassword() { //首先向数据库中添加一个用户 FrameworkUserBase v = new FrameworkUserBase(); using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory)) { v.ITCode = "user"; v.Name = "name"; v.Password = Utils.GetMD5String("password"); v.IsValid = true; context.Set <FrameworkUserBase>().Add(v); context.SaveChanges(); } //调用ChangePassword PartialViewResult rv = (PartialViewResult)_controller.ChangePassword(); //测试是否正确返回ChangePasswordVM Assert.IsInstanceOfType(rv.Model, typeof(ChangePasswordVM)); //使用返回的ChangePasswordVM,给字段赋值 ChangePasswordVM vm = rv.Model as ChangePasswordVM; vm.ITCode = "user"; vm.OldPassword = "******"; vm.NewPassword = "******"; vm.NewPasswordComfirm = "p1"; //调用ChangePassword方法修改密码 var rv2 = _controller.ChangePassword(vm); //测试是否正确修改了密码 using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory)) { var u = context.Set <FrameworkUserBase>().FirstOrDefault(); Assert.AreEqual(u.Password, Utils.GetMD5String("p1")); } //测试是否正确返回 Assert.IsInstanceOfType(rv2, typeof(FResult)); }
public void EditTest() { FrameworkUserBase v = new FrameworkUserBase(); using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory)) { v.ITCode = "itcode"; v.Name = "name"; v.Password = "******"; context.Set <FrameworkUserBase>().Add(v); context.SaveChanges(); } PartialViewResult rv = (PartialViewResult)_controller.Edit(v.ID.ToString()); Assert.IsInstanceOfType(rv.Model, typeof(FrameworkUserVM)); FrameworkUserVM vm = rv.Model as FrameworkUserVM; v = new FrameworkUserBase(); v.ID = vm.Entity.ID; v.ITCode = "itcode1"; v.Name = "name1"; vm.Entity = v; vm.FC = new Dictionary <string, object>(); vm.FC.Add("Entity.ITCode", ""); vm.FC.Add("Entity.Name", ""); _controller.Edit(vm); using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <FrameworkUserBase>().FirstOrDefault(); Assert.AreEqual(data.ITCode, "itcode1"); Assert.AreEqual(data.Name, "name1"); Assert.AreEqual(data.UpdateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10); } }
public static void MyClassInitialize(TestContext testContext) { var frameworkContext = new FrameworkContext( ConfigurationManager.GetSection("umbraco.foundation") as IFoundationConfigurationSection); var persistenceConfig = ConfigurationManager.GetSection("hive.persistence") as HiveConfigurationSection; var localConfig = persistenceConfig.AvailableProviders.ReadWriters["rw-nhibernate-01"].GetLocalProviderConfig() as ProviderConfigurationSection; var nhSetup = new NHibernateConfigBuilder("rw-nhibernate-01", localConfig); var config = nhSetup.BuildConfiguration(); // Setup the local provider var dataContextFactory = new DataContextFactory(config.BuildSessionFactory()); var unitOfWorkFactory = new ReadWriteRepositoryUnitOfWorkFactory(dataContextFactory); var reader = new Reader(unitOfWorkFactory); var readWriter = new ReadWriter(unitOfWorkFactory); var uriMatch = new DefaultUriMatch() {MatchType = UriMatchElement.MatchTypes.Wildcard, Uri = "content://*/"}; // Setup hive's provider governor. Normally it takes two uow factories (read and read-write) but we can use the same for both here _mappingGroup = new DefaultPersistenceMappingGroup("rw-nhibernate-01", new[] { unitOfWorkFactory }, new[] { unitOfWorkFactory }, new[] { reader }, new[] { readWriter }, new[]{uriMatch}); }
private static void App_Start() { ProfileRegistration.RegisterMapping(); _context = new DesignTimeDbContextFactory().CreateDbContext(null); //_studentService = new StudentService(_context); }
public StudentService(FrameworkContext context, IConnection busClient) { _uow = new EFUnitOfWork(context); _busClient = busClient; }
public EFUnitOfWork(FrameworkContext dbContext) { // Database.SetInitializer<FrameworkContext>(null); _dbContext = dbContext; }
public HomeController(ILogger <HomeController> logger, FrameworkContext context) { _logger = logger; _context = context; }
public EFRepository(FrameworkContext dbContext) { _dbContext = dbContext; _dbSet = dbContext.Set <T>(); }
private static void InitUsers(FrameworkContext context) { var admin = new User { RoleId = context.Role.First(x => x.IsDeleted == false && x.Name == Constants.RoleName.Admin).Id, Email = BackendHelpers.AdminEmail(), FirstName = Constants.RoleName.Admin, LastName = Constants.AppName, PasswordHash = BackendHelpers.AdminPasswordHash(), PasswordSalt = BackendHelpers.AdminPasswordSalt(), IsActive = true, IsDeleted = false, CreatedDate = DateTimeHelper.UTCNow() }; context.User.AddOrUpdate(x => x.Email, admin); context.SaveChanges(); }
public BooksController(IConfiguration configuration, FrameworkContext frameworkContext) { _configuration = configuration; _frameworkContext = frameworkContext; }
public static void Initialize(FrameworkContext context) { //context.Database.EnsureCreated(); // Look for any students. if (context.Students.Any()) { return; // DB has been seeded } var students = new Student[] { new Student { FirstMidName = "Carson", LastName = "Alexander", EnrollmentDate = DateTime.Parse("2005-09-01") }, new Student { FirstMidName = "Meredith", LastName = "Alonso", EnrollmentDate = DateTime.Parse("2002-09-01") }, new Student { FirstMidName = "Arturo", LastName = "Anand", EnrollmentDate = DateTime.Parse("2003-09-01") }, new Student { FirstMidName = "Gytis", LastName = "Barzdukas", EnrollmentDate = DateTime.Parse("2002-09-01") }, new Student { FirstMidName = "Yan", LastName = "Li", EnrollmentDate = DateTime.Parse("2002-09-01") }, new Student { FirstMidName = "Peggy", LastName = "Justice", EnrollmentDate = DateTime.Parse("2001-09-01") }, new Student { FirstMidName = "Laura", LastName = "Norman", EnrollmentDate = DateTime.Parse("2003-09-01") }, new Student { FirstMidName = "Nino", LastName = "Olivetto", EnrollmentDate = DateTime.Parse("2005-09-01") } }; foreach (Student s in students) { context.Students.Add(s); } context.SaveChanges(); var courses = new Course[] { new Course { CourseID = 1050, Title = "Chemistry", Credits = 3 }, new Course { CourseID = 4022, Title = "Microeconomics", Credits = 3 }, new Course { CourseID = 4041, Title = "Macroeconomics", Credits = 3 }, new Course { CourseID = 1045, Title = "Calculus", Credits = 4 }, new Course { CourseID = 3141, Title = "Trigonometry", Credits = 4 }, new Course { CourseID = 2021, Title = "Composition", Credits = 3 }, new Course { CourseID = 2042, Title = "Literature", Credits = 4 } }; foreach (Course c in courses) { context.Courses.Add(c); } context.SaveChanges(); var enrollments = new Enrollment[] { new Enrollment { StudentID = 1, CourseID = 1050, Grade = Grade.A }, new Enrollment { StudentID = 1, CourseID = 4022, Grade = Grade.C }, new Enrollment { StudentID = 1, CourseID = 4041, Grade = Grade.B }, new Enrollment { StudentID = 2, CourseID = 1045, Grade = Grade.B }, new Enrollment { StudentID = 2, CourseID = 3141, Grade = Grade.F }, new Enrollment { StudentID = 2, CourseID = 2021, Grade = Grade.F }, new Enrollment { StudentID = 3, CourseID = 1050 }, new Enrollment { StudentID = 4, CourseID = 1050 }, new Enrollment { StudentID = 4, CourseID = 4022, Grade = Grade.F }, new Enrollment { StudentID = 5, CourseID = 4041, Grade = Grade.C }, new Enrollment { StudentID = 6, CourseID = 1045 }, new Enrollment { StudentID = 7, CourseID = 3141, Grade = Grade.A }, }; foreach (Enrollment e in enrollments) { context.Enrollments.Add(e); } context.SaveChanges(); }
public ExamUnitOfWork(FrameworkContext context, IStudentRepository studentRepositroy) : base(context) { StudentRepositroy = studentRepositroy; }
private static void InitialData(FrameworkContext context) { InitRoles(context); InitUsers(context); }
public SettingsController(FrameworkContext frameworkContext) { _frameworkContext = frameworkContext; }
public virtual FrameworkContext Get() { return(this.frameworkContext_0 ?? (this.frameworkContext_0 = (FrameworkContext)Activator.CreateInstance <TContext>())); }
public StockMarketUnitOfWork(FrameworkContext context, IStockMarketRepository stockMarketRepository) : base(context) { StockMarketRepository = stockMarketRepository; }
public IActionResult Config() { var test = new FrameworkContext(); return(PartialView()); }
public EmsUnitOfWork(FrameworkContext databaseContext, ICampaignRepository campaignRepository ) : base(databaseContext) { CampaignRepository = campaignRepository; }