public void Execute_IntegrationTest_SQLite()
        {
            string          filePath  = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");
            List <W3CEvent> logEvents = null;

            using (StreamReader logStream = new StreamReader(TestAsset.ReadTextStream(TestAsset.LogFile)))
            {
                logEvents = W3CEnumerable.FromStream(logStream).ToList();
            }

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();
                dbContext.BeginTransaction();

                // create the project first so we have one
                ProjectModel project = DataHelper.CreateProjectModel();
                DataHelper.InsertProjectModel(dbContext, project);

                // create the log file
                LogFileModel logFile = DataHelper.CreateLogFileModel(project.Id);
                DataHelper.InsertLogFileModel(dbContext, logFile);

                // create the request batch
                ICreateRequestBatchCommand createRequestBatchCommand = new CreateRequestBatchCommand(dbContext, new RequestValidator());
                createRequestBatchCommand.Execute(logFile.Id, logEvents);

                int rowCount = dbContext.ExecuteScalar <int>("SELECT COUNT(*) FROM Requests");
                Assert.AreEqual(logEvents.Count, rowCount);
            }
        }
        public void GetAll_Integration_ReturnsSortedList()
        {
            string filePath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();
                dbContext.BeginTransaction();

                IUserRepository userRepo = new UserRepository(dbContext);

                ICreateUserCommand createUserCommand = new CreateUserCommand(dbContext, new UserValidator(userRepo), new PasswordProvider());

                // create the users
                UserModel userB = DataHelper.CreateUserModel();
                userB.UserName = "******";
                createUserCommand.Execute(userB.UserName, userB.Password, userB.Role);

                UserModel userC = DataHelper.CreateUserModel();
                userC.UserName = "******";
                createUserCommand.Execute(userC.UserName, userC.Password, userC.Role);

                UserModel userA = DataHelper.CreateUserModel();
                userA.UserName = "******";
                createUserCommand.Execute(userA.UserName, userA.Password, userA.Role);

                List <UserModel> result = userRepo.GetAll().ToList();
                Assert.AreEqual(3, result.Count);
                Assert.AreEqual(userA.UserName, result[0].UserName);
                Assert.AreEqual(userB.UserName, result[1].UserName);
                Assert.AreEqual(userC.UserName, result[2].UserName);
            }
        }
Exemple #3
0
        public void Execute_IntegrationTest_SQLite()
        {
            string filePath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();
                dbContext.BeginTransaction();

                IUserRepository    userRepo          = new UserRepository(dbContext);
                ICreateUserCommand createUserCommand = new CreateUserCommand(dbContext, new UserValidator(userRepo), new PasswordProvider());
                IDeleteUserCommand deleteUserCommand = new DeleteUserCommand(dbContext);


                // create the user
                UserModel user = createUserCommand.Execute("test", Guid.NewGuid().ToString(), Roles.User);

                int rowCount = dbContext.ExecuteScalar <int>("SELECT COUNT(*) FROM Users");
                Assert.AreEqual(1, rowCount);

                //  run the delete command and check the end tables - should be 0 records
                deleteUserCommand.Execute(user.Id);

                rowCount = dbContext.ExecuteScalar <int>("SELECT COUNT(*) FROM Users");
                Assert.AreEqual(0, rowCount);
            }
        }
