public void GetTests_MultiplePathsAndMultipleMappingsWithSomeMatchingPaths_ReturnsAllTests()
        {
            //arrange
            HashSet <string> paths = new HashSet <string>()
            {
                "src/ResourceManager/StreamAnalytics/",
                "src/path2",
                "random3"
            };

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

            int expectedNumberFiles = GetFullSetFromMappingsFile(MapFilePath).Count;
            HashSet <string> actual;

            //act
            actual = (HashSet <string>)(SetGenerator.Generate(paths, MapFilePath));

            //assert
            Assert.True(expectedNumberFiles <= actual.Count);
        }
        public void GetTestSet_OnePathAndMultipleMappingsWithNonMatchingPaths_ReturnsAllTests()
        {
            //arrange
            HashSet <String> paths = new HashSet <String>()
            {
                "src/random"
            };

            Dictionary <String, String[]> map = new Dictionary <String, String[]>()
            {
                { "src/path1", new String[] { "test1.dll" } },
                { "src/path2", new String[] { "test2.dll" } },
                { "src/path3", new String[] { "test2.dll", "test3.dll" } }
            };

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

            HashSet <String> actual = new HashSet <String>();

            //act
            actual = SetGenerator.Generate(paths, map);

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

            string mapFilePath = @"random";

            try
            {
                SetGenerator.Generate(paths, mapFilePath);
            }
            catch (System.IO.FileNotFoundException e)
            {
                // assert
                Assert.Contains("The file path provided for the mappings could not be found.", e.Message);
                return;
            }

            throw new Exception("No exception was thrown.");
        }
        public void GetTestSet_OnePathAndOneMappingWithMatchingPath_ReturnsTestSetMatchingPath()
        {
            //declarations
            HashSet <String> paths = new HashSet <String>()
            {
                "src/path1/fullpath"
            };

            Dictionary <String, String[]> map = new Dictionary <String, String[]>()
            {
                { "src/path1", new String[] { "test1.dll" } }
            };

            HashSet <String> expected = new HashSet <String>()
            {
                "test1.dll"
            };

            HashSet <String> actual = new HashSet <String>();

            //act
            actual = SetGenerator.Generate(paths, map);

            //assert
            Assert.True(expected.SetEquals(actual));
        }
        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 = SetGenerator.Generate(paths, mapFilePath);

            //assert
            Assert.True(expected.SetEquals(actual));
        }
        public void GetTestSet_NoMappingsProvided_ShouldThrowArgumentException()
        {
            //arrange
            HashSet <String> paths = new HashSet <String>()
            {
                "random1",
                "random2",
                "random3"
            };

            Dictionary <String, String[]> map = new Dictionary <String, String[]>();

            //act
            try
            {
                SetGenerator.Generate(paths, map);
            }
            catch (ArgumentException e)
            {
                // assert
                Assert.Contains(e.Message, "The mappings dictionary does not contain any elements.");
                return;
            }

            throw new Exception("No exception was thrown.");
        }
        public void GetTestSet_SomePathIsNull_ShouldThrowArgumentNullException()
        {
            //arrange
            HashSet <String> paths = new HashSet <String>()
            {
                null,
                "random2",
                "random3"
            };

            Dictionary <String, String[]> map = new Dictionary <String, String[]>()
            {
                { "src/path1", new String[] { "test1.dll" } },
                { "src/path2", new String[] { } },
                { "path3", new String[] { "test2.dll", "test3.dll" } }
            };

            //act
            try
            {
                SetGenerator.Generate(paths, map);
            }
            catch (ArgumentNullException e)
            {
                // assert
                Assert.Contains("One or more of the elements in the set of changed files is null.", e.Message);
                return;
            }

            throw new Exception("No exception was thrown.");
        }
示例#8
0
        public void GetTests_WithActualMappings_FilesFound_ReturnsMatchingTests()
        {
            //arrange
            HashSet <string> paths = new HashSet <string>()
            {
                ".github",
                "documentation",
                "src/LogicApp/file",
                "src/Billing/file"
            };

            string           mapFilePath = MapFilePath;
            HashSet <string> expected    = new HashSet <string>()
            {
                @".\src\Billing\Commands.UsageAggregates.Test\bin\Debug\Microsoft.Azure.PowerShell.Cmdlets.UsageAggregates.Test.dll",
                @".\src\LogicApp\Commands.LogicApp.Test\bin\Debug\Microsoft.Azure.PowerShell.Cmdlets.LogicApp.Test.dll"
            };

            IEnumerable <string> actual;

            //act
            actual = SetGenerator.Generate(paths, mapFilePath);

            //assert
            Assert.True(expected.SetEquals(actual));
        }
        public void GetTests_EmptyListOfFiles_ShouldReturnAllTests()
        {
            //arrange
            HashSet <string> paths = new HashSet <string>()
            {
            };
            int expectedNumberFiles = GetFullSetFromMappingsFile(MapFilePath).Count;
            HashSet <string> actual;

            //act
            actual = (HashSet <string>)(SetGenerator.Generate(paths, MapFilePath));

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

            try
            {
                SetGenerator.Generate(null, mapFilePath);
            }
            catch (ArgumentNullException e)
            {
                // assert
                Assert.Contains("The list of files changed cannot be null.", e.Message);
                return;
            }

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

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

            //act
            actual = (HashSet <string>)(SetGenerator.Generate(paths, mapFilePath));

            //assert
            Assert.True(expectedNumberFiles == actual.Count);
        }
