示例#1
0
        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 = TestSetGenerator.GetTestSet(paths, map);

            //assert
            Assert.True(expected.SetEquals(actual));
        }
示例#2
0
        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
            {
                TestSetGenerator.GetTestSet(paths, map);
            }
            catch (ArgumentNullException e)
            {
                // assert
                Assert.Contains("One or more of the paths provided are null.", e.Message);
                return;
            }

            throw new Exception("No exception was thrown.");
        }
示例#3
0
        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 = TestSetGenerator.GetTestSet(paths, map);

            //assert
            Assert.True(expected.SetEquals(actual));
        }
示例#4
0
        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
            {
                TestSetGenerator.GetTestSet(paths, map);
            }
            catch (ArgumentException e)
            {
                // assert
                Assert.Contains(e.Message, "Map does not contain any element.");
                return;
            }

            throw new Exception("No exception was thrown.");
        }
示例#5
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> GetTests(IEnumerable <string> files, string mapFilePath)
        {
            if (mapFilePath == null)
            {
                throw new ArgumentNullException("The filepath of the map should never be null.");
            }

            if (files == null)
            {
                throw new ArgumentNullException("The files should never be null.");
            }

            HashSet <string> paths = new HashSet <string>(files);
            Dictionary <string, string[]> pathToTestsMappings;

            try
            {
                pathToTestsMappings = JsonConvert.DeserializeObject <Dictionary <string, string[]> >(File.ReadAllText(mapFilePath));
            }
            catch (FileNotFoundException)
            {
                throw new FileNotFoundException("The filepath provided for the map could not be found. Please provide a valid filepath.");
            }

            return(TestSetGenerator.GetTestSet(paths, pathToTestsMappings));
        }
示例#6
0
        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 = TestSetGenerator.GetTestSet(paths, map);

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

            //act
            try
            {
                TestSetGenerator.GetTestSet(paths, null);
            }
            catch (ArgumentNullException e)
            {
                // assert
                Assert.Contains("Mapping should never be null.", e.Message);
                return;
            }

            throw new Exception("No exception was thrown.");
        }
示例#8
0
        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
            {
                TestSetGenerator.GetTestSet(null, map);
            }
            catch (ArgumentNullException e)
            {
                // assert
                Assert.Contains("Paths set should never be null.", e.Message);
                return;
            }

            throw new Exception("No exception was thrown.");
        }