Example #1
0
        public void Test_dataAdapter_create_article()
        {
            // Arrange
            utils.CleanTables();
            Tuple <string, string> userIds = utils.CreateUsers();
            IDataAccessAdapter     adapter = container.Resolve <IDataAccessAdapter>();
            string  test_title             = "test_title";
            string  test_body = "test_body";
            Article article   = adapter.Create <Article>();

            article.Title       = test_title;
            article.Body        = test_body;
            article.CreatedDate = DateTime.Now;
            article.AuthorId    = userIds.Item1;

            // Act
            adapter.Add <Article>(article);
            adapter.SaveChanges();
            List <Article> articleList    = adapter.GetEntities <Article>().ToList();
            Article        createdArticle = articleList[0];

            // Assert
            Assert.IsTrue(articleList.Count == 1);
            Assert.IsNotNull(createdArticle.AspNetUser);
            Assert.IsTrue(createdArticle.AuthorId == userIds.Item1);
            Assert.IsTrue(createdArticle.Likes.Count() == 0);
        }
Example #2
0
        public void Test_dataAdapter_add_like()
        {
            // Arrange
            utils.CleanTables();
            Tuple <string, string> userIds = utils.CreateUsers();
            int articleId = utils.CreateSingleArticle(userIds.Item2);
            IDataAccessAdapter adapter = container.Resolve <IDataAccessAdapter>();
            Article            article = adapter.GetEntities <Article>().SingleOrDefault(n => n.Id == articleId);
            Like like = adapter.Create <Like>();

            like.CreatedDate = DateTime.Now;
            like.ArticleId   = articleId;
            like.UserId      = userIds.Item1;

            // Act
            article.Likes.Add(like);
            adapter.SaveChanges();
            Article modifiedArticle = adapter.GetEntities <Article>().SingleOrDefault(n => n.Id == articleId);

            // Assert
            Assert.IsNotNull(modifiedArticle);
            Assert.IsTrue(modifiedArticle.Likes.Count() == 1);
            Assert.IsNotNull(like.Article);
            Assert.IsNotNull(like.AspNetUser);
        }
Example #3
0
 public TEntity Create()
 {
     return(_dataAccessAdapter.Create <TEntity>());
 }