Example #1
0
        public void ReturnViewWithEmptyModel_WhenThereNoItems()
        {
            // Arrange
            var mockedCategoryService  = new Mock <ICategoryService>();
            var mockedRentItemyService = new Mock <IRentItemService>();
            var categoryModel          = new CategoryDtoModel()
            {
                ID   = Guid.NewGuid(),
                Name = "FakeName"
            };

            var mockedList = new List <CategoryDtoModel>()
            {
                categoryModel
            };

            mockedCategoryService.Setup(m => m.GetAllCategories()).Returns(mockedList);

            var stubRecentItems = new List <RentItemDtoModel>();

            mockedRentItemyService.Setup(x => x.Recent(10)).Returns(stubRecentItems);
            HomeController homeController = new HomeController(mockedCategoryService.Object, mockedRentItemyService.Object);

            // Act & Assert
            homeController
            .WithCallTo(c => c.Index())
            .ShouldRenderDefaultView()
            .WithModel <HomeViewModel>(
                v =>
            {
                Assert.IsEmpty(v.RecentItems);
            }
                );
        }
Example #2
0
        public void ReturnViewWithModelWithCorrectProperties()
        {
            // Arrange
            var mockedCategoryService  = new Mock <ICategoryService>();
            var mockedRentItemyService = new Mock <IRentItemService>();
            var categoryModel          = new CategoryDtoModel()
            {
                ID   = Guid.NewGuid(),
                Name = "FakeName"
            };

            var mockedList = new List <CategoryDtoModel>()
            {
                categoryModel
            };

            mockedCategoryService.Setup(m => m.GetAllCategories()).Returns(mockedList);

            var stubRecentItems = new List <RentItemDtoModel>();
            var stubModel       = 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
            };

            stubRecentItems.Add(stubModel);
            mockedRentItemyService.Setup(x => x.Recent(10)).Returns(stubRecentItems);

            // Act & Assert
            HomeController homeController = new HomeController(mockedCategoryService.Object, mockedRentItemyService.Object);

            homeController
            .WithCallTo(c => c.Index())
            .ShouldRenderDefaultView()
            .WithModel <HomeViewModel>(
                v =>
            {
                Assert.AreEqual(stubModel.AvailableFrom, v.RecentItems.First().AvailableFrom);
                Assert.AreEqual(stubModel.AvailableTo, v.RecentItems.First().AvailableTo);
                Assert.AreEqual(stubModel.CategoryId, v.RecentItems.First().CategoryId);
                Assert.AreEqual(stubModel.Description, v.RecentItems.First().Description);
                Assert.AreEqual(stubModel.ItemId, v.RecentItems.First().ItemId);
                Assert.AreEqual(stubModel.Location, v.RecentItems.First().Location);
                Assert.AreEqual(stubModel.Name, v.RecentItems.First().Name);
                Assert.AreEqual(stubModel.OwnerId, v.RecentItems.First().OwnerId);
                Assert.AreEqual(stubModel.Price, v.RecentItems.First().Price);
            }
                );
        }
Example #3
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);
            });
        }
Example #4
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();
        }
Example #5
0
        public void ReturnViewWithModelWithViewBag_SameMessages()
        {
            // Arrange
            var mockedCategoryService  = new Mock <ICategoryService>();
            var mockedRentItemyService = new Mock <IRentItemService>();
            var categoryModel          = new CategoryDtoModel()
            {
                ID   = Guid.NewGuid(),
                Name = "FakeName"
            };

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

            // Act & Assert
            sut
            .WithCallTo(c => c.Contact())
            .ShouldRenderDefaultView();
            Assert.AreEqual("Your contact page.", sut.ViewBag.Message);
        }
Example #6
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);
        }