Пример #1
0
        public async Task <IActionResult> Upload(UploadZipFileModel uploadZipFileModel)
        {
            if (ModelState.IsValid)
            {
                var result = ZipFileProcessor.Process(uploadZipFileModel.ZipFile);

                if (result.IsFailure)
                {
                    Logger.LogError(result.Error);
                    ModelState.AddModelError("ZipFile", result.Error);
                    return(View(uploadZipFileModel));
                }

                var auth = new AuthCredential
                {
                    Password = uploadZipFileModel.Password,
                    Username = uploadZipFileModel.Username
                };

                var responseMessage = await ZipContentStorageHelper.SendContent(result.Value, auth);

                if (responseMessage.IsFailure)
                {
                    Logger.LogError(responseMessage.Error, result.Value);
                    ModelState.AddModelError("ZipFile", responseMessage.Error);
                    return(View(uploadZipFileModel));
                }

                return(RedirectToAction("Success"));
            }

            return(View(uploadZipFileModel));
        }
        public async void SendContent_WithoutAuthCredential_Failed()
        {
            var zipContentStorageHelper = new ZipContentStorageHelper(MockAxSecureConfiguration.Object,
                                                                      MockAuthenticationHeaderValueProvider.Object,
                                                                      MockHttpClientFactory.Object);

            var authCredential = FakeObjectCreator.CreateAuthCredential();

            await Assert.ThrowsAsync <Exception>(() => zipContentStorageHelper.SendContent("{\"data\": {}}", null));
        }
        public async void SendContent_WithAuthorizationAndContent_Success()
        {
            var zipContentStorageHelper = new ZipContentStorageHelper(MockAxSecureConfiguration.Object,
                                                                      MockAuthenticationHeaderValueProvider.Object,
                                                                      MockHttpClientFactory.Object);

            var authCredential = FakeObjectCreator.CreateAuthCredential();

            var result = await zipContentStorageHelper.SendContent("{\"data\": {}}", authCredential);

            result.IsSuccess.Should().Be(true);
        }