Ejemplo n.º 1
0
        public void RenderRentItemView()
        {
            // Arrange
            var mockedCategoryService  = new Mock <ICategoryService>();
            var mockedRentItemyService = new Mock <IRentItemService>();
            var categoryModel          = new CategoryDtoModel()
            {
                ID   = Guid.NewGuid(),
                Name = "FakeName"
            };
            var stubId    = Guid.NewGuid();
            var stubModel = new RentItemDetaildDtoModel()
            {
                AvailableFrom = new DateTime(2017, 03, 26),
                AvailableTo   = new DateTime(2017, 04, 26),
                CategoryId    = Guid.NewGuid().ToString(),
                Description   = "test description",
                Images        = new List <ImagesDtoModel>(),
                ItemId        = Guid.NewGuid().ToString(),
                Location      = "SomeLocation",
                Name          = "FakeName",
                OwnerId       = Guid.NewGuid().ToString(),
                Price         = 10.2m,
                Category      = new CategoryDtoModel(),
                Comments      = new List <DtoModels.CommentsDto.CommentDtoModel>(),
                IsDeleted     = false,
                Owner         = "someOwner"
            };

            mockedRentItemyService.Setup(x => x.GetRentItemById(stubId)).Returns(stubModel);

            RentItemsController sut = new RentItemsController(mockedCategoryService.Object, mockedRentItemyService.Object);

            // Act & Assert
            sut
            .WithCallTo(c => c.Get(stubId))
            .ShouldRenderView("RentItem")
            .WithModel <RentItemsViewModelDetailed>(
                v =>
            {
                Assert.AreEqual(stubModel.AvailableFrom, v.RentItem.AvailableFrom);
                Assert.AreEqual(stubModel.AvailableTo, v.RentItem.AvailableTo);
                Assert.AreEqual(stubModel.CategoryId, v.RentItem.CategoryId);
                Assert.AreEqual(stubModel.Description, v.RentItem.Description);
                Assert.AreEqual(stubModel.ItemId, v.RentItem.ItemId);
                Assert.AreEqual(stubModel.Location, v.RentItem.Location);
                Assert.AreEqual(stubModel.Name, v.RentItem.Name);
                Assert.AreEqual(stubModel.OwnerId, v.RentItem.OwnerId);
                Assert.AreEqual(stubModel.Price, v.RentItem.Price);
                Assert.AreEqual(stubModel.Category, v.RentItem.Category);
                Assert.AreEqual(stubModel.Comments, v.RentItem.Comments);
                Assert.AreEqual(stubModel.IsDeleted, v.RentItem.IsDeleted);
                Assert.AreEqual(stubModel.Owner, v.RentItem.Owner);
            });
        }
Ejemplo n.º 2
0
        public void RenderRentItemViewAndFillTempDataAndPreservsItAfterThreeCalls()
        {
            // Arrange
            var mockedCategoryService  = new Mock <ICategoryService>();
            var mockedRentItemyService = new Mock <IRentItemService>();
            var searchViewModelStub    = new SearchViewModel()
            {
                CategoryId = Guid.NewGuid(),
                StartDate  = new DateTime(2017, 03, 20),
                EndDate    = new DateTime(2017, 03, 26),
                Filter     = "someFilter",
                LoginView  = new LoginViewModel()
            };

            var homeViewModelStub = new HomeViewModel()
            {
                Search = searchViewModelStub
            };

            var stubReturnModel = new RentItemDtoModel();
            var mockedViewModel = new List <RentItemDtoModel>()
            {
                stubReturnModel
            };

            mockedRentItemyService.Setup(x => x.GetRentItems(searchViewModelStub.StartDate,
                                                             searchViewModelStub.EndDate,
                                                             searchViewModelStub.CategoryId,
                                                             searchViewModelStub.Filter, 0)).Returns(mockedViewModel);

            RentItemsController sut = new RentItemsController(mockedCategoryService.Object, mockedRentItemyService.Object);

            // Act & Assert
            sut.WithCallTo(c => c.Search(homeViewModelStub, null));
            Assert.IsNotNull(sut.TempData["model"]);
            sut.WithCallTo(c => c.Search(homeViewModelStub, null));
            Assert.IsNotNull(sut.TempData["model"]);
            sut.WithCallTo(c => c.Search(homeViewModelStub, null));
            Assert.IsNotNull(sut.TempData["model"]);
        }
Ejemplo n.º 3
0
        public void ReturnsDefaultView()
        {
            // Arrange
            var mockedCategoryService  = new Mock <ICategoryService>();
            var mockedRentItemyService = new Mock <IRentItemService>();
            var categoryModel          = new CategoryDtoModel()
            {
                ID   = Guid.NewGuid(),
                Name = "FakeName"
            };

            RentItemsController sut = new RentItemsController(mockedCategoryService.Object, mockedRentItemyService.Object);

            // Act & Assert
            sut
            .WithCallTo(c => c.Index())
            .ShouldRenderDefaultView();
        }
