public void GeographyCollection_Serialize()
        {
            Dictionary <Type, object> data = new Dictionary <Type, object>();

            foreach (var sample in testData)
            {
                data.Add(SpatialTestUtil.GeographyTypeFor(sample.Key), sample.Value.Select(wkt => wktFormatter.Read <Geography>(new StringReader(wkt))).ToList());
            }

            using (TestWebRequest request = CreateCollectionReadService(data).CreateForInProcess())
            {
                System.Data.Test.Astoria.TestUtil.RunCombinations(UnitTestsUtil.ResponseFormats, (format) =>
                {
                    var response = UnitTestsUtil.GetResponseAsAtomXLinq(request, "/Entities", format);

                    // feed/entry/content/properties/CollectionGeographyPoint[@type = \"Collection(Edm.Point)\"]"
                    UnitTestsUtil.VerifyXPaths(response,
                                               testData.Keys.Select(type =>
                                                                    String.Format("atom:feed/atom:entry/atom:content/adsm:properties/ads:Collection{0}[@adsm:type = \"#Collection({1})\"]",
                                                                                  SpatialTestUtil.GeographyTypeFor(type).Name, SpatialTestUtil.GeographyEdmNameFor(type))).ToArray());

                    UnitTestsUtil.VerifyXPaths(response,
                                               testData.Select(d =>
                                                               String.Format("count(atom:feed/atom:entry/atom:content/adsm:properties/ads:Collection{0}/adsm:element) = {1}",
                                                                             SpatialTestUtil.GeographyTypeFor(d.Key).Name, d.Value.Length)).ToArray());
                });
            }
        }
        public void GeometryAsOpenProperty_AtomWithTypeDeserialize()
        {
            // tests atom deserialization with m:type information
            var testCases = testData.Select(kvp =>
                                            new
            {
                Type    = SpatialTestUtil.GeometryTypeFor(kvp.Key),
                EdmName = SpatialTestUtil.GeometryEdmNameFor(kvp.Key),
                WktData = kvp.Value
            });

            TestUtil.RunCombinations(testCases, (tcase) =>
            {
                using (TestWebRequest request = CreateSpatialPropertyService(new Geometry[tcase.WktData.Length], tcase.Type, true, true).CreateForInProcessWcf())
                {
                    request.RequestUriString   = "/Entities";
                    request.HttpMethod         = "POST";
                    request.Accept             = "application/atom+xml,application/xml";
                    request.RequestContentType = UnitTestsUtil.AtomFormat;
                    request.SetRequestStreamAsText(AggregateAtomPayloadFromWkt(tcase.Type.Name, tcase.WktData, tcase.EdmName));
                    request.SendRequest();

                    var response     = request.GetResponseStreamAsXDocument();
                    string rootXpath = "atom:entry/atom:content/adsm:properties/ads:" + tcase.Type.Name;
                    UnitTestsUtil.VerifyXPaths(response, tcase.WktData.Select((v, i) => rootXpath + i + "[@adsm:type = '" + tcase.EdmName + "' and namespace-uri(*) = 'http://www.opengis.net/gml']").ToArray());
                }
            });
        }
            public void CheckRelationshipLinkForDeleteOperationForEntityCollection()
            {
                // CreateChangeScope will make sure that changes are preserved after every SendRequest.
                // By default the data source is created for every request
                using (UnitTestsUtil.CreateChangeScope(typeof(CustomDataContext)))
                {
                    using (TestWebRequest request = TestWebRequest.CreateForInProcessWcf())
                    {
                        request.ServiceType = typeof(RelationshipLinksService);

                        request.RequestUriString = "/Customers(1)/Orders/$ref";
                        request.HttpMethod       = "GET";
                        request.SendRequest();
                        var response1 = request.GetResponseStreamAsText();

                        request.RequestUriString = "/Customers(1)/Orders/$ref?$id=Orders(1)";
                        request.HttpMethod       = "DELETE";
                        request.SendRequest();

                        var response = request.GetResponseStreamAsText();
                        Assert.IsTrue(response != null);
                        Assert.IsTrue(request.ResponseStatusCode == 204);

                        request.RequestUriString = "/Customers(1)/Orders/$ref";
                        request.HttpMethod       = "GET";
                        request.SendRequest();
                        var response2 = request.GetResponseStreamAsText();

                        Assert.IsTrue(response1 != response2);
                    }
                }
            }
