public async Task <CreatedItemDto> Handle(CreateScenarioCommand request, CancellationToken cancellationToken)
            {
                var projectEntity = await db.Projects
                                    .FirstOrDefaultAsync(p => p.Id.Equals(request.ProjectId), cancellationToken);

                EntityGuard.NullGuard(projectEntity, new EntityNotFoundException(nameof(Project), request.ProjectId));

                Feature featureEntity = null;

                if (request.FeatureId != Guid.Empty)
                {
                    featureEntity = await db.Features
                                    .FirstOrDefaultAsync(p => p.Id.Equals(request.FeatureId), cancellationToken);

                    EntityGuard.NullGuard(featureEntity, new EntityNotFoundException(nameof(Feature), request.FeatureId));
                }

                var entity = Scenario.Factory(request.Name, projectEntity, featureEntity);

                EntityGuard.NullGuard(entity, new EntityCreateFailureException(nameof(Scenario), request, "Entity Creation failed"));

                projectEntity.AddScenario(entity);

                db.Projects.Attach(projectEntity);
                await db.SaveChangesAsync(cancellationToken);

                return(new CreatedItemDto(entity.Id));
            }
예제 #2
0
            public async Task <GetTagDto> Handle(GetTagQuery request, CancellationToken cancellationToken)
            {
                var entity = await context.Tags
                             .AsNoTracking()
                             .Include(f => f.Project)
                             .Include(f => f.FeatureList)
                             .Include(f => f.ScenarioList)
                             .Where(f => f.Project.Id.Equals(request.ProjectId))
                             .Where(f => f.Id.Equals(request.Id))
                             .SingleOrDefaultAsync(cancellationToken);

                EntityGuard.NullGuard(entity, new EntityNotFoundException(nameof(Tag), request.Id));

                var dto = new GetTagDto
                {
                    Id           = entity.Id,
                    Name         = entity.Name,
                    Description  = entity.Description,
                    ProjectId    = entity.Project.Id,
                    FeatureList  = entity.FeatureList.Select(f => f.Id).ToList(),
                    ScenarioList = entity.ScenarioList.Select(s => s.Id).ToList(),
                };

                return(dto);
            }
예제 #3
0
        public void Should_Throw_Exception_When_Entity_Null()
        {
            var project = Project.Factory("test", true);

            project = null;

            Should.Throw <Exception>(() => EntityGuard.NullGuard(project, new Exception()));
        }
예제 #4
0
            public async Task <CreatedItemDto> Handle(CreateTestSuiteCommand request, CancellationToken cancellationToken)
            {
                var entity = TestSuite.Factory(request.Name, request.ProjectId);

                EntityGuard.NullGuard(entity, new EntityCreateFailureException(nameof(TestSuite), request.ProjectId, "Entity Creation failed"));

                db.TestSuites.Attach(entity);
                await db.SaveChangesAsync(cancellationToken);

                return(new CreatedItemDto(entity.Id));
            }
