Ejemplo n.º 1
0
        public void GetEditShould_ReturnDefaultView_WhenCurrentUserIsManagerOfFoundPlace()
        {
            var placeServiceMock   = new Mock <IPlaceService>();
            var addressServiceMock = new Mock <IAddressService>();
            var tablesServiceMock  = new Mock <ITablesService>();
            var reviewsServiceMock = new Mock <IReviewsService>();
            var authProviderMock   = new Mock <IAuthenticationProvider>();
            var factoryMock        = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.PlacesController(authProviderMock.Object, factoryMock.Object,
                                                                  placeServiceMock.Object, addressServiceMock.Object, tablesServiceMock.Object,
                                                                  reviewsServiceMock.Object);

            InitializeMapper();
            var placeId = Guid.NewGuid();
            var userId  = Guid.NewGuid().ToString();

            authProviderMock.Setup(ap => ap.CurrentUserId).Returns(userId);
            var place = new Place()
            {
                Id        = placeId,
                ManagerId = userId
            };
            var list = new List <Place>()
            {
                place
            };

            placeServiceMock.Setup(s => s.GetPlaceById(placeId)).Returns(list.AsQueryable());

            controller
            .WithCallTo(c => c.Edit(placeId))
            .ShouldRenderDefaultView();
        }
Ejemplo n.º 2
0
        public void GetPlacesByCategoryShould_ReturnViewWithCorrectModel_WhenPassedCategoryIsNotNull(string category)
        {
            var placeServiceMock   = new Mock <IPlaceService>();
            var addressServiceMock = new Mock <IAddressService>();
            var tablesServiceMock  = new Mock <ITablesService>();
            var reviewsServiceMock = new Mock <IReviewsService>();
            var authProviderMock   = new Mock <IAuthenticationProvider>();
            var factoryMock        = new Mock <IViewModelFactory>();

            InitializeMapper();

            var controller = new Web.Controllers.PlacesController(authProviderMock.Object, factoryMock.Object,
                                                                  placeServiceMock.Object, addressServiceMock.Object, tablesServiceMock.Object,
                                                                  reviewsServiceMock.Object);
            var place = new Place()
            {
                Type = category
            };
            var list = new List <Place>()
            {
                place
            };

            placeServiceMock.Setup(s => s.GetPlacesByCategory(category)).Returns(list.AsQueryable());
            var model =
                controller
                .WithCallTo(c => c.GetPlacesByCategory(category, 10, 1))
                .ShouldRenderPartialView("_PartialList");
        }
Ejemplo n.º 3
0
        public void GetEditShould_ReturnErrorView_WhenPlaceWasNotFound()
        {
            var placeServiceMock   = new Mock <IPlaceService>();
            var addressServiceMock = new Mock <IAddressService>();
            var tablesServiceMock  = new Mock <ITablesService>();
            var reviewsServiceMock = new Mock <IReviewsService>();
            var authProviderMock   = new Mock <IAuthenticationProvider>();
            var factoryMock        = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.PlacesController(authProviderMock.Object, factoryMock.Object,
                                                                  placeServiceMock.Object, addressServiceMock.Object, tablesServiceMock.Object,
                                                                  reviewsServiceMock.Object);

            var placeId = Guid.NewGuid();
            var userId  = Guid.NewGuid().ToString();

            authProviderMock.Setup(ap => ap.CurrentUserId).Returns(userId);
            var emptyList = new List <Place>();

            placeServiceMock.Setup(s => s.GetPlaceById(placeId)).Returns(emptyList.AsQueryable());

            controller
            .WithCallTo(c => c.Edit(placeId))
            .ShouldRenderView("Error");
        }
Ejemplo n.º 4
0
        public void GetEditShould_RedirectToDetails_WhenModelIsValid()
        {
            var placeServiceMock   = new Mock <IPlaceService>();
            var addressServiceMock = new Mock <IAddressService>();
            var tablesServiceMock  = new Mock <ITablesService>();
            var reviewsServiceMock = new Mock <IReviewsService>();
            var authProviderMock   = new Mock <IAuthenticationProvider>();
            var factoryMock        = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.PlacesController(authProviderMock.Object, factoryMock.Object,
                                                                  placeServiceMock.Object, addressServiceMock.Object, tablesServiceMock.Object,
                                                                  reviewsServiceMock.Object);

            var id    = Guid.NewGuid();
            var model = new EditViewModel()
            {
                Id = id
            };
            var place = new Place()
            {
                Id = id, AddressId = Guid.NewGuid()
            };

            placeServiceMock.Setup(s => s.EditPlace(model.Id, model.Contact, model.Description, model.PhotoUrl,
                                                    model.WeekdayHours, model.WeekendHours, model.AverageBill))
            .Returns(place);

            controller
            .WithCallTo(c => c.Edit(model))
            .ShouldRedirectTo((Web.Controllers.PlacesController pc) => pc.Details(place.Id));
        }
