Exemplo n.º 1
0
        public void TaskHelper_AddTask_ExistsInCache()
        {
            var target = "Test Target";

            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;
            var settings = SingletonFactory.GetHelperSettings();

            var targetRanSuccess = false;

            settings.TaskTargetFunc = taskName => { return(new CakeTaskBuilder <ActionTask>(new ActionTask(taskName))); };

            settings.RunTargetFunc = targ =>
            {
                targetRanSuccess = targ == target;
                return(new CakeReport());
            };

            var taskHelper = SingletonFactory.GetTaskHelper();

            Assert.IsNotNull(taskHelper);

            var firstTask = taskHelper.AddTask(target);

            Assert.IsNotNull(firstTask);

            var nextTask = taskHelper.AddTask(target);

            Assert.IsNotNull(nextTask);
            Assert.AreEqual(firstTask, nextTask);
        }
Exemplo n.º 2
0
        public void TaskHelper_RunTarget_String_Success()
        {
            var target = "Test Target";

            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;
            var settings = SingletonFactory.GetHelperSettings();

            var targetRanSuccess = false;

            settings.RunTargetFunc = targ =>
            {
                targetRanSuccess = targ == target;
                return(new CakeReport());
            };

            var taskHelper = SingletonFactory.GetTaskHelper();

            Assert.IsNotNull(taskHelper);

            var report = taskHelper.RunTarget(target);

            Assert.IsNotNull(report);
            Assert.IsTrue(targetRanSuccess);
        }
Exemplo n.º 3
0
        public void TaskHelper_RunTarget_Task_Success()
        {
            var target = "Test Target";

            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;
            var settings = SingletonFactory.GetHelperSettings();

            var targetRanSuccess = false;

            settings.TaskTargetFunc = taskName => { return(new CakeTaskBuilder <ActionTask>(new ActionTask(taskName))); };

            settings.RunTargetFunc = targ =>
            {
                targetRanSuccess = targ == target;
                return(new CakeReport());
            };

            var targetTaskBuilder = context.HelperTask(target);

            var taskHelper = SingletonFactory.GetTaskHelper();

            Assert.IsNotNull(taskHelper);

            var helperTask = taskHelper.Tasks.FirstOrDefault(t => t.Task == targetTaskBuilder.Task);

            Assert.IsNotNull(helperTask);

            var report = taskHelper.RunTarget(helperTask);

            Assert.IsNotNull(report);
            Assert.IsTrue(targetRanSuccess);
        }
