public void TransferDirectoryDifferentSizeObject()
        {
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo("rootfolder");

            DMLibDataHelper.AddMultipleFilesNormalSize(sourceDataInfo.RootNode, BVT.UnicodeFileName);

            var options = new TestExecutionOptions<DMLibDataInfo>()
            {
                IsDirectoryTransfer = true,
                TransferItemModifier = (notUsed, item) =>
                {
                    dynamic transferOptions = DefaultTransferDirectoryOptions;
                    transferOptions.Recursive = true;
                    item.Options = transferOptions;
                },
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            // For sync copy, recalculate md5 of destination by downloading the file to local.
            if (IsCloudService(DMLibTestContext.DestType) && !DMLibTestContext.IsAsync)
            {
                DMLibDataHelper.SetCalculatedFileMD5(result.DataInfo, DestAdaptor);
            }

            Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown.");
            Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, result.DataInfo), "Verify transfer result.");
        }
 protected internal override TestResult RunImpl(ITestCommand rootTestCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)
 {
     using (progressMonitor.BeginTask("Running tests.", rootTestCommand.TestCount))
     {
         return RunTest(rootTestCommand, parentTestStep, options, progressMonitor);
     }
 }
        public void TestDirectorySetContentType()
        {
            string contentType = "contenttype";
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            int[] fileSizes = new int[] {1024, 1024, 1024 };
            DMLibDataHelper.AddMultipleFilesDifferentSize(sourceDataInfo.RootNode, DMLibTestBase.FileName, fileSizes);

            var options = new TestExecutionOptions<DMLibDataInfo>();
            options.IsDirectoryTransfer = true;
            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                dynamic uploadOptions = DefaultTransferDirectoryOptions;
                uploadOptions.ContentType = "contenttype";

                transferItem.Options = uploadOptions;
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown.");
            Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, result.DataInfo), "Verify transfer result.");

            foreach (FileNode destFileNode in result.DataInfo.RootNode.FileNodes)
            {
                Test.Assert(contentType.Equals(destFileNode.ContentType), "Verify content type: {0}, expected {1}", destFileNode.ContentType, contentType);
            }
        }
        /// <summary>
        /// Runs the tests.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method can be called at most once during the lifetime of a test controller.
        /// </para>
        /// </remarks>
        /// <param name="rootTestCommand">The root test monitor.</param>
        /// <param name="parentTestStep">The parent test step, or null if starting a root step.</param>
        /// <param name="options">The test execution options.</param>
        /// <param name="progressMonitor">The progress monitor.</param>
        /// <returns>The combined result of the root test command.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="rootTestCommand"/>
        /// <paramref name="progressMonitor"/>, or <paramref name="options"/> is null.</exception>
        public TestResult Run(ITestCommand rootTestCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)
        {
            if (rootTestCommand == null)
                throw new ArgumentNullException("rootTestCommand");
            if (progressMonitor == null)
                throw new ArgumentNullException("progressMonitor");
            if (options == null)
                throw new ArgumentNullException("options");

            return RunImpl(rootTestCommand, parentTestStep, options, progressMonitor);
        }
        private TestResult RunTest(ITestCommand testCommand, TestStep parentTestStep,
            TestExecutionOptions options, IProgressMonitor progressMonitor)
        {
            // NOTE: This method has been optimized to minimize the total stack depth of the action
            //       by inlining blocks on the critical path that had previously been factored out.

            using (TestController testController = testControllerProvider(testCommand.Test))
            {
                if (testController != null)
                {
                    try
                    {
                        using (IProgressMonitor subProgressMonitor = progressMonitor.CreateSubProgressMonitor(testCommand.TestCount))
                        {
                            // Calling RunImpl directly instead of Run to minimize stack depth
                            // because we already know the arguments are valid.
                            return testController.RunImpl(testCommand, parentTestStep, options, subProgressMonitor);
                        }
                    }
                    catch (Exception ex)
                    {
                        ITestContext context = testCommand.StartPrimaryChildStep(parentTestStep);
                        context.LogWriter.Failures.WriteException(ex, "Fatal Exception in test controller");
                        return context.FinishStep(TestOutcome.Error, null);
                    }
                }
            }

            // Enter the scope of the test and recurse until we find a controller.
            progressMonitor.SetStatus(testCommand.Test.FullName);

            ITestContext testContext = testCommand.StartPrimaryChildStep(parentTestStep);
            TestOutcome outcome = TestOutcome.Passed;

            foreach (ITestCommand monitor in testCommand.Children)
            {
                if (progressMonitor.IsCanceled)
                    break;

                TestResult childResult = RunTest(monitor, testContext.TestStep, options, progressMonitor);
                outcome = outcome.CombineWith(childResult.Outcome).Generalize();
            }

            if (progressMonitor.IsCanceled)
                outcome = TestOutcome.Canceled;

            TestResult result = testContext.FinishStep(outcome, null);

            progressMonitor.Worked(1);
            return result;
        }
        public void TestCheckContentMD5()
        {
            long fileSize = 10 * 1024 * 1024;
            string wrongMD5 = "wrongMD5";

            string checkWrongMD5File = "checkWrongMD5File";
            string notCheckWrongMD5File = "notCheckWrongMD5File";
            string checkCorrectMD5File = "checkCorrectMD5File";
            string notCheckCorrectMD5File = "notCheckCorrectMD5File";

            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, checkWrongMD5File, fileSize);
            FileNode tmpFileNode = sourceDataInfo.RootNode.GetFileNode(checkWrongMD5File);
            tmpFileNode.MD5 = wrongMD5;

            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, notCheckWrongMD5File, fileSize);
            tmpFileNode = sourceDataInfo.RootNode.GetFileNode(notCheckWrongMD5File);
            tmpFileNode.MD5 = wrongMD5;

            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, checkCorrectMD5File, fileSize);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, notCheckCorrectMD5File, fileSize);

            var options = new TestExecutionOptions<DMLibDataInfo>();
            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                string fileName = fileNode.Name;
                DownloadOptions downloadOptions = new DownloadOptions();
                if (fileName.Equals(checkWrongMD5File) || fileName.Equals(checkCorrectMD5File))
                {
                    downloadOptions.DisableContentMD5Validation = false;
                }
                else if (fileName.Equals(notCheckWrongMD5File) || fileName.Equals(notCheckCorrectMD5File))
                {
                    downloadOptions.DisableContentMD5Validation = true;
                }

                transferItem.Options = downloadOptions;
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            Test.Assert(result.Exceptions.Count == 1, "Verify there's one exception.");
            Exception exception = result.Exceptions[0];

            Test.Assert(exception is InvalidOperationException, "Verify it's an invalid operation exception.");
            VerificationHelper.VerifyExceptionErrorMessage(exception, "The MD5 hash calculated from the downloaded data does not match the MD5 hash stored", checkWrongMD5File);
        }
        public void TransferDifferentSizeObject()
        {
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            DMLibDataHelper.AddMultipleFilesNormalSize(sourceDataInfo.RootNode, BVT.UnicodeFileName);

            var options = new TestExecutionOptions<DMLibDataInfo>();
            options.AfterDataPrepared = () =>
                {
                    if ((DMLibTestContext.SourceType == DMLibDataType.CloudFile || DMLibTestContext.SourceType == DMLibDataType.PageBlob) &&
                        !DMLibTestContext.IsAsync)
                    {
                        string sparseFileName = "SparseFile";

                        DMLibDataHelper.AddOneFile(sourceDataInfo.RootNode, sparseFileName, 1);
                        FileNode sparseFileNode = sourceDataInfo.RootNode.GetFileNode(sparseFileName);

                        if (DMLibTestContext.SourceType == DMLibDataType.CloudFile)
                        {
                            CloudFileDataAdaptor cloudFileDataAdaptor = SourceAdaptor as CloudFileDataAdaptor;
                            CloudFile sparseCloudFile = cloudFileDataAdaptor.GetCloudFileReference(sparseFileNode);
                            this.PrepareCloudFileWithDifferentSizeRange(sparseCloudFile);
                            sparseFileNode.MD5 = sparseCloudFile.Properties.ContentMD5;
                            sparseFileNode.Metadata = sparseCloudFile.Metadata;
                        }
                        else if (DMLibTestContext.SourceType == DMLibDataType.PageBlob)
                        {
                            CloudBlobDataAdaptor cloudBlobDataAdaptor = SourceAdaptor as CloudBlobDataAdaptor;
                            CloudPageBlob sparsePageBlob = cloudBlobDataAdaptor.GetCloudBlobReference(sparseFileNode) as CloudPageBlob;
                            this.PreparePageBlobWithDifferenSizePage(sparsePageBlob);
                            sparseFileNode.MD5 = sparsePageBlob.Properties.ContentMD5;
                            sparseFileNode.Metadata = sparsePageBlob.Metadata;
                        }
                    }
                };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            // For sync copy, recalculate md5 of destination by downloading the file to local.
            if (IsCloudService(DMLibTestContext.DestType) && !DMLibTestContext.IsAsync)
            {
                DMLibDataHelper.SetCalculatedFileMD5(result.DataInfo, DestAdaptor);
            }

            Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown.");
            Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, result.DataInfo), "Verify transfer result.");
        }
		public async Task RunTestsAsync(IEnumerable<ITest> selectedTests, TestExecutionOptions options, CancellationToken cancellationToken)
		{
			this.cancellationToken = cancellationToken;
			GroupTestsByProject(selectedTests);
			
			ClearTasks();
			ShowUnitTestsPad();
			ShowOutputPad();
			
			ResetTestResults();
			saveAllFilesCommand.SaveAllFiles();
			
			// Run the build, if necessary:
			var projectsToBuild = testsByProject.Keys.Where(p => p.IsBuildNeededBeforeTestRun).Select(p => p.Project).ToList();
			if (projectsToBuild.Count > 0) {
				using (cancellationToken.Register(buildService.CancelBuild)) {
					var buildOptions = new BuildOptions(BuildTarget.Build);
					buildOptions.BuildDetection = BuildOptions.BuildOnExecute;
					var buildResults = await buildService.BuildAsync(projectsToBuild, buildOptions);
					if (buildResults.Result != BuildResultCode.Success)
						return;
				}
			}
			
			cancellationToken.ThrowIfCancellationRequested();
			using (IProgressMonitor progressMonitor = statusBarService.CreateProgressMonitor(cancellationToken)) {
				int projectsLeftToRun = testsByProject.Count;
				foreach (IGrouping<ITestProject, ITest> g in testsByProject.OrderBy(g => g.Key.DisplayName)) {
					currentProjectBeingTested = g.Key;
					progressMonitor.TaskName = GetProgressMonitorLabel(currentProjectBeingTested);
					progressMonitor.Progress = GetProgress(projectsLeftToRun);
					using (testProgressMonitor = progressMonitor.CreateSubTask(1.0 / testsByProject.Count)) {
						using (ITestRunner testRunner = currentProjectBeingTested.CreateTestRunner(options)) {
							testRunner.TestFinished += testRunner_TestFinished;
							var writer = new MessageViewCategoryTextWriter(testService.UnitTestMessageView);
							await testRunner.RunAsync(g, testProgressMonitor, writer, testProgressMonitor.CancellationToken);
						}
					}
					projectsLeftToRun--;
					progressMonitor.CancellationToken.ThrowIfCancellationRequested();
				}
			}
			
			ShowErrorList();
		}
        public void TestProgressHandlerTest()
        {
            long fileSize = 10 * 1024 * 1024;

            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, DMLibTestBase.FileName, fileSize);

            var options = new TestExecutionOptions<DMLibDataInfo>();
            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                TransferContext transferContext = new TransferContext();
                ProgressChecker progressChecker = new ProgressChecker(1, fileNode.SizeInByte);
                transferContext.ProgressHandler = progressChecker.GetProgressHandler();
                transferItem.TransferContext = transferContext;
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown.");
            Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, result.DataInfo), "Verify transfer result.");
        }
        public void TestDirectoryIncludeSnapshots()
        {
            string snapshotFile1 = "snapshotFile1";
            string snapshotFile2 = "snapshotFile2";
            string snapshotFile3 = "snapshotFile3";

            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);

            // the 1st file has 1 snapshot
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, snapshotFile1, 1024);
            FileNode fileNode1 = sourceDataInfo.RootNode.GetFileNode(snapshotFile1);
            fileNode1.SnapshotsCount = 1;

            // the 2nd file has 2 snapshots
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, snapshotFile2, 1024);
            FileNode fileNode2 = sourceDataInfo.RootNode.GetFileNode(snapshotFile2);
            fileNode2.SnapshotsCount = 2;

            // the 3rd file has no snapshot
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, snapshotFile3, 1024);

            var options = new TestExecutionOptions<DMLibDataInfo>();
            options.IsDirectoryTransfer = true;

            // transfer with IncludeSnapshots = true
            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                dynamic dirOptions = DefaultTransferDirectoryOptions;
                dirOptions.Recursive = true;
                dirOptions.IncludeSnapshots = true;
                transferItem.Options = dirOptions;
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            // verify that snapshots are transferred
            Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown.");
            Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, result.DataInfo), "Verify transfer result.");
        }
        public void TestSetContentType()
        {
            string contentType = "contenttype";
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            DMLibDataHelper.AddOneFile(sourceDataInfo.RootNode, DMLibTestBase.FileName, 1024);

            var options = new TestExecutionOptions<DMLibDataInfo>();
            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                UploadOptions uploadOptions = new UploadOptions();
                uploadOptions.ContentType = "contenttype";

                transferItem.Options = uploadOptions;
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown.");
            Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, result.DataInfo), "Verify transfer result.");

            FileNode destFileNode = result.DataInfo.RootNode.GetFileNode(DMLibTestBase.FileName);
            Test.Assert(contentType.Equals(destFileNode.ContentType), "Verify content type: {0}, expected {1}", destFileNode.ContentType, contentType);
        }
        public void DirectoryOverwriteDestination()
        {
            string destExistYName    = "destExistY";
            string destExistNName    = "destExistN";
            string destNotExistYName = "destNotExistY";

            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);

            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, destExistYName, 1024);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, destExistNName, 1024);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, destNotExistYName, 1024);

            DMLibDataInfo destDataInfo = new DMLibDataInfo(string.Empty);

            DMLibDataHelper.AddOneFileInBytes(destDataInfo.RootNode, destExistYName, 1024);
            DMLibDataHelper.AddOneFileInBytes(destDataInfo.RootNode, destExistNName, 1024);

            TransferContext transferContext = new TransferContext();

            transferContext.OverwriteCallback = (string sourcePath, string destinationPath) =>
            {
                if (sourcePath.EndsWith(destExistNName))
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            };

            int skipCount    = 0;
            int successCount = 0;

            transferContext.FileSkipped += (object sender, TransferEventArgs args) =>
            {
                Interlocked.Increment(ref skipCount);
                TransferException transferException = args.Exception as TransferException;
                Test.Assert(transferException != null, "Verify the exception is a TransferException");

                VerificationHelper.VerifyTransferException(transferException, TransferErrorCode.NotOverwriteExistingDestination,
                                                           "Skiped file", destExistNName);
            };

            transferContext.FileTransferred += (object sender, TransferEventArgs args) =>
            {
                Interlocked.Increment(ref successCount);
            };

            var options = new TestExecutionOptions <DMLibDataInfo>();

            options.IsDirectoryTransfer = true;
            if (DMLibTestContext.DestType != DMLibDataType.Stream)
            {
                options.DestTransferDataInfo = destDataInfo;
            }

            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                transferItem.TransferContext = transferContext;

                dynamic transferOptions = DefaultTransferDirectoryOptions;
                transferOptions.Recursive = true;
                transferItem.Options      = transferOptions;
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            DMLibDataInfo expectedDataInfo = new DMLibDataInfo(string.Empty);

            if (DMLibTestContext.DestType != DMLibDataType.Stream)
            {
                expectedDataInfo.RootNode.AddFileNode(sourceDataInfo.RootNode.GetFileNode(destExistYName));
                expectedDataInfo.RootNode.AddFileNode(destDataInfo.RootNode.GetFileNode(destExistNName));
                expectedDataInfo.RootNode.AddFileNode(sourceDataInfo.RootNode.GetFileNode(destNotExistYName));
            }
            else
            {
                expectedDataInfo = sourceDataInfo;
            }

            // Verify transfer result
            Test.Assert(DMLibDataHelper.Equals(expectedDataInfo, result.DataInfo), "Verify transfer result.");

            // Verify exception
            if (DMLibTestContext.DestType != DMLibDataType.Stream)
            {
                VerificationHelper.VerifySingleTransferStatus(result, 2, 1, 0, 1024 * 2);
                Test.Assert(successCount == 2, "Verify success transfers");
                Test.Assert(skipCount == 1, "Verify skipped transfer");
            }
            else
            {
                VerificationHelper.VerifySingleTransferStatus(result, 3, 0, 0, 1024 * 3);
                Test.Assert(successCount == 3, "Very all transfers are success");
                Test.Assert(skipCount == 0, "Very no transfer is skipped");
            }
        }
