The TestCaseData class represents a set of arguments and other parameter info to be used for a parameterized test case. It provides a number of instance modifiers for use in initializing the test case. Note: Instance modifiers are getters that return the same instance after modifying it's state.
Inheritance: ITestCaseData
 private TestCaseData CreateRootFolderData(string path, string rootFolder, bool isMatched, string name)
 {
     FileSystemItem item = new FileSystemItem(path);
     List<string> rootFolders = new List<string> { rootFolder };
     TestCaseData testCaseData = new TestCaseData(item, rootFolders, null, isMatched).SetName(name);
     return testCaseData;
 }
        private static TestCaseData GetTestCaseData(string name)
        {
            var asm = Assembly.GetExecutingAssembly();
            var originalStream = asm.GetManifestResourceStream(typeof (_Dummy), name + ".txt");
            var goldStream = asm.GetManifestResourceStream(typeof (_Dummy), name + ".gold");

            Debug.Assert(originalStream != null, "originalStream != null");
            Debug.Assert(goldStream != null, "goldStream != null");

            string original;
            string gold;

            using (var streamReader = new StreamReader(originalStream, Encoding.UTF8))
                original = streamReader.ReadToEnd();

            using (var streamReader = new StreamReader(goldStream, Encoding.UTF8))
                gold = streamReader.ReadToEnd();

            var testCaseData = new TestCaseData(original);

            testCaseData.SetName(name);
            testCaseData.Returns(gold.Split(new[] {'\r', '\n'}, StringSplitOptions.RemoveEmptyEntries));

            return testCaseData;
        }
 TestCaseData ProvideIgnoreReasonTo(TestCaseData target)
 {
     if (reason != null) {
         target.Ignore(reason);
     }
     return target;
 }
		public IEnumerable<TestCaseData> PerformTest() {
			string filename = Path.Combine(Environment.CurrentDirectory, Guid.NewGuid().ToString("N") + ".js");
			try {
				File.WriteAllText(filename, "(new " + TestClassName + @"()).runTests();");
				var p = Process.Start(new ProcessStartInfo { FileName = Path.GetFullPath("runner/node.exe"), Arguments = "run-tests.js \"" + filename + "\"", WorkingDirectory = Path.GetFullPath("runner"), RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true });
				var output = JsonConvert.DeserializeObject<QUnitOutput>(p.StandardOutput.ReadToEnd());
				var result = new List<TestCaseData>();
				foreach (var t in output.tests) {
					TestCaseData d;
					if (t.failed == 0) {
						d = new TestCaseData(true, null);
					}
					else {
						var failures = output.failures.Where(f => f.module == t.module && f.test == t.name).ToList();
						string errorMessage = string.Join("\n", failures.Select(f => f.message + (f.expected != null ? ", expected: " + f.expected.ToString() : "") + (f.actual != null ? ", actual: " + f.actual.ToString() : "")));
						if (errorMessage == "")
							errorMessage = "Failed";
						d = new TestCaseData(false, errorMessage);
					}
					d.SetName((t.module != "CoreLib.TestScript" ? t.module + ": " : "") + t.name);
					result.Add(d);
				}
				p.Close();
				return result;
			}
			catch (Exception ex) {
				return new[] { new TestCaseData(false, ex.Message).SetName(ex.Message) };
			}
			finally {
				try { File.Delete(filename); } catch {}
			}
		}
 private TestCaseData CreateExcludeTemplateData(string path, string excludeFolderTemplate, bool isMatched, string name)
 {
     FileSystemItem item = new FileSystemItem(path);
     List<string> excludeFolderTemplates = excludeFolderTemplate == null ? null : new List<string> { excludeFolderTemplate };
     TestCaseData testCaseData = new TestCaseData(item, null, excludeFolderTemplates, isMatched).SetName(name);
     return testCaseData;
 }
        public IEnumerable<TestCaseData> GetBuildQuotedStringData()
        {
            List<string> substrings;
            string expectedOutput;
            TestCaseData testCaseData;

            //Empty input
            expectedOutput = string.Empty;
            substrings = new List<string>();
            testCaseData = new TestCaseData(substrings, expectedOutput).SetName("Build Empty input");
            yield return testCaseData;

            //Null input
            expectedOutput = string.Empty;
            substrings = null;
            testCaseData = new TestCaseData(substrings, expectedOutput).SetName("Build Null input");
            yield return testCaseData;

            //Single string without quotes
            expectedOutput = "asdasd";
            substrings = new List<string> { "asdasd" };
            testCaseData = new TestCaseData(substrings, expectedOutput).SetName("Build Single string without quotes");
            yield return testCaseData;

            //Several strings without quotes
            expectedOutput = "C:\\asd D:\\sdf";
            substrings = new List<string> { "C:\\asd", "D:\\sdf" };
            testCaseData = new TestCaseData(substrings, expectedOutput).SetName("Build Several strings without quotes");
            yield return testCaseData;

            //Single quoted string
            expectedOutput = "\"C:\\asd asd   \"";
            substrings = new List<string> { "C:\\asd asd   " };
            testCaseData = new TestCaseData(substrings, expectedOutput).SetName("Build Single quoted string");
            yield return testCaseData;

            //Multiple quoted strings
            expectedOutput = "\"C:\\asd asd\" \"D:\\sdf sdf\"";
            substrings = new List<string> { "C:\\asd asd", "D:\\sdf sdf" };
            testCaseData = new TestCaseData(substrings, expectedOutput).SetName("Build Multiple quoted strings");
            yield return testCaseData;

            //Mixed quoting (first string quoted)
            expectedOutput = "\"C:\\asd asd\" D:\\sdf \"   D:\\sdf sdf\" \"D:\\sdf sdf   \"";
            substrings = new List<string> { "C:\\asd asd", "D:\\sdf", "   D:\\sdf sdf", "D:\\sdf sdf   " };
            testCaseData = new TestCaseData(substrings, expectedOutput).SetName("Build Mixed quoting (first string quoted)");
            yield return testCaseData;

            //Mixed quoting (second string quoted)
            expectedOutput = "D:\\sdf \"C:\\asd asd\" \" \t D:\\sdf sdf\" D:\\sdf \"D:\\sdf\t\"";
            substrings = new List<string> { "D:\\sdf", "C:\\asd asd", " \t D:\\sdf sdf", "D:\\sdf", "D:\\sdf\t" };
            testCaseData = new TestCaseData(substrings, expectedOutput).SetName("Build Mixed quoting (second string quoted)");
            yield return testCaseData;
        }
        private ITestCaseData CreateTestCase(TestPath path, IDictionary<string, string> ignores)
        {
            var testCase = new TestCaseData(path).SetName(path.TestName);

            if (ignores.ContainsKey(path.Ignore))
            {
                testCase.Ignore(ignores[path.Ignore]);
            }

            return testCase;
        }
 public static IEnumerable<TestCaseData> Suite()
 {
     string[] files = Directory.GetFiles(@"..\..\Ralph.Core.Tests\AstCompareTests\TestCases", "*.cs");
     foreach (string codefile in files)
     {
         string codefile1 = Path.GetFullPath(codefile);
         var tcase = new TestCaseData(codefile1);
         tcase.SetName(Path.GetFileNameWithoutExtension(codefile));
         yield return tcase;
     }
 }
