//Constructor public QueriesModel(Workspace workspace, SerializationFormatKind kind, string queryType) : base() { _workspace = workspace; _kind = kind; _queryType = queryType; }
public static void SetupDefaultOpenTypeAttributes(Workspace w) { if (w.DataLayerProviderKind != DataLayerProviderKind.NonClr) AstoriaTestLog.FailAndThrow("Open types not supported for data-layers other than NonCLR"); #if !ClientSKUFramework // let the open types tests do their own thing if (w is OpenTypesWorkspace) return; #endif if (w.Name.Equals("Northwind", StringComparison.InvariantCultureIgnoreCase)) { foreach (ResourceType type in w.ServiceContainer.ResourceTypes.Distinct().Where(t => !t.Facets.IsOpenType)) type.Facets.Add(NodeFacet.Attribute(new OpenTypeResourceAttribute(type, (rp => rp.IsNavigation || rp.PrimaryKey != null || rp.Facets.ConcurrencyModeFixed)))); } else if (w.Name.Equals("Aruba", StringComparison.InvariantCultureIgnoreCase)) { foreach (ResourceType type in w.ServiceContainer.ResourceTypes.Distinct().Where(t => !t.Facets.IsOpenType)) type.Facets.Add(NodeFacet.Attribute(new OpenTypeResourceAttribute(type, (rp => rp.IsNavigation || rp.PrimaryKey != null || rp.Facets.ConcurrencyModeFixed)))); } #if !ClientSKUFramework w.AfterServiceCreation.Add(() => (w as NonClrWorkspace).OpenTypeMethodsImplementation = System.Data.Test.Astoria.LateBound.OpenTypeMethodsImplementations.Realistic); #endif // immediately after creating the service, register the undeclared properties' types w.AfterServiceCreation.Insert(0, () => RegisterTypesForUnDeclaredProperties(w)); }
public static void GetAndVerifyStatusCode(Workspace w, QueryNode query, HttpStatusCode expectedStatusCode) { AstoriaRequest request = w.CreateRequest(query); request.ExpectedStatusCode = expectedStatusCode; AstoriaResponse response = request.GetResponse(); ResponseVerification.VerifyStatusCode(response); }
public static void GetAndVerifyStatusCode(Workspace w, string uri, HttpStatusCode expectedStatusCode, out AstoriaResponse response, WebHeaderCollection requestHeaders) { AstoriaRequest request = w.CreateRequest(); request.URI = uri; request.ExpectedStatusCode = expectedStatusCode; request.Accept = "*/*"; if (requestHeaders != null) { foreach (string header in requestHeaders.AllKeys) { request.Headers[header] = requestHeaders[header]; } } response = request.GetResponse(); try { ResponseVerification.VerifyStatusCode(response); } catch (Exception e) { ResponseVerification.LogFailure(response, e); } }
protected override void WorkspaceCallback(Workspace workspace) { ServiceContainer sc = workspace.ServiceContainer; Nodes<ResourceContainer> containers = sc.ResourceContainers; ResourceContainer builds = containers["Builds"]; ResourceContainer run1s = containers["Run1s"]; ResourceContainer run2s = containers["Run2s"]; ResourceContainer run3s = containers["Run3s"]; ResourceContainer test1s = containers["Test1s"]; ResourceContainer test2s = containers["Test2s"]; ResourceContainer test3s = containers["Test3s"]; ResourceContainer test4s = containers["Test4s"]; ResourceContainer test5s = containers["Test5s"]; ResourceContainer test6s = containers["Test6s"]; ResourceContainer test7s = containers["Test7s"]; ResourceContainer test8s = containers["Test8s"]; ResourceContainer test9s = containers["Test9s"]; sc.Facets.Add(NodeFacet.Attribute(new ContainmentAttribute(builds, run1s, true))); sc.Facets.Add(NodeFacet.Attribute(new ContainmentAttribute(run1s, test1s, true))); sc.Facets.Add(NodeFacet.Attribute(new ContainmentAttribute(run1s, test2s))); sc.Facets.Add(NodeFacet.Attribute(new ContainmentAttribute(run1s, test3s, false))); sc.Facets.Add(NodeFacet.Attribute(new ContainmentAttribute(builds, run2s))); sc.Facets.Add(NodeFacet.Attribute(new ContainmentAttribute(run2s, test4s, true))); sc.Facets.Add(NodeFacet.Attribute(new ContainmentAttribute(run2s, test5s))); sc.Facets.Add(NodeFacet.Attribute(new ContainmentAttribute(run2s, test6s, false))); sc.Facets.Add(NodeFacet.Attribute(new ContainmentAttribute(builds, run3s, false))); sc.Facets.Add(NodeFacet.Attribute(new ContainmentAttribute(run3s, test7s, true))); sc.Facets.Add(NodeFacet.Attribute(new ContainmentAttribute(run3s, test8s))); sc.Facets.Add(NodeFacet.Attribute(new ContainmentAttribute(run3s, test9s, true))); }
//--------------------------------------------------------------------- // Adds concurrency attributes to resource types. //--------------------------------------------------------------------- protected virtual void AddConcurrencyAttributes(Workspace w) { if (!GetType().Name.Contains("Concurrency")) return; HashSet<ResourceType> typesWithETags = new HashSet<ResourceType>(); foreach (ResourceContainer container in w.ServiceContainer.ResourceContainers) { ResourceType baseType = container.BaseType; if (!typesWithETags.Add(baseType)) continue; // set up ETags NodeType[] etagTypes = new NodeType[] { Clr.Types.String, Clr.Types.Int16, Clr.Types.Int32, Clr.Types.Int64, Clr.Types.Guid }; List<ResourceProperty> possibleETagProperties = baseType.Properties.OfType<ResourceProperty>() .Where(p => etagTypes.Contains(p.Type) && !p.IsComplexType && !p.IsNavigation && p.PrimaryKey == null && p.Facets.IsDeclaredProperty && !p.Facets.FixedLength && p.ResourceType == baseType && p.Facets.UnderlyingType == UnderlyingType.Same && !p.Facets.IsStoreBlob && (p.Type != Clr.Types.String || (p.Facets.MaxSize.HasValue && p.Facets.MaxSize.Value < 512))) .ToList(); if (possibleETagProperties.Any()) baseType.Facets.Add(NodeFacet.Attribute(new ConcurrencyAttribute(baseType, possibleETagProperties.Choose(2).Select(p => p.Name).ToArray()))); } }
// Turns a resource type into an MLE. private static void MakeMLE(Workspace w, string typeName) { // Add blob attribute. ResourceType type = w.ServiceContainer.ResourceTypes.Where(p => p.Name == typeName).First(); type.Facets.Add(NodeFacet.Attribute(new BlobsAttribute(type))); AstoriaTestLog.WriteLineIgnore("MLE type: " + type.Name); }
//--------------------------------------------------------------------- // Constructs AstoriaRequest and sets. //--------------------------------------------------------------------- private BlobsRequest(Workspace w, SerializationFormatKind format, RequestVerb verb, string uri, HttpStatusCode expectedStatusCode) : base(w) { // Common settings for MLEs and MRs. base.IsBlobRequest = true; base.Verb = verb; base.ExpectedStatusCode = expectedStatusCode; // Construct request URI. if (uri.Contains("(*)")) { // Replace (*) with random key. string relativeURI = uri.Remove(0, w.ServiceUri.Length + 1); ResourceContainer container = w.ServiceContainer.ResourceContainers[relativeURI.Substring(0, relativeURI.IndexOf("(*)"))]; KeyExpression key = null; try { key = w.GetRandomExistingKey(container, container.BaseType); } catch(Exception e) { AstoriaTestLog.Skip("Unable to get random key"); } base.Query = ContainmentUtil.BuildCanonicalQuery(key); base.URI += relativeURI.Substring(relativeURI.IndexOf("(*)") + 3); } else { // Deterministic URI. base.URI = uri; } LastURI = base.URI; }
//Constructor public QueryModel(Workspace workspace, SerializationFormatKind kind, QueryModel parent) : base( parent ) { _workspace = workspace; _kind = kind; _parent = parent; }
public AstoriaServiceHost(Workspace workspace, string webDataServicePrefixName, string machineName, AstoriaDatabase database) : base(workspace, webDataServicePrefixName, machineName, database) { if (AstoriaTestProperties.Host == Host.IDSH || AstoriaTestProperties.Host == Host.IDSH2) { if (AstoriaTestProperties.HostAuthenicationMethod != "None") AstoriaTestLog.FailAndThrow("Test implementations of IDSH do not support authentication"); } waitHandleName = waitHandlePrefix + identifier; serviceInstanceName = this.WebDataServicePrefixName + "_" + identifier; exeName = serviceName + this.WebDataServicePrefixName; if (ProcessHelper.IsLocalMachine(this.MachineName)) { DestinationFolder = Path.Combine(serviceHostFolder, serviceInstanceName); DestinationFolder_Local = DestinationFolder; ExecutablePath = Path.Combine(DestinationFolder, exeName + ".exe"); localExecutablePath = ExecutablePath; } else { string remoteMachineLocalPath = IISHelper.GetLocalMachineWWWRootSharePath(this.MachineName); DestinationFolder_Local = Path.Combine(IISHelper.GetLocalMachineWWWRootSharePath(this.MachineName), serviceInstanceName); DestinationFolder = Path.Combine(IISHelper.GetWWWRootSharePath(this.MachineName), serviceInstanceName); ExecutablePath = Path.Combine(DestinationFolder, exeName + ".exe"); localExecutablePath = Path.Combine(DestinationFolder_Local, exeName + ".exe"); } rootUri = Uri.UriSchemeHttp + "://" + this.MachineName + ":7777"; }
protected override void WorkspaceCallback(Workspace w) { // Turn some entities into MLEs. MakeMLE(w, "Project"); _w = w; w.BeforeServiceCreation.Insert(w.BeforeServiceCreation.IndexOf(w.PopulateHostSourceFolder) + 1, this.CreateDataStreamProviderCode); }
//Constructor public PredicateModel(Workspace w,ResourceContainer container, ResourceProperty p, KeyExpression parentKey, ResourceType resType) { _resourceContainer = container; _workspace = w; _resType = resType; _key = parentKey; _prop = p; }
//--------------------------------------------------------------------- // Adds blobs attributes to resource types. //--------------------------------------------------------------------- protected virtual void AddBlobsAttributes(Workspace w, params string[] typeNames) { foreach (string typeName in typeNames) { ResourceType type = w.ServiceContainer.ResourceTypes.Where(t => t.Name == typeName).First(); type.Facets.Add(NodeFacet.Attribute(new BlobsAttribute(type))); } }
//Constructor public UriQueryBuilder(Workspace workspace, string rootHttpAddress) : base(workspace) { _rootHttpAddress = rootHttpAddress; this.UseBinaryFormatForDates = true; this.CleanUpSpecialCharacters = true; this.EscapeUriValues = false; this.UseSmallCasing = null; }
protected internal CodeLayerBuilderBase(Workspace workspace, WorkspaceLanguage language, string codefilePath) { _workspace = workspace; _language = language; _codeFilePath = codefilePath; _writer = new StreamWriter(_codeFilePath); _codeLanguageHelper = new CSharpCodeLanguageHelper(_writer); }
//--------------------------------------------------------------------- protected override void WorkspaceCallback(Workspace w) { // Enable expression capture callback. InjectCode(w, "ExpressionHook", "ExpressionTreeTestBaseVisitor", "ExpressionTreeToXmlSerializer"); // Enable various features. base.WorkspaceCallback(w); // Fix all NonClr property types. AstoriaTestProperties.Seed = 2009; }
public NonClrContextTemplateFile(Workspace workspace, string destinationPath) : base("Microsoft.Data.Test.ReflectionCodeGeneration.Templates.NonClrContextTemplate.cs", destinationPath) { _workspace = workspace; this.ReplaceCustomTokens += GenerateServiceOperations; this.ReplaceCustomTokens += GenerateMetadata; this.AddDefaultWorkspaceTokens(workspace); this.Tokens.Add("[[Inheritance]]", "NonClrContext"); }
public static AstoriaCustomServiceHost GetCustomHost(Workspace workspace) { if (workspace.Database == null && (workspace.DataLayerProviderKind == DataLayerProviderKind.Edm || workspace.DataLayerProviderKind == DataLayerProviderKind.LinqToSql)) workspace.Database = new TestExecutionLayer.AstoriaDatabase(workspace.Name); AstoriaCustomServiceHost host = new AstoriaCustomServiceHost(workspace, workspace.WebServiceName, workspace.Database); workspace.DataService = host; host.CreateWebService(false); return host; }
//--------------------------------------------------------------------- // Constructs request to MLE. //--------------------------------------------------------------------- public static BlobsRequest MLE(Workspace w, SerializationFormatKind format, RequestVerb verb, BlobsPayload payload, HttpStatusCode expectedStatusCode, params string[] URI) { string uri = URI.Length == 0 ? LastURI : URI[0]; BlobsRequest rq = new BlobsRequest(w, format, verb, uri, expectedStatusCode); // Specific request properties. rq.Format = format; rq.ContentType = SerializationFormatKinds.ContentTypeFromKind(format); rq.Accept = rq.ContentType; rq.Payload = (payload != null ? payload.ToString() : null); return rq; }
public static void RegisterTypesForUnDeclaredProperties(Workspace w) { if (w.DataService == null || w.DataService.ConfigSettings == null) AstoriaTestLog.FailAndThrow("Cannot register complex types as service is not set up yet"); IEnumerable<Type> toAdd = w.ServiceContainer.ResourceTypes .SelectMany(rt => rt.Properties.OfType<ResourceProperty>()) .Where(rp => !rp.Facets.IsDeclaredProperty) .Select(rp => rp.Type.ClrType) .Distinct(); //foreach (Type type in toAdd) // w.DataService.ConfigSettings.AddRegisterKnownType(type.FullName); }
public static UpdatePayloadBuilder CreateUpdatePayloadBuilder(Workspace w, SerializationFormatKind format, RequestVerb requestVerb) { switch (format) { case SerializationFormatKind.Atom: case SerializationFormatKind.Default: case SerializationFormatKind.PlainXml: return new AtomUpdatePayloadBuilder(w, requestVerb); case SerializationFormatKind.JSON: return new JsonUpdatePayloadBuilder(w, requestVerb); default: throw new ArgumentException("Could not create a payload builder for format: " + format.ToString()); } }
public GraphBasedDataGenerator(Workspace w, IDataInserter inserter) { #if !ClientSKUFramework if (!(w is InMemoryWorkspace || w is NonClrWorkspace)) throw new NotSupportedException("GraphBasedDataGenerator is not supported for workspaces other than InMemory and NonClr"); #endif _workspace = w; Done = false; DataInserter = inserter; Done = false; }
public void AddDefaultWorkspaceTokens(Workspace workspace) { _tokens.Add("[[ContextTypeName]]", workspace.ContextTypeName); _tokens.Add("[[ContextNamespace]]", workspace.ContextNamespace); _tokens.Add("[[WorkspaceName]]", workspace.Name); switch (AstoriaTestProperties.Host) { case Host.WebServiceHost: case Host.WebServiceHostRemote: case Host.IDSH: case Host.IDSH2: _tokens.Add("[[ServiceClassName]]", "TestServiceHost." + workspace.ServiceClassName); break; default: _tokens.Add("[[ServiceClassName]]", workspace.ServiceClassName); break; } }
//--------------------------------------------------------------------- // Customizes the workspace by enabling features. //--------------------------------------------------------------------- protected override void WorkspaceCallback(Workspace w) { // Enable features. EnableServerGeneratedKeys(w); AddBlobsAttributes(w, "Project", "College", "GradStudent", "Vehicle"); AddConcurrencyAttributes(w); ImplementServiceProvider(w); ImplementStreamProvider(w); // Fixup and inject additional code. w.GlobalAdditionalCode = FixupAdditionalCode(w.GlobalAdditionalCode ?? "") .Replace("ContextNamespace", w.ContextNamespace) .Replace("ContextTypeName", w.ContextTypeName) .Replace("DataServiceClass", w.ServiceClassName); // Dump additional code for easier lab run investigations. if (AstoriaTestProperties.IsLabRun) AstoriaTestLog.WriteLineIgnore(w.GlobalAdditionalCode); w.GenerateClientTypes = true; w.PopulateClientTypes(); }
private void AddPagingProvider(Workspace w) { w.Settings.HasPagingProvider = true; w.ServiceModifications.Interfaces.IServiceProvider.Services[typeof(Microsoft.OData.Service.Providers.IDataServicePagingProvider)] = "new PagingProviderWrapper(new SimplePagingProvider())"; w.GlobalAdditionalCode += string.Join(Environment.NewLine, new string[] { "internal class SimplePagingProvider : IDataServicePagingProvider", "{", " object[] IDataServicePagingProvider.GetContinuationToken(IEnumerator enumerator)", " {", " return " + ContinuationTokenAsCode + ";", " }", " void IDataServicePagingProvider.SetContinuationToken(IQueryable query, ResourceType resourceType, object[] continuationToken)", " {", " // do nothing", " }", "}" }); w.WebServiceName = w.WebServiceName + "_PP"; }
// Creates MLEs and generates server-side code. protected override void WorkspaceCallback(Workspace w) { // Turn some entities into MLEs. MakeMLE(w, "InternalPicture"); MakeMLE(w, "ExternalPicture"); // Read additional code from resources. string resPath = "Microsoft.Data.Test.Features.Blobs.Client.Resources.PicturesTagsEdm.res.cs"; using (StreamReader reader = new StreamReader(GetType().Assembly.GetManifestResourceStream(resPath), true)) { w.GlobalAdditionalCode = reader.ReadToEnd(); } w.GlobalAdditionalCode = w.GlobalAdditionalCode.Replace("ContextNamespace", w.ContextNamespace).Replace("ContextTypeName", w.ContextTypeName).Replace("DataServiceClass", w.ServiceClassName); // Dump additional code for easier lab run investigations. if (AstoriaTestProperties.IsLabRun) { AstoriaTestLog.WriteLineIgnore("Global additional code for workspace " + w.Name + ":"); AstoriaTestLog.WriteLineIgnore(w.GlobalAdditionalCode); } }
//--------------------------------------------------------------------- // Constructs request to MR. //--------------------------------------------------------------------- public static BlobsRequest MRR(Workspace w, SerializationFormatKind format, RequestVerb verb, string payload, HttpStatusCode expectedStatusCode, params string[] URI) { string uri = URI.Length == 0 ? LastURI : URI[0]; BlobsRequest rq = new BlobsRequest(w, format, verb, uri, expectedStatusCode); // Specific request properties. rq.Format = SerializationFormatKind.PlainText; rq.ContentType = "audio/mp3"; rq.Accept = (verb == RequestVerb.Get ? "*/*" : SerializationFormatKinds.ContentTypeFromKind(format)); rq.Payload = payload; // Append $value, if needed. if (uri.StartsWith("$") || uri.EndsWith(")")) { rq.URI += "/$value"; // Expect dummy ETags from stream provider. byte[] hash = new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(System.Text.Encoding.ASCII.GetBytes(rq.URI)); if ((hash[0] & 3) > 1) rq.ETagHeaderExpected = true; } return rq; }
/// <summary> /// Hook added so that people can update workspaces with Service Operations /// /// </summary> /// <param name="workspace"></param> public virtual void OnWorkspaceCreate(Workspace workspace) { }
private ResourceBodyTree CanonicalResourcePayload(Workspace workspace, ResourceContainer resourceContainer) { ResourceType type = resourceContainer.BaseType; // TODO: support PUT by adding key support. ResourceInstanceProperty[] keyProperties = new ResourceInstanceProperty[0]; ResourceInstanceKey keyExpression = new ResourceInstanceKey(resourceContainer,type, keyProperties); List<ResourceInstanceProperty> properties = new List<ResourceInstanceProperty>(); foreach (NodeProperty p in type.Properties) { // TODO: support to implement binding. if (p.Type is ResourceCollection) { continue; } if (p.Type is ComplexType) { continue; } properties.Add(new ResourceInstanceSimpleProperty(p.Name, p.GetSampleValue())); } KeyedResourceInstance instance = new KeyedResourceInstance(keyExpression, properties.ToArray()); return instance; }
public WorkspaceSettings(Workspace w) { object[] attributes = w.GetType().GetCustomAttributes(typeof(WorkspaceDefaultSettingsAttribute), true); if (attributes.Length > 0) { WorkspaceDefaultSettingsAttribute att = attributes[0] as WorkspaceDefaultSettingsAttribute; foreach (FieldInfo p in att.GetType().GetFields()) { object val = p.GetValue(att); this.GetType().GetProperty(p.Name).SetValue(this, val, null); } } }