Beispiel #13
0
        protected override TestResult RunImpl(ITestCommand rootTestCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)
        {
            using (progressMonitor.BeginTask("Verifying Specifications", rootTestCommand.TestCount))
            {
                if (options.SkipTestExecution)
                {
                    return(SkipAll(rootTestCommand, parentTestStep));
                }
                else
                {
                    ITestContext rootContext = rootTestCommand.StartPrimaryChildStep(parentTestStep);
                    TestStep     rootStep    = rootContext.TestStep;
                    TestOutcome  outcome     = TestOutcome.Passed;

                    foreach (ITestCommand command in rootTestCommand.Children)
                    {
                        NSpecAssemblyTest assemblyTest = command.Test as NSpecAssemblyTest;
                        if (assemblyTest == null)
                        {
                            continue;
                        }

                        var assemblyResult = this.RunAssembly(command, rootStep);
                        outcome = outcome.CombineWith(assemblyResult.Outcome);
                    }

                    return(rootContext.FinishStep(outcome, null));
                }
            }
        }
 /// <summary>
 /// Implementation of <see cref="Run" /> called after argument validation has taken place.
 /// </summary>
 /// <param name="rootTestCommand">The root test command, not null.</param>
 /// <param name="parentTestStep">The parent test step, or null if none.</param>
 /// <param name="options">The test execution options, not null.</param>
 /// <param name="progressMonitor">The progress monitor, not null.</param>
 /// <returns>The combined result of the root test command.</returns>
 protected internal abstract TestResult RunImpl(ITestCommand rootTestCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor);
 public RunTestCommandsAction(SimpleTestDriver driver, ITestCommand rootTestCommand, TestExecutionOptions options, TestHarness testHarness, ITestContextManager testContextManager, IProgressMonitor progressMonitor)
 {
     this.driver = driver;
     this.rootTestCommand = rootTestCommand;
     this.options = options;
     this.testHarness = testHarness;
     this.testContextManager = testContextManager;
     this.progressMonitor = progressMonitor;
 }
        /// <inheritdoc />
        protected override sealed void RunAssembly(Assembly assembly, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
        {
            using (progressMonitor.BeginTask(string.Format("Running {0} tests.", FrameworkName), 100))
            {
                using (TestHarness testHarness = CreateTestHarness())
                {
                    IDisposable appDomainState = null;
                    try
                    {
                        progressMonitor.SetStatus("Setting up the test harness.");
                        appDomainState = testHarness.SetUpAppDomain();
                        progressMonitor.Worked(1);

                        progressMonitor.SetStatus("Building the test model.");
                        TestModel testModel = GenerateTestModel(assembly, messageSink);
                        progressMonitor.Worked(3);

                        progressMonitor.SetStatus("Building the test commands.");
                        ITestContextManager testContextManager = CreateTestContextManager(messageSink);
                        ITestCommand rootTestCommand = GenerateCommandTree(testModel, testExecutionOptions, testContextManager);
                        progressMonitor.Worked(2);

                        progressMonitor.SetStatus("Running the tests.");
                        if (rootTestCommand != null)
                        {
                            RunTestCommandsAction action = new RunTestCommandsAction(this, rootTestCommand, testExecutionOptions,
                                testHarness, testContextManager, progressMonitor.CreateSubProgressMonitor(93));

                            if (testExecutionOptions.SingleThreaded)
                            {
                                // The execution options require the use of a single thread.
                                action.Run();
                            }
                            else
                            {
                                // Create a new thread so that we can consistently set the default apartment
                                // state to STA and so as to reduce the effective stack depth during the
                                // test run.  We use Thread instead of ThreadTask because we do not
                                // require the ability to abort the Thread so we do not need to take the
                                // extra overhead.
                                Thread thread = new Thread(action.Run);
                                thread.Name = "Simple Test Driver";
                                thread.SetApartmentState(ApartmentState.STA);
                                thread.Start();
                                thread.Join();
                            }

                            if (action.Exception != null)
                                throw new ModelException("A fatal exception occurred while running test commands.", action.Exception);
                        }
                        else
                        {
                            progressMonitor.Worked(93);
                        }
                    }
                    finally
                    {
                        progressMonitor.SetStatus("Tearing down the test harness.");
                        if (appDomainState != null)
                            appDomainState.Dispose();
                        progressMonitor.Worked(1);
                    }
                }
            }
        }
        public void TestResume()
        {
            int fileSizeInKB = 100 * 1024;
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            DMLibDataHelper.AddOneFile(sourceDataInfo.RootNode, DMLibTestBase.FileName, fileSizeInKB);

            CancellationTokenSource tokenSource = new CancellationTokenSource();

            TransferItem transferItem = null;
            var options = new TestExecutionOptions<DMLibDataInfo>();
            options.LimitSpeed = true;
            var transferContext = new TransferContext();
            var progressChecker = new ProgressChecker(1, fileSizeInKB * 1024);
            transferContext.ProgressHandler = progressChecker.GetProgressHandler();
            options.TransferItemModifier = (fileName, item) =>
                {
                    item.CancellationToken = tokenSource.Token;
                    item.TransferContext = transferContext;
                    transferItem = item;
                };

            TransferCheckpoint firstCheckpoint = null, secondCheckpoint = null;
            options.AfterAllItemAdded = () =>
                {
                    // Wait until there are data transferred
                    progressChecker.DataTransferred.WaitOne();

                    // Store the first checkpoint
                    firstCheckpoint = transferContext.LastCheckpoint;
                    Thread.Sleep(1000);

                    // Cancel the transfer and store the second checkpoint
                    tokenSource.Cancel();
                    secondCheckpoint = transferContext.LastCheckpoint;
                };

            // Cancel and store checkpoint for resume
            var result = this.ExecuteTestCase(sourceDataInfo, options);

            Test.Assert(result.Exceptions.Count == 1, "Verify job is cancelled");
            Exception exception = result.Exceptions[0];
            VerificationHelper.VerifyExceptionErrorMessage(exception, "A task was canceled.");

            TransferCheckpoint firstResumeCheckpoint = null, secondResumeCheckpoint = null;

            // DMLib doesn't support to resume transfer from a checkpoint which is inconsistent with
            // the actual transfer progress when the destination is an append blob.
            if (Helper.RandomBoolean() && DMLibTestContext.DestType != DMLibDataType.AppendBlob)
            {
                Test.Info("Resume with the first checkpoint first.");
                firstResumeCheckpoint = firstCheckpoint;
                secondResumeCheckpoint = secondCheckpoint;
            }
            else
            {
                Test.Info("Resume with the second checkpoint first.");
                firstResumeCheckpoint = secondCheckpoint;
                secondResumeCheckpoint = firstCheckpoint;
            }

            // resume with firstResumeCheckpoint
            TransferItem resumeItem = transferItem.Clone();
            progressChecker.Reset();
            TransferContext resumeContext = new TransferContext(firstResumeCheckpoint)
            {
                ProgressHandler = progressChecker.GetProgressHandler()
            };
            resumeItem.TransferContext = resumeContext;

            result = this.RunTransferItems(new List<TransferItem>() { resumeItem }, new TestExecutionOptions<DMLibDataInfo>());

            VerificationHelper.VerifySingleObjectResumeResult(result, sourceDataInfo);

            // resume with secondResumeCheckpoint
            resumeItem = transferItem.Clone();
            progressChecker.Reset();
            resumeContext = new TransferContext(secondResumeCheckpoint)
            {
                ProgressHandler = progressChecker.GetProgressHandler()
            };
            resumeItem.TransferContext = resumeContext;

            result = this.RunTransferItems(new List<TransferItem>() { resumeItem }, new TestExecutionOptions<DMLibDataInfo>());

            if (DMLibTestContext.DestType != DMLibDataType.AppendBlob || DMLibTestContext.SourceType == DMLibDataType.Stream)
            {
                VerificationHelper.VerifySingleObjectResumeResult(result, sourceDataInfo);
            }
            else
            {
                Test.Assert(result.Exceptions.Count == 1, "Verify reumse fails when checkpoint is inconsistent with the actual progress when destination is append blob.");
                exception = result.Exceptions[0];
                Test.Assert(exception is InvalidOperationException, "Verify reumse fails when checkpoint is inconsistent with the actual progress when destination is append blob.");
                VerificationHelper.VerifyExceptionErrorMessage(exception, "Destination might be changed by other process or application.");
            }
        }
Beispiel #18
0
        /// <inheritdoc />
        public Report Run(TestPackage testPackage, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IProgressMonitor progressMonitor)
        {
            if (testPackage == null)
            {
                throw new ArgumentNullException("testPackageConfig");
            }
            if (testExplorationOptions == null)
            {
                throw new ArgumentNullException("testExplorationOptions");
            }
            if (testExecutionOptions == null)
            {
                throw new ArgumentNullException("testExecutionOptions");
            }
            if (progressMonitor == null)
            {
                throw new ArgumentNullException("progressMonitor");
            }

            ThrowIfDisposed();
            if (state != State.Initialized)
            {
                throw new InvalidOperationException("The test runner must be initialized before this operation is performed.");
            }

            testPackage            = testPackage.Copy();
            testExplorationOptions = testExplorationOptions.Copy();
            testExecutionOptions   = testExecutionOptions.Copy();
            GenericCollectionUtils.ForEach(testRunnerOptions.Properties, x => testPackage.AddProperty(x.Key, x.Value));

            using (progressMonitor.BeginTask("Running the tests.", 10))
            {
                Stopwatch stopwatch = Stopwatch.StartNew();
                Report    report    = new Report()
                {
                    TestPackage    = new TestPackageData(testPackage),
                    TestModel      = new TestModelData(),
                    TestPackageRun = new TestPackageRun()
                    {
                        StartTime = DateTime.Now
                    }
                };
                var reportLockBox = new LockBox <Report>(report);

                eventDispatcher.NotifyRunStarted(new RunStartedEventArgs(testPackage, testExplorationOptions,
                                                                         testExecutionOptions, reportLockBox));

                bool success;
                using (Listener listener = new Listener(eventDispatcher, tappedLogger, reportLockBox))
                {
                    try
                    {
                        ITestDriver testDriver = testFrameworkManager.GetTestDriver(
                            testPackage.CreateTestFrameworkSelector(), tappedLogger);

                        using (testIsolationContext.BeginBatch(progressMonitor.SetStatus))
                        {
                            testDriver.Run(testIsolationContext, testPackage, testExplorationOptions,
                                           testExecutionOptions, listener, progressMonitor.CreateSubProgressMonitor(10));
                        }

                        success = true;
                    }
                    catch (Exception ex)
                    {
                        success = false;

                        tappedLogger.Log(LogSeverity.Error,
                                         "A fatal exception occurred while running tests.  Possible causes include invalid test runner parameters and stack overflows.",
                                         ex);
                        report.TestModel.Annotations.Add(new AnnotationData(AnnotationType.Error,
                                                                            CodeLocation.Unknown, CodeReference.Unknown,
                                                                            "A fatal exception occurred while running tests.  See log for details.", null));
                    }
                    finally
                    {
                        report.TestPackageRun.EndTime             = DateTime.Now;
                        report.TestPackageRun.Statistics.Duration = stopwatch.Elapsed.TotalSeconds;
                    }
                }

                eventDispatcher.NotifyRunFinished(new RunFinishedEventArgs(success, report));

                return(report);
            }
        }
Beispiel #19
0
        public void DirectoryForceOverwriteTest()
        {
            string destExistName    = "destExist";
            string destNotExistName = "destNotExist";

            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);

            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, destExistName, 1024);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, destNotExistName, 1024);

            DMLibDataInfo destDataInfo = new DMLibDataInfo(string.Empty);

            DMLibDataHelper.AddOneFileInBytes(destDataInfo.RootNode, destExistName, 1024);

            TransferContext transferContext = new DirectoryTransferContext();

            transferContext.ShouldOverwriteCallbackAsync = TransferContext.ForceOverwrite;

            int skipCount    = 0;
            int successCount = 0;

            transferContext.FileSkipped += (object sender, TransferEventArgs args) =>
            {
                Interlocked.Increment(ref skipCount);
            };

            transferContext.FileTransferred += (object sender, TransferEventArgs args) =>
            {
                Interlocked.Increment(ref successCount);
            };

            var options = new TestExecutionOptions <DMLibDataInfo>();

            options.IsDirectoryTransfer = true;
            if (DMLibTestContext.DestType != DMLibDataType.Stream)
            {
                options.DestTransferDataInfo = destDataInfo;
            }

            if (IsCloudService(DMLibTestContext.DestType))
            {
                SharedAccessPermissions permissions;

                if (DMLibTestContext.CopyMethod == DMLibCopyMethod.ServiceSideAsyncCopy)
                {
                    permissions = SharedAccessPermissions.Write | SharedAccessPermissions.Read;
                }
                else
                {
                    permissions = SharedAccessPermissions.Write;
                }

                StorageCredentials destSAS = new StorageCredentials(DestAdaptor.GenerateSAS(permissions, (int)new TimeSpan(1, 0, 0, 0).TotalSeconds));
                options.DestCredentials = destSAS;
            }

            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                transferItem.TransferContext = transferContext;

                dynamic transferOptions = DefaultTransferDirectoryOptions;
                transferOptions.Recursive = true;
                transferItem.Options      = transferOptions;
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            // Verify transfer result
            Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, result.DataInfo), "Verify transfer result.");
            VerificationHelper.VerifySingleTransferStatus(result, 2, 0, 0, 1024 * 2);
            Test.Assert(successCount == 2, "Verify success transfers");
            Test.Assert(skipCount == 0, "Verify skipped transfer");
        }