示例#12
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()
        {
            if (MapFilePath == null)
            {
                throw new ArgumentNullException("The MapFilePath cannot be null.");
            }

            if (!File.Exists(MapFilePath))
            {
                throw new FileNotFoundException("The MapFilePath provided could not be found. Please provide a valid MapFilePath.");
            }

            var mappingsDictionary = JsonConvert.DeserializeObject <Dictionary <string, string[]> >(File.ReadAllText(MapFilePath));

            if (FilesChanged != null && FilesChanged.Length > 0)
            {
                Console.WriteLine($"Filter according to {FilesChanged.Length} file(s) in FilesChanged");
                var filesChangedSet = new HashSet <string>(FilesChanged);
                Output = SetGenerator.Generate(filesChangedSet, mappingsDictionary).ToArray();
            }
            else if (!string.IsNullOrWhiteSpace(TargetModule))
            {
                Console.WriteLine($"Filter module {TargetModule}");
                var modules = (TargetModule.Equals("Accounts"))? new string[] { "Accounts" } : new string[] { "Accounts", TargetModule };
                Output = SetGenerator.Generate(modules, mappingsDictionary).ToArray();
            }
            else
            {
                Console.WriteLine($"Skip filter and load all from ${MapFilePath}");
                var set = new HashSet <string>();
                mappingsDictionary = JsonConvert.DeserializeObject <Dictionary <string, string[]> >(File.ReadAllText(MapFilePath));
                foreach (KeyValuePair <string, string[]> pair in mappingsDictionary)
                {
                    set.UnionWith(pair.Value);
                }

                Output = set.ToArray();
            }

            return(true);
        }
        public void GetTests_WithActualMappings_FilesNotFound_ReturnsAllTests()
        {
            //arrange
            HashSet <string> paths = new HashSet <string>()
            {
                ".github",
                "documentation",
                "random1",
                "random2",
                "random3"
            };

            int expectedNumberFiles = GetFullSetFromMappingsFile(MapFilePath).Count;
            HashSet <string> actual;

            //act
            actual = (HashSet <string>)(SetGenerator.Generate(paths, MapFilePath));

            //assert
            Assert.True(expectedNumberFiles <= actual.Count);
        }
示例#14
0
        /// <summary>
        /// Static method used to generate a set of tests to be run based on
        /// a Json file which maps files to test Dlls.
        /// </summary>
        /// <param name="files">This is a set of paths.</param>
        /// <param name="mapFilePath">This is the filepath of the map that contains
        /// the mapping between files and test DLLs.</param>
        /// <returns>Set of tests to be run</returns>
        public static IEnumerable <string> Generate(IEnumerable <string> filesChanged, string mapFilePath)
        {
            if (mapFilePath == null)
            {
                throw new ArgumentNullException("The mappings file path cannot be null.");
            }

            if (!File.Exists(mapFilePath))
            {
                throw new FileNotFoundException("The file path provided for the mappings could not be found.");
            }

            if (filesChanged == null)
            {
                throw new ArgumentNullException("The list of files changed cannot be null.");
            }

            var filesChangedSet    = new HashSet <string>(filesChanged);
            var mappingsDictionary = JsonConvert.DeserializeObject <Dictionary <string, string[]> >(File.ReadAllText(mapFilePath));

            return(SetGenerator.Generate(filesChangedSet, mappingsDictionary));
        }
        public void GetTestSet_NoPathsProvided_ReturnsAllTests()
        {
            //arrange
            HashSet <String> paths = new HashSet <String>()
            {
            };
            Dictionary <String, String[]> map = new Dictionary <String, String[]>()
            {
                { "src/path1", new String[] { "test1.dll" } },
                { "src/path2", new String[] { } },
                { "path3", new String[] { "test2.dll", "test3.dll" } }
            };

            int expectedNumberFiles = 3;
            HashSet <string> actual;

            //act
            actual = SetGenerator.Generate(paths, map);

            //assert
            Assert.True(expectedNumberFiles == actual.Count);
        }
        public void GetTestSet_MapNullArgument_ShouldThrowArgumentNullException()
        {
            //arrange
            HashSet <String> paths = new HashSet <String>()
            {
                "random1",
                "random2",
                "random3"
            };

            //act
            try
            {
                SetGenerator.Generate(paths, null);
            }
            catch (ArgumentNullException e)
            {
                // assert
                Assert.Contains("The mappings dictionary cannot be null.", e.Message);
                return;
            }

            throw new Exception("No exception was thrown.");
        }
        public void GetTestSet_PathsNullArgument_ShouldThrowArgumentNullException()
        {
            //arrange
            Dictionary <String, String[]> map = new Dictionary <String, String[]>()
            {
                { "src/path1", new String[] { "test1.dll" } },
                { "src/path2", new String[] { } },
                { "path3", new String[] { "test2.dll", "test3.dll" } }
            };

            //act
            try
            {
                SetGenerator.Generate(null, map);
            }
            catch (ArgumentNullException e)
            {
                // assert
                Assert.Contains("The set of files changed cannot be null.", e.Message);
                return;
            }

            throw new Exception("No exception was thrown.");
        }
示例#18
0
 public string[] GetOutput(string[] filesChanged, string mapFilePath)
 {
     return(SetGenerator.Generate(filesChanged, mapFilePath).ToArray());
 }