Exemple #4
0
        public void Execute_IntegrationTest_SQLite()
        {
            string filePath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();
                dbContext.BeginTransaction();

                IProjectValidator projectValidator = new ProjectValidator();
                IProjectRequestAggregateValidator     validator = new ProjectRequestAggregateValidator();
                ISetLogFileUnprocessedCommand         setLogFileUnprocessedCommand         = Substitute.For <ISetLogFileUnprocessedCommand>();
                ICreateProjectRequestAggregateCommand createProjectRequestAggregateCommand = new CreateProjectRequestAggregateCommand(dbContext, validator, new LogFileRepository(dbContext), setLogFileUnprocessedCommand);

                // create the project first so we have one
                ProjectModel project = DataHelper.CreateProjectModel();
                DataHelper.InsertProjectModel(dbContext, project);

                // create the request aggregate
                ProjectRequestAggregateModel projectRequestAggregate = DataHelper.CreateProjectRequestAggregateModel();
                projectRequestAggregate.ProjectId = project.Id;
                createProjectRequestAggregateCommand.Execute(projectRequestAggregate);

                Assert.Greater(projectRequestAggregate.Id, 0);

                int rowCount = dbContext.ExecuteScalar <int>("SELECT COUNT(*) FROM ProjectRequestAggregates");
                Assert.Greater(rowCount, 0);

                ProjectRequestAggregateModel savedModel = dbContext.Query <ProjectRequestAggregateModel>("SELECT * FROM ProjectRequestAggregates WHERE Id = @Id", new { Id = projectRequestAggregate.Id }).Single();
                Assert.AreEqual(projectRequestAggregate.RegularExpression, savedModel.RegularExpression);
                Assert.AreEqual(projectRequestAggregate.AggregateTarget, savedModel.AggregateTarget);
            }
        }
        public void Execute_IntegrationTest_SQLite()
        {
            string filePath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();
                dbContext.BeginTransaction();

                // create the user
                UserModel       user          = DataHelper.CreateUserModel();
                IUserRepository userRepo      = new UserRepository(dbContext);
                IUserValidator  userValidator = new UserValidator(userRepo);

                IPasswordProvider  passwordProvider  = new PasswordProvider();
                ICreateUserCommand createUserCommand = new CreateUserCommand(dbContext, userValidator, passwordProvider);
                UserModel          savedUser         = createUserCommand.Execute(user.UserName, user.Password, user.Role);

                // reset the password
                string newPassword = Guid.NewGuid().ToString();
                IUpdateUserPasswordCommand updateCommand = new UpdateUserPasswordCommand(dbContext, userRepo, passwordProvider);
                updateCommand.Execute(savedUser.UserName, newPassword);

                // now fetch it again and check the password is good
                savedUser = userRepo.GetByUserName(user.UserName);
                Assert.IsTrue(passwordProvider.CheckPassword(newPassword, savedUser.Password));
            }
        }
        public void GetById_Integration_ReturnsData()
        {
            string filePath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();
                dbContext.BeginTransaction();

                IProjectRequestAggregateRepository projectRequestAggregateRepo = new ProjectRequestAggregateRepository(dbContext);

                ICreateProjectCommand                 createProjectCommand                 = new CreateProjectCommand(dbContext, new ProjectValidator());
                ISetLogFileUnprocessedCommand         setLogFileUnprocessedCommand         = Substitute.For <ISetLogFileUnprocessedCommand>();
                ICreateProjectRequestAggregateCommand createProjectRequestAggregateCommand = new CreateProjectRequestAggregateCommand(dbContext, new ProjectRequestAggregateValidator(), new LogFileRepository(dbContext), setLogFileUnprocessedCommand);
                IDeleteProjectRequestAggregateCommand deleteProjectRequestAggregateCommand = new DeleteProjectRequestAggregateCommand(dbContext, projectRequestAggregateRepo, new LogFileRepository(dbContext), setLogFileUnprocessedCommand);

                // create the project
                ProjectModel projectA = DataHelper.CreateProjectModel();
                createProjectCommand.Execute(projectA);

                // create the request aggregate record for ProjectA
                ProjectRequestAggregateModel projectRequestAggregate = DataHelper.CreateProjectRequestAggregateModel();
                projectRequestAggregate.ProjectId = projectA.Id;
                createProjectRequestAggregateCommand.Execute(projectRequestAggregate);
                int id = projectRequestAggregate.Id;
                Assert.Greater(id, 0);

                // fetch the record
                ProjectRequestAggregateModel result = projectRequestAggregateRepo.GetById(id);
                Assert.IsNotNull(result);
                Assert.AreEqual(projectRequestAggregate.Id, id);
                Assert.AreEqual(projectRequestAggregate.RegularExpression, result.RegularExpression);
                Assert.AreEqual(projectRequestAggregate.AggregateTarget, result.AggregateTarget);
            }
        }
