Exemplo n.º 1
0
        public void OnUploadCanceled()
        {
            // arrange
            var vm = new FieldFileViewModel();

            var fileProcess = Mock.Create<IFileProcess>(Behavior.Loose);
            fileProcess.IsUploading = true;
            Mock.NonPublic.Arrange<IFileProcess>(vm, "CurrentFileProcess").Returns(fileProcess);

            var privateAccessor = new PrivateAccessor(vm);
            privateAccessor.SetField("_stopExecuteUploadCanceledEvent", true);

            // act
            vm.OnUploadCanceled(null, null);

            // assert
            Assert.IsTrue(fileProcess.IsUploading);

            // arrange
            privateAccessor.SetField("_stopExecuteUploadCanceledEvent", false);

            var beginCancelUploadingCalled = false;
            Mock.Arrange(() => fileProcess.BeginCancelUploading(Arg.IsAny<Action<object, IDataPortalResult>>()))
                .DoInstead(() => beginCancelUploadingCalled = true);

            // act
            vm.OnUploadCanceled(null, null);

            // assert
            Assert.IsFalse(fileProcess.IsUploading);
            Assert.IsTrue(beginCancelUploadingCalled);
            Assert.AreEqual(FileControlMode.Upload, vm.CurrentState);
        }