Ejemplo n.º 1
0
        public void IndexShould_CallFactoryMethodCreateAllInformationViewModel()
        {
            var placeServiceMock    = new Mock <IPlaceService>();
            var userServiceMock     = new Mock <IUserService>();
            var reviewsServiceMock  = new Mock <IReviewsService>();
            var questionServiceMock = new Mock <IQuestionService>();
            var authProviderMock    = new Mock <IAuthenticationProvider>();
            var factoryMock         = new Mock <IViewModelFactory>();

            var controller = new Areas.Administration.Controllers.AdministrationController(placeServiceMock.Object,
                                                                                           reviewsServiceMock.Object, authProviderMock.Object, userServiceMock.Object,
                                                                                           questionServiceMock.Object, factoryMock.Object);

            var places = new List <Place>();

            placeServiceMock.Setup(s => s.GetAll()).Returns(places.AsQueryable());
            var users = new List <User>();

            userServiceMock.Setup(s => s.GetAll()).Returns(users.AsQueryable());
            var reviews = new List <Review>();

            reviewsServiceMock.Setup(s => s.GetAll()).Returns(reviews.AsQueryable());

            var placesModel    = new List <PlaceViewModel>();
            var usersModel     = new List <UserViewModel>();
            var reviewsModel   = new List <ReviewViewModel>();
            var questionsModel = new List <QuestionViewModel>();

            controller.Index();
            factoryMock.Verify(s => s.CreateAllInformationViewModel(usersModel, reviewsModel, placesModel, questionsModel), Times.Once);
        }
Ejemplo n.º 2
0
        public void ConstructorShould_SetPassedDataCorrectly_WhenDataIsNotNull()
        {
            var placeServiceMock    = new Mock <IPlaceService>();
            var userServiceMock     = new Mock <IUserService>();
            var reviewsServiceMock  = new Mock <IReviewsService>();
            var questionServiceMock = new Mock <IQuestionService>();
            var authProviderMock    = new Mock <IAuthenticationProvider>();
            var factoryMock         = new Mock <IViewModelFactory>();

            var controller = new Areas.Administration.Controllers.AdministrationController(placeServiceMock.Object,
                                                                                           reviewsServiceMock.Object, authProviderMock.Object, userServiceMock.Object,
                                                                                           questionServiceMock.Object, factoryMock.Object);

            Assert.IsNotNull(controller);
        }
Ejemplo n.º 3
0
        public void IndexShould_CallUserServiceMethodGetAll()
        {
            var placeServiceMock    = new Mock <IPlaceService>();
            var userServiceMock     = new Mock <IUserService>();
            var reviewsServiceMock  = new Mock <IReviewsService>();
            var questionServiceMock = new Mock <IQuestionService>();
            var authProviderMock    = new Mock <IAuthenticationProvider>();
            var factoryMock         = new Mock <IViewModelFactory>();

            var controller = new Areas.Administration.Controllers.AdministrationController(placeServiceMock.Object,
                                                                                           reviewsServiceMock.Object, authProviderMock.Object, userServiceMock.Object,
                                                                                           questionServiceMock.Object, factoryMock.Object);

            controller.Index();
            userServiceMock.Verify(s => s.GetAll(), Times.Once);
        }
Ejemplo n.º 4
0
        public void DeleteReviewShould_ReturnEmptyResult()
        {
            var placeServiceMock    = new Mock <IPlaceService>();
            var userServiceMock     = new Mock <IUserService>();
            var reviewsServiceMock  = new Mock <IReviewsService>();
            var questionServiceMock = new Mock <IQuestionService>();
            var authProviderMock    = new Mock <IAuthenticationProvider>();
            var factoryMock         = new Mock <IViewModelFactory>();

            var controller = new Areas.Administration.Controllers.AdministrationController(placeServiceMock.Object,
                                                                                           reviewsServiceMock.Object, authProviderMock.Object, userServiceMock.Object,
                                                                                           questionServiceMock.Object, factoryMock.Object);

            var id = Guid.NewGuid();

            controller
            .WithCallTo(c => c.DeleteReview(id))
            .ShouldReturnEmptyResult();
        }
