public void GetListTest2() { //使用 IoCHelper 测试 (不指定 Name 注入) IArticleRepository target = IoCHelper.Resolve <IArticleRepository>(); IEnumerable <BlogArticle> list = target.GetList(); //测试序列化成JSON数据 string json = SerializeHelper.JsonSerialize(list); Assert.IsTrue(list != null); }
/// <summary> /// 在需要授权时调用。 /// </summary> /// <param name="filterContext">筛选器上下文。</param> public void OnAuthorization(AuthorizationContext filterContext) { if (!IoCHelper.Resolve <IUserService>().CheckLogin()) { var urlHelper = new UrlHelper(filterContext.RequestContext); filterContext.Result = new RedirectResult(urlHelper.Action("Login", "Default", new { area = "Account", redirect = filterContext.RequestContext.HttpContext.Request.Url.ToString() })); } }
public void NewSaveTest() { ICategoryRepository category = IoCHelper.Resolve <ICategoryRepository>(); BlogCategory model = new BlogCategory(); int expected = 0; int actual = 0; model.CateName = "新分类" + new Random().Next(100000, 999999).ToString(); model.ParentID = 0; model.State = 0; model.CreateTime = DateTime.Now; category.NewSave(model); category.SaveChanges(); Assert.AreEqual(expected, actual); }
public void GetListTest() { //使用IoC测试 //IUnityContainer container = new UnityContainer(); //UnityConfigurationSection section = ConfigurationManager.GetSection("unity") as UnityConfigurationSection; //section.Configure(container, "ContainerEF"); //IArticleRepository target = container.Resolve<IArticleRepository>("articleRepository"); //固定代码测试 //RoRoWoDBEntities context = new RoRoWoDBEntities(); //ArticleRepository target = new ArticleRepository(context); //使用 IoCHelper 测试 IArticleRepository target = IoCHelper.Resolve <IArticleRepository>("articleRepository"); IEnumerable <BlogArticle> list = target.GetList(); Assert.IsTrue(list != null); }
public void FindAllTest() { FindAllTestHelper <int>(); ICategoryRepository target = IoCHelper.Resolve <ICategoryRepository>(); int PageIndex = 1; // TODO: 初始化为适当的值 int PageSize = 10; // TODO: 初始化为适当的值 Expression <Func <BlogCategory, bool> > condition = x => x.CateID > 0; // TODO: 初始化为适当的值 Expression <Func <BlogCategory, int> > orderByExpression = x => x.CateID; // TODO: 初始化为适当的值 bool IsDESC = false; // TODO: 初始化为适当的值 PageData <BlogCategory> expected = null; // TODO: 初始化为适当的值 PageData <BlogCategory> actual; ISpecification <BlogCategory> specification = new DirectSpecification <BlogCategory>(condition); actual = target.FindAll <int>(PageIndex, PageSize, specification, orderByExpression, IsDESC); Assert.IsTrue(actual.DataList.Count > 0); }
public void FindAllTest() { IArticleRepository target = IoCHelper.Resolve <IArticleRepository>(); int PageIndex = 1; int PageSize = 10; Expression <Func <BlogArticle, bool> > condition = x => x.ArticleID > 0; Expression <Func <BlogArticle, int> > orderByExpression = x => x.ArticleID; bool IsDESC = true; ISpecification <BlogArticle> specification = new DirectSpecification <BlogArticle>(condition); PageData <BlogArticle> left; PageData <BlogArticle> right; left = target.Find <int>(PageIndex, PageSize, specification, orderByExpression, IsDESC); right = target.FindAll <int>(PageIndex, PageSize, specification, orderByExpression, IsDESC); Assert.IsTrue(right.DataList.Count > 0); Assert.IsTrue(left.DataList.Count < right.DataList.Count); }
public void NewArcitleTest() { IArticleServices article = IoCHelper.Resolve <IArticleServices>("articleServices"); BlogArticle model = new BlogArticle(); int expected = 0; int actual = 0; model.Title = "测试标题" + new Random().Next(100000, 999999).ToString(); model.IsTop = true; model.Content = "这里是内容--ArticleServices--NewArcitleTest"; model.PublishTime = DateTime.Now; model.CreateTime = DateTime.Now; model.UpdateTime = DateTime.Now; actual = article.NewArcitle(model, 2); Assert.IsTrue(expected < actual); }
public string InsertUseDbContextTransaction(bool success) { //插入数据,使用数据库事务,不支持多连接。 var dbContext = IoCHelper.Resolve <IDbContextCore>(); using (IDbContextTransaction trans = dbContext.BeginTransaction()) { try { var service1 = IoCHelper.Resolve <ICRUDService <sys_log> >(); service1.Use(dbContext); sys_log e1 = new sys_log() { Id = GuidHelper.NewGuid().ToString(), CreateDate = DateTime.Now }; int i1 = service1.Insert(e1); var service2 = IoCHelper.Resolve <ICRUDService <sys_file> >(); service2.Use(dbContext); string id = success ? GuidHelper.NewGuid().ToString() : GuidHelper.NewGuid().ToString().PadRight(100, '0'); sys_file e2 = new sys_file() { Id = id, CreateDate = DateTime.Now }; int i2 = service2.Insert(e2); trans.Commit(); return($"成功{i1},{i2}"); } catch (Exception) { trans.Rollback(); throw; } } }
public string Insert(bool success) { //插入数据 var service1 = IoCHelper.Resolve <ICRUDService <sys_log> >(); sys_log e1 = new sys_log() { Id = GuidHelper.NewGuid().ToString(), CreateDate = DateTime.Now }; int i1 = service1.Insert(e1); var service2 = IoCHelper.Resolve <ICRUDService <sys_file> >(); string id = success ? GuidHelper.NewGuid().ToString() : GuidHelper.NewGuid().ToString().PadRight(100, '0'); sys_file e2 = new sys_file() { Id = id, CreateDate = DateTime.Now }; int i2 = service2.Insert(e2); return($"成功{i1},{i2}"); }
public CollapsiblePanel() { this.InitializeComponent(); this.DataContext = IoCHelper.Resolve <CollapsiblePanelViewModel>(); }
public MainWindow() { this.InitializeComponent(); this.DataContext = IoCHelper.Resolve <MainWindowViewModel>(); }
public MainView() { InitializeComponent(); _userWindowsConnector = IoCHelper.Resolve <IUserWindowsConnector>(); }
public SummaryPanel() { this.InitializeComponent(); this.DataContext = IoCHelper.Resolve <SummaryPanelViewModel>(); }
public string CRUDSimple() { //增删改查服务 var service = IoCHelper.Resolve <ICRUDService <ts_test> >(); //构建实体,从前端或根据业务逻辑构建获得 ts_test one = new ts_test() { Id = GuidHelper.NewGuid().ToString(), TestName = "单个名称" + DateTime.Now.Millisecond, CreatorId = GuidHelper.NewGuid().ToString(), CreatorName = "创建人", CreateDate = DateTime.Now }; //新增单个实体 service.Insert(one); //更新单个实体 one.TestName += "update"; service.Update(one); //查询分页 var pagelist = service.PageQuery(new PageInfo() { PageIndex = 1, PageSize = 10 }); //删除单个实体 service.Delete(one.Id); //新增多个实体 var list = new List <ts_test>() { new ts_test() { Id = GuidHelper.NewGuid().ToString(), TestName = "批量名称" + DateTime.Now.Millisecond, CreatorId = GuidHelper.NewGuid().ToString(), CreatorName = "创建人", CreateDate = DateTime.Now }, new ts_test() { Id = GuidHelper.NewGuid().ToString(), TestName = "批量名称" + DateTime.Now.Millisecond, CreatorId = GuidHelper.NewGuid().ToString(), CreatorName = "创建人", CreateDate = DateTime.Now } }; service.Insert(list); //更新方式二 service.Update(x => x.CreatorName == list[0].CreatorName, y => new ts_test { TestName = y.TestName + "UpdateForExpression" }); //查询分页 pagelist = service.PageQuery(new PageInfo() { PageIndex = 1, PageSize = 10 }); //删除方式二 service.Delete(x => x.CreatorName == list[0].CreatorName); return(pagelist.ToJson()); }
public GalaxyMapPanel() { this.InitializeComponent(); this.DataContext = IoCHelper.Resolve <GalaxyMapPanelViewModel>(); }
public StartupWindow() { this.InitializeComponent(); this.DataContext = IoCHelper.Resolve <StartupWindowViewModel>(); (this.DataContext as StartupWindowViewModel).CloseAction = this.Close; }
public HabitationBarControl() { this.InitializeComponent(); this.DataContext = IoCHelper.Resolve <HabitationBarControlViewModel>(); }