Beispiel #1
0
        public void ContextBuildsAViewModelWithAllCategories()
        {
            var category = new Category {
                Description = "Category 1"
            };
            var categoryViewModel = new CategoryViewModel {
                Description = "Category 1"
            };
            var categories = new List <Category> {
                category
            };
            var mockCategoryRepository = new MockCategoryRepository().StubGetAllToReturn(categories);
            var mockCategoryMapper     = new MockCategoryMapper().StubMapToReturn(categoryViewModel);
            var categoriesContext      = new CategoriesContext(mockCategoryRepository, mockCategoryMapper);

            var viewModel = categoriesContext.BuildViewModel();

            Assert.NotNull(viewModel);
            Assert.IsType <CategoriesViewModel>(viewModel);
            Assert.Equal(categories.Count, viewModel.Categories.Count());

            var categoryViewModels = viewModel.Categories.ToList();

            Assert.Equal(category.Id, categoryViewModels.First()
                         .Id);
            Assert.Equal(category.Description, categoryViewModels.First()
                         .Description);

            mockCategoryRepository.VerifyGetAllCalled();
            mockCategoryMapper.VerifyMapCalledWith(category);
        }
Beispiel #2
0
        public void CreatesACategoryContext()
        {
            var mockCategoryRepository = new MockCategoryRepository();
            var mockCategoryMapper     = new MockCategoryMapper();
            var categoryContext        = new CategoryContext(mockCategoryRepository, mockCategoryMapper);

            Assert.NotNull(categoryContext);
        }
Beispiel #3
0
        public void ContextBuildsAViewModelWithNewCategory()
        {
            var mockCategoryRepository = new MockCategoryRepository();
            var mockCategoryMapper     = new MockCategoryMapper();
            var categoryContext        = new CategoryContext(mockCategoryRepository, mockCategoryMapper);

            var viewModel = categoryContext.BuildViewModel();

            Assert.NotNull(viewModel);
        }
Beispiel #4
0
 private GameContext BuildGameContext(MockGameRepository mockGameRepository         = null,
                                      MockCategoryRepository mockCategoryRepository = null, MockGameMapper mockGameMapper             = null,
                                      MockCategoryMapper mockCategoryMapper         = null, MockPlayedDateMapper mockPlayedGameMapper = null)
 {
     mockGameRepository     = mockGameRepository ?? new MockGameRepository();
     mockCategoryRepository = mockCategoryRepository ?? new MockCategoryRepository();
     mockGameMapper         = mockGameMapper ?? new MockGameMapper();
     mockCategoryMapper     = mockCategoryMapper ?? new MockCategoryMapper();
     mockPlayedGameMapper   = mockPlayedGameMapper ?? new MockPlayedDateMapper();
     return(new GameContext(mockGameRepository, mockCategoryRepository, mockGameMapper, mockCategoryMapper, mockPlayedGameMapper));
 }
Beispiel #5
0
        public void ContextRemovesACategory()
        {
            var category = new Category {
                Description = "Category 2"
            };
            var mockCategoryRepository = new MockCategoryRepository().StubGetByIdToReturn(category);
            var mockCategoryMapper     = new MockCategoryMapper();
            var categoriesContext      = new CategoriesContext(mockCategoryRepository, mockCategoryMapper);

            categoriesContext.Remove(category.Id);

            mockCategoryRepository.VerifyGetByCalledWith(category.Id);
            mockCategoryRepository.VerifyRemoveCalledWith(category);
        }
Beispiel #6
0
        public void ContextSavesANewCategory()
        {
            var category = new Category {
                Id = 4, Description = "This is new category"
            };
            var categoryViewModel = new CategoryViewModel {
                Id = 4, Description = "This is a new category"
            };
            var mockCategoryRepository = new MockCategoryRepository();
            var mockCategoryMapper     = new MockCategoryMapper().StubMapToReturn(category);
            var categoryContext        = new CategoryContext(mockCategoryRepository, mockCategoryMapper);

            categoryContext.Save(categoryViewModel);

            mockCategoryRepository.VerifyGetByCalledWith(categoryViewModel.Id);
            mockCategoryRepository.VerifyAddCalledWith(category);
            mockCategoryMapper.VerifyMapCalledWith(categoryViewModel);
        }
Beispiel #7
0
        public void ContextBuildsAViewModelWithEditedCategory()
        {
            var category = new Category {
                Id = 2, Description = "This is category 2"
            };
            var categoryViewModel = new CategoryViewModel {
                Id = 2, Description = "This is category 2"
            };
            var mockCategoryRepository = new MockCategoryRepository().StubGetByIdToReturn(category);
            var mockCategoryMapper     = new MockCategoryMapper().StubMapToReturn(categoryViewModel);
            var categoryContext        = new CategoryContext(mockCategoryRepository, mockCategoryMapper);

            var viewModel = categoryContext.BuildViewModel(category.Id);

            Assert.NotNull(viewModel);
            mockCategoryRepository.VerifyGetByCalledWith(category.Id);
            mockCategoryMapper.VerifyMapCalledWith(category);
        }