Esempio n. 4
0
            public void ExpressionHookTest()
            {
                // This is just a constant expression with the resultant array
                var q = ExpressionTreeTestUtils.CreateRequestAndGetQueryable(typeof(CustomDataContext), "/Customers").Expression;

                Assert.AreEqual(q.NodeType, ExpressionType.Constant);

                // this is a call to IQueryable.Where
                q = ExpressionTreeTestUtils.CreateRequestAndGetQueryable(typeof(CustomDataContext), "/Customers?$filter=ID eq 0").Expression;
                Assert.AreEqual(q.NodeType, ExpressionType.Call);

                XmlDocument xDoc = ExpressionTreeTestUtils.CreateRequestAndGetExpressionTreeXml(typeof(CustomDataContext), "/Customers?$filter=ID eq 0");

                UnitTestsUtil.VerifyXPaths(xDoc,
                                           "/Call[Method='Where']",
                                           "/Call/Arguments/Constant[position()=1]");

                using (TestUtil.RestoreStaticValueOnDispose(typeof(ExpressionTreeToXmlSerializer), "UseFullyQualifiedTypeNames"))
                {
                    xDoc = ExpressionTreeTestUtils.CreateRequestAndGetExpressionTreeXml(typeof(CustomDataContext), "/Customers?$filter=isof('AstoriaUnitTests.Stubs.Customer')");
                    UnitTestsUtil.VerifyXPaths(xDoc,
                                               "/Call/Arguments/Quote/Lambda/Body/TypeIs[TypeOperand='Customer']");

                    ExpressionTreeToXmlSerializer.UseFullyQualifiedTypeNames = true;
                    xDoc = ExpressionTreeTestUtils.CreateRequestAndGetExpressionTreeXml(typeof(CustomDataContext), "/Customers?$filter=isof('AstoriaUnitTests.Stubs.Customer')");
                    UnitTestsUtil.VerifyXPaths(xDoc,
                                               "/Call/Arguments/Quote/Lambda/Body/TypeIs[TypeOperand='AstoriaUnitTests.Stubs.Customer']");
                }
            }
Esempio n. 5
0
            public void Projections_Batch()
            {
                using (TestUtil.MetadataCacheCleaner())
                    using (ocs.PopulateData.CreateTableAndPopulateData())
                        using (TestWebRequest request = TestWebRequest.CreateForInProcess())
                        {
                            TestUtil.RunCombinations(
                                new Type[] { typeof(CustomDataContext), typeof(ocs.CustomObjectContext), typeof(CustomRowBasedContext), typeof(CustomRowBasedOpenTypesContext) },
                                CustomerSelects.Variations(2),
                                (dataServiceType, selects) =>
                            {
                                request.DataServiceType = dataServiceType;

                                BatchWebRequest batchRequest = new BatchWebRequest();
                                foreach (var select in selects)
                                {
                                    InMemoryWebRequest part = new InMemoryWebRequest();
                                    part.Accept             = "application/atom+xml,application/xml";
                                    part.RequestUriString   = "/Customers?$select=" + select.Select;
                                    batchRequest.Parts.Add(part);
                                }

                                batchRequest.SendRequest(request);

                                for (int i = 0; i < selects.Length; i++)
                                {
                                    UnitTestsUtil.VerifyXPathExists(UnitTestsUtil.GetResponseAsAtomXLinq(batchRequest.Parts[i]), selects[i].VerificationXPaths);
                                }
                            });
                        }
            }
Esempio n. 6
0
        private static ServiceModelData ForType(Type serviceModelType)
        {
            Debug.Assert(serviceModelType != null, "serviceModelType != null");

            ServiceModelData result = new ServiceModelData();

            result.serviceModelType = serviceModelType;

            result.EnsureDependenciesAvailable();
            result.model          = UnitTestsUtil.LoadMetadataFromDataServiceType(serviceModelType, null);
            result.isValid        = true;
            result.containerNames = new List <string>();

            // ensure that there is one container
            var container = result.model.EntityContainer;

            foreach (var entitySet in container.EntitySets())
            {
                result.ContainerNames.Add(entitySet.Name);
            }

            // For the time being, we don't have invalid service models in here.
            Debug.Assert(result.containerNames.Count > 0, "result.containerNames.Count > 0");

            result.web3STestPrefix = GetWeb3STestPrefix(serviceModelType);

            return(result);
        }