Ejemplo n.º 5
0
        public void ListShould_ReturnDefaultView()
        {
            var placeServiceMock   = new Mock <IPlaceService>();
            var addressServiceMock = new Mock <IAddressService>();
            var tablesServiceMock  = new Mock <ITablesService>();
            var reviewsServiceMock = new Mock <IReviewsService>();
            var authProviderMock   = new Mock <IAuthenticationProvider>();
            var factoryMock        = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.PlacesController(authProviderMock.Object, factoryMock.Object,
                                                                  placeServiceMock.Object, addressServiceMock.Object, tablesServiceMock.Object,
                                                                  reviewsServiceMock.Object);

            controller.WithCallTo(c => c.List(10, 1)).ShouldRenderDefaultView();
        }
Ejemplo n.º 6
0
        public void DetailsShould_ReturnErrorView_WhenIdIsNull()
        {
            var placeServiceMock   = new Mock <IPlaceService>();
            var addressServiceMock = new Mock <IAddressService>();
            var tablesServiceMock  = new Mock <ITablesService>();
            var reviewsServiceMock = new Mock <IReviewsService>();
            var authProviderMock   = new Mock <IAuthenticationProvider>();
            var factoryMock        = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.PlacesController(authProviderMock.Object, factoryMock.Object,
                                                                  placeServiceMock.Object, addressServiceMock.Object, tablesServiceMock.Object,
                                                                  reviewsServiceMock.Object);

            controller
            .WithCallTo(c => c.Details(null))
            .ShouldRenderView("Error");
        }
Ejemplo n.º 7
0
        public void GetPlacesByCategoryShould_ReturnErrorView_WhenPassedCategoryIsNull()
        {
            var placeServiceMock   = new Mock <IPlaceService>();
            var addressServiceMock = new Mock <IAddressService>();
            var tablesServiceMock  = new Mock <ITablesService>();
            var reviewsServiceMock = new Mock <IReviewsService>();
            var authProviderMock   = new Mock <IAuthenticationProvider>();
            var factoryMock        = new Mock <IViewModelFactory>();

            InitializeMapper();

            var controller = new Web.Controllers.PlacesController(authProviderMock.Object, factoryMock.Object,
                                                                  placeServiceMock.Object, addressServiceMock.Object, tablesServiceMock.Object,
                                                                  reviewsServiceMock.Object);

            controller
            .WithCallTo(c => c.GetPlacesByCategory(null, 10, 1))
            .ShouldRenderView("Error");
        }
Ejemplo n.º 8
0
        public void DetailsShould_ReturnView_WhenPlaceWasFound()
        {
            var placeServiceMock   = new Mock <IPlaceService>();
            var addressServiceMock = new Mock <IAddressService>();
            var tablesServiceMock  = new Mock <ITablesService>();
            var reviewsServiceMock = new Mock <IReviewsService>();
            var authProviderMock   = new Mock <IAuthenticationProvider>();
            var factoryMock        = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.PlacesController(authProviderMock.Object, factoryMock.Object,
                                                                  placeServiceMock.Object, addressServiceMock.Object, tablesServiceMock.Object,
                                                                  reviewsServiceMock.Object);

            InitializeMapper();

            var placeId  = Guid.NewGuid();
            var userId   = Guid.NewGuid().ToString();
            var username = "******";
            var place    = new Place()
            {
                Id = placeId
            };
            var list = new List <Place>()
            {
                place
            };

            placeServiceMock.Setup(s => s.GetPlaceWithReviews(placeId)).Returns(list.AsQueryable());
            authProviderMock.Setup(ap => ap.CurrentUserId).Returns(userId);
            authProviderMock.Setup(ap => ap.CurrentUserUsername).Returns(username);
            var emptyListReviews = new List <Review>();

            reviewsServiceMock.Setup(s => s.GetByUserAndPlace(placeId, userId)).Returns(emptyListReviews.AsQueryable());
            var reviewForm = new SingleReviewViewModel();

            factoryMock.Setup(f => f.CreateReviewViewModel(placeId, userId, username)).Returns(reviewForm);

            controller
            .WithCallTo(c => c.Details(placeId))
            .ShouldRenderDefaultView();
        }
Ejemplo n.º 9
0
        public void GetEditShould_ReturnSameView_WhenModelIsNotValid()
        {
            var placeServiceMock   = new Mock <IPlaceService>();
            var addressServiceMock = new Mock <IAddressService>();
            var tablesServiceMock  = new Mock <ITablesService>();
            var reviewsServiceMock = new Mock <IReviewsService>();
            var authProviderMock   = new Mock <IAuthenticationProvider>();
            var factoryMock        = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.PlacesController(authProviderMock.Object, factoryMock.Object,
                                                                  placeServiceMock.Object, addressServiceMock.Object, tablesServiceMock.Object,
                                                                  reviewsServiceMock.Object);

            controller.ModelState.AddModelError("key", "message");

            var model = new EditViewModel();

            controller
            .WithCallTo(c => c.Edit(model))
            .ShouldRenderDefaultView();
        }
