I am trying to setup a simple unit test using Noda Time. My code is:
public void ValidityPassedDate()
{
FakeClock fakeClock = new FakeClock(SystemClock.Instance.Now);
fakeClock.AdvanceDays(60);
MyClass myObj = new MyClass(fakeClock);
myObj.Validity = "1";
myObj.Date = SystemClock.Instance.Now.InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).LocalDateTime.Date;
Assert.IsTrue(myObj.ValidityIsValid);
}
But I get this error when I try to build the test:
error CS0012: The type 'System.Xml.Serialization.IXmlSerializable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=----------(I erased this on purpose)'.
How can I solve this? What's missing? VS2013 point the error to the FakeClock
type in "FakeClock fakeClock =..."
You need to add a reference to the System.Xml
assembly (not a using
directive for the System.Xml
namespace). Do that in Solution Explorer - it's not a code issue.
This is unfortunate, but as far as I can tell it's an unavoidable side-effect of Noda Time implementing XML serialization... presumably due to the attributes used to decorate the type.
See more on this question at Stackoverflow