Exemplo n.º 1
0
        public void TestGetAll_ShouldReturnCorrectly()
        {
            // Arrange
            var logs = new List <TrainingLog>
            {
                new TrainingLog()
            }.AsQueryable();

            var mockedLogRepository = new Mock <IRepository <TrainingLog> >();

            mockedLogRepository.Setup(r => r.All).Returns(logs);

            var mockedUnitOfWork       = new Mock <IUnitOfWork>();
            var mockedLogFactory       = new Mock <ITrainingLogFactory>();
            var mockedUserService      = new Mock <IUserService>();
            var mockedDateTimeProvider = new Mock <IDateTimeProvider>();

            var service = new LogsService(mockedLogRepository.Object,
                                          mockedUnitOfWork.Object,
                                          mockedLogFactory.Object,
                                          mockedUserService.Object,
                                          mockedDateTimeProvider.Object);

            // Act
            var result = service.GetAll();

            // Assert
            CollectionAssert.AreEqual(logs, result);
        }
Exemplo n.º 2
0
        public ActionResult LoadLogs(string sidx, string sord, int page, int rows,
                                     bool _search, string searchField, string searchOper, string searchString)
        {
            // Get the list of users
            IQueryable <LogsViewModel> logs = _logService.GetAll().OrderByDescending(x => x.DateModified);

            // If search, filter the list against the search condition.
            // Only "contains" search is implemented here.
            var filteredRoles = logs;

            if (_search)
            {
                switch (searchOper)
                {
                case "eq":
                    filteredRoles = logs.Where(x => x.ModifiedBy == searchString).AsQueryable();
                    break;
                    //case "cn":
                    //    filteredRoles = category.Where( s => s.Name.Contains( searchString ) ).AsQueryable();
                    //    break;
                }
            }
            // Sort the student list
            var sortedRoles = SortIQueryable <LogsViewModel>(filteredRoles, sidx, sord).AsEnumerable();

            // Calculate the total number of pages
            var totalRecords = filteredRoles.Count();
            var totalPages   = (int)Math.Ceiling((double)totalRecords / (double)rows);

            // NOTE:XXXX Prepare the data to fit the requirement of jQGrid
            var data =
                sortedRoles.Select(s => new
            {
                id   = s.ID,
                cell = new object[] {
                    s.ID,
                    s.ActionType,
                    s.Description,
                    s.ModifiedBy,
                    s.DateModified
                }
            }).ToArray();

            // Send the data to the jQGrid
            var jsonData = new
            {
                total   = totalPages,
                page    = page,
                records = totalRecords,
                rows    = data.Skip((page - 1) * rows).Take(rows)
            };

            return(Json(jsonData, JsonRequestBehavior.AllowGet));
        }
        public async Task Can_Return_Logs()
        {
            var dbContextOptions = CreateNewContextOptions();

            using (var context = new ApplicationDbContext(dbContextOptions))
            {
                context.Logs.AddRange(new Logs(), new Logs());

                await context.SaveChangesAsync();
            }

            using (var context = new ApplicationDbContext(dbContextOptions))
            {
                var service = new LogsService(context);
                var result  = await service.GetAll();

                Assert.Equal(2, result.Count);
            }
        }
Exemplo n.º 4
0
        public void TestGetAll_ShouldCallRepositoryAll()
        {
            // Arrange
            var mockedLogRepository    = new Mock <IRepository <TrainingLog> >();
            var mockedUnitOfWork       = new Mock <IUnitOfWork>();
            var mockedLogFactory       = new Mock <ITrainingLogFactory>();
            var mockedUserService      = new Mock <IUserService>();
            var mockedDateTimeProvider = new Mock <IDateTimeProvider>();

            var service = new LogsService(mockedLogRepository.Object,
                                          mockedUnitOfWork.Object,
                                          mockedLogFactory.Object,
                                          mockedUserService.Object,
                                          mockedDateTimeProvider.Object);

            // Act
            service.GetAll();

            // Assert
            mockedLogRepository.Verify(r => r.All, Times.Once);
        }
Exemplo n.º 5
0
 public List <Log> GetAll()
 {
     return(_logsService.GetAll().ToList());
 }