Exemple #1
0
        public static Output <UT.UnitTest, List <string> > Regenerate(UT.UnitTest test)
        {
            if (test == null)
            {
                BH.Engine.Base.Compute.RecordError("Could not regenerate unit test as test input was null.");
                return(null);
            }

            List <UT.TestData> newTestData = new List <UT.TestData>();
            List <string>      errors      = new List <string>();
            MethodBase         method      = test.Method;

            foreach (UT.TestData data in test.Data)
            {
                var result = Run(method, data);
                //Check if no errors occured during the execution
                if (result.Item2.Count == 0)
                {
                    newTestData.Add(new UT.TestData(data.Inputs, result.Item1));
                }
                else
                {
                    errors.AddRange(result.Item2);
                }
            }

            return(new Output <UT.UnitTest, List <string> >
            {
                Item1 = new UT.UnitTest {
                    Method = method, Data = newTestData
                },
                Item2 = errors
            });
        }
Exemple #2
0
        public static UT.UnitTest ClearOutputData(this UT.UnitTest test)
        {
            if (test == null)
            {
                BH.Engine.Base.Compute.RecordError("Test cannot be null when clearing output data.");
                return(test);
            }

            List <UT.TestData> data = new List <UT.TestData>();

            foreach (UT.TestData inData in test.Data)
            {
                data.Add(new UT.TestData(inData.Inputs, new List <object>()));
            }

            return(new UT.UnitTest
            {
                Method = test.Method,
                Data = data,
                Name = test.Name,
                CustomData = new Dictionary <string, object>(test.CustomData),
                Tags = new HashSet <string>(test.Tags),
                Fragments = new FragmentSet(test.Fragments)
            });
        }
Exemple #3
0
        public static TestResult CheckTest(this UT.UnitTest test)
        {
            if (test == null)
            {
                return new TestResult {
                           Status = oM.Test.TestStatus.Error, Description = "UnitTest", Message = "The provided UnitTest was null and could not be evaluated."
                }
            }
            ;

            MethodBase method = test.Method;

            if (method == null)
            {
                return new TestResult {
                           Status = oM.Test.TestStatus.Error, Description = "UnitTest", Message = "The method of the provided UnitTest was null and could not be evaluated."
                }
            }
            ;


            string description = $"UnitTest: Method: {method.ToText()}" + (!string.IsNullOrWhiteSpace(test.Name) ? $" ,name: {test.Name}." : ".");

            TestResult testResult = new TestResult {
                Description = description
            };

            int counter = 0;

            foreach (UT.TestData data in test.Data)
            {
                testResult.Information.Add(CheckTest(method, data, counter));

                counter++;
            }

            testResult.Status = testResult.Information.MostSevereStatus();

            if (testResult.Status == oM.Test.TestStatus.Error)
            {
                testResult.Message = "The UnitTest did not pass.";
            }
            else if (testResult.Status == oM.Test.TestStatus.Pass)
            {
                testResult.Message = "No errors or warnings were reported from running the UnitTest.";
            }
            else
            {
                testResult.Message = "Warnings were reported during the execution of the UnitTest.";
            }

            return(testResult);
        }
Exemple #4
0
        public static Output <List <List <object> >, List <string> > Run(this UT.UnitTest test)
        {
            if (test == null)
            {
                BH.Engine.Base.Compute.RecordError("Could not run unit test as provided test was null.");
                return(null);
            }

            List <List <object> > results = new List <List <object> >();
            List <string>         errors  = new List <string>();
            MethodBase            method  = test.Method;

            foreach (UT.TestData data in test.Data)
            {
                var result = Run(method, data);
                results.Add(result.Item1);
                errors.AddRange(result.Item2);
            }
            return(new Output <List <List <object> >, List <string> > {
                Item1 = results, Item2 = errors
            });
        }