// Returns list of workspaces matching test properties but does not create them public static Workspaces GetFilteredWorkspaces() { Workspaces workspaces = new Workspaces(); workspaces.Filter(att => att.Standard); return(workspaces); }
internal static Workspaces GetWorkspacesFilteredByTestProperties(Action <Workspace> beforeWorkspaceCreate) { if (_workspaceCreationFailed) { throw new TestFailedException("Workspaces failed on creation previously"); } if (_filteredWorkspaces == null) { try { _filteredWorkspaces = CreateFilteredWorkspaces(AstoriaTestProperties.DataLayerProviderKinds, AstoriaTestProperties.MaxPriority, true, beforeWorkspaceCreate); } catch (System.Reflection.ReflectionTypeLoadException typeloadException) { _workspaceCreationFailed = true; AstoriaTestLog.WriteLine("LoaderExceptions:"); foreach (Exception exc in typeloadException.LoaderExceptions) { AstoriaTestLog.FailAndContinue(exc); } throw typeloadException; } catch (Exception exc) { _workspaceCreationFailed = true; throw; } } return(_filteredWorkspaces); }
internal static Workspaces CreateFilteredWorkspaces(DataLayerProviderKind[] kinds, int maxPriority, bool standardOnly, Action <Workspace> beforeWorkspaceCreate) { Workspaces workspaces = new Workspaces(); //Find all workspaces List <WorkspaceCreation> workspacesToBeInitialized = new List <WorkspaceCreation>(); //Filter by Test Property information foreach (Type t in typeof(Workspaces).Assembly.GetTypes()) { object[] attributes = t.GetCustomAttributes(typeof(WorkspaceAttribute), true); if (attributes.Length > 0) { WorkspaceAttribute workspaceAttribute = attributes[0] as WorkspaceAttribute; if (kinds.Contains(workspaceAttribute.DataLayerProviderKind) && workspaceAttribute.Priority <= maxPriority && (!standardOnly || workspaceAttribute.Standard)) { WorkspaceCreation creationType = new WorkspaceCreation(); creationType.WorkspaceAttribute = workspaceAttribute; creationType.WorkspaceType = t; workspacesToBeInitialized.Add(creationType); } } } //Initialize Workspace types foreach (WorkspaceCreation wc in workspacesToBeInitialized) // some tests RELY on the arbitrary order of the workspaces //.OrderBy(wc => wc.WorkspaceAttribute.DataLayerProviderKind + "." + wc.WorkspaceAttribute.Name)) { if (!wc.WorkspaceType.IsSubclassOf(typeof(Workspace))) { //TODO: Should possibly error here continue; } else { Workspace workspace = (Workspace)wc.WorkspaceType.GetConstructor(new Type[] { }).Invoke(new object[] { }); workspaces.Add(workspace); } } //Now call create on all workspaces foreach (Workspace w in workspaces) { beforeWorkspaceCreate(w); w.Create(); } return(workspaces); }
//Overrides public override void Init() { _workspaces = new Workspaces(); //Redirect modeling output to our (debug) logger ModelTrace.Enabled = false; ModelTrace.Out = new TestLogWriter(TestLogFlags.Trace | TestLogFlags.Ignore); //Delegate base.Init(); HashSet <string> interestingPropertyNames = new HashSet <string>() { "AstoriaBuild", "Host", "Client", "DataLayerProviderKinds", "HostAuthenicationMethod", "ServerVersion", "ClientVersion", "DesignVersion", "UseOpenTypes" }; IEnumerable <PropertyInfo> properties = typeof(AstoriaTestProperties).GetProperties(BindingFlags.Public | BindingFlags.Static).OrderBy(p => p.Name); IEnumerable <PropertyInfo>[] subsets = new IEnumerable <PropertyInfo>[] { properties.Where(p => interestingPropertyNames.Contains(p.Name)), properties.Where(p => !interestingPropertyNames.Contains(p.Name)) }; foreach (IEnumerable <PropertyInfo> subset in subsets) { foreach (PropertyInfo property in subset) { Type type = property.PropertyType; object value = property.GetValue(null, null); if (type.IsValueType || type.IsPrimitive || type == typeof(string)) { AstoriaTestLog.WriteLineIgnore(property.Name + ": " + value); } else if (type.IsArray) { AstoriaTestLog.WriteLineIgnore(property.Name + ": {" + string.Join(", ", ((Array)value).OfType <object>().Select(o => o.ToString()).ToArray()) + "}"); } } AstoriaTestLog.WriteLineIgnore(""); } Workspace.CreateNewWorkspaceEvent += this.HandleWorkspaceCreationEvent; }
public Workspaces FilterByName(string name) { Workspaces result = new Workspaces(); foreach (Workspace workspace in this) { if (workspace.Name == name) { result.Add(workspace); } } return(result); }
public static void SimpleTestOnSpecificContainerType(Workspaces workspaces, string containerName, string resourceTypeName, Action <ResourceContainer, ResourceType> action) { bool testRun = false; bool testSkipped = false; foreach (Workspace workspace in workspaces) { ResourceType resourceType = null; ResourceContainer container = null; IEnumerable <ResourceContainer> containers = workspace.ServiceContainer.ResourceContainers.Where(rc => rc.Name == containerName); if (containers.Count() > 0) { container = containers.First(); } if (container != null) { if (!container.Workspace.Settings.SupportsUpdate) { testSkipped = true; continue; } IEnumerable <ResourceType> resourceTypes = container.ResourceTypes.Where(rt => rt.Name == resourceTypeName).ToList(); if (resourceTypes.Count() > 0) { resourceType = resourceTypes.First(); } action.Invoke(container, resourceType); testRun = true; } } //Test likely to be more of a one off type of test on a specific resourceType if ((testRun == false) && (!testSkipped)) { throw new TestFailedException("Couldn't find a container:" + containerName + " with a type:" + resourceTypeName + " to run test with"); } else { if (testSkipped) { throw new TestSkippedException("Container: " + containerName + " in this workspace does not support update"); } } }
public TestVariation GenerateVariation(TestCase testcase, MethodInfo method, VariationAttribute testVarAttrib) { //do not generate variations for tests which have KeepInContent set to false and the version is not V2 if (!this.KeepInContent && !Versioning.Server.SupportsV2Features) { return(null); } TestVariation ffTestVariation; MethodInfo generateEpmMappingsMethod = testcase.GetType().GetMethod("GenerateEpmMappings"); FilterResourcesLambda = GenerateLambda(); TestFunc testMethodAction = delegate() { bool thisTestFailed = true; SkipInvalidRuns(); try { generateEpmMappingsMethod.Invoke(testcase, new object[] { KeepInContent, //bool pKeepInContent, RemoveUnEligibleTypes, //bool pRemoveUnEligibleTypes, GenerateClientTypes, //bool pGenerateClientTypes, MapToAtomElements, //bool pMapPropertiesToAtomElements, MapToNonAtomElements, //bool pMapPropertiesToNonAtomElements, GenerateServerEPMMappings, //bool GenerateServerEPMMappings, KeepSameNamespace, //bool KeepSameNamespace, IncludeComplexTypes, //bool IncludeComplexTypes PreDefinedPaths, //string[] PreDefinedPaths FilterResourcesLambda //Func<ResourceType, bool> pFilterResourcesLambda }); method.Invoke(testcase, null); thisTestFailed = AstoriaTestLog.FailureFound; } catch (Microsoft.OData.Client.DataServiceClientException dsException) { if (dsException.InnerException != null) { AstoriaTestLog.WriteLine(dsException.InnerException.Message); } } catch (TestFailedException testException) { AstoriaTestLog.WriteLine("Test failed with :{0}", testException.Message); AstoriaTestLog.WriteLine("Repro Details\r\nClient Code"); } finally { //Disabling this as OOM errors prevent file copying thisTestFailed = false; #region //Clean out all the facets after the test , so that the next test is clear object workspacePointer = null; PropertyInfo testWorkspacesProperty = testcase.Parent.GetType().GetProperty("Workspaces"); workspacePointer = testcase.Parent; if (testWorkspacesProperty == null) { testWorkspacesProperty = testcase.GetType().GetProperty("Workspaces"); workspacePointer = testcase; } Workspaces testWorkspaces = (Workspaces)testWorkspacesProperty.GetValue(workspacePointer, null); foreach (Workspace workspace in testWorkspaces) { if (thisTestFailed) { string testFailureReproPath = String.Format("FF_Failure_{0}", System.Guid.NewGuid().ToString()); testFailureReproPath = System.IO.Path.Combine(Environment.CurrentDirectory, testFailureReproPath); IOUtil.CopyFolder(workspace.DataService.DestinationFolder, testFailureReproPath, true); AstoriaTestLog.WriteLine("Test failed , Repro available at : {0} ", testFailureReproPath); } if (!(workspace is EdmWorkspace)) { workspace.GenerateClientTypes = true; workspace.GenerateServerMappings = false; workspace.ApplyFriendlyFeeds(); } } #endregion } }; ffTestVariation = new TestVariation(testMethodAction); if (testVarAttrib != null) { ffTestVariation.Params = testVarAttrib.Params; ffTestVariation.Param = testVarAttrib.Param; ffTestVariation.Desc = String.Format( "{3} , {0},{1},{2},{4}{5}{6}{7}", GenerateClientTypes ? "Client Mapped" : "", GenerateServerEPMMappings ? "Server Mapped" : "", MapToAtomElements ? "Mapped to Atom" : "Mapped to Non-Atom Elements", testVarAttrib.Desc, InheritanceFilter.ToString(), KeepSameNamespace ? "Same Namespace" : "Different NameSpaces", PreDefinedPaths != null ? ",PredefinedPaths" : "", KeepInContent.ToString()); if (AstoriaTestProperties.MaxPriority == 0) { ffTestVariation.Id = 1; } else { ffTestVariation.Id = idCounter++; } ffTestVariation.Priority = this.Priority; } return(ffTestVariation); }