public HttpResponseMessage ValidateGroup(int groupId, int connectionId = 0) { try { var testGroup = _testGroupFactory.CreateTestGroup(groupId); Connection connection; if (connectionId == 0) { connection = _dataRepository.ConnectionRepository .GetDataByProjectId(testGroup.ProjectId) .FirstOrDefault(x => x.IsActive & x.IsDefault & x.ProjectId == testGroup.ProjectId); if (connection != null) { connection.ConnectionProvider = _dataRepository.ConnectionProviderRepository.GetDataById(connection.ConnectionProviderId) .FirstOrDefault(); connectionId = connection.ConnectionId; } } else { connection = _connectionFactory.CreateConnection(connectionId); } var proj = new ValidationProject(_dataRepository, testGroup.ProjectId); if (!proj.ValidateConnection(connectionId)) throw new Exception(ConnectionNotValid); var valTestGroup = new ValidationTestGroup(connection, testGroup); var valCollection = valTestGroup.Validate(); PersistValidationResults(valCollection, groupId, null); return Request.CreateResponse(HttpStatusCode.OK, valTestGroup); } catch (Exception ex) { return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, new HttpError(ex.Message)); } }
public HttpResponseMessage ValidateProject(int projectId, int connectionId = 0) { try { var project = _projectFactory.CreateProject(projectId); Connection connection; if (connectionId == 0) { connection = _dataRepository.ConnectionRepository .GetDataByProjectId(projectId) .FirstOrDefault(x => x.IsActive & x.IsDefault & x.ProjectId == projectId); if (connection != null) { connection.ConnectionProvider = _dataRepository.ConnectionProviderRepository.GetDataById(connection.ConnectionProviderId) .FirstOrDefault(); connectionId = connection.ConnectionId; } } else { connection = _connectionFactory.CreateConnection(connectionId); } var validationProject = new ValidationProject(_dataRepository, projectId); if (!validationProject.ValidateConnection(connectionId)) throw new Exception(ConnectionNotValid); foreach (var test in project.Tests) { validationProject.ValidationTests.Add(new ValidationTest(connection, test)); } foreach (var testGroup in project.TestGroups) { validationProject.ValidationTestGroups.Add(new ValidationTestGroup(connection, testGroup)); } var valCollection = validationProject.Validate(); PersistValidationResults(valCollection, null, projectId); return Request.CreateResponse(HttpStatusCode.OK, validationProject); } catch (Exception ex) { return Request.CreateErrorResponse( ex.Message == ConnectionNotValid ? HttpStatusCode.BadRequest : HttpStatusCode.InternalServerError, new HttpError(ex.Message)); } }
public HttpResponseMessage ValidateTest(int testId, int connectionId = 0) { var test = _testFactory.CreateTest(testId); var valProject = new ValidationProject(_dataRepository, test.ProjectId); Connection connection; if (connectionId == 0) { connection = _dataRepository.ConnectionRepository .GetDataByProjectId(test.ProjectId) .FirstOrDefault(x => x.IsActive & x.IsDefault & x.ProjectId == test.ProjectId); if (connection != null) { connection.ConnectionProvider = _dataRepository.ConnectionProviderRepository.GetDataById(connection.ConnectionProviderId) .FirstOrDefault(); connectionId = connection.ConnectionId; } } else { connection = _connectionFactory.CreateConnection(connectionId); } if (!valProject.ValidateConnection(connectionId)) throw new Exception(ConnectionNotValid); var valTest = new ValidationTest(connection, test); var valResult = new Collection<ValidationResponse> {valTest.Validate()}; PersistValidationResults(valResult, null, null); return Request.CreateResponse(HttpStatusCode.OK, valResult); }