Exemplo n.º 4
0
        public void GetHelperSettings_Success()
        {
            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;

            var settings = SingletonFactory.GetHelperSettings();

            Assert.IsNotNull(settings);
            Assert.IsNotNull(settings.Context);
            Assert.IsFalse(settings.RunAllDependencies);

            Assert.IsNotNull(settings.DotNetCoreSettings);

            Assert.IsNotNull(settings.DotNetCoreSettings.NugetSettings);
            Assert.IsNotNull(settings.DotNetCoreSettings.NugetSettings.Context);
            Assert.AreEqual(1, settings.DotNetCoreSettings.NugetSettings.NugetSources.Count());

            Assert.IsNotNull(settings.DotNetCoreSettings.BuildSettings);
            Assert.AreEqual("./BuildTemp", settings.DotNetCoreSettings.BuildSettings.BuildTempFolder);

            Assert.IsNotNull(settings.DotNetCoreSettings.TestSettings);
            Assert.AreEqual("./TestTemp", settings.DotNetCoreSettings.TestSettings.TestTempFolder);

            var newSettings = SingletonFactory.GetHelperSettings();

            Assert.AreEqual(settings, newSettings);
        }
        public void DotNetCoreAlias_AddProject_Default_NoTestFilters()
        {
            var context    = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());
            var defaultSln = SolutionFixture.GetDefaultSolution(context.FileSystem);

            context.AddDotNetCoreProject(defaultSln.SlnFile.Path.FullPath);

            var helperSetting = SingletonFactory.GetHelperSettings();

            Assert.IsNotNull(helperSetting);

            helperSetting.DotNetCoreSettings.TestSettings.TestProjectNameFilters.Clear();
            var projects = helperSetting.DotNetCoreSettings.Projects.ToArray();

            Assert.AreEqual(1, projects.Length);
            Assert.IsTrue(projects.Any(t => t.ProjectAlias == "CakeHelpers"));

            var slnProj = projects.FirstOrDefault();

            Assert.IsNotNull(slnProj);
            Assert.AreEqual("CakeHelpers", slnProj.ProjectAlias);
            slnProj.ProjectAlias = "Test";
            Assert.AreEqual("Test", slnProj.ProjectAlias);
            Assert.IsTrue(string.IsNullOrWhiteSpace(slnProj.Configuration));
            Assert.IsTrue(string.IsNullOrWhiteSpace(slnProj.Framework));
            Assert.IsTrue(string.IsNullOrWhiteSpace(slnProj.Platform));
            Assert.AreEqual(2, slnProj.AllProjects.Count());
            Assert.AreEqual(2, slnProj.SrcProjects.Count());
            Assert.AreEqual(0, slnProj.TestProjects.Count());
        }
        public void DotNetCoreAlias_AddNugetSource_Success()
        {
            var feedUrl1  = "testUrl";
            var feedUrl2  = "blahUrl";
            var feedName2 = "blah";

            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            Assert.IsFalse(SingletonFactory.ExistsInCache(typeof(HelperSettings)));

            context.AddDotNetCoreHelperNugetSource(feedUrl1);

            var helperSetting = SingletonFactory.GetHelperSettings();

            Assert.IsNotNull(helperSetting);

            var nugetSources = helperSetting.DotNetCoreSettings.NugetSettings.NugetSources.ToArray();

            Assert.AreEqual(2, nugetSources.Length);
            Assert.IsTrue(nugetSources.Any(t => t.FeedSource == feedUrl1 && string.IsNullOrWhiteSpace(t.FeedName)));

            context.AddDotNetCoreHelperNugetSource(feedUrl2, config =>
            {
                config.FeedName = feedName2;
            });

            nugetSources = helperSetting.DotNetCoreSettings.NugetSettings.NugetSources.ToArray();
            Assert.AreEqual(3, nugetSources.Length);
            Assert.IsTrue(nugetSources.Any(t => t.FeedSource == feedUrl1 && string.IsNullOrWhiteSpace(t.FeedName)));
            Assert.IsTrue(nugetSources.Any(t => t.FeedSource == feedUrl2 && t.FeedName == feedName2));
        }
Exemplo n.º 7
0
        public void TaskHelper_AddTaskDependency_DependentTaskExists()
        {
            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;

            var settings = SingletonFactory.GetHelperSettings();

            settings.TaskTargetFunc = taskName => { return(new CakeTaskBuilder <ActionTask>(new ActionTask(taskName))); };

            var taskHelper = SingletonFactory.GetTaskHelper();

            Assert.IsNotNull(taskHelper);

            var firstTask = taskHelper.AddTask("test");
            var nextTask  = taskHelper.AddTask("test2");

            Assert.AreEqual(0, firstTask.Task.Dependencies.Count);
            Assert.AreEqual(0, nextTask.Task.Dependencies.Count);

            taskHelper.AddTaskDependency(firstTask, nextTask);

            Assert.AreEqual(1, firstTask.Task.Dependencies.Count);
            Assert.IsTrue(firstTask.Task.Dependencies.Contains("test2"));
            Assert.AreEqual(0, nextTask.Task.Dependencies.Count);

            taskHelper.AddTaskDependency(firstTask, nextTask);

            Assert.AreEqual(1, firstTask.Task.Dependencies.Count);
            Assert.IsTrue(firstTask.Task.Dependencies.Contains("test2"));
            Assert.AreEqual(0, nextTask.Task.Dependencies.Count);
        }
        public static IDotNetCoreTestHelperSettings DotNetCoreTestHelperSettings(this ICakeContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            SingletonFactory.Context = context;
            return(SingletonFactory.GetHelperSettings().DotNetCoreSettings.TestSettings);
        }
