Exemplo n.º 1
0
        public async Task UploadAsync(DataUploadDto dto)
        {
            var blockBlob = await GetBlockBlobReference(
                dto.ImportType.ToString().ToLowerInvariant(),
                dto.FileName, dto.ContentType, dto.UserName);

            await blockBlob.UploadFromByteArrayAsync(dto.Data, 0, dto.Data.Length);

            _logger.LogInformation($"Successfully uploaded {dto.FileName} to {dto.ImportType} folder");
        }
Exemplo n.º 2
0
        public When_Data_Import_Controller_Index_Is_Submitted_With_No_File()
        {
            _dataUploadDto = new DataUploadDto();

            var mapper = Substitute.For <IMapper>();

            _dataBlobUploadService = Substitute.For <IDataBlobUploadService>();
            _dataImportController  = new DataImportController(mapper, _dataBlobUploadService);

            var viewModel = new DataImportParametersViewModel
            {
                SelectedImportType = DataImportType.LearningAimReference
            };

            _result = _dataImportController.Index(viewModel).Result;
        }
        public When_Data_Import_Controller_Index_Is_Submitted_Successfully()
        {
            _dataUploadDto = new DataUploadDto();
            var formFile = Substitute.For <IFormFile>();

            var viewModel = new DataImportParametersViewModel
            {
                SelectedImportType = DataImportType.LearningAimReference,
                File = formFile
            };
            var mapper = Substitute.For <IMapper>();

            mapper.Map <DataUploadDto>(viewModel).Returns(_dataUploadDto);

            _dataBlobUploadService = Substitute.For <IDataBlobUploadService>();
            formFile.ContentType.Returns("application/vnd.ms-excel");

            var dataImportController = new DataImportController(mapper, _dataBlobUploadService);
            var controllerWithClaims = new ClaimsBuilder <DataImportController>(dataImportController)
                                       .AddUserName("username")
                                       .Build();

            _result = controllerWithClaims.Index(viewModel).Result;
        }
Exemplo n.º 4
0
        public When_DataImportViewModelMapper_Maps_ViewModel()
        {
            _data = new byte[] { 0x48, 0x45, 0x4C, 0x4C, 0x4F };

            var formFile = Substitute.For <IFormFile>();

            formFile.FileName.Returns(FileName);
            formFile.ContentType.Returns(FileContentType);

            formFile.CopyTo(Arg.Do <MemoryStream>(ms =>
            {
                ms.Write(_data);
                ms.Seek(0, SeekOrigin.Begin);
            }));

            var dateTimeProvider = Substitute.For <IDateTimeProvider>();

            dateTimeProvider.UtcNowString(Arg.Any <string>()).Returns(FormattedDateTimeNowUtc);

            var viewModel = new DataImportParametersViewModel
            {
                File = formFile,
                IsImportSuccessful = true,
                SelectedImportType = DataImportType.LearningAimReference
            };

            var config = new MapperConfiguration(c =>
            {
                c.AddProfile <DataImportViewModelMapper>();
                c.ConstructServicesUsing(d => new FileNameResolver(dateTimeProvider));
            });

            IMapper mapper = new Mapper(config);

            _result = mapper.Map <DataUploadDto>(viewModel);
        }