public static IEnumerable <ITestCaseData> GetTestCases() { const string prefix = "MongoDB.Driver.Tests.Specifications.crud.tests."; var testDocuments = Assembly .GetExecutingAssembly() .GetManifestResourceNames() .Where(path => path.StartsWith(prefix) && path.EndsWith(".json")) .Select(path => ReadDocument(path)); foreach (var testDocument in testDocuments) { var data = testDocument["data"].AsBsonArray.Cast <BsonDocument>().ToList(); foreach (BsonDocument definition in testDocument["tests"].AsBsonArray) { foreach (var async in new[] { false, true }) { var testCase = new TestCaseData(data, definition, async); testCase.SetCategory("Specifications"); testCase.SetCategory("crud"); testCase.SetName($"{definition["description"]}({async})"); yield return(testCase); } } } }
public static IEnumerable <ITestCaseData> GetTestCases() { const string prefix = "MongoDB.Driver.Specifications.connection_string.tests."; 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.SetCategory("Specifications"); data.SetCategory("ConnectionString"); var testName = fullName.Remove(fullName.Length - 5) + ": " + test["description"]; if (_ignoredTestNames.Contains(testName)) { data = data.Ignore("Does not apply"); } list.Add(data.SetName(testName)); } return list; })); }
public static IEnumerable <TestCaseData> RemoteConnections(bool?named, int flags = 0) { foreach (var item in GetFileItems(svrfn, null, filter)) { var tcd = new TestCaseData(item.Take(5).Cast <object>().ToArray()); //.SetName(item[10]); int flagVal = 0; for (int i = 5; i < 10; i++) { if (item[i][0] == 'T') { tcd.SetCategory(svrhdr[i]); flagVal |= (1 << (i - 5)); } } if (flags == 0 || flags == flagVal) { yield return(tcd); } } bool filter(IReadOnlyDictionary <string, string> d) { var svr = d["Server"]; var bSvr = !named.HasValue || string.IsNullOrEmpty(svr) != named.Value; //var real = bool.Parse(d["ValidSvr"]?.ToLower()); //var bReal = valid.HasValue ? real == valid.Value : true; //var vCred = bool.Parse(d["ValidCred"]?.ToLower()); //var bCred = validCred.HasValue ? vCred == validCred.Value : true; //var vAdm = bool.Parse(d["UserIsAdmin"]?.ToLower()); //var bAdm = admin.HasValue ? vAdm == admin.Value : true; return(bSvr); // && bReal && bCred && bAdm; } }
public static IEnumerable <TestCaseData> GetData() { foreach (Goto gotoItem in CurrentConfiguration.Gotos) { // Go through each of the browser enum. For example: gotoItem.Browser might be ALL foreach (Browser browser in Enum.GetValues(typeof(Browser))) { // Skip the all enum: We only want to see the individual ones if (browser == Browser.ALL) { continue; } // If specified IEXPLORE but flag looking at is CHROME, don't create a test for it // However, if specified ALL, ALL has CHROME, create a test for it, and one for IEXPLORE too if (!gotoItem.Browser.HasFlag(browser)) { continue; } TestCaseData tcd = new TestCaseData(gotoItem); tcd.SetCategory(browser.ToString()); yield return(tcd); } } }
/// <summary> /// Build list of reports to test. /// </summary> /// <remarks> /// Note: We're not passing the reportId through the params because we don't want the test-case name to vary from build-to-build, confusing TeamCity. /// </remarks> public static IEnumerable <TestCaseData> GetReports() { var includeInFastTests = new List <string> { "AA_All Fields", "AA_Employee", "AF_All Fields" }; var skipReports = new List <string> { "Drinks" }; // TODO: Repair the Drinks report. if (testCaseData != null) { return(testCaseData); } try { const string sql = @"select Id,name from _vReport where TenantId = (select Id from _vTenant where name='EDC') order by name"; List <TestCaseData> res = new List <TestCaseData>(); using (DatabaseContext ctx = DatabaseContext.GetContext()) using (IDbCommand cmd = ctx.CreateCommand(sql)) { IDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { long id = reader.GetInt64(0); string name = reader.GetString(1); if (skipReports.Contains(name)) { continue; } if (reportLookup.ContainsKey(name)) { EventLog.Application.WriteWarning("Multiple reports named: " + name); } else { reportLookup[name] = id; var testCase = new TestCaseData(name); if (!includeInFastTests.Contains(name)) { testCase = testCase.SetCategory("ExtendedTests"); } res.Add(testCase); } } } testCaseData = res; return(res); } catch (Exception ex) { EventLog.Application.WriteError(ex.ToString()); throw; } }
public static List <TestCaseData> RoomsFromJsonFile() { // read and parse file var filePath = "rooms.json"; var contents = File.ReadAllText(filePath); var rooms = JsonConvert.DeserializeObject <List <ExternalRoomData> >(contents); var testCases = new List <TestCaseData>(); //build up the test case data foreach (var test in rooms) { var testCase = new TestCaseData(test.RoomData) .SetName(test.TestName) .SetDescription(test.Description); test.Categories.ForEach(cat => testCase.SetCategory(cat)); if (test.IsExplicit) { testCase.Explicit(); } if (test.IsIgnored) { testCase.Ignore(test.IgnoreReason); } testCases.Add(testCase); } ; return(testCases); }
public static IEnumerable <TestCaseData> GetTestData() { var results = new List <TestCaseData>(); var oldClasses = _oldAssembly.GetTypes().Where(m => m.IsPublic && !string.IsNullOrEmpty(m.Namespace)).ToList(); var newClasses = _newAssembly.GetTypes().Where(m => m.IsPublic && !string.IsNullOrEmpty(m.Namespace)).ToList(); foreach (var oldClass in oldClasses) { // Find new class that match with old class var newClass = GetMemberInType(newClasses, oldClass); if (newClass == null) { throw new Exception("Could not found type " + oldClass.FullName + " in new assembly."); } var newClassMembers = newClass.GetCommonMembers(); var oldClassMembers = oldClass.GetCommonMembers(); foreach (var mi in oldClassMembers) { var testCaseData = new TestCaseData(new CompatibilityTestData { ClassName = newClass.FullName, ClassMembersFound = newClassMembers, MemberToTest = mi }); var className = GetActualTypeName(newClass); var typeName = mi.MemberType == MemberTypes.Constructor ? "" : GetMemberUnderlyingTypeName(mi) + " "; var testCaseName = ""; testCaseData.SetCategory(className); if (mi.MemberType == MemberTypes.Constructor || mi.MemberType == MemberTypes.Method) { var oldClassCi = (mi as MethodBase); var oldParams = oldClassCi.GetParameters(); var prms = string.Join(",", oldParams.Select(p => p.ParameterType.Name).ToArray()); testCaseName = string.Format("{0}({1})", mi.MemberType == MemberTypes.Constructor ? className : mi.Name, prms); } else { testCaseName = mi.Name; } testCaseData.SetName(className + " --> " + " [" + mi.MemberType + "] --> " + typeName + testCaseName); results.Add(testCaseData); } } return(results); }
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); } }
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.SetCategory("Specifications"); data.SetCategory("server-selection"); return data.SetName(fullName.Remove(fullName.Length - 5)); })); }
private static TestCaseData CreateTestCaseData <TTestData>(TTestData data, string testName, string testCategory, string testDescription) { var tcData = new TestCaseData(data); tcData.SetCategory(testCategory); tcData.SetDescription(testDescription); tcData.SetName(testName); return(tcData); }
private static TestCaseData GenData(int fullYears) { var gruntEmployee = new Organization.Grunt("Ivan", "Ivanov", DateTime.Now.AddYears(-fullYears), Organization.BASEPAYRATE); var data = new TestCaseData(gruntEmployee); data.SetName(string.Format(namePattern, fullYears)); data.SetCategory(categoryName); return(data); }
private static TestCaseData ToTestCaseData(this TestCase testCase) { var testCaseData = new TestCaseData(testCase.Because) { TestName = testCase.TestName, }; testCase.Categories.ForEach(category => testCaseData.SetCategory(category)); return(testCaseData); }
public static TestCaseData BuildTestCase <T>(this IConfigurationScenario <T> scenario) { var testCaseData = new TestCaseData(scenario.Name, scenario); scenario.Categories .Do(category => testCaseData.SetCategory(category)) .Done(); return(testCaseData); }
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); }
public static IEnumerable <ITestCaseData> GetTestCases() { const string prefix = "MongoDB.Driver.Specifications.server_discovery_and_monitoring.tests."; 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.SetCategory("Specifications"); data.SetCategory("server-discovery-and-monitoring"); return data .SetName(fullName.Remove(fullName.Length - 5).Replace(".", "_")) .SetDescription(definition["description"].ToString()); })); }
private static TestCaseData GenData(int fullYears) { Organization.Manager managerEmployee = new Organization.Manager("Manager", "Manageroff", DateTime.Now.AddYears(-fullYears), Organization.BASEPAYRATE); TestCaseData data = new TestCaseData(managerEmployee); data.SetName(string.Format(namePattern, fullYears)); data.SetCategory(categoryName); return(data); }
private static TestCaseData CheckAndMark(IEnumerable <BugMarkerAttribute> conditions, TestCaseData testCase) { TestCaseData result = testCase; foreach (var condition in conditions) { if (condition != null && condition.VerifyConditions(testCase.Arguments)) { result = testCase.SetCategory("Bug").SetProperty(BugAttribute.PropertyName, condition.Bug); } } return(result); }
public IEnumerable GetObservations() { Type currentType = GetType(); string categoryName = "Uncategorized"; string description = string.Empty; IEnumerable <CategoryAttribute> categoryAttributes = currentType.GetTypeInfo().GetCustomAttributes(typeof(CategoryAttribute), true) .OfType <CategoryAttribute>() .ToArray(); IEnumerable <SubjectAttribute> subjectAttributes = currentType.GetTypeInfo().GetCustomAttributes(typeof(SubjectAttribute), true).OfType <SubjectAttribute>() .ToArray(); if (categoryAttributes.Any()) { CategoryAttribute categoryAttribute = categoryAttributes.First(); categoryName = categoryAttribute.Name; } if (subjectAttributes.Any()) { //SubjectAttribute subjectAttribute = subjectAttributes.First(); //description = subjectAttribute.Subject; } FieldInfo[] fieldInfos = currentType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy); FieldInfo[] itFieldInfos = fieldInfos.Where(field => field.FieldType == typeof(Then)).ToArray(); foreach (FieldInfo thenFieldInfo in itFieldInfos) { var data = new TestCaseData(thenFieldInfo.GetValue(this)); string caseDescription = (string.IsNullOrWhiteSpace(description) ? thenFieldInfo.Name : description) .NormalizeTestName().EnsureStartsWithPrefix(); data.SetDescription(caseDescription); data.SetName(thenFieldInfo.Name.NormalizeTestName().EnsureStartsWithPrefix() + " [" + thenFieldInfo.Name + "]"); data.SetCategory(categoryName); yield return(data); } }
public static IEnumerable ListTestFiles(string folder) { var baseDir = Path.GetFullPath(Path.Combine(BaseDirectory, RelativeBasePath)); foreach (var file in Directory.EnumerateFiles(Path.Combine(baseDir, folder), InputFilePattern, SearchOption.AllDirectories) .Where(f => !f.EndsWith(OutputEndFileExtension)) .Select(f => f.StartsWith(baseDir) ? f.Substring(baseDir.Length + 1) : f) .OrderBy(f => f)) { var caseData = new TestCaseData(file); var category = Path.GetDirectoryName(file); caseData.TestName = category + "/" + Path.GetFileNameWithoutExtension(file); caseData.SetCategory(category); yield return(caseData); } }
public IEnumerable GetObservations() { var t = GetType(); var categoryName = "Uncategorized"; var description = string.Empty; var categoryAttributes = t.GetTypeInfo().GetCustomAttributes(typeof(CategoryAttribute), true); var subjectAttributes = t.GetTypeInfo().GetCustomAttributes(typeof(SubjectAttribute), true); if (categoryAttributes.Any()) { var categoryAttribute = (CategoryAttribute)categoryAttributes.First(); categoryName = categoryAttribute.Name; } if (subjectAttributes.Any()) { var subjectAttribute = (SubjectAttribute)subjectAttributes.First(); description = subjectAttribute.Subject; } 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); } }
private static TestCaseData GetManagerWithSubordinnatesData(int fullYears, double expectedResult, int[] gruntYears = null, int[] managersYears = null, int[] salesYears = null) { var manager = new Organization.Manager("Manager", "Manageroff", DateTime.Now.AddYears(-fullYears), Organization.BASEPAYRATE); int gruntsCount = 0; int managersCount = 0; int salesCount = 0; if (gruntYears != null) { gruntsCount = gruntYears.Length; foreach (var fullYear in gruntYears) { GetGrunt(fullYear).SetManager(manager); } } if (managersYears != null) { managersCount = managersYears.Length; foreach (var fullYear in managersYears) { GetManager(fullYear).SetManager(manager); } } if (salesYears != null) { salesCount = salesYears.Length; foreach (var fullYear in salesYears) { GetSales(fullYear).SetManager(manager); } } var data = new TestCaseData(manager); data.SetCategory(categoryName); data.SetDescription(string.Format(descriptionPattern, fullYears, gruntsCount, managersCount, salesCount)); data.SetName(string.Format(namePattern, fullYears, gruntsCount + managersCount + salesCount)); data.Returns(expectedResult); return(data); }
private IEnumerable <TestCaseData> BuildTestCases(IEnumerable <TestXml> tests) { var testCases = new List <TestCaseData>(tests.Count()); foreach (var test in tests) { // Build different instances for a test, if no instance-settling is defined then the default instance is created var instanceArgsBuilder = new InstanceArgsBuilder(serviceLocator, Variables); instanceArgsBuilder.Setup(test.InstanceSettling); instanceArgsBuilder.Build(); var factory = new InstanceFactory(); var instances = factory.Instantiate(instanceArgsBuilder.GetArgs()); // For each instance create a test-case foreach (var instance in instances) { var scalarHelper = new ScalarHelper(serviceLocator, instance.Variables); var testName = instance.IsDefault ? $"{test.GetName()}" : test.GetName().StartsWith("~") ? scalarHelper.InstantiateResolver <string>(test.GetName()).Execute() : $"{test.GetName()} ({instance.GetName()})"; Trace.WriteLineIf(Extensibility.NBiTraceSwitch.TraceVerbose, $"Loading test named: {testName}"); var testCaseDataNUnit = new TestCaseData(test, testName, instance.Variables); testCaseDataNUnit.SetName(testName); 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 instance categories and traits foreach (var category in instance.Categories) { var evaluatedCategory = scalarHelper.InstantiateResolver <string>(category).Execute(); testCaseDataNUnit.SetCategory(CategoryHelper.Format(evaluatedCategory)); } foreach (var trait in instance.Traits) { var evaluatedTraitValue = scalarHelper.InstantiateResolver <string>(trait.Value).Execute(); testCaseDataNUnit.SetProperty(trait.Key, evaluatedTraitValue); } //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); }
/// <summary> /// Get a list of tenants. /// </summary> /// <param name="typeAliasWithNamespace">Alias (with namespace) of type to load instances for.</param> /// <param name="csvIgnoreByName">CSV list of the names of instances that should be flagged as 'ignore'.</param> /// <returns>A list of TestCaseData with three parameters set: 1. <see cref="TenantInfo"/>, 2. instance ID, 3. instance name</returns> public static IEnumerable <TestCaseData> GetInstancesAsTestData(string typeAliasWithNamespace, string csvIgnoreByName = null, string customSql = null) { var tenantList = GetTenants( ); var tenantDict = tenantList.ToDictionary(t => t.TenantId); if (tenantDict.Count == 0) { throw new Exception("No tenants found"); } ISet <string> ignoreNames = new HashSet <string>((csvIgnoreByName ?? "").Split(',').Where(n => n != "")); List <TestCaseData> result = new List <TestCaseData>( ); using (DatabaseContext ctx = DatabaseContext.GetContext( )) using (IDbCommand command = ctx.CreateCommand( )) { // For all tenants, get instances of the (exact) type string sql = customSql ?? @" select isOfTypeRel.TenantId, isOfTypeRel.FromId, name.Data from Relationship isOfTypeRel join Data_Alias isOfTypeAlias on isOfTypeRel.TypeId = isOfTypeAlias.EntityId and isOfTypeRel.TenantId = isOfTypeAlias.TenantId and isOfTypeAlias.Data='isOfType' join Data_Alias typeAlias on isOfTypeRel.ToId = typeAlias.EntityId and isOfTypeRel.TenantId = typeAlias.TenantId and typeAlias.Data=@typeAlias and typeAlias.Namespace=@typeNs join Data_Alias nameAlias on isOfTypeRel.TenantId = nameAlias.TenantId and nameAlias.Data='name' left join Data_NVarChar name on isOfTypeRel.FromId = name.EntityId and isOfTypeRel.TenantId = name.TenantId and name.FieldId = nameAlias.EntityId where isOfTypeRel.TenantId <> 0 order by isOfTypeRel.TenantId, name.Data "; command.CommandText = sql; // Apply type name if (typeAliasWithNamespace != null) { string [] parts = typeAliasWithNamespace.Split(':'); if (parts.Length != 2) { throw new Exception("Expected full namespace"); } ctx.AddParameter(command, "@typeAlias", DbType.String, parts [1]); ctx.AddParameter(command, "@typeNs", DbType.String, parts [0]); } using (IDataReader reader = command.ExecuteReader( )) { while (reader.Read( )) { long tenantId = reader.GetInt64(0); long entityId = reader.GetInt64(1); string entityName = reader.IsDBNull(2) ? "Unnamed" : reader.GetString(2); TenantInfo tenantInfo; if (!tenantDict.TryGetValue(tenantId, out tenantInfo)) { tenantInfo = new TenantInfo(tenantId, "Tenant" + tenantId); tenantDict.Add(tenantId, tenantInfo); } // Create test data TestCaseData testCaseData = new TestCaseData(tenantInfo, entityId, entityName); if (ignoreNames.Contains(entityName)) { testCaseData = testCaseData.Ignore("Ignored"); } testCaseData = testCaseData.SetCategory(tenantInfo.TenantName); if (entityName == "Self Serve Component" || entityName == "Control on Form Except Screens") { testCaseData = testCaseData.SetCategory("ExtendedTests"); } result.Add(testCaseData); } } } return(result); }