Ejemplo n.º 4
0
        public void RenderRentItemViewWithEmtyModelIfNotItemsFound()
        {
            // Arrange
            var mockedCategoryService  = new Mock <ICategoryService>();
            var mockedRentItemyService = new Mock <IRentItemService>();
            var searchViewModelStub    = new SearchViewModel()
            {
                CategoryId = Guid.NewGuid(),
                StartDate  = new DateTime(2017, 03, 20),
                EndDate    = new DateTime(2017, 03, 26),
                Filter     = "someFilter",
                LoginView  = new LoginViewModel()
            };

            var homeViewModelStub = new HomeViewModel()
            {
                Search = searchViewModelStub
            };


            var mockedViewModel = new List <RentItemDtoModel>();

            mockedRentItemyService.Setup(x => x.GetRentItems(searchViewModelStub.StartDate,
                                                             searchViewModelStub.EndDate,
                                                             searchViewModelStub.CategoryId,
                                                             searchViewModelStub.Filter, 1)).Returns(mockedViewModel);

            RentItemsController sut = new RentItemsController(mockedCategoryService.Object, mockedRentItemyService.Object);

            // Act & Assert
            sut
            .WithCallTo(c => c.Search(homeViewModelStub, null))
            .ShouldRenderPartialView("_RentItemsPartialView")
            .WithModel <List <RentItemDtoModel> >(
                v =>
            {
                Assert.AreEqual(0, v.Count);
            });
        }
Ejemplo n.º 5
0
        public void CallRentItemsServiceGetRentItemById_Once()
        {
            // Arrange
            var mockedCategoryService  = new Mock <ICategoryService>();
            var mockedRentItemyService = new Mock <IRentItemService>();
            var categoryModel          = new CategoryDtoModel()
            {
                ID   = Guid.NewGuid(),
                Name = "FakeName"
            };
            var stubId       = Guid.NewGuid();
            var rentItemStub = new RentItemDetaildDtoModel();

            mockedRentItemyService.Setup(x => x.GetRentItemById(stubId)).Returns(rentItemStub);

            RentItemsController sut = new RentItemsController(mockedCategoryService.Object, mockedRentItemyService.Object);

            // Act
            sut.WithCallTo(c => c.Get(stubId));

            //Assert
            mockedRentItemyService.Verify(x => x.GetRentItemById(stubId), Times.Once);
        }
Ejemplo n.º 6
0
        public void RenderRentItemView(int id)
        {
            // Arrange
            var mockedCategoryService  = new Mock <ICategoryService>();
            var mockedRentItemyService = new Mock <IRentItemService>();
            var searchViewModelStub    = new SearchViewModel()
            {
                CategoryId = Guid.NewGuid(),
                StartDate  = new DateTime(2017, 03, 20),
                EndDate    = new DateTime(2017, 03, 26),
                Filter     = "someFilter",
                LoginView  = new LoginViewModel()
            };

            var homeViewModelStub = new HomeViewModel()
            {
                Search = searchViewModelStub
            };

            var stubReturnModel = new RentItemDtoModel
            {
                AvailableFrom = new DateTime(2017, 03, 26),
                AvailableTo   = new DateTime(2017, 04, 26),
                CategoryId    = Guid.NewGuid().ToString(),
                Description   = "test description",
                Images        = new List <ImagesDtoModel>(),
                ItemId        = Guid.NewGuid().ToString(),
                Location      = "SomeLocation",
                Name          = "FakeName",
                OwnerId       = Guid.NewGuid().ToString(),
                Price         = 10.2m
            };

            var mockedViewModel = new List <RentItemDtoModel>()
            {
                stubReturnModel
            };

            mockedRentItemyService.Setup(x => x.GetRentItems(searchViewModelStub.StartDate,
                                                             searchViewModelStub.EndDate,
                                                             searchViewModelStub.CategoryId,
                                                             searchViewModelStub.Filter, id - 1)).Returns(mockedViewModel);

            RentItemsController sut = new RentItemsController(mockedCategoryService.Object, mockedRentItemyService.Object);

            //sut.ControllerContext.
            // Act & Assert
            sut
            .WithCallTo(c => c.Search(homeViewModelStub, id))
            .ShouldRenderPartialView("_RentItemsPartialView")
            .WithModel <List <RentItemDtoModel> >(
                v =>
            {
                Assert.AreEqual(stubReturnModel.AvailableFrom, v.First().AvailableFrom);
                Assert.AreEqual(stubReturnModel.AvailableTo, v.First().AvailableTo);
                Assert.AreEqual(stubReturnModel.CategoryId, v.First().CategoryId);
                Assert.AreEqual(stubReturnModel.Description, v.First().Description);
                Assert.AreEqual(stubReturnModel.ItemId, v.First().ItemId);
                Assert.AreEqual(stubReturnModel.Location, v.First().Location);
                Assert.AreEqual(stubReturnModel.Name, v.First().Name);
                Assert.AreEqual(stubReturnModel.OwnerId, v.First().OwnerId);
                Assert.AreEqual(stubReturnModel.Price, v.First().Price);
            });
        }