public async Task Upload_photo_to_server_and_verify_progress()
        {
            var uploadServer     = SubstituresForVkApi.PhotosGetWallUploadSever();
            var saveWallPhoto    = SubstituresForVkApi.PhotosSaveWallPhoto();
            var ct               = CancellationToken.None;
            var photo            = new byte[1024 * 1];
            var contentToRecieve = new byte[1024 * 2];

            contentToRecieve[233] = byte.MaxValue;
            contentToRecieve[510] = byte.MaxValue;
            var progress = new Progress <HttpProgressEventArgs>();

            bool progressReportEverCalled = false;
            int  progressPercentage       = 0;

            progress.ProgressChanged += (sender, i) => {
                progressReportEverCalled = true;
                progressPercentage       = i.ProgressPercentage;
            };

            var fakeMessagehandler = new FakeResponseHandler();

            fakeMessagehandler.AddFakeResponse(new Uri("http://upload.uri/"),
                                               new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(contentToRecieve)
            });

            var uploader = new VkUploader(uploadServer, saveWallPhoto, fakeMessagehandler);

            var info = await uploader.TryUploadPhotoToWallAsync(photo, -1, progress, ct);

            Assert.That(info.Successful, Is.True);
            Assert.That(info.Photo?.Photo1280, Is.EqualTo(FakeResponsesForVkApi.ForPhotosSaveWallPhoto().Content[0]?.Photo1280));
            //Assert.That(progressReportEverCalled, Is.True);
            //Assert.That(progressPercentage, Is.EqualTo(100));
        }
示例#2
0
        public UploaderViewModel(IEventAggregator eventAggregator, VkUploader uploader, UploadSettings uploadSettings,
                                 VkApiProvider vkApi, PullersController pullersController)
        {
            _eventAggregator   = eventAggregator;
            _uploader          = uploader;
            _uploadSettings    = uploadSettings;
            _vkApi             = vkApi;
            _pullersController = pullersController;
            MissingDates       = new List <int>();

            _pullersController.Postponed.PullInvoked       += onPostponedPullInvoked;
            _pullersController.Postponed.PullCompleted     += onPostponedPullCompleted;
            _pullersController.Postponed.WallHolderChanged += onPostponedWallHolderChanged;

            _shrinkAfterPublish = _uploadSettings.CloseUploadWindowAfterPublish;
            _signedPost         = _uploadSettings.SignedPosting;
            _postFromGroup      = _uploadSettings.PostFromGroup;

            Attachments = new ObservableCollection <AttachmentItem>();

            _cts = new CancellationTokenSource();

            CancelCommand = new DelegateCommand(() => {
                _cts.Cancel();
            }, () => IsShowing)
                            .ObservesProperty(() => IsShowing);

            ShowHideCommand = new DelegateCommand(() => {
                IsShowing = !IsShowing;
            });

            PublishCommand = DelegateCommand.FromAsyncHandler(publishExecute,
                                                              () => IsEnabled && IsShowing && !IsBusy && (!string.IsNullOrWhiteSpace(Message) || Attachments.Any()))
                             .ObservesProperty(() => IsShowing)
                             .ObservesProperty(() => IsBusy)
                             .ObservesProperty(() => Message)
                             .ObservesProperty(() => Attachments)
                             .ObservesProperty(() => IsEnabled);

            BrowseCommand = DelegateCommand.FromAsyncHandler(browseExecute, () => IsShowing)
                            .ObservesProperty(() => IsShowing);

            MovePreviousCommand = new DelegateCommand(moveToPreviousMissing);
            MoveNextCommand     = new DelegateCommand(moveToNextMissing);

            //_eventAggregator.GetEvent<MainBottomEvents.Refresh>().Subscribe(async () => {
            //   if (IsBusy || !IsEnabled) return;
            //   IsBusy = true;
            //   ProgressString = "Pull...";
            //   try {
            //      await _wallContainer.PullWithScheduleHightlightAsync(new MissingPostFilter(), new Schedule());
            //   }
            //   finally {
            //      IsBusy = false;
            //      ProgressString = "";
            //   }
            //});

            _eventAggregator.GetEvent <UploaderEvents.SetVisibility>().Subscribe(onSetVisibility);
            _eventAggregator.GetEvent <UploaderEvents.Configure>().Subscribe(onConfigure);
        }