Esempio n. 9
0
 internal IgnoredTestCaseData(TestCaseData data, RunState prevRunState)
 {
     this.Arguments         = data.Arguments;
     this.ArgDisplayNames   = data.ArgDisplayNames;
     this.ExpectedResult    = data.ExpectedResult;
     this.HasExpectedResult = data.HasExpectedResult;
     this.OriginalArguments = data.OriginalArguments;
     this.Properties        = data.Properties;
     this.RunState          = data.RunState;
     this.TestName          = data.TestName;
     this._prevRunState     = prevRunState;
 }
Esempio n. 10
0
        public IEnumerable<TestCaseData> DataProvider()
        {
            using (var driver = new OpenQA.Selenium.PhantomJS.PhantomJSDriver())
            {
                driver.Navigate().GoToUrl("https://www.google.com/search?q=test");

              //  this.BlockUntilElementIsAvailable(driver, "input");

                //Thread.Sleep(500); // needed for PhantomJS. Chrome works without.

                // load JS onto a page
                driver.ExecuteScript(File.ReadAllText("scripts/jasmine.js"));
                driver.ExecuteScript(File.ReadAllText("scripts/jquery-2.1.4.js"));
                driver.ExecuteScript(File.ReadAllText("scripts/boot.js"));  // this contains both reporter and bootstrapper
                driver.ExecuteScript(File.ReadAllText("scripts/googleTests.js"));
                driver.ExecuteScript(File.ReadAllText("scripts/execute.js"));

                // wait until all tests are done
                while ((driver.ExecuteScript("return ReportCollector.Status;") as string) != "Finished")
                {
                    Thread.Sleep(100);
                }

                // now get the results
                var specResultsJson = (string)driver.ExecuteScript("return JSON.stringify(ReportCollector.SpecResults);");

                var results = JsonConvert.DeserializeObject<JasmineResults[]>(specResultsJson);

                // and create test case data
                foreach (var result in results)
                {
                    string msg = null;
                    if (result.status == "passed")
                    {
                        msg = result.status;
                    }
                    else
                    {
                        foreach (var item in result.failedExpectations)
                        {
                            msg += "Matcher: " + item.matcherName + "; Message: " + item.message + Environment.NewLine;
                        }
                    }

                    var testCase = new TestCaseData(msg)
                    .SetDescription(result.description)
                    .SetName(result.fullName)
                    .Returns("passed");

                    yield return testCase;
                }
            }
        }
