示例#1
0
        public void DetailsShould_CallPlaceServiceMethodGetPlaceWithReviews_WhenIdIsNotNull()
        {
            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();

            controller.Details(placeId);

            placeServiceMock.Verify(s => s.GetPlaceWithReviews(placeId), Times.Once);
        }
示例#2
0
        public void DetailsShould_CallFactoryMethodCreateReviewViewModel_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.Details(placeId);

            factoryMock.Verify(f => f.CreateReviewViewModel(placeId, userId, username), Times.Once);
        }