Beispiel #1
0
        public void ReturnGetUserRatings_WhenUserExists_OnCallToGetCurrentUserRatings()
        {
            var userId           = 1;
            var ratingRepository = A.Fake <IRatingRepository>();
            var userHelper       = A.Fake <IUserHelper>();

            A.CallTo(() => userHelper.GetUserId(A <HttpContext> .Ignored)).Returns(userId);

            var userRepository = A.Fake <IUserRepository>();

            A.CallTo(() => userRepository.UserExists(userId)).Returns(true);

            var controller = new RatingsController(ratingRepository, userRepository, userHelper, null);
            var response   = controller.GetCurrentUserRatings();

            A.CallTo(() => ratingRepository.GetUserRatings(userId)).MustHaveHappened();
        }
Beispiel #2
0
        public void ReturnBadRequest_WhenUserDoesNotExist_OnCallToGetCurrentUserRatings()
        {
            var userId           = 1;
            var ratingRepository = A.Fake <IRatingRepository>();
            var userHelper       = A.Fake <IUserHelper>();

            A.CallTo(() => userHelper.GetUserId(A <HttpContext> .Ignored)).Returns(userId);

            var userRepository = A.Fake <IUserRepository>();

            A.CallTo(() => userRepository.UserExists(userId)).Returns(false);

            var controller = new RatingsController(ratingRepository, userRepository, userHelper, null);
            var response   = controller.GetCurrentUserRatings();

            Assert.AreEqual((int)HttpStatusCode.BadRequest, ((BadRequestObjectResult)response.Result).StatusCode);
            Assert.AreEqual($"User with Id {userId} does not exist.", ((BadRequestObjectResult)response.Result).Value);
        }