本文整理汇总了C#中TestRepository.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# TestRepository.Insert方法的具体用法?C# TestRepository.Insert怎么用?C# TestRepository.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestRepository
的用法示例。
在下文中一共展示了TestRepository.Insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEntityByIDTest
public void GetEntityByIDTest()
{
IUnitOfWork unitOfWork = new TestDBContext(); // TODO: 初始化为适当的值
TestRepository target = new TestRepository(unitOfWork); // TODO: 初始化为适当的值
TestModel actual = new TestModel();
actual.testName = "name";
actual.testDesc = "1223";
target.Insert(actual);
target.Save();
TestModel expected = target.GetEntityByID(actual.testID);
Assert.AreEqual(expected.testID, actual.testID,"新插入数据ID用来获取,其结果ID不一致");
}
示例2: ListTest
public void ListTest()
{
IUnitOfWork unitOfWork = new TestDBContext(); // TODO: 初始化为适当的值
TestRepository target = new TestRepository(unitOfWork); // TODO: 初始化为适当的值
TestModel expected = null; // TODO: 初始化为适当的值
IEnumerable<TestModel> actual;
target.DeleteAll();
target.Save();
actual = target.List();
Assert.AreEqual((actual as List<TestModel>).Count,0);
expected = new TestModel();
expected.testName = "123Name";
expected.testDesc = "123Desc";
target.Insert(expected);
expected = new TestModel();
expected.testName = "123Name";
expected.testDesc = "123Desc";
target.Insert(expected);
target.Save();
actual = target.List();
Assert.AreEqual((actual as List<TestModel>).Count, 2);
}
示例3: TestRepositoryConstructorTest
public void TestRepositoryConstructorTest()
{
//1.准备工作
IUnitOfWork unitOfWork = new TestDBContext(); // TODO: 初始化为适当的值
TestRepository target = new TestRepository(unitOfWork);
//
bool isTrue = target.Context is TestDBContext;
Assert.IsTrue(isTrue, "给定对象不能转换为指定的TestDBContext类型");
isTrue = target.Context is BaseDBContext;
Assert.IsTrue(isTrue, "给定对象不能转换为指定的BaseDBContext类型");
TestModel test = new TestModel();
target.Insert(test);
TestDBContext testDBC = target.Context as TestDBContext;
Assert.AreEqual(testDBC, target.Context);
Assert.IsNotNull(testDBC.Tests.Find(test.testID));
Assert.IsNull(testDBC.Tests.Find(0));
BaseDBContext baseDBC = target.Context as BaseDBContext;
Assert.IsNotNull(baseDBC.Set<TestModel>().Find(test.testID));
Assert.IsNull(baseDBC.Set<TestModel>().Find(0));
Assert.AreEqual(testDBC, target.Context);
}