Example #1
0
        public void ConstructorShould_SetPassedData_WhenDataIsNotNull()
        {
            var consumableServiceMock = new Mock <IConsumableService>();
            var placeServiceMock      = new Mock <IPlaceService>();
            var facctoryMock          = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.ConsumablesController(consumableServiceMock.Object,
                                                                       placeServiceMock.Object, facctoryMock.Object);

            Assert.IsNotNull(controller);
        }
Example #2
0
        public void GetCreateShould_ReturnErrorView_WhenPassedIdIsNull()
        {
            var consumableServiceMock = new Mock <IConsumableService>();
            var placeServiceMock      = new Mock <IPlaceService>();
            var facctoryMock          = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.ConsumablesController(consumableServiceMock.Object,
                                                                       placeServiceMock.Object, facctoryMock.Object);

            controller
            .WithCallTo(c => c.Create(null))
            .ShouldRenderView("Error");
        }
Example #3
0
        public void AddConsumableShould_CallConsumableServiceMethodAddConsumable_WhenModelIsValid()
        {
            var consumableServiceMock = new Mock <IConsumableService>();
            var placeServiceMock      = new Mock <IPlaceService>();
            var facctoryMock          = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.ConsumablesController(consumableServiceMock.Object,
                                                                       placeServiceMock.Object, facctoryMock.Object);
            var model = new ConsumableViewModel();

            controller.AddConsumable(model);
            consumableServiceMock.Verify(s => s.AddConsumable(model.PlaceId, model.Name, model.Quantity, model.Price,
                                                              model.Type, model.Ingredients));
        }
Example #4
0
        public void GetNewFormShould_CallFactoryMethodCreateConsumableViewModel_WhenPassedIdIsNotNull()
        {
            var consumableServiceMock = new Mock <IConsumableService>();
            var placeServiceMock      = new Mock <IPlaceService>();
            var factoryMock           = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.ConsumablesController(consumableServiceMock.Object,
                                                                       placeServiceMock.Object, factoryMock.Object);
            var id = Guid.NewGuid();

            controller.GetNewForm(id);

            factoryMock.Verify(f => f.CreateConsumableViewModel(id), Times.Once);
        }
Example #5
0
        public void GetCreateShould_CallConsumableServiceMethodGetAllConsumablesOf_WhenPassedIdIsNotNull()
        {
            var consumableServiceMock = new Mock <IConsumableService>();
            var placeServiceMock      = new Mock <IPlaceService>();
            var facctoryMock          = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.ConsumablesController(consumableServiceMock.Object,
                                                                       placeServiceMock.Object, facctoryMock.Object);

            var id = Guid.NewGuid();

            controller.Create(id);

            consumableServiceMock.Verify(s => s.GetAllConsumablesOf(id), Times.Once);
        }
Example #6
0
        public void AddConsumableShould_ReturnViewWithCorrectModel_WhenModelIssValid()
        {
            var consumableServiceMock = new Mock <IConsumableService>();
            var placeServiceMock      = new Mock <IPlaceService>();
            var facctoryMock          = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.ConsumablesController(consumableServiceMock.Object,
                                                                       placeServiceMock.Object, facctoryMock.Object);
            var model = new ConsumableViewModel();

            controller
            .WithCallTo(c => c.AddConsumable(model))
            .ShouldRenderPartialView("_Consumable")
            .WithModel(model);
        }
Example #7
0
        public void AddConsumableShould_ReturnSameView_WhenModelIsNotValid()
        {
            var consumableServiceMock = new Mock <IConsumableService>();
            var placeServiceMock      = new Mock <IPlaceService>();
            var facctoryMock          = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.ConsumablesController(consumableServiceMock.Object,
                                                                       placeServiceMock.Object, facctoryMock.Object);
            var model = new ConsumableViewModel();

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

            controller
            .WithCallTo(c => c.AddConsumable(model))
            .ShouldRenderPartialView("_ConsumableForm")
            .WithModel(model);
        }
Example #8
0
        public void GetCreateShould_CallFactoryMethodCreateMenuViewModel_WhenPassedIdIsNotNull()
        {
            var consumableServiceMock = new Mock <IConsumableService>();
            var placeServiceMock      = new Mock <IPlaceService>();
            var facctoryMock          = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.ConsumablesController(consumableServiceMock.Object,
                                                                       placeServiceMock.Object, facctoryMock.Object);

            var id        = Guid.NewGuid();
            var emptyList = new List <Consumable>();

            consumableServiceMock.Setup(s => s.GetAllConsumablesOf(id)).Returns(emptyList.AsQueryable());

            controller.Create(id);

            facctoryMock.Verify(s => s.CreateMenuViewModel(id, emptyList), Times.Once);
        }
Example #9
0
        public void GetNewFormShould_ReturnViewWithCorrectModel_WhenPassedIdIsNotNull()
        {
            var consumableServiceMock = new Mock <IConsumableService>();
            var placeServiceMock      = new Mock <IPlaceService>();
            var factoryMock           = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.ConsumablesController(consumableServiceMock.Object,
                                                                       placeServiceMock.Object, factoryMock.Object);
            var id    = Guid.NewGuid();
            var model = new ConsumableViewModel()
            {
                PlaceId = id
            };

            factoryMock.Setup(f => f.CreateConsumableViewModel(id)).Returns(model);

            controller
            .WithCallTo(c => c.GetNewForm(id))
            .ShouldRenderPartialView("_ConsumableForm")
            .WithModel(model);
        }
Example #10
0
        public void GetCreateShould_ReturnViewWithCorrectModel_WhenPassedIdIsNotNull()
        {
            var consumableServiceMock = new Mock <IConsumableService>();
            var placeServiceMock      = new Mock <IPlaceService>();
            var facctoryMock          = new Mock <IViewModelFactory>();

            var controller = new Web.Controllers.ConsumablesController(consumableServiceMock.Object,
                                                                       placeServiceMock.Object, facctoryMock.Object);

            var id        = Guid.NewGuid();
            var emptyList = new List <Consumable>();
            var model     = new CreateMenuViewModel();

            model.Menu    = emptyList;
            model.PlaceId = id;

            consumableServiceMock.Setup(s => s.GetAllConsumablesOf(id)).Returns(emptyList.AsQueryable());
            facctoryMock.Setup(s => s.CreateMenuViewModel(id, emptyList)).Returns(model);

            controller
            .WithCallTo(c => c.Create(id))
            .ShouldRenderView("CreateMenu")
            .WithModel(model);
        }