public async Task CrearReview()
        {
            var nombreBD = Guid.NewGuid().ToString();
            var contexto = ConstruirContext(nombreBD);

            CrearPeliculas(nombreBD);

            var peliculaId = contexto.Peliculas.Select(x => x.Id).First();
            var contexto2  = ConstruirContext(nombreBD);

            var mapper     = ConfigurarAutoMapper();
            var controller = new ReviewController(contexto2, mapper);

            controller.ControllerContext = ConstruirControllerContext();

            var reviewCreacionDTO = new ReviewCreacionDTO()
            {
                Puntuacion = 5
            };
            var respuesta = await controller.Post(peliculaId, reviewCreacionDTO);

            var valor = respuesta as NoContentResult;

            Assert.IsNotNull(valor);

            var contexto3 = ConstruirContext(nombreBD);
            var reviewDB  = contexto3.Reviews.First();

            Assert.AreEqual(usuarioPorDefectoId, reviewDB.UsuarioId);
        }
Esempio n. 2
0
        public async Task PostReviews_Invalid()
        {
            RatingandReviewDetails ratingandreviewsentity = new RatingandReviewDetails
            {
                Rating          = 0,
                Reviews         = "",
                TblCustomerId   = 1,
                TblRestaurantId = 1
            };

            var mockOrder = new Mock <IRestaurantBuisness>();

            mockOrder.Setup(x => x.PostRatingandReviews(ratingandreviewsentity)).Returns(true);
            var postreviews = new ReviewController(mockOrder.Object);

            postreviews.ControllerContext             = new ControllerContext();
            postreviews.ControllerContext.HttpContext = new DefaultHttpContext();
            postreviews.ControllerContext.HttpContext.Request.Headers["CustomerId"] = "1";
            postreviews.ControllerContext.HttpContext.Request.Headers["AuthToken"]  = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IjEiLCJuYmYiOjE1OTU1MjIwNDYsImV4cCI6MTU5NTUyMzg0NiwiaWF0IjoxNTk1NTIyMDQ2LCJpc3MiOiJNMTA0MzAyN0BtaW5kdHJlZS5jb20ifQ.Vz94haCPJEXw88laXihE4TFfUQPoJfH9spGD_Cnnhsc";
            mockOrder.Setup(x => x.IsValidRestaurantAsync(ratingandreviewsentity, 1, postreviews.ControllerContext.HttpContext.Request.Headers["AuthToken"])).ReturnsAsync(true);
            var data = await postreviews.Post(ratingandreviewsentity);

            var okObjectResult = data as BadRequestObjectResult;

            Assert.AreEqual(400, okObjectResult.StatusCode);
        }
        public async Task UsuarioNoPuedeCrearDosReviewsParaLaMismaPelicula()
        {
            var nombreBD = Guid.NewGuid().ToString();
            var contexto = ConstruirContext(nombreBD);

            CrearPeliculas(nombreBD);

            var peliculaId = contexto.Peliculas.Select(x => x.Id).First();
            var review1    = new Review()
            {
                PeliculaId = peliculaId,
                UsuarioId  = usuarioPorDefectoId,
                Puntuacion = 5
            };

            contexto.Add(review1);
            await contexto.SaveChangesAsync();

            var contexto2 = ConstruirContext(nombreBD);
            var mapper    = ConfigurarAutoMapper();

            var controller = new ReviewController(contexto2, mapper);

            controller.ControllerContext = ConstruirControllerContext();

            var reviewCreacionDTO = new ReviewCreacionDTO {
                Puntuacion = 5
            };
            var respuesta = await controller.Post(peliculaId, reviewCreacionDTO);

            var valor = respuesta as IStatusCodeActionResult;

            Assert.AreEqual(400, valor.StatusCode.Value);
        }
        public void CreateReviewInternalErrorFailedTest()
        {
            var mock = new Mock <IReviewManagement>(MockBehavior.Strict);

            mock.Setup(m => m.Create(It.IsAny <Review>(), reserve.Id)).Throws(new ServerBusinessLogicException());
            ReviewController reviewController = new ReviewController(mock.Object);

            var result        = reviewController.Post(reviewForRequest);
            var createdResult = result as ObjectResult;

            mock.VerifyAll();
            Assert.AreEqual(500, createdResult.StatusCode);
        }
        public void CreateReviewScoreGreaterThanFiveFailedTest()
        {
            reviewForRequest.Score = 6;

            var mock = new Mock <IReviewManagement>(MockBehavior.Strict);

            mock.Setup(m => m.Create(It.IsAny <Review>(), reserve.Id)).Throws(new DomainBusinessLogicException());
            ReviewController reviewController = new ReviewController(mock.Object);

            var result        = reviewController.Post(reviewForRequest);
            var createdResult = result as BadRequestObjectResult;

            mock.VerifyAll();
            Assert.AreEqual(400, createdResult.StatusCode);
        }
        public void CreateReviewOk()
        {
            var mock = new Mock <IReviewManagement>(MockBehavior.Strict);

            mock.Setup(m => m.Create(It.IsAny <Review>(), reserve.Id)).Returns(review);
            ReviewController reviewController = new ReviewController(mock.Object);

            var result        = reviewController.Post(reviewForRequest);
            var createdResult = result as CreatedAtRouteResult;
            var model         = createdResult.Value as ReviewModelForResponse;
            var expected      = ReviewModelForResponse.ToModel(review);

            mock.VerifyAll();
            Assert.AreEqual(expected, model);
        }
