public void Count_DataAbsent_ZeroReturned() { // Arrange var filePath = System.IO.Path.Combine(Utilities.IO.UncPath.GetApplicationDirectory(), "[Foundation].[Article].json"); Utilities.IO.File.Delete(filePath); var articleRepository = new ArticleRepository(); // Act var count = articleRepository.Count(); // Assert Assert.AreEqual(0, count); }
public void Count_DataPresent_CorrectNumberReturned() { // Arrange var expectedCount = 2; string filePath = null; try { var articles = new List <Article>(); for (var i = 0; i < expectedCount; i++) { articles.Add(new Article { ApprovalStatus = 444, ApprovedBy = "Ryan", DateApproved = DateTime.Now, DateTime = DateTime.Now.AddDays(-1), Id = Guid.NewGuid(), Rating = 5, RelatesToId = Guid.NewGuid().ToString(), RelatesToType = "Test", ThreadId = Guid.NewGuid(), UserId = Guid.NewGuid().ToString(), WebsiteId = Guid.NewGuid() }); } var serialisedArticles = JsonConvert.SerializeObject(articles); var serialisedArticleBytes = System.Text.Encoding.Unicode.GetBytes(serialisedArticles); filePath = System.IO.Path.Combine(Utilities.IO.UncPath.GetApplicationDirectory(), "[Foundation].[Article].json"); System.IO.File.WriteAllBytes(filePath, serialisedArticleBytes); var articleRepository = new ArticleRepository(); // Act var count = articleRepository.Count(); // Assert Assert.AreEqual(expectedCount, count); } finally { if (!string.IsNullOrWhiteSpace(filePath)) { Utilities.IO.File.Delete(filePath); } } }