public void ReadDatabase_FileContentsAreNullOrEmpty_ReturnsEmptyList(string stub_fileContents) { var stubReader = new StubIFileReader(); var stubWriter = new StubIFileWriter(); var fileDataAccess = new FileDataAccess <FakeBlogModel>(stubReader, stubWriter); stubReader.StubRead(stub_fileContents); var param_filePath = "path/to/the/file.json"; var expected_return = new List <FakeBlogModel>(); var actual_return = fileDataAccess.ReadDatabase(param_filePath); Assert.Equal(expected_return, actual_return); }
public void WriteToDatabase_ListOfEntityIsValidAndDatabaseContainsOneObject_Returns() { var stubReader = new StubIFileReader(); var stubWriter = new StubIFileWriter(); var fileDataAccess = new FileDataAccess <FakeBlogModel>(stubReader, stubWriter); var param_filePath = "path/to/the/file.json"; var param_listOfEntity = new List <FakeBlogModel> { new FakeBlogModel() }; stubReader.StubRead(JsonConvert.SerializeObject(param_listOfEntity)); fileDataAccess.WriteToDatabase(param_filePath, param_listOfEntity); }
public void ReadDatabase_FileContainsOneObject_ReturnsListWithTheOneObject() { var stubReader = new StubIFileReader(); var stubWriter = new StubIFileWriter(); var fileDataAccess = new FileDataAccess <FakeBlogModel>(stubReader, stubWriter); var param_filePath = "path/to/the/file.json"; var stub_listOfEntity = new List <FakeBlogModel> { new FakeBlogModel() }; var stub_fileContents = JsonConvert.SerializeObject(stub_listOfEntity); stubReader.StubRead(stub_fileContents); var expected_return = JsonConvert.DeserializeObject <List <FakeBlogModel> >(stub_fileContents); var actual_return = fileDataAccess.ReadDatabase(param_filePath); Assert.Equal(expected_return.Count, actual_return.Count); Assert.Equal(expected_return[0].FakeProperty, actual_return[0].FakeProperty); }
public void WriteToDatabase_ListOfEntityIsValidAndDatabaseContainsOneObject_VerifyWriter() { var stubReader = new StubIFileReader(); var mockWriter = new MockIFileWriter(); var fileDataAccess = new FileDataAccess <FakeBlogModel>(stubReader, mockWriter); var param_filePath = "path/to/the/file.json"; var param_listOfEntity = new List <FakeBlogModel> { new FakeBlogModel() }; var stub_listOfEntity = new List <FakeBlogModel> { new FakeBlogModel() }; stubReader.StubRead(JsonConvert.SerializeObject(stub_listOfEntity)); stub_listOfEntity.AddRange(param_listOfEntity); fileDataAccess.WriteToDatabase(param_filePath, param_listOfEntity); mockWriter.VerifyWrite(param_filePath, false, JsonConvert.SerializeObject(stub_listOfEntity)); }