public async Task BulkShouldNotRegisterOneOdsInstancePreviouslyRegistered() { ResetOdsInstanceRegistrations(); const string instanceName = "23456"; const string description = "Test Description"; const string encryptedSecretConfigValue = "Encrypted string"; await using var connection = GetDatabaseConnection(instanceName); await using var connection2 = GetDatabaseConnection(instanceName); await using var connection3 = GetDatabaseConnection(instanceName); await using var connection4 = GetDatabaseConnection(instanceName); await using var connection5 = GetDatabaseConnection(instanceName); _connectionProvider .SetupSequence(x => x.CreateNewConnection(23456, ApiMode.DistrictSpecific)) .Returns(connection) .Returns(connection2) .Returns(connection3) .Returns(connection4) .Returns(connection5); var testUsername = UserTestSetup.SetupUsers(1).Single().Id; var odsInstancesToRegister = new List <RegisterOdsInstanceModel>(); var repeatedInstance = new RegisterOdsInstanceModel { NumericSuffix = 23456, Description = description }; odsInstancesToRegister.Add(repeatedInstance); var newInstances = await ScopedAsync <AdminAppIdentityDbContext, IEnumerable <BulkRegisterOdsInstancesResult> >(async identity => { return(await ScopedAsync <AdminAppDbContext, IEnumerable <BulkRegisterOdsInstancesResult> >(async database => { var odsInstanceFirstTimeSetupService = GetOdsInstanceFirstTimeSetupService(encryptedSecretConfigValue, instanceName, database); var inferInstanceService = new InferInstanceService(_connectionProvider.Object); var registerOdsInstanceCommand = new RegisterOdsInstanceCommand(odsInstanceFirstTimeSetupService, identity, _setCurrentSchoolYear, inferInstanceService); var command = new BulkRegisterOdsInstancesCommand(registerOdsInstanceCommand, _dataFiltrationService.Object); return await command.Execute(odsInstancesToRegister, new List <RegisterOdsInstanceModel>(), ApiMode.DistrictSpecific, testUsername, new CloudOdsClaimSet()); })); }); var newInstance = newInstances.FirstOrDefault(); newInstance.ShouldNotBeNull(); newInstance.NumericSuffix.ShouldBe(repeatedInstance.NumericSuffix.ToString()); newInstance.Description.ShouldBe(repeatedInstance.Description); newInstance.OdsInstanceRegisteredId.ShouldBe(0); newInstance.IndividualInstanceResult.ShouldBe(IndividualInstanceResult.Skipped); }
public async Task <ActionResult> BulkRegisterOdsInstances(BulkRegisterOdsInstancesModel model) { var currentUserId = User.Identity.GetUserId(); var results = await _bulkRegisterOdsInstancesCommand.Execute( model.OdsInstancesFile.DataRecords(), CloudOdsAdminAppSettings.Instance.Mode, currentUserId, CloudOdsAdminAppClaimSetConfiguration.Default); var bulkRegisterOdsInstancesResults = results.ToList(); var successCount = bulkRegisterOdsInstancesResults.Count(x => x.Success); var failCount = bulkRegisterOdsInstancesResults.Count(x => !x.Success); return(JsonSuccess( $"Successful instance registrations: {successCount}. Failed instance registrations: {failCount}. Please refer log file for further details.")); }
public async Task <ActionResult> BulkRegisterOdsInstances(BulkRegisterOdsInstancesModel model) { var currentUserId = User.FindFirstValue(ClaimTypes.NameIdentifier); var results = await _bulkRegisterOdsInstancesCommand.Execute( model.DataRecords(), model.FilteredDataRecords, CloudOdsAdminAppSettings.Instance.Mode, currentUserId, CloudOdsAdminAppClaimSetConfiguration.Default); var bulkRegisterOdsInstancesResults = results.ToList(); var successCount = bulkRegisterOdsInstancesResults.Count(x => x.IndividualInstanceResult == IndividualInstanceResult.Succeded); var failCount = bulkRegisterOdsInstancesResults.Count(x => x.IndividualInstanceResult == IndividualInstanceResult.Failed); var skippedCount = bulkRegisterOdsInstancesResults.Count(x => x.IndividualInstanceResult == IndividualInstanceResult.Skipped); return(JsonSuccess( $"Successful instance registrations: {successCount}. Failed instance registrations: {failCount}. Skipped instance registrations: {skippedCount}. Please refer to log file for further details.")); }
public async Task ShouldRegisterOneNewOdsInstanceInBulk() { ResetOdsInstanceRegistrations(); const string instanceName = "23456"; const string description = "Test Description"; const string encryptedSecretConfigValue = "Encrypted string"; await using (var connection = GetDatabaseConnection(instanceName, "EdFi_Ods_")) { _connectionProvider.Setup(x => x.CreateNewConnection(23456, ApiMode.DistrictSpecific)) .Returns(connection); var odsInstancesToRegister = new List <RegisterOdsInstanceModel>(); var newInstance1 = new RegisterOdsInstanceModel { NumericSuffix = 23456, Description = description }; odsInstancesToRegister.Add(newInstance1); var testUsername = UserTestSetup.SetupUsers(1).Single().Id; var newInstances = await ScopedAsync <AdminAppIdentityDbContext, IEnumerable <BulkRegisterOdsInstancesResult> >(async identity => { return(await ScopedAsync <AdminAppDbContext, IEnumerable <BulkRegisterOdsInstancesResult> >(async database => { var odsInstanceFirstTimeSetupService = GetOdsInstanceFirstTimeSetupService(encryptedSecretConfigValue, instanceName, database); var inferInstanceService = new InferInstanceService(_connectionProvider.Object); var registerOdsInstanceCommand = new RegisterOdsInstanceCommand(odsInstanceFirstTimeSetupService, identity, _setCurrentSchoolYear, inferInstanceService); var command = new BulkRegisterOdsInstancesCommand(registerOdsInstanceCommand, _dataFiltrationService.Object); return await command.Execute(odsInstancesToRegister, odsInstancesToRegister, ApiMode.DistrictSpecific, testUsername, new CloudOdsClaimSet()); })); }); var addedInstance = Query <OdsInstanceRegistration>(newInstances.FirstOrDefault().OdsInstanceRegisteredId); var secretConfiguration = Transaction(database => database.SecretConfigurations.FirstOrDefault(x => x.OdsInstanceRegistrationId == newInstances.FirstOrDefault().OdsInstanceRegisteredId)); secretConfiguration.ShouldNotBeNull(); secretConfiguration.EncryptedData.ShouldBe(encryptedSecretConfigValue); addedInstance.Name.ShouldBe(instanceName); addedInstance.Description.ShouldBe(newInstance1.Description); addedInstance.DatabaseName.ShouldBe($"EdFi_Ods_{instanceName}"); } }