Exemple #7
0
        public void GetById_Integration_ReturnsData()
        {
            string filePath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();

                ILogFileRepository logFileRepo = new LogFileRepository(dbContext);

                // create the project
                ProjectModel project = DataHelper.CreateProjectModel();
                DataHelper.InsertProjectModel(dbContext, project);

                // create the log file record
                LogFileModel logFile = DataHelper.CreateLogFileModel(project.Id);
                DataHelper.InsertLogFileModel(dbContext, logFile);

                int logFileId = dbContext.ExecuteScalar <int>("select last_insert_rowid()");

                LogFileModel result = logFileRepo.GetById(logFileId);
                Assert.IsNotNull(result);
                Assert.AreEqual(logFile.FileHash, result.FileHash);
            }
        }
Exemple #8
0
        public void GetByHash_Integration_ReturnsData()
        {
            string filePath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");
            string fileHash = Guid.NewGuid().ToString();

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();

                ILogFileRepository logFileRepo = new LogFileRepository(dbContext);

                // create the project
                ProjectModel project = DataHelper.CreateProjectModel();
                DataHelper.InsertProjectModel(dbContext, project);

                // create the log file record
                LogFileModel logFile = DataHelper.CreateLogFileModel();
                logFile.ProjectId = project.Id;
                logFile.FileHash  = fileHash;
                DataHelper.InsertLogFileModel(dbContext, logFile);

                LogFileModel result = logFileRepo.GetByHash(project.Id, fileHash);
                Assert.IsNotNull(result);
                Assert.AreEqual(logFile.FileName, result.FileName);

                result = logFileRepo.GetByHash(0, fileHash);
                Assert.IsNull(result);
            }
        }
        public void GetAll_Integration_ReturnsData()
        {
            string filePath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();

                IProjectRepository projectRepo = new ProjectRepository(dbContext);

                ProjectModel projectA = DataHelper.CreateProjectModel();
                projectA.Name = "AAA";
                ProjectModel projectB = DataHelper.CreateProjectModel();
                projectB.Name = "BBB";
                ProjectModel projectC = DataHelper.CreateProjectModel();
                projectC.Name = "CCC";

                DataHelper.InsertProjectModel(dbContext, projectA);
                DataHelper.InsertProjectModel(dbContext, projectC);
                DataHelper.InsertProjectModel(dbContext, projectB);

                List <ProjectModel> projects = projectRepo.GetAll().ToList();

                Assert.AreEqual(3, projects.Count);
                Assert.AreEqual("AAA", projects[0].Name);
                Assert.AreEqual("BBB", projects[1].Name);
                Assert.AreEqual("CCC", projects[2].Name);
            }
        }
        public void Execute_IntegrationTest_SQLite()
        {
            string filePath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();
                dbContext.BeginTransaction();

                // create the user
                UserModel user = DataHelper.CreateUserModel();

                IUserRepository   userRepo         = new UserRepository(dbContext);
                IUserValidator    userValidator    = new UserValidator(userRepo);
                IPasswordProvider passwordProvider = new PasswordProvider();

                ICreateUserCommand createUserCommand = new CreateUserCommand(dbContext, userValidator, passwordProvider);
                createUserCommand.Execute(user.UserName, user.Password, user.Role);

                UserModel savedUser = userRepo.GetByUserName(user.UserName);

                Assert.IsNotNull(savedUser);
                Assert.AreEqual(user.Role, savedUser.Role);
                Assert.IsTrue(passwordProvider.CheckPassword(user.Password, savedUser.Password));
            }
        }
        public void GetByUriStemAggregate_Integration_ReturnsData()
        {
            string          filePath         = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");
            List <W3CEvent> logEvents        = null;
            string          uriStemAggregate = Guid.NewGuid().ToString();
            int             expectedCount    = new Random().Next(3, 7);

            using (StreamReader logStream = new StreamReader(TestAsset.ReadTextStream(TestAsset.LogFile)))
            {
                logEvents = W3CEnumerable.FromStream(logStream).ToList();
            }

            for (int i = 0; i < expectedCount; i++)
            {
                logEvents[i].cs_uri_stem = uriStemAggregate;
            }

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();
                dbContext.BeginTransaction();

                IRequestRepository requestRepo = new RequestRepository(dbContext);

                ICreateRequestBatchCommand createRequestBatchCommand = new CreateRequestBatchCommand(dbContext, new RequestValidator());

                // create the project
                ProjectModel project = DataHelper.CreateProjectModel();
                DataHelper.InsertProjectModel(dbContext, project);

                ProjectModel project2 = DataHelper.CreateProjectModel();
                DataHelper.InsertProjectModel(dbContext, project2);

                // create log file and request records for each
                LogFileModel logFile = DataHelper.CreateLogFileModel(project.Id);
                DataHelper.InsertLogFileModel(dbContext, logFile);
                createRequestBatchCommand.Execute(logFile.Id, logEvents);

                LogFileModel logFile2 = DataHelper.CreateLogFileModel(project2.Id);
                DataHelper.InsertLogFileModel(dbContext, logFile2);
                createRequestBatchCommand.Execute(logFile2.Id, logEvents);


                IEnumerable <RequestModel> result = requestRepo.GetByUriStemAggregate(project.Id, uriStemAggregate);
                Assert.IsNotNull(result);
                Assert.AreEqual(expectedCount, result.Count());
                foreach (RequestModel rm in result)
                {
                    Assert.AreEqual(logFile.Id, rm.LogFileId);
                }
            }
        }
        public void GetPageLoadTimes_Integration_ReturnsData()
        {
            string filePath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");

            List <W3CEvent> logEvents = new List <W3CEvent>();

            logEvents.Add(CreateW3CEvent("PageA", 17));
            logEvents.Add(CreateW3CEvent("PageA", 13));
            logEvents.Add(CreateW3CEvent("PageA", 21));
            logEvents.Add(CreateW3CEvent("PageA", 9));
            logEvents.Add(CreateW3CEvent("PageA", 40));

            logEvents.Add(CreateW3CEvent("PageB", 1000));
            logEvents.Add(CreateW3CEvent("PageB", 3000));

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();
                dbContext.BeginTransaction();

                ICreateRequestBatchCommand createRequestBatchCommand = new CreateRequestBatchCommand(dbContext, new RequestValidator());
                IRequestRepository         requestRepo = new RequestRepository(dbContext);

                // create the project
                ProjectModel project = DataHelper.CreateProjectModel();
                DataHelper.InsertProjectModel(dbContext, project);

                // create the log file record
                LogFileModel logFile = DataHelper.CreateLogFileModel(project.Id);
                DataHelper.InsertLogFileModel(dbContext, logFile);

                // create the requests
                createRequestBatchCommand.Execute(logFile.Id, logEvents);

                // update all requests so the aggregate is different to the stem
                string sql = "UPDATE Requests SET UriStemAggregate = UriStem || '__'";
                dbContext.ExecuteNonQuery(sql);

                IEnumerable <RequestPageLoadTimeModel> result = requestRepo.GetPageLoadTimes(project.Id);
                Assert.AreEqual(2, result.Count());

                RequestPageLoadTimeModel pageAResult = result.Where(x => x.UriStemAggregate == "PageA__").SingleOrDefault();
                Assert.IsNotNull(pageAResult);
                Assert.AreEqual(5, pageAResult.RequestCount);
                Assert.AreEqual(20, pageAResult.AvgTimeTakenMilliseconds);

                RequestPageLoadTimeModel pageBResult = result.Where(x => x.UriStemAggregate == "PageB__").SingleOrDefault();
                Assert.IsNotNull(pageBResult);
                Assert.AreEqual(2, pageBResult.RequestCount);
                Assert.AreEqual(2000, pageBResult.AvgTimeTakenMilliseconds);
            }
        }