Esempio n. 11
0
        protected IEnumerable SpecificationFinder()
        {
            var specMethods =
                GetType().GetMethods().Where(x => typeof(Specification).IsAssignableFrom(x.ReturnType));

            foreach (var specMethod in specMethods)
            {
                var testCase = new TestCaseData(specMethod);
                testCase.SetName(getSpecName(specMethod.DeclaringType, specMethod));

                yield return testCase;
            }
        }
        public IEnumerable<TestCaseData> GetListeningData()
        {
            //Keys keysToListen;
            //Keys keysToPress;
            //bool shouldRaiseEvent;
            TestCaseData testCaseData;

            //keysToListen = Keys.L;
            //keysToPress = Keys.L;
            //shouldRaiseEvent = true;
            testCaseData = new TestCaseData(Keys.L, "L", true).SetName("ExpectSimpleKey_ListenThisKey_KeyHandled");
            yield return testCaseData;
        }
Esempio n. 13
0
 private static ITestCaseData GenerateTestCase(ApiTestData apiTestData)
 {
     IComparerResult comparerResult = apiTestData.ComparerResult;
       bool fail = comparerResult.GetAllCount(Severity.Error) + comparerResult.GetAllCount(Severity.Warning) > 0;
       TestCaseData testCaseData = new TestCaseData(!fail, fail ? GetFailMessage(comparerResult) : "").SetName(comparerResult.Name).SetCategory(apiTestData.Category);
       if (apiTestData.IgnoreList.Contains(comparerResult.Name))
       {
     testCaseData.Ignore();
       }
       if (apiTestData.Explicit)
       {
     testCaseData.MakeExplicit("");
       }
       return testCaseData;
 }
        public static IEnumerable<TestCaseData> ExtractMethodTestFactoryMethod()
        {
            string[] files = Directory.GetFiles(@"..\..\Ralph.Core.Tests\ExtractMethodTests\TestCases", "*.cs");
            foreach (var file in files)
            {
                string codefile = Path.GetFullPath(file);
                string codeText = File.ReadAllText(codefile);

                var testCaseData = new TestCaseData(codeText);
                testCaseData.SetName(Path.GetFileNameWithoutExtension(codefile));
                testCaseData.SetDescription(ParseDesc(codeText));

                yield return testCaseData;
            }
        }
 public static IEnumerable<ITestCaseData> GetTestCases()
 {
     const string prefix = "MongoDB.Driver.Specifications.server_selection.tests.rtt.";
     return Assembly
         .GetExecutingAssembly()
         .GetManifestResourceNames()
         .Where(path => path.StartsWith(prefix) && path.EndsWith(".json"))
         .Select(path =>
         {
             var definition = ReadDefinition(path);
             var fullName = path.Remove(0, prefix.Length);
             var data = new TestCaseData(definition);
             data.Categories.Add("Specifications");
             data.Categories.Add("server-selection");
             return data.SetName(fullName.Remove(fullName.Length - 5));
         });
 }
 public IEnumerable<TestCaseData> TestCases()
 {
     var namespaceLength = typeof(Harness).Namespace.Length + 1;
     var assembly = Assembly.GetExecutingAssembly();
     var resourceNames = assembly.GetManifestResourceNames().Where(name => name.EndsWith(Extension));
     foreach(var resourceName in resourceNames)
     {
         var stream = assembly.GetManifestResourceStream(resourceName);
         var reader = new StreamReader(stream);
         var config = TestCaseConfig.Read(reader);
         config.FileName = resourceName;
         config.TestName = resourceName.Substring(namespaceLength, resourceName.Length - namespaceLength - Extension.Length);
         var testCaseData = new TestCaseData(config, reader).SetName(config.TestName);
         if(!string.IsNullOrWhiteSpace(config.Description))
             testCaseData.SetDescription(config.Description);
         yield return testCaseData;
     }
 }
        public static IEnumerable<TestCaseData> TestCasesFromDirectory(string testDirectory = null)
        {
            var tests = TestRunner.RunAllTests(testDirectory);
            List<TestCaseData> testCases = new List<TestCaseData>();

            foreach (var test in tests)
            {
                var testCase = new TestCaseData(test).SetName(test.Name);

                if (test.Skipped)
                {
                    testCase.Ignore("This test was skipped in mocha");
                }

                testCases.Add(testCase);
            }

            return testCases;
        }
