Esempio n. 1
0
 public void ShareFeed(Reviews reviews)
 {
     if (FB.IsLoggedIn)
     {
         FeedLink =
             "http://demofacilities.tk";
         FeedLinkName =
             "Facilities Reviews";
         FeedLinkCaption     = reviews.Comment;
         FeedLinkDescription = "New Facility Review Has Been Post ";
         PostFbFeed();
     }
 }
Esempio n. 2
0
        public ActionResult Create([Bind(Include = "Id,BookId,UserId,Title,Text,Rating,Created,IsDeleted")] Reviews reviews)
        {
            if (ModelState.IsValid)
            {
                db.Reviews.Add(reviews);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserId = new SelectList(db.AspNetUsers, "Id", "Email", reviews.UserId);
            ViewBag.BookId = new SelectList(db.Books, "Id", "UserId", reviews.BookId);
            return(View(reviews));
        }
Esempio n. 3
0
 public bool AddReviews(AddReviewRequest request)
 {
     if (request != null)
     {
         Reviews review = new Reviews();
         review.HonestReviews = request.Reviews;
         review.MoviesId      = request.MoviesId;
         _db.ReviewsTable.Add(review);
         _db.SaveChanges();
         return(true);
     }
     return(false);
 }
        public async Task <ActionResult <Reviews> > PostReviews(Reviews reviews)
        {
            var u = await _context.Users.FindAsync(reviews.users.id);

            var g = await _context.Genres.FindAsync(reviews.genre.id);

            reviews.users = u;
            reviews.genre = g;
            _context.Reviews.Add(reviews);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetReviews", new { id = reviews.id }, reviews));
        }
Esempio n. 5
0
 /*try to get reviews if it not exist, return first one*/
 public Reviews GetReviews(int id)
 {
     reviews = createReviews();
     try
     {
         Reviews toReturn = reviews.First(x => x.ReviewsId == id);
         return(toReturn);
     }
     catch (Exception e)
     {
         return(reviews.FirstOrDefault());
     }
 }
Esempio n. 6
0
        public async Task <ActionResult <BookViewModel> > GetBook(string authorFullName, string bookTitle)
        {
            var book = Books.GetBook(authorFullName, bookTitle);

            if (book == null)
            {
                return(NotFound());
            }
            var result = Mapper.Map <BookViewModel>(book);

            result.AvgRating = Reviews.GetRatingForBook(book);
            return((ActionResult <BookViewModel>)result);
        }
        public IActionResult UpdateReviews(int id)
        {
            Reviews rev = repo.GetReview(id);

            repo.UpdateReviews(rev);

            if (rev == null)
            {
                return(View("ReviewNotFound"));
            }

            return(View(rev));
        }
        public ActionResult Create(int Cus_id, int Pro_id, string Content, int star)
        {
            Reviews review = new Reviews();

            review.Review_ProductId  = Pro_id;
            review.Review_CustomerId = Cus_id;
            review.Review_Content    = Content;
            review.Review_Rate       = star;
            review.Review_DateTime   = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
            db.Reviews.Add(review);
            db.SaveChanges();
            return(Redirect("/Products/Details/" + Pro_id));
        }
        public async Task <ActionResult> Edit([Bind(Include = "Review_Id,Review_CustomerId,Review_ProductId,Review_DateTime,Review_Content,Review_Rate")] Reviews reviews)
        {
            if (ModelState.IsValid)
            {
                db.Entry(reviews).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.Review_CustomerId = new SelectList(db.Customers, "Cus_Id", "Cus_Name", reviews.Review_CustomerId);
            ViewBag.Review_ProductId  = new SelectList(db.Product, "Pro_Id", "Pro_Name", reviews.Review_ProductId);
            return(View(reviews));
        }
Esempio n. 10
0
 public IActionResult Create(Reviews review)
 {
     if (ModelState.IsValid)
     {
         _context.Add(review);
         _context.SaveChanges();
         return(RedirectToAction("Result"));
     }
     else
     {
         return(View("Index"));
     }
 }
        public ActionResult Review(Reviews re)
        {
            if (HttpContext.Session.GetString("uid") != null || HttpContext.Session.GetString("movieID") != null)
            {
                re.UserDetailId = Convert.ToInt32(HttpContext.Session.GetString("uid"));
                re.MovieId      = Convert.ToInt32(HttpContext.Session.GetString("movieID"));
            }

            context.Reviews.Add(re);
            context.SaveChanges();

            return(RedirectToAction("Details", "BookMovie", new { @id = re.MovieId }));
        }
Esempio n. 12
0
 public ActionResult Details(int? id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     Reviews reviews = db.Reviews.Find(id);
     if (reviews == null || reviews.IsDeleted)
     {
         return HttpNotFound();
     }
     return View(reviews);
 }
 public bool PostReview(Reviews review)
 {
     try
     {
         _productDBContext.Reviews.Add(review);
         _productDBContext.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Esempio n. 14
0
        public async Task <IActionResult> Create([Bind("Id,Description,Grade,PizzaId,Title")] Reviews reviews)
        {
            if (ModelState.IsValid)
            {
                reviews.Date = DateTime.Now;
                _context.Add(reviews);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["PizzaId"] = new SelectList(_context.Pizzas.OrderBy(r => r.Name), "Id", "Name", reviews.PizzaId);
            return(View(reviews));
        }
Esempio n. 15
0
 public bool AddReview(AddReviews request)
 {
     if (request != null)
     {
         Reviews newreview = new Reviews();
         newreview.reviews   = request.reviews;
         newreview.movieName = request.movieName;
         mov.MyReviews.Add(newreview);
         mov.SaveChanges();
         return(true);
     }
     return(false);
 }
Esempio n. 16
0
        public async Task <IActionResult> Create([Bind("Id,UserId,GameId,Review,Reviewdate")] Reviews reviews)
        {
            if (ModelState.IsValid)
            {
                _context.Add(reviews);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GameId"] = new SelectList(_context.Games, "Id", "Description", reviews.GameId);
            ViewData["UserId"] = new SelectList(_context.Users, "Id", "Displayname", reviews.UserId);
            return(View(reviews));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Rating,Description,Hidden,ProductId,UserAccountId")] Reviews review)
        {
            if (id != review.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(review);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReviewExists(review.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            ReviewsDTO reviews = new ReviewsDTO
            {
                Id            = review.Id,
                Description   = review.Description,
                Hidden        = review.Hidden,
                ProductId     = review.ProductId,
                Rating        = review.Rating,
                UserAccountId = review.UserAccountId
            };

            try
            {
                var response = await _reviews.PushReview(reviews);
            }
            catch (Exception e)
            {
                //_logger.LogWarning(e);
            }

            ViewData["UserAccountId"] = new SelectList(_context.UserAccounts, "Id", "Id", review.UserAccountId);
            ViewData["ProductId"]     = new SelectList(_context.Products, "Id", "Id", review.ProductId);
            return(View(review));
        }
        public ActionResult Edit([Bind(Include = "ID,ConUsername,HomeUsername,ConFirstName,HomeFirstname,ConLastName,HomeLastName,ConAddress,HomeAddress,ConCity,HomeCity,ConState,HomeState,ConZip,HomeZip,ConEmail,HomeEmail,PostedDate,Bid,CompletionDeadline,Description,Completed,Invoice,ContractorPaid,ContractorDue,Expired,Service_Number,Review,Rating")] CompletedBids completedBids)
        {
            if (completedBids.Review == null)
            {
                if (ModelState.IsValid)
                {
                    db.Entry(completedBids).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                return(View(completedBids));
            }

            if (ModelState.IsValid)
            {
                Reviews review = new Reviews();
                review.ConUsername        = completedBids.ConUsername;
                review.HomeUsername       = completedBids.HomeUsername;
                review.ConFirstName       = completedBids.ConFirstName;
                review.HomeFirstname      = completedBids.HomeFirstname;
                review.ConLastName        = completedBids.ConLastName;
                review.HomeLastName       = completedBids.HomeLastName;
                review.ConAddress         = completedBids.ConAddress;
                review.HomeAddress        = completedBids.HomeAddress;
                review.ConCity            = completedBids.ConCity;
                review.HomeCity           = completedBids.HomeCity;
                review.ConState           = completedBids.ConState;
                review.HomeState          = completedBids.HomeState;
                review.ConZip             = completedBids.ConZip;
                review.HomeZip            = completedBids.HomeZip;
                review.ConEmail           = completedBids.ConEmail;
                review.HomeEmail          = completedBids.HomeEmail;
                review.PostedDate         = completedBids.PostedDate;
                review.Bid                = completedBids.Bid;
                review.CompletionDeadline = completedBids.CompletionDeadline;
                review.Description        = completedBids.Description;
                review.Completed          = completedBids.Completed;
                review.Invoice            = completedBids.Invoice;
                review.ContractorDue      = completedBids.ContractorDue;
                review.ContractorPaid     = completedBids.ContractorPaid;
                review.Service_Number     = completedBids.Service_Number;
                review.Expired            = completedBids.Expired;
                review.Review             = completedBids.Review;
                review.Rating             = completedBids.Rating;
                db.Reviews.Add(review);
                db.Entry(completedBids).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(completedBids));
        }
Esempio n. 19
0
        public void AddReview_validReviewRatingOne_succeed()
        {
            #region Add one review
            Reviews.Add(new Review
            {
                Comment        = "Comment 1",
                CreatedBy      = 1,
                PostedDateTime = DateTime.Now.AddDays(-1),
                Rating         = 3,
                ReviewNumber   = 1,
                //ReviewRestaurant = Restaurants[0],
                ReviewUser = Users[0],
                UpdatedBy  = 1
            });
            #endregion

            //Assign
            var expectedRating         = 1;
            var expectedPostedDateTime = DateTime.Now;
            var expectedComment        = "rating comment 2";
            var expectedRestId         = 2;
            var expectedCreatedById    = 2;
            var expectedUpdatedById    = expectedCreatedById;
            var expectedReviewNumber   = 2;
            var expectedSucessStatus   = true;
            var reqData = new AddReviewRequestModel()
            {
                Rating         = expectedRating,
                DateTimePosted = expectedPostedDateTime,
                Comment        = expectedComment,
                UserId         = expectedCreatedById,
                RestaurantId   = expectedRestId
            };

            var expectedResponse = new AddReviewResponseModel()
            {
                WasSucessfull = expectedSucessStatus,
                ReviewNumber  = expectedReviewNumber
            };

            //act
            var sut = new AddReviewTransaction(Repo, Log, reqData);
            sut.Execute();
            var actualResponse = sut.Response;

            //assert
            Assert.AreEqual(expectedSucessStatus, actualResponse.WasSucessfull, "Invalid execution status");
            Assert.AreEqual(expectedResponse, actualResponse, "Invalid response");

            ValidateResponse(expectedResponse, expectedRating, expectedPostedDateTime, expectedComment, expectedCreatedById, expectedUpdatedById, expectedReviewNumber);
        }
Esempio n. 20
0
        private void Init(JObject jObj)
        {
            var test = jObj.ToString();

            Id           = _isFromGetMua ? (string)jObj["Id"] : (string)jObj["MuaId"];
            FirstName    = _isFromGetMua ? (string)jObj["FirstName"] : (string)jObj["MuaFirstName"];
            LastName     = _isFromGetMua ? (string)jObj["LastName"] : (string)jObj["MuaLastName"];
            Address      = _isFromGetMua ? (string)jObj["Address"] : (string)jObj["MuaAddress"];
            BusinessName = _isFromGetMua ? (string)jObj["BusinessName"] : null;
            var imageUri = _isFromGetMua ? jObj["ProfilePicture"] : jObj["MuaImage"];

            if (imageUri != null)
            {
                UriImageSource imgs = (UriImageSource)ImageSource.FromUri(new Uri((string)imageUri));
                imgs.CachingEnabled = false;
                ArtistImage         = imgs;
            }
            else
            {
                ArtistImage = ImageSource.FromResource("TiroApp.Images.empty_profile.jpg");
            }
            if (jObj["Pictures"] != null)
            {
                Images = ((JArray)jObj["Pictures"]).Select(jo => (string)jo).ToList();
            }
            Lat = _isFromGetMua ? (double)jObj["LocationLat"] : (double)jObj["MuaLocationLat"];
            Lon = _isFromGetMua ? (double)jObj["LocationLon"] : (double)jObj["MuaLocationLon"];
            var url = $"https://maps.googleapis.com/maps/api/staticmap?center={Lat},{Lon}&zoom=12&size={App.ScreenWidth}x300&key={Props.GOOGLE_KEY}";

            Map        = new Image();
            Map.Source = ImageSource.FromUri(new Uri(url));
            Map.Aspect = Aspect.AspectFill;
            if (_isFromGetMua)
            {
                AboutMe = (string)jObj["AboutMe"];
                if (jObj["Services"] != null)
                {
                    foreach (JObject service in (JArray)jObj["Services"])
                    {
                        Services.Add(new Service(service, true));
                    }
                }
                if (jObj["Reviews"] != null)
                {
                    foreach (JObject review in (JArray)jObj["Reviews"])
                    {
                        Reviews.Add(new Review(review));
                    }
                }
            }
        }
        public IHttpActionResult DeleteReviews(int id)
        {
            Reviews reviews = db.Reviews.Find(id);

            if (reviews == null)
            {
                return(NotFound());
            }

            db.Reviews.Remove(reviews);
            db.SaveChanges();

            return(Ok(reviews));
        }
Esempio n. 22
0
 public ActionResult Edit([Bind(Include = "Id,Rating,Comment,ProductId,AuthorId")] Reviews reviews)
 {
     if (ModelState.IsValid)
     {
         float oldRate = db.Reviews.Find(reviews.Id).Rating;
         db.Entry(reviews).State = EntityState.Modified;
         var product = db.Products.Find(reviews.ProductId);
         product.AverageRating   = (product.AverageRating * product.NumberOfReviews - oldRate + reviews.Rating) / (product.NumberOfReviews);
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", new { id = reviews.ProductId }));
     }
     return(View(reviews));
 }
Esempio n. 23
0
        public IActionResult Review(Reviews review)
        {
            if (ModelState.IsValid)
            {
                _repo.Reviews.Create(review);
                _repo.Save();

                return(RedirectToAction("Index"));
            }
            else
            {
                return(NotFound());
            }
        }
        // GET: Reviews/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Reviews reviews = await db.Reviews.FindAsync(id);

            if (reviews == null)
            {
                return(HttpNotFound());
            }
            return(View(reviews));
        }
        public async Task <ActionResult> Create([Bind(Include = "Id,Review,DataReview,Rating,UtlizadorFK,EmpresaFK")] Reviews reviews)
        {
            if (ModelState.IsValid)
            {
                db.Reviews.Add(reviews);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.EmpresaFK   = new SelectList(db.Empresas, "Id", "Nome", reviews.EmpresaFK);
            ViewBag.UtlizadorFK = new SelectList(db.Utilizadores, "Id", "Nome", reviews.UtlizadorFK);
            return(View(reviews));
        }
Esempio n. 26
0
        public ActionResult DeleteConfirmed(int id)
        {
            Reviews reviews = db.Reviews.Find(id);

            var product = db.Products.Find(reviews.ProductId);

            product.AverageRating   = (product.AverageRating * product.NumberOfReviews - reviews.Rating) / (product.NumberOfReviews - 1);
            product.NumberOfReviews = product.NumberOfReviews - 1;
            db.Entry(product).State = EntityState.Modified;

            db.Reviews.Remove(reviews);
            db.SaveChanges();
            return(RedirectToAction("Index", new { id = reviews.ProductId }));
        }
Esempio n. 27
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Reviews reviews = db.Reviews.Find(id);

            if (reviews == null)
            {
                return(HttpNotFound());
            }
            return(View(reviews));
        }
        public async Task <IActionResult> Create([Bind("Name,MovieReview,MovieID")] Reviews reviews, int?id)
        {
            if (ModelState.IsValid)
            {
                reviews.MovieID = (int)id;
                _context.Add(reviews);

                ViewData["mID"] = reviews.MovieID;
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "Movies", new { id = reviews.MovieID }));
            }
            return(View(reviews));
        }
Esempio n. 29
0
        public async Task InsertReview(string rate, string text, string roomid)
        {
            int userId = Convert.ToInt16(_userManager.GetUserId(HttpContext.User));
            var entry  = new Reviews
            {
                Rate   = Convert.ToInt16(rate),
                Text   = text,
                RoomId = Convert.ToInt16(roomid),
                UserId = userId
            };
            await _context.Reviews.AddAsync(entry);

            await _context.SaveChangesAsync();
        }
Esempio n. 30
0
 public int NewReview([FromBody] Reviews reviews)
 {
     if (reviews.Rating > 5 || reviews.Rating < 1 || reviews.ApartmentID < 1 || String.IsNullOrEmpty(reviews.Description) ||
         reviews.Description.Length > 70 || reviews.Description.Length < 3)
     {
         return(-1);
     }
     reviews.UserName = ((ClaimsIdentity)User.Identity).FindFirst("UserName").Value;
     if (String.IsNullOrEmpty(reviews.UserName))
     {
         return(-1);
     }
     return(DB.ReviewsDB.NewReview(reviews));
 }
Esempio n. 31
0
        public void RatingsForumReadByUid_FromDbCorrectInput_ReturnsValidList()
        {
            var siteList = mocks.DynamicMock<ISiteList>();
            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var site = mocks.DynamicMock<ISite>();
            var reader = mocks.DynamicMock<IDnaDataReader>();
            var readerComments = mocks.DynamicMock<IDnaDataReader>();

            var cacheManager = mocks.DynamicMock<ICacheManager>();
            string siteName = "h2g2";
            string uid = "";

            cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything());
            site.Stub(x => x.ModerationStatus).Return(ModerationStatus.SiteStatus.UnMod);
            site.Stub(x => x.IsEmergencyClosed).Return(false);
            site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false);
            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true).Repeat.Once();
            reader.Stub(x => x.GetStringNullAsEmpty("sitename")).Return(siteName);

            readerComments.Stub(x => x.HasRows).Return(true);
            readerComments.Stub(x => x.Read()).Return(true).Repeat.Once();
            readerComments.Stub(x => x.GetInt32NullAsZero("totalresults")).Return(1);

            readerCreator.Stub(x => x.CreateDnaDataReader("RatingForumreadbyuid")).Return(reader);
            readerCreator.Stub(x => x.CreateDnaDataReader("ratingsreadbyforumid")).Return(readerComments);

            site.Stub(x => x.SiteID).Return(1);
            siteList.Stub(x => x.GetSiteOptionValueString(1, "General", "ComplaintUrl")).Return("http://www.bbc.co.uk/dna/[sitename]/comments/UserComplaintPage?PostID=[postid]&s_start=1");
            siteList.Stub(x => x.GetSite(siteName)).Return(site);
            mocks.ReplayAll();

            var reviews = new Reviews(null, readerCreator, cacheManager, siteList);
            RatingForum forum = reviews.RatingForumReadByUID(uid, site);

            Assert.IsNotNull(forum);
            Assert.AreEqual(1, forum.ratingsList.TotalCount);
            Assert.AreEqual(1, forum.ratingsList.ratings.Count);
            readerCreator.AssertWasCalled(x => x.CreateDnaDataReader("RatingForumreadbyuid"));
        }
Esempio n. 32
0
 public void AddToReviews(Reviews reviews)
 {
     base.AddObject("Reviews", reviews);
 }
Esempio n. 33
0
 public static Reviews CreateReviews(int id, int rating, string reviewText)
 {
     Reviews reviews = new Reviews();
     reviews.Id = id;
     reviews.Rating = rating;
     reviews.ReviewText = reviewText;
     return reviews;
 }
Esempio n. 34
0
        public void RatingCreate_AsPreMod_ReturnCorrectError()
        {
            string siteName = "h2g2";
            int siteId = 1;
            string uid = "uid";
            string text = "test text";
            var siteList = mocks.DynamicMock<ISiteList>();
            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var site = mocks.DynamicMock<ISite>();
            var reader = mocks.DynamicMock<IDnaDataReader>();
            var cacheManager = mocks.DynamicMock<ICacheManager>();
            var callingUser = mocks.DynamicMock<ICallingUser>();
            var ratingForum = new RatingForum
                                  {
                                      Id = uid,
                                      SiteName = siteName,
                                      ModerationServiceGroup = ModerationStatus.ForumStatus.PreMod
                                  };
            var ratingInfo = new RatingInfo {text = text, rating = 0};

            callingUser.Stub(x => x.IsSecureRequest).Return(true);

            callingUser.Stub(x => x.UserID).Return(1);
            callingUser.Stub(x => x.IsUserA(UserTypes.SuperUser)).Return(false).Constraints(Is.Anything());

            cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything());

            site.Stub(x => x.SiteID).Return(siteId);
            site.Stub(x => x.IsEmergencyClosed).Return(false);
            site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false);

            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true).Repeat.Once();

            readerCreator.Stub(x => x.CreateDnaDataReader("ratingscreate")).Return(reader);
            readerCreator.Stub(x => x.CreateDnaDataReader("commentcreate")).Return(reader);

            var readerUserRating = mocks.DynamicMock<IDnaDataReader>();
            readerUserRating.Stub(x => x.HasRows).Return(false);
            readerUserRating.Stub(x => x.Read()).Return(false);
            readerCreator.Stub(x => x.CreateDnaDataReader("ratingsreadbyforumanduser")).Return(readerUserRating);

            siteList.Stub(x => x.GetSite(siteName)).Return(site);
            mocks.ReplayAll();

            var reviews = new Reviews(null, readerCreator, cacheManager, siteList);
            reviews.CallingUser = callingUser;
            RatingInfo comment = reviews.RatingCreate(ratingForum, ratingInfo);

            Assert.IsNotNull(comment);
            readerCreator.AssertWasCalled(x => x.CreateDnaDataReader("commentcreate"));
        }
Esempio n. 35
0
        public void RatingCreate_NotSecureWithOption_ReturnCorrectError()
        {
            string siteName = "h2g2";
            string uid = "uid";
            var text = "Here is my rating that is not posted securely";
            var siteList = mocks.DynamicMock<ISiteList>();
            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var site = mocks.DynamicMock<ISite>();
            var reader = mocks.DynamicMock<IDnaDataReader>();
            var cacheManager = mocks.DynamicMock<ICacheManager>();
            var callingUser = mocks.DynamicMock<ICallingUser>();
            var ratingForum = new RatingForum { Id = uid, SiteName = siteName };
            var ratingInfo = new RatingInfo { text = text, rating = 0 };

            callingUser.Stub(x => x.UserID).Return(1);
            callingUser.Stub(x => x.IsUserA(UserTypes.SuperUser)).Return(false).Constraints(Is.Anything());

            cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything());

            site.Stub(x => x.IsEmergencyClosed).Return(false);
            site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false);

            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true).Repeat.Once();

            readerCreator.Stub(x => x.CreateDnaDataReader("ratingscreate")).Return(reader);
            var readerUserRating = mocks.DynamicMock<IDnaDataReader>();
            readerUserRating.Stub(x => x.HasRows).Return(false);
            readerUserRating.Stub(x => x.Read()).Return(false);
            readerCreator.Stub(x => x.CreateDnaDataReader("ratingsreadbyforumanduser")).Return(readerUserRating);
            siteList.Stub(x => x.GetSite(siteName)).Return(site);
            siteList.Stub(x => x.GetSiteOptionValueInt(0, "CommentForum", "EnforceSecurePosting")).Return(1);
            mocks.ReplayAll();

            var reviews = new Reviews(null, readerCreator, cacheManager, siteList);
            reviews.CallingUser = callingUser;
            try
            {
                reviews.RatingCreate(ratingForum, ratingInfo);
                throw new Exception("No exception thrown");
            }
            catch (ApiException ex)
            {
                Assert.AreEqual(ErrorType.NotSecure, ex.type);
            }

            readerCreator.AssertWasNotCalled(x => x.CreateDnaDataReader("ratingscreate"));
        }