Beispiel #20
0
            private static void ExploreOrRun(TestPackage testPackage, ScriptRuntimeSetup scriptRuntimeSetup, string testDriverScriptPath,
                                             TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions,
                                             IMessageSink messageSink, IProgressMonitor progressMonitor, ILogger logger)
            {
                using (BufferedLogWriter outputWriter = new BufferedLogWriter(logger, LogSeverity.Info, Encoding.Default),
                       errorWriter = new BufferedLogWriter(logger, LogSeverity.Error, Encoding.Default))
                {
                    using (var queuedMessageSink = new QueuedMessageSink(messageSink))
                    {
                        using (new ConsoleRedirection(outputWriter, errorWriter))
                        {
                            var scriptRuntime = new ScriptRuntime(scriptRuntimeSetup);

                            scriptRuntime.IO.SetInput(Stream.Null, TextReader.Null, Encoding.Default);
                            scriptRuntime.IO.SetOutput(new TextWriterStream(outputWriter), outputWriter);
                            scriptRuntime.IO.SetErrorOutput(new TextWriterStream(errorWriter), errorWriter);

                            try
                            {
                                var scriptParameters = new Dictionary <string, object>();
                                scriptParameters.Add("Verb", testExecutionOptions != null ? "Run" : "Explore");
                                scriptParameters.Add("TestPackage", testPackage);
                                scriptParameters.Add("TestExplorationOptions", testExplorationOptions);
                                scriptParameters.Add("TestExecutionOptions", testExecutionOptions);
                                scriptParameters.Add("MessageSink", queuedMessageSink);
                                scriptParameters.Add("ProgressMonitor", progressMonitor);
                                scriptParameters.Add("Logger", logger);

                                scriptRuntime.Globals.SetVariable(ScriptParametersVariableName, scriptParameters);

                                RunScript(scriptRuntime, testDriverScriptPath);
                            }
                            finally
                            {
                                scriptRuntime.Shutdown();
                            }
                        }
                    }
                }
            }
Beispiel #21
0
 /// <inheritdoc />
 sealed protected override void RunImpl(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
 {
     ExploreOrRun(testIsolationContext, testPackage, testExplorationOptions, testExecutionOptions, messageSink,
                  progressMonitor, "Running tests.");
 }
Beispiel #22
0
        private void TestDirectorySetAttribute_Restart(
            int bigFileSizeInKB,
            int smallFileSizeInKB,
            int bigFileNum,
            int smallFileNum,
            Action <DirNode> bigFileDirAddFileAction,
            Action <DirNode> smallFileDirAddFileAction,
            SetAttributesCallbackAsync setAttributesCallback = null,
            Action <DMLibDataInfo> sourceDataInfoDecorator   = null)
        {
            int  totalFileNum     = bigFileNum + smallFileNum;
            long totalSizeInBytes = ((bigFileSizeInKB * bigFileNum) + (smallFileSizeInKB * smallFileNum)) * 1024;

            DMLibDataInfo sourceDataInfo   = new DMLibDataInfo(string.Empty);
            DirNode       bigFileDirNode   = new DirNode("big");
            DirNode       smallFileDirNode = new DirNode("small");

            sourceDataInfo.RootNode.AddDirNode(bigFileDirNode);
            sourceDataInfo.RootNode.AddDirNode(smallFileDirNode);
            bigFileDirAddFileAction(bigFileDirNode);
            smallFileDirAddFileAction(smallFileDirNode);

            CancellationTokenSource tokenSource = new CancellationTokenSource();

            TransferItem transferItem = null;
            var          options      = new TestExecutionOptions <DMLibDataInfo> {
                LimitSpeed = true, IsDirectoryTransfer = true
            };

            using (Stream journalStream = new MemoryStream())
            {
                bool isStreamJournal = random.Next(0, 2) == 0;

                var transferContext = isStreamJournal ? new DirectoryTransferContext(journalStream) : new DirectoryTransferContext();
                transferContext.SetAttributesCallbackAsync = setAttributesCallback;

                var progressChecker = new ProgressChecker(totalFileNum, totalSizeInBytes, totalFileNum, null, 0, totalSizeInBytes);
                transferContext.ProgressHandler = progressChecker.GetProgressHandler();

                var eventChecker = new TransferEventChecker();
                eventChecker.Apply(transferContext);

                transferContext.FileFailed += (sender, e) =>
                {
                    Helper.VerifyCancelException(e.Exception);
                };

                options.TransferItemModifier = (fileName, item) =>
                {
                    dynamic dirOptions = DefaultTransferDirectoryOptions;
                    dirOptions.Recursive = true;

                    item.Options           = dirOptions;
                    item.CancellationToken = tokenSource.Token;
                    item.TransferContext   = transferContext;
                    transferItem           = item;
                };

                TransferCheckpoint firstCheckpoint = null, secondCheckpoint = null;
                options.AfterAllItemAdded = () =>
                {
                    // Wait until there are data transferred
                    progressChecker.DataTransferred.WaitOne();

                    if (!isStreamJournal)
                    {
                        // Store the first checkpoint
                        firstCheckpoint = transferContext.LastCheckpoint;
                    }

                    Thread.Sleep(1000);

                    // Cancel the transfer and store the second checkpoint
                    tokenSource.Cancel();
                };

                // Cancel and store checkpoint for resume
                var result = this.ExecuteTestCase(sourceDataInfo, options);

                if (progressChecker.FailedFilesNumber <= 0)
                {
                    Test.Error("Verify file number in progress. Failed: {0}", progressChecker.FailedFilesNumber);
                }

                TransferCheckpoint firstResumeCheckpoint = null, secondResumeCheckpoint = null;

                if (!isStreamJournal)
                {
                    secondCheckpoint = transferContext.LastCheckpoint;

                    Test.Info("Resume with the second checkpoint first.");
                    firstResumeCheckpoint  = secondCheckpoint;
                    secondResumeCheckpoint = firstCheckpoint;
                }

                // resume with firstResumeCheckpoint
                TransferItem resumeItem = transferItem.Clone();

                progressChecker.Reset();
                TransferContext resumeContext = null;

                if (isStreamJournal)
                {
                    resumeContext = new DirectoryTransferContext(journalStream)
                    {
                        ProgressHandler = progressChecker.GetProgressHandler()
                    };
                }
                else
                {
                    resumeContext = new DirectoryTransferContext(DMLibTestHelper.RandomReloadCheckpoint(firstResumeCheckpoint))
                    {
                        ProgressHandler = progressChecker.GetProgressHandler()
                    };
                }

                resumeContext.SetAttributesCallbackAsync = setAttributesCallback;

                eventChecker.Reset();
                eventChecker.Apply(resumeContext);

                resumeItem.TransferContext = resumeContext;

                result = this.RunTransferItems(new List <TransferItem>()
                {
                    resumeItem
                }, new TestExecutionOptions <DMLibDataInfo>());

                sourceDataInfoDecorator?.Invoke(sourceDataInfo);

                VerificationHelper.VerifyFinalProgress(progressChecker, totalFileNum, 0, 0);
                VerificationHelper.VerifySingleTransferStatus(result, totalFileNum, 0, 0, totalSizeInBytes);
                VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);

                if (!isStreamJournal)
                {
                    // resume with secondResumeCheckpoint
                    resumeItem = transferItem.Clone();

                    progressChecker.Reset();
                    resumeContext = new DirectoryTransferContext(DMLibTestHelper.RandomReloadCheckpoint(secondResumeCheckpoint))
                    {
                        ProgressHandler = progressChecker.GetProgressHandler(),

                        // Need this overwrite callback since some files is already transferred to destination
                        ShouldOverwriteCallbackAsync = DMLibInputHelper.GetDefaultOverwiteCallbackY(),

                        SetAttributesCallbackAsync = setAttributesCallback
                    };

                    eventChecker.Reset();
                    eventChecker.Apply(resumeContext);

                    resumeItem.TransferContext = resumeContext;

                    result = this.RunTransferItems(new List <TransferItem>()
                    {
                        resumeItem
                    }, new TestExecutionOptions <DMLibDataInfo>());

                    VerificationHelper.VerifyFinalProgress(progressChecker, totalFileNum, 0, 0);
                    VerificationHelper.VerifySingleTransferStatus(result, totalFileNum, 0, 0, totalSizeInBytes);
                    VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);
                }
            }
        }
