Пример #1
0
        public void GetFindsPage_CorrectInputDataOffset_PagingResultInstanceExpected()
        {
            // Arrange
            int pageSize           = 5;
            int offset             = 5;
            int expectedItemsCount = 3;
            PagingResult <List <FindsQuickViewModel> > result;
            IQueryable <Find>    finds     = GetQueryableFindsList();
            Mock <DbSet <Find> > findTable = new Mock <DbSet <Find> >();

            SetupDbSetFindsMock(findTable, finds);
            int expectedTotalCount          = findTable.Object.Count();
            Mock <AppDbContext> mockContext = new Mock <AppDbContext>();

            mockContext.Setup(m => m.Finds).Returns(findTable.Object);
            FindRepository findRepo = new FindRepository(mockContext.Object);

            // Act
            result = findRepo.GetFindsPage(pageSize, offset);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedItemsCount, result.Items.Count);
            Assert.AreEqual(expectedTotalCount, result.TotalCount);
        }
Пример #2
0
        public void GetFindById_NonExistentId_NullExpected()
        {
            // Arrange
            int idToSearch = 9;
            DetailedFindModel    foundFind;
            IQueryable <Find>    finds      = GetQueryableFindsList();
            Mock <DbSet <Find> > findsTable = new Mock <DbSet <Find> >();

            SetupDbSetFindsMock(findsTable, finds);
            Mock <AppDbContext> mockContext = new Mock <AppDbContext>();

            mockContext.Setup(m => m.Finds).Returns(findsTable.Object);
            FindRepository findsRepo = new FindRepository(mockContext.Object);

            // Act
            foundFind = findsRepo.GetFindById(idToSearch);

            // Assert
            Assert.IsNull(foundFind);
        }
Пример #3
0
        public ActionResult Index(string global, string scope, string terms)
        {
            var model = new FindIndexModel();

            model.FindText = terms;

            if (!string.IsNullOrEmpty(terms))
            {
                var findResults = FindRepository.Find(model.FindText)
                                  .OrderBy(row => row.Type)
                                  .ThenByDescending(row => row.CreatedDate)
                                  .AsEnumerable();

                switch (scope)
                {
                case "hours":
                    findResults = findResults.Where(row => row.Type == "Hour").AsEnumerable();
                    break;

                case "projects":
                    findResults = findResults.Where(row => row.Type == "Project").AsEnumerable();
                    break;

                case "stories":
                    findResults = findResults.Where(row => row.Type == "Story").AsEnumerable();
                    break;

                case "users":
                    findResults = findResults.Where(row => row.Type == "User").AsEnumerable();
                    break;
                }

                model.FindResults = findResults;
                model.ShowScope   = true;
            }

            return(View(model));
        }