设为首页 加入收藏

TOP

[开源]Entity Framework 6 Repository 一种实现方式(五)
2019-09-17 19:08:24 】 浏览:119
Tags:开源 Entity Framework Repository 实现 方式
ervice = _kernel.Get<ISampleService>(); //if (!_sampleService.Exist(ent => ent.ID == _testID)) //{ // _sampleService.Create(new EFSample() { UserName = _testName, ID = _testID }); //} } /// <summary> /// 创建测试 /// </summary> [TestMethod()] public void CreateTest() { bool actual = _sampleService.Create(new EfSample() { UserName = "ef" + DateTime.Now.ToString("MMddHHmmss") }); Assert.IsTrue(actual); actual = _sampleService.Create(new EfSample() { UserName = "ef" + DateTime.Now.ToString("MMddHHmmss") }); Assert.IsTrue(actual); actual = _sampleService.Create(new EfSample() { UserName = "ef" + DateTime.Now.ToString("MMddHHmmss") }); Assert.IsTrue(actual); actual = _sampleService.Create(new EfSample() { UserName = "ef" + DateTime.Now.ToString("MMddHHmmss") }); Assert.IsTrue(actual); actual = _sampleService.Create(new EfSample() { UserName = "ef" + DateTime.Now.ToString("MMddHHmmss") }); Assert.IsTrue(actual); } [TestMethod()] public void GetFirstOrDefaultTest() { EfSample actual = _sampleService.GetFirstOrDefault(ent => ent.Id == _testId); Assert.IsNotNull(actual); } [TestMethod()] public void GetByKeyIdTest() { EfSample actual = _sampleService.GetByKeyId(_testId); Assert.IsNotNull(actual); } [TestMethod()] public void GetListTest() { // ReSharper disable once RedundantBoolCompare List<EfSample> actual = _sampleService.GetList(ent => ent.Available == true); Assert.IsNotNull(actual); CollectionAssert.AllItemsAreNotNull(actual); } [TestMethod()] public void UpdateTest() { EfSample sample = new EfSample { Id = _testId, ModifyTime = DateTime.Now, UserName = "modify" }; bool actual = _sampleService.Update(sample); Assert.IsNotNull(actual); } [TestMethod()] public void TransactionSuccessTest() { EfSample sample = new EfSample { UserName = "TransactionSuccess1" }; EfSample sample2 = new EfSample { UserName = "TransactionSuccess2" }; bool actual = _sampleService.CreateWithTransaction(sample, sample2); Assert.IsTrue(actual); } [TestMethod()] public void TransactionFailTest() { EfSample sample3 = new EfSample { UserName = "TransactionSuccess3" }; EfSample sample4 = new EfSample { UserName = null }; bool actual = _sampleService.CreateWithTransaction(sample3, sample4); Assert.IsFalse(actual); } [TestMethod()] public void ExistTest() { bool actual = _sampleService.Exist(ent => ent.Id == _testId); Assert.IsTrue(actual); actual = _sampleService.Exist(ent => ent.UserName == TestName); Assert.IsTrue(actual); DateTime createTime = DateTime.Now.AddDays(-1); actual = _sampleService.Exist(ent => ent.CreateTime >= createTime); Assert.IsTrue(actual); actual = _sampleService.Exist(ent => ent.CreateTime <= DateTime.Now); Assert.IsTrue(actual); // ReSharper disable once RedundantBoolCompare actual = _sampleService.Exist(ent => ent.Available == true); Assert.IsTrue(actual); actual = _sampleService.Exist(ent => ent.Available != true); Assert.IsFalse(actual); } [TestMethod()] public void SqlQueryTest() { string sql = @"select * from [dbo].[EFSample] where CreateTime
首页 上一页 2 3 4 5 下一页 尾页 5/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇9.10 翻译系列:EF数据注解特性之.. 下一篇<<C语言--神奇的指针>&g..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目