Exemplo n.º 9
0
        public void TaskHelper_RunTarget_NoRunTargetFunc()
        {
            var target = "Test Target";

            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;
            var settings = SingletonFactory.GetHelperSettings();

            var taskHelper = SingletonFactory.GetTaskHelper();

            Assert.IsNotNull(taskHelper);

            Assert.ThrowsException <ArgumentNullException>(() => taskHelper.RunTarget(target));
        }
        public void DotNetCoreAlias_BuildHelperSettings_Success()
        {
            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            Assert.IsFalse(SingletonFactory.ExistsInCache(typeof(HelperSettings)));

            var dotCoreSettings = context.DotNetCoreBuildHelperSettings();

            Assert.IsNotNull(dotCoreSettings);
            Assert.IsTrue(SingletonFactory.ExistsInCache(typeof(HelperSettings)));

            var helperSettings = SingletonFactory.GetHelperSettings();

            Assert.IsNotNull(helperSettings);
            Assert.AreEqual(helperSettings.DotNetCoreSettings.BuildSettings, dotCoreSettings);
        }
Exemplo n.º 11
0
        public void CommandAlias_CommandHelper_Success()
        {
            var context    = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());
            var defaultSln = SolutionFixture.GetDefaultSolution(context.FileSystem);

            context.AddDotNetCoreProject(defaultSln.SlnFile.Path.FullPath);

            var helperSetting = SingletonFactory.GetHelperSettings();

            Assert.IsNotNull(helperSetting);

            var commandHelper = context.CommandHelper();

            Assert.IsNotNull(commandHelper);

            Assert.ThrowsException <ArgumentNullException>(() => ((ICakeContext)null).CommandHelper());
        }
Exemplo n.º 12
0
        public void TaskHelper_AddTaskDependency_NoTask()
        {
            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;

            var settings = SingletonFactory.GetHelperSettings();

            settings.TaskTargetFunc = taskName => { return(new CakeTaskBuilder <ActionTask>(new ActionTask(taskName))); };

            var taskHelper = SingletonFactory.GetTaskHelper();

            Assert.IsNotNull(taskHelper);

            IHelperTask firstTask = null;

            Assert.ThrowsException <ArgumentNullException>(() => taskHelper.AddTaskDependency(firstTask, "test"));
        }
Exemplo n.º 13
0
        public void TaskHelper_GetBuildTask_NoTask()
        {
            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;

            var settings = SingletonFactory.GetHelperSettings();

            settings.TaskTargetFunc = taskName => { return(new CakeTaskBuilder <ActionTask>(new ActionTask(taskName))); };

            var taskHelper = SingletonFactory.GetTaskHelper();

            Assert.IsNotNull(taskHelper);

            IHelperTask firstTask = null;
            var         buildTask = firstTask.GetTaskBuilder();

            Assert.IsNull(buildTask);
        }
Exemplo n.º 14
0
        public void TaskHelper_NoScriptTaskFunc()
        {
            var target = "Test Target";

            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;
            var settings = SingletonFactory.GetHelperSettings();

            var targetRanSuccess = false;

            settings.RunTargetFunc = targ =>
            {
                targetRanSuccess = targ == target;
                return(new CakeReport());
            };

            Assert.ThrowsException <ArgumentNullException>(() => context.HelperTask(target));
        }
Exemplo n.º 15
0
        public void SingletonFactoryClear_Success()
        {
            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;

            var settings = SingletonFactory.GetHelperSettings();

            Assert.IsNotNull(settings);

            SingletonFactory.ClearFactory();
            Assert.IsNull(SingletonFactory.Context);

            SingletonFactory.Context = context;
            var newSettings = SingletonFactory.GetHelperSettings();

            Assert.IsNotNull(newSettings);
            Assert.AreNotEqual(settings, newSettings);
        }
        public void DotNetCoreAlias_TestHelperSettings_Success()
        {
            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            Assert.IsFalse(SingletonFactory.ExistsInCache(typeof(HelperSettings)));

            var dotCoreSettings = context.DotNetCoreTestHelperSettings();

            Assert.IsNotNull(dotCoreSettings);
            Assert.IsTrue(SingletonFactory.ExistsInCache(typeof(HelperSettings)));

            var helperSettings = SingletonFactory.GetHelperSettings();

            Assert.IsNotNull(helperSettings);
            Assert.AreEqual(helperSettings.DotNetCoreSettings.TestSettings, dotCoreSettings);

            Assert.AreEqual("./TestTemp", dotCoreSettings.TestTempFolder);
            dotCoreSettings.TestTempFolder = "AnotherTest";
            Assert.AreEqual("AnotherTest", dotCoreSettings.TestTempFolder);
        }
