public static ResourceIdentifier Create(string id, Type expectedException)
        {
            if (ResourceIdentifiers == null)
                ResourceIdentifiers = new List<ResourceIdentifier>();

            ResourceIdentifier resourceIdentifier = new ResourceIdentifier(typeof(Microsoft.OData.Client.DataServiceContext).Assembly, id, ComparisonFlag.Full, expectedException);
            ResourceIdentifiers.Add(resourceIdentifier);

            return resourceIdentifier;
        }
Beispiel #2
0
        public static string GetLocalizedResourceString(ResourceIdentifier identifier, params Object[] args)
        {
            ResourceManager resourceManager = null;
            resourceManager = ResourceManagerUtil.GetResourceManagerFromAssembly(identifier.AssemblyResourceContainer);

            string result = resourceManager.GetString(identifier.Id, Thread.CurrentThread.CurrentUICulture);
            if (result == null)
                throw new ArgumentException(MissingLocalizeResourceString);

            return FormatResourceString(result, args);
        }
        public static ResourceIdentifier Create(string id, Type expectedException)
        {
            if (ResourceIdentifiers == null)
                ResourceIdentifiers = new List<ResourceIdentifier>();
#if !ClientSKUFramework

            ResourceIdentifier resourceIdentifier = new ResourceIdentifier(typeof(Microsoft.OData.Service.DataServiceHost).Assembly, id, ComparisonFlag.Full, expectedException);
            ResourceIdentifiers.Add(resourceIdentifier);

            return resourceIdentifier;
#endif
#if ClientSKUFramework
	return null;
#endif
        }
Beispiel #4
0
        public static void VerifyException(Exception e, ResourceIdentifier identifier, params Object[] args)
        {
            if (identifier == null)
                throw new TestFailedException("VerifyException: an exception was expected, but ResourceIdentifier is null");

            //Exception not thrown, and should have
            if (e == null)
                throw new TestFailedException("VerifyException: an exception was expected, but not thrown Id='" + identifier.CompleteIdInfo + "'");

            if (identifier.ExpectedExceptionType == null)
                throw new TestFailedException("VerifyException: ResourceIdentifier doesn't contain a ExpectedException");

            //Reflection
            while (e is TargetInvocationException && e.InnerException != null && identifier.ExpectedExceptionType != typeof(TargetInvocationException))
                e = e.InnerException;

            //Test Exceptions (never expected)
            if (e is TestException)
                throw e;

            if (String.IsNullOrEmpty(identifier.Id))
            {
                if (e != null)
                    throw new TestFailedException("VerifyException: an exception was thrown, incorrect Identifier");
                return;
            }


            //Verify the type
            if (identifier.ExpectedExceptionType != null && e.GetType() != identifier.ExpectedExceptionType)
                throw new TestFailedException("Verify exception type", e.GetType(), identifier.ExpectedExceptionType, e);

            if (e.Source == null || e.Source == String.Empty)
                throw new TestFailedException("Exception is thrown, but the Source property of the exception is not set.");


            //Exception not thrown, and should have
            if (e == null && identifier.Id != null)
                throw new TestFailedException("VerifyException: an exception was expected, but not thrown Id='" + identifier.Id + "'");

            AstoriaTestLog.TraceInfo("VerifyException: " + identifier.CompleteIdInfo + " - " + e.GetType().Name);

            string expectedMessage = GetLocalizedResourceString(identifier);

            VerifyMessage(e.Message, expectedMessage, identifier.ComparisonFlag);
        }
 private static void VerifyError(Func<AstoriaResponse, bool, string> responseParser, AstoriaResponse response, ResourceIdentifier resourceIdentifier, bool localResource, params object[] args)
 {
     string resourceText = GetLocalizedResourceString(response.Workspace, resourceIdentifier, localResource, args);
     VerifyError(responseParser, response, resourceText, resourceIdentifier.ComparisonFlag);
 }
 public static void VerifyError(Func<AstoriaResponse, string> responseParser, AstoriaResponse response, ResourceIdentifier resourceIdentifier, bool localResource, params object[] args)
 {
     VerifyError((payload, inStream) => responseParser(payload), response, resourceIdentifier, localResource, args);
 }
 public static void VerifyError(AstoriaResponse response, ResourceIdentifier resourceIdentifier, params object[] args)
 {
     if (response.ContentType.Contains(SerializationFormatKinds.JsonMimeType))
         VerifyError(ParseResponseErrorJSON, response, resourceIdentifier, false, args);
     else
         VerifyError(ParseResponseErrorXML, response, resourceIdentifier, false, args);
 }
 public static string GetLocalizedResourceString(Workspace w, ResourceIdentifier identifier, bool isLocal, object[] args)
 {
     try
     {
         if (isLocal)
             return ResourceUtil.GetLocalizedResourceString(identifier, args);
         else
             return w.GetLocalizedResourceString(identifier.Id, args);
     }
     catch (ArgumentException e)
     {
         if (e.Message == ResourceUtil.MissingLocalizeResourceString)
         {
             AstoriaTestLog.FailAndThrow(String.Format("Resource identifier '{0}' could not be found {1}",
                 identifier.Id, (isLocal ? "locally" : "remotely")));
         }
         throw;
     }
 }
Beispiel #9
0
 public static void VerifyMessage(string actualMessage, ResourceIdentifier identifier, params Object[] args)
 {
     //Lookup Id
     string expectedLocalizedMessage = GetLocalizedResourceString(identifier, args);
     VerifyMessage(actualMessage, expectedLocalizedMessage, identifier.ComparisonFlag);
 }