Esempio n. 36
0
        public void RatingCreate_ProcessPreMod_ReturnCorrectError()
        {
            string siteName = "h2g2";
            int siteId = 1;
            string uid = "uid";
            string text = "test comment";
            var siteList = mocks.DynamicMock<ISiteList>();
            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var site = mocks.DynamicMock<ISite>();
            var reader = mocks.DynamicMock<IDnaDataReader>();
            var cacheManager = mocks.DynamicMock<ICacheManager>();
            var callingUser = mocks.DynamicMock<ICallingUser>();
            var ratingForum = new RatingForum { Id = uid, SiteName = siteName, ModerationServiceGroup= ModerationStatus.ForumStatus.PreMod };
            var ratingInfo = new RatingInfo { text = text, rating = 0 };

            callingUser.Stub(x => x.IsSecureRequest).Return(true);

            callingUser.Stub(x => x.UserID).Return(1);
            callingUser.Stub(x => x.IsUserA(UserTypes.SuperUser)).Return(false).Constraints(Is.Anything());

            cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything());

            site.Stub(x => x.SiteID).Return(siteId);
            site.Stub(x => x.IsEmergencyClosed).Return(false);
            site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false);

            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true).Repeat.Once();

            readerCreator.Stub(x => x.CreateDnaDataReader("ratingscreate")).Return(reader);
            var readerUserRating = mocks.DynamicMock<IDnaDataReader>();
            readerUserRating.Stub(x => x.HasRows).Return(false);
            readerUserRating.Stub(x => x.Read()).Return(false);
            readerCreator.Stub(x => x.CreateDnaDataReader("ratingsreadbyforumanduser")).Return(readerUserRating);



            siteList.Stub(x => x.GetSiteOptionValueBool(siteId, "Moderation", "ProcessPreMod")).Return(true);
            siteList.Stub(x => x.GetSite(siteName)).Return(site);
            mocks.ReplayAll();

            var reviews = new Reviews(null, readerCreator, cacheManager, siteList);
            reviews.CallingUser = callingUser;
            try
            {
                reviews.RatingCreate(ratingForum, ratingInfo);
                throw new Exception("No exception thrown");
            }
            catch (ApiException ex)
            {
                Assert.AreEqual(ErrorType.InvalidProcessPreModState, ex.type);
            }

            readerCreator.AssertWasNotCalled(x => x.CreateDnaDataReader("ratingscreate"));
        }