Esempio n. 7
0
        public void BatchSmokeTestWhereRequestUriIsNotRelativeToService()
        {
            Run(request =>
            {
                request.HttpMethod = "POST";

                request.RequestUriString = "NotBatchAtAll";
                request.RequestHeaders["MyCustomRequestUri"] = "http://myservicebase/path1/path2/$batch";
                request.RequestHeaders["MyCustomServiceUri"] = "http://myservicebase/path1/path2/";

                var batch        = new BatchWebRequest();
                var innerRequest = new InMemoryWebRequest();

                innerRequest.RequestUriString = "SomethingThatWillNotBeUsedAtAll";
                innerRequest.RequestHeaders["MyCustomRequestUri"] = "http://myservicebase/path2/Customers(0)";

                batch.Parts.Add(innerRequest);
                batch.SetContentTypeAndRequestStream(request);

                TestUtil.RunCatching(request.SendRequest);
                Assert.AreEqual(202, request.ResponseStatusCode);
                batch.ParseResponseFromRequest(request, true);
                Assert.AreEqual(400, innerRequest.ResponseStatusCode);
                var innerPayload = innerRequest.GetResponseStreamAsXDocument();
                UnitTestsUtil.VerifyXPathExists(innerPayload, "adsm:error/adsm:message[text()=\"The URI 'http://myservicebase/path2/Customers(0)' is not valid because it is not based on 'http://myservicebase/path1/path2/'.\"]");
            });
        }
Esempio n. 8
0
 public void RequestUriLinksCollectionTest()
 {
     UnitTestsUtil.VerifyPayload("/Customers(2)/Orders/$ref", typeof(CustomDataContext), UnitTestsUtil.JsonLightMimeType, null,
                                 new string[] { String.Format("/{1}/value/{0}/{1}/odata.id[text()='http://host/Orders(2)']", JsonValidator.ArrayString, JsonValidator.ObjectString),
                                                String.Format("/{1}/value/{0}/{1}/odata.id[text()='http://host/Orders(102)']", JsonValidator.ArrayString, JsonValidator.ObjectString),
                                                String.Format("count(/{1}/value/{0}/{1}//odata.id)=2", JsonValidator.ArrayString, JsonValidator.ObjectString) });
 }
        public void JsonLightPayloadMetadataIntegrationTest()
        {
            Stream resultStream = UnitTestsUtil.GetResponseStream(WebServerLocation.InProcess, "application/json;odata.metadata=none", "/Customers?$select=Name", typeof(CustomDataContext));
            Stream stream       = TestUtil.EnsureStreamWithSeek(resultStream);
            string actualText   = new StreamReader(stream).ReadToEnd();

            const string expectedSuccessText = @"{""value"":[{""Name"":""Customer 0""},{""Name"":""Customer 1""},{""Name"":""Customer 2""}]}";

            Assert.AreEqual(expectedSuccessText, actualText);

            // now test that it is fails for the query option
            // $controlinfo was briefly used for controlling how much metadata a client wanted
            // in JSON-Light payloads. It was removed and replaced with a parameter in the media type.
            using (TestWebRequest request = TestWebRequest.CreateForLocation(WebServerLocation.InProcessWcf))
            {
                request.DataServiceType  = typeof(CustomDataContext);
                request.RequestUriString = "/Customers?$controlinfo=all";
                request.Accept           = "application/json;odata.metadata=minimal";

                TestUtil.RunCatching(() => request.SendRequest());

                Assert.AreEqual(400, request.ResponseStatusCode);
            }

            // now test that it is fails for 'odata-light' which was also eventually replaced.
            using (TestWebRequest request = TestWebRequest.CreateForLocation(WebServerLocation.InProcessWcf))
            {
                request.DataServiceType  = typeof(CustomDataContext);
                request.RequestUriString = "/Customers";
                request.Accept           = "application/json;odata.metadata=light";

                TestUtil.RunCatching(() => request.SendRequest());

                Assert.AreEqual(415, request.ResponseStatusCode);
            }

            // now test that it is fails with 'metadata' parameter which was later combined into the 'odata' parameter.
            using (TestWebRequest request = TestWebRequest.CreateForLocation(WebServerLocation.InProcessWcf))
            {
                request.DataServiceType  = typeof(CustomDataContext);
                request.RequestUriString = "/Customers";
                request.Accept           = "application/json;odata.metadata=minimal;metadata=all";

                TestUtil.RunCatching(() => request.SendRequest());

                Assert.AreEqual(415, request.ResponseStatusCode);
            }

            // Now test that it fails for an invalid type/subtype.
            using (TestWebRequest request = TestWebRequest.CreateForLocation(WebServerLocation.InProcessWcf))
            {
                request.DataServiceType  = typeof(CustomDataContext);
                request.RequestUriString = "/Customers";
                request.Accept           = "fake/things;odata.metadata=minimal";

                TestUtil.RunCatching(() => request.SendRequest());

                Assert.AreEqual(415, request.ResponseStatusCode);
            }
        }
