Пример #1
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 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 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());
            }
        }
Пример #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();

                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);
            }
        }