Esempio n. 18
0
        private static IEnumerable<TestCaseData> GetTestCases()
        {
            var manifest = JsonLdProcessor.FromRDF(File.ReadAllText(ManifestPath), new TurtleRDFParser());
            var framed = JsonLdProcessor.Frame(manifest, ManifestFrame, new JsonLdOptions());

            foreach (var testCase in framed["@graph"][0]["mf:entries"])
            {
                var testCaseData = new TestCaseData((string)testCase["mf:action"])
                    .SetName(((string)testCase["mf:name"]).Trim('"'))
                    .SetDescription(((string)testCase["rdfs:comment"]).Trim('"'));

                if ((string)testCase["@type"] == "rdft:TestNQuadsNegativeSyntax")
                {
                    testCaseData.Throws(typeof(ParsingException));
                }

                yield return testCaseData;
            }
        }
        public IEnumerable<TestCaseData> GetMakeFirstLetterUppercaseData()
        {
            TestCaseData testCaseData;

            //Null input
            testCaseData = new TestCaseData(null, null).SetName("Uppercase: Null input");
            yield return testCaseData;

            //Empty input
            testCaseData = new TestCaseData(string.Empty, string.Empty).SetName("Uppercase: Empty input");
            yield return testCaseData;

            //First letter lowercase
            testCaseData = new TestCaseData("aSd", "ASd").SetName("Uppercase: First letter lowercase");
            yield return testCaseData;

            //First letter uppercase
            testCaseData = new TestCaseData("ASd", "ASd").SetName("Uppercase: First letter uppercase");
            yield return testCaseData;
        }
