public void ShouldAllowBulkLoadApiKeyAssociatedWithValidApplication() { var odsInstance1 = new OdsInstance { Name = "Test Instance 1", InstanceType = "Ods", IsExtended = false, Status = "OK", Version = "1.0.0" }; var apiClientForInstance1 = SetupApplicationForInstance(odsInstance1); var bulkFileUpLoadModel = new BulkFileUploadModel { ApiKey = apiClientForInstance1.Key }; Scoped <IUsersContext>(usersContext => { var validator = new BulkFileUploadModelValidator(usersContext); var validationResults = validator.Validate(bulkFileUpLoadModel); validationResults.IsValid.ShouldBe(true); }); }
private OdsInstance RegisterOdsInstance(OdsFirstTimeSetupConfiguration configuration) { var existingInstance = _usersContext.OdsInstances.SingleOrDefault(x => x.Name == configuration.Name); if (existingInstance != null) { return(existingInstance); } var instance = new OdsInstance { InstanceType = "Cloud", IsExtended = false, Name = configuration.Name, Status = CloudOdsStatus.SetupRequired.DisplayName, Version = configuration.Version, OdsInstanceComponents = configuration.Components.Select(c => new OdsInstanceComponent { Name = $"{c.Name} ({c.Environment})", Url = c.Url, Version = c.Version }).ToList() }; _usersContext.OdsInstances.Add(instance); return(instance); }
public CloudOdsStatus Execute(string instanceName) { OdsInstance instance = null; try { instance = _usersContext.OdsInstances.SingleOrDefault(i => i.Name == instanceName); } catch (SqlException s) { //Login failed likely means we haven't yet completed initial setup //so we'll return InstanceNotRegistered below if (!s.Message.StartsWith("Login failed")) { throw; } } catch (EntityCommandExecutionException s) { //Similarly check for the corresponding exception from NpgSql var inner = s.InnerException as PostgresException; if (inner == null || !(inner.Message.Contains("relation") && inner.Message.Contains("does not exist"))) { throw; } } if (instance == null) { return(CloudOdsStatus.InstanceNotRegistered); } return(CloudOdsStatus.Parse(instance.Status)); }
public CloudOdsStatus Execute(string instanceName) { OdsInstance instance = null; try { instance = _usersContext.OdsInstances.SingleOrDefault(i => i.Name == instanceName); } catch (SqlException s) { //Login failed likely means we haven't yet completed initial setup //so we'll return InstanceNotRegistered below if (!s.Message.StartsWith("Login failed")) { throw; } } if (instance == null) { return(CloudOdsStatus.InstanceNotRegistered); } return(CloudOdsStatus.Parse(instance.Status)); }
public void ShouldNotAllowBulkLoadCredentialsFromADifferentInstance() { var odsInstance1 = new OdsInstance { Name = "Test Instance 1", InstanceType = "Ods", IsExtended = false, Status = "OK", Version = "1.0.0" }; var apiClientForInstance1 = SetupApplicationForInstance(odsInstance1); var odsInstance2 = new OdsInstance { Name = "Test Instance 2", InstanceType = "Ods", IsExtended = false, Status = "OK", Version = "1.0.0" }; SetupApplicationForInstance(odsInstance2); var saveBulkUploadCredentialsModel = new SaveBulkUploadCredentialsModel { ApiKey = apiClientForInstance1.Key, ApiSecret = apiClientForInstance1.Secret }; var instanceContext = new InstanceContext { Id = odsInstance2.OdsInstanceId, Name = odsInstance2.Name }; Scoped <IUsersContext>(usersContext => { var validator = new SaveBulkUploadCredentialsModelValidator(usersContext, instanceContext); var validationResults = validator.Validate(saveBulkUploadCredentialsModel); validationResults.IsValid.ShouldBe(false); validationResults.Errors.Select(x => x.ErrorMessage).ShouldContain("The Api Key provided is not associated with the currently selected ODS instance."); }); }
public void ShouldAllowBulkLoadCredentialsFromTheSameInstance() { var odsInstance1 = new OdsInstance { Name = "Test Instance 1", InstanceType = "Ods", IsExtended = false, Status = "OK", Version = "1.0.0" }; var apiClientForInstance1 = SetupApplicationForInstance(odsInstance1); var odsInstance2 = new OdsInstance { Name = "Test Instance 2", InstanceType = "Ods", IsExtended = false, Status = "OK", Version = "1.0.0" }; SetupApplicationForInstance(odsInstance2); var saveBulkUploadCredentialsModel = new SaveBulkUploadCredentialsModel { ApiKey = apiClientForInstance1.Key, ApiSecret = apiClientForInstance1.Secret }; var instanceContext = new InstanceContext { Id = odsInstance1.OdsInstanceId, Name = odsInstance1.Name }; Scoped <IUsersContext>(usersContext => { var validator = new SaveBulkUploadCredentialsModelValidator(usersContext, instanceContext); var validationResults = validator.Validate(saveBulkUploadCredentialsModel); validationResults.IsValid.ShouldBe(true); }); }
private OdsInstance CreateOdsInstance(string odsInstanceName, string odsInstanceVersion) { var existingInstance = UsersContext.OdsInstances.SingleOrDefault(x => x.Name == odsInstanceName); if (existingInstance != null) { return(existingInstance); } var instance = new OdsInstance { InstanceType = "CloudOds", IsExtended = false, Name = odsInstanceName, Status = CloudOdsStatus.Ok.DisplayName, Version = odsInstanceVersion }; UsersContext.OdsInstances.Add(instance); return(instance); }
public void ShouldExecute() { const string odsInstanceName = "Test Instance"; var vendor = new Vendor { VendorNamespacePrefixes = new List <VendorNamespacePrefix> { new VendorNamespacePrefix { NamespacePrefix = "http://tests.com" } }, VendorName = "Integration Tests" }; var user = new Admin.DataAccess.Models.User { Email = "*****@*****.**", FullName = "Integration Tests", Vendor = vendor }; var profile = new Profile { ProfileName = "Test Profile" }; var odsInstance = new OdsInstance { Name = odsInstanceName, InstanceType = "Ods", IsExtended = false, Status = "OK", Version = "1.0.0" }; Save(vendor, user, profile, odsInstance); var instanceContext = new InstanceContext { Id = 1, Name = odsInstanceName }; var command = new AddApplicationCommand(SetupContext, instanceContext); var newApplication = new TestApplication { Environment = CloudOdsEnvironment.Production, ApplicationName = "Test Application", ClaimSetName = "FakeClaimSet", ProfileId = profile.ProfileId, VendorId = vendor.VendorId, EducationOrganizationIds = new List <int> { 12345, 67890 } }; var result = command.Execute(newApplication); var persistedApplication = TestContext.Applications.Single(a => a.ApplicationId == result.ApplicationId); persistedApplication.ClaimSetName.ShouldBe("FakeClaimSet"); persistedApplication.Profiles.Count.ShouldBe(1); persistedApplication.Profiles.First().ProfileName.ShouldBe("Test Profile"); persistedApplication.ApplicationEducationOrganizations.Count.ShouldBe(2); persistedApplication.ApplicationEducationOrganizations.All(o => o.EducationOrganizationId == 12345 || o.EducationOrganizationId == 67890).ShouldBeTrue(); persistedApplication.Vendor.VendorId.ShouldBeGreaterThan(0); persistedApplication.Vendor.VendorId.ShouldBe(vendor.VendorId); persistedApplication.ApiClients.Count.ShouldBe(1); var apiClient = persistedApplication.ApiClients.First(); apiClient.Name.ShouldBe(CloudOdsApplicationName.GetPersistedName("Test Application", CloudOdsEnvironment.Production)); apiClient.ApplicationEducationOrganizations.All(o => o.EducationOrganizationId == 12345 || o.EducationOrganizationId == 67890).ShouldBeTrue(); apiClient.Key.ShouldBe(result.Key); apiClient.Secret.ShouldBe(result.Secret); persistedApplication.OdsInstance.ShouldNotBeNull(); persistedApplication.OdsInstance.Name.ShouldBe(odsInstanceName); }
private ApiClient SetupApplicationForInstance(OdsInstance instance) { var vendor = new Vendor { VendorNamespacePrefixes = new List <VendorNamespacePrefix> { new VendorNamespacePrefix { NamespacePrefix = "http://tests.com" } }, VendorName = "Integration Tests" }; var user = new Admin.DataAccess.Models.User { Email = "*****@*****.**", FullName = "Integration Tests", Vendor = vendor }; var profile = new Profile { ProfileName = "Test Profile" }; Save(vendor, user, profile, instance); var instanceContext = new InstanceContext { Id = instance.OdsInstanceId, Name = instance.Name }; AddApplicationResult result = null; Scoped <IUsersContext>(usersContext => { var command = new AddApplicationCommand(usersContext, instanceContext); var newApplication = new TestApplication { ApplicationName = "Test Application", ClaimSetName = "FakeClaimSet", ProfileId = profile.ProfileId, VendorId = vendor.VendorId, EducationOrganizationIds = new List <int> { 12345, 67890 } }; result = command.Execute(newApplication); }); ApiClient apiClient = null; Scoped <IUsersContext>(usersContext => { var persistedApplication = usersContext.Applications.Single(a => a.ApplicationId == result.ApplicationId); persistedApplication.ApiClients.Count.ShouldBe(1); apiClient = persistedApplication.ApiClients.First(); apiClient.Name.ShouldBe("Test Application"); apiClient.ApplicationEducationOrganizations.All(o => o.EducationOrganizationId == 12345 || o.EducationOrganizationId == 67890).ShouldBeTrue(); apiClient.Key.ShouldBe(result.Key); apiClient.Secret.ShouldBe(result.Secret); persistedApplication.OdsInstance.ShouldNotBeNull(); persistedApplication.OdsInstance.Name.ShouldBe(instance.Name); }); return(apiClient); }