Beispiel #23
0
        public void TestDirectorySetAttributes()
        {
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);

            for (int i = 0; i < 3; ++i)
            {
                FileNode fileNode = new FileNode(DMLibTestBase.FileName + i)
                {
                    SizeInByte = DMLibTestBase.FileSizeInKB * 1024L
                };

                if (DMLibTestContext.SourceType != DMLibDataType.Local)
                {
                    fileNode.Metadata = new Dictionary <string, string>();
                    fileNode.Metadata.Add("foo", "bar");
                    fileNode.ContentLanguage = SetAttributesTest.TestContentLanguage;
                }

                sourceDataInfo.RootNode.AddFileNode(fileNode);
            }

            DirectoryTransferContext context = new DirectoryTransferContext()
            {
                SetAttributesCallbackAsync = async(destObj) =>
                {
                    dynamic destCloudObj = destObj;

                    destCloudObj.Properties.ContentType = SetAttributesTest.TestContentType;

                    destCloudObj.Metadata.Add("aa", "bb");
                }
            };

            var options = new TestExecutionOptions <DMLibDataInfo>();

            options.TransferItemModifier = (node, transferItem) =>
            {
                dynamic transferOptions = DefaultTransferDirectoryOptions;
                transferOptions.Recursive    = true;
                transferItem.Options         = transferOptions;
                transferItem.TransferContext = context;
            };
            options.IsDirectoryTransfer = true;

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            foreach (FileNode fileNode in sourceDataInfo.EnumerateFileNodes())
            {
                fileNode.Metadata.Add("aa", "bb");
            }

            VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);
            VerificationHelper.VerifySingleTransferStatus(result, 3, 0, 0, 3 * DMLibTestBase.FileSizeInKB * 1024L);

            foreach (FileNode destFileNode in result.DataInfo.EnumerateFileNodes())
            {
                Test.Assert(TestContentType.Equals(destFileNode.ContentType), "Verify content type: {0}, expected {1}", destFileNode.ContentType, TestContentType);

                if (DMLibTestContext.SourceType != DMLibDataType.Local)
                {
                    Test.Assert(SetAttributesTest.TestContentLanguage.Equals(destFileNode.ContentLanguage), "Verify ContentLanguage: {0}, expected {1}", destFileNode.ContentLanguage, SetAttributesTest.TestContentLanguage);
                }
            }
        }
 /// <inheritdoc />
 protected override TestResult RunImpl(ITestCommand rootTestCommand, TestStep parentTestStep, TestExecutionOptions options, IProgressMonitor progressMonitor)
 {
     using (progressMonitor.BeginTask(Resources.MSTestController_RunningMSTestTests, rootTestCommand.TestCount))
     {
         if (options.SkipTestExecution)
         {
             return(SkipAll(rootTestCommand, parentTestStep));
         }
         else
         {
             return(RunTest(rootTestCommand, parentTestStep, progressMonitor));
         }
     }
 }
        public void OverwriteDestination()
        {
            string destExistYName    = "destExistY";
            string destExistNName    = "destExistN";
            string destNotExistYName = "destNotExistY";

            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);

            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, destExistYName, 1024);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, destExistNName, 1024);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, destNotExistYName, 1024);

            DMLibDataInfo destDataInfo = new DMLibDataInfo(string.Empty);

            DMLibDataHelper.AddOneFileInBytes(destDataInfo.RootNode, destExistYName, 1024);
            DMLibDataHelper.AddOneFileInBytes(destDataInfo.RootNode, destExistNName, 1024);

            var options = new TestExecutionOptions <DMLibDataInfo>();

            if (DMLibTestContext.DestType != DMLibDataType.Stream)
            {
                options.DestTransferDataInfo = destDataInfo;
            }

            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                string          fileName        = fileNode.Name;
                TransferContext transferContext = new TransferContext();

                if (fileName.Equals(destExistYName))
                {
                    transferContext.OverwriteCallback = DMLibInputHelper.GetDefaultOverwiteCallbackY();
                }
                else if (fileName.Equals(destExistNName))
                {
                    transferContext.OverwriteCallback = DMLibInputHelper.GetDefaultOverwiteCallbackN();
                }
                else if (fileName.Equals(destNotExistYName))
                {
                    transferContext.OverwriteCallback = DMLibInputHelper.GetDefaultOverwiteCallbackY();
                }

                transferItem.TransferContext = transferContext;
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            DMLibDataInfo expectedDataInfo = new DMLibDataInfo(string.Empty);

            if (DMLibTestContext.DestType != DMLibDataType.Stream)
            {
                expectedDataInfo.RootNode.AddFileNode(sourceDataInfo.RootNode.GetFileNode(destExistYName));
                expectedDataInfo.RootNode.AddFileNode(destDataInfo.RootNode.GetFileNode(destExistNName));
                expectedDataInfo.RootNode.AddFileNode(sourceDataInfo.RootNode.GetFileNode(destNotExistYName));
            }
            else
            {
                expectedDataInfo = sourceDataInfo;
            }

            // Verify transfer result
            Test.Assert(DMLibDataHelper.Equals(expectedDataInfo, result.DataInfo), "Verify transfer result.");

            // Verify exception
            if (DMLibTestContext.DestType != DMLibDataType.Stream)
            {
                Test.Assert(result.Exceptions.Count == 1, "Verify there's only one exceptions.");
                TransferException transferException = result.Exceptions[0] as TransferException;
                Test.Assert(transferException != null, "Verify the exception is a TransferException");

                VerificationHelper.VerifyTransferException(transferException, TransferErrorCode.NotOverwriteExistingDestination,
                                                           "Skiped file", destExistNName);
            }
        }
Beispiel #26
0
 internal ContentUtil(TestExecutionOptions options)
 {
     _options = options;
 }
Beispiel #27
0
        private void TestSASTokenOfEachVersion(string targetSASVersion, bool isDirectoryTransfer)
        {
            Test.Info("Testing version of {0}", targetSASVersion);
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);

            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, DMLibTestBase.FileName, 1024);

            var options = new TestExecutionOptions <DMLibDataInfo>();

            options.IsDirectoryTransfer = isDirectoryTransfer;

            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                dynamic transferOptions = isDirectoryTransfer ? DefaultTransferDirectoryOptions : DefaultTransferOptions;

                transferItem.Options = transferOptions;

                if (isDirectoryTransfer)
                {
                    transferItem.TransferContext = new DirectoryTransferContext();

                    transferItem.TransferContext.FileFailed += (source, e) =>
                    {
                        Test.Error(e.Exception.ToString());
                    };

                    DirectoryOptions dirOptions = transferItem.Options as DirectoryOptions;
                    dirOptions.Recursive = true;
                }
                else
                {
                    transferItem.TransferContext = new SingleTransferContext();
                }

                transferItem.TransferContext.ShouldOverwriteCallbackAsync = TransferContext.ForceOverwrite;
            };


            string sourceSAS = null;
            string destSAS   = null;

            switch (DMLibTestContext.SourceType)
            {
            case DMLibDataType.CloudBlob:
            case DMLibDataType.AppendBlob:
            case DMLibDataType.BlockBlob:
            case DMLibDataType.PageBlob:
                if ((DMLibTestContext.SourceType == DMLibDataType.AppendBlob) &&
                    (string.CompareOrdinal(targetSASVersion, "2015-04-05") < 0))
                {
                    break;
                }

                SourceAdaptor.CreateIfNotExists();
                CloudBlobDataAdaptor blobAdaptor = SourceAdaptor as CloudBlobDataAdaptor;
                sourceSAS = Util.SASGenerator.GetSharedAccessSignature(blobAdaptor.GetBaseContainer(),
                                                                       new SharedAccessBlobPolicy
                {
                    Permissions            = isDirectoryTransfer ? SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.List : SharedAccessBlobPermissions.Read,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1)
                },
                                                                       null,
                                                                       null,
                                                                       null,
                                                                       targetSASVersion);
                break;

            case DMLibDataType.CloudFile:
                if (string.CompareOrdinal(targetSASVersion, "2015-02-21") < 0)
                {
                    break;
                }

                SourceAdaptor.CreateIfNotExists();
                CloudFileDataAdaptor fileAdaptor = SourceAdaptor as CloudFileDataAdaptor;
                sourceSAS = Util.SASGenerator.GetSharedAccessSignature(
                    fileAdaptor.GetBaseShare(),
                    new SharedAccessFilePolicy
                {
                    Permissions            = isDirectoryTransfer ? SharedAccessFilePermissions.List | SharedAccessFilePermissions.Read : SharedAccessFilePermissions.Read,
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1)
                },
                    null,
                    null,
                    null,
                    targetSASVersion);
                break;

            default:
                break;
            }

            if ((DMLibTestContext.CopyMethod != DMLibCopyMethod.ServiceSideAsyncCopy) ||
                (string.CompareOrdinal(targetSASVersion, "2014-02-14") >= 0))
            {
                switch (DMLibTestContext.DestType)
                {
                case DMLibDataType.CloudBlob:
                case DMLibDataType.AppendBlob:
                case DMLibDataType.BlockBlob:
                case DMLibDataType.PageBlob:
                    if ((DMLibTestContext.DestType == DMLibDataType.AppendBlob) &&
                        (string.CompareOrdinal(targetSASVersion, "2015-04-05") < 0))
                    {
                        break;
                    }

                    DestAdaptor.CreateIfNotExists();
                    CloudBlobDataAdaptor blobAdaptor = DestAdaptor as CloudBlobDataAdaptor;
                    destSAS = Util.SASGenerator.GetSharedAccessSignature(blobAdaptor.GetBaseContainer(),
                                                                         new SharedAccessBlobPolicy
                    {
                        Permissions            = (DMLibTestContext.CopyMethod == DMLibCopyMethod.ServiceSideAsyncCopy) ? SharedAccessBlobPermissions.Write | SharedAccessBlobPermissions.Read : SharedAccessBlobPermissions.Write,
                        SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1)
                    },
                                                                         null,
                                                                         null,
                                                                         null,
                                                                         targetSASVersion);
                    break;

                case DMLibDataType.CloudFile:
                    if (string.CompareOrdinal(targetSASVersion, "2015-02-21") < 0)
                    {
                        break;
                    }

                    DestAdaptor.CreateIfNotExists();
                    CloudFileDataAdaptor fileAdaptor = DestAdaptor as CloudFileDataAdaptor;
                    destSAS = Util.SASGenerator.GetSharedAccessSignature(
                        fileAdaptor.GetBaseShare(),
                        new SharedAccessFilePolicy
                    {
                        Permissions            = (DMLibTestContext.CopyMethod == DMLibCopyMethod.ServiceSideAsyncCopy) ? SharedAccessFilePermissions.Write | SharedAccessFilePermissions.Read : SharedAccessFilePermissions.Write,
                        SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1)
                    },
                        null,
                        null,
                        null,
                        targetSASVersion);
                    break;

                default:
                    break;
                }
            }

            if (null != sourceSAS)
            {
                options.SourceCredentials = new StorageCredentials(sourceSAS);
            }

            if (null != destSAS)
            {
                options.DestCredentials = new StorageCredentials(destSAS);
            }

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);
        }
