public async Task GetCurrentRatingWorkCorrectlyWithNotCorrectlyId() { 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.GetCurrentRating("2"); Assert.Equal(result, -1); }
public JsonResult Search(string searchString) { var vms = new List <VideoGameViewModel>(); var foundGames = VideoGameService.GetVideoGameByName(searchString); foreach (var game in foundGames) { var vm = new VideoGameViewModel(game); vm.PlatformName = PlatformService.Get(game.PlatformId).Name; vm.RatingName = RatingService.Get(game.RatingId).Name; vms.Add(vm); } return(Json(vms, JsonRequestBehavior.AllowGet)); }
public ActionResult Index() { //get list of platforms from database var platforms = PlatformService.GetAll(); var ratings = RatingService.GetAll(); var ratingsSelectList = new SelectList(ratings, "Id", "Name"); var platformSelectList = new SelectList(platforms, "Id", "Name"); var vm = new NewVideoGameViewModel { RatingOptions = ratingsSelectList, PlatformOptions = platformSelectList }; return(View(vm)); }
public async Task <IEnumerable <SelectListItem> > GetRatingAsync() { // var userId = Guid.Parse(User.Identity.GetUserId()); var catService = new RatingService(); var categoryList = await catService.GetRatingAsync(); var catSelectList = categoryList.Select( e => new SelectListItem { Value = e.RatingId.ToString(), } ).ToList(); return(catSelectList); }
public async Task AddRatingQuestion_Should_NotSave() { _svc = CreateService(); var add = new RatingQuestionAnswerData() { RatingQuestionId = VALID_QUESTION_ID, LoadId = Guid.NewGuid(), LoadClaimId = Guid.NewGuid() }; await _svc.AddRatingQuestionAnswer(add); //string userId, System.Threading.CancellationToken _db.Verify(x => x.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Never); }
// GET api/<controller> public IHttpActionResult Get() { IHttpActionResult result = null; RatingService service = new RatingService(); IEnumerable <Rating> ratings = service.GetRatings(); if (ratings.Count() > 0) { result = Ok(ratings); } else { result = NotFound(); } return(result); }
public IHttpActionResult Put(RatingEdit rating) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } RatingService service = CreateRatingService(); if (!service.UpdateRating(rating)) { return(InternalServerError()); } return(Ok()); }
public static double Evaluate(int userId) { List <int> ratedItems = UserService.GetRatedItems(userId); IPrediction prediction = new WeightedPrediction(); int N = ratedItems.Count; double absoluteError = 0d; foreach (var ratedItem in ratedItems) { double predicateRate = prediction.Predict(userId, ratedItem); double realRate = RatingService.GetRate(userId, ratedItem); absoluteError += Math.Abs(predicateRate - realRate); } return(absoluteError / (double)N); }
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); }
public void GetAllRatingsForPatient_WithValidPatientIdAndRatings_ShouldReturnRatingsCollection() { var options = new DbContextOptionsBuilder <DentHubContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Give a Unique name to the DB .Options; var dbContext = new DentHubContext(options); var rating = new Rating { Id = 1, PatientId = "1", RatingByDentist = 10 }; var rating2 = new Rating { Id = 2, PatientId = "1", RatingByDentist = 9 }; var rating3 = new Rating { Id = 3, PatientId = "1", RatingByDentist = 0 }; var rating4 = new Rating { Id = 4, PatientId = "2", RatingByDentist = 10 }; dbContext.Ratings.Add(rating); dbContext.Ratings.Add(rating2); dbContext.Ratings.Add(rating3); dbContext.Ratings.Add(rating4); dbContext.SaveChanges(); var ratingRepository = new DbRepository <Rating>(dbContext); var service = new RatingService(ratingRepository); var result = service.GetAllRatingsForPatient("1"); Assert.Equal(new Rating[] { rating, rating2 }, result); }
public void Init() { _repository = new KindActionRepository(); _userRepository = new UserRepository(); _ratingRepository = new RatingRepository(); _ratingService = new RatingService(_userRepository, _ratingRepository, true); _service = new KindActionService(_repository, _userRepository, _ratingService); _imageService = new ImageService(new ImageProvider(), new UserRepository()); _appCountersService = new AppCountersService(new AppCountersRepository()); var principal = new ClaimsPrincipal(); principal.AddIdentity(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Sid, "User1Id") })); _controller = new KindActionController(_service, _imageService, _appCountersService) { User = principal }; }
public IHttpActionResult Post(Rating rating) { IHttpActionResult result = null; RatingService service = new RatingService(); Rating newRating = service.InsertRating(rating); if (newRating != null) { result = Created <Rating>(Request.RequestUri + newRating.ID.ToString(), newRating); } else { result = NotFound(); } return(result); }
// PUT api/<controller>/5 public IHttpActionResult Put(Rating rating) { IHttpActionResult result = null; RatingService service = new RatingService(); if (service.GetRating(rating.ID) != null) { service.UpdateRating(rating); result = Ok(rating); } else { result = NotFound(); } return(result); }
public async Task TestRateComplaintValid() { //Arrange MockUp(new Complaint(), null, true); var ratingServices = new RatingService(_serviceProvider); var expectedState = true; var ratingDTO = new RatingDTO(); var expectedMessage = "Rating added successfully"; //ACT var actual = await ratingServices.RateComplain("complaintId", "userId", ratingDTO); //Assert Assert.IsNotNull(actual); Assert.AreEqual(expectedState, actual.Success); Assert.AreEqual(expectedMessage, actual.Message); }
public IHttpActionResult Excel(int value1, int value2) { var ratingEnginePath = System.Web.Hosting.HostingEnvironment.MapPath("~/Files/RatingEngineBeta.xlsx"); RatingService ratingService = new RatingService(); Premium Premium = new Premium(); //Calculates premium // Premium.PremiumAmount = ratingService.calculatePremium(ratingEnginePath, value1, value2); var quotePath = System.Web.Hosting.HostingEnvironment.MapPath("~/Files/QuoteDocument.docx"); var quotePathCopy = System.Web.Hosting.HostingEnvironment.MapPath("~/Files/QuoteDocumentCopy.docx"); var quotePathPdf = System.Web.Hosting.HostingEnvironment.MapPath("~/Files/QuoteDocumentBeta.pdf"); //DocumentService documentService = new DocumentService(); //documentService.generateQuote(quotePath, quotePathCopy, quotePathPdf, Premium.PremiumAmount); return(Ok(new { PremiumAmount = Premium.PremiumAmount })); }
public LeaderboardService( DataContext context, MatchService matchService, RatingService ratingService, DecayService decayService, IMemoryCache cache ) { _context = context; _matchService = matchService; _ratingService = ratingService; _decayService = decayService; _cache = cache; var _leaderboardConfig = new LeaderboardConfig(); _leaderboardKey = _leaderboardConfig.CacheKey; _seasonStart = _leaderboardConfig.SeasonStart; }
public async Task TestRateComplaintInvalid2() { //Arrange MockUp(new Complaint(), new Ratings(), false); var ratingServices = new RatingService(_serviceProvider); var expectedState = false; var expectedMessage = "Failed to add rating"; var ratingDTO = new RatingDTO(); //ACT var actual = await ratingServices.RateComplain("complaintId", "userId", ratingDTO); //Assert Assert.IsNotNull(actual); Assert.IsNull(actual.Data); Assert.AreEqual(expectedState, actual.Success); Assert.AreEqual(expectedMessage, actual.Message); }
public void TestInit() { var repositoryMock = new Mock <IRepository <Rating> >(); repositoryMock.Setup(x => x.GetAll()).Returns(new List <Rating> { _mockRating }); repositoryMock.Setup(x => x.Delete(_mockRating)); repositoryMock.Setup(x => x.SaveOrUpdate(_mockRating)); var testManager = new PersistenceManager <Rating> { Repository = repositoryMock.Object }; _ratTestService = new RatingService { Manager = testManager }; }
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); var service = new RatingService(mockedData.Object); //Act service.GetUserRating(1, "1"); //Assert mockedRatingsRepo.Verify(x => x.All, Times.Once()); }
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); }
// GET api/<controller>/5 public IHttpActionResult Get(int id) { IHttpActionResult result = null; RatingService service = new RatingService(); Rating rating = service.GetRating(id); if (rating != null) { result = Ok(rating); } else { result = NotFound(); } return(result); }
public ActionResult Rate(RetreatRatingCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = new RatingService(Guid.Parse(User.Identity.GetUserId())); if (service.CreateRetreatRating(model)) { TempData["SaveResult"] = "Your retreat was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Retreat could not be created."); return(View(model)); }
// DELETE api/<controller>/5 public IHttpActionResult Delete(int id) { IHttpActionResult result = null; RatingService service = new RatingService(); Rating rating = service.GetRating(id); if (rating != null) { service.RemoveRating(id); result = Ok(true); } else { result = NotFound(); } return(result); }
protected void rating5_Click(object sender, EventArgs e) { if (Page.IsValid) { localMoviesWebService.MoviesWebService moviesWeb = new localMoviesWebService.MoviesWebService(); RatingService ratingService = new RatingService(); int id = moviesWeb.GetIDbyName(movieName); ratingService.InsertUserRateMovie((string)Session["Username"], id, 5, DateTime.Now, review.Text); if (moviesWeb.GetMovieByID(id).NumberOfUsers == -1) { moviesWeb.UpdateMovieRating(5, id, 2); } else { moviesWeb.UpdateMovieRating(5, id, 1); } rating.Visible = false; } }
// // GET: /Photo/Slideshow public ActionResult Slideshow(string type, int id = 1) { List <Photo> list; switch (type) { case "user": list = unitOfWork.UserRepository.GetByID(id).Photos.ToList(); break; case "tag": list = unitOfWork.PhotoRepository.Get().Where(x => x.Tags.Any(y => y.ID == id)).ToList(); break; default: list = RatingService.GetPopularPhotosList(); break; } ViewBag.FirstPhoto = list.First(); return(View(list)); }
public async Task CheckIfGetAverageRatingReturnsCorrectData() { var list = new List <TypeTravel>(); var mockRepo = new Mock <IDeletableEntityRepository <TypeTravel> >(); mockRepo.Setup(x => x.All()).Returns(list.AsQueryable()); mockRepo.Setup(x => x.AddAsync(It.IsAny <TypeTravel>())).Callback( (TypeTravel rate) => list.Add(rate)); var service = new RatingService(mockRepo.Object); await service.SetRateAsync("Gosho", "Pesho", 1); await service.SetRateAsync("Gosho", "Spas", 5); var expectedResult = 3; var averageRating = service.GetAverageRating("Gosho"); Assert.Equal(expectedResult, averageRating); }
public void TestGetNumberOfReviewsFromReviewer() { Mock <IRatingAccess> m = new Mock <IRatingAccess>(); List <BEReview> returnValue = new List <BEReview> { new BEReview { Movie = 123, Grade = 7, Reviewer = 20, Date = "06-06-2009" }, new BEReview { Movie = 120, Grade = 3, Reviewer = 50, Date = "08-06-2009" } }; m.Setup(m => m.GetAllRatings()).Returns(() => returnValue); RatingService rService = new RatingService(m.Object); //m.Setup(m => m.GetAllRatings()).Returns(() => rService.GetAllRatings()); int actualResult = rService.GetNumberOfReviewsFromReviewer(20); Console.WriteLine(actualResult); Assert.IsTrue(actualResult == 1); }
private void PopulateRating() { RatingService ratingService = new RatingService(); if ((string)Session["Username"] != null) { if (ratingService.DidRateAlready((string)Session["Username"], movieID) == false) { rating.Visible = true; } else { rating.Visible = false; RatingMsg = "You Voted Already!"; } } else { rating.Visible = false; } }
public async Task Init() { DbContextOptions <Context> options = new DbContextOptionsBuilder <Context>() .UseInMemoryDatabase("bookish") .Options; context = new Context(options); commentService = new CommentService(context, new MessageService(context)); postService = new PostService(context, commentService); ratingService = new RatingService(context); openLibraryService = new OpenLibraryService(new System.Net.Http.HttpClient()); authUser = new AuthUserModel { Id = 1, Username = "******" }; context.Users.Add(new User { Id = authUser.Id, Username = authUser.Username }); postModel = new PostModel { Title = "This is a new book", Body = "The body of the post", Posted_At = DateTime.Now, ISBN = "9780553573404", Posted_By = authUser.Username }; postModel = await postService.CreatePost(authUser, postModel, openLibraryService); commentModel = new CommentModel { Post_Id = postModel.Id, Body = "This is a comment on a post" }; commentModel = commentService.CreateComment(authUser, commentModel); }
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()); }
public void ValidRating_ShouldBeSavedToDatabase() { var mockReviewContext = new Mock<ReviewContext>(); var mockRatingSet = new Mock<DbSet<Rating>>(); mockReviewContext.Setup(context => context.Ratings).Returns(mockRatingSet.Object); var reviewService = new RatingService(mockReviewContext.Object); reviewService.SaveRating(new Rating { ArenaDefense = 5, ArenaOffense = 5, Dungeon = 5, GuildDefense = 5, GuildOffense = 5, IdentityId = 0, Identity = new Identity(), RatingId = 0, TowerOfAscension = 5 }); mockRatingSet.Verify(set => set.Add(It.IsAny<Rating>()), Times.Once); }