Ejemplo n.º 1
0
        public void HttpContextServiceHostTunnelingTest()
        {
            CombinatorialEngine engine = CombinatorialEngine.FromDimensions(
                new Dimension("Method", new string[] { "GET", "POST", "PUT", "DELETE" }),
                new Dimension("XMethod", new string[] { "GET", "POST", "PATCH", "DELETE", "DELETE,DELETE" }));

            TestUtil.RunCombinatorialEngineFail(engine, delegate(Hashtable values)
            {
                using (TestWebRequest request = TestWebRequest.CreateForLocal())
                {
                    request.DataServiceType  = typeof(CustomDataContext);
                    request.RequestUriString = "/Orders(100)";

                    string method      = (string)values["Method"];
                    string xmethod     = (string)values["XMethod"];
                    request.HttpMethod = method;
                    if (xmethod == "PATCH")
                    {
                        request.RequestContentType = UnitTestsUtil.JsonLightMimeType;
                        request.SetRequestStreamAsText(
                            "{ @odata.type:\"#AstoriaUnitTests.Stubs.Order\"" +
                            " , DollarAmount: 10 }");
                    }

                    request.RequestHeaders["X-HTTP-Method"] = xmethod;
                    Exception exception = TestUtil.RunCatching(request.SendRequest);
                    TestUtil.AssertExceptionExpected(exception,
                                                     method != "POST",
                                                     xmethod != "PATCH");
                }
            });
        }
Ejemplo n.º 2
0
            //[TestMethod]
            public void SilverlightBasicTest()
            {
                // setup northwind database
                ServiceModelData modelData = ServiceModelData.Values[0];

                using (TestWebRequest request = TestWebRequest.CreateForLocal())
                {
                    request.DataServiceType = modelData.ServiceModelType;
                    request.StartService();

                    #region copy compiled binaries for Silverlight request

                    string baseUri = request.BaseUri;
                    Assert.IsTrue(baseUri.EndsWith(".svc", StringComparison.Ordinal));

                    string FileTargetPath = LocalWebServerHelper.FileTargetPath;
                    Assert.IsTrue(!FileTargetPath.EndsWith("\\"));

                    string SilverlightSrcPath = LocalWebServerHelper.BinarySourcePath + "\\Silverlight";
                    string ClientBinPath      = FileTargetPath + "\\ClientBin";

                    string startPage  = "Astoria.Silverlight.html";
                    string requestUri = baseUri.Substring(0, baseUri.LastIndexOf('/') + 1) + "ClientBin/" + startPage;

                    string[] binariesToCopy = new string[] { // to ClientBinPath
                        DataFxAssemblyRef.File.DataServicesClient,
                        DataFxAssemblyRef.File.DataServicesClient.Replace(".dll", ".pdb"),
                        "Astoria.Silverlight.UnitTests.dll",
                        "Astoria.Silverlight.UnitTests.pdb",
                    };

                    string[] pagesToCopy = new string[] { // to FileTargetPath
                        "Astoria.Silverlight.xaml",
                        startPage,
                        startPage + ".js",
                        "Silverlight.js",
                    };

                    foreach (string file in binariesToCopy)
                    {
                        Assert.IsTrue(File.Exists(SilverlightSrcPath + "\\" + file), file);
                    }

                    foreach (string file in pagesToCopy)
                    {
                        Assert.IsTrue(File.Exists(SilverlightSrcPath + "\\" + file), file);
                    }

                    Directory.CreateDirectory(ClientBinPath);

                    foreach (string file in binariesToCopy)
                    {
                        File.Copy(
                            SilverlightSrcPath + "\\" + file,
                            ClientBinPath + "\\" + file,
                            /*overwrite*/ true);
                    }

                    foreach (string binary in pagesToCopy)
                    {
                        File.Copy(
                            SilverlightSrcPath + "\\" + binary,
                            ClientBinPath + "\\" + binary,
                            /*overwrite*/ true);
                    }

                    #endregion

                    string status = "missing";

                    Thread uiThread = new Thread(delegate(object o)
                    {
                        Form form          = new Form();
                        form.Width         = 640;
                        form.Height        = 480;
                        WebBrowser browser = new WebBrowser();
                        browser.Width      = form.Width;
                        browser.Height     = form.Height;
                        form.Controls.Add(browser);
                        browser.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;

                        SilverlightExternal scriptingObject = new SilverlightExternal();
                        scriptingObject.TestCompletedEvent += delegate(object sender, TestCompletedEventArgs e)
                        {
                            status = e.Status;
#if false
                            Action action = delegate { form.Text = e.Status; };
                            form.Invoke(action);
#else
                            form.Close();
#endif
                        };

                        browser.ObjectForScripting = scriptingObject;

                        form.Load += delegate(object sender, EventArgs e)
                        {
                            browser.Url = new Uri(requestUri);
                            form.BringToFront();
                        };
                        form.ShowDialog();
                        return;
                    });

                    uiThread.SetApartmentState(ApartmentState.STA);
                    uiThread.Start();
                    if (!uiThread.Join(new TimeSpan(0, 3, 0)))
                    {
                        status = "timeout";
                    }

                    if (status != "test finished")
                    {
                        throw new Exception(status);
                    }
                }
            }