예제 #1
0
        private void Write(APICallLogEntry entry)
        {
            string fileName  = string.Format("{0:0000000000000000000000000}.xml", entryCount++);
            string entryPath = Path.Combine(directoryPath, fileName);
            string xml       = APICallLogEntry.ToXml(entry).ToString();

            TrustedMethods.WriteAllText(entryPath, xml);
        }
예제 #2
0
        public static T Execute <T>(Func <T> f, bool inWebRequest, out System.Net.WebException exc)
        {
            exc = null;
            for (int i = 0; i < SocketExceptionRetries; i++)
            {
                try
                {
                    exc = null;
                    return(TrustedMethods.ReturnFuncResult <T>(f));
                }
                catch (WebException ex)
                {
                    exc = ex;
                    if (ex.InnerException is SocketException)
                    {
                        HandleSocketException(inWebRequest, (SocketException)exc.InnerException);
                    }
                    else
                    {
                        if (inWebRequest)
                        {
                            return(default(T)); // it will handle this
                        }
                        if (ex.Status == WebExceptionStatus.Timeout && CatchTimeouts)
                        {
                            HandleWebRequestTimeout(inWebRequest, ex);
                        }
                        else
                        {
                            throw ex;
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (ex.InnerException == null || !(ex.InnerException is System.Net.WebException))
                    {
                        throw ex;
                    }

                    exc = (WebException)ex.InnerException;
                    if (exc.InnerException != null && (exc.InnerException is SocketException))
                    {
                        HandleSocketException(inWebRequest, (SocketException)exc.InnerException);
                    }
                    else if (exc.Status == WebExceptionStatus.Timeout && CatchTimeouts)
                    {
                        HandleWebRequestTimeout(inWebRequest, exc);
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
            AstoriaTestLog.FailAndThrow("Repeated socket exceptions encountered, consequences unpredictable.");
            return(default(T));
        }
예제 #3
0
 public virtual void CompareValue(IQueryable baseline, bool stripQuotes, bool valueUri)
 {
     // TODO: There should only be 1 element in baseline
     foreach (object element in TrustedMethods.IQueryableGetResultList(baseline))
     {
         object expected = element;
         CompareSingleValue(expected, stripQuotes, valueUri);
     }
 }
예제 #4
0
        protected void RetrieveAPICallLog()
        {
            string directoryPath  = Path.Combine(Workspace.DataService.DestinationFolder, APICallLog.DirectoryName);
            string markerFilePath = Path.Combine(directoryPath, APICallLog.MarkerFileName);

            if (!this.LogAPICalls)
            {
                AstoriaTestLog.IsFalse(TrustedMethods.IsFileExists(markerFilePath), "Marker file should have been cleaned up by prior request");
                return;
            }

            IOUtil.EnsureFileDeleted(markerFilePath);

            this.APICallLogXml     = new XElement("APICallLog");
            this.APICallLogEntries = new List <APICallLogEntry>();

            string[] files;
            // re-query each time, in case any new files were created
            while ((files = Directory.GetFiles(directoryPath, "*.xml")).Length > 0)
            {
                foreach (string filePath in files.OrderBy(f => f)) //NEED TO BE IN CORRECT ORDER
                {
                    string   text    = File.ReadAllText(filePath);
                    XElement element = null;
                    try
                    {
                        element = XElement.Parse(text);
                    }
                    catch
                    { }

                    if (element != null)
                    {
                        this.APICallLogXml.Add(element);
                        this.APICallLogEntries.Add(APICallLogEntry.FromXml(element));
                    }
                    else
                    {
                        this.APICallLogXml.Add(text);
                        this.APICallLogEntries.Add(new APICallLogEntry(text, new KeyValuePair <string, string> [0])); //this will hopefully ALWAYS fail to compare
                    }

                    IOUtil.EnsureFileDeleted(filePath);
                }
            }

            //if (APICallLogEntries.Any(e => e.MethodName == APICallLog.UnterminatedCall))
            //{
            //    foreach (APICallLogEntry entry in APICallLogEntries)
            //        AstoriaTestLog.WriteLine("(Observed) - " + entry.ToString());
            //    AstoriaTestLog.FailAndContinue(new Microsoft.Test.ModuleCore.TestFailedException("Un-terminated API calls detected"));
            //}
        }
예제 #5
0
        protected void SetupAPICallLog()
        {
            string directoryPath  = Path.Combine(Workspace.DataService.DestinationFolder, APICallLog.DirectoryName);
            string markerFilePath = Path.Combine(directoryPath, APICallLog.MarkerFileName);

            if (!this.LogAPICalls)
            {
                AstoriaTestLog.IsFalse(TrustedMethods.IsFileExists(markerFilePath), "Marker file should have been cleaned up by prior request");
                AstoriaTestLog.IsFalse(TrustedMethods.IsDirectoryNotEmpty(directoryPath), "Directory should be empty!");
                return;
            }

            IOUtil.EnsureDirectoryExists(directoryPath);
            IOUtil.CreateEmptyFile(markerFilePath);
        }
예제 #6
0
 /// <summary>
 /// Add specific permissions to the permission set based on what test is running. Currently concurrency client test and databinding client test require additional permissions
 /// </summary>
 /// <param name="ps"></param>
 private void AddPermissionByTest(PermissionSet ps)
 {
     // concurrency client test requires permissions to write files in IIS wwwroot directory.
     if (this.Name == "Astoria.Test.Client.Concurrency")
     {
         string           iisPath = TrustedMethods.GetIISRootPath();
         FileIOPermission perm    = new FileIOPermission(FileIOPermissionAccess.AllAccess, iisPath);
         ps.AddPermission(perm);
     }
     // databinding test requires reflection permission with member access flag
     else if (this.Name == "Astoria.Test.Client.ServerDrivenPaging")
     {
         string           iisPath = TrustedMethods.GetIISRootPath();
         FileIOPermission perm1   = new FileIOPermission(FileIOPermissionAccess.AllAccess, iisPath);
         ps.AddPermission(perm1);
     }
     else if (this.Name == "Astoria.Test.FriendlyFeedsClient")
     {
         string           iisPath = TrustedMethods.GetIISRootPath();
         FileIOPermission perm1   = new FileIOPermission(FileIOPermissionAccess.AllAccess, iisPath);
         ps.AddPermission(perm1);
     }
 }
예제 #7
0
        public static void Verify(Workspace w, ExpNode q, IEnumerable results, ResourceType resType, ComplexType cType, bool bCount)
        {
            long count = 0;

            if (bCount)
            {
                object[] args    = new object[] { results };
                Type     qorType = typeof(QueryOperationResponseWrapper <>).MakeGenericType(resType.ClientClrType);
                object   qor     = Activator.CreateInstance(qorType, args);

                PropertyInfo pi = qor.GetType().GetProperty("GetTotalCount");
                object       i  = pi.GetValue(qor, new object[] { });

                count = (long)i;

                LinqQueryBuilder lb = new LinqQueryBuilder(w);
                lb.CountingMode = true;
                lb.Build(q);

                object baselineElementsCount = CommonPayload.CreateList(lb.QueryResult).Count;
                AstoriaTestLog.IsTrue(count == Convert.ToInt64(baselineElementsCount), "Count is different.Count is " + count.ToString() + ". Baseline count is " + baselineElementsCount.ToString());
            }

            LinqQueryBuilder linqBuilder = new LinqQueryBuilder(w);

            linqBuilder.Build(q);

            IQueryable baselines = linqBuilder.QueryResult;

            IEnumerator b = null;

            IEnumerator r = null;

            try
            {
                b = TrustedMethods.IQueryableGetEnumerator(baselines);
                r = results.GetEnumerator();
            }
            catch (InvalidOperationException invalidOperation)
            {
                if (!AstoriaTestProperties.IsRemoteClient)
                {
                    throw invalidOperation;
                }
            }

            PropertyInfo propertyInfo    = null;
            Object       expectedResult1 = null;
            Object       expectedResult2 = null;

            try
            {
                while (b.MoveNext() && r.MoveNext())
                {
                    if (b.Current == null)
                    {
                        return;
                    }

                    if (r.Current == null)
                    {
                        throw new TestFailedException("Less results than expected");
                    }
                    //skip verification for Binary data type for Linq to Sql
                    if (AstoriaTestProperties.DataLayerProviderKinds[0] == DataLayerProviderKind.LinqToSql && b.Current is System.Byte[])
                    {
                        return;
                    }

                    if (b.Current is System.Byte[])
                    {
                        byte[] newBase = (byte[])b.Current;
                        byte[] newAct  = (byte[])r.Current;

                        if (newBase.Length != newAct.Length)
                        {
                            throw new TestFailedException("Failed to compare the results!");
                        }
                    }
#if !ClientSKUFramework
                    else if (b.Current is System.Data.Linq.Binary)
                    {
                        System.Data.Linq.Binary newBase = (System.Data.Linq.Binary)b.Current;
                        System.Data.Linq.Binary newAct  = new System.Data.Linq.Binary((byte[])r.Current);

                        if (newBase.Length != newAct.Length)
                        {
                            throw new TestFailedException("Failed to compare the results!");
                        }
                    }
#endif

                    else if (b.Current is System.Xml.Linq.XElement)
                    {
                        if (b.Current.ToString() != r.Current.ToString())
                        {
                            throw new TestFailedException("Failed to compare the results!");
                        }
                    }
                    else
                    {
                        if (!b.Current.Equals(r.Current))
                        {
                            if (cType != null)
                            {
                                foreach (ResourceProperty property in cType.Properties)
                                {
                                    if (!property.IsNavigation && !property.IsComplexType && !(property.Type is CollectionType))
                                    {
                                        propertyInfo    = b.Current.GetType().GetProperty(property.Name);
                                        expectedResult1 = propertyInfo.GetValue(b.Current, null);

                                        PropertyInfo propertyInfo2 = r.Current.GetType().GetProperty(property.Name);
                                        expectedResult2 = propertyInfo2.GetValue(r.Current, null);

                                        if (expectedResult1 != expectedResult2)
                                        {
                                            if (expectedResult1 is System.Xml.Linq.XElement)
                                            {
                                                expectedResult1 = ((System.Xml.Linq.XElement)expectedResult1).ToString(System.Xml.Linq.SaveOptions.None);
                                            }
                                            if (expectedResult2 is System.Xml.Linq.XElement)
                                            {
                                                expectedResult2 = ((System.Xml.Linq.XElement)expectedResult2).ToString(System.Xml.Linq.SaveOptions.None);
                                            }
                                            #if !ClientSKUFramework
                                            if (expectedResult1 is byte[])
                                            {
                                                expectedResult1 = new System.Data.Linq.Binary((byte[])expectedResult1);
                                            }

                                            if (expectedResult2 is byte[])
                                            {
                                                expectedResult2 = new System.Data.Linq.Binary((byte[])expectedResult2);
                                            }
                                            #endif


                                            AstoriaTestLog.AreEqual(expectedResult1, expectedResult2, String.Format("Resource value for {0} does not match", property.Name), false);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                foreach (ResourceProperty property in resType.Properties)
                                {
                                    if (!property.IsNavigation && !property.IsComplexType && !(property.Type is CollectionType))
                                    {
                                        //skip verification for Binary data type for Linq to Sql
                                        if (AstoriaTestProperties.DataLayerProviderKinds[0] == DataLayerProviderKind.LinqToSql && property.Type.Name == "LinqToSqlBinary")
                                        {
                                            return;
                                        }

                                        propertyInfo    = b.Current.GetType().GetProperty(property.Name);
                                        expectedResult1 = propertyInfo.GetValue(b.Current, null);

                                        PropertyInfo propertyinfo2 = r.Current.GetType().GetProperty(property.Name);
                                        expectedResult2 = propertyinfo2.GetValue(r.Current, null);

                                        if (expectedResult1 != expectedResult2)
                                        {
                                            if (expectedResult1 is System.Xml.Linq.XElement)
                                            {
                                                expectedResult1 = ((System.Xml.Linq.XElement)expectedResult1).ToString(System.Xml.Linq.SaveOptions.None);
                                            }

                                            if (expectedResult2 is System.Xml.Linq.XElement)
                                            {
                                                expectedResult2 = ((System.Xml.Linq.XElement)expectedResult2).ToString(System.Xml.Linq.SaveOptions.None);
                                            }
                                            #if !ClientSKUFramework
                                            if (expectedResult1 is byte[])
                                            {
                                                expectedResult1 = new System.Data.Linq.Binary((byte[])expectedResult1);
                                            }

                                            if (expectedResult2 is byte[])
                                            {
                                                expectedResult2 = new System.Data.Linq.Binary((byte[])expectedResult2);
                                            }
                                            #endif
                                            AstoriaTestLog.AreEqual(expectedResult1, expectedResult2, String.Format("Resource value for {0} does not match", property.Name), false);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                AstoriaTestLog.WriteLine(e.ToString());
                throw;
            }
        }