private void OperationOnProgressChanged(object sender, OperationProgressChangedEventArgs e)
 {
     Progress = e.CurrentProgress * 100;
 }
Esempio n. 2
0
 private void OperationOnProgressChanged(object sender, OperationProgressChangedEventArgs e) =>
 UpdateProgress();
Esempio n. 3
0
        protected void FireProgressChangedEvent(double currentProgress)
        {
            var args = new OperationProgressChangedEventArgs(currentProgress);

            ProgressChanged.Raise(this, args);
        }
    public async Task TestInProgressOperation(OperationState operationState, bool isLastSuccessful)
    {
        var stateViewModelMock = new Mock <IOperationStateViewModel>();

        stateViewModelMock
        .Setup(m => m.State)
        .Returns(operationState);
        _autoMocker
        .Setup <IApplicationDispatcher>(m => m.Dispatch(It.IsAny <Action>()))
        .Callback <Action>(action => action());
        _autoMocker
        .Setup <IOperationStateViewModelFactory, IOperationStateViewModel>(m => m.Create(It.IsAny <IOperation>()))
        .Returns(stateViewModelMock.Object);

        var configuration = new OperationsStatesConfiguration
        {
            MaximumFinishedOperationsCount = 1
        };

        _autoMocker.Use(configuration);

        var viewModel = _autoMocker.CreateInstance <OperationsStatesListViewModel>();

        var state         = OperationState.InProgress;
        var operationMock = new Mock <IOperation>();

        operationMock
        .SetupGet(m => m.State)
        .Returns(() => state);
        var array      = new string[0];
        var dictionary = new Dictionary <string, string>();

        for (var i = 0; i < 5; i++)
        {
            dictionary[i.ToString()] = i.ToString();
        }
        var settings = new BinaryFileSystemOperationSettings(
            array, array,
            array, array, dictionary, array);
        var operationInfo = new OperationInfo(OperationType.Copy, settings);

        operationMock
        .SetupGet(m => m.Info)
        .Returns(operationInfo);

        Assert.False(viewModel.IsInProgress);
        Assert.Equal(0, viewModel.TotalProgress);

        var operationStartedEventArgs = new OperationStartedEventArgs(operationMock.Object);

        _autoMocker
        .GetMock <IOperationsStateService>()
        .Raise(m => m.OperationStarted += null, operationStartedEventArgs);

        Assert.NotEmpty(viewModel.ActiveOperations);
        Assert.Single(viewModel.ActiveOperations);
        Assert.Empty(viewModel.InactiveOperations);

        _autoMocker
        .Setup <IOperationsStateService, IReadOnlyList <IOperation> >(m => m.ActiveOperations)
        .Returns(new[] { operationMock.Object });

        const double progress = 0.5;
        var          args     = new OperationProgressChangedEventArgs(progress);

        operationMock
        .Setup(m => m.CurrentProgress)
        .Returns(progress);
        operationMock
        .Raise(m => m.ProgressChanged += null, args);

        Assert.NotEmpty(viewModel.ActiveOperations);
        Assert.Single(viewModel.ActiveOperations);
        Assert.Empty(viewModel.InactiveOperations);

        Assert.True(viewModel.IsInProgress);
        Assert.Equal(50, viewModel.TotalProgress);

        var taskCompletionSource = new TaskCompletionSource <bool>();

        _autoMocker
        .Setup <IApplicationDispatcher>(m => m.Dispatch(It.IsAny <Action>()))
        .Callback <Action>(action =>
        {
            action();
            taskCompletionSource.SetResult(true);
        });

        state = operationState;
        var finishedArgs = new OperationStateChangedEventArgs(state);

        operationMock
        .Raise(m => m.StateChanged += null, finishedArgs);

        var task = await Task.WhenAny(Task.Delay(1000), taskCompletionSource.Task);

        if (task != taskCompletionSource.Task)
        {
            taskCompletionSource.SetResult(false);
        }

        var result = await taskCompletionSource.Task;

        Assert.True(result);

        Assert.NotEmpty(viewModel.InactiveOperations);
        Assert.Single(viewModel.InactiveOperations);
        Assert.Empty(viewModel.ActiveOperations);
        Assert.Equal(viewModel.IsLastOperationSuccessful, isLastSuccessful);
    }