public async Task When_Perform_Get_Request_To_BulkUploadForm_Return_PartialView_With_Expected_ModelData() { // Arrange const string expectedKey = "key"; const string expectedSecret = "secret"; OdsSecretConfigurationProvider.Setup(x => x.GetSecretConfiguration(It.IsAny <int>())) .Returns(Task.FromResult(new OdsSecretConfiguration { BulkUploadCredential = new BulkUploadCredential { ApiKey = expectedKey, ApiSecret = expectedSecret } })); // Act var result = (ViewResult)await SystemUnderTest.BulkLoad(); // Assert result.ShouldNotBeNull(); var model = (OdsInstanceSettingsModel)result.Model; model.ShouldNotBeNull(); model.BulkFileUploadModel.CloudOdsEnvironment.ShouldBeSameAs(_environment); model.BulkFileUploadModel.ApiKey.ShouldBe(expectedKey); model.BulkFileUploadModel.ApiSecret.ShouldBe(expectedSecret); model.BulkFileUploadModel.CredentialsSaved.ShouldBeTrue(); }
public async Task When_Perform_Post_Request_To_ResetCredentials_With_No_BulkUploadCredentials_Returns_Json_Error() { // Arrange OdsSecretConfigurationProvider.Setup(x => x.GetSecretConfiguration(It.IsAny <int>())) .Returns(Task.FromResult(new OdsSecretConfiguration())); // Act var result = (ContentResult)await SystemUnderTest.ResetCredentials(); // Assert result.Content.Contains("Missing bulk load credentials").ShouldBeTrue(); }
public async Task When_Perform_Get_Request_To_BulkUploadForm_With_Null_SecretConfig_Returns_JsonError() { // Arrange OdsSecretConfigurationProvider.Setup(x => x.GetSecretConfiguration(It.IsAny <int>())) .Returns(Task.FromResult <OdsSecretConfiguration>(null)); // Act var result = (ContentResult)await SystemUnderTest.BulkLoad(); // Assert result.ShouldNotBeNull(); result.Content.Contains("ODS secret configuration can not be null").ShouldBeTrue(); }
public async Task When_Perform_Get_Request_To_BulkUploadForm_Return_PartialView_With_Expected_Model() { // Arrange OdsSecretConfigurationProvider.Setup(x => x.GetSecretConfiguration(It.IsAny <int>())) .Returns(Task.FromResult(new OdsSecretConfiguration())); // Act var result = (ViewResult)await SystemUnderTest.Index(); // Assert result.ShouldNotBeNull(); var model = (BulkFileUploadIndexModel)result.Model; model.ShouldNotBeNull(); model.BulkFileUploadModel.ApiKey.ShouldBeEmpty(); model.BulkFileUploadModel.ApiSecret.ShouldBeEmpty(); model.BulkFileUploadModel.CredentialsSaved.ShouldBeFalse(); }
private OdsInstanceFirstTimeSetupService GetOdsInstanceFirstTimeSetupService(string encryptedSecretConfigValue, string instanceName) { var mockStringEncryptorService = new Mock <IStringEncryptorService>(); mockStringEncryptorService.Setup(x => x.Encrypt(It.IsAny <string>())).Returns(encryptedSecretConfigValue); var odsSecretConfigurationProvider = new OdsSecretConfigurationProvider(mockStringEncryptorService.Object); var mockFirstTimeSetupService = new Mock <IFirstTimeSetupService>(); var mockReportViewsSetUp = new Mock <IReportViewsSetUp>(); var mockUsersContext = new Mock <IUsersContext>(); mockFirstTimeSetupService.Setup(x => x.CreateAdminAppInAdminDatabase(It.IsAny <string>(), instanceName, It.IsAny <string>(), ApiMode.DistrictSpecific)).ReturnsAsync(new ApplicationCreateResult()); var odsInstanceFirstTimeSetupService = new OdsInstanceFirstTimeSetupService(odsSecretConfigurationProvider, mockFirstTimeSetupService.Object, mockUsersContext.Object, mockReportViewsSetUp.Object, SetupContext); return(odsInstanceFirstTimeSetupService); }
public async Task When_Perform_Post_Request_To_SaveBulkLoadCredentials_With_BulkUpload_Credentials_Return_Json_Success() { // Arrange const string expectedKey = "key"; const string expectedSecret = "secret"; var model = new SaveBulkUploadCredentialsModel { ApiKey = expectedKey, ApiSecret = expectedSecret }; OdsSecretConfigurationProvider.Setup(x => x.GetSecretConfiguration(It.IsAny <int>())) .Returns(Task.FromResult(new OdsSecretConfiguration())); // Act var result = (ContentResult)await SystemUnderTest.SaveBulkLoadCredentials(model); // Assert result.Content.Contains("Credentials successfully saved").ShouldBeTrue(); }
private OdsInstanceSettingsModel SetupBulkUpload(out FileUploadResult fileUploadResult) { const string filename = "test.xml"; var file = new Mock <HttpPostedFileBase>(); file.Setup(x => x.ContentLength).Returns(200); file.Setup(x => x.FileName).Returns("test.xml"); var model = new OdsInstanceSettingsModel { BulkFileUploadModel = new BulkFileUploadModel { BulkFiles = new List <HttpPostedFileBase> { file.Object } } }; fileUploadResult = new FileUploadResult { Directory = "directoryPath", FileNames = new[] { filename } }; InstanceContext.Id = OdsInstanceContext.Id; InstanceContext.Name = OdsInstanceContext.Name; FileUploadHandler.Setup(x => x.SaveFilesToUploadDirectory(It.IsAny <HttpPostedFileBase[]>(), It.IsAny <Func <string, string> >())) .Returns(fileUploadResult); ApiConnectionInformationProvider .Setup(x => x.GetConnectionInformationForEnvironment(CloudOdsEnvironment.Production)) .ReturnsAsync(_connectionInformation); OdsSecretConfigurationProvider.Setup(x => x.GetSecretConfiguration(It.IsAny <int>())) .Returns(Task.FromResult(OdsSecretConfig)); return(model); }
private BulkFileUploadModel SetupBulkUpload(out FileUploadResult fileUploadResult) { const string filename = "test.xml"; var file = new Mock <IFormFile>(); file.Setup(x => x.Length).Returns(200); file.Setup(x => x.FileName).Returns("test.xml"); var model = new BulkFileUploadModel { BulkFileType = InterchangeFileType.AssessmentMetadata.Value, BulkFiles = new List <IFormFile> { file.Object } }; fileUploadResult = new FileUploadResult { Directory = "directoryPath", FileNames = new[] { filename } }; InstanceContext.Id = OdsInstanceContext.Id; InstanceContext.Name = OdsInstanceContext.Name; FileUploadHandler.Setup(x => x.SaveFilesToUploadDirectory(It.IsAny <IFormFile[]>(), It.IsAny <Func <string, string> >(), WebHostingEnvironment.Object)) .Returns(fileUploadResult); ApiConnectionInformationProvider .Setup(x => x.GetConnectionInformationForEnvironment()) .ReturnsAsync(_connectionInformation); OdsSecretConfigurationProvider.Setup(x => x.GetSecretConfiguration(It.IsAny <int>())) .Returns(Task.FromResult(OdsSecretConfig)); return(model); }
public async Task When_Perform_Post_Request_To_ResetCredentials_With_Valid_OdsSecretConfig_Returns_Json_Success() { // Arrange const string expectedKey = "key"; const string expectedSecret = "secret"; var odsConfig = new OdsSecretConfiguration { BulkUploadCredential = new BulkUploadCredential { ApiKey = expectedKey, ApiSecret = expectedSecret } }; OdsSecretConfigurationProvider.Setup(x => x.GetSecretConfiguration(It.IsAny <int>())) .Returns(Task.FromResult(odsConfig)); // Act var result = (ContentResult)await SystemUnderTest.ResetCredentials(); // Assert result.Content.Contains("Credentials successfully reset").ShouldBeTrue(); }
private OdsInstanceFirstTimeSetupService GetOdsInstanceFirstTimeSetupService(string encryptedSecretConfigValue, string instanceName, AdminAppDbContext database, ApiMode apiMode) { var appSettings = new Mock <IOptions <AppSettings> >(); appSettings.Setup(x => x.Value).Returns(new AppSettings()); var options = appSettings.Object; var mockStringEncryptorService = new Mock <IStringEncryptorService>(); mockStringEncryptorService.Setup(x => x.Encrypt(It.IsAny <string>())).Returns(encryptedSecretConfigValue); var odsSecretConfigurationProvider = new OdsSecretConfigurationProvider(mockStringEncryptorService.Object, database); var mockFirstTimeSetupService = new Mock <IFirstTimeSetupService>(); var mockReportViewsSetUp = new Mock <IReportViewsSetUp>(); var mockUsersContext = new Mock <IUsersContext>(); mockFirstTimeSetupService.Setup(x => x.CreateAdminAppInAdminDatabase(It.IsAny <string>(), instanceName, It.IsAny <string>(), apiMode)).ReturnsAsync(new ApplicationCreateResult()); var odsInstanceFirstTimeSetupService = new OdsInstanceFirstTimeSetupService(odsSecretConfigurationProvider, mockFirstTimeSetupService.Object, mockUsersContext.Object, mockReportViewsSetUp.Object, database, options); return(odsInstanceFirstTimeSetupService); }