Chapter 6 - Adding mine own unit test following example from the book is not working : (
Closed this issue · 2 comments
iqbalsiddiqui commented
[Fact]
public void Adding_third_entry_in_existing_file_which_have_already_two_entries()
{
var fileSystemMock = new Mock<IFileSystem>();
fileSystemMock
.Setup(x => x.GetFiles("audits"))
.Returns(new string[]
{
@"audits\audit_1.txt"
});
fileSystemMock
.Setup(x => x.ReadAllLines(@"audits\audit_1.txt"))
.Returns(new List<string>
{
"Peter; 2019-04-06T16:30:00",
"Jane; 2019-04-06T16:40:00"
});
var sut = new AuditManager(3, "audits", fileSystemMock.Object);
sut.AddRecord("Alice", DateTime.Parse("2019-04-06T18:00:00"));
fileSystemMock.Verify(x => x.WriteAllText(
@"audits\audit_1.txt",
"Peter; 2019-04-06T16:30:00\r\nJane; 2019-04-06T16:40:00\r\nAlice; 2019-04-06T18:00:00"));
}
vkhorikov commented
@iqbalsiddiqui There's an extra space in your assertion, should read as Alice;2019-04-06T18:00:00
:
fileSystemMock.Verify(x => x.WriteAllText(
@"audits\audit_1.txt",
"Peter; 2019-04-06T16:30:00\r\nJane; 2019-04-06T16:40:00\r\nAlice;2019-04-06T18:00:00"));
iqbalsiddiqui commented
I see, thanks a lot! 👍