Esempio n. 10
0
        public void HttpContextServiceHostRequestNameTest()
        {
            CombinatorialEngine engine = CombinatorialEngine.FromDimensions(
                new Dimension("WebServerLocation", new WebServerLocation[] { WebServerLocation.InProcessWcf }),
                new Dimension("LocalHostName", new string[] { "127.0.0.1" }));

            TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values)
            {
                WebServerLocation location = (WebServerLocation)values["WebServerLocation"];
                string hostName            = (string)values["LocalHostName"];
                using (TestWebRequest request = TestWebRequest.CreateForLocation(location))
                {
                    request.DataServiceType  = typeof(CustomDataContext);
                    request.RequestUriString = "/Customers(1)?$format=atom";
                    request.StartService();

                    UriBuilder builder = new UriBuilder(request.FullRequestUriString);
                    builder.Host       = hostName;
                    WebClient client   = new WebClient();
                    string response    = client.DownloadString(builder.Uri);

                    response             = response.Substring(response.IndexOf('<'));
                    XmlDocument document = new XmlDocument(TestUtil.TestNameTable);
                    document.LoadXml(response);
                    string baseUri = UnitTestsUtil.GetBaseUri(document.DocumentElement);
                    TestUtil.AssertContains(baseUri, hostName);
                }
            });
        }
Esempio n. 11
0
        private void VerifyResults(IQueryable query, IEnumerable baseline)
        {
            IEnumerator left  = query.GetEnumerator();
            IEnumerator right = baseline.GetEnumerator();

            try
            {
                IDataServiceProvider provider = UnitTestsUtil.GetProvider(typeof(OpenNorthwindContext));
                while (left.MoveNext() && right.MoveNext())
                {
                    if (left.Current == null && right.Current == null)
                    {
                        break;
                    }

                    if ((left.Current == null || right.Current == null) ||
                        !left.Current.Equals(right.Current))
                    {
                        throw new Exception("Test Failed");
                    }
                }
                if (left.MoveNext() || right.MoveNext())
                {
                    throw new Exception("Test Failed");
                }
            }
            finally
            {
                typeof(LateBoundMethods).GetProperty("Provider", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, null, null);
            }
        }
Esempio n. 12
0
        /// <summary>Returns a resource type as specified by the test.</summary>
        /// <param name="metadata">The DSPMetadata to use.</param>
        /// <param name="typeSpecification">The type specification. If it's a string, then it means the name of the type to get. If it's a Type it means
        /// to return a primitive resource type of that type.</param>
        /// <returns>The ResourceType specified by the test.</returns>
        public static providers.ResourceType GetResourceTypeFromTestSpecification(this DSPMetadata metadata, object typeSpecification)
        {
            if (metadata == null)
            {
                return(null);
            }

            if (typeSpecification is Type)
            {
                return(providers.ResourceType.GetPrimitiveResourceType(typeSpecification as Type));
            }
            else
            {
                string typeName             = typeSpecification as string;
                providers.ResourceType type = metadata.GetResourceType(typeName);
                if (type == null)
                {
                    metadata.TryResolveResourceType(typeName, out type);
                }

                if (type == null)
                {
                    type = UnitTestsUtil.GetPrimitiveResourceTypes().FirstOrDefault(rt => rt.FullName == typeName);
                }

                if (type == null)
                {
                    type = UnitTestsUtil.GetPrimitiveResourceTypes().FirstOrDefault(rt => rt.Name == typeName);
                }

                return(type);
            }
        }