Beispiel #8
0
        public void ContextSavesAnUpdatedCategory()
        {
            var category = new Category {
                Id = 2, Description = "This is category 2"
            };
            var categoryViewModel = new CategoryViewModel
            {
                Id          = 2,
                Description = "This is an updated category"
            };
            var mockCategoryRepository = new MockCategoryRepository().StubGetByIdToReturn(category);
            var mockCategoryMapper     = new MockCategoryMapper();
            var categoryContext        = new CategoryContext(mockCategoryRepository, mockCategoryMapper);

            categoryContext.Save(categoryViewModel);

            mockCategoryRepository.VerifyGetByCalledWith(categoryViewModel.Id);
            mockCategoryRepository.VerifyUpdateCalledWith(category);
        }
Beispiel #9
0
        public void ContextBuildsAViewModelWithNewGame()
        {
            var category = new Category {
                Id = 1, Description = "Category 1"
            };
            var categories = new List <Category> {
                category
            };
            var item = new SelectListItem {
                Value = "1", Text = "Category 1"
            };
            var categorySelectListItems = new List <SelectListItem> {
                item
            };
            var electedCategories = new List <CategoryViewModel>();
            var playedDates       = new List <PlayedDateViewModel>();
            var game          = new Game();
            var gameViewModel = new GameViewModel
            {
                Categories        = categorySelectListItems,
                ElectedCategories = electedCategories,
                PlayedDates       = playedDates
            };
            var mockGameRepository     = new MockGameRepository().StubGetByToReturn(game);
            var mockCategoryRepository = new MockCategoryRepository().StubGetAllToReturn(categories);
            var mockGameMapper         = new MockGameMapper().StubMapWithCategoriesToReturn(gameViewModel);
            var mockCategoryMapper     = new MockCategoryMapper().StubSelectMapToReturn(item);
            var gameContext            = BuildGameContext(mockGameRepository, mockCategoryRepository, mockGameMapper,
                                                          mockCategoryMapper);

            var viewModel = gameContext.BuildViewModel(game.Id);

            Assert.NotNull(viewModel);
            Assert.Equal(1, viewModel.Categories.Count());
            mockGameRepository.VerifyGetByCalledWith(game.Id);
            mockCategoryRepository.VerifyGetAllCalled();
            mockGameMapper.VerifyMapCalledWith(game, categorySelectListItems, electedCategories, playedDates);
            mockCategoryMapper.VerifySelectMapCalledWith(category);
        }
Beispiel #10
0
        public void ContextBuildsAViewModelWithEditedGame()
        {
            var category = new Category {
                Id = 1, Description = "Category 1"
            };
            var categories = new List <Category> {
                category
            };
            var item = new SelectListItem {
                Value = "1", Text = "Category 1"
            };
            var categorySelectListItems = new List <SelectListItem> {
                item
            };
            var categoryViewModel = new CategoryViewModel {
                Id = 1, Description = "Category 1"
            };
            var electedCategories = new List <CategoryViewModel> {
                categoryViewModel
            };
            var playedDateViewModel = new PlayedDateViewModel {
                Id = 1, FormattedPlayedDate = "1/1/2016"
            };
            var playedDates = new List <PlayedDateViewModel> {
                playedDateViewModel
            };
            var game = new Game {
                Id = 2, Name = "Game 2", Description = "This is game 2"
            };
            var gamePlayedDate = new GamePlayedDate {
                Id = 1, GameId = game.Id, Game = game, PlayedDate = new DateTime(2016, 1, 1)
            };
            var gamePlayedDates = new List <GamePlayedDate> {
                gamePlayedDate
            };
            var gameViewModel = new GameViewModel
            {
                Id                = 2,
                Name              = "Game 2",
                Description       = "This is game 2",
                Categories        = categorySelectListItems,
                ElectedCategories = electedCategories,
                PlayedDates       = playedDates
            };
            var mockGameRepository = new MockGameRepository()
                                     .StubGetAllCategoriesByToReturn(categories)
                                     .StubGetAllPlayedDatesByToReturn(gamePlayedDates)
                                     .StubGetByToReturn(game);
            var mockCategoryRepository = new MockCategoryRepository()
                                         .StubGetAllToReturn(categories);
            var mockGameMapper = new MockGameMapper()
                                 .StubMapWithCategoriesToReturn(gameViewModel);
            var mockCategoryMapper = new MockCategoryMapper()
                                     .StubMapToReturn(categoryViewModel)
                                     .StubSelectMapToReturn(item);
            var mockPlayedDateMapper = new MockPlayedDateMapper()
                                       .StubMapToReturn(playedDateViewModel);
            var gameContext = BuildGameContext(mockGameRepository, mockCategoryRepository, mockGameMapper, mockCategoryMapper, mockPlayedDateMapper);

            var viewModel = gameContext.BuildViewModel(game.Id);

            Assert.NotNull(viewModel);
            Assert.Equal(1, viewModel.Categories.Count());
            Assert.Equal(1, viewModel.ElectedCategories.Count());
            Assert.Equal(1, viewModel.PlayedDates.Count());
            mockGameRepository.VerifyGetByCalledWith(game.Id);
            mockGameRepository.VerifyGetAllCategoriesByCalledWith(game.Id);
            mockGameRepository.VerifyGetAllPlayedDatesByCalledWith(game.Id);
            mockCategoryRepository.VerifyGetAllCalled();
            mockGameMapper.VerifyMapCalledWith(game, categorySelectListItems, electedCategories, playedDates);
            mockCategoryMapper.VerifySelectMapCalledWith(category);
            mockCategoryMapper.VerifyMapCalledWith(category);
            mockPlayedDateMapper.VerifyMapCalledWith(gamePlayedDate);
        }