Esempio n. 20
0
        /// <summary>
        /// Reads the data drive file and set test name.
        /// </summary>
        /// <param name="testData">Name of the child element in xml file.</param>
        /// <param name="diffParam">The difference parameter, will be used in test case name.</param>
        /// <param name="testName">Name of the test.</param>
        /// <returns></returns>
        protected IEnumerable<TestCaseData> ReadDataDriveFile(string testData, string[] diffParam, [Optional] string testName)
        {
            var doc = XDocument.Load(Path);

            if (!doc.Descendants(testData).Any())
            {
                throw new Exception(string.Format(" Exception while reading Data Driven file\n row '{0}' not found \n in file '{1}'", testData, Path));
            }

            foreach (XElement element in doc.Descendants(testData))
            {
                var testParams = element.Attributes().ToDictionary(k => k.Name.ToString(), v => v.Value);

                var testCaseName = string.IsNullOrEmpty(testName) ? testData : testName;
                if (diffParam != null && diffParam.Any())
                {
                    foreach (var p in diffParam)
                    {
                        string keyValue;
                        bool keyFlag = testParams.TryGetValue(p, out keyValue);

                        if (keyFlag)
                        {
                            if (!string.IsNullOrEmpty(keyValue))
                            {
                                testCaseName += "_" + keyValue;
                            }
                        }
                        else
                        {
                            throw new Exception(string.Format(" Exception while reading Data Driven file\n test data '{0}' \n test name '{1}' \n searched key '{2}' not found in row \n '{3}'  \n in file '{4}'", testData, testName, p, element, Path));
                        }
                    }
                }

                var data = new TestCaseData(testParams);
                data.SetName(testCaseName);
                yield return data;
            }
        }
        /// <summary>
        /// Constructs the specification and builds test cases from the 
        /// <see cref="SpecificationBase.Tests"/>.
        /// </summary>
        IEnumerable<TestMethod> ITestBuilder.BuildFrom(IMethodInfo method, Test suite)
        {
            var tests = new List<TestMethod>();

            try
            {
                var specification = (SpecificationBase)method.TypeInfo.Construct(null);

                foreach (var test in specification.Tests)
                {
                    tests.Add(builder.BuildTestMethod(method, suite, test));
                }
            }
            catch
            {
                var test = new TestCaseData(new Assertion { Action = () => { } });
                test.SetName(method.TypeInfo.Name);
                tests.Add(builder.BuildTestMethod(method, suite, test));
            }

            return tests;
        }
        static ComplexExpressionTreeBuilderExtensionsTests()
        {
            var targetAssembly = Assembly.LoadFrom("TAlex.MathCore.ComplexExpressions.Extensions.dll");

            ConstantFactory = new ConstantFlyweightFactory<object>();
            ConstantFactory.LoadFromAssemblies(new List<Assembly> { targetAssembly });

            FunctionFactory = new FunctionFactory<object>();
            FunctionFactory.LoadFromAssemblies(new List<Assembly> { targetAssembly });

            ExpressionTreeBuilder = new ComplexExpressionTreeBuilder
            {
                ConstantFactory = ConstantFactory,
                FunctionFactory = FunctionFactory
            };

            FunctionsTestCasesData = FunctionFactory.GetMetadata().Select(x =>
            {
                var d = new TestCaseData(x);
                d.SetName(String.Format("ShouldContainsCorrectedExampleUsages: {0}", x.DisplayName));
                return d;
            }).ToList();
        }
Esempio n. 23
0
        /// <summary>
        /// Reads the data drive file and set test name.
        /// </summary>
        /// <param name="testData">Name of the child element in xml file.</param>
        /// <param name="diffParam">The difference parameter, will be used in test case name.</param>
        /// <param name="testName">Name of the test.</param>
        /// <returns></returns>
        protected IEnumerable<TestCaseData> ReadDataDriveFile(string testData, string[] diffParam, [Optional] string testName)
        {
            var doc = XDocument.Load(Path);
            foreach (XElement element in doc.Descendants(testData))
            {
                var testParams = element.Attributes().ToDictionary(k => k.Name.ToString(), v => v.Value);

                var testCaseName = string.IsNullOrEmpty(testName) ? testData : testName;
                if (diffParam != null && diffParam.Any())
                {
                    foreach (var p in diffParam)
                    {
                        if (testParams[p] != string.Empty)
                        {
                            testCaseName += "_" + testParams[p];
                        }
                    }
                }

                var data = new TestCaseData(testParams);
                data.SetName(testCaseName);
                yield return data;
            }
        }
 public static IEnumerable<ITestCaseData> GetTestCases()
 {
     const string prefix = "MongoDB.Driver.Specifications.read_write_concern.tests.connection_string.";
     return Assembly
         .GetExecutingAssembly()
         .GetManifestResourceNames()
         .Where(path => path.StartsWith(prefix) && path.EndsWith(".json"))
         .SelectMany(path =>
         {
             var definition = ReadDefinition(path);
             var tests = (BsonArray)definition["tests"];
             var fullName = path.Remove(0, prefix.Length);
             var list = new List<TestCaseData>();
             foreach (BsonDocument test in tests)
             {
                 var data = new TestCaseData(test);
                 data.Categories.Add("Specifications");
                 if (test.Contains("readConcern"))
                 {
                     data.Categories.Add("ReadConcern");
                 }
                 else
                 {
                     data.Categories.Add("WriteConcern");
                 }
                 data.Categories.Add("ConnectionString");
                 var testName = fullName.Remove(fullName.Length - 5) + ": " + test["description"];
                 list.Add(data.SetName(testName));
             }
             return list;
         });
 }
