public void Delete_allTrue()
        {
            // Setup dependency
            var settingsMock = new Mock<ISettings>();
            var repositoryMock = new Mock<IRepository>();
            var uowMock = new Mock<IUnitOfWork>();
            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(x => x.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);
            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);

            // Arrange
            List<Log> logs = new List<Log>();
            bool isDeleteAll = true;

            LogLevel logLevel = LogLevel.Error;

            for (int i = 0; i < 20; i++)
            {
                logs.Add(new Log
                {
                    Message = i.ToString(),
                    Level = logLevel.ToString(),
                    Date = DateTime.UtcNow
                });
            }
            repositoryMock.Setup(r => r.Query<Log>()).Returns(logs.AsQueryable());

            // Act
            LogManagementService logAdminService = new LogManagementService(
                uowMock.Object, repositoryMock.Object, settingsMock.Object);
            logAdminService.Delete(isDeleteAll);

            // Assert
            repositoryMock.Verify(r => r.Delete<Log>(It.IsAny<Log>()));
            uowMock.Verify(u => u.Save());
        }
        public void Delete_DebugLog_DeleteInWeek_allFalse()
        {
            // Setup dependency
            var settingsMock = new Mock<ISettings>();
            var repositoryMock = new Mock<IRepository>();
            var uowMock = new Mock<IUnitOfWork>();
            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(x => x.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);
            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);

            // Arrange
            List<string> expectedResult = new List<string>();
            List<Log> logs = new List<Log>();
            bool isDeleteAll = false;

            LogLevel logLevel = LogLevel.Debug;

            for (int i = 0; i < 20; i++)
            {
                if (i < 10)
                {
                    logs.Add(new Log
                    {
                        Message = i.ToString(),
                        Level = logLevel.ToString().ToUpper(),
                        Date = DateTime.UtcNow.AddDays(-3)
                    });
                    expectedResult.Add(i.ToString());
                }
                else //Older Last week
                {
                    logs.Add(new Log
                    {
                        Message = i.ToString(),
                        Level = logLevel.ToString().ToUpper(),
                        Date = DateTime.UtcNow.AddDays(-8)
                    });
                }
            }
            repositoryMock.Setup(r => r.Query<Log>()).Returns(logs.AsQueryable());

            // Act
            LogManagementService logAdminService = new LogManagementService(
                uowMock.Object, repositoryMock.Object, settingsMock.Object);
            logAdminService.Delete(isDeleteAll);

            // Assert
            repositoryMock.Verify(r => r.Delete<Log>(It.IsAny<Log>()));
            repositoryMock.Verify(r => r.Delete<Log>(
                It.Is<Log>(l => !expectedResult.Contains(l.Message))));
            uowMock.Verify(u => u.Save());
        }
        public void Get_AnyLogIds()
        {
            // Setup dependency
            var settingsMock = new Mock<ISettings>();
            var repositoryMock = new Mock<IRepository>();
            var uowMock = new Mock<IUnitOfWork>();
            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(x => x.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);
            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);

            // Arrange
            int id = 1;

            // Act
            LogManagementService logManagementService = new LogManagementService(uowMock.Object, repositoryMock.Object,
                settingsMock.Object);
            logManagementService.Get(id);

            // Assert
            repositoryMock.Verify(repo => repo.FindById<Log>(id));
        }
        public void List_GetError_Page1()
        {
            // Setup dependency
            var settingsMock = new Mock<ISettings>();
            var repositoryMock = new Mock<IRepository>();
            var uowMock = new Mock<IUnitOfWork>();
            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(x => x.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);
            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);

            // Arrange
            decimal expectedResult = 10;
            string expectedName = "0";
            List<Log> logs = new List<Log>();
            DateTime startDate = DateTime.Now.AddYears(-1);
            DateTime endDate = DateTime.Now.AddYears(1);

            Page page = new Page
            {
                PageNumber = 1
            };
            LogLevel logLevel = LogLevel.Error;

            for (int i = 0; i < 20; i++)
            {
                logs.Add(new Log
                {
                    Message = i.ToString(),
                    Level = logLevel.ToString(),
                    Date = DateTime.Now
                });
            }
            repositoryMock.Setup(r => r.Query<Log>()).Returns(logs.AsQueryable());

            // Act
            LogManagementService logAdminService = new LogManagementService(
                uowMock.Object, repositoryMock.Object, settingsMock.Object);
            IPagedList<Log> currentResult = logAdminService.List(page, LogLevel.Error);

            // Assert
            Assert.AreEqual(expectedResult, currentResult.Count());
            Assert.AreEqual(expectedName, currentResult.First().Message);
        }
        public void Delete_NullData()
        {
            // Setup dependency
            var settingsMock = new Mock<ISettings>();
            var repositoryMock = new Mock<IRepository>();
            var uowMock = new Mock<IUnitOfWork>();
            var serviceLocatorMock = new Mock<IServiceLocator>();
            serviceLocatorMock.Setup(x => x.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);
            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);

            // Arrange
            bool isDeleteAll = false;

            // Act
            LogManagementService logAdminService = new LogManagementService(
                uowMock.Object, repositoryMock.Object, settingsMock.Object);
            logAdminService.Delete(isDeleteAll);

            // Assert
            uowMock.Verify(u => u.Save());
        }