public void GetUserDislikedJokesIdList_Must_Return_Id_List_Of_User_Liked_Jokes()
        {
            // Arrange
            var dbContext = StaticMethods.GetDb();

            dbContext.Database.EnsureDeleted();
            var jokesService = new JokesService(dbContext, mapper);
            var testUser     = StaticMethods.GetTestUser();
            var testJokeBM   = GetTestJokeBM();

            //Act
            dbContext.Users.Add(testUser);
            dbContext.SaveChanges();
            var Joke1      = jokesService.AddJoke(testJokeBM, testUser);
            var Joke2      = jokesService.AddJoke(testJokeBM, testUser);
            var Joke3      = jokesService.AddJoke(testJokeBM, testUser);
            var ratedJoke1 = GetTestJokeRatedDownBM(Joke1.Id, testUser.UserName);
            var ratedJoke2 = GetTestJokeRatedDownBM(Joke2.Id, testUser.UserName);
            var ratedJoke3 = GetTestJokeRatedDownBM(Joke3.Id, testUser.UserName);

            jokesService.RateJoke(ratedJoke1, testUser);
            jokesService.RateJoke(ratedJoke2, testUser);
            jokesService.RateJoke(ratedJoke3, testUser);

            var result = jokesService.GetUserDislikedJokesIdList(testUser.Id);

            //Assert
            Assert.True(result.Contains(Joke1.Id));
            Assert.True(result.Contains(Joke2.Id));
            Assert.True(result.Contains(Joke3.Id));
        }
        public void GetTopJokes_Must_Return_Top_Jokes_From_Every_Category()
        {
            // Arrange
            var dbContext    = StaticMethods.GetDb();
            var jokesService = new JokesService(dbContext, mapper);
            var testUser     = StaticMethods.GetTestUser();
            var testJokeBM1  = GetTestJokeBM(JokeCategory.ChuckNorris);
            var testJokeBM2  = GetTestJokeBM(JokeCategory.Animals);
            var testJokeBM3  = GetTestJokeBM(JokeCategory.Computers);
            var testJokeBM4  = GetTestJokeBM(JokeCategory.DriversAndPilots);
            var testJokeBM5  = GetTestJokeBM(JokeCategory.Ivancho);
            var testJokeBM6  = GetTestJokeBM(JokeCategory.Students);
            var testJokeBM7  = GetTestJokeBM(JokeCategory.Different);

            //Act
            dbContext.Users.Add(testUser);
            dbContext.SaveChanges();
            jokesService.AddJoke(testJokeBM1, testUser);
            jokesService.AddJoke(testJokeBM2, testUser);
            jokesService.AddJoke(testJokeBM3, testUser);
            jokesService.AddJoke(testJokeBM4, testUser);
            jokesService.AddJoke(testJokeBM5, testUser);
            jokesService.AddJoke(testJokeBM6, testUser);
            jokesService.AddJoke(testJokeBM7, testUser);
            var topJokes = jokesService.GetTopJokes(testUser.Id);

            //Assert
            Assert.True(topJokes.Count == 7);
        }
        public void GetAllJokes_Must_Return_AllJokesViewModel()
        {
            // Arrange
            var dbContext = StaticMethods.GetDb();

            dbContext.Database.EnsureDeleted();
            var jokesService = new JokesService(dbContext, mapper);
            var testUser     = StaticMethods.GetTestUser();
            var testJokeBM   = GetTestJokeBM();

            //Act
            dbContext.Users.Add(testUser);
            dbContext.SaveChanges();
            jokesService.AddJoke(testJokeBM, testUser);
            jokesService.AddJoke(testJokeBM, testUser);
            jokesService.AddJoke(testJokeBM, testUser);
            var result = jokesService.GetAllJokes();

            //Assert
            Assert.True(result.Jokes.Count == 3);
        }
        public void GetUserDislikedJokesIdList_Must_Return_Empty_Collection_If_User_Havent_Disliked_Any_Joke()
        {
            // Arrange
            var dbContext    = StaticMethods.GetDb();
            var jokesService = new JokesService(dbContext, mapper);
            var testUser     = StaticMethods.GetTestUser();
            var testJokeBM   = GetTestJokeBM();

            //Act
            dbContext.Users.Add(testUser);
            dbContext.SaveChanges();
            var addedJoke = jokesService.AddJoke(testJokeBM, testUser);
            var result    = jokesService.GetUserDislikedJokesIdList(testUser.Id);

            //Assert
            Assert.True(result.Count == 0);
        }
        public void IsUserDislikedJoke_Must_Return_FALSE_If_User_Likes_Given_Joke()
        {
            // Arrange
            var dbContext    = StaticMethods.GetDb();
            var jokesService = new JokesService(dbContext, mapper);
            var testUser     = StaticMethods.GetTestUser();
            var testJokeBM   = GetTestJokeBM();

            //Act
            dbContext.Users.Add(testUser);
            dbContext.SaveChanges();
            var addedJoke = jokesService.AddJoke(testJokeBM, testUser);
            var result    = jokesService.IsUserDisLikedJoke(addedJoke.Id, testUser.Id);

            //Assert
            Assert.True(!result);
        }
        public void GetJoke_Must_Return_Joke_When_T_Is_JokeEditBindingModel()
        {
            // Arrange
            var dbContext    = StaticMethods.GetDb();
            var jokesService = new JokesService(dbContext, mapper);
            var testUser     = StaticMethods.GetTestUser();
            var testJokeBM   = GetTestJokeBM();

            //Act
            dbContext.Users.Add(testUser);
            dbContext.SaveChanges();
            var addedJoke = jokesService.AddJoke(testJokeBM, testUser);
            var result    = jokesService.GetJoke <JokeEditBindingModel>(addedJoke.Id);

            //Assert
            Assert.True(result.Content == addedJoke.Content);
            Assert.True(result.Category == addedJoke.Category);
            Assert.True(result.Id == addedJoke.Id);
        }
        public void RateJoke_Must_Return_NULL_If_Joke_RatedDown_Twice()
        {
            // Arrange
            var dbContext    = StaticMethods.GetDb();
            var jokesService = new JokesService(dbContext, mapper);
            var testUser     = StaticMethods.GetTestUser();
            var testJokeBM   = GetTestJokeBM();

            //Act
            dbContext.Users.Add(testUser);
            dbContext.SaveChanges();
            var addedJoke        = jokesService.AddJoke(testJokeBM, testUser);
            var testJokeRatingBM = GetTestJokeRatedDownBM(addedJoke.Id, testUser.UserName);
            var firstTime        = jokesService.RateJoke(testJokeRatingBM, testUser);
            var secondTime       = jokesService.RateJoke(testJokeRatingBM, testUser);

            //Assert
            Assert.True(secondTime == null);
        }
        public void DeleteJoke_Must_Return_Deleted_Joke()
        {
            // Arrange
            var dbContext    = StaticMethods.GetDb();
            var jokesService = new JokesService(dbContext, mapper);
            var testUser     = StaticMethods.GetTestUser();
            var testJokeBM   = GetTestJokeBM();

            //Act
            dbContext.Users.Add(testUser);
            dbContext.SaveChanges();
            var addedJoke = jokesService.AddJoke(testJokeBM, testUser);
            var result    = jokesService.DeleteJoke(addedJoke.Id);

            //Assert
            Assert.True(result.Id == addedJoke.Id);
            Assert.True(result.Content == addedJoke.Content);
            Assert.True(result.Category == addedJoke.Category);
            Assert.True(result.PublisherId == addedJoke.PublisherId);
        }
        public void AddJoke_Must_Return_Created_Joke()
        {
            // Arrange
            var dbContext    = StaticMethods.GetDb();
            var jokesService = new JokesService(dbContext, mapper);
            var testUser     = StaticMethods.GetTestUser();
            var testJokeBM   = GetTestJokeBM();

            //Act
            dbContext.Users.Add(testUser);
            dbContext.SaveChanges();
            var result = jokesService.AddJoke(testJokeBM, testUser);

            //Assert
            Assert.True(result.Content == testJokeBM.Content);
            Assert.True(result.Category == testJokeBM.Category);
            Assert.True(result.Likes == 0);
            Assert.True(result.Dislikes == 0);
            Assert.True(result.PublisherId == testUser.Id);
        }
