我正在为我的WP7.1应用实施一个数据储存接入班。
课程的一般继承结构如下:
IDataStore
——接口,使应用狗类的逻辑操作脱节。
http://www.ohchr.org。
<代码>摘要方法 缩略语
public abstract void CreateDataStore();
public abstract void OpenDataStore();
public abstract void SaveChanges();
此外,一个抽象的类别包含由继承人使用的一系列定义:
protected const string xmlRoot = "Data";
protected const string booksRoot = "Records";
protected const string settingsRoot = "Settings";
<代码>有两个继承人 XmlDataStore:IsolatedStorageDataStore
和InMemoryDataStore
。
之后是出于测试目的建立的,因此,我可以测试在<条码>上实施的XmlDataStore的腐蚀性。
I have added a Windows Phone Class Library to my solution. References NUnit via NuGet and have implemented one [TestFixture]:
[TestFixture]
public class XmlDataStoreTest
{
private IDataStore _store;
public XmlBookProgressStoreTest()
{
_store = new InMemoryXmlDataStore();
}
[Test]
public void TestRegisterBookView()
{
_store.RegisterBookView(BookId, "TestBook");
}
}
An InMemoryDataStore
currently is the following class:
public class InMemoryDataStore : XmlDataStore
{
private XDocument _inMemDoc;
public InMemoryDataStore()
{
CreateDataStore();
OpenDataStore();
}
public override void CreateDataStore()
{
try
{
var root = new XElement(xmlRoot);
root.Add(new XElement(booksRoot));
root.Add(new XElement(settingsRoot));
_inMemDoc = new XDocument(root);
}
catch (Exception ex)
{
throw ex;
}
}
public override void OpenDataStore()
{
_deusBookDataFile = _inMemDoc;
}
public override void SaveChanges()
{}
}
}
现在,当我用简单的申请表对这个类别进行辩论时,InMemoryDataStore
instanciates予以罚款,但当我对我的单位进行测试时,我收到了一份“var fundamental =个新的XElement(xmlRoot);
。
Clearly the problem only happens in unit test execution so it must be somehow connected to it. Why is the exception there and how can I fix it?