예제 #1
0
        private foundSpellCM buildFoundSpellCM(Spell spell)
        {
            ReadModelMapper <Spell, foundSpellCM> mapper = new ReadModelMapper <Spell, foundSpellCM>();
            foundSpellCM cm = mapper.mapDataModelToViewModel(spell);

            return(cm);
        }
예제 #2
0
        public IPagedList <foundSpellCM> searchSpellsToPagedList(String searchString, string getSpellsBy, int?page)
        {
            int pageNumber = (page ?? 1);
            int pageSize   = 20;

            IQueryable <Spell> query = Search(searchString, getSpellsBy);

            //Paginate the query, then get the set of items specified by the paginated query.
            //Increases efficiency, as I now only get the spells I need for the page, rather than all spells that fit the user's query.
            IPagedList <Spell>  pagedQuery = query.ToPagedList(pageNumber, pageSize);
            List <foundSpellCM> CMList     = new List <foundSpellCM>();

            foreach (Spell spell in pagedQuery)
            {
                foundSpellCM cm = buildFoundSpellCM(spell);
                CMList.Add(cm);
            }

            IPagedList <foundSpellCM> result = new PagedList <foundSpellCM>(CMList, pageNumber, pageSize);

            return(result);
        }
예제 #3
0
        public void SpellSearchFacade_GetByNameContainingTOWER_ReturnPagedList()
        {
            //ensure that capitalization does not effect the search result.
            //Arrange
            List <Spell> spells  = CreateTestData.GetListOfSpells();
            var          mockSet = new Mock <DbSet <Spell> >()
                                   .SetupData(spells, o =>
            {
                return(spells.Single(x => x.Spell_id.CompareTo(o.First()) == 0));
            });

            List <foundSpellCM> expectedList = new List <foundSpellCM>();
            foundSpellCM        tower        = new foundSpellCM
            {
                Spell_id = Guid.Parse("46d10bb8-84d2-408d-a928-5847ff99461f"),
                Name     = "Widogast's Nascent Nine-sided Tower"
            };

            expectedList.Add(tower);
            IPagedList <foundSpellCM> expected = expectedList.ToPagedList(1, 20);

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Spells).Returns(mockSet.Object);
                mockContext.Mock <SpellsContext>()
                .Setup(x => x.Set <Spell>()).Returns(mockSet.Object);

                SpellsContext context = mockContext.Create <SpellsContext>();

                //Act
                var toTest = new SpellSearchFacade(context);
                var actual = toTest.searchSpellsToPagedList("TOWER", "Name", 1);

                //Assert
                actual.Should().BeEquivalentTo(expected);
            }
        }