Esempio n. 25
0
 private static TestCaseData MapTestCaseData(NPQTest qUnitTest)
 {
     var testCase = new TestCaseData(qUnitTest);
     testCase.SetName(qUnitTest.Name);
     testCase.SetDescription(qUnitTest.Description);
     return testCase;
 }
Esempio n. 26
0
 /// <summary>
 /// テストケースデータを生成します.
 /// 主にダウンロードスクリプトを含んだコンパイル手順を含んだテストケースの生成で使用されます.
 /// </summary>
 /// <param name="dirName">ソースコードを配置するディレクトリ名</param>
 /// <param name="deploySource">指定したディレクトリにソースコードを配置するアクション</param>
 /// <param name="compileActionWithWorkDirPath">作業ディレクトリと</param>
 /// <param name="relativePathsForBinaryFiles">バイナリファイルが存在するディレクトリの相対パスのリスト</param>
 /// <returns>テストケースデータのシーケンス(ソースコードの配置に失敗した場合は空)</returns>
 protected IEnumerable<TestCaseData> SetUpTestCaseData(
     string dirName,
     Func<string, bool> deploySource,
     Action<string> compileActionWithWorkDirPath,
     params string[] relativePathsForBinaryFiles)
 {
     var deployPath = FixtureUtil.GetDownloadPath(LanguageName, dirName);
     // relativePathsForBinaryFilesの正規化
     if (relativePathsForBinaryFiles == null
         || relativePathsForBinaryFiles.Length == 0) {
         relativePathsForBinaryFiles = new[] { dirName };
     }
     var testCase = new TestCaseData(
             deployPath, relativePathsForBinaryFiles,
             compileActionWithWorkDirPath ?? (workDirPath => { }));
     if (Directory.Exists(deployPath)
         &&
         Directory.EnumerateFiles(
                 deployPath, "*" + Extension, SearchOption.AllDirectories).Any()) {
         yield return testCase;
         yield break;
     }
     Directory.CreateDirectory(deployPath);
     // ソースコードの配置に成功した場合のみテストケースデータを生成する
     if (deploySource(deployPath)) {
         yield return testCase;
     }
 }
Esempio n. 27
0
        private IEnumerable<TestCaseData> BuildTestCases(IEnumerable<TestXml> tests)
        {
            var testCases = new List<TestCaseData>(tests.Count());

            foreach (var test in tests)
            {
                TestCaseData testCaseDataNUnit = new TestCaseData(test);
                testCaseDataNUnit.SetName(test.GetName());
                testCaseDataNUnit.SetDescription(test.Description);
                foreach (var category in test.Categories)
                    testCaseDataNUnit.SetCategory(CategoryHelper.Format(category));
                foreach (var property in test.Traits)
                    testCaseDataNUnit.SetProperty(property.Name, property.Value);

                //Assign auto-categories
                if (EnableAutoCategories)
                {
                    foreach (var system in test.Systems)
                        foreach (var category in system.GetAutoCategories())
                            testCaseDataNUnit.SetCategory(CategoryHelper.Format(category));
                }
                //Assign auto-categories
                if (EnableGroupAsCategory)
                {
                    foreach (var groupName in test.GroupNames)
                        testCaseDataNUnit.SetCategory(CategoryHelper.Format(groupName));
                }

                testCases.Add(testCaseDataNUnit);
            }
            return testCases;
        }
 private static IEnumerable<TestCaseData> GetCases()
 {
     return Cases.Select(c =>
         {
             var data = new TestCaseData(c.Value.Item1, c.Value.Item2);
             data.SetName(c.Key);
             return data;
         });
 }
 public static TestCaseData SetSourceLocationEx(this TestCaseData td, string path, int lineNumber = 1)
 {
     td.Properties.Add(CodeFilePath, path);
     td.Properties.Add(LineNumber, lineNumber);
     return(td);
 }
