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();
        }
Ejemplo n.º 4
0
        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();
        }
        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);
        }
Ejemplo n.º 7
0
        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();
        }