Ejemplo n.º 10
0
        public void GetCreateShould_ReturnViewWithCorrectModel()
        {
            var placeServiceMock   = new Mock <IPlaceService>();
            var addressServiceMock = new Mock <IAddressService>();
            var tablesServiceMock  = new Mock <ITablesService>();
            var reviewsServiceMock = new Mock <IReviewsService>();
            var authProviderMock   = new Mock <IAuthenticationProvider>();
            var factoryMock        = new Mock <IViewModelFactory>();

            var model = new CreateViewModel();

            factoryMock.Setup(f => f.CreateCreateViewModel()).Returns(model);

            var controller = new Web.Controllers.PlacesController(authProviderMock.Object, factoryMock.Object,
                                                                  placeServiceMock.Object, addressServiceMock.Object, tablesServiceMock.Object,
                                                                  reviewsServiceMock.Object);

            controller
            .WithCallTo(c => c.Create())
            .ShouldRenderDefaultView()
            .WithModel(model);
        }
Ejemplo n.º 11
0
        public void PostCreateShould_RedirectToDetails_WhenModelIsValid()
        {
            var placeServiceMock   = new Mock <IPlaceService>();
            var addressServiceMock = new Mock <IAddressService>();
            var tablesServiceMock  = new Mock <ITablesService>();
            var reviewsServiceMock = new Mock <IReviewsService>();
            var authProviderMock   = new Mock <IAuthenticationProvider>();
            var factoryMock        = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.PlacesController(authProviderMock.Object, factoryMock.Object,
                                                                  placeServiceMock.Object, addressServiceMock.Object, tablesServiceMock.Object,
                                                                  reviewsServiceMock.Object);

            var model   = new CreateViewModel();
            var userId  = Guid.NewGuid().ToString();
            var address = new Address()
            {
                Id = Guid.NewGuid()
            };
            var place = new Place()
            {
                Id = Guid.NewGuid()
            };

            authProviderMock.Setup(ap => ap.CurrentUserId).Returns(userId);
            addressServiceMock.Setup(s => s.CreateAddress(model.Country, model.City, model.Area, model.Street,
                                                          model.Number))
            .Returns(address);

            placeServiceMock.Setup(s => s.CreatePlace(model.Name, model.Types, model.Contact, model.WeekendHours,
                                                      model.WeekdayHours, model.Description, model.AverageBill, userId, address.Id))
            .Returns(place);

            controller
            .WithCallTo(c => c.Create(model))
            .ShouldRedirectTo((Web.Controllers.PlacesController c) => c.Details(place.Id));
        }
Ejemplo n.º 12
0
        public void DetailsShould_ReturnErrorView_WhenPlaceWasNotFound()
        {
            var placeServiceMock   = new Mock <IPlaceService>();
            var addressServiceMock = new Mock <IAddressService>();
            var tablesServiceMock  = new Mock <ITablesService>();
            var reviewsServiceMock = new Mock <IReviewsService>();
            var authProviderMock   = new Mock <IAuthenticationProvider>();
            var factoryMock        = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.PlacesController(authProviderMock.Object, factoryMock.Object,
                                                                  placeServiceMock.Object, addressServiceMock.Object, tablesServiceMock.Object,
                                                                  reviewsServiceMock.Object);

            InitializeMapper();

            var placeId   = Guid.NewGuid();
            var emptyList = new List <Place>();

            placeServiceMock.Setup(s => s.GetPlaceWithReviews(placeId)).Returns(emptyList.AsQueryable());

            controller
            .WithCallTo(c => c.Details(placeId))
            .ShouldRenderView("Error");
        }
Ejemplo n.º 13
0
        public void MyPlacesShould_ReturnDefaultView()
        {
            var placeServiceMock   = new Mock <IPlaceService>();
            var addressServiceMock = new Mock <IAddressService>();
            var tablesServiceMock  = new Mock <ITablesService>();
            var reviewsServiceMock = new Mock <IReviewsService>();
            var authProviderMock   = new Mock <IAuthenticationProvider>();
            var factoryMock        = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.PlacesController(authProviderMock.Object, factoryMock.Object,
                                                                  placeServiceMock.Object, addressServiceMock.Object, tablesServiceMock.Object,
                                                                  reviewsServiceMock.Object);

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

            authProviderMock.Setup(ap => ap.CurrentUserId).Returns(userId);
            var model = new List <Place>();

            placeServiceMock.Setup(s => s.GetUserPlaces(userId)).Returns(model.AsQueryable());

            controller
            .WithCallTo(c => c.MyPlaces())
            .ShouldRenderDefaultView();
        }