本文整理汇总了C#中Repository.GetData方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.GetData方法的具体用法?C# Repository.GetData怎么用?C# Repository.GetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Repository
的用法示例。
在下文中一共展示了Repository.GetData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestChangePath
public void TestChangePath()
{
string name = "Test before";
int number = 42;
string newpath = TEST_DIRECTORY + "testChangePathNew.txt";
using (Repository<TestObject> manager = new Repository<TestObject>(TEST_DIRECTORY + "testChangePath.txt"))
{
TestObject data = manager.GetData();
data.Name = name;
data.Number = number;
manager.Save();
manager.ChangePath(newpath);
Assert.IsTrue(File.Exists(newpath));
Assert.AreEqual(Path.GetFullPath(newpath), manager.Path);
TestObject loadData = manager.GetData();
Assert.AreEqual(name, loadData.Name);
Assert.AreEqual(number, loadData.Number);
}
using (Repository<TestObject> manager = new Repository<TestObject>(newpath))
{
TestObject loadData = manager.GetData();
Assert.AreEqual(name, loadData.Name);
Assert.AreEqual(number, loadData.Number);
}
}
示例2: TestInvalidFileOverride
public void TestInvalidFileOverride()
{
string path = TEST_DIRECTORY + "testInvalidFileOverride.txt";
string fileContent = "}!Invalid file!{";
using (StreamWriter writer = new StreamWriter(path))
{
writer.Write(fileContent);
}
using (Repository<TestObject> manager = new Repository<TestObject>(path, true)) {
TestObject loadData = manager.GetData();
loadData.Name = "Testing one two";
loadData.Number = 42;
manager.Save();
}
using (StreamReader reader = new StreamReader(path))
{
Assert.AreNotEqual(fileContent, reader.ReadToEnd());
}
}
示例3: TestReset
public void TestReset()
{
using (Repository<TestObject> manager = new Repository<TestObject>(TEST_DIRECTORY + "testReset.txt"))
{
string name = "Test before";
int number = 42;
TestObject data = manager.GetData();
data.Name = name;
data.Number = number;
manager.Save();
manager.Reset();
TestObject loadData = manager.GetData();
Assert.AreNotEqual(loadData.Name, name);
Assert.AreNotEqual(loadData.Number, number);
}
}
示例4: TestSaving
public void TestSaving()
{
string path = TEST_DIRECTORY + "testSaving.txt";
string name = "Test";
int number = 42;
Repository<TestObject> manager = null;
using (manager = new Repository<TestObject>(path))
{
TestObject data = manager.GetData();
data.Name = name;
data.Number = number;
manager.Save();
TestObject loadData1 = manager.GetData();
Assert.AreEqual(name, loadData1.Name);
Assert.AreEqual(number, loadData1.Number);
}
using (manager = new Repository<TestObject>(path))
{
TestObject loadData2 = manager.GetData();
Assert.AreEqual(name, loadData2.Name);
Assert.AreEqual(number, loadData2.Number);
}
}
示例5: TestReference
public void TestReference()
{
using (Repository<TestObjectReference> manager = new Repository<TestObjectReference>(TEST_DIRECTORY + "testReference.txt"))
{
int value1 = 1;
int value2 = 2;
TestObjectReference data1 = manager.GetData();
TestObjectReference data2 = new TestObjectReference();
data1.Reference = data2;
data1.Value = value1;
data2.Reference = data1;
data2.Value = value2;
manager.Save();
TestObjectReference result = manager.GetData();
Assert.AreEqual(value1, result.Value);
Assert.AreEqual(value2, result.Reference.Value);
Assert.AreEqual(value1, result.Reference.Reference.Value);
}
}