Esempio n. 37
0
        public void RatingsForumReadByUid_CacheValid_ReturnsValidList()
        {
            DateTime lastUpdate = DateTime.Now.AddDays(1);
            string uid = "testUid";
            var validForum = new RatingForum() {Id = uid};
            var reviews = new Reviews(null, null, null, null);

            var siteList = mocks.DynamicMock<ISiteList>();
            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var site = mocks.DynamicMock<ISite>();
            var reader = mocks.DynamicMock<IDnaDataReader>();
            var readerComments = mocks.DynamicMock<IDnaDataReader>();
            var readerLastUpdate = mocks.DynamicMock<IDnaDataReader>();

            var cacheManager = mocks.DynamicMock<ICacheManager>();
            string siteName = "h2g2";

            string cacheKey = reviews.RatingForumCacheKey(uid, 0);

            cacheManager.Stub(x => x.GetData(cacheKey + "|LASTUPDATED")).Return(lastUpdate);
            cacheManager.Stub(x => x.GetData(cacheKey)).Return(validForum);
            site.Stub(x => x.ModerationStatus).Return(ModerationStatus.SiteStatus.UnMod);
            site.Stub(x => x.IsEmergencyClosed).Return(false);
            site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false);
            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true).Repeat.Once();
            reader.Stub(x => x.GetStringNullAsEmpty("sitename")).Return(siteName);

            readerComments.Stub(x => x.HasRows).Return(true);
            readerComments.Stub(x => x.Read()).Return(true).Repeat.Once();
            readerComments.Stub(x => x.GetInt32NullAsZero("totalresults")).Return(1);

            readerLastUpdate.Stub(x => x.HasRows).Return(true);
            readerLastUpdate.Stub(x => x.Read()).Return(true).Repeat.Once();
            readerLastUpdate.Stub(x => x.GetDateTime("lastupdated")).Return(lastUpdate);


            readerCreator.Stub(x => x.CreateDnaDataReader("RatingForumreadbyuid")).Return(reader);
            readerCreator.Stub(x => x.CreateDnaDataReader("ratingsreadbyforumid")).Return(readerComments);
            readerCreator.Stub(x => x.CreateDnaDataReader("CommentforumGetLastUpdate")).Return(readerLastUpdate);


            siteList.Stub(x => x.GetSite(siteName)).Return(site);
            mocks.ReplayAll();

            reviews = new Reviews(null, readerCreator, cacheManager, siteList);
            RatingForum forum = reviews.RatingForumReadByUID(uid, site);

            Assert.IsNotNull(forum);
            Assert.AreEqual(uid, forum.Id);
            readerCreator.AssertWasNotCalled(x => x.CreateDnaDataReader("RatingForumreadbyuid"));
            readerCreator.AssertWasNotCalled(x => x.CreateDnaDataReader("ratingsreadbyforumid"));
        }
