Example #1
0
        private void RunMergeTest(string target)
        {
            var working      = Path.Combine(Path.GetTempPath(), "working");
            var artefact     = Path.Combine(Path.GetTempPath(), "artefact");
            var label        = "1.2.3.4";
            var targetFolder = Path.Combine(
                Path.Combine(artefact, label),
                target ?? string.Empty);

            // Mock the logger
            var logger = mocks.StrictMock <ILogger>();

            Expect.Call(() => { logger.Info(""); }).IgnoreArguments().Repeat.AtLeastOnce();
            Expect.Call(() => { logger.Warning(""); }).IgnoreArguments().Repeat.AtLeastOnce();

            // Mock the file system
            var fileSystem = mocks.StrictMock <IFileSystem>();

            Expect.Call(fileSystem.FileExists(Path.Combine(working, "text.xml"))).Return(true);
            Expect.Call(fileSystem.FileExists(Path.Combine(working, "text.xml"))).Return(true);
            Expect.Call(fileSystem.FileExists(Path.Combine(working, "text.txt"))).Return(true);
            Expect.Call(fileSystem.FileExists(Path.Combine(working, "blank.txt"))).Return(false);
            Expect.Call(() => { fileSystem.EnsureFolderExists(targetFolder); });
            Expect.Call(() =>
            {
                fileSystem.Copy(
                    Path.Combine(working, "text.txt"),
                    Path.Combine(targetFolder, "text.txt"));
            });

            // Initialise the task
            var task = new MergeFilesTask
            {
                Logger       = logger,
                FileSystem   = fileSystem,
                TargetFolder = target
            };

            task.MergeFiles = new MergeFileInfo[] {
                new MergeFileInfo {
                    FileName = "text.xml", MergeAction = MergeFileInfo.MergeActionType.Merge
                },
                new MergeFileInfo {
                    FileName = "text.txt", MergeAction = MergeFileInfo.MergeActionType.Copy
                },
                new MergeFileInfo {
                    FileName = "blank.txt", MergeAction = MergeFileInfo.MergeActionType.Copy
                }
            };

            // Mock the result
            var result = mocks.StrictMock <IIntegrationResult>();

            Expect.Call(() =>
            {
                result.AddTaskResult((ITaskResult)null);
            }).IgnoreArguments();
            Expect.Call(result.Status).PropertyBehavior();
            Expect.Call(result.Succeeded).Return(true);

            var buildProgress = mocks.StrictMock <BuildProgressInformation>(artefact, "Project1");

            SetupResult.For(result.BuildProgressInformation)
            .Return(buildProgress);
            SetupResult.For(result.WorkingDirectory).Return(working);
            SetupResult.For(result.ArtifactDirectory).Return(artefact);
            SetupResult.For(result.Label).Return(label);
            Expect.Call(() => { buildProgress.SignalStartRunTask("Merging Files"); });
            buildProgress.Expect(bpi => bpi.AddTaskInformation(null)).IgnoreArguments();
            buildProgress.Expect(bpi => bpi.AddTaskInformation(null)).IgnoreArguments();

            //var testFile = new FileInfo(Path.Combine(working, "text.xml"));
            //Expect.Call(fileSystem.FileExists(testFile.FullName)).Return(true);
            //Expect.Call(() =>
            //                {
            //                    result.AddTaskResult(new FileTaskResult(
            //                                             testFile, false,
            //                                             fileSystem) {WrapInCData = false});
            //                });

            // Run the test
            mocks.ReplayAll();
            result.Status = IntegrationStatus.Unknown;
            task.Run(result);

            // Check the results
            mocks.VerifyAll();
        }
