Exemplo n.º 1
0
        public void ReturnUnauthorized_WhenInvalidUser_CallsDeleteRating()
        {
            var id = 1;

            var result = new Rating
            {
                Id     = id,
                UserId = 1
            };

            var ratingRepository = A.Fake <IRatingRepository>();

            A.CallTo(() => ratingRepository.RatingExists(id)).Returns(true);
            A.CallTo(() => ratingRepository.GetRating(id)).Returns(result);

            var userHelper = A.Fake <IUserHelper>();

            A.CallTo(() => userHelper.MatchingUsers(A <HttpContext> .Ignored, result.UserId)).Returns(false);

            var controller = new RatingsController(ratingRepository, null, userHelper, null);

            var response = controller.DeleteRating(id);

            Assert.AreEqual((int)HttpStatusCode.Unauthorized, ((UnauthorizedResult)response.Result).StatusCode);
        }
Exemplo n.º 2
0
        public void ReturnRating_WhenValidUser_CallsDeleteRating()
        {
            var id = 1;

            var result = new Rating
            {
                Id     = id,
                UserId = 1
            };

            var ratingRepository = A.Fake <IRatingRepository>();

            A.CallTo(() => ratingRepository.RatingExists(id)).Returns(true);
            A.CallTo(() => ratingRepository.GetRating(id)).Returns(result);

            var userHelper = A.Fake <IUserHelper>();

            A.CallTo(() => userHelper.MatchingUsers(A <HttpContext> .Ignored, result.UserId)).Returns(true);

            var controller = new RatingsController(ratingRepository, null, userHelper, null);

            var response = controller.DeleteRating(id);

            A.CallTo(() => ratingRepository.Delete(id)).MustHaveHappened();
            Assert.AreEqual(result.Id, response.Value.Id);
        }
Exemplo n.º 3
0
        public void TestMethodDelete()
        {
            var context = new TestBankDBContext();
            var item    = GetSingleItem();

            context.Ratings.Add(item);

            var controller = new RatingsController(context);
            var result     = controller.DeleteRating(1) as OkNegotiatedContentResult <Rating>;

            Assert.IsNotNull(result);
            Assert.AreEqual(item.Id, result.Content.Id);
        }
Exemplo n.º 4
0
        public void ReturnBadRequest_WhenRatingDoesNotExist_OnCallToDeleteRating()
        {
            var id = 1;

            var ratingRepository = A.Fake <IRatingRepository>();

            A.CallTo(() => ratingRepository.RatingExists(id)).Returns(false);

            var controller = new RatingsController(ratingRepository, null, null, null);

            var response = controller.DeleteRating(id);

            Assert.AreEqual((int)HttpStatusCode.BadRequest, ((BadRequestObjectResult)response.Result).StatusCode);
            Assert.AreEqual($"Rating with Id {id} does not exist.", ((BadRequestObjectResult)response.Result).Value);
        }
        public void DeleteExistingRating_ReturnNoContent()
        {
            var options = new DbContextOptionsBuilder <DataContext>()
                          .UseInMemoryDatabase(databaseName: "DeleteRatingsDataBase")
                          .Options;
            var context = new DataContext(options);
            RatingsController ratingsController = new RatingsController(context);

            context.Add(new Rating()
            {
                MovieId = 3,
                UserId  = 3,
                Score   = 3
            });
            context.SaveChanges();
            string jwt    = UserManagementMicroservice.JWT.CreateJWT(3, 1);
            var    result = ratingsController.DeleteRating(3, jwt);

            Assert.IsType <NoContentResult>(result);
        }