Esempio n. 38
0
        public void RatingCreate_ValidInput_ReturnCorrectObject()
        {
            string siteName = "h2g2";
            string uid = "uid";
            string text = "test comment";
            var siteList = mocks.DynamicMock<ISiteList>();
            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var site = mocks.DynamicMock<ISite>();
            var reader = mocks.DynamicMock<IDnaDataReader>();
            var cacheManager = mocks.DynamicMock<ICacheManager>();
            var callingUser = mocks.DynamicMock<ICallingUser>();
            var ratingForum = new RatingForum {Id = uid, SiteName = siteName};
            var ratingInfo = new RatingInfo {text = text, rating = 0};

            callingUser.Stub(x => x.IsSecureRequest).Return(true);

            callingUser.Stub(x => x.UserID).Return(1);
            callingUser.Stub(x => x.IsUserA(UserTypes.SuperUser)).Return(false).Constraints(Is.Anything());

            cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything());

            site.Stub(x => x.IsEmergencyClosed).Return(false);
            site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false);

            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true);
            reader.Stub(x => x.GetInt32NullAsZero("postid")).Return(1);

            readerCreator.Stub(x => x.CreateDnaDataReader("ratingscreate")).Return(reader);
            readerCreator.Stub(x => x.CreateDnaDataReader("commentcreate")).Return(reader);
            var readerUserRating = mocks.DynamicMock<IDnaDataReader>();
            readerUserRating.Stub(x => x.HasRows).Return(false);
            readerUserRating.Stub(x => x.Read()).Return(false);
            readerCreator.Stub(x => x.CreateDnaDataReader("ratingsreadbyforumanduser")).Return(readerUserRating);

            site.Stub(x => x.SiteID).Return(1);
            siteList.Stub(x => x.GetSiteOptionValueString(1, "General", "ComplaintUrl")).Return("http://www.bbc.co.uk/dna/[sitename]/comments/UserComplaintPage?PostID=[postid]&s_start=1");
            siteList.Stub(x => x.GetSite(siteName)).Return(site);
            mocks.ReplayAll();

            var reviews = new Reviews(null, readerCreator, cacheManager, siteList);
            reviews.CallingUser = callingUser;
            RatingInfo comment = reviews.RatingCreate(ratingForum, ratingInfo);

            Assert.IsNotNull(comment);
            readerCreator.AssertWasCalled(x => x.CreateDnaDataReader("commentcreate"));
        }