Beispiel #28
0
 internal CachingTestExecutor(TestExecutionOptions options, ITestExecutor testExecutor, IDataStorage dataStorage)
 {
     _testExecutor = testExecutor;
     _dataStorage = dataStorage;
     _contentUtil = new ContentUtil(options);
 }
        private void TestSearchPattern(bool recursive, DMLibDataInfo expectedResult, string searchPattern = null)
        {
            var options = new TestExecutionOptions<DMLibDataInfo>()
            {
                IsDirectoryTransfer = true,
                TransferItemModifier = (notUsed, item) =>
                {
                    dynamic transferOptions = DefaultTransferDirectoryOptions;
                    transferOptions.Recursive = recursive;
                    transferOptions.SearchPattern = searchPattern;
                    item.Options = transferOptions;
                },
            };

            var testResult = this.ExecuteTestCase(null, options);

            VerificationHelper.VerifyTransferSucceed(testResult, expectedResult);
        }
Beispiel #30
0
        private void ExploreOrRun <TTask>(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor, string taskName)
            where TTask : AbstractTask, new()
        {
            double totalWorkUnits = Math.Max(testPackage.Files.Count, 1);

            using (progressMonitor.BeginTask(taskName, totalWorkUnits))
            {
                var remoteMessageSink = new RemoteMessageSink(messageSink);
                var remoteLogger      = new RemoteLogger(logger);

                if (progressMonitor.IsCanceled)
                {
                    return;
                }

                using (var remoteProgressMonitor = new RemoteProgressMonitor(progressMonitor))
                {
                    foreach (FileInfo file in testPackage.Files)
                    {
                        HostSetup hostSetup = CreateHostSetup(testPackage, file);
                        testIsolationContext.RunIsolatedTask <TTask>(hostSetup, progressMonitor.SetStatus, new object[]
                        {
                            testPackage,
                            testExplorationOptions,
                            testExecutionOptions,
                            remoteMessageSink,
                            remoteProgressMonitor,
                            remoteLogger,
                            file,
                        });
                    }

                    remoteProgressMonitor.Worked(1);
                }
            }
        }
Beispiel #31
0
 internal ContentUtil(TestExecutionOptions options)
 {
     _options = options;
 }
        private ITestCommand GenerateCommandTree(TestModel testModel, TestExecutionOptions testExecutionOptions, ITestContextManager testContextManager)
        {
            ITestCommandFactory testCommandFactory = CreateTestCommandFactory();

            ITestCommand rootCommand = testCommandFactory.BuildCommands(testModel, testExecutionOptions.FilterSet,
                testExecutionOptions.ExactFilter, testContextManager);
            return rootCommand;
        }
        private void TestAccessCondition(SourceOrDest sourceOrDest)
        {
            string eTag = "notmatch";
            AccessCondition accessCondition = new AccessCondition()
            {
                IfMatchETag = eTag
            };

            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, DMLibTestBase.FileName, 1024);

            DMLibDataInfo destDataInfo = new DMLibDataInfo(string.Empty);
            DMLibDataHelper.AddOneFileInBytes(destDataInfo.RootNode, DMLibTestBase.FileName, 1024);

            var options = new TestExecutionOptions<DMLibDataInfo>();

            if (sourceOrDest == SourceOrDest.Dest)
            {
                options.DestTransferDataInfo = destDataInfo;
            }

            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                dynamic transferOptions = DefaultTransferOptions;

                if (sourceOrDest == SourceOrDest.Source)
                {
                    transferOptions.SourceAccessCondition = accessCondition;
                }
                else
                {
                    transferOptions.DestinationAccessCondition = accessCondition;
                }

                transferItem.Options = transferOptions;
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            if (sourceOrDest == SourceOrDest.Dest)
            {
                Test.Assert(DMLibDataHelper.Equals(destDataInfo, result.DataInfo), "Verify no file is transferred.");
            }
            else
            {
                if (DMLibTestContext.DestType != DMLibDataType.Stream)
                {
                    Test.Assert(DMLibDataHelper.Equals(new DMLibDataInfo(string.Empty), result.DataInfo), "Verify no file is transferred.");
                }
                else
                {
                    foreach(var fileNode in result.DataInfo.EnumerateFileNodes())
                    {
                        Test.Assert(fileNode.SizeInByte == 0, "Verify file {0} is empty", fileNode.Name);
                    }
                }
            }
            
            // Verify TransferException
            if (result.Exceptions.Count != 1)
            {
                Test.Error("There should be exactly one exceptions.");
                return;
            }

            Exception exception = result.Exceptions[0];
            VerificationHelper.VerifyTransferException(exception, TransferErrorCode.Unknown);

            // Verify innner StorageException
            VerificationHelper.VerifyStorageException(exception.InnerException, (int)HttpStatusCode.PreconditionFailed,
                "The condition specified using HTTP conditional header(s) is not met.");
        }
