Пример #1
0
        public void CreateRatingTest()
        {
            Rating r = new Rating(DateTime.Now, 5, "bonjour je suis le commentaire");

            _ratingService.AddRating(_mainRestaurant, r);
            var rateid = r.ID;

            _mainRestaurant = _restaurantService.GetAllRestaurant().Find(m => m.ID == _mainRestaurant.ID);// this updates the restaurant to have the correct rating id
            Assert.IsTrue(_mainRestaurant.Rating.ID == rateid);
        }
        public void AddRating_Rating_AddsRatingToDatabase()
        {
            var song = new Song {
                Id = Guid.NewGuid(), SongId = Guid.NewGuid(), Album = new Album {
                    Id = Guid.NewGuid()
                }
            };
            var user = new User {
                Id = Guid.NewGuid(), UserId = Guid.NewGuid()
            };

            _context.Songs.Add(song);
            _context.Users.Add(user);
            _context.SaveChanges();

            var rating = new Rating
            {
                Id   = Guid.NewGuid(),
                Song = new Song {
                    SongId = song.SongId
                },
                User = new User {
                    UserId = user.UserId
                }
            };

            _ratingService.AddRating(rating);

            var ratings = _context.Ratings.ToList();

            Assert.IsTrue(ratings.Contains(rating));
        }
        public async Task <IActionResult> AddRating(int score, string comment, int bookID)
        {
            //Gets current User.
            var user = await _userManager.GetUserAsync(User);

            var userID = user.Id;

            //Sees if user filled in comment. Avoids null reference error when doing comment.Length.
            if (comment != null)
            {
                //Comment can not exceed 500.
                if (comment.Length > 500)
                {
                    //Returns user to the Rating Site to write again.
                    return(RedirectToAction("Rating", "Book", new { id = bookID }));
                }
            }

            //Creates a new Review model.
            var newReview = new RatingInputModel()
            {
                Score   = score,
                Comment = comment,
                BookID  = bookID,
                UserID  = userID,
            };

            //Adds the rating itself. The comment which is at the bottom of the page.
            _ratingService.AddRating(newReview);
            //Updates the book star rating.
            _bookService.AddRating(newReview);

            //Redirects User to Details.
            return(RedirectToAction("Details", "Book", new { id = bookID }));
        }
        public IHttpActionResult Post([FromBody] RatingModel ratingModel)
        {
            var headers = Request.Headers;

            if (!headers.Contains("token"))
            {
                return(Ok(new { errorCode = "66", message = "unauthorized" }));
            }
            if (headers.Contains("token"))
            {
                var token = headers.GetValues("token").First();
                var jwt   = new JwtToken();
                if (!jwt.VerifyTokenAndRole(token, (int)RolesEnum.FAN))
                {
                    return(Ok(new { errorCode = "66", message = "unauthorized" }));
                }
            }
            var service = new RatingService();

            try
            {
                var rating = service.AddRating(ratingModel.ArtistId, ratingModel.FanId, ratingModel.Score);
                return(Ok(new RatingModel {
                    Score = rating.Score
                }));
            }
            catch (NotFoundException ex)
            {
                return(NotFound());
            }
            catch (InvalidModelException ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Пример #5
0
        public void AddRating_Rating_CallsSongRepoGet()
        {
            var rating = new Rating
            {
                Song = new Song {
                    SongId = Guid.NewGuid()
                },
                User = new User {
                    UserId = Guid.NewGuid()
                }
            };

            _ratingService.AddRating(rating);

            _songRepository.Verify(x => x.Get(It.IsAny <Guid>()), Times.AtLeastOnce);
        }
        public async Task AddRatingUpdateWorkCorrectly()
        {
            var rating = new Rating()
            {
                TotalRating    = 4,
                UserId         = "1",
                AnnouncementId = "1",
            };
            var service = new RatingService(this.ratingRepository);
            await service.AddRating(rating.AnnouncementId, (int)rating.TotalRating, rating.UserId);

            await service.AddRating(rating.AnnouncementId, 3, rating.UserId);

            var result = service.GetCurrentRating("1");

            Assert.Equal(3, result);
        }
Пример #7
0
        public void AddShouldCallRespositoryAddMethodWithCorrectRating(int rating)
        {
            var repository    = new Mock <IGenericRepository <Rating> >();
            var unitOfWork    = new Mock <IUnitOfWork>();
            var ratingFactory = new Mock <IRatingFactory>();
            var service       = new RatingService(repository.Object, unitOfWork.Object, ratingFactory.Object);

            service.AddRating(It.IsAny <Guid>(), It.IsAny <int>(), rating);
            ratingFactory.Verify(x => x.Create(It.IsAny <Guid>(), It.IsAny <int>(), It.Is <int>(arg => arg == rating)), Times.Once);
        }
        public void TestAddRating()
        {
            var    service   = new RatingService(carpentryWebsiteContext);
            Rating itemToAdd = new Rating {
                RatingId = 105, User = "******", UserRating = "Wrox Press", Text = "Nem vagyok elégedett"
            };

            service.AddRating(itemToAdd);
            Rating result = service.GetRatingDetails(105);

            Assert.Equal(itemToAdd, result);
        }
        public async Task GetCurrentRatingWorkCorrectly()
        {
            var rating = new Rating()
            {
                TotalRating    = 4,
                UserId         = "1",
                AnnouncementId = "1",
            };
            var service = new RatingService(this.ratingRepository);
            await service.AddRating(rating.AnnouncementId, (int)rating.TotalRating, rating.UserId);

            service.GetCurrentRating(rating.AnnouncementId);
            Assert.Equal(4, this.dbContext.Ratings.FirstOrDefault().TotalRating);
        }
        public async Task CurrentUserRatingWorkCorrectlyWithNotCorrectlyId()
        {
            var rating = new Rating()
            {
                TotalRating    = 4,
                UserId         = "1",
                AnnouncementId = "1",
            };
            var service = new RatingService(this.ratingRepository);
            await service.AddRating(rating.AnnouncementId, (int)rating.TotalRating, rating.UserId);

            var result = service.CurrentUserRating("2", rating.UserId);

            Assert.Equal(0, result);
        }
        public void TestEditRatings()
        {
            string expectedText = "Nem vagyok elégedett";
            var    service      = new RatingService(carpentryWebsiteContext);
            Rating itemToAdd    = new Rating {
                RatingId = 14, User = "******", UserRating = "Wrox Press", Text = "Nem vagyok elégedett"
            };

            service.AddRating(itemToAdd);
            carpentryWebsiteContext.Entry(service.GetRatingDetails(14)).State = EntityState.Detached;

            service.UpdateRating(new Rating {
                RatingId = 14, User = "******", UserRating = "Wrox Press", Text = "Nem vagyok elégedett"
            });
            Rating result = service.GetRatingDetails(14);

            Assert.Equal(expectedText, result.Text);
        }
        public void CallRatingsRepo_AddMethod_WithTheNewRating_IfRatingDoesNotExist()
        {
            //Assert
            var ratings = new List <Rating>()
            {
                new Rating()
                {
                    BarId = 2, UserId = "2", Value = 4
                },
                new Rating()
                {
                    BarId = 1, UserId = "1", Value = 5
                },
                new Rating()
                {
                    BarId = 1, UserId = "2", Value = 2
                }
            }.AsQueryable();

            var mockedRatingsRepo = new Mock <IEntityFrameworkRepository <Rating> >();

            mockedRatingsRepo.Setup(x => x.All).Returns(ratings);
            mockedRatingsRepo.Setup(x => x.Add(It.IsAny <Rating>())).Verifiable();
            var mockedData = new Mock <IShishaTimeData>();

            mockedData.Setup(x => x.Ratings).Returns(mockedRatingsRepo.Object);
            mockedData.Setup(x => x.SaveChanges()).Verifiable();
            var service = new RatingService(mockedData.Object);
            var rating  = new Rating()
            {
                BarId = 3, UserId = "1", Value = 1
            };

            //Act
            service.AddRating(rating);

            //Assert
            mockedRatingsRepo.Verify(x => x.Add(rating), Times.Once());
        }
Пример #13
0
        public async Task <object> AddEditRating(RatingRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(JsonResults.Error(400, ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage.ToString()));
            }

            try
            {
                var checkRating = await _ratingService.CheckRating(request);

                if (!checkRating)
                {
                    var model = new Rating
                    {
                        UserId    = request.UserId,
                        ServiceId = request.ServiceId,
                        Rating1   = request.Rating1
                    };

                    await _ratingService.AddRating(model);

                    return(JsonResults.Success(model));
                }

                var rating = await _ratingService.GetRating(request.Id);

                rating.Rating1 = request.Rating1;

                await _ratingService.UpdateRating(rating);

                return(JsonResults.Success(rating));
            }
            catch (Exception ex)
            {
                return(JsonResults.Error(400, ex.Message));
            }
        }
        public void CallDataRatingsRepo_AllProperty()
        {
            //Assert
            var ratings           = new List <Rating>().AsQueryable();
            var mockedRatingsRepo = new Mock <IEntityFrameworkRepository <Rating> >();

            mockedRatingsRepo.Setup(x => x.All).Returns(ratings);
            var mockedData = new Mock <IShishaTimeData>();

            mockedData.Setup(x => x.Ratings).Returns(mockedRatingsRepo.Object);
            mockedData.Setup(x => x.SaveChanges()).Verifiable();
            var service = new RatingService(mockedData.Object);
            var rating  = new Rating()
            {
                BarId = 1, UserId = "1", Value = 5
            };

            //Act
            service.AddRating(rating);

            //Assert
            mockedRatingsRepo.Verify(x => x.All, Times.Once());
        }
        public void ChangeRatingValue_IfAlreadyExists()
        {
            //Assert
            var rating = new Rating()
            {
                BarId = 1, UserId = "1", Value = 5
            };
            var ratings = new List <Rating>()
            {
                new Rating()
                {
                    BarId = 2, UserId = "2", Value = 4
                },
                rating,
                new Rating()
                {
                    BarId = 1, UserId = "2", Value = 2
                }
            }.AsQueryable();
            var mockedRatingsRepo = new Mock <IEntityFrameworkRepository <Rating> >();

            mockedRatingsRepo.Setup(x => x.All).Returns(ratings);
            var mockedData = new Mock <IShishaTimeData>();

            mockedData.Setup(x => x.Ratings).Returns(mockedRatingsRepo.Object);
            mockedData.Setup(x => x.SaveChanges()).Verifiable();
            var service = new RatingService(mockedData.Object);

            //Act
            service.AddRating(new Rating()
            {
                BarId = 1, UserId = "1", Value = 1
            });

            //Assert
            Assert.AreEqual(1, rating.Value);
        }
Пример #16
0
        public void AddRating_ShouldAddRating_WhenPassedValidArguments()
        {
            // Arrange
            var mockedRepo = new Mock <IEfRepostory <Rating> >();
            var guid       = Guid.NewGuid();
            var rating     = 1;

            var expected = new Rating()
            {
                BookId = guid,
                UserId = guid,
                Value  = 1
            };

            var sut = new RatingService(mockedRepo.Object);

            mockedRepo.Setup(x => x.Add(It.IsAny <Rating>()));

            //Act
            sut.AddRating(guid, guid, rating);

            //Asssert
            mockedRepo.Verify(x => x.Add(It.Is <Rating>(r => r.BookId == guid && r.UserId == guid && r.Value == rating)), Times.Once);
        }
Пример #17
0
 public void RatingService_AddRating_Throws_On_Null_Rating()
 {
     AutoTester.ArgumentNull <Rating>(marker => RatingService.AddRating(marker));
 }
Пример #18
0
        public void AddRatingTest()
        {
            var success = _ratTestService.AddRating(_mockRating);

            Assert.IsTrue(success);
        }
Пример #19
0
 public int Create([FromBody] Rating rating)
 {
     return(ratingService.AddRating(rating));
 }