Пример #1
0
        public void Test_dataAdapter_delete_article()
        {
            // Arrange
            utils.CleanTables();
            Tuple <string, string> userIds = utils.CreateUsers();
            int articleId = utils.CreateSingleArticle(userIds.Item2);

            utils.AddLike(userIds.Item2, articleId);
            IDataAccessAdapter adapter = container.Resolve <IDataAccessAdapter>();
            Article            article = adapter.GetEntities <Article>().SingleOrDefault(n => n.Id == articleId);

            // Act
            article.Likes.Select(l => adapter.Remove(l));
            //for (int i = 0; i < article.Likes.Count(); i++)
            //{
            //    adapter.Remove(article.Likes.ElementAt(i));
            //}
            Article deletedArticle = adapter.Remove(article);

            adapter.SaveChanges();
            IEnumerable <Article> articlees = adapter.GetEntities <Article>();

            // Assert
            Assert.IsNotNull(deletedArticle);
            Assert.AreEqual(0, articlees.Count());
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
0
        public void Test_dataAdapter_update_user_and_otp()
        {
            // Arrange
            CleanTables();
            CreateOtp(CreateUser());
            IDataAccessAdapter adapter       = container.Resolve <IDataAccessAdapter>();
            DateTime           testDate      = new DateTime(2016, 6, 5, 12, 51, 12);
            string             updatedUserId = "_updated";

            // Act
            List <User> userList   = adapter.GetEntities <User>().ToList();
            User        user       = userList.First();
            string      old_userId = user.UserId;

            if (user != null)
            {
                user.UserId += updatedUserId;
            }
            if (user.Otp != null)
            {
                user.Otp.StartDate = testDate;
            }
            adapter.SaveChanges();
            User updatedUser = adapter.GetEntities <User>().SingleOrDefault(u => u.Id == user.Id);

            // Assert
            Assert.IsNotNull(user);
            Assert.IsNotNull(user.Otp);
            Assert.IsNotNull(updatedUser);
            Assert.IsNotNull(updatedUser.Otp);
            Assert.IsTrue(updatedUser.UserId == old_userId + updatedUserId);
            Assert.IsTrue(updatedUser.Otp.StartDate.Equals(testDate));
        }
Пример #5
0
        public void Test_dataAdapter_create_user()
        {
            // Arrange
            CleanTables();
            IDataAccessAdapter adapter = container.Resolve <IDataAccessAdapter>();
            User user = new User {
                UserId = "testUser"
            };

            // Act
            adapter.Add <User>(user);
            adapter.SaveChanges();
            List <User> userList = adapter.GetEntities <User>().ToList();

            // Assert
            Assert.IsTrue(userList.Count == 1);
        }
Пример #6
0
        public void Test_dataAdapter_remove_like()
        {
            // Arrange
            utils.CleanTables();
            Tuple <string, string> userIds = utils.CreateUsers();
            int articleId = utils.CreateSingleArticle(userIds.Item2);
            int likeId    = utils.AddLike(userIds.Item1, articleId);
            IDataAccessAdapter adapter = container.Resolve <IDataAccessAdapter>();
            Article            article = adapter.GetEntities <Article>().SingleOrDefault(n => n.Id == articleId);
            Like like = article.Likes.Single(l => l.Id == likeId);

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

            // Assert
            Assert.IsNotNull(modifiedArticle);
            Assert.IsTrue(modifiedArticle.Likes.Count() == 0);
        }
Пример #7
0
        public void Test_dataAdapter_delete_user_and_otp()
        {
            // Arrange
            CleanTables();
            CreateOtp(CreateUser());
            IDataAccessAdapter adapter = container.Resolve <IDataAccessAdapter>();

            // Act
            List <User> userList = adapter.GetEntities <User>().ToList();
            User        user     = userList.First();

            adapter.Remove(user.Otp);
            adapter.Remove(user);
            adapter.SaveChanges();
            List <User> users = adapter.GetEntities <User>().ToList();
            List <Otp>  otps  = adapter.GetEntities <Otp>().ToList();

            // Assert
            Assert.IsTrue(users.Count() == 0);
            Assert.IsTrue(otps.Count() == 0);
        }
Пример #8
0
        public void Test_dataAdapter_create_user_and_otp()
        {
            // Arrange
            CleanTables();
            IDataAccessAdapter adapter = container.Resolve <IDataAccessAdapter>();
            User user = new User {
                UserId = "testUser"
            };
            Otp otp = new Otp {
                User = user, Password = "******", StartDate = DateTime.Now
            };

            // Act
            adapter.Add <User>(user);
            adapter.Add <Otp>(otp);
            adapter.SaveChanges();
            List <User> userList  = adapter.GetEntities <User>().ToList();
            User        addedUser = userList.SingleOrDefault(u => u.Id == user.Id);

            // Assert
            Assert.IsNotNull(addedUser);
            Assert.IsNotNull(addedUser.Otp);
        }
Пример #9
0
        public void Test_dataAdapter_update_article()
        {
            // 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);
            string             new_title_piece = "modified";

            // Act
            article.Title      += new_title_piece;
            article.Body       += new_title_piece;
            article.UpdatedDate = DateTime.Now;
            adapter.SaveChanges();
            Article modifiedArticle = adapter.GetEntities <Article>().SingleOrDefault(n => n.Id == articleId);

            // Assert
            Assert.IsNotNull(modifiedArticle);
            Assert.AreEqual(article.Title, modifiedArticle.Title);
            Assert.AreEqual(article.Body, modifiedArticle.Body);
            Assert.AreEqual(article.UpdatedDate, modifiedArticle.UpdatedDate);
            Assert.IsTrue(modifiedArticle.Likes.Count() == 0);
        }
Пример #10
0
 public virtual int SaveChanges()
 {
     return(_dataAccessAdapter.SaveChanges());
 }