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

            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.Create(model);

            addressServiceMock.Verify(
                s => s.CreateAddress(model.Country, model.City, model.Area, model.Street, model.Number), Times.Once);
        }
示例#2
0
        public void GetCreateShould_CallFactoryMethodCreateCreateViewModel()
        {
            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.Create();

            factoryMock.Verify(f => f.CreateCreateViewModel(), Times.Once);
        }