Esempio n. 7
0
        public async Task PostReviewandRatings()
        {
            RatingandReviewDetails ratingandreviewsentity = new RatingandReviewDetails
            {
                Rating        = 2,
                Reviews       = "very good",
                TblCustomerId = 1
            };
            var mockOrder = new Mock <IRestaurantBuisness>();

            mockOrder.Setup(x => x.PostRatingandReviews(ratingandreviewsentity)).Returns(true);
            var postreviews = new ReviewController(mockOrder.Object);

            postreviews.ControllerContext             = new ControllerContext();
            postreviews.ControllerContext.HttpContext = new DefaultHttpContext();
            postreviews.ControllerContext.HttpContext.Request.Headers["CustomerId"] = "1";
            postreviews.ControllerContext.HttpContext.Request.Headers["AuthToken"]  = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IjEiLCJuYmYiOjE1OTU3OTIwMjcsImV4cCI6MTU5NTc5MzgyNywiaWF0IjoxNTk1NzkyMDI3LCJpc3MiOiJNMTA0MzAyN0BtaW5kdHJlZS5jb20ifQ._uVEF3Y-4NJqmxXXh60f5dAFZb1TYoxn34LsyUuXdjw";
            var data = await postreviews.Post(ratingandreviewsentity);

            var okObjectResult = data as OkObjectResult;

            Assert.AreEqual(200, okObjectResult.StatusCode);
        }
Esempio n. 8
0
        public void TestReviewCreate()
        {
            // Arrange
            var fakeReview = FakeReviews().First();

            var mockBusinessLogic = new Mock <ISportStoreBusinessLogic>();

            mockBusinessLogic
            .Setup(bl => bl.Review.Create(fakeReview))
            .Returns(fakeReview.Id);

            var controller = new ReviewController(mockBusinessLogic.Object);

            // Act
            var result            = controller.Post(fakeReview);
            var createdReviewCode = (result as OkNegotiatedContentResult <Guid>).Content;

            // Assert
            mockBusinessLogic.VerifyAll();

            Assert.IsNotNull(createdReviewCode);
            Assert.AreEqual(fakeReview.Id, createdReviewCode);
        }
Esempio n. 9
0
        public async void Test_Controller_Post()
        {
            var resultPass = await _controller.Post(new ReviewModel());

            Assert.NotNull(resultPass);
        }
Esempio n. 10
0
        public string Put([FromBody] Trip trip)
        {
            try
            {
                var builder = Builders<Driver>.Filter;
                var filter = builder.Eq(f => f.driverName, trip.driverName)
                    & (builder.Eq(f => f.vehicleNumber, trip.vehicleNumber) | builder.Eq(f => f.contactNumber, trip.contactNumber));

                var driver = driverColl
                    .Find<Driver>(filter)
                    .FirstOrDefaultAsync().Result;

                if (driver == null)
                {
                    //throw new HttpException(500, "Driver not found");
                    return "";
                }

                var existingTrip = Get(trip.tripId);
                if (existingTrip != null)
                {
                    return trip.tripId;
                }

                // create review
                var reviewController = new ReviewController();
                var review = new Review();
                review.tripId = trip.tripId;
                review.reviewerId = trip.reviewerId;
                review.driverId = driver.driverId;
                review.status = ReviewStatus.UNRATED;

                return reviewController.Post(review);
            }
            catch (Exception ex)
            {
                throw new HttpException(500, ex.Message);
            }
        }