Beispiel #34
0
        public IEnumerable <AutoTest.TestRunners.Shared.Results.TestResult> Run(RunSettings settings)
        {
            if (!_isInitialized)
            {
                return new AutoTest.TestRunners.Shared.Results.TestResult[] { getNotInitializedResult(settings) }
            }
            ;
            var tests      = settings.Assembly.Tests.ToList();
            var members    = settings.Assembly.Members.ToList();
            var namespaces = settings.Assembly.Namespaces.ToList();

            var runAll      = namespaces.Count == 0 && members.Count == 0 && tests.Count == 0;
            var steps       = new List <TestStepData>();
            var testResults = new List <AutoTest.TestRunners.Shared.Results.TestResult>();

            // Get a test isolation context.  Here we want to run tests in the same AppDomain.
            var testIsolationProvider = (ITestIsolationProvider)RuntimeAccessor.ServiceLocator.ResolveByComponentId("Gallio.LocalTestIsolationProvider");
            var testIsolationOptions  = new TestIsolationOptions();
            ITestIsolationContext testIsolationContext = testIsolationProvider.CreateContext(testIsolationOptions, _logger);

            var testPackage = new TestPackage();

            testPackage.AddFile(new FileInfo(settings.Assembly.Assembly));
            testPackage.TestFrameworkFallbackMode = TestFrameworkFallbackMode.Strict;

            // Create some test exploration options.  Nothing interesting for you here, probably.
            var testExplorationOptions = new TestExplorationOptions();
            var messageSink            = new MessageConsumer()
                                         .Handle <TestStepStartedMessage>((message) =>
            {
                steps.Add(message.Step);
            })
                                         .Handle <TestStepFinishedMessage>(message =>
            {
                var test = steps.FirstOrDefault(x => x.Id.Equals(message.StepId) && x.IsTestCase);
                if (test == null)
                {
                    return;
                }
                var fixture = string.Format("{0}.{1}", test.CodeReference.NamespaceName, steps.First(x => x.Id.Equals(test.ParentId)).Name);
                testResults.Add(new AutoTest.TestRunners.Shared.Results.TestResult(
                                    "MbUnit",
                                    settings.Assembly.Assembly,
                                    fixture,
                                    message.Result.Duration.TotalMilliseconds,
                                    string.Format("{0}.{1}", fixture, test.Name),
                                    convertState(message.Result.Outcome.Status),
                                    message.Result.Outcome.DisplayName));
            });

            // Provide a progress monitor.
            var logProgressMonitorProvider = new LogProgressMonitorProvider(_logger);
            var options = new TestExecutionOptions();

            options.FilterSet = new Gallio.Model.Filters.FilterSet <ITestDescriptor>(new OrFilter <ITestDescriptor>(getTestFilter(namespaces, members, tests)));

            // Run the tests.
            logProgressMonitorProvider.Run((progressMonitor) =>
            {
                _testDriver.Run(testIsolationContext, testPackage, testExplorationOptions, options, messageSink, progressMonitor);
            });

            return(testResults);
        }
        public void TestResume()
        {
            int fileSizeInKB = 100 * 1024;
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            DMLibDataHelper.AddOneFile(sourceDataInfo.RootNode, DMLibTestBase.FileName, fileSizeInKB);

            CancellationTokenSource tokenSource = new CancellationTokenSource();

            TransferItem transferItem = null;
            var options = new TestExecutionOptions<DMLibDataInfo>();
            options.LimitSpeed = true;
            var transferContext = new TransferContext();
            var progressChecker = new ProgressChecker(1, fileSizeInKB * 1024, 0, 1, 0, fileSizeInKB * 1024);
            transferContext.ProgressHandler = progressChecker.GetProgressHandler();
            options.TransferItemModifier = (fileName, item) =>
                {
                    item.CancellationToken = tokenSource.Token;
                    item.TransferContext = transferContext;
                    transferItem = item;
                };

            TransferCheckpoint firstCheckpoint = null, secondCheckpoint = null;
            options.AfterAllItemAdded = () =>
                {
                    // Wait until there are data transferred
                    progressChecker.DataTransferred.WaitOne();

                    // Store the first checkpoint
                    firstCheckpoint = transferContext.LastCheckpoint;
                    Thread.Sleep(1000);

                    // Cancel the transfer and store the second checkpoint
                    tokenSource.Cancel();
                };

            // Cancel and store checkpoint for resume
            var result = this.ExecuteTestCase(sourceDataInfo, options);

            secondCheckpoint = transferContext.LastCheckpoint;

            Test.Assert(result.Exceptions.Count == 1, "Verify job is cancelled");
            Exception exception = result.Exceptions[0];
            VerificationHelper.VerifyExceptionErrorMessage(exception, "A task was canceled.");

            TransferCheckpoint firstResumeCheckpoint = null, secondResumeCheckpoint = null;
            ProgressChecker firstProgressChecker = null, secondProgressChecker = null;

            // DMLib doesn't support to resume transfer from a checkpoint which is inconsistent with
            // the actual transfer progress when the destination is an append blob.
            if (Helper.RandomBoolean() && (DMLibTestContext.DestType != DMLibDataType.AppendBlob || DMLibTestContext.IsAsync))
            {
                Test.Info("Resume with the first checkpoint first.");
                firstResumeCheckpoint = firstCheckpoint;
                secondResumeCheckpoint = secondCheckpoint;
            }
            else
            {
                Test.Info("Resume with the second checkpoint first.");
                firstResumeCheckpoint = secondCheckpoint;
                secondResumeCheckpoint = firstCheckpoint;
            }

            // first progress checker
            if (DMLibTestContext.SourceType == DMLibDataType.Stream && DMLibTestContext.DestType != DMLibDataType.BlockBlob)
            {
                // The destination is already created, will cause a transfer skip
                firstProgressChecker = new ProgressChecker(2, fileSizeInKB * 1024, 0, 1 /* failed */, 1 /* skipped */, fileSizeInKB * 1024);
            }
            else if (DMLibTestContext.DestType == DMLibDataType.Stream || (DMLibTestContext.SourceType == DMLibDataType.Stream && DMLibTestContext.DestType == DMLibDataType.BlockBlob))
            {
                firstProgressChecker = new ProgressChecker(2, 2 * fileSizeInKB * 1024, 1 /* transferred */, 1 /* failed */, 0, 2 * fileSizeInKB * 1024);
            }
            else
            {
                firstProgressChecker = new ProgressChecker(1, fileSizeInKB * 1024, 1, 0, 0, fileSizeInKB * 1024);
            }

            // second progress checker
            if (DMLibTestContext.SourceType == DMLibDataType.Stream)
            {
                // The destination is already created, will cause a transfer skip
                secondProgressChecker = new ProgressChecker(2, fileSizeInKB * 1024, 0, 1 /* failed */, 1 /* skipped */, fileSizeInKB * 1024);
            }
            else if (DMLibTestContext.DestType == DMLibDataType.Stream)
            {
                secondProgressChecker = new ProgressChecker(2, 2 * fileSizeInKB * 1024, 1 /* transferred */, 1 /* failed */, 0, 2 * fileSizeInKB * 1024);
            }
            else if (DMLibTestContext.DestType == DMLibDataType.AppendBlob && !DMLibTestContext.IsAsync)
            {
                secondProgressChecker = new ProgressChecker(1, fileSizeInKB * 1024, 0, 1 /* failed */, 0, fileSizeInKB * 1024);
            }
            else
            {
                secondProgressChecker = new ProgressChecker(1, fileSizeInKB * 1024, 1 /* transferred */, 0, 0, fileSizeInKB * 1024);
            }

            // resume with firstResumeCheckpoint
            TransferItem resumeItem = transferItem.Clone();
            TransferContext resumeContext = new TransferContext(
                IsStreamDirection() ? firstResumeCheckpoint : DMLibTestHelper.RandomReloadCheckpoint(firstResumeCheckpoint))
            {
                ProgressHandler = firstProgressChecker.GetProgressHandler()
            };

            resumeItem.TransferContext = resumeContext;

            result = this.RunTransferItems(new List<TransferItem>() { resumeItem }, new TestExecutionOptions<DMLibDataInfo>());

            if (DMLibTestContext.SourceType == DMLibDataType.Stream && DMLibTestContext.DestType != DMLibDataType.BlockBlob)
            {
                Test.Assert(result.Exceptions.Count == 1, "Verify transfer is skipped when source is stream.");
                exception = result.Exceptions[0];
                VerificationHelper.VerifyTransferException(result.Exceptions[0], TransferErrorCode.NotOverwriteExistingDestination, "Skiped file");
            }
            else
            {
                // For sync copy, recalculate md5 of destination by downloading the file to local.
                if (IsCloudService(DMLibTestContext.DestType) && !DMLibTestContext.IsAsync)
                {
                    DMLibDataHelper.SetCalculatedFileMD5(result.DataInfo, DestAdaptor);
                }

                VerificationHelper.VerifySingleObjectResumeResult(result, sourceDataInfo);
            }

            // resume with secondResumeCheckpoint
            resumeItem = transferItem.Clone();
            resumeContext = new TransferContext(
                IsStreamDirection() ? secondResumeCheckpoint : DMLibTestHelper.RandomReloadCheckpoint(secondResumeCheckpoint))
            {
                ProgressHandler = secondProgressChecker.GetProgressHandler()
            };
            resumeItem.TransferContext = resumeContext;

            result = this.RunTransferItems(new List<TransferItem>() { resumeItem }, new TestExecutionOptions<DMLibDataInfo>());

            if (DMLibTestContext.SourceType == DMLibDataType.Stream)
            {
                Test.Assert(result.Exceptions.Count == 1, "Verify transfer is skipped when source is stream.");
                exception = result.Exceptions[0];
                VerificationHelper.VerifyTransferException(result.Exceptions[0], TransferErrorCode.NotOverwriteExistingDestination, "Skiped file");
            }
            else if (DMLibTestContext.DestType == DMLibDataType.AppendBlob && !DMLibTestContext.IsAsync)
            {
                Test.Assert(result.Exceptions.Count == 1, "Verify reumse fails when checkpoint is inconsistent with the actual progress when destination is append blob.");
                exception = result.Exceptions[0];
                Test.Assert(exception is InvalidOperationException, "Verify reumse fails when checkpoint is inconsistent with the actual progress when destination is append blob.");
                VerificationHelper.VerifyExceptionErrorMessage(exception, "Destination might be changed by other process or application.");
            }
            else
            {
                // For sync copy, recalculate md5 of destination by downloading the file to local.
                if (IsCloudService(DMLibTestContext.DestType) && !DMLibTestContext.IsAsync)
                {
                    DMLibDataHelper.SetCalculatedFileMD5(result.DataInfo, DestAdaptor);
                }

                VerificationHelper.VerifySingleObjectResumeResult(result, sourceDataInfo);
            }
        }
        public void DirectoryOverwriteDestination()
        {
            string destExistYName = "destExistY";
            string destExistNName = "destExistN";
            string destNotExistYName = "destNotExistY";

            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, destExistYName, 1024);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, destExistNName, 1024);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, destNotExistYName, 1024);

            DMLibDataInfo destDataInfo = new DMLibDataInfo(string.Empty);
            DMLibDataHelper.AddOneFileInBytes(destDataInfo.RootNode, destExistYName, 1024);
            DMLibDataHelper.AddOneFileInBytes(destDataInfo.RootNode, destExistNName, 1024);

            TransferContext transferContext = new TransferContext();
            transferContext.OverwriteCallback = (string sourcePath, string destinationPath) =>
            {
                if (sourcePath.EndsWith(destExistNName))
                {
                    return false;
                }
                else
                {
                    return true;
                }
            };

            int skipCount = 0;
            int successCount = 0;
            transferContext.FileSkipped += (object sender, TransferEventArgs args) =>
            {
                Interlocked.Increment(ref skipCount);
                TransferException transferException = args.Exception as TransferException;
                Test.Assert(transferException != null, "Verify the exception is a TransferException");

                VerificationHelper.VerifyTransferException(transferException, TransferErrorCode.NotOverwriteExistingDestination,
                    "Skiped file", destExistNName);
            };

            transferContext.FileTransferred += (object sender, TransferEventArgs args) =>
            {
                Interlocked.Increment(ref successCount);
            };

            var options = new TestExecutionOptions<DMLibDataInfo>();
            options.IsDirectoryTransfer = true;
            if (DMLibTestContext.DestType != DMLibDataType.Stream)
            {
                options.DestTransferDataInfo = destDataInfo;
            }

            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                transferItem.TransferContext = transferContext;

                dynamic transferOptions = DefaultTransferDirectoryOptions;
                transferOptions.Recursive = true;
                transferItem.Options = transferOptions;
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            DMLibDataInfo expectedDataInfo = new DMLibDataInfo(string.Empty);
            if (DMLibTestContext.DestType != DMLibDataType.Stream)
            {
                expectedDataInfo.RootNode.AddFileNode(sourceDataInfo.RootNode.GetFileNode(destExistYName));
                expectedDataInfo.RootNode.AddFileNode(destDataInfo.RootNode.GetFileNode(destExistNName));
                expectedDataInfo.RootNode.AddFileNode(sourceDataInfo.RootNode.GetFileNode(destNotExistYName));
            }
            else
            {
                expectedDataInfo = sourceDataInfo;
            }

            // Verify transfer result
            Test.Assert(DMLibDataHelper.Equals(expectedDataInfo, result.DataInfo), "Verify transfer result.");

            // Verify exception
            if (DMLibTestContext.DestType != DMLibDataType.Stream)
            {
                Test.Assert(successCount == 2, "Verify success transfers");
                Test.Assert(skipCount == 1, "Verify skipped transfer");
            }
            else
            {
                Test.Assert(successCount == 3, "Very all transfers are success");
                Test.Assert(skipCount == 0, "Very no transfer is skipped");
            }
        }
Beispiel #37
0
 public void RunTests(TestExecutionTask[] testExecutionTasks, TestExecutionOptions options)
 {
     TestService.RunTests(testExecutionTasks, options);
 }
        private void TestSearchPatternError(bool recursive, string searchPattern, string expectedErrorMessage)
        {
            var options = new TestExecutionOptions<DMLibDataInfo>()
            {
                IsDirectoryTransfer = true,
                TransferItemModifier = (notUsed, item) =>
                {
                    dynamic transferOptions = DefaultTransferDirectoryOptions;
                    transferOptions.Recursive = recursive;
                    transferOptions.SearchPattern = searchPattern;
                    item.Options = transferOptions;
                },
            };

            var testResult = this.ExecuteTestCase(null, options);

            if (testResult.Exceptions.Count != 1)
            {
                Test.Error("Should be exactly one exception, actual: {0}", testResult.Exceptions.Count);
            }

            VerificationHelper.VerifyExceptionErrorMessage(testResult.Exceptions[0], expectedErrorMessage);
        }