Esempio n. 39
0
        public void RatingCreate_UserAlreadyRated_ReturnCorrectError()
        {
            string siteName = "h2g2";
            int siteId = 1;
            string uid = "uid";
            string text = "test comment";
            var siteList = mocks.DynamicMock<ISiteList>();
            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var site = mocks.DynamicMock<ISite>();
            var reader = mocks.DynamicMock<IDnaDataReader>();
            var cacheManager = mocks.DynamicMock<ICacheManager>();
            var callingUser = mocks.DynamicMock<ICallingUser>();
            var ratingForum = new RatingForum { Id = uid, SiteName = siteName };
            var ratingInfo = new RatingInfo { text = text, rating = 0 };

            callingUser.Stub(x => x.IsSecureRequest).Return(true);

            callingUser.Stub(x => x.UserID).Return(1);
            callingUser.Stub(x => x.IsUserA(UserTypes.SuperUser)).Return(false).Constraints(Is.Anything());

            cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything());

            site.Stub(x => x.SiteID).Return(siteId);
            site.Stub(x => x.IsEmergencyClosed).Return(false);
            site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false);

            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true).Repeat.Once();

            readerCreator.Stub(x => x.CreateDnaDataReader("ratingscreate")).Return(reader);
            var readerUserRating = mocks.DynamicMock<IDnaDataReader>();
            readerUserRating.Stub(x => x.HasRows).Return(true);
            readerUserRating.Stub(x => x.Read()).Return(true);
            readerCreator.Stub(x => x.CreateDnaDataReader("ratingsreadbyforumanduser")).Return(readerUserRating);

            site.Stub(x => x.SiteID).Return(1);
            siteList.Stub(x => x.GetSiteOptionValueString(1, "General", "ComplaintUrl")).Return("http://www.bbc.co.uk/dna/[sitename]/comments/UserComplaintPage?PostID=[postid]&s_start=1");
            siteList.Stub(x => x.GetSite(siteName)).Return(site);
            mocks.ReplayAll();

            var reviews = new Reviews(null, readerCreator, cacheManager, siteList);
            reviews.CallingUser = callingUser;
            try
            {
                reviews.RatingCreate(ratingForum, ratingInfo);
                throw new Exception("No exception thrown");
            }
            catch (ApiException ex)
            {
                Assert.AreEqual(ErrorType.MultipleRatingByUser, ex.type);
            }

            readerCreator.AssertWasNotCalled(x => x.CreateDnaDataReader("ratingscreate"));
        }