Exemple #13
0
        public void Execute_IntegrationTest_SQLite()
        {
            string          filePath  = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");
            List <W3CEvent> logEvents = null;

            using (StreamReader logStream = new StreamReader(TestAsset.ReadTextStream(TestAsset.LogFile)))
            {
                logEvents = W3CEnumerable.FromStream(logStream).ToList();
            }

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();
                dbContext.BeginTransaction();

                ICreateProjectCommand      createProjectCommand      = new CreateProjectCommand(dbContext, new ProjectValidator());
                ICreateRequestBatchCommand createRequestBatchCommand = new CreateRequestBatchCommand(dbContext, new RequestValidator());
                IDeleteLogFileCommand      deleteLogFileCommand      = new DeleteLogFileCommand(dbContext);


                // create the project first so we have one
                ProjectModel project = DataHelper.CreateProjectModel();

                // create 2 the log files
                LogFileModel logFile1 = DataHelper.CreateLogFileModel(project.Id);
                DataHelper.InsertLogFileModel(dbContext, logFile1);

                LogFileModel logFile2 = DataHelper.CreateLogFileModel(project.Id);
                DataHelper.InsertLogFileModel(dbContext, logFile2);

                // create the request batch
                createRequestBatchCommand.Execute(logFile1.Id, logEvents);
                createRequestBatchCommand.Execute(logFile2.Id, logEvents);

                int rowCount = dbContext.ExecuteScalar <int>("SELECT COUNT(*) FROM Requests WHERE LogFileId = @LogFileId", new { LogFileId = logFile1.Id });
                Assert.AreEqual(logEvents.Count, rowCount);

                //  run the delete command
                deleteLogFileCommand.Execute(logFile1.Id);

                // there should be no requests for logFile1, but requests for logFile2 should still exist
                rowCount = dbContext.ExecuteScalar <int>("SELECT COUNT(*) FROM Requests WHERE LogFileId = @LogFileId", new { LogFileId = logFile1.Id });
                Assert.AreEqual(0, rowCount);
                rowCount = dbContext.ExecuteScalar <int>("SELECT COUNT(*) FROM Requests WHERE LogFileId = @LogFileId", new { LogFileId = logFile2.Id });
                Assert.AreEqual(logEvents.Count, rowCount);

                rowCount = dbContext.ExecuteScalar <int>("SELECT COUNT(*) FROM LogFiles");
                Assert.AreEqual(1, rowCount);
            }
        }
        public void GetByLogFile_Integration_ReturnsData()
        {
            string          filePath  = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");
            List <W3CEvent> logEvents = null;
            int             logFileId = 0;

            using (StreamReader logStream = new StreamReader(TestAsset.ReadTextStream(TestAsset.LogFile)))
            {
                logEvents = W3CEnumerable.FromStream(logStream).ToList().GetRange(0, 10);
            }


            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();
                dbContext.BeginTransaction();

                IRequestRepository requestRepo = new RequestRepository(dbContext);

                ICreateRequestBatchCommand createRequestBatchCommand = new CreateRequestBatchCommand(dbContext, new RequestValidator());

                // create the project
                ProjectModel project = DataHelper.CreateProjectModel();
                DataHelper.InsertProjectModel(dbContext, project);

                // create multiple log file records
                for (var i = 0; i < 3; i++)
                {
                    LogFileModel logFile = DataHelper.CreateLogFileModel(project.Id);
                    DataHelper.InsertLogFileModel(dbContext, logFile);

                    createRequestBatchCommand.Execute(logFile.Id, logEvents);

                    if (logFileId == 0)
                    {
                        logFileId = logFile.Id;
                    }
                }


                IEnumerable <RequestModel> result = requestRepo.GetByLogFile(logFileId);
                Assert.IsNotNull(result);
                Assert.AreEqual(logEvents.Count, result.Count());
            }
        }
        public void GetUnprocessedLogFileCount_Integration_ReturnsValidCount()
        {
            string filePath       = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");
            int    processedCount = new Random().Next(0, 5);

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();

                IProjectRepository projectRepo = new ProjectRepository(dbContext);

                ProjectModel project = DataHelper.CreateProjectModel();
                DataHelper.InsertProjectModel(dbContext, project);

                ProjectModel project2 = DataHelper.CreateProjectModel();
                DataHelper.InsertProjectModel(dbContext, project2);

                // create records
                const string sql = @"INSERT INTO LogFiles (ProjectId, FileName, FileHash, CreateDate, FileLength, RecordCount, Status) VALUES (@ProjectId, @FileName, @FileHash, @CreateDate, @FileLength, @RecordCount, @Status)";

                // create two processing record - this should be included
                LogFileModel logFile = DataHelper.CreateLogFileModel(project.Id);
                logFile.Status = LogFileStatus.Processing;
                dbContext.ExecuteNonQuery(sql, logFile);

                // create a processing record - this should be included
                logFile        = DataHelper.CreateLogFileModel(project.Id);
                logFile.Status = LogFileStatus.Processing;
                dbContext.ExecuteNonQuery(sql, logFile);

                // create an error records - this should not be included
                logFile        = DataHelper.CreateLogFileModel(project.Id);
                logFile.Status = LogFileStatus.Error;
                dbContext.ExecuteNonQuery(sql, logFile);

                // create a pending record for another project - this should also not be included
                logFile        = DataHelper.CreateLogFileModel(project2.Id);
                logFile.Status = LogFileStatus.Processing;
                dbContext.ExecuteNonQuery(sql, logFile);

                int result = projectRepo.GetUnprocessedLogFileCount(project.Id);
                Assert.AreEqual(2, result);
            }
        }
        public void Execute_IntegrationTest_SQLite()
        {
            string          filePath   = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");
            List <W3CEvent> logEvents1 = null;
            List <W3CEvent> logEvents2 = new List <W3CEvent>();

            using (StreamReader logStream = new StreamReader(TestAsset.ReadTextStream(TestAsset.LogFile)))
            {
                logEvents1 = W3CEnumerable.FromStream(logStream).ToList();
                logEvents2.AddRange(logEvents1.GetRange(0, 10));
            }

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();

                ISetLogFileUnprocessedCommand setLogFileUnprocessedCommand = new SetLogFileUnprocessedCommand(dbContext, _jobRegistrationService);

                // create the project first so we have one
                ProjectModel project = DataHelper.CreateProjectModel();
                DataHelper.InsertProjectModel(dbContext, project);

                // create the log files
                LogFileModel logFile1 = DataHelper.CreateLogFileModel(project.Id);
                logFile1.Status = LogFileStatus.Complete;
                DataHelper.InsertLogFileModel(dbContext, logFile1);

                LogFileModel logFile2 = DataHelper.CreateLogFileModel(project.Id);
                logFile2.Status = LogFileStatus.Complete;
                DataHelper.InsertLogFileModel(dbContext, logFile2);


                // check that the log file is processed
                int processedCount = dbContext.ExecuteScalar <int>("SELECT COUNT(*) FROM LogFiles WHERE ProjectId = @ProjectId AND Status = @Status", new { ProjectId = project.Id, Status = LogFileStatus.Complete });
                Assert.AreEqual(2, processedCount);

                // execute for a single log file
                setLogFileUnprocessedCommand.Execute(logFile1.Id);

                processedCount = dbContext.ExecuteScalar <int>("SELECT COUNT(*) FROM LogFiles WHERE ProjectId = @ProjectId AND Status = @Status", new { ProjectId = project.Id, Status = LogFileStatus.Processing });
                Assert.AreEqual(1, processedCount);
            }
        }
        public void GetByProject_Integration_ReturnsData()
        {
            string filePath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();
                dbContext.BeginTransaction();

                IProjectRequestAggregateRepository projectRequestAggregateRepo = new ProjectRequestAggregateRepository(dbContext);

                ISetLogFileUnprocessedCommand         setLogFileUnprocessedCommand   = Substitute.For <ISetLogFileUnprocessedCommand>();
                ICreateProjectRequestAggregateCommand projectRequestAggregateCommand = new CreateProjectRequestAggregateCommand(dbContext, new ProjectRequestAggregateValidator(), new LogFileRepository(dbContext), setLogFileUnprocessedCommand);

                // create the projects
                ProjectModel projectA = DataHelper.CreateProjectModel();
                DataHelper.InsertProjectModel(dbContext, projectA);
                ProjectModel projectZ = DataHelper.CreateProjectModel();
                DataHelper.InsertProjectModel(dbContext, projectZ);

                // create the request aggregate records for ProjectA
                int numRecords = new Random().Next(5, 10);
                for (var i = 0; i < numRecords; i++)
                {
                    ProjectRequestAggregateModel projectRequestAggregate = DataHelper.CreateProjectRequestAggregateModel();
                    projectRequestAggregate.ProjectId = projectA.Id;
                    projectRequestAggregateCommand.Execute(projectRequestAggregate);
                }

                // create the log file records for ProjectB that should be excluded by the query
                for (var i = 0; i < 5; i++)
                {
                    ProjectRequestAggregateModel projectRequestAggregate = DataHelper.CreateProjectRequestAggregateModel();
                    projectRequestAggregate.ProjectId = projectZ.Id;
                    projectRequestAggregateCommand.Execute(projectRequestAggregate);
                }


                IEnumerable <ProjectRequestAggregateModel> result = projectRequestAggregateRepo.GetByProject(projectA.Id);
                Assert.IsNotNull(result);
                Assert.AreEqual(numRecords, result.Count());
            }
        }
