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));
            }
        }
Example #2
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);
            }
        }
Example #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);
            }
        }
        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);
            }
        }
        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 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);
            }
        }
        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 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);
            }
        }
Example #10
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 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());
            }
        }
Example #13
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);
            }
        }
Example #14
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);
            }
        }