示例#1
0
        public void GetTests_WithActualMappings_FilesFound_ReturnsMatchingTests()
        {
            //arrange
            HashSet <string> paths = new HashSet <string>()
            {
                ".github",
                "documentation",
                "src/ServiceManagement/file",
                "src/ResourceManager/LogicApp/file",
                "src/ResourceManager/UsageAggregates/file"
            };

            string           mapFilePath = MapFilePath;
            HashSet <string> expected    = new HashSet <string>()
            {
                @".\src\ServiceManagement\Common\Commands.Common.Test\bin\Debug\Microsoft.WindowsAzure.Commands.Common.Test.dll",
                @".\src\ServiceManagement\Services\Commands.Test\bin\Debug\Microsoft.WindowsAzure.Commands.Test.dll",
                @".\src\ServiceManagement\StorSimple\Commands.StorSimple.Test\bin\Debug\Microsoft.WindowsAzure.Commands.StorSimple.Test.dll",
                @".\src\ServiceManagement\Common\Commands.ScenarioTest\bin\Debug\Microsoft.WindowsAzure.Commands.ScenarioTest.dll",
                @".\src\ServiceManagement\RecoveryServices\Commands.RecoveryServices.Test\bin\Debug\Microsoft.Azure.Commands.RecoveryServices.Test.dll",
                @".\src\ServiceManagement\Network\Commands.Network.Test\bin\Debug\Microsoft.WindowsAzure.Commands.ServiceManagement.Network.Test.dll",
                @".\src\ResourceManager\UsageAggregates\Commands.UsageAggregates.Test\bin\Debug\Microsoft.Azure.Commands.UsageAggregates.Test.dll",
                @".\src\ResourceManager\LogicApp\Commands.LogicApp.Test\bin\Debug\Microsoft.Azure.Commands.LogicApp.Test.dll"
            };

            IEnumerable <string> actual;

            //act
            actual = TestSetGenerator.GetTests(paths, mapFilePath);

            //assert
            Assert.True(expected.SetEquals(actual));
        }
示例#2
0
        public void GetTests_InvalidPath_ThrowNotNullException()
        {
            //arrange
            HashSet <string> paths = new HashSet <string>()
            {
                "src /path1",
                "src/path2",
                "random3"
            };

            string mapFilePath = @"random";

            try
            {
                TestSetGenerator.GetTests(paths, mapFilePath);
            }
            catch (System.IO.FileNotFoundException e)
            {
                // assert
                Assert.Contains("The filepath provided for the map could not be found.", e.Message);
                return;
            }

            throw new Exception("No exception was thrown.");
        }
示例#3
0
        public void GetTests_MultiplePathsAndMultipleMappingsWithSomeMatchingPaths_ReturnsAllTests()
        {
            //arrange
            HashSet <string> paths = new HashSet <string>()
            {
                "src/ResourceManager/StreamAnalytics/",
                "src/path2",
                "random3"
            };

            string           mapFilePath = MapFilePath;
            HashSet <string> expected    = new HashSet <string>()
            {
                "test1.dll",
                "test2.dll",
                "test3.dll"
            };

            int expectedNumberFiles = 53;
            HashSet <string> actual;

            //act
            actual = (HashSet <string>)(TestSetGenerator.GetTests(paths, mapFilePath));

            //assert
            Assert.True(expectedNumberFiles <= actual.Count);
        }
示例#4
0
        public void GetTests_EmptyListOfFiles_ShouldReturnAllTests()
        {
            //arrange
            HashSet <string> paths = new HashSet <string>()
            {
            };
            string           mapFilePath         = MapFilePath;
            int              expectedNumberFiles = 53;
            HashSet <string> actual;

            //act
            actual = (HashSet <string>)(TestSetGenerator.GetTests(paths, mapFilePath));

            //assert
            Assert.True(expectedNumberFiles <= actual.Count);
        }
示例#5
0
        public void GetTests_FilesNull_ThrowNullException()
        {
            //arrange
            string mapFilePath = MapFilePath;

            try
            {
                TestSetGenerator.GetTests(null, mapFilePath);
            }
            catch (ArgumentNullException e)
            {
                // assert
                Assert.Contains("The files should never be null.", e.Message);
                return;
            }

            throw new Exception("No exception was thrown.");
        }