Esempio n. 30
0
            public static IEnumerable<ITestCaseData> GetTestCases()
            {
                const string prefix = "MongoDB.Driver.Tests.Specifications.command_monitoring.tests.";
                return Assembly
                    .GetExecutingAssembly()
                    .GetManifestResourceNames()
                    .Where(path => path.StartsWith(prefix) && path.EndsWith(".json"))
                    .SelectMany(path =>
                    {
                        var doc = ReadDocument(path);
                        var data = ((BsonArray)doc["data"]).Select(x => (BsonDocument)x).ToList();
                        var databaseName = doc["database_name"].ToString();
                        var collectionName = doc["collection_name"].ToString();

                        return ((BsonArray)doc["tests"]).Select(def =>
                        {
                            var testCase = new TestCaseData(data, databaseName, collectionName, (BsonDocument)def);
                            testCase.Categories.Add("Specifications");
                            testCase.Categories.Add("command-monitoring");
                            return testCase.SetName((string)def["description"]);
                        });
                    });
            }
Esempio n. 31
0
    public IEnumerable GetObservations()
    {
      var t = GetType();

      var categoryName = "Uncategorized";
      var description = string.Empty;

#if NET_STANDARD
      var categoryAttributes = t.GetTypeInfo().CustomAttributes.Where(ca => ca.AttributeType == typeof(CategoryAttribute));
      var subjectAttributes = t.GetTypeInfo().CustomAttributes.Where(ca => ca.AttributeType == typeof(SubjectAttribute));
#else
      var categoryAttributes = t.GetCustomAttributes(typeof(CategoryAttribute), true);
      var subjectAttributes = t.GetCustomAttributes(typeof(SubjectAttribute), true);
#endif

#if NET_STANDARD
            if (categoryAttributes.Any())
      {
        categoryName = categoryAttributes.First().ConstructorArguments[0].Value.ToString();
#else
      if (categoryAttributes.Length > 0)
      {
        var categoryAttribute = (CategoryAttribute)categoryAttributes[0];
        categoryName = categoryAttribute.Name;
#endif
      }

#if NET_STANDARD
      if (subjectAttributes.Any())
      {
        description = subjectAttributes.First().ConstructorArguments[0].Value.ToString();
#else
            if (subjectAttributes.Length > 0)
      {
        var subjectAttribute = (SubjectAttribute)subjectAttributes[0];
        description = subjectAttribute.Subject;
#endif
      }

      var fieldInfos = t.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
      var itFieldInfos = new List<FieldInfo>();

      foreach (var info in fieldInfos)
      {
        if (info.FieldType.Name.Equals("It"))
          itFieldInfos.Add(info);
      }

      foreach (var it in itFieldInfos)
      {
        var data = new TestCaseData(it.GetValue(this));
        data.SetDescription(description);
        data.SetName(it.Name.Replace("_", " "));
        data.SetCategory(categoryName);
        yield return data;
      }
    }

    [Test, SpecificationSource("GetObservations")]
Esempio n. 32
0
        public void Tessellate_WithAsset_ReturnsExpectedTriangulation(TestCaseData data)
        {
            var pset = _loader.GetAsset(data.AssetName).Polygons;
            var tess = new Tess();
            PolyConvert.ToTess(pset, tess);
            tess.Tessellate(data.Winding, ElementType.Polygons, data.ElementSize);

            var resourceName = Assembly.GetExecutingAssembly().GetName().Name + ".TestData." + data.AssetName + ".testdat";
            var testData = ParseTestData(data.Winding, data.ElementSize, Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName));
            Assert.IsNotNull(testData);
            Assert.AreEqual(testData.ElementSize, data.ElementSize);

            var indices = new List<int>();
            for (int i = 0; i < tess.ElementCount; i++)
            {
                for (int j = 0; j < data.ElementSize; j++)
                {
                    int index = tess.Elements[i * data.ElementSize + j];
                    indices.Add(index);
                }
            }

            Assert.AreEqual(testData.Indices, indices.ToArray());
        }