public void getJSON_NonDRPage() { RequestAttribute attrs = new RequestAttribute { URI = "https://api.dealerrater.com/", URL = "https://www.google.com/", API = false, AccessToken = "ACCESSTOKENHERE", DealerID = "23685", PaginationOptions = new PaginationOptions { Pages = 1, ResultsPerPage = 10, Offset = 0 } }; WebScraper scraper = new WebScraper(attrs); string returnedJSON = scraper.getJSON(); ReviewCollection collection = JsonConvert.DeserializeObject <ReviewCollection>(returnedJSON); Assert.AreEqual(0, collection.reviews.Count); }
public ReviewCollection FetchAll() { ReviewCollection coll = new ReviewCollection(); Query qry = new Query(Review.Schema); coll.LoadAndCloseReader(qry.ExecuteReader()); return coll; }
public void getJSON_StressTest() { RequestAttribute attrs = new RequestAttribute { URI = "https://api.dealerrater.com/", URL = "https://www.dealerrater.com/dealer/McKaig-Chevrolet-Buick-A-Dealer-For-The-People-dealer-reviews-23685", API = false, AccessToken = "ACCESSTOKENHERE", DealerID = "23685", PaginationOptions = new PaginationOptions { Pages = 50, ResultsPerPage = 10, Offset = 0 } }; WebScraper scraper = new WebScraper(attrs); string returnedJSON = scraper.getJSON(); ReviewCollection collection = JsonConvert.DeserializeObject <ReviewCollection>(returnedJSON); Assert.AreEqual(attrs.PaginationOptions.Pages * attrs.PaginationOptions.ResultsPerPage, collection.reviews.Count); }
internal static MovieReviewDto GetReviewsByUser(string userId) { var response = new MovieReviewDto(); var reviewCollection = ReviewCollection.Where(x => string.Equals(x.AuthorId, userId)).OrderBy(x => x.CreatedOn); return(response); }
public void runRules_TwoReviewsOneRule() { List <AnalyzerRule> rules = new List <AnalyzerRule>() { new AnalyzerRule() { Key = "comments", Rules = new List <KeyWeight>() { new KeyWeight() { Keyword = "positiveOne", Weight = 1 }, new KeyWeight() { Keyword = "negativeOne", Weight = -1 }, new KeyWeight() { Keyword = "positiveTwo", Weight = 2 } } } }; JsonAnalyzer <Review> analyzer = new JsonAnalyzer <Review>(rules); ReviewCollection mockCollection = new ReviewCollection() { dealerId = "12345", ratingURl = "test/ratings", name = "testDealer", reviewCount = 1, reviews = new List <Review>() { new Review() { id = "001", dateWritten = "01/19/2021", comments = "positiveOne positiveOne positiveOne positiveOne positiveTwo " + "positiveTwo negativeOne negativeOne negativeOne negativeOne negativeOne" }, new Review() { id = "002", dateWritten = "01/19/2021", comments = "positiveOne positiveOne positiveOne positiveOne positiveTwo " + "positiveTwo negativeOne negativeOne negativeOne negativeOne negativeOne" } } }; analyzer.runRules(JsonConvert.SerializeObject(mockCollection.reviews)); KeyValuePair <Review, int> review = analyzer.getTop(2)[0]; Assert.AreEqual(3, review.Value); review = analyzer.getTop(2)[1]; Assert.AreEqual(3, review.Value); }
internal static MovieReviewDto GetReviews(string movieId) { var response = new MovieReviewDto(); var reviewCollection = ReviewCollection.Where(x => string.Equals(x.MovieId, movieId)); var userCollection = UserCollection.Where(x => reviewCollection.Select(c => c.AuthorId).Contains(x.Id)); var movie = new MovieDto(movieId, string.Empty); var reviews = reviewCollection.Select(x => new ReviewDto { Description = x.ReviewDescription, DownvotedBy = x.DownVotedBy, UpvotedBy = x.UpVotedBy, Rating = x.Rating, Id = x.Id, Title = x.ReviewTitle, Author = userCollection.Where(c => string.Equals(x.AuthorId, c.Id)).Select(c => new UserDto { DisplayName = c.DisplayName, Id = c.Id, UserName = c.UserName }).Single(), Movie = movie }); response = response with { Reviews = reviews }; return(response); }
/// <summary> /// Fetch by product id. /// </summary> /// <param name="productId">The product id.</param> /// <returns></returns> public ReviewCollection FetchByProductId(int productId) { ReviewCollection reviewCollection = new ReviewCollection(). Where(Review.Columns.ProductId, Comparison.Equals, productId). Load(); return reviewCollection; }
/// <summary Get Collection> /// Get collection of emails. If no records to return, LoyaltyAccountCollection will be null. /// </summary> /// <returns></returns> public static ReviewCollection GetCollection() { ReviewCollection tempList = null; using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString)) { using (SqlCommand myCommand = new SqlCommand("usp_GetReview", myConnection)) { myCommand.CommandType = CommandType.StoredProcedure; myCommand.Parameters.AddWithValue("@QueryId", SelectTypeEnum.GetCollection); myConnection.Open(); using (SqlDataReader myReader = myCommand.ExecuteReader()) { if (myReader.HasRows) { tempList = new ReviewCollection(); while (myReader.Read()) { tempList.Add(FillDataRecord(myReader)); } } myReader.Close(); } } } return tempList; }
public async Task GetMovieFailureTest(string movieId, Exception exception) { var mockMovieRepository = new Mock <IMovieRepository>(); mockMovieRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <MovieEntity, bool> > >())) .Returns(Task.FromResult(EntityCollection.Where(x => x.Id == movieId))); var mockReviewRepository = new Mock <IReviewRepository>(); mockReviewRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <ReviewEntity, bool> > >())) .Returns(Task.FromResult(ReviewCollection.Where(x => x.MovieId == movieId))); var mockUserRepository = new Mock <IUserProfileRepository>(); mockUserRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <UserProfileEntity, bool> > >())) .Returns((Expression <Func <UserProfileEntity, bool> > x) => Task.FromResult(UserCollection.AsQueryable <UserProfileEntity>().Where(x).AsEnumerable())); var unitOfWork = new Mock <IUnitOfWork>(); unitOfWork.SetupGet(x => x.MovieRepository).Returns(mockMovieRepository.Object); unitOfWork.SetupGet(x => x.UserProfileRepository).Returns(mockUserRepository.Object); unitOfWork.SetupGet(x => x.ReviewRepository).Returns(mockReviewRepository.Object); // Act var movieService = new MovieService(unitOfWork.Object); await Assert.ThrowsAsync(exception.GetType(), () => movieService.GetOne(movieId)); }
public async Task GetAllReviewsFailureTest(string movieId) { // Arrange var mockReviewRepository = new Mock <IReviewRepository>(); mockReviewRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <ReviewEntity, bool> > >())) .Returns(Task.FromResult(ReviewCollection.Where(x => string.Equals(x.MovieId, movieId, StringComparison.OrdinalIgnoreCase)))); var mockMovieRepository = new Mock <IMovieRepository>(); mockMovieRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <MovieEntity, bool> > >())) .Returns(Task.FromResult(Enumerable.Empty <MovieEntity>())); var mockUserRepository = new Mock <IUserProfileRepository>(); mockUserRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <UserProfileEntity, bool> > >())) .Returns((Expression <Func <UserProfileEntity, bool> > x) => Task.FromResult(UserCollection.AsQueryable <UserProfileEntity>().Where(x).AsEnumerable())); var unitOfWork = new Mock <IUnitOfWork>(); unitOfWork.SetupGet(x => x.ReviewRepository).Returns(mockReviewRepository.Object); unitOfWork.SetupGet(x => x.UserProfileRepository).Returns(mockUserRepository.Object); unitOfWork.SetupGet(x => x.MovieRepository).Returns(mockMovieRepository.Object); // Act var reviewService = new ReviewService(unitOfWork.Object); var response = await Assert.ThrowsAsync <ArgumentException>(() => reviewService.GetAllReviewsAsync(movieId)); }
public void outputWordCount_OneReviewOneRule() { List <AnalyzerRule> rules = new List <AnalyzerRule>() { new AnalyzerRule() { Key = "comments", Rules = new List <KeyWeight>() { new KeyWeight() { Keyword = "positiveOne", Weight = 1 }, new KeyWeight() { Keyword = "negativeOne", Weight = -1 }, new KeyWeight() { Keyword = "positiveTwo", Weight = 2 } } } }; JsonAnalyzer <Review> analyzer = new JsonAnalyzer <Review>(rules); StringWriter debugLog = new StringWriter(); Console.SetOut(debugLog); Console.SetError(debugLog); ReviewCollection mockCollection = new ReviewCollection() { dealerId = "12345", ratingURl = "test/ratings", name = "testDealer", reviewCount = 1, reviews = new List <Review>() { new Review() { id = "001", dateWritten = "01/19/2021", comments = "positiveOne positiveOne positiveOne positiveOne positiveTwo " + "positiveTwo negativeOne negativeOne negativeOne negativeOne negativeOne" } } }; analyzer.outputWordCount(JsonConvert.SerializeObject(mockCollection.reviews)); string log = debugLog.ToString(); Assert.AreEqual(0, "negativeone 5\r\npositiveone 4\r\npositivetwo 2\r\n".CompareTo(log)); }
private void UpdateButtonState() { NewCollection.RaiseCanExecuteChanged(); OpenCollection.RaiseCanExecuteChanged(); SaveCollection.RaiseCanExecuteChanged(); EditCollection.RaiseCanExecuteChanged(); DeleteCollection.RaiseCanExecuteChanged(); CommitCollection.RaiseCanExecuteChanged(); ReviewCollection.RaiseCanExecuteChanged(); }
public ActionResult ReviewAccountSite(int?Code) { var respReviewActSites = new ReviewCollection(); if (Code.HasValue && Code.Value > 0) { respReviewActSites = dbUser.GetAllReviewActSiteById(Code.Value); } return(View(respReviewActSites)); }
/// <summary> /// Fetches by product id and user id. /// </summary> /// <param name="productId">The product id.</param> /// <param name="userId">The user id.</param> /// <returns></returns> public Review FetchByProductIdAndUserId(int productId, string userId) { Review review = null; ReviewCollection reviewCollection = new ReviewCollection(). Where(Review.Columns.ProductId, productId). Where(Review.Columns.CreatedBy, userId). Load(); if(reviewCollection.Count > 0) { review = reviewCollection[0]; } return review; }
private void UpdateButtonState() { NewCollection.RaiseCanExecuteChanged(); OpenCollection.RaiseCanExecuteChanged(); SaveCollection.RaiseCanExecuteChanged(); EditCollection.RaiseCanExecuteChanged(); DeleteCollection.RaiseCanExecuteChanged(); CommitCollection.RaiseCanExecuteChanged(); ReviewCollection.RaiseCanExecuteChanged(); ViewRecordCommand.RaiseCanExecuteChanged(); //IsSaveVisible = FormArgs == null ? false : FormArgs.HasNoRecords == false && FormArgs.ViewMode != FormMode.DELETEMODE; OnPropertyChanged("IsCommitVisible"); }
internal static IEnumerable <MovieEntity> GetMovies(string movieTitle) { return(MovieCollection.Where(c => c.Title.Contains(movieTitle, StringComparison.OrdinalIgnoreCase)) .Select(movie => new MovieEntity { Id = movie.Id, Director = movie.Director, PlotSummary = movie.PlotSummary, Language = movie.Language, Title = movie.Title, Genre = movie.Genre, ReleaseDate = movie.ReleaseDate, CastAndCrew = movie.CastAndCrew, Rating = ReviewCollection.Where(review => review.MovieId == movie.Id).Any()?ReviewCollection.Where(review => review.MovieId == movie.Id).Average(review => review.Rating):0, TotalReviews = ReviewCollection.Where(review => review.MovieId == movie.Id).Count(), })); }
public async Task GetAllReviewsSuccessTest(string movieId, MovieReviewDto expectedResult) { // Arrange var mockReviewRepository = new Mock <IReviewRepository>(); mockReviewRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <ReviewEntity, bool> > >())) .Returns(Task.FromResult(ReviewCollection.Where(x => string.Equals(x.MovieId, movieId, StringComparison.OrdinalIgnoreCase)))); var mockMovieRepository = new Mock <IMovieRepository>(); mockMovieRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <MovieEntity, bool> > >())) .Returns(Task.FromResult(MovieCollection.Where(x => string.Equals(x.Id, movieId, StringComparison.OrdinalIgnoreCase)))); var mockUserRepository = new Mock <IUserProfileRepository>(); mockUserRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <UserProfileEntity, bool> > >())) .Returns((Expression <Func <UserProfileEntity, bool> > x) => Task.FromResult(UserCollection.AsQueryable <UserProfileEntity>().Where(x).AsEnumerable())); var unitOfWork = new Mock <IUnitOfWork>(); unitOfWork.SetupGet(x => x.ReviewRepository).Returns(mockReviewRepository.Object); unitOfWork.SetupGet(x => x.MovieRepository).Returns(mockMovieRepository.Object); unitOfWork.SetupGet(x => x.UserProfileRepository).Returns(mockUserRepository.Object); // Act var reviewService = new ReviewService(unitOfWork.Object); var response = await reviewService.GetAllReviewsAsync(movieId); // Assert Assert.Equal(expectedResult.Reviews.Count(), response.Reviews.Count()); foreach (var(expected, actual) in expectedResult.Reviews.OrderBy(x => x.Id).Zip(response.Reviews.OrderBy(x => x.Id))) { Assert.Equal(expected.Title, actual.Title); Assert.Equal(expected.Description, actual.Description); Assert.Equal(expected.Id, actual.Id); Assert.Equal(expected.Rating, actual.Rating); Assert.Equal(expected.UpvotedBy.OrderBy(x => x), actual.UpvotedBy.OrderBy(x => x)); Assert.Equal(expected.DownvotedBy.OrderBy(x => x), actual.DownvotedBy.OrderBy(x => x)); Assert.Equal(expected.Movie.Id, actual.Movie.Id); Assert.Equal(expected.Movie.Title, actual.Movie.Title); } }
/// <summary> /// Loads the reviews. /// </summary> private void LoadReviews() { if (SiteSettings.DisplayRatings) { review.Product = _product; ReviewCollection reviewCollection = Store.Caching.ProductCache.GetReviewCollectionByProductID(productId); if (reviewCollection.Count > 0) { reviewCollection.Sort(Review.Columns.CreatedOn, false); rptrReviews.DataSource = reviewCollection; rptrReviews.DataBind(); } else { lblNoReviews.Visible = true; } } }
public ReviewCollection GetAllReviewActSiteById(int AccountId) { try { db.Configuration.ProxyCreationEnabled = false; ReviewCollection reviewsite = new ReviewCollection(); reviewsite.Reviewsites = new List <SMAM_ReviewSites_ST>(); reviewsite.Reviewsites = db.SMAM_ReviewSites_ST.ToList(); reviewsite.ReviewActsites = db.SMIM_ReviewAccountSite_ST.Where(x => x.AccountID == AccountId).Select(x => new ReviewAccountSite { AccountID = x.AccountID, AccountSiteID = x.AccountSiteID, IsActive = x.IsActive, ReviewSiteID = x.ReviewSiteID, ReviewURL = x.ReviewURL }).ToList(); return(reviewsite); } catch (Exception ex) { throw ex; } }
internal static MovieEntity GetMovie(string movieId) { var reviews = ReviewCollection.Where(review => review.MovieId == movieId); var movieReview = MovieCollection.Where(c => c.Id == movieId) .Select(movie => new MovieEntity { Id = movie.Id, Director = movie.Director, PlotSummary = movie.PlotSummary, Language = movie.Language, Title = movie.Title, ReleaseDate = movie.ReleaseDate, CastAndCrew = movie.CastAndCrew, TotalReviews = reviews.Count(), Rating = reviews.Any() ? reviews.Average(x => x.Rating):0 }).Single(); return(movieReview); }
public TextAnalyticsReportContext(IEnumerable <Review> reviews) { ReviewScoreGroups = new List <ReviewStarGrouping> { new ReviewStarGrouping(1), new ReviewStarGrouping(2), new ReviewStarGrouping(3), new ReviewStarGrouping(4), new ReviewStarGrouping(5) }; ReviewCollection = reviews.ToList(); foreach (var review in reviews) { ReviewScoreGroups.FirstOrDefault(x => x.StarRating == review.StarRating).Reviews.Add(review.FormatMessage()); KeyPhraseCounts.AppendKeyPhrases(review.KeyPhrases); } MinimumScore = ReviewCollection.Min(x => x.StarRating); MaximumScore = ReviewCollection.Max(x => x.StarRating); AverageScore = ReviewCollection.Average(x => x.StarRating); }
public async Task GetMovieSuccessTest(string movieId, MovieEntity expectedResult) { // Arrange var mockMovieRepository = new Mock <IMovieRepository>(); mockMovieRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <MovieEntity, bool> > >())) .Returns(Task.FromResult(EntityCollection.Where(x => x.Id == movieId))); var mockReviewRepository = new Mock <IReviewRepository>(); mockReviewRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <ReviewEntity, bool> > >())) .Returns(Task.FromResult(ReviewCollection.Where(x => x.MovieId == movieId))); var mockUserRepository = new Mock <IUserProfileRepository>(); mockUserRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <UserProfileEntity, bool> > >())) .Returns((Expression <Func <UserProfileEntity, bool> > x) => Task.FromResult(UserCollection.AsQueryable <UserProfileEntity>().Where(x).AsEnumerable())); var unitOfWork = new Mock <IUnitOfWork>(); unitOfWork.SetupGet(x => x.MovieRepository).Returns(mockMovieRepository.Object); unitOfWork.SetupGet(x => x.UserProfileRepository).Returns(mockUserRepository.Object); unitOfWork.SetupGet(x => x.ReviewRepository).Returns(mockReviewRepository.Object); // Act var movieService = new MovieService(unitOfWork.Object); var result = await movieService.GetOne(movieId); // Assert Assert.Equal(expectedResult.Id, result.Id); Assert.Equal(expectedResult.Title, result.Title); Assert.Equal(expectedResult.PlotSummary, result.PlotSummary); Assert.Equal(expectedResult.Director, result.Director); Assert.Equal(expectedResult.CastAndCrew, result.CastAndCrew); Assert.Equal(expectedResult.ReleaseDate, result.ReleaseDate); Assert.Equal(expectedResult.Language, result.Language); Assert.Equal(expectedResult.TotalReviews, result.TotalReviews); Assert.Equal(expectedResult.Rating, result.Rating); }
public async Task SearchMovieSuccessTest(string movieTitle, int maxCount, IEnumerable <MovieEntity> expected) { var mockMovieRepository = new Mock <IMovieRepository>(); mockMovieRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <MovieEntity, bool> > >())) .Returns(Task.FromResult(EntityCollection.Where(x => (x.Title.ToLower().Contains(movieTitle.ToLower()) || x.Title.ToLower().StartsWith(movieTitle.ToLower()))))); var mockReviewRepository = new Mock <IReviewRepository>(); mockReviewRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <ReviewEntity, bool> > >())) .Returns((Expression <Func <ReviewEntity, bool> > a) => Task.FromResult(ReviewCollection.Where(a.Compile()))); var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork.SetupGet(x => x.MovieRepository).Returns(mockMovieRepository.Object); mockUnitOfWork.SetupGet(x => x.ReviewRepository).Returns(mockReviewRepository.Object); var movieService = new MovieService(mockUnitOfWork.Object); var result = await movieService.SearchMovie(movieTitle, maxCount); Assert.Equal(expected.Count(), result.Count()); foreach (var movie in result) { var expectedMovie = expected.Single(c => c.Id.Equals(movie.Id)); Assert.Equal(expectedMovie.Title, movie.Title); Assert.Equal(expectedMovie.PlotSummary, movie.PlotSummary); Assert.Equal(expectedMovie.Language, movie.Language); Assert.Equal(expectedMovie.Director, movie.Director); Assert.Equal(expectedMovie.Genre, movie.Genre); Assert.Equal(expectedMovie.ReleaseDate, movie.ReleaseDate); Assert.Equal(expectedMovie.Rating, movie.Rating); Assert.Equal(expectedMovie.TotalReviews, movie.TotalReviews); Assert.True(expectedMovie.CastAndCrew.OrderBy(x => x).SequenceEqual(movie.CastAndCrew.OrderBy(x => x))); } }
public void getTop_ReturnSubset() { List <AnalyzerRule> rules = new List <AnalyzerRule>() { new AnalyzerRule() { Key = "comments", Rules = new List <KeyWeight>() { new KeyWeight() { Keyword = "amazing", Weight = 2 }, new KeyWeight() { Keyword = "helpful", Weight = 1 }, new KeyWeight() { Keyword = "bad", Weight = -1 } } } }; JsonAnalyzer <Review> analyzer = new JsonAnalyzer <Review>(rules); ReviewCollection mockCollection = new ReviewCollection() { dealerId = "12345", ratingURl = "test/ratings", name = "testDealer", reviewCount = 1, reviews = new List <Review>() { new Review() { id = "001", dateWritten = "01/19/2021", comments = "Helpful and amazing" }, new Review() { id = "002", dateWritten = "01/19/2021", comments = "Amazing and a little bad" }, new Review() { id = "003", dateWritten = "01/19/2021", comments = "Helpful and a little bad" }, new Review() { id = "003", dateWritten = "01/19/2021", comments = "Just bad" } } }; analyzer.runRules(JsonConvert.SerializeObject(mockCollection.reviews)); int numToReturn = 2; List <KeyValuePair <Review, int> > returned = analyzer.getTop(numToReturn); Assert.AreEqual(numToReturn, returned.Count); }
public ReviewCollection FetchByQuery(Query qry) { ReviewCollection coll = new ReviewCollection(); coll.LoadAndCloseReader(qry.ExecuteReader()); return coll; }
public ReviewCollection FetchByID(object ReviewId) { ReviewCollection coll = new ReviewCollection().Where("ReviewId", ReviewId).Load(); return coll; }