Example #2
0
        private void RunMergeTest(string target)
        {
            var working      = Path.Combine(Path.GetTempPath(), "working");
            var artefact     = Path.Combine(Path.GetTempPath(), "artefact");
            var label        = "1.2.3.4";
            var targetFolder = Path.Combine(
                Path.Combine(artefact, label),
                target ?? string.Empty);

            // Mock the logger
            var logger = mocks.Create <ILogger>(MockBehavior.Strict).Object;

            Mock.Get(logger).Setup(_logger => _logger.Info(It.IsAny <string>(), It.IsAny <object[]>())).Verifiable();
            Mock.Get(logger).Setup(_logger => _logger.Warning(It.IsAny <string>(), It.IsAny <object[]>())).Verifiable();

            // Mock the file system
            var fileSystem = mocks.Create <IFileSystem>(MockBehavior.Strict).Object;

            Mock.Get(fileSystem).Setup(_fileSystem => _fileSystem.FileExists(Path.Combine(working, "text.xml"))).Returns(true).Verifiable();
            Mock.Get(fileSystem).Setup(_fileSystem => _fileSystem.FileExists(Path.Combine(working, "text.xml"))).Returns(true).Verifiable();
            Mock.Get(fileSystem).Setup(_fileSystem => _fileSystem.FileExists(Path.Combine(working, "text.txt"))).Returns(true).Verifiable();
            Mock.Get(fileSystem).Setup(_fileSystem => _fileSystem.FileExists(Path.Combine(working, "blank.txt"))).Returns(false).Verifiable();
            Mock.Get(fileSystem).Setup(_fileSystem => _fileSystem.EnsureFolderExists(targetFolder)).Verifiable();
            Mock.Get(fileSystem).Setup(_fileSystem => _fileSystem.Copy(
                                           Path.Combine(working, "text.txt"),
                                           Path.Combine(targetFolder, "text.txt"))
                                       ).Verifiable();

            // Initialise the task
            var task = new MergeFilesTask
            {
                Logger       = logger,
                FileSystem   = fileSystem,
                TargetFolder = target
            };

            task.MergeFiles = new MergeFileInfo[] {
                new MergeFileInfo {
                    FileName = "text.xml", MergeAction = MergeFileInfo.MergeActionType.Merge
                },
                new MergeFileInfo {
                    FileName = "text.txt", MergeAction = MergeFileInfo.MergeActionType.Copy
                },
                new MergeFileInfo {
                    FileName = "blank.txt", MergeAction = MergeFileInfo.MergeActionType.Copy
                }
            };

            // Mock the result
            var result = mocks.Create <IIntegrationResult>(MockBehavior.Strict).Object;

            Mock.Get(result).Setup(_result => _result.AddTaskResult(It.IsAny <ITaskResult>())).Verifiable();
            Mock.Get(result).SetupProperty(_result => _result.Status);
            Mock.Get(result).SetupGet(_result => _result.Succeeded).Returns(true).Verifiable();

            var buildProgress = mocks.Create <BuildProgressInformation>(MockBehavior.Strict, artefact, "Project1").Object;

            Mock.Get(result).SetupGet(_result => _result.BuildProgressInformation).Returns(buildProgress);
            Mock.Get(result).SetupGet(_result => _result.WorkingDirectory).Returns(working);
            Mock.Get(result).SetupGet(_result => _result.ArtifactDirectory).Returns(artefact);
            Mock.Get(result).SetupGet(_result => _result.Label).Returns(label);
            Mock.Get(buildProgress).Setup(_buildProgress => _buildProgress.SignalStartRunTask("Merging Files")).Verifiable();
            Mock.Get(buildProgress).Setup(_buildProgress => _buildProgress.AddTaskInformation(It.IsAny <string>())).Verifiable();

            //var testFile = new FileInfo(Path.Combine(working, "text.xml"));
            //Expect.Call(fileSystem.FileExists(testFile.FullName)).Return(true);
            //Expect.Call(() =>
            //                {
            //                    result.AddTaskResult(new FileTaskResult(
            //                                             testFile, false,
            //                                             fileSystem) {WrapInCData = false});
            //                });

            // Run the test
            result.Status = IntegrationStatus.Unknown;
            task.Run(result);

            // Check the results
            mocks.VerifyAll();
        }