示例#6
0
        public void GetTests_MultiplePathsAndMultipleMappingsWithMatchingPaths_ReturnsMatchingTests()
        {
            //arrange
            HashSet <string> paths = new HashSet <string>()
            {
                "src/ResourceManager/StreamAnalytics/file",
                "src/ResourceManager/Websites/"
            };

            string           mapFilePath         = MapFilePath;
            int              expectedNumberFiles = 2;
            HashSet <string> actual;

            //act
            actual = (HashSet <string>)(TestSetGenerator.GetTests(paths, mapFilePath));

            //assert
            Assert.True(expectedNumberFiles == actual.Count);
        }
示例#7
0
        public void GetTests_WithActualMappings_FilesNotFound_ReturnsAllTests()
        {
            //arrange
            HashSet <string> paths = new HashSet <string>()
            {
                ".github",
                "documentation",
                "random1",
                "random2",
                "random3"
            };

            string           mapFilePath         = MapFilePath;
            int              expectedNumberFiles = 53;
            HashSet <string> actual;

            //act
            actual = (HashSet <string>)(TestSetGenerator.GetTests(paths, mapFilePath));

            //assert
            Assert.True(expectedNumberFiles <= actual.Count);
        }
示例#8
0
        /// <summary>
        /// Executes the task to generate a list of test assemblies
        /// based on file changes from a specified Pull Request.
        /// The output it produces is said list.
        /// </summary>
        /// <returns> Returns a value indicating wheter the success status of the task. </returns>
        public override bool Execute()
        {
            // validate parameters
            if (RepositoryOwner == null)
            {
                throw new ArgumentNullException("The RepositoryOwner cannot be null.");
            }

            if (RepositoryName == null)
            {
                throw new ArgumentNullException("The RepositoryName cannot be null.");
            }

            if (MapFilePath == null)
            {
                throw new ArgumentNullException("The MapFilePath cannot be null.");
            }

            var  debugEnvironmentVariable = Environment.GetEnvironmentVariable("DebugLocalBuildTasks");
            bool debug;

            if (!Boolean.TryParse(debugEnvironmentVariable, out debug))
            {
                debug = false;
            }

            int ParsedPullRequestNumber;

            // The next statement will convert the string representation of a number to its integer equivalent.
            // If it succeeds it will return 'true'.
            if (int.TryParse(PullRequestNumber, out ParsedPullRequestNumber))
            {
                List <string>         filesChanged = new List <string>();
                Collection <PSObject> psOutput     = new Collection <PSObject>();
                var        GetFilesScript          = File.ReadAllText(ScriptFilePath);
                PowerShell powerShell = PowerShell.Create();
                powerShell.AddScript(GetFilesScript);
                if (debug)
                {
                    powerShell.AddScript("$DebugPreference=\"Continue\"");
                }

                powerShell.AddScript($"Get-PullRequestFileChanges " +
                                     $"-RepositoryOwner {RepositoryOwner} " +
                                     $"-RepositoryName {RepositoryName} " +
                                     $"-PullRequestNumber {ParsedPullRequestNumber}");
                powerShell.Streams.Debug.Clear();
                try
                {
                    if (debug)
                    {
                        Console.WriteLine("DEBUG: ---Starting PS script to detect file changes...");
                    }

                    psOutput = powerShell.Invoke();
                    if (debug)
                    {
                        foreach (var debugRecord in powerShell.Streams.Debug)
                        {
                            Console.WriteLine("[PS]DEBUG: " + debugRecord.ToString());
                        }
                    }

                    if (psOutput == null)
                    {
                        return(false);
                    }

                    if (debug)
                    {
                        Console.WriteLine("DEBUG: ---Using these files: ");
                    }

                    foreach (var element in psOutput)
                    {
                        var filename = element.ToString();
                        if (debug)
                        {
                            Console.WriteLine("DEBUG: " + filename);
                        }

                        filesChanged.Add(filename);
                    }

                    if (debug)
                    {
                        Console.WriteLine("Total: " + filesChanged.Count);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("---Exception Caught when trying to detect file changes with PS script: " + e.ToString());
                }

                TestAssemblies = new List <string>(TestSetGenerator.GetTests(filesChanged, MapFilePath)).ToArray();
            }
            else
            {
                TestAssemblies = new List <string>(TestSetGenerator.GetTests(MapFilePath)).ToArray();
            }

            return(true);
        }