Beispiel #39
0
        private void TestDirectoryCheckContentMD5StreamResume(bool checkMD5)
        {
            long   fileSize       = 5 * 1024;
            int    fileCountMulti = 32;
            long   totalSize      = fileSize * 4 * fileCountMulti;
            string wrongMD5       = "wrongMD5";

            string wrongMD5File   = "wrongMD5File";
            string correctMD5File = "correctMD5File";

            // Prepare data for transfer items with checkMD5
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            DirNode       checkMD5Folder = new DirNode(checkMD5 ? "checkMD5" : "notCheckMD5");

            for (int i = 0; i < fileCountMulti; ++i)
            {
                var wrongMD5FileNode = new FileNode($"{wrongMD5File}_{i}")
                {
                    SizeInByte = fileSize,
                    MD5        = wrongMD5
                };

                checkMD5Folder.AddFileNode(wrongMD5FileNode);

                DMLibDataHelper.AddOneFileInBytes(checkMD5Folder, $"{correctMD5File}_{i}", fileSize);
            }
            sourceDataInfo.RootNode.AddDirNode(checkMD5Folder);

            SourceAdaptor.GenerateData(sourceDataInfo);
            DestAdaptor.Cleanup();

            TransferEventChecker    eventChecker            = new TransferEventChecker();
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            using (var resumeStream = new MemoryStream())
            {
                TransferContext context = new DirectoryTransferContext(resumeStream);
                eventChecker.Apply(context);

                ProgressChecker progressChecker = new ProgressChecker(2 * fileCountMulti,
                                                                      totalSize, checkMD5 ? fileCountMulti : 2 * fileCountMulti, null, 0, totalSize);

                context.ProgressHandler = progressChecker.GetProgressHandler();
                List <Exception> transferExceptions = new List <Exception>();

                TransferItem checkMD5Item = new TransferItem()
                {
                    SourceObject        = SourceAdaptor.GetTransferObject(sourceDataInfo.RootPath, checkMD5Folder),
                    DestObject          = DestAdaptor.GetTransferObject(sourceDataInfo.RootPath, checkMD5Folder),
                    IsDirectoryTransfer = true,
                    SourceType          = DMLibTestContext.SourceType,
                    DestType            = DMLibTestContext.DestType,
                    IsServiceCopy       = DMLibTestContext.IsAsync,
                    TransferContext     = context,
                    Options             = new DownloadDirectoryOptions()
                    {
                        DisableContentMD5Validation = !checkMD5,
                        Recursive = true,
                    },
                    CancellationToken = cancellationTokenSource.Token,
                };

                var executionOption = new TestExecutionOptions <DMLibDataInfo>();
                executionOption.AfterAllItemAdded = () =>
                {
                    // Wait until there are data transferred
                    if (!progressChecker.DataTransferred.WaitOne(30000))
                    {
                        Test.Error("No progress in 30s.");
                    }

                    // Cancel the transfer and store the second checkpoint
                    cancellationTokenSource.Cancel();
                };
                executionOption.LimitSpeed = true;

                var testResult = this.RunTransferItems(new List <TransferItem>()
                {
                    checkMD5Item
                }, executionOption);

                if (null != testResult.Exceptions)
                {
                    foreach (var exception in testResult.Exceptions)
                    {
                        Test.Info("Got exception during transferring. {0}", exception);
                    }
                }

                eventChecker          = new TransferEventChecker();
                resumeStream.Position = 0;
                context = new DirectoryTransferContext(resumeStream);
                eventChecker.Apply(context);

                bool failureReported = false;
                context.FileFailed += (sender, args) =>
                {
                    if (args.Exception != null)
                    {
                        failureReported = args.Exception.Message.Contains(wrongMD5File);
                    }

                    transferExceptions.Add(args.Exception);
                };

                progressChecker.Reset();
                context.ProgressHandler = progressChecker.GetProgressHandler();

                checkMD5Item = checkMD5Item.Clone();

                checkMD5Item.TransferContext = context;

                testResult = this.RunTransferItems(new List <TransferItem>()
                {
                    checkMD5Item
                }, new TestExecutionOptions <DMLibDataInfo>());

                DMLibDataInfo expectedDataInfo = sourceDataInfo.Clone();
                DMLibDataInfo actualDataInfo   = testResult.DataInfo;
                for (int i = 0; i < fileCountMulti; ++i)
                {
                    expectedDataInfo.RootNode.GetDirNode(checkMD5Folder.Name).DeleteFileNode($"{wrongMD5File}_{i}");
                    actualDataInfo.RootNode.GetDirNode(checkMD5Folder.Name).DeleteFileNode($"{wrongMD5File}_{i}");
                }

                Test.Assert(DMLibDataHelper.Equals(expectedDataInfo, actualDataInfo), "Verify transfer result.");
                Test.Assert(checkMD5 ? failureReported : !failureReported, "Verify md5 check failure is expected.");
                VerificationHelper.VerifyFinalProgress(progressChecker, checkMD5 ? fileCountMulti : 2 * fileCountMulti, 0, checkMD5 ? fileCountMulti : 0);

                if (checkMD5)
                {
                    if (testResult.Exceptions.Count != 0 || transferExceptions.Count != fileCountMulti)
                    {
                        Test.Error("Expect one exception but actually no exception is thrown.");
                    }
                    else
                    {
                        for (int i = 0; i < fileCountMulti; ++i)
                        {
                            VerificationHelper.VerifyExceptionErrorMessage(transferExceptions[i], new string[] { "The MD5 hash calculated from the downloaded data does not match the MD5 hash stored in the property of source" });
                        }
                    }
                }
                else
                {
                    Test.Assert(testResult.Exceptions.Count == 0, "Should no exception thrown out when disabling check md5");
                }
            }
        }
        public void TestDirectoryNotIncludeSnapshots()
        {
            string snapshotFile1 = "snapshotFile1";
            string snapshotFile2 = "snapshotFile2";
            string snapshotFile3 = "snapshotFile3";

            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, snapshotFile1, 1024);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, snapshotFile2, 1024);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, snapshotFile3, 1024);

            // the 1st file has 1 snapshot
            FileNode fileNode1 = sourceDataInfo.RootNode.GetFileNode(snapshotFile1);
            fileNode1.SnapshotsCount = 1;

            // the 2nd file has 2 snapshots
            FileNode fileNode2 = sourceDataInfo.RootNode.GetFileNode(snapshotFile2);
            fileNode2.SnapshotsCount = 2;

            var options = new TestExecutionOptions<DMLibDataInfo>();
            options.IsDirectoryTransfer = true;

            // transfer with default options, or IncludeSnapshots = false
            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                dynamic dirOptions = DefaultTransferDirectoryOptions;
                dirOptions.Recursive = true;

                if (random.Next(0, 2) == 0)
                {
                    Test.Info("Transfer directory with IncludeSnapshots=false");
                    dirOptions.IncludeSnapshots = false;
                }
                else
                {
                    Test.Info("Transfer directory with defaullt IncludeSnapshots");
                }

                transferItem.Options = dirOptions;
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            // verify that only non-snapshot blobs are transferred

            DMLibDataInfo expectedDataInfo = new DMLibDataInfo(string.Empty);
            expectedDataInfo.RootNode.AddFileNode(fileNode1);
            expectedDataInfo.RootNode.AddFileNode(fileNode2);
            expectedDataInfo.RootNode.AddFileNode(sourceDataInfo.RootNode.GetFileNode(snapshotFile3));
            Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown.");
            Test.Assert(DMLibDataHelper.Equals(expectedDataInfo, result.DataInfo), "Verify transfer result.");
        }
 public MSTestRunner(TestExecutionOptions options)
     : base(new MSTestProcessRunnerContext(options))
 {
 }
        public void OverwriteDestination()
        {
            string destExistYName = "destExistY";
            string destExistNName = "destExistN";
            string destNotExistYName = "destNotExistY";

            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, destExistYName, 1024);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, destExistNName, 1024);
            DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, destNotExistYName, 1024);

            DMLibDataInfo destDataInfo = new DMLibDataInfo(string.Empty);
            DMLibDataHelper.AddOneFileInBytes(destDataInfo.RootNode, destExistYName, 1024);
            DMLibDataHelper.AddOneFileInBytes(destDataInfo.RootNode, destExistNName, 1024);

            var options = new TestExecutionOptions<DMLibDataInfo>();
            if (DMLibTestContext.DestType != DMLibDataType.Stream)
            {
                options.DestTransferDataInfo = destDataInfo;
            }

            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                string fileName = fileNode.Name;
                TransferContext transferContext = new TransferContext();

                if (fileName.Equals(destExistYName))
                {
                    transferContext.OverwriteCallback = DMLibInputHelper.GetDefaultOverwiteCallbackY();
                }
                else if (fileName.Equals(destExistNName))
                {
                    transferContext.OverwriteCallback = DMLibInputHelper.GetDefaultOverwiteCallbackN();
                }
                else if (fileName.Equals(destNotExistYName))
                {
                    transferContext.OverwriteCallback = DMLibInputHelper.GetDefaultOverwiteCallbackY();
                }

                transferItem.TransferContext = transferContext;
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            DMLibDataInfo expectedDataInfo = new DMLibDataInfo(string.Empty);
            if (DMLibTestContext.DestType != DMLibDataType.Stream)
            {
                expectedDataInfo.RootNode.AddFileNode(sourceDataInfo.RootNode.GetFileNode(destExistYName));
                expectedDataInfo.RootNode.AddFileNode(destDataInfo.RootNode.GetFileNode(destExistNName));
                expectedDataInfo.RootNode.AddFileNode(sourceDataInfo.RootNode.GetFileNode(destNotExistYName));
            }
            else
            {
                expectedDataInfo = sourceDataInfo;
            }

            // Verify transfer result
            Test.Assert(DMLibDataHelper.Equals(expectedDataInfo, result.DataInfo), "Verify transfer result.");

            // Verify exception
            if (DMLibTestContext.DestType != DMLibDataType.Stream)
            {
                Test.Assert(result.Exceptions.Count == 1, "Verify there's only one exceptions.");
                TransferException transferException = result.Exceptions[0] as TransferException;
                Test.Assert(transferException != null, "Verify the exception is a TransferException");

                VerificationHelper.VerifyTransferException(transferException, TransferErrorCode.NotOverwriteExistingDestination,
                    "Skiped file", destExistNName);
            }
        }