Esempio n. 40
0
        public void RatingForumReadByUIDAndUserList_WithUserList_ReturnsCorrectError()
        {
            var siteList = mocks.DynamicMock<ISiteList>();
            var readerCreator = mocks.DynamicMock<IDnaDataReaderCreator>();
            var site = mocks.DynamicMock<ISite>();
            var reader = mocks.DynamicMock<IDnaDataReader>();
            var readerComments = mocks.DynamicMock<IDnaDataReader>();

            var cacheManager = mocks.DynamicMock<ICacheManager>();
            string siteName = "h2g2";
            string uid = "";
            var userList = new int[0];

            cacheManager.Stub(x => x.GetData("")).Return(null).Constraints(Is.Anything());
            site.Stub(x => x.ModerationStatus).Return(ModerationStatus.SiteStatus.UnMod);
            site.Stub(x => x.IsEmergencyClosed).Return(false);
            site.Stub(x => x.IsSiteScheduledClosed(DateTime.Now)).Return(false);
            reader.Stub(x => x.HasRows).Return(true);
            reader.Stub(x => x.Read()).Return(true).Repeat.Once();
            reader.Stub(x => x.GetStringNullAsEmpty("sitename")).Return(siteName);

            readerComments.Stub(x => x.HasRows).Return(true);
            readerComments.Stub(x => x.Read()).Return(true).Repeat.Once();
            readerComments.Stub(x => x.GetInt32NullAsZero("totalresults")).Return(1);

            readerCreator.Stub(x => x.CreateDnaDataReader("RatingForumreadbyuid")).Return(reader);
            readerCreator.Stub(x => x.CreateDnaDataReader("RatingsReadByForumandUsers")).Return(readerComments);

            siteList.Stub(x => x.GetSite(siteName)).Return(site);
            mocks.ReplayAll();

            var reviews = new Reviews(null, readerCreator, cacheManager, siteList);
            try
            {
                reviews.RatingForumReadByUIDAndUserList(uid, site, userList);
                throw new Exception("No exception thrown");
            }
            catch (ApiException ex)
            {
                Assert.AreEqual(ErrorType.MissingUserList, ex.type);
            }
            readerCreator.AssertWasCalled(x => x.CreateDnaDataReader("RatingForumreadbyuid"));
            readerCreator.AssertWasNotCalled(x => x.CreateDnaDataReader("RatingsReadByForumandUsers"));
        }