Esempio n. 13
0
 private void GetResponse(string uri, string responseFormat, Type contextType, string[] xPathsToVerify, KeyValuePair <string, string>[] headerValues, string httpMethodName, string requestPayload)
 {
     using (TestWebRequest request = TestWebRequest.CreateForInProcess())
     {
         request.DataServiceType  = contextType;
         request.RequestUriString = uri;
         request.Accept           = responseFormat;
         request.HttpMethod       = httpMethodName;
         UnitTestsUtil.SetHeaderValues(request, headerValues);
         if (requestPayload != null)
         {
             request.RequestContentType = responseFormat;
             request.RequestStream      = new MemoryStream();
             StreamWriter writer = new StreamWriter(request.RequestStream);
             writer.Write(requestPayload);
             writer.Flush();
         }
         request.SendRequest();
         Stream responseStream = request.GetResponseStream();
         if (xPathsToVerify != null)
         {
             UnitTestsUtil.VerifyXPaths(responseStream, responseFormat, xPathsToVerify);
         }
     }
 }
Esempio n. 14
0
 public void RequestUriLinksReferenceTest()
 {
     UnitTestsUtil.VerifyPayload("/Customers(1)/BestFriend/$ref", typeof(CustomDataContext), UnitTestsUtil.JsonLightMimeType, null,
                                 new string[] {
         String.Format("/{0}/odata.id[text()='http://host/Customers(0)']", JsonValidator.ObjectString),
         String.Format("count(//{0}/odata.id)=1", JsonValidator.ObjectString)
     });
 }
Esempio n. 15
0
 public void RequestUriProjectPropertyTest()
 {
     UnitTestsUtil.VerifyPayload("/Customers(1)/Name", typeof(CustomDataContext), null,
                                 new string[] { "/cdc:Name",
                                                "/cdc:Name[text()='Customer 1']" },
                                 new string[] { String.Format("/{0}/Name[text()='Customer 1']", JsonValidator.ObjectString) },
                                 new string[0]);
 }
Esempio n. 16
0
 private static void ResponseShouldMatchXPath(string requestUriString, bool openType, int statusCode, string xpath)
 {
     ResponseShouldHaveStatusCode(requestUriString, openType, statusCode, request =>
     {
         var responsePayload = request.GetResponseStreamAsXDocument();
         UnitTestsUtil.VerifyXPaths(responsePayload, new[] { xpath });
     });
 }
Esempio n. 17
0
        private static XElement GetAtomEntryProperties(TestWebRequest request, string resourceSetName, int id)
        {
            request.HttpMethod = "GET";
            XDocument response = UnitTestsUtil.GetResponseAsAtomXLinq(request, string.Format("/{0}({1})", resourceSetName, id), "application/atom+xml,application/xml");
            XElement  entry    = response.Root.Element(UnitTestsUtil.AtomNamespace + "content");

            Assert.IsNotNull(entry, "Expected the request to produce an ATOM entry.");
            return(entry.Element(UnitTestsUtil.MetadataNamespace + "properties"));
        }
Esempio n. 18
0
        /// <summary>Returns list of all primitive resource types.</summary>
        /// <returns>All primitive resource types.</returns>
        public static IEnumerable <ResourceType> GetPrimitiveResourceTypes()
        {
            if (primitiveResourceTypes == null)
            {
                primitiveResourceTypes = UnitTestsUtil.GetPrimitiveResourceTypes();
            }

            return(primitiveResourceTypes);
        }
Esempio n. 19
0
        /// <summary>Starts an instance of the local web server.</summary>
        public static void StartWebServer()
        {
            if (process == null)
            {
                string serverPath = FindWebServerPath();
                process = UnitTestsUtil.StartIISExpress(serverPath, LocalWebServerHelper.FileTargetPath, ref localPortNumber);
            }

            processReferenceCount++;
        }
Esempio n. 20
0
            public void GetNullValuedResourceFromReferenceNavigationProperty()
            {
                TestWebRequest request = UnitTestsUtil.GetTestWebRequestInstance(UnitTestsUtil.JsonLightMimeType, "/Customers(0)/BestFriend", typeof(CustomDataContext), null, "GET");

                Assert.IsTrue(request.ResponseStatusCode == 204);
                VerifyEmptyStream(request.GetResponseStream());
                request = UnitTestsUtil.GetTestWebRequestInstance(UnitTestsUtil.AtomFormat, "/Customers(0)/BestFriend", typeof(CustomDataContext), null, "GET");
                Assert.IsTrue(request.ResponseStatusCode == 204);
                VerifyEmptyStream(request.GetResponseStream());
            }