Beispiel #43
0
        protected override TestReport RunTests(TestItem testItem, bool isCovering, bool isDebugging)
        {
            List <TestResult> testResults = new List <TestResult>();

            try
            {
                var sessionId       = _sessionId++;
                var outputDirectory = _storageController.CreateTestRunDirectory();

                var testMethods = testItem
                                  .Flatten(p => p.Children)
                                  .OfType <TestMethod>()
                                  .Where(p => p.Case != null)
                                  .ToArray();

                var testExecutionTasks = testMethods
                                         .GroupBy(p => p.TestAdapterName)
                                         .Distinct()
                                         .Select(p => new TestExecutionTask()
                {
                    TestCases          = p.Where(q => q.Case != null).Select(q => q.Case).ToArray(),
                    TestAdapterOptions = _testAdapterRepository.Adapters[p.Key]
                                         .GetLoadingOptions()
                                         .Do(q => q.IsRedirectingAssemblies = _options.IsRedirectingFrameworkAssemblies)
                })
                                         .ToArray();

                var testMethodsById = testMethods.ToDictionary(p => p.Case.Id);

                IHostProcessInfo hostProcessInfo = null;

                var solution = testItem.GetParent <TestSolution>();
                if (isCovering)
                {
                    var openCoverOptions = new OpenCoverOptions()
                    {
                        CodeAssemblies                = solution.CodeAssemblies,
                        TestAssemblies                = solution.TestAssemblies,
                        CoverageReportPath            = Path.Combine(outputDirectory, "coverageReport.xml"),
                        IsCoveringByTest              = _options.IsCoveringByTest,
                        IsIncludingSolutionAssemblies = _options.IsIncludingSolutionAssemblies,
                        IsExcludingTestAssemblies     = _options.IsExcludingTestAssemblies,
                        IsMergingByHash               = _options.IsMergingByHash,
                        IsSkippingAutoProps           = _options.IsSkippingAutoProps,
                        ExcludeAttributes             = _options.ExcludeAttributes,
                        ExcludeDirectories            = _options.ExcludeDirectories,
                        ExcludeFiles          = _options.ExcludeFiles,
                        Filters               = _options.Filters,
                        IsVisitorCountLimited = _options.IsVisitorCountLimited,
                        VisitorCountLimit     = _options.VisitorCountLimit,
                        PdbDirectories        = solution.Children.OfType <TestProject>().Select(p => p.OutputDirectory),
                        RegisterAs            = !string.IsNullOrWhiteSpace(_options.RegisterAs) ? _options.RegisterAs :
                                                new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator) ? "administrator" : "user"
                    };
                    hostProcessInfo = new OpenCoverProcessInfo(openCoverOptions);
                }

                _executionProcess = ExecutionProcess.Create(AdapterExtensions.GetTestPlatformAssemblyPaths(_options.TestAdapterMode), hostProcessInfo, _options);
                _executionProcess.MessageReceived += (o, e) => OnTestLogAdded(e.Value);
                _executionProcess.TestStarted     += (o, e) =>
                {
                    var testMethod = testMethodsById.TryGetValue(e.Value.Id);
                    if (testMethod != null)
                    {
                        OnTestStarted(testMethod);
                    }
                };
                _executionProcess.TestResult += (o, e) =>
                {
                    var testMethod = testMethodsById.TryGetValue(e.Value.TestCase.Id);
                    if (testMethod != null)
                    {
                        var testResult = e.Value.ToTestResult(testMethod, sessionId);
                        testResults.Add(testResult);
                        OnTestExecuted(testResult);
                    }
                };
                _executionProcess.OutputReceived += (o, e) => OnTestLogAdded(e.Value);

                if (isDebugging)
                {
                    var debuggerAttachedEvent = new ManualResetEvent(false);
                    _executionProcess.DebuggerAttached += (o, e) => debuggerAttachedEvent.Set();

                    OnTestLogAdded(Resources.DebuggerAttaching);
                    if (_editorContext.AttachToProcess(_executionProcess.ProcessId) &&
                        debuggerAttachedEvent.WaitOne(TimeSpan.FromSeconds(_options.DebuggerTimeout)))
                    {
                        OnTestLogAdded(Resources.DebuggerAttached);
                        OnDebuggingStarted();
                    }
                    else
                    {
                        OnTestLogAdded(Resources.DebuggerFailedToAttach);
                    }
                }

                var options = new TestExecutionOptions()
                {
                    RunSettingsPath = _ioProvider.GetAbsolutePath(_options.TestSettings),
                    ApartmentState  = _options.TestApartmentState,
                    OutputPath      = outputDirectory,
                    SolutionPath    = solution.FilePath
                };

                _executionProcess.RunTests(testExecutionTasks, options);

                if (!_isAborting)
                {
                    if (isDebugging)
                    {
                        _editorContext.DetachFromProcess(_executionProcess.ProcessId);
                    }

                    OnTestLogAdded(Resources.ShuttingDown);
                    if (!_executionProcess.TryShutdown())
                    {
                        OnTestLogAdded(Resources.ShutdownFailed);
                    }
                    if (isCovering)
                    {
                        OnTestLogAdded(Resources.GeneratingCoverageReport);
                    }
                }

                _executionProcess.WaitForExit();

                if (_isAborting)
                {
                    return(null);
                }

                if (isCovering)
                {
                    var coverageReportPath = (hostProcessInfo as OpenCoverProcessInfo).CoverageReportPath;
                    if (System.IO.File.Exists(coverageReportPath))
                    {
                        var coverageReport = GenericExtensions.ParseXml <CoverageSession>(coverageReportPath);
                        return(new TestReport(testResults, coverageReport));
                    }
                }
                else
                {
                    return(new TestReport(testResults, null));
                }
            }
            catch (RemoteException exception) when(exception.RemoteReason != null)
            {
                _telemetryManager.UploadExceptionAsync(exception.RemoteReason);
                throw;
            }
            finally
            {
                if (_executionProcess != null)
                {
                    _executionProcess.Dispose();
                    _executionProcess = null;
                }
            }

            return(null);
        }
        public void TestDirectoryWithSpecialCharNamedBlobs()
        {
#if DNXCORE50
            // TODO: There's a known issue that signature for URI with '[' or ']' doesn't work.
            string specialChars = "~`!@#$%()-_+={};?.^&";
#else
            string specialChars = "~`!@#$%()-_+={}[];?.^&";
#endif
            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);

            var subDirWithDot = new DirNode(DMLibTestBase.FolderName + "." + DMLibTestBase.FolderName);

            for (int i = 0; i < specialChars.Length; ++i)
            {
                string fileName = DMLibTestBase.FileName + specialChars[i] + DMLibTestBase.FileName;

                if (random.Next(2) == 0)
                {
                    if ((specialChars[i] != '.') &&
                        (random.Next(2) == 0))
                    {
                        string folderName = DMLibTestBase.FolderName + specialChars[i] + DMLibTestBase.FolderName;

                        var subDir = new DirNode(folderName);
                        DMLibDataHelper.AddOneFileInBytes(subDir, fileName, 1024);
                        FileNode fileNode1 = subDir.GetFileNode(fileName);
                        fileNode1.SnapshotsCount = 1;

                        sourceDataInfo.RootNode.AddDirNode(subDir);
                    }
                    else
                    {
                        DMLibDataHelper.AddOneFileInBytes(subDirWithDot, fileName, 1024);
                        FileNode fileNode1 = subDirWithDot.GetFileNode(fileName);
                        fileNode1.SnapshotsCount = 1;
                    }
                }
                else
                {
                    DMLibDataHelper.AddOneFileInBytes(sourceDataInfo.RootNode, fileName, 1024);
                    FileNode fileNode1 = sourceDataInfo.RootNode.GetFileNode(fileName);
                    fileNode1.SnapshotsCount = 1;
                }
            }

            sourceDataInfo.RootNode.AddDirNode(subDirWithDot);

            var options = new TestExecutionOptions <DMLibDataInfo>();
            options.IsDirectoryTransfer = true;

            // transfer with IncludeSnapshots = true
            options.TransferItemModifier = (fileNode, transferItem) =>
            {
                dynamic dirOptions = DefaultTransferDirectoryOptions;
                dirOptions.Recursive        = true;
                dirOptions.IncludeSnapshots = true;
                transferItem.Options        = dirOptions;
            };

            var result = this.ExecuteTestCase(sourceDataInfo, options);

            // verify that snapshots are transferred
            Test.Assert(result.Exceptions.Count == 0, "Verify no exception is thrown.");
            Test.Assert(DMLibDataHelper.Equals(sourceDataInfo, result.DataInfo), "Verify transfer result.");
        }
 internal CachingTestExecutor(TestExecutionOptions options, ITestExecutor testExecutor, IDataStorage dataStorage)
 {
     _testExecutor = testExecutor;
     _dataStorage  = dataStorage;
     _contentUtil  = new ContentUtil(options);
 }
        public void ResumeInAllDirections()
        {
            List<TransferItem> allItems = AllTransferDirectionTest.GetTransformItemsForAllDirections(resume: true);

            int fileCount = expectedFileNodes.Keys.Count;

            // Execution and store checkpoints
            CancellationTokenSource tokenSource = new CancellationTokenSource();

            var transferContext = new TransferContext();
            var progressChecker = new ProgressChecker(fileCount, 1024 * fileCount);
            transferContext.ProgressHandler = progressChecker.GetProgressHandler();
            allItems.ForEach(item =>
            {
                item.CancellationToken = tokenSource.Token;
                item.TransferContext = transferContext;
            });

            var options = new TestExecutionOptions<DMLibDataInfo>();
            options.DisableDestinationFetch = true;

            // Checkpoint names
            const string PartialStarted = "PartialStarted",
                         AllStarted = "AllStarted",
                         AllStartedAndWait = "AllStartedAndWait",
                         BeforeCancel = "BeforeCancel",
                         AfterCancel = "AfterCancel";
            Dictionary<string, TransferCheckpoint> checkpoints = new Dictionary<string, TransferCheckpoint>();

            TransferItem randomItem = allItems[random.Next(0, allItems.Count)];

            randomItem.AfterStarted = () =>
            {
                Test.Info("Store check point after transfer item: {0}.", randomItem.ToString());
                checkpoints.Add(PartialStarted, transferContext.LastCheckpoint);
            };

            options.AfterAllItemAdded = () =>
                {
                    progressChecker.DataTransferred.WaitOne();
                    checkpoints.Add(AllStarted, transferContext.LastCheckpoint);
                    Thread.Sleep(1000);
                    checkpoints.Add(AllStartedAndWait, transferContext.LastCheckpoint);
                    Thread.Sleep(1000);
                    checkpoints.Add(BeforeCancel, transferContext.LastCheckpoint);
                    tokenSource.Cancel();
                    checkpoints.Add(AfterCancel, transferContext.LastCheckpoint);
                };

            var result = this.RunTransferItems(allItems, options);

            // Resume with stored checkpoints in random order
            var checkpointList = new List<KeyValuePair<string,TransferCheckpoint>>();
            checkpointList.AddRange(checkpoints);
            checkpointList.Shuffle();

            foreach(var pair in checkpointList)
            {
                Test.Info("===Resume with checkpoint '{0}'===", pair.Key);
                options = new TestExecutionOptions<DMLibDataInfo>();
                options.DisableDestinationFetch = true;

                progressChecker.Reset();
                transferContext = new TransferContext(DMLibTestHelper.RandomReloadCheckpoint(pair.Value))
                {
                    ProgressHandler = progressChecker.GetProgressHandler(),

                    // The checkpoint can be stored when DMLib doesn't check overwrite callback yet.
                    // So it will case an skip file error if the desination file already exists and 
                    // We don't have overwrite callback here.
                    OverwriteCallback = DMLibInputHelper.GetDefaultOverwiteCallbackY()
                };

                TransferEventChecker eventChecker = new TransferEventChecker();
                eventChecker.Apply(transferContext);

                List<TransferItem> itemsToResume = allItems.Select(item =>
                {
                    TransferItem itemToResume = item.Clone();
                    itemToResume.TransferContext = transferContext;
                    return itemToResume;
                }).ToList();

                result = this.RunTransferItems(itemsToResume, options);

                foreach (DMLibDataType destDataType in DataTypes)
                {
                    DataAdaptor<DMLibDataInfo> destAdaptor = GetSourceAdaptor(destDataType);
                    DMLibDataInfo destDataInfo = destAdaptor.GetTransferDataInfo(string.Empty);

                    foreach (FileNode destFileNode in destDataInfo.EnumerateFileNodes())
                    {
                        string fileName = destFileNode.Name;
                        FileNode sourceFileNode = expectedFileNodes[fileName];
                        Test.Assert(DMLibDataHelper.Equals(sourceFileNode, destFileNode), "Verify transfer result.");
                    }
                }

                Test.Assert(result.Exceptions.Count == 0, "Verify no error happens. Actual: {0}", result.Exceptions.Count);
            }
        }
        public void TestDirectoryResume()
        {
            int bigFileSizeInKB = 5 * 1024; // 5 MB
            int smallFileSizeInKB = 1; // 1 KB
            int bigFileNum = 5;
            int smallFileNum = 50;
            long totalSizeInBytes = (bigFileSizeInKB * bigFileNum + smallFileSizeInKB * smallFileNum) * 1024;
            int totalFileNum = bigFileNum + smallFileNum;

            DMLibDataInfo sourceDataInfo = new DMLibDataInfo(string.Empty);
            DirNode bigFileDirNode = new DirNode("big");
            DirNode smallFileDirNode = new DirNode("small");

            sourceDataInfo.RootNode.AddDirNode(bigFileDirNode);
            sourceDataInfo.RootNode.AddDirNode(smallFileDirNode);

            DMLibDataHelper.AddMultipleFiles(bigFileDirNode, FileName, bigFileNum, bigFileSizeInKB);
            DMLibDataHelper.AddMultipleFiles(smallFileDirNode, FileName, smallFileNum, smallFileSizeInKB);

            CancellationTokenSource tokenSource = new CancellationTokenSource();

            TransferItem transferItem = null;
            var options = new TestExecutionOptions<DMLibDataInfo>();
            options.LimitSpeed = true;
            options.IsDirectoryTransfer = true;

            var transferContext = new TransferContext();
            var progressChecker = new ProgressChecker(totalFileNum, totalSizeInBytes, totalFileNum, null, 0, totalSizeInBytes);
            transferContext.ProgressHandler = progressChecker.GetProgressHandler();
            var eventChecker = new TransferEventChecker();
            eventChecker.Apply(transferContext);

            transferContext.FileFailed += (sender, e) =>
            {
                Test.Assert(e.Exception.Message.Contains("cancel"), "Verify task is canceled: {0}", e.Exception.Message);
            };

            options.TransferItemModifier = (fileName, item) =>
            {
                dynamic dirOptions = DefaultTransferDirectoryOptions;
                dirOptions.Recursive = true;

                item.Options = dirOptions;
                item.CancellationToken = tokenSource.Token;
                item.TransferContext = transferContext;
                transferItem = item;
            };

            TransferCheckpoint firstCheckpoint = null, secondCheckpoint = null;
            options.AfterAllItemAdded = () =>
            {
                // Wait until there are data transferred
                progressChecker.DataTransferred.WaitOne();

                // Store the first checkpoint
                firstCheckpoint = transferContext.LastCheckpoint;
                Thread.Sleep(1000);

                // Cancel the transfer and store the second checkpoint
                tokenSource.Cancel();
            };

            // Cancel and store checkpoint for resume
            var result = this.ExecuteTestCase(sourceDataInfo, options);

            secondCheckpoint = transferContext.LastCheckpoint;

            if (progressChecker.FailedFilesNumber <= 0)
            {
                Test.Error("Verify file number in progress. Failed: {0}", progressChecker.FailedFilesNumber);
            }

            TransferCheckpoint firstResumeCheckpoint = null, secondResumeCheckpoint = null;

            Test.Info("Resume with the second checkpoint first.");
            firstResumeCheckpoint = secondCheckpoint;
            secondResumeCheckpoint = firstCheckpoint;

            // resume with firstResumeCheckpoint
            TransferItem resumeItem = transferItem.Clone();

            progressChecker.Reset();
            TransferContext resumeContext = new TransferContext(DMLibTestHelper.RandomReloadCheckpoint(firstResumeCheckpoint))
            {
                ProgressHandler = progressChecker.GetProgressHandler()
            };

            eventChecker.Reset();
            eventChecker.Apply(resumeContext);

            resumeItem.TransferContext = resumeContext;

            result = this.RunTransferItems(new List<TransferItem>() { resumeItem }, new TestExecutionOptions<DMLibDataInfo>());

            VerificationHelper.VerifyFinalProgress(progressChecker, totalFileNum, 0, 0);
            VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);

            // resume with secondResumeCheckpoint
            resumeItem = transferItem.Clone();

            progressChecker.Reset();
            resumeContext = new TransferContext(DMLibTestHelper.RandomReloadCheckpoint(secondResumeCheckpoint))
            {
                ProgressHandler = progressChecker.GetProgressHandler(),

                // Need this overwrite callback since some files is already transferred to destination
                OverwriteCallback = DMLibInputHelper.GetDefaultOverwiteCallbackY(),
            };

            eventChecker.Reset();
            eventChecker.Apply(resumeContext);

            resumeItem.TransferContext = resumeContext;

            result = this.RunTransferItems(new List<TransferItem>() { resumeItem }, new TestExecutionOptions<DMLibDataInfo>());

            VerificationHelper.VerifyFinalProgress(progressChecker, totalFileNum, 0, 0);
            VerificationHelper.VerifyTransferSucceed(result, sourceDataInfo);
        }