Exemplo n.º 17
0
        public void TaskHelper_GetTargetTasks()
        {
            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;
            var settings = SingletonFactory.GetHelperSettings();

            settings.TaskTargetFunc = taskName => { return(new CakeTaskBuilder <ActionTask>(new ActionTask(taskName))); };

            var taskHelper = SingletonFactory.GetTaskHelper();

            Assert.IsNotNull(taskHelper);

            var firstTask = context.HelperTask("test1");
            var nextTask  = context.HelperTask("test2", false, "Generic", "test1");

            var targetTasks = taskHelper.Tasks.GetTargetTasks().ToArray();

            Assert.AreEqual(1, targetTasks.Length);
            Assert.IsTrue(targetTasks.Any(t => t.Task.Name == "test1"));
        }
Exemplo n.º 18
0
        public void TaskHelper_GetCategoriesForTasks_NoHelper()
        {
            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;
            var settings = SingletonFactory.GetHelperSettings();

            settings.TaskTargetFunc = taskName => { return(new CakeTaskBuilder <ActionTask>(new ActionTask(taskName))); };

            var taskHelper = SingletonFactory.GetTaskHelper();

            Assert.IsNotNull(taskHelper);

            var firstTask = context.HelperTask("test1");
            var nextTask  = context.HelperTask("test2", true, "Test");

            IHelperTaskHandler nullHelper = null;
            var categories = nullHelper.GetCategories().ToArray();

            Assert.AreEqual(0, categories.Length);
        }
Exemplo n.º 19
0
        public void TaskHelper_Change_BuildAllDependencies()
        {
            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;

            var settings = SingletonFactory.GetHelperSettings();

            Assert.IsNotNull(settings);
            Assert.AreEqual(false, settings.RunAllDependencies);

            var taskHelper = SingletonFactory.GetTaskHelper();

            Assert.IsNotNull(taskHelper);
            Assert.AreEqual(false, taskHelper.BuildAllDependencies);

            taskHelper.BuildAllDependencies = true;

            Assert.AreEqual(true, settings.RunAllDependencies);
            Assert.AreEqual(true, taskHelper.BuildAllDependencies);
        }
Exemplo n.º 20
0
        private IHelperSettings GetSettings(ICakeContext context)
        {
            SingletonFactory.Context = context;
            var settings = SingletonFactory.GetHelperSettings();

            settings.TaskTargetFunc = taskName =>
            {
                var task = new ActionTask(taskName);
                return(new CakeTaskBuilder <ActionTask>(task));
            };

            settings.RunTargetFunc = targetName =>
            {
                var report = new CakeReport {
                    { targetName, TimeSpan.Zero, CakeTaskExecutionStatus.Executed }
                };

                return(report);
            };

            return(settings);
        }