Esempio n. 21
0
        private static void GetResponseAndVerify(TestWebRequest request, int expectedStatusCode, string xpath)
        {
            TestUtil.RunCatching(request.SendRequest);

            Assert.AreEqual(expectedStatusCode, request.ResponseStatusCode);

            var responsePayload = request.GetResponseStreamAsXDocument();

            UnitTestsUtil.VerifyXPaths(responsePayload, new[] { xpath });
        }
Esempio n. 22
0
        public void KeyPropertiesWithAttributesHaveHighestPriority()
        {
            Stream      responseStream = UnitTestsUtil.GetResponseStream(WebServerLocation.InProcess, null, "/$metadata", typeof(TypedCustomDataContext <MultiplePropertiesSatisfyingKeyCriteria>));
            XmlDocument document       = new XmlDocument(TestUtil.TestNameTable);

            document.Load(responseStream);
            XmlNode node = document.SelectSingleNode("//csdl:Key[csdl:PropertyRef/@Name='ActualID' and csdl:PropertyRef/@Name='ActualID1']", TestUtil.TestNamespaceManager);

            Assert.IsTrue(node != null, "Property with attribute should get the highest priority");
        }
Esempio n. 23
0
 public void GetMetadataForUnitTestProviders()
 {
     foreach (Type providerType in UnitTestsUtil.ProviderTypes)
     {
         using (UnitTestsUtil.CreateChangeScope(providerType))
         {
             UnitTestsUtil.LoadMetadataFromDataServiceType(providerType,
                                                           Path.Combine(TestUtil.GeneratedFilesLocation, "Metadata" + providerType.Name + ".csdl"));
         }
     }
 }
 public void TearDown()
 {
     UnitTestsUtil.TearDownGameTest(ref game, ref map, ref players, ref gui);
     foreach (var unit in units)
     {
         if (unit != null)
         {
             Object.Destroy(unit.gameObject);
         }
     }
 }
Esempio n. 25
0
        public void RequestUriResourceSetPropertyTest()
        {
            UnitTestsUtil.VerifyPayload("/Customers(0)/Orders", typeof(CustomDataContext), null,
                                        new string[] { "/cdc:Orders",
                                                       "/cdc:Orders/cdc:Order" },
                                        new string[] { String.Format("/{0}", JsonValidator.ArrayString),
                                                       JsonValidator.GetJsonTypeXPath(typeof(Order), true /*isArray*/) },
                                        new string[0]);

            UnitTestsUtil.VerifyInvalidUri("/Customers!1000/Orders", typeof(CustomDataContext));
            UnitTestsUtil.VerifyInvalidUri("/Customers(1)/Orders(10000)", typeof(CustomDataContext));
        }
Esempio n. 26
0
 private static void ResponseShouldMatchXPath(string requestUriString, int statusCode, string xpath, Type serviceType = null)
 {
     ResponseShouldHaveStatusCode(
         requestUriString,
         statusCode,
         request =>
     {
         var responsePayload = request.GetResponseStreamAsXDocument();
         UnitTestsUtil.VerifyXPaths(responsePayload, new[] { xpath });
     },
         serviceType);
 }
Esempio n. 27
0
        public void RequestUriComplexPropertyTest()
        {
            UnitTestsUtil.VerifyPayload("/Customers(0)/Address", typeof(CustomDataContext), null,
                                        new string[] { "/cdc:Address" },
                                        new string[] { String.Format("/{0}/Address/StreetAddress[text()='Line1']", JsonValidator.ObjectString),
                                                       String.Format("/{0}/Address/City[text()='Redmond']", JsonValidator.ObjectString) },
                                        new string[0]);

            UnitTestsUtil.VerifyPayload("/Customers(0)/Address/StreetAddress", typeof(CustomDataContext), null,
                                        new string[] { "/cdc:Line1" },
                                        new string[] { String.Format("/{0}/StreetAddress[text()='Line1']", JsonValidator.ObjectString) },
                                        new string[0]);
        }