Exemple #18
0
        public void GetByProject_Integration_ReturnsData()
        {
            string filePath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();

                ILogFileRepository logFileRepo = new LogFileRepository(dbContext);

                // create the projects
                ProjectModel projectA = DataHelper.CreateProjectModel();
                DataHelper.InsertProjectModel(dbContext, projectA);
                ProjectModel projectZ = DataHelper.CreateProjectModel();
                DataHelper.InsertProjectModel(dbContext, projectZ);

                // create the log file records for ProjectA, as well as some for a different project
                int numRecords = new Random().Next(5, 10);
                for (var i = 0; i < numRecords; i++)
                {
                    LogFileModel logFile = DataHelper.CreateLogFileModel();
                    logFile.ProjectId = projectA.Id;
                    logFile.FileName  = "ProjectA_" + i.ToString();
                    DataHelper.InsertLogFileModel(dbContext, logFile);
                }

                // create the log file records for ProjectB that should be excluded by the query
                for (var i = 0; i < 5; i++)
                {
                    LogFileModel logFile = DataHelper.CreateLogFileModel();
                    logFile.ProjectId = projectZ.Id;
                    logFile.FileName  = "ProjectZ_" + i.ToString();
                    DataHelper.InsertLogFileModel(dbContext, logFile);
                }


                IEnumerable <LogFileModel> result = logFileRepo.GetByProject(projectA.Id);
                Assert.IsNotNull(result);
                Assert.AreEqual(numRecords, result.Count());
                Assert.AreEqual(numRecords, result.Select(x => x.FileName.StartsWith("ProjectA_")).Count());
            }
        }