예제 #5
0
            public async Task <Unit> Handle(DeleteTestSuiteCommand request, CancellationToken cancellationToken)
            {
                var testSuiteEntity = await context.TestSuites
                                      .Where(t => t.ProjectId == request.ProjectId)
                                      .Where(t => t.Id == request.Id)
                                      .SingleOrDefaultAsync();

                EntityGuard.NullGuard(testSuiteEntity, new EntityNotFoundException(nameof(TestSuite), request.Id));

                context.TestSuites.Remove(testSuiteEntity);
                await context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
            public async Task <Unit> Handle(DeleteScenarioCommand request, CancellationToken cancellationToken)
            {
                var scenarioEntity = await context.Scenarios
                                     .Include(s => s.Project)
                                     .Where(t => t.Project.Id.Equals(request.ProjectId))
                                     .Where(t => t.Id.Equals(request.Id))
                                     .SingleOrDefaultAsync();

                EntityGuard.NullGuard(scenarioEntity, new EntityNotFoundException(nameof(Scenario), request.Id));

                context.Scenarios.Remove(scenarioEntity);
                await context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
            public async Task <Unit> Handle(UpdateProjectCommand request, CancellationToken cancellationToken)
            {
                var entityQuery = db.Projects;
                var query       = entityQuery.ToQueryString();

                var entity = await entityQuery.FirstOrDefaultAsync(p => p.Id.Equals(request.Id), cancellationToken);

                EntityGuard.NullGuard(entity, new EntityNotFoundException(nameof(Project), request.Id));

                entity.Update(request.Name, request.IsEnabled);

                db.Projects.Attach(entity);
                await db.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
            public async Task <GetProjectDto> Handle(GetProjectQuery request, CancellationToken cancellationToken)
            {
                var entitiy = await context.Projects
                              .AsNoTracking()
                              .FirstOrDefaultAsync(p => p.Id.Equals(request.Id), cancellationToken);

                EntityGuard.NullGuard(entitiy, new EntityNotFoundException(nameof(Project), request.Id));

                var dto = new GetProjectDto
                {
                    Id        = entitiy.Id,
                    Name      = entitiy.Name,
                    IsEnabled = entitiy.IsEnabled,
                };

                return(dto);
            }
            public async Task <CreatedItemDto> Handle(CreateTagCommand request, CancellationToken cancellationToken)
            {
                var projectEntity = await db.Projects
                                    .FirstOrDefaultAsync(p => p.Id.Equals(request.ProjectId), cancellationToken);

                EntityGuard.NullGuard(projectEntity, new EntityNotFoundException(nameof(Project), request.ProjectId));

                var entity = Tag.Factory(request.Name, projectEntity, request.Description);

                EntityGuard.NullGuard(entity, new EntityCreateFailureException(nameof(Tag), request.ProjectId, "Entity Creation failed"));

                projectEntity.Tags.Add(entity);

                db.Projects.Attach(projectEntity);
                await db.SaveChangesAsync(cancellationToken);

                return(new CreatedItemDto(entity.Id));
            }
예제 #10
0
            public async Task <Unit> Handle(UpdateScenarioResultToSuiteCommand request, CancellationToken cancellationToken)
            {
                var entityQuery = db.TestSuites
                                  .Include(s => s.ResultList)
                                  .Where(p => p.ProjectId.Equals(request.ProjectId));

                var testSuiteEntity = await entityQuery.FirstOrDefaultAsync(p => p.Id.Equals(request.TestSuiteId), cancellationToken);

                EntityGuard.NullGuard(testSuiteEntity, new EntityNotFoundException(nameof(TestSuite), request.TestSuiteId));

                var resultList = request.ScenarioResults.Select(s => new ResultSnapshot()).ToList();

                testSuiteEntity.ResultList.AddRange(resultList);

                db.TestSuites.Attach(testSuiteEntity);
                await db.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
            public async Task <GetScenarioDto> Handle(GetScenarioQuery request, CancellationToken cancellationToken)
            {
                var entityQuery = context.Scenarios
                                  .Include(s => s.Project)
                                  .Where(s => s.Project.Id == request.ProjectId);

                if (request.IncludeFeature)
                {
                    entityQuery
                    .Include(s => s.Feature);
                }

                if (request.IncludeSteps)
                {
                    entityQuery
                    .Include(s => s.StepsList);
                }

                var entity = await entityQuery.FirstOrDefaultAsync(p => p.Id.Equals(request.Id), cancellationToken);

                EntityGuard.NullGuard(entity, new EntityNotFoundException(nameof(Scenario), request.Id));

                var dto = new GetScenarioDto
                {
                    Id          = entity.Id,
                    ProjectId   = entity.Project.Id,
                    Description = entity.Description,
                };

                if (request.IncludeFeature)
                {
                    dto.FeatureId = entity.Feature.Id;
                }

                if (request.IncludeSteps)
                {
                    dto.StepList = entity.StepsList.Select(s => new GetScenarioDto.Step(s.Order, s.Description)).ToList();
                }

                return(dto);
            }
예제 #12
0
            public async Task <GetFeatureDto> Handle(GetFeatureQuery request, CancellationToken cancellationToken)
            {
                var entity = await context.Features
                             .AsNoTracking()
                             .Include(f => f.Project)
                             .Where(f => f.Project.Id.Equals(request.ProjectId))
                             .Where(f => f.Id.Equals(request.Id))
                             .SingleOrDefaultAsync(cancellationToken);

                EntityGuard.NullGuard(entity, new EntityNotFoundException(nameof(Feature), request.ProjectId));

                var dto = new GetFeatureDto
                {
                    Id          = entity.Id,
                    Name        = entity.Name,
                    Description = entity.Description,
                    ProjectId   = entity.Project.Id
                };

                return(dto);
            }
            public async Task <Unit> Handle(UpdateTagCommand request, CancellationToken cancellationToken)
            {
                var entityQuery = db.Projects;
                var query       = entityQuery.ToQueryString();

                var projectEntity = await entityQuery.FirstOrDefaultAsync(p => p.Id.Equals(request.ProjectId), cancellationToken);

                EntityGuard.NullGuard(projectEntity, new EntityNotFoundException(nameof(Project), request.ProjectId));

                var tagEntity = await db.Tags
                                .Where(t => t.Id == request.Id)
                                .SingleOrDefaultAsync();

                EntityGuard.NullGuard(tagEntity, new EntityNotFoundException(nameof(Tag), request.Id));

                tagEntity.UpdateInfo(request.Name, request.Description);

                db.Tags.Attach(tagEntity);
                await db.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
예제 #14
0
            public async Task <Unit> Handle(UpdateScenarioCommand request, CancellationToken cancellationToken)
            {
                var entityQuery = db.Scenarios
                                  .Include(s => s.Project)
                                  .Where(p => p.Project.Id.Equals(request.ProjectId));

                if (request.FeatureId == default)
                {
                    entityQuery.Include(s => s.Feature).Where(p => p.Feature.Id == request.FeatureId);
                }

                var query = entityQuery.ToQueryString();

                var scenarioEntity = await entityQuery.FirstOrDefaultAsync(p => p.Id.Equals(request.Id), cancellationToken);

                EntityGuard.NullGuard(scenarioEntity, new EntityNotFoundException(nameof(Scenario), request.Id));

                scenarioEntity.UpdateInfo(request.Description);

                db.Scenarios.Attach(scenarioEntity);
                await db.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
            public async Task <Unit> Handle(UpdateStepsToScenarioCommand request, CancellationToken cancellationToken)
            {
                var entityQuery = db.Scenarios
                                  .Include(s => s.Project)
                                  .Include(s => s.StepsList)
                                  .Where(p => p.Project.Id.Equals(request.ProjectId));

                var scenarioEntity = await entityQuery.FirstOrDefaultAsync(p => p.Id.Equals(request.ScenarioId), cancellationToken);

                EntityGuard.NullGuard(scenarioEntity, new EntityNotFoundException(nameof(Scenario), request.ScenarioId));

                var stepList = request.Steps.Select(s => new Step(s.Order, s.Description, scenarioEntity)).ToList();

                scenarioEntity.StepsList.Clear();

                await db.SaveChangesAsync(cancellationToken);

                scenarioEntity.AddSteps(stepList);

                db.Scenarios.Attach(scenarioEntity);
                await db.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }