У меня есть текст, к которому у лога c есть доступ через репозиторий. Я хочу определить, что когда я вызываю метод Write из logi c, метод Write для репозиториев вызывается один раз. Мой код:
[Test]
public void TestThatWriteWasCalledOnce()
{
Mock<IRepository> mockinstance = new Mock<IRepository>();
LogicSaveGame logic = new LogicSaveGame(mockinstance.Object);
//mockinstance.Setup(x => x.Write(It.IsAny<string>(), It.IsAny<string>())). //???
logic.Write(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>());
mockinstance.Verify(x => x.Write(It.IsAny<string>(), It.IsAny<string>()), Times.Once());
}
Когда я запускаю тест, описанный выше, я получаю сообщение об ошибке:
Message:
System.ArgumentNullException : Value cannot be null.
Parameter name: value
Stack Trace:
XAttribute.ctor(XName name, Object value)
Я очень благодарен за любую помощь, не могу найти что-нибудь с Google.
Правка, логическая игра:
private readonly IRepository saveGameRepo;
public LogicSaveGame(IRepository repo)
{
this.saveGameRepo = repo;
}
public void Write(string name, string a, string b, string filename)
{
int ids = this.saveGameRepo.GetIds(filename);
var xd = new XElement(
"game",
new XAttribute("id", ids + 1),
new XAttribute("name", name),
new XAttribute("hour", DateTime.Now.Hour),
new XAttribute("minute", DateTime.Now.Minute),
new XElement(
"player1",
new XElement("name", a.Name),
new XElement(
"player2",
new XElement("name", b.Name),
));
this.saveGameRepo.Write(filename, xd.ToString());
}
Правка 2: я получаю ту же ошибку с mockinstance.Setup (x => x.Write (It.IsAny (), It.IsAny ()) ) .Verifiable ();