Exemple #19
0
        public void Execute_IntegrationTest_SQLite()
        {
            string dbPath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");

            using (SQLiteDbContext dbContext = new SQLiteDbContext(dbPath))
            {
                dbContext.Initialise();
                dbContext.BeginTransaction();

                // create the project first so we have one
                ProjectModel       project          = DataHelper.CreateProjectModel();
                IProjectValidator  projectValidator = new ProjectValidator();
                ILogFileRepository logFileRepo      = new LogFileRepository(dbContext);

                int        projectId  = new Random().Next(1, 1000);
                string     filePath   = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".log");
                FileDetail fileDetail = new FileDetail();
                fileDetail.Length = new Random().Next(1000, 10000);
                fileDetail.Hash   = Guid.NewGuid().ToString();
                fileDetail.Name   = Guid.NewGuid().ToString();
                _fileUtils.GetFileHash(filePath).Returns(fileDetail);

                DataHelper.InsertProjectModel(dbContext, project);

                // create the log file
                LogFileModel logFile = DataHelper.CreateLogFileModel();
                logFile.ProjectId = project.Id;
                ILogFileValidator     logFileValidator     = new LogFileValidator();
                ICreateLogFileCommand createLogFileCommand = new CreateLogFileCommand(dbContext, logFileValidator, logFileRepo, _jobRegistrationService, _fileUtils);
                LogFileModel          savedLogFile         = createLogFileCommand.Execute(project.Id, filePath);

                Assert.Greater(savedLogFile.Id, 0);

                int rowCount = dbContext.ExecuteScalar <int>("SELECT COUNT(*) FROM LogFiles");
                Assert.Greater(rowCount, 0);

                string fileName = dbContext.ExecuteScalar <string>("SELECT FileName FROM LogFiles WHERE Id = @Id", savedLogFile);
                Assert.AreEqual(savedLogFile.FileName, fileName);
                Assert.AreEqual(LogFileStatus.Processing, savedLogFile.Status);
            }
        }
        public void GetById_Integration_ReturnsData()
        {
            string filePath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();

                IProjectRepository projectRepo = new ProjectRepository(dbContext);

                ProjectModel project = DataHelper.CreateProjectModel();

                DataHelper.InsertProjectModel(dbContext, project);

                ProjectModel result = projectRepo.GetById(project.Id);
                Assert.IsNotNull(result);
                Assert.AreEqual(project.Name, result.Name);

                result = projectRepo.GetById(project.Id + 1);
                Assert.IsNull(result);
            }
        }