Exemplo n.º 21
0
        public void TaskHelper_RemoveTask_Success()
        {
            var target = "Test Target";

            var context = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());

            SingletonFactory.Context = context;

            var settings = SingletonFactory.GetHelperSettings();

            settings.TaskTargetFunc = taskName => { return(new CakeTaskBuilder <ActionTask>(new ActionTask(taskName))); };

            var taskHelper = SingletonFactory.GetTaskHelper();

            Assert.IsNotNull(taskHelper);

            var firstTask = taskHelper.AddTask(target);

            Assert.IsNotNull(firstTask);
            Assert.AreEqual(1, taskHelper.Tasks.Count());

            taskHelper.RemoveTask(target);
            Assert.AreEqual(0, taskHelper.Tasks.Count());
        }
        public void DotNetCoreAlias_AddProject_Custom_Success()
        {
            var context    = this.GetMoqContext(new Dictionary <string, bool>(), new Dictionary <string, string>());
            var defaultSln = SolutionFixture.GetDefaultSolution(context.FileSystem);

            context.AddDotNetCoreProject(defaultSln.SlnFile.Path.FullPath, proj =>
            {
                proj.Configuration = "Release";
            });

            var helperSetting = SingletonFactory.GetHelperSettings();

            Assert.IsNotNull(helperSetting);

            var projects = helperSetting.DotNetCoreSettings.Projects.ToArray();

            Assert.AreEqual(1, projects.Length);
            Assert.IsTrue(projects.Any(t => t.ProjectAlias == "CakeHelpers"));

            var slnProj = projects.FirstOrDefault();

            Assert.IsNotNull(slnProj);
            Assert.AreEqual("Release", slnProj.Configuration);
            Assert.AreEqual("BuildTemp/CakeHelpers/Release", slnProj.BuildTempDirectory.FullPath);

            slnProj.Framework = "net40";
            Assert.AreEqual("net40", slnProj.Framework);
            Assert.AreEqual("BuildTemp/CakeHelpers/Release/net40", slnProj.BuildTempDirectory.FullPath);

            slnProj.Platform = "x86";
            Assert.AreEqual("x86", slnProj.Platform);
            Assert.AreEqual("BuildTemp/CakeHelpers/Release/net40/x86", slnProj.BuildTempDirectory.FullPath);

            helperSetting.DotNetCoreSettings.BuildSettings.BuildTempFolder = string.Empty;
            Assert.IsNull(slnProj.BuildTempDirectory);

            Assert.AreEqual(2, slnProj.AllProjects.Count());
            Assert.AreEqual(1, slnProj.SrcProjects.Count());
            Assert.AreEqual(1, slnProj.TestProjects.Count());

            var unitConfig = slnProj.AddTestConfig("Unit");

            Assert.IsNotNull(unitConfig);
            Assert.IsTrue(string.IsNullOrWhiteSpace(unitConfig.Logger));
            unitConfig.Logger = "teamcity";
            Assert.IsFalse(string.IsNullOrWhiteSpace(unitConfig.Logger));

            Assert.AreEqual("Unit", unitConfig.TestCategory);

            Assert.AreEqual(TestTypeEnum.Default, unitConfig.TestType);
            unitConfig.TestType = TestTypeEnum.MsTest;
            Assert.AreEqual(TestTypeEnum.MsTest, unitConfig.TestType);

            Assert.IsNotNull(unitConfig.Context);

            var systemTest = "System";
            var testAdded  = string.Empty;

            slnProj.TestConfigAdded += (configuration, testConfiguration) =>
            {
                testAdded = testConfiguration.TestCategory;
            };

            var systemTestConfig = slnProj.AddTestConfig(systemTest);

            Assert.AreEqual(systemTest, testAdded);
            Assert.AreEqual(2, slnProj.TestConfigurations.Count());
            Assert.AreEqual("TestCategory=System", systemTestConfig.GetDotNetCoreCategoryString());
            systemTestConfig.TestType = TestTypeEnum.XUnit;
            Assert.AreEqual("Category=System", systemTestConfig.GetDotNetCoreCategoryString());
            Assert.ThrowsException <ArgumentNullException>(() => ((ITestConfiguration)null).GetDotNetCoreCategoryString());

            var sameProj = context.AddDotNetCoreProject(defaultSln.SlnFile.Path.FullPath);

            Assert.IsNotNull(sameProj);
            Assert.AreEqual(slnProj, sameProj);
            var outputPaths = slnProj.GetAllProjectOutputDirectoryPaths().ToArray();

            Assert.AreEqual(4, outputPaths.Length);

            Assert.ThrowsException <ArgumentNullException>(() => sameProj.AddTestConfig((ITestConfiguration)null));
            Assert.ThrowsException <ArgumentNullException>(() => ((IProjectConfiguration)null).AddTestConfig("test"));
            Assert.ThrowsException <ArgumentNullException>(() => ((IProjectConfiguration)null)
                                                           .GetAllProjectOutputDirectoryPaths());
            Assert.ThrowsException <ArgumentNullException>(() => ((IProjectConfiguration)null)
                                                           .GetRelativeSlnFilePath());
        }