예제 #10
0
        public void RateJoke_Must_Return_Rated_Joke_If_RatedUp()
        {
            // Arrange
            var dbContext    = StaticMethods.GetDb();
            var jokesService = new JokesService(dbContext, mapper);
            var testUser     = StaticMethods.GetTestUser();
            var testJokeBM   = GetTestJokeBM();

            //Act
            dbContext.Users.Add(testUser);
            dbContext.SaveChanges();
            var addedJoke        = jokesService.AddJoke(testJokeBM, testUser);
            var testJokeRatingBM = GetTestJokeRatedUpBM(addedJoke.Id, testUser.UserName);
            var result           = jokesService.RateJoke(testJokeRatingBM, testUser);

            //Assert
            Assert.True(result.Content == addedJoke.Content);
            Assert.True(result.Category == addedJoke.Category);
            Assert.True(result.Likes == 1);
            Assert.True(result.Dislikes == 0);
            Assert.True(result.PublisherId == testUser.Id);
        }
예제 #11
0
        public void EditJoke_Must_Return_Edited_Joke()
        {
            // Arrange
            var dbContext    = StaticMethods.GetDb();
            var jokesService = new JokesService(dbContext, mapper);
            var testUser     = StaticMethods.GetTestUser();
            var testJokeBM   = GetTestJokeBM();

            //Act
            dbContext.Users.Add(testUser);
            dbContext.SaveChanges();
            var addedJoke  = jokesService.AddJoke(testJokeBM, testUser);
            var editJokeBM = GetTestJokeEditBM(addedJoke.Id);
            var editedJoke = jokesService.EditJoke(editJokeBM);

            //Assert
            Assert.True(editedJoke.Content == addedJoke.Content);
            Assert.True(editedJoke.Category == addedJoke.Category);
            Assert.True(editedJoke.Likes == 0);
            Assert.True(editedJoke.Dislikes == 0);
            Assert.True(editedJoke.PublisherId == testUser.Id);
        }