Exemple #21
0
        public void Execute_IntegrationTest_SQLite()
        {
            string filePath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();
                dbContext.BeginTransaction();

                IProjectRequestAggregateRepository projectRequestAggregateRepo = new ProjectRequestAggregateRepository(dbContext);

                ISetLogFileUnprocessedCommand         setLogFileUnprocessedCommand         = Substitute.For <ISetLogFileUnprocessedCommand>();
                ICreateProjectRequestAggregateCommand createProjectRequestAggregateCommand = new CreateProjectRequestAggregateCommand(dbContext, new ProjectRequestAggregateValidator(), new LogFileRepository(dbContext), setLogFileUnprocessedCommand);
                IDeleteProjectRequestAggregateCommand deleteProjectRequestAggregateCommand = new DeleteProjectRequestAggregateCommand(dbContext, projectRequestAggregateRepo, new LogFileRepository(dbContext), setLogFileUnprocessedCommand);

                // create the project first so we have one
                ProjectModel project = DataHelper.CreateProjectModel();
                DataHelper.InsertProjectModel(dbContext, project);

                // create the request aggregate
                ProjectRequestAggregateModel projectRequestAggregate = DataHelper.CreateProjectRequestAggregateModel();
                projectRequestAggregate.ProjectId = project.Id;
                createProjectRequestAggregateCommand.Execute(projectRequestAggregate);
                int id = projectRequestAggregate.Id;
                Assert.Greater(id, 0);

                // fetch the record to make sure it exists
                ProjectRequestAggregateModel record = projectRequestAggregateRepo.GetById(id);
                Assert.IsNotNull(record);

                // delete the request aggregate
                deleteProjectRequestAggregateCommand.Execute(id);

                record = projectRequestAggregateRepo.GetById(id);
                Assert.IsNull(record);
            }
        }
        public void GetByUserName_Integration_ReturnsData()
        {
            string filePath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");
            string userName = Path.GetRandomFileName();

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();
                dbContext.BeginTransaction();

                IUserRepository userRepo = new UserRepository(dbContext);

                ICreateUserCommand createUserCommand = new CreateUserCommand(dbContext, new UserValidator(userRepo), new PasswordProvider());

                // create the user
                UserModel user = DataHelper.CreateUserModel();
                user.UserName = userName;
                createUserCommand.Execute(user.UserName, user.Password, user.Role);

                UserModel result = userRepo.GetByUserName(userName);
                Assert.IsNotNull(result);
                Assert.AreEqual(userName, result.UserName);
            }
        }
        public void Execute_IntegrationTest_SQLite()
        {
            string filePath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName() + ".dbtest");

            using (SQLiteDbContext dbContext = new SQLiteDbContext(filePath))
            {
                dbContext.Initialise();
                dbContext.BeginTransaction();

                ProjectModel project = DataHelper.CreateProjectModel();

                IProjectValidator     projectValidator     = new ProjectValidator();
                ICreateProjectCommand createProjectCommand = new CreateProjectCommand(dbContext, projectValidator);
                ProjectModel          savedProject         = createProjectCommand.Execute(project);

                Assert.Greater(savedProject.Id, 0);

                int rowCount = dbContext.ExecuteScalar <int>("SELECT COUNT(*) FROM Projects");
                Assert.Greater(rowCount, 0);

                string projectName = dbContext.ExecuteScalar <string>("SELECT Name FROM projects WHERE Id = @Id", savedProject);
                Assert.AreEqual(savedProject.Name, projectName);
            }
        }
Exemple #24
0
 public void Initialise_CreatesDatabaseFile()
 {
     _dbContext.Initialise();
     Assert.IsTrue(File.Exists(_filePath));
 }