internal void InsertLanguageData(Workspace workspace, ResourceType resourceType) { fxLanguages languages = new fxLanguages(); fxLanguage language = languages.Choose(); AstoriaTestLog.TraceInfo("Language Data: " + language.GetType().Name); // do them one at a time so that if one fails, we know which using (SqlConnection sqlConn = new SqlConnection(this.MachineConnectionString)) { sqlConn.Open(); for (int i = 0; i < 5; i++) { using (SqlCommand sqlCmd = sqlConn.CreateCommand()) { sqlCmd.CommandTimeout = 0; sqlCmd.CommandText = GetInsertString(workspace, resourceType, language, TestUtil.Random); try { sqlCmd.ExecuteNonQuery(); } catch (SqlException error) { AstoriaTestLog.WriteLineIgnore("Error while executing: " + sqlCmd.CommandText); throw; } } } } }
protected override bool VerifyLambda(QueryTreeInfo queryTreeInfo) { List <String> outVal = null; bool result = nodeValues.TryGetValue("Where", out outVal); //Check for the where key values for (int i = 0; i < refKeys.Count; i++) { bool valuePresent = false; foreach (String s in outVal) { if (s.Contains("element." + refKeys[i].Name)) { valuePresent = true; } } if (!valuePresent) { //RefKey not found in the list AstoriaTestLog.WriteLine("RefKey not found in the list"); return(false); } } return(true); }
private void AttachDatabase() { if (_isLocal) { EnsureLocalLoginExists(); } DropDatabase(); AstoriaTestLog.WriteLineIgnore("-------AttachDb: {0}---------", this.MachineConnectionString); using (SqlConnection sqlConn = new SqlConnection(this.MachineConnectionString)) { sqlConn.Open(); using (SqlCommand sqlCmd = sqlConn.CreateCommand()) { sqlCmd.CommandTimeout = 0; CopyDatabaseFiles(); sqlCmd.CommandText = "sp_attach_db"; sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.Parameters.Add(new SqlParameter("@dbname", this.DatabaseName)); sqlCmd.Parameters.Add(new SqlParameter("@filename1", AttachedMdf)); sqlCmd.Parameters.Add(new SqlParameter("@filename2", AttachedLdf)); sqlCmd.ExecuteNonQuery(); AstoriaTestLog.WriteLineIgnore(String.Format("Completed Attaching Db {0}", this.DatabaseName)); } } }
/// <summary>Copies an existing file to a new file.</summary> /// <param name="sourcePath">The file to copy.</param> /// <param name="destinationPath">The name of the destination file. This cannot be a directory or an existing file.</param> private static void FileCopy(string sourcePath, string destinationPath) { Debug.Assert(sourcePath != null, "sourcePath != null"); Debug.Assert(destinationPath != null, "destinationPath != null"); AstoriaTestLog.WriteLineIgnore("Copying \"" + sourcePath + "\" to \"" + destinationPath + "\"..."); bool impersonate = true; Account account = new Account(null, null, null); //If its running local no need to either if (AstoriaTestProperties.DataProviderMachineName.ToLower().Equals("local")) { impersonate = false; } ImpersonationWrapper.DoAction(account, impersonate, delegate { File.Copy(sourcePath, destinationPath); if (CompactUtil.IsFileCompressed(destinationPath)) { AstoriaTestLog.WriteLineIgnore("Uncompressing '" + destinationPath + "'..."); CompactUtil.UncompressFile(destinationPath); } }); }
public void Delete() { AstoriaTestLog.WriteLineIgnore("-------Delete WebdataService ---------"); AstoriaTestLog.WriteLineIgnore("------- URI: {0}---------", this.ServiceUri); string args = String.Format("{0} {1}", Path.Combine(DestinationFolder_Local, "..\\DeleteVDir.vbs"), this.WebDataServiceName); RunProcess("cscript", args); }
public void Restore() { AstoriaTestLog.WriteLineIgnore("-------Restoring Database ---------"); AstoriaTestLog.WriteLineIgnore("------- DatabaseConnectionString: {0}---------", this.DatabaseConnectionString); if (IsEmpty) { CreateEmptyDatabase(); } else { AttachDatabase(); } }
// Generate the next random query to test public void Next() { // Choose a random Query component to test this.queryComponent = Enum.GetValues(typeof(QueryComponent)).Cast <QueryComponent>().Choose(); AstoriaTestLog.WriteLine("Testing.... " + this.queryComponent.ToString()); // Idenity the queryComponents corresponding verification class ConcretePatternDictionary patternDictionary = new ConcretePatternDictionary(); this.pattern = patternDictionary.GetPattern(this.queryComponent); // Build the actual query tree for the queryComponent this.pattern.Build(this); }
public override bool VerifyResults(bool success, string log) { switch (AstoriaTestProperties.DesignVersion) { case null: case "V1": case "V2": case "Dev10": return(success == true); default: AstoriaTestLog.FailAndThrow("Unknown /ClientVersion parameter value"); return(success == true); } }
private void CreateDatabase() { AstoriaTestLog.WriteLineIgnore("-------Create Database ---------"); AstoriaTestLog.WriteLineIgnore("------- DataLayerProviderMachineName: {0}---------", this.Machine); AstoriaTestLog.WriteLineIgnore("------- MachineConnectionString: {0}---------", this.MachineConnectionString); AstoriaTestLog.WriteLineIgnore("------- DatabaseName: {0}---------", this.DatabaseName); AstoriaTestLog.WriteLineIgnore("------- DatabaseConnectionString: {0}---------", this.DatabaseConnectionString); if (IsEmpty) { CreateEmptyDatabase(); } else { AttachDatabase(); } }
public ExecutableResults Run(string arguments) { using (Process process = new Process()) { process.StartInfo.FileName = _executablePath; if (!System.IO.File.Exists(_executablePath)) { throw new TestFailedException("Unable to find file to execute:" + _executablePath); } process.StartInfo.Arguments = arguments; process.StartInfo.WorkingDirectory = this.WorkingDirectory; AstoriaTestLog.TraceLine("Commandline tool arguments:" + arguments); process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.Start(); ReadToEndDelegate readToEnd = new ReadToEndDelegate(process.StandardOutput.ReadToEnd); IAsyncResult readToEndResult = readToEnd.BeginInvoke(null, null); try { process.WaitForExit(_millisecondsToWait); } catch (System.ComponentModel.Win32Exception win32Exception) { throw new TestFailedException( String.Format("Process {0} failed to finish in less than {1} seconds.{2}Exception information:{2}{3}", _executablePath, _millisecondsToWait / 1000, System.Environment.NewLine, win32Exception.Message)); } catch (System.SystemException systemException) { throw new TestFailedException( String.Format("Process {0} failed to finish in less than {1} seconds.{2}Exception information:{2}{3}", _executablePath, _millisecondsToWait / 1000, System.Environment.NewLine, systemException.Message)); } string output = readToEnd.EndInvoke(readToEndResult); ExecutableResults result = new ExecutableResults(process.ExitCode, output); return(result); } }
protected override bool VerifyNodes(QueryTreeInfo queryTreeInfo) { //Find the list of keys for this resource set that will appear as where nodes in the tree foreach (ResourceType type in queryTreeInfo.resourceContainer.ResourceTypes) { foreach (ResourceProperty property in type.Properties.OfType<ResourceProperty>()) { if (property.PrimaryKey != null) { refKeys.Add(property); AstoriaTestLog.WriteLine(property.Name); } } } return true; }
// Call the compare method of corresponding pattern class to verify the expr tree public void Verify() { // NOTE: The difftree assignment will change later once we go into multi level Query components this.diffTree = this.currentTree; //Do the comparison on the diff ET bool result = this.pattern.Compare(this); if (result) { //Only if succeeded, replace the prev tree with current, else preserve since it will be needed for debugging. this.prevTree = this.currentTree; } else { AstoriaTestLog.FailAndContinue(new Exception("Tree comparison failed")); } }
protected override bool VerifyLambda(QueryTreeInfo queryTreeInfo) { XmlDocument currentTreeXml = queryTreeInfo.currentTreeXml; XmlNodeList projectedNodes = null; // Find the nodes that contain the projected properties if (queryTreeInfo.wkspc.DataLayerProviderKind == DataLayerProviderKind.Edm) { projectedNodes = currentTreeXml.SelectNodes("/Call/Arguments/Quote/Lambda/Body/MemberInit/MemberAssignment"); } else if (queryTreeInfo.wkspc.DataLayerProviderKind == DataLayerProviderKind.InMemoryLinq) { projectedNodes = currentTreeXml.SelectNodes("/Call/Arguments/Quote/Lambda/Body/Conditional/False/MemberInit/MemberAssignment"); } if (projectedNodes.Count == 0) { AstoriaTestLog.WriteLine("Projected nodes not found"); return false; } // Verify all the projected properties in the node foreach (XmlNode node in projectedNodes) { if (node.Attributes[0].Value == "PropertyNameList") { List<String> projectedProps = node.SelectSingleNode("./Constant").InnerText.Split(new char[] { ',' }).ToList(); if (projectedProps.Count != refKeys.Count) { AstoriaTestLog.WriteLine("Projected props count does not match refkeys"); return false; } foreach (ResourceProperty rp in refKeys) { if (!projectedProps.Contains(rp.Name)) { AstoriaTestLog.WriteLine("Projected props is not a refkey"); return false; } } } } return true; }
/// <summary> /// Runs the specifed application with the given arguments on the Machine /// for this service. /// </summary> /// <param name="appString">Application to run.</param> /// <param name="argString">Argument to application.</param> private void RunProcess(string appString, string argString) { if (ShouldWorkaroundDueToVistaUAC()) { Process[] processes = Process.GetProcessesByName("Commander.Server"); if (processes.Length > 0) { ProcessHelper.UseCommander(Environment.MachineName, delegate(Commander.RemoteServer remoteServer) { Commander.RemoteExecutableResults results = remoteServer.ExecuteScript(argString); if (results.ExitCode != 0) { throw new TestFailedException("Unable to run create website script:\n" + results.Output); } AstoriaTestLog.TraceLine(results.Output); }); } else { throw new TestFailedException("Expected a RemoteServer program called Commander.Server.exe to be running"); } } else if (ProcessHelper.IsLocalMachine(this.MachineName)) { // Run locally. ProcessStartInfo processStart = new ProcessStartInfo(appString, argString); processStart.UseShellExecute = false; processStart.CreateNoWindow = true; AstoriaTestLog.WriteLineIgnore(appString); AstoriaTestLog.WriteLineIgnore(argString); using (Process process = Process.Start(processStart)) { if (process != null) { const int timeoutMilliseconds = 20 * 1000; process.WaitForExit(timeoutMilliseconds); } } } }
private string getRemoteSystemDrive() { try { using (SqlConnection sqlConn = new SqlConnection(this.MachineConnectionString)) { sqlConn.Open(); SqlCommand sqlCmd = sqlConn.CreateCommand(); sqlCmd.CommandTimeout = 0; sqlCmd.CommandText = "exec master..xp_cmdshell N'echo %SYSTEMDRIVE%'"; String driveLetter = (String)sqlCmd.ExecuteScalar(); return(driveLetter); } } catch (Exception e) { AstoriaTestLog.FailAndThrow("Unable to retrieve %SYSTEMDRIVE% of remote DB Machine"); } return(null); }
private void DeleteDatabaseFiles() { try { IOUtil.EnsureFileDeleted(Path.Combine(this.DestinationFolder, this.DatabaseName + ".mdf")); } catch (Exception e) { AstoriaTestLog.TraceInfo("Database cleanup failed for " + this.DestinationFolder + this.DatabaseName + ".mdf"); } try { IOUtil.EnsureFileDeleted(Path.Combine(this.DestinationFolder, this.DatabaseName + ".ldf")); } catch (Exception e) { AstoriaTestLog.TraceInfo("Database cleanup failed for " + this.DestinationFolder + this.DatabaseName + ".mdf"); } }
private void CreateEmptyDatabase() { if (_isLocal) { EnsureLocalLoginExists(); } DropDatabase(); AstoriaTestLog.WriteLineIgnore("-------CreateEmptyDb: {0}---------", this.MachineConnectionString); using (SqlConnection sqlConn = new SqlConnection(this.MachineConnectionString)) { sqlConn.Open(); using (SqlCommand sqlCmd = sqlConn.CreateCommand()) { sqlCmd.CommandTimeout = 0; sqlCmd.CommandText = String.Format("CREATE DATABASE [{0}];", this.DatabaseName); sqlCmd.ExecuteNonQuery(); } } }
//Get the expression tree public static String ProcessExpressionTree(Workspace w, QueryTreeInfo queryTreeInfo) { // Retrieve expression tree. AstoriaResponse rs; RequestUtil.GetAndVerifyStatusCode(w, w.ServiceUri + "/ExpToXml", HttpStatusCode.OK, out rs); if (rs.ActualStatusCode != HttpStatusCode.OK && rs.ActualStatusCode != HttpStatusCode.NotFound) { AstoriaTestLog.WriteLine("/ExpToXml returned error code " + rs.ActualStatusCode.ToString() + ", payload:"); AstoriaTestLog.FailAndThrow(rs.Payload); } // Extract XML document from response. XmlDocument xml = new XmlDocument(); xml.LoadXml(rs.Payload); // Skip verification in retail builds as they do not contain expression capture hook. string embeddedDocument = xml.DocumentElement.InnerText; AstoriaTestLog.WriteLine(embeddedDocument); if (embeddedDocument.StartsWith("WARNING")) { // Warn the user. AstoriaTestLog.WriteLine("WARNING: missing expression tree!"); AstoriaTestLog.Skip("Test variation skipped"); } // Separate string form and XML form. string[] pair = embeddedDocument.Split(new string[] { "[[===]]" }, StringSplitOptions.None); xml.LoadXml(pair[1].Replace("utf-16", "utf-8")); AstoriaTestLog.WriteLine(xml.OuterXml); if (queryTreeInfo != null) { queryTreeInfo.currentTreeXml = xml; } //return xml; return(pair[0]); }
private bool ShouldWorkaroundDueToVistaUAC() { if (AstoriaTestProperties.Host == Host.LocalIIS) { AstoriaTestLog.TraceLine("Host=LocalIIS"); if (!ProcessHelper.IsVistaOrLater()) { AstoriaTestLog.TraceLine("IsVista=False"); return(false); } AstoriaTestLog.TraceLine("IsVista=True"); WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent(); WindowsPrincipal principle = new WindowsPrincipal(currentIdentity); SecurityIdentifier sidAdmin = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null); if (!principle.IsInRole(sidAdmin)) { AstoriaTestLog.TraceLine("IsAdmin=False"); return(true); } AstoriaTestLog.TraceLine("IsAdmin=true"); } return(false); }
public void VerifyService() { // for call logging, we need the directory to exist, and the service doesn't necessarily have permission to create it // TODO: find some better, common place to put this for IIS, WebServiceHost, etc. Right now this is the best spot #if !ClientSKUFramework IOUtil.EnsureEmptyDirectoryExists(Path.Combine(DestinationFolder, CallOrder.APICallLog.DirectoryName)); #endif const int retryCount = 10; const int sleepTime = 6000; AstoriaTestLog.WriteLineIgnore("Verifying web service: " + this.ServiceUri); HttpWebRequest request = null; HttpWebResponse response = null; WebException webException = null; for (int count = 0; count < retryCount; count++) { try { request = (HttpWebRequest)HttpWebRequest.Create(this.ServiceUri + "/$metadata"); request.UseDefaultCredentials = true; response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream())) reader.ReadToEnd(); if (response.StatusCode == HttpStatusCode.OK) { AstoriaTestLog.WriteLineIgnore("Service verified."); return; } else { // can this happen without throwing? AstoriaTestLog.WriteLine("\tUnexpected status code: " + response.StatusCode); } } catch (Exception e) { string indent = "\t"; while (e != null) { if (e is WebException) { webException = e as WebException; } AstoriaTestLog.WriteLine(indent + e.GetType().Name + ": " + e.Message); indent += "\t"; e = e.InnerException; } } Thread.Sleep(sleepTime); } if (webException != null) { AstoriaTestLog.TraceLine("Web exception:"); AstoriaTestLog.TraceLine(webException.ToString()); if (webException.Response != null) { string exceptionPayload; using (StreamReader reader = new StreamReader(webException.Response.GetResponseStream())) exceptionPayload = reader.ReadToEnd(); AstoriaTestLog.TraceLine("Exception Payload:"); AstoriaTestLog.TraceLine(exceptionPayload); } } AstoriaTestLog.FailAndThrow("Service could not be verified."); }
protected void WriteEntityTypeClass(ResourceType rt) { // write the key attribute CodeBuilder.WriteDataKeyAttribute(rt.Properties.OfType <ResourceProperty>().Where(rp => rp.PrimaryKey != null)); // write other attributes foreach (ResourceAttribute att in rt.Facets.Attributes) { att.Apply(CodeBuilder); } //// friendly feeds attributes are sometimes on the properties! //foreach (NodeProperty p in rt.Properties) //{ // FriendlyFeedsAttribute attribute; // if (FriendlyFeedsAttribute.TryGetAttribute(rt, p, out attribute)) // { // FriendlyFeedsAttribute fromBase; // if (rt.BaseType == null || !FriendlyFeedsAttribute.TryGetAttribute(rt.BaseType, p, out fromBase) || attribute != fromBase) // { // attribute.Apply(CodeBuilder); // } // } //} string baseType = null; if (rt.BaseType != null) { baseType = rt.BaseType.Name; } CodeBuilder.WriteBeginClass(rt.Name, baseType, null, rt.Facets.AbstractType); List <string> incrementers = new List <string>(); foreach (ResourceProperty rp in rt.Properties.OfType <ResourceProperty>().Where(p => p.Facets.ServerGenerated)) { if (rp.Type != Clr.Types.Int32) { AstoriaTestLog.FailAndThrow("Currently, we only code-gen server-generated ints"); } CodeBuilder.WriteLine("private static int _" + rp.Name + "_Counter = 0;"); incrementers.Add(rp.Name); } if (incrementers.Any()) { CodeBuilder.WriteLine(" public " + rt.Name + "()"); CodeBuilder.WriteLine(" {"); foreach (string propertyName in incrementers) { CodeBuilder.WriteLine(" this." + propertyName + " = _" + propertyName + "_Counter++;"); } CodeBuilder.WriteLine(" }"); } // write out the properties foreach (ResourceProperty rp in rt.Properties.OfType <ResourceProperty>()) { // if this property is not defined on the base type if (rt.BaseType == null || !rt.BaseType.Properties.Any(p => p.Name == rp.Name)) { if (rp.Facets.IsDeclaredProperty) { if (rp.IsNavigation) { CreateNavigationProperty(rp); } else { CreateValueProperty(rp); } } } } //Create a BiDirectionalRelationshipMap CodeBuilder.CreateNavigationMapMethod(rt); CodeBuilder.WriteEndClass(rt.Name); CodeBuilder.WriteLine(); }
protected override bool VerifyNodes(QueryTreeInfo queryTreeInfo) { //Find the list of keys for this resource set that will appear as where nodes in the tree foreach (ResourceType type in queryTreeInfo.resourceContainer.ResourceTypes) { foreach (ResourceProperty property in type.Properties.OfType <ResourceProperty>()) { if (property.PrimaryKey != null) { refKeys.Add(property); AstoriaTestLog.WriteLine(property.Name); } } } if (queryTreeInfo.currentTree.Contains(queryTreeInfo.rootTree)) { // Obtain the diff tree. The +1 is for the "." that is the node separator queryTreeInfo.diffTree = queryTreeInfo.currentTree.Substring(queryTreeInfo.rootTree.Length + 1); AstoriaTestLog.WriteLine("Diff Tree : " + queryTreeInfo.diffTree); } //Construct the Tree Dictionary String[] splitString = new String[] { ")." }; String[] result = queryTreeInfo.diffTree.Split(splitString, StringSplitOptions.None); AstoriaTestLog.WriteLine("Split string"); foreach (String s in result) { AstoriaTestLog.WriteLine(s); } //ThenBy and Where nodes can repeat, so create a list to capture the multiple values List <String> whereList = new List <String>(); //Look through each node and construct the dictionary foreach (String s in result) { if (s.StartsWith("Where")) { //Can have multiple where nodes, so just create the list of values here and add it to dictionary later String tempStr = s.Split(new String[] { "Where(" }, StringSplitOptions.RemoveEmptyEntries)[0]; //Dont add where(p => true) occurances //TODO: Confirm if its ok to ignore where(p=>true) nodes. if (!(tempStr.Contains("p => True"))) { whereList.Add(tempStr); } else { AstoriaTestLog.WriteLine("Where(p => true) node found, ignoring the node"); } } } //Add the where list to the dictionary if (!nodeValues.ContainsKey("Where")) { if (whereList.Count > 0) { nodeValues.Add("Where", whereList); } if ((refKeys.Count) != whereList.Count) { //Where node count doesnt match AstoriaTestLog.WriteLine("Where nodes count doesnt match"); return(false); } } return(true); }
public static void CompileCodeFiles(string[] codeFilePaths, string[] resourceFiles, string dllFilePath, string[] compilerDefines, WorkspaceLanguage language, Dictionary <string, string> providerOptions, string[] referencedAssemblies, bool compileExe) { CodeDomProvider compiler; if (language == WorkspaceLanguage.VB) { compiler = new VBCodeProvider(providerOptions); } else { compiler = new CSharpCodeProvider(providerOptions); } //Options CompilerParameters cp = new CompilerParameters(); cp.GenerateExecutable = compileExe; cp.IncludeDebugInformation = true; cp.OutputAssembly = dllFilePath; if (!Versioning.Server.SupportsV2Features) { cp.CompilerOptions = "/Define:ASTORIA_PRE_V2"; } if (compilerDefines != null) { foreach (string define in compilerDefines) { cp.CompilerOptions += " /Define:" + define; } } if (resourceFiles != null && resourceFiles.Length > 0) { foreach (string embeddedResourceFile in resourceFiles) { cp.CompilerOptions += " /res:" + embeddedResourceFile; } } Func <string, string> resolve = delegate(string f) { if (string.Equals(DataFxAssemblyRef.File.DataServicesClient, f, StringComparison.OrdinalIgnoreCase) || string.Equals(DataFxAssemblyRef.File.ODataLib, f, StringComparison.OrdinalIgnoreCase) || string.Equals(DataFxAssemblyRef.File.DataServices, f, StringComparison.OrdinalIgnoreCase)) { return(Environment.ExpandEnvironmentVariables(System.IO.Path.Combine(DataFxAssemblyRef.File.DS_ReferenceAssemblyPath, f))); } return(f); }; //References //Note: We don't hard-code the assmeblies, but obtain the name from the referenced types cp.ReferencedAssemblies.Clear(); cp.ReferencedAssemblies.AddRange(referencedAssemblies.Select(resolve).Distinct().ToArray()); //Compile CompilerResults cr = compiler.CompileAssemblyFromFile(cp, codeFilePaths); //Compiler Errors string completeError = ""; foreach (CompilerError error in cr.Errors) { switch (error.ErrorNumber) { case "CS0016": //File is locked (file already loaded) case "CS0042": //Failure to generate debug information (file already loaded) continue; } ; //Otherwise if (completeError.Length > 0) { completeError += "\r\n" + error.ToString(); } else { completeError = error.ToString(); } } if (completeError.Length > 0) { AstoriaTestLog.FailAndThrow(completeError); } }
protected override bool VerifyNodes(QueryTreeInfo queryTreeInfo) { //Find the list of keys for this resource set that will appear as orderby/thenby nodes in the tree foreach (ResourceType type in queryTreeInfo.resourceContainer.ResourceTypes) { foreach (ResourceProperty property in type.Properties.OfType <ResourceProperty>()) { if (property.PrimaryKey != null) { refKeys.Add(property); AstoriaTestLog.WriteLine(property.Name); } } } if (queryTreeInfo.currentTree.Contains(queryTreeInfo.rootTree)) { // Obtain the diff tree. The +1 is for the "." that is the node separator queryTreeInfo.diffTree = queryTreeInfo.currentTree.Substring(queryTreeInfo.rootTree.Length + 1); AstoriaTestLog.WriteLine("Diff Tree : " + queryTreeInfo.diffTree); } //Construct the Tree Dictionary String[] splitString = new String[] { ")." }; String[] result = queryTreeInfo.diffTree.Split(splitString, StringSplitOptions.None); AstoriaTestLog.WriteLine("Split string"); foreach (String s in result) { AstoriaTestLog.WriteLine(s); } //ThenBy and Where nodes can repeat, so create a list to capture the multiple values List <String> thenByList = new List <String>(); List <String> whereList = new List <String>(); String expectedNode = null; //Based on the queryComponent, identify the node we should look for in the tree if (queryTreeInfo.queryComponent == QueryComponent.Top) { expectedNode = "Take"; } else if (queryTreeInfo.queryComponent == QueryComponent.Skip) { expectedNode = "Skip"; } //Look through each node and construct the dictionary foreach (String s in result) { if (s.StartsWith("OrderBy")) { if (!nodeValues.ContainsKey("OrderBy")) { nodeValues.Add("OrderBy", new List <String>(s.Split(new String[] { "OrderBy(" }, StringSplitOptions.RemoveEmptyEntries))); } else { //OrderBy found again, return error AstoriaTestLog.WriteLine("More than 1 OrderBy node found"); return(false); } } if (s.StartsWith("ThenBy")) { //Can have multiple thenby nodes, so just create the list of values here and add it to dictionary later thenByList.Add((s.Split(new String[] { "ThenBy(" }, StringSplitOptions.RemoveEmptyEntries)[0])); } //Check for take/skip if (expectedNode != null) { if (s.StartsWith(expectedNode)) { if (!nodeValues.ContainsKey(expectedNode)) { nodeValues.Add(expectedNode, new List <String>(s.Split(new String[] { expectedNode + "(", ")" }, StringSplitOptions.RemoveEmptyEntries))); } else { //Node found again, return error AstoriaTestLog.WriteLine("More than 1 " + expectedNode + " node found"); return(false); } } } if (s.StartsWith("Where")) { //Can have multiple where nodes, so just create the list of values here and add it to dictionary later whereList.Add((s.Split(new String[] { "Where(" }, StringSplitOptions.RemoveEmptyEntries)[0])); } } //Verify that the correct number of orderby/thenby/take nodes are present //Check for take/skip if (expectedNode != null) { //Is Take/Skip node present if (!nodeValues.ContainsKey(expectedNode)) { //Take/Skip node not found AstoriaTestLog.WriteLine(expectedNode + " node not found"); return(false); } } //Is OrderBy node present? if (!nodeValues.ContainsKey("OrderBy")) { //OrderBy node not found AstoriaTestLog.WriteLine("OrderBy node not found"); return(false); } //Add the theyby list to the dictionary and Verify the count of ThenBy nodes if (!nodeValues.ContainsKey("ThenBy")) { if (thenByList.Count > 0) { nodeValues.Add("ThenBy", thenByList); } if ((refKeys.Count - 1) != thenByList.Count) { //ThenBy node count doesnt match AstoriaTestLog.WriteLine("ThenBy nodes count doesnt match"); return(false); } } //Add the where list to the dictionary if (!nodeValues.ContainsKey("Where")) { if (whereList.Count > 0) { nodeValues.Add("Where", whereList); } } return(true); }
public static AstoriaWebDataService CreateAstoriaDataWebService(Workspace workspace, string webDataServicePrefixName, AstoriaDatabase database, bool skipDataServiceVerify) { AstoriaWebDataService service = null; //Base the creation on the AstoriaTestProperties switch (AstoriaTestProperties.Host) { case Host.WebServiceHost: case Host.IDSH: case Host.IDSH2: service = new AstoriaServiceHost(workspace, webDataServicePrefixName, Environment.MachineName, database); break; case Host.WebServiceHostRemote: service = new AstoriaServiceHost(workspace, webDataServicePrefixName, GetMachineName(), database); break; default: service = new IISWebDataService(workspace, webDataServicePrefixName, GetMachineName(), database); break; } // write out helpful debugging URIs if (AstoriaTestProperties.Client == ClientEnum.SILVERLIGHT) { WriteUriToList(service.ServiceRootUri + "Monitor.aspx"); WriteUriToList(service.ServiceRootUri + "SilverlightAstoriaTestPage.html"); WriteUriToList(service.ServiceUri); } // if running locally in partial trust, ensure that the trusted methods are available if (AstoriaTestProperties.IsLocalHost && AstoriaTestProperties.ServiceTrustLevel != TrustLevel.Full && AstoriaTestProperties.RuntimeEnvironment == TestRuntimeEnvironment.Lab) { Assembly trustedAssembly = typeof(FullTrust.TrustedMethods).Assembly; //if (!trustedAssembly.GlobalAssemblyCache) //{ // AstoriaTestLog.FailAndThrow("Assembly containing fully trusted components must be in the GAC. " + // "Run 'gacutil -if <dll>' on AstoriaTestFramework.FullTrust from a visual studio command prompt"); //} if (!trustedAssembly.IsFullyTrusted) { AstoriaTestLog.FailAndThrow("Assembly containing components requiring full trust is not trusted"); } } try { // push the verification step down to the derived classes so that a failure there can be handled accordingly // service.CreateWebService(!skipDataServiceVerify); } catch (Exception e) { // we need to make sure that we don't 'leak' services that fail to start, as it can mean a process is left running that will // cause subsequent ArtClean's to fail. This has caused build failures at least once. // if (AstoriaTestProperties.IsLabRun || AstoriaTestProperties.RuntimeEnvironment == TestRuntimeEnvironment.CheckinSuites) { service.Dispose(); } throw new TestFailedException("Failed to create web service", null, null, e); } if (skipDataServiceVerify) { // for call logging, we need the directory to exist, and the service doesn't necessarily have permission to create it // TODO: find some better, common place to put this for IIS, WebServiceHost, etc. Right now this is the best spot #if !ClientSKUFramework IOUtil.EnsureEmptyDirectoryExists(Path.Combine(service.DestinationFolder, CallOrder.APICallLog.DirectoryName)); #endif Thread.Sleep(5000); //To allow time for the service to start running before requests get made } return(service); }
protected override bool VerifyLambda(QueryTreeInfo queryTreeInfo) { List <String> outVal = null; bool result = false; if (queryTreeInfo.queryComponent == QueryComponent.Top) { result = nodeValues.TryGetValue("Take", out outVal); } else if (queryTreeInfo.queryComponent == QueryComponent.Skip) { result = nodeValues.TryGetValue("Skip", out outVal); } //Check for take/skip value if (result) { if (!(takeSkipValue.ToString() == outVal[0])) { //Take node value does not match AstoriaTestLog.WriteLine("Take/Skip node value does not match"); return(false); } } else { if (queryTreeInfo.queryComponent != QueryComponent.OrderBy) { //Take node not found in the list AstoriaTestLog.WriteLine("Take/Skip node not found"); return(false); } } //Check for the orderby/thenby key values for (int i = 0; i < refKeys.Count; i++) { bool keyPresent; List <String> outOrderByVal = null; List <String> outThenByVal = null; //Must find orderby node keyPresent = nodeValues.TryGetValue("OrderBy", out outOrderByVal); if (outVal != null) { outVal.Clear(); outVal.AddRange(outOrderByVal); } else { outVal = outOrderByVal; } if (keyPresent) { //thenby nodes are optional nodeValues.TryGetValue("ThenBy", out outThenByVal); if (outThenByVal != null) { outVal.AddRange(outThenByVal); } } else { //OrderBy/ThenBy node not found AstoriaTestLog.WriteLine("OrderBy/ThenBy node not found"); return(false); } //Verify the values if (keyPresent) { bool valuePresent = false; foreach (String s in outVal) { if (s.Contains("element." + refKeys[i].Name)) { valuePresent = true; } } if (!valuePresent) { //RefKey not found in the list AstoriaTestLog.WriteLine("RefKey not found in the list"); return(false); } } } return(true); }
protected override void CreateWebService(bool verify) { try { if (AstoriaTestProperties.Host == Host.LocalIIS) { DestinationFolder = Path.Combine(Environment.GetEnvironmentVariable("SystemDrive") + @"\inetpub\wwwroot", this.WebDataServiceName); DestinationFolder_Local = DestinationFolder; } SourceFolder = Path.Combine(Path.Combine(Environment.CurrentDirectory, databaseFolder), this.WebDataServicePrefixName); SourceFolder = Path.Combine(SourceFolder, "DataService"); string sWindowsAuth = ""; string sAnonymousAuth = ""; AstoriaTestLog.WriteLineIgnore("Creating IIS webservice on: " + this.MachineName); this.CopySourceFolderToHost(); DeployWebConfig(); // if not full trust, then compiler options aren't allowed, so we need to add #defines to each file manually if (AstoriaTestProperties.ServiceTrustLevel != TrustLevel.Full) { List <string> toDefine = new List <string>() { Workspace.DataLayerProviderKind.ToString() }; if (!Versioning.Server.SupportsV2Features) { toDefine.Add("ASTORIA_PRE_V2"); } string defines = string.Join(Environment.NewLine, toDefine.Select(d => "#define " + d).ToArray()); foreach (string path in Directory.GetFiles(DestinationFolder, "*.cs", SearchOption.AllDirectories)) { string fileContent = File.ReadAllText(path); fileContent = defines + Environment.NewLine + fileContent; File.WriteAllText(path, fileContent); } } Assembly resourceAssembly = this.GetType().Assembly; IOUtil.FindAndWriteResourceToFile(resourceAssembly, Path.Combine(DestinationFolder, "CreateVDir.vbs")); IOUtil.FindAndWriteResourceToFile(resourceAssembly, Path.Combine(DestinationFolder, "..\\DeleteVDir.vbs")); if (AstoriaTestProperties.HostAuthenicationMethod == "Windows") { sWindowsAuth = "True"; sAnonymousAuth = "False"; } else if (AstoriaTestProperties.HostAuthenicationMethod == "None") { sWindowsAuth = "False"; sAnonymousAuth = "True"; } string args = String.Format("{0} {1} {2} {3} {4}", Path.Combine(DestinationFolder_Local, "CreateVDir.vbs"), this.WebDataServiceName, DestinationFolder_Local, sAnonymousAuth, sWindowsAuth); RunProcess("cscript", args); Thread.Sleep(2000); // set up service uris if (AstoriaTestProperties.TransportSecurityMode.Equals("transport", StringComparison.InvariantCultureIgnoreCase)) { ServiceRootUri = Uri.UriSchemeHttps + "://" + this.MachineName + "/" + this.WebDataServiceName + "/"; } else { ServiceRootUri = Uri.UriSchemeHttp + "://" + this.MachineName + "/" + this.WebDataServiceName + "/"; } ServiceUri = ServiceRootUri + Workspace.WebServiceFileName; if (AstoriaTestProperties.UseDomainServices) { ServiceUri = ServiceUri + "/dataservice/"; AstoriaTestLog.WriteLineIgnore("OData Endpoint is at : " + ServiceUri); } if (verify) { VerifyService(); } } catch (Exception e) { if (AstoriaTestProperties.Host == Host.LocalIIS) { throw new TestFailedException("Could not create IIS web service on local host", null, null, e); } } }
/// <summary>Create a populated database.</summary> private void CreatePopulatedDatabase() { if (_isLocal) { EnsureLocalLoginExists(); } DropDatabase(); AstoriaTestLog.WriteLineIgnore("-------CreatePopulatedDb: {0}---------", this.MachineConnectionString); using (SqlConnection sqlConn = new SqlConnection(this.MachineConnectionString)) { sqlConn.Open(); using (SqlCommand sqlCmd = sqlConn.CreateCommand()) { sqlCmd.CommandTimeout = 0; sqlCmd.CommandText = String.Format( "CREATE DATABASE [{0}]\n" + " CONTAINMENT = NONE\n" + " ON PRIMARY\n" + "(NAME = N'{0}', FILENAME = N'{1}', SIZE = 4288KB, MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB)\n" + " LOG ON\n" + "(NAME = N'{0}_log', FILENAME = N'{2}', SIZE = 3456KB, MAXSIZE = 2048GB, FILEGROWTH = 10 %)", this.DatabaseName, this.AttachedMdf, this.AttachedLdf); sqlCmd.ExecuteNonQuery(); } // Note: SSMS will create a file that ends with GO\n. The code // below expects that and won't execute an SQL fragment unless it is // followed by GO\n. String filePath = FindDatabaseFile(this.DatabasePrefixName + ".sql"); using (StreamReader reader = new StreamReader(filePath)) using (SqlCommand sqlCmd = sqlConn.CreateCommand()) { // Read from the file until it is empty. StringBuilder sqlStatements = new StringBuilder(); String fileLine = reader.ReadLine(); while (fileLine != null) { // If we find a "GO", execute everything we received up // to this point and ignore the "GO". if (fileLine == "GO") { if (sqlStatements.Length > 0) { // Get command and clean buffer. String sqlStatement = sqlStatements.ToString(); sqlStatements.Clear(); // Replace database name if needed. if (sqlStatement.Contains("{0}")) { sqlStatement = String.Format(sqlStatement, this.DatabaseName); } // Execute. sqlCmd.CommandText = sqlStatement; sqlCmd.CommandTimeout = 0; sqlCmd.ExecuteNonQuery(); } } else if (!String.IsNullOrEmpty(fileLine)) { // Buffer all statements up until "GO". sqlStatements.AppendLine(fileLine); } fileLine = reader.ReadLine(); } } AstoriaTestLog.WriteLineIgnore(String.Format("Completed Create Populated Db {0}", this.DatabaseName)); } }
public void GenerateServiceOperations(TemplateFile templateFile) { StringBuilder serviceOps = new StringBuilder(); foreach (MethodInfo method in typeof(NonClrTestWebService <>).GetMethods()) { object[] attribs = method.GetCustomAttributes(false); bool isSingleResult = false; foreach (object attrib in attribs) { if (attrib is Microsoft.OData.Service.SingleResultAttribute) { isSingleResult = true; break; } } foreach (object attrib in attribs) { if (attrib is System.ServiceModel.Web.WebGetAttribute || attrib is System.ServiceModel.Web.WebInvokeAttribute) { string kind; if (typeof(IQueryable).IsAssignableFrom(method.ReturnType)) { if (isSingleResult) { kind = "ServiceOperationResultKind.QueryWithSingleResult"; } else { kind = "ServiceOperationResultKind.QueryWithMultipleResults"; } } else if (typeof(IEnumerable).IsAssignableFrom(method.ReturnType) && !typeof(RowComplexType).IsAssignableFrom(method.ReturnType) && method.ReturnType != typeof(string) && method.ReturnType != typeof(byte[])) { // this will be incorrect for complex types which derive from IEnumerable, but its the best we can do for now kind = "ServiceOperationResultKind.Enumeration"; } else if (typeof(void).IsAssignableFrom(method.ReturnType)) { kind = "ServiceOperationResultKind.Void"; } else { // either primitive or complex kind = "ServiceOperationResultKind.DirectValue"; } string verb; if (attrib is System.ServiceModel.Web.WebGetAttribute) { verb = "GET"; } else { verb = (attrib as System.ServiceModel.Web.WebInvokeAttribute).Method; } serviceOps.AppendLine("serviceOpCreateParams.Add(new ServiceOperationCreationParams(\"" + method.Name + "\", " + kind + ", \"\", \"" + verb + "\"));"); break; } } } foreach (ServiceOperation op in _workspace.ServiceContainer.ResourceContainers.OfType <ServiceOperation>()) { if (!op.ServiceOperationResultKind.HasValue) { AstoriaTestLog.FailAndThrow("Cannot generate code for service operation because the result kind is not set"); } if (op.ExpectedTypeName == null) { AstoriaTestLog.FailAndThrow("Cannot generate code for service operation because the expected type name is not set"); } string kind = "ServiceOperationResultKind." + op.ServiceOperationResultKind.Value.ToString(); serviceOps.AppendLine("serviceOpCreateParams.Add(new ServiceOperationCreationParams(\"" + op.Name + "\", " + kind + ", \"" + op.BaseType.Name + "\", \"" + op.Verb.ToHttpMethod() + "\"));"); } templateFile.FileText = templateFile.FileText.Replace("[[GeneratedServiceOperations]]", serviceOps.ToString()); }
private string CreateProperty(ComplexType type, ResourceProperty property, bool lazyLoad) { StringBuilder propertyCode = new StringBuilder(); string typeName = type.Name.ToLowerInvariant(); string propertyDeclarationName = type.Name + property.Name + "Property"; string propertyNameParam = String.Format("\"{0}\"", property.Name); string propertyKindParam = GetPropertyKindString(property); string propertyTypeParam = GetPropertyTypeString(property); string propertyParams = string.Join(", ", new string[] { propertyNameParam, propertyKindParam, propertyTypeParam }); string existingName = ExistingPropertyName(propertyParams, property.Facets.IsClrProperty, propertyDeclarationName); if (existingName != null && !property.IsComplexType && !property.IsNavigation) { if (lazyLoad) { propertyCode.AppendLine(String.Format("{0}.AddLazyProperty({1});", typeName, existingName)); } else { propertyCode.AppendLine(String.Format("{0}.AddProperty({1});", typeName, existingName)); } } else { propertyCode.AppendLine(String.Format("ResourceProperty {0} = new ResourceProperty({1});", propertyDeclarationName, propertyParams)); if (property.Facets.IsClrProperty) { propertyCode.AppendLine(String.Format("{0}.CanReflectOnInstanceTypeProperty = true;", propertyDeclarationName)); } else { propertyCode.AppendLine(String.Format("{0}.CanReflectOnInstanceTypeProperty = false;", propertyDeclarationName)); } if (property.IsNavigation) { if (property.OtherSideNavigationProperty != null) { propertyCode.AppendLine(String.Format("{0}.CustomState = \"{1}\";", propertyDeclarationName, property.OtherSideNavigationProperty.ResourceAssociation.Name)); } else if (property.Facets.MestTag != null) { propertyCode.AppendLine(String.Format("{0}.CustomState = \"{1}\";", propertyDeclarationName, property.Facets.MestTag)); } } else if (property.Facets.ServerGenerated) { if (property.Type != Clr.Types.Int32) { AstoriaTestLog.FailAndThrow("Server-generated values only supported for ints"); } propertyCode.AppendLine(String.Format("{0}.CustomState = \"{1}\";", propertyDeclarationName, NonClr.NonClrContext.ServerGeneratedCustomState)); } if (lazyLoad) { propertyCode.AppendLine(String.Format("{0}.AddLazyProperty({1});", typeName, propertyDeclarationName)); } else { propertyCode.AppendLine(String.Format("{0}.AddProperty({1});", typeName, propertyDeclarationName)); } } return(propertyCode.ToString()); }