コード例 #1
0
        public void FindByIds_MatchingRecordsPresent_ReturnsInstances()
        {
            // Arrange
            var    count    = 10;
            string filePath = null;

            try
            {
                var articles = new List <Article>();
                for (var i = 0; i < count; 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();
                var sourceObject1     = articles[0];
                var sourceObject2     = articles[1];

                // Act
                var results = articleRepository.FindByIds(new object[] { sourceObject1.Id, sourceObject2.Id });

                // Assert
                var result1  = results.FirstOrDefault(r => r.Id == sourceObject1.Id);
                var result2  = results.FirstOrDefault(r => r.Id == sourceObject2.Id);
                var comparer = new Utilities.Collections.EqualityComparer <Article>();
                Assert.AreEqual(2, results.Count);
                Assert.IsTrue(comparer.Equals(sourceObject1, result1));
                Assert.IsTrue(comparer.Equals(sourceObject2, result2));
            }
            finally
            {
                if (!string.IsNullOrWhiteSpace(filePath))
                {
                    Utilities.IO.File.Delete(filePath);
                }
            }
        }