Ejemplo n.º 5
0
        public void DeleteReviewShould_CallReviewsServiceMethodDeleteReview()
        {
            var placeServiceMock    = new Mock <IPlaceService>();
            var userServiceMock     = new Mock <IUserService>();
            var reviewsServiceMock  = new Mock <IReviewsService>();
            var questionServiceMock = new Mock <IQuestionService>();
            var authProviderMock    = new Mock <IAuthenticationProvider>();
            var factoryMock         = new Mock <IViewModelFactory>();

            var controller = new Areas.Administration.Controllers.AdministrationController(placeServiceMock.Object,
                                                                                           reviewsServiceMock.Object, authProviderMock.Object, userServiceMock.Object,
                                                                                           questionServiceMock.Object, factoryMock.Object);

            var id = Guid.NewGuid();

            controller.DeleteReview(id);

            reviewsServiceMock.Verify(s => s.DeleteReview(id), Times.Once);
        }
Ejemplo n.º 6
0
        public void AddAdminShould_CallAuthProviderMethodAddToRole()
        {
            var placeServiceMock    = new Mock <IPlaceService>();
            var userServiceMock     = new Mock <IUserService>();
            var reviewsServiceMock  = new Mock <IReviewsService>();
            var questionServiceMock = new Mock <IQuestionService>();
            var authProviderMock    = new Mock <IAuthenticationProvider>();
            var factoryMock         = new Mock <IViewModelFactory>();

            var controller = new Areas.Administration.Controllers.AdministrationController(placeServiceMock.Object,
                                                                                           reviewsServiceMock.Object, authProviderMock.Object, userServiceMock.Object,
                                                                                           questionServiceMock.Object, factoryMock.Object);

            var id = Guid.NewGuid().ToString();

            controller.AddAdmin(id);

            authProviderMock.Verify(ap => ap.AddToRole(id, "Admin"), Times.Once);
        }
Ejemplo n.º 7
0
        public void AddAdminShould_ReturnPartialViewWithCorrectModel()
        {
            var placeServiceMock    = new Mock <IPlaceService>();
            var userServiceMock     = new Mock <IUserService>();
            var reviewsServiceMock  = new Mock <IReviewsService>();
            var questionServiceMock = new Mock <IQuestionService>();
            var authProviderMock    = new Mock <IAuthenticationProvider>();
            var factoryMock         = new Mock <IViewModelFactory>();

            var controller = new Areas.Administration.Controllers.AdministrationController(placeServiceMock.Object,
                                                                                           reviewsServiceMock.Object, authProviderMock.Object, userServiceMock.Object,
                                                                                           questionServiceMock.Object, factoryMock.Object);

            var id = Guid.NewGuid().ToString();

            controller
            .WithCallTo(c => c.AddAdmin(id))
            .ShouldRenderPartialView("_RemoveFromRole")
            .WithModel(id);
        }
Ejemplo n.º 8
0
        public void IndexShould_ReturnViewWithCorrectModel()
        {
            var placeServiceMock    = new Mock <IPlaceService>();
            var userServiceMock     = new Mock <IUserService>();
            var reviewsServiceMock  = new Mock <IReviewsService>();
            var questionServiceMock = new Mock <IQuestionService>();
            var authProviderMock    = new Mock <IAuthenticationProvider>();
            var factoryMock         = new Mock <IViewModelFactory>();

            var controller = new Areas.Administration.Controllers.AdministrationController(placeServiceMock.Object,
                                                                                           reviewsServiceMock.Object, authProviderMock.Object, userServiceMock.Object,
                                                                                           questionServiceMock.Object, factoryMock.Object);

            var places = new List <Place>();

            placeServiceMock.Setup(s => s.GetAll()).Returns(places.AsQueryable());
            var users = new List <User>();

            userServiceMock.Setup(s => s.GetAll()).Returns(users.AsQueryable());
            var reviews = new List <Review>();

            reviewsServiceMock.Setup(s => s.GetAll()).Returns(reviews.AsQueryable());

            var placesModel    = new List <PlaceViewModel>();
            var usersModel     = new List <UserViewModel>();
            var reviewsModel   = new List <ReviewViewModel>();
            var questionsModel = new List <QuestionViewModel>();
            var model          = new AllInformationViewModel()
            {
                Places  = placesModel,
                Users   = usersModel,
                Reviews = reviewsModel
            };

            factoryMock.Setup(s => s.CreateAllInformationViewModel(usersModel, reviewsModel, placesModel, questionsModel)).Returns(model);

            controller
            .WithCallTo(c => c.Index())
            .ShouldRenderDefaultView()
            .WithModel(model);
        }