Esempio n. 28
0
            public void DeleteUsingAnyValueForIfMatch()
            {
                using (CustomDataContext.CreateChangeScope())
                {
                    Type contextType   = typeof(CustomDataContext);
                    var  ifMatchHeader = new KeyValuePair <string, string>[] { new KeyValuePair <string, string>("If-Match", "*") };

                    // Directly deleting a top level entity
                    UnitTestsUtil.SendRequestAndVerifyXPath(null, "/Customers(0)", null, contextType, null, "DELETE", ifMatchHeader, false);

                    // Deleting a deep entity
                    UnitTestsUtil.SendRequestAndVerifyXPath(null, "/Customers(2)/BestFriend", null, contextType, null, "DELETE", ifMatchHeader, false);
                }
            }
        private static void ResponseShouldContainEntities(string requestUriString, params string[] expectedEditLinks)
        {
            RunGetRequest(
                requestUriString,
                request =>
            {
                Assert.AreEqual(200, request.ResponseStatusCode);
                var responsePayload = request.GetResponseStreamAsXDocument();

                const string xpath = "//atom:entry/atom:link[@rel='edit' and @href=\"{0}\"]";
                var xpaths         = expectedEditLinks.Select(e => string.Format(xpath, e)).Concat(new[] { "count(//atom:entry)=" + expectedEditLinks.Length }).ToArray();
                UnitTestsUtil.VerifyXPaths(responsePayload, xpaths);
            });
        }
Esempio n. 30
0
        private void do_startup()
        {
            // this includes the executable as s[0], which we don't want
            string[] args = Environment.GetCommandLineArgs();
            Debug.Assert(args.Length >= 2, "Unexpected number of args. args[0]=exe, args[1]=dll to test");
            string[] new_args = args.Skip(2).ToArray();

            if (runUnitTest)
            {
                try
                {
                    // Setup the unit test case
                    unitTestMethod = UnitTestsUtil.FindUnitTestMethodByName(testAssembly, unitTestMethodName, new_args.Length);
                    unitTestCase   = UnitTestsUtil.CreateUnitTestCase(unitTestMethod, CreateTestContext(), new_args);
                }
                catch (Exception ex)
                {
                    ReportErrorAndExit(ex.Message, ChessExitCode.TestFailure, false, ex);
                }
            }
            else
            {
                // Use the ChessTest.Startup method
                try
                {
                    if (startup != null)
                    {
                        bool ret = (bool)startup.Invoke(null, new Object[] { new_args });
                        if (!ret)
                        {
                            ReportErrorAndExit(testclass + ".Startup returned false.", ChessExitCode.TestFailure, false, null);
                        }
                    }

                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    manager.RunFinalizers();
                }
                catch (Exception ex)
                {
                    if (ex is TargetInvocationException)
                    {
                        ex = ((TargetInvocationException)ex).InnerException;
                    }

                    string message = testclass + ".Startup threw unexpected exception: " + ex.GetType();
                    ReportErrorAndExit(message, ChessExitCode.UnitTestException, false, ex);
                }
            }
        }
Esempio n. 31
0
 internal static void CustomProviderRequest(
     Type providerType,
     string uri,
     string responseFormat,
     PayloadBuilder payloadBuilder,
     KeyValuePair<string, string[]>[] uriAndXPathsToVerify,
     string httpMethodName,
     bool verifyETagReturned,
     IList<KeyValuePair<string, string>> requestHeaders = null,
     IList<KeyValuePair<string, string>> responseHeaders = null,
     UnitTestsUtil.SendRequestModifier sendRequestModifier = UnitTestsUtil.SendRequestModifier.None)
 {
     using (UnitTestsUtil.AppendTypesForOpenProperties(providerType, payloadBuilder, responseFormat))
     {
         UnitTestsUtil.CustomProviderRequest(providerType, uri, responseFormat, PayloadGenerator.Generate(payloadBuilder, responseFormat), uriAndXPathsToVerify, httpMethodName, verifyETagReturned, requestHeaders, responseHeaders, sendRequestModifier);
     }
 }
Esempio n. 32
0
 internal static void CustomProviderRequest(
     Type providerType, 
     string uri, 
     string responseFormat, 
     string payload, 
     KeyValuePair<string, string[]>[] uriAndXPathsToVerify, 
     string httpMethodName, 
     bool verifyETagReturned, 
     IList<KeyValuePair<string, string>> requestHeaders = null,
     IList<KeyValuePair<string, string>> responseHeaders = null,
     UnitTestsUtil.SendRequestModifier sendRequestModifier = UnitTestsUtil.SendRequestModifier.None)
 {
     UnitTestsUtil.CustomProviderRequest(providerType, uri, responseFormat, payload, uriAndXPathsToVerify, httpMethodName, verifyETagReturned, requestHeaders, responseHeaders, sendRequestModifier);
 }