当前位置: 首页>>代码示例>>C#>>正文


C# Proxy.Add方法代码示例

本文整理汇总了C#中System.Proxy.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Proxy.Add方法的具体用法?C# Proxy.Add怎么用?C# Proxy.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Proxy的用法示例。


在下文中一共展示了Proxy.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Initialize

        public void Initialize()
        {
            Proxy = new Proxy(10011);
            Proxy.DeleteAll();

            // Post
            var s = SimulationFactory.When.I.Post().ToImdb("/Pet/{Kind}/Toy/{Name}/Price", "owner").AsJson().And.NotExists("{Ranking}").Then.AddToImdb().And.Return.StatusCode(System.Net.HttpStatusCode.Created);
            Proxy.Add(s);

            s = SimulationFactory.When.I.Post().ToImdb("/Pet/{Kind}/Toy/{Name}/Price", "owner").AsJson().And.Exists("{Ranking}").Then.Return.StatusCode(System.Net.HttpStatusCode.Conflict);
            Proxy.Add(s);

            // Put
            s = SimulationFactory.When.I.Put().ToImdb("/Pet/{Kind}/Toy/{Name}/Price", "owner").AsJson().And.NotExists("{Ranking}").Then.Return.StatusCode(System.Net.HttpStatusCode.Created).Then.AddToImdb();
            Proxy.Add(s);

            s = SimulationFactory.When.I.Put().ToImdb("/Pet/{Kind}/Toy/{Name}/Price", "owner").AsJson().And.Exists("{Ranking}").Then.Return.StatusCode(System.Net.HttpStatusCode.PartialContent).Then.AddToImdb();
            Proxy.Add(s);

            s = SimulationFactory.When.I.Put().ToImdb("/Pet/{Kind}/Toy/{Name}/Price/{Ranking}", "owner").AsJson().And.NotExists("{Ranking}").Then.Return.StatusCode(System.Net.HttpStatusCode.Unauthorized).Then.AddToImdb();
            Proxy.Add(s);

            s = SimulationFactory.When.I.Put().ToImdb("/Pet/{Kind}/Toy/{Name}/Price/{Ranking}", "owner").AsJson().And.Exists("{Ranking}").Then.Return.StatusCode(System.Net.HttpStatusCode.UnsupportedMediaType).Then.AddToImdb();
            Proxy.Add(s);

            // GetById
            s = SimulationFactory.When.I.Get().FromImdb("/Pet/{Kind}/Toy/{Name}/Price/{Ranking}", "owner").AsJson().And.Exists("{Ranking}").Then.Return.StatusCode(System.Net.HttpStatusCode.OK).And.Body("{value}");
            Proxy.Add(s);

            s = SimulationFactory.When.I.Get().FromImdb("/Pet/{Kind}/Toy/{Name}/Price/{Ranking}", "owner").AsJson().And.NotExists("{Ranking}").Then.Return.StatusCode(System.Net.HttpStatusCode.NotFound);
            Proxy.Add(s);

            // Get All
            s = SimulationFactory.When.I.Get().FromImdb("/Pet/{Kind}/Toy/{Name}/Price", "owner").AsJson().Then.Return.StatusCode(System.Net.HttpStatusCode.PaymentRequired).And.Body("[{value}]");
            Proxy.Add(s);
        }
开发者ID:aidancasey,项目名称:Moksy,代码行数:36,代码来源:ImdbNestedTests.cs

示例2: Main

        static void Main(string[] args)
        {
            if (args == null || args.Length < 1)
            {
                Usage();
                System.Environment.Exit(1);
            }

            int port = 0;
            var success = Int32.TryParse(args[0], out port);
            if (!success)
            {
                Usage();
                System.Environment.Exit(1);
            }

            bool simulationsSpecified = false;
            string simulationsPath = null;
            Moksy.Common.SimulationCollection simulations = new Common.SimulationCollection();
            simulationsPath = args.FirstOrDefault(f => f.StartsWith("/File:", StringComparison.InvariantCultureIgnoreCase));
            if (simulationsPath != null)
            {
                simulationsPath = simulationsPath.Substring(6);
                simulationsSpecified = true;
            }
            var log = args.FirstOrDefault(f => f.StartsWith("/Log:true", StringComparison.InvariantCultureIgnoreCase) || string.Compare(f, "/log", true) == 0);

            System.Reflection.Assembly thisExe;
            thisExe = System.Reflection.Assembly.GetExecutingAssembly();
            var list = thisExe.GetManifestResourceNames();

            var header = ReadResource("Moksy.Host.Resources.Header.txt");
            var simulationsText = ReadResource("Moksy.Host.Resources.Simulations.txt");

            ApplicationDirectives parameters = new ApplicationDirectives() { Log = (log != null) };

            try
            {
                Console.WriteLine("----------------------------------------------");
                Console.WriteLine("MOKSY: REST API / JSON Endpoint Faking Toolkit");
                Console.WriteLine("----------------------------------------------");
                Console.WriteLine("by Grey Ham");
                Console.WriteLine();
                Console.WriteLine("See www.brekit.com for more information. ");
                Console.WriteLine("Source at https://github.com/greyham/Moksy");
                Console.WriteLine();

                if (simulationsSpecified)
                {
                    Console.Write(string.Format("Loading simulations from {0}...", simulationsPath));

                    var contents = System.IO.File.ReadAllText(simulationsPath);
                    simulations = Newtonsoft.Json.JsonConvert.DeserializeObject<Moksy.Common.SimulationCollection>(contents);

                    Console.WriteLine(string.Format("{0} simulations have been loaded. ", simulations.Count));
                    Console.WriteLine("");

                    // ASSERTION: We have loaded the simulations into memory.
                }

                Application app = new Application(port, parameters);
                app.Start();

                Console.WriteLine(string.Format("Running Moksy on Port {0}. ", port));
                Console.WriteLine(string.Format("Navigate to: http://localhost:{0} for a sanity test.", port));

                if (simulationsSpecified)
                {
                    Task.Factory.StartNew(() =>
                    {
                        Proxy proxy = new Proxy(port);
                        proxy.Wait(20);

                        // We need to wait until the service has started.
                        foreach (var simulation in simulations)
                        {
                            proxy.Add(simulation);
                        }
                    }, TaskCreationOptions.LongRunning
                    );
                }

                Console.WriteLine("Press a key to exit...");
                Console.ReadKey();
                app.Stop();
            }
            catch (System.AggregateException aggregate)
            {
                Console.WriteLine("ERROR: Launching Moksy.Host.Exe");
                Console.WriteLine(aggregate.Message);
                if (aggregate.InnerException.GetType().FullName == "System.ServiceModel.AddressAccessDeniedException")
                {
                    Console.WriteLine();
                    Console.WriteLine("Moksy launches a real HTTP Server and opens up a HTTP Endpoint so that your");
                    Console.WriteLine("tests and other services can hit it. ");
                    Console.WriteLine();
                    Console.WriteLine("By default, only applications launched as Administrator are allowed to");
                    Console.WriteLine("launch the HTTP Server and create the end-point. ");
                    Console.WriteLine();
                    Console.WriteLine("You are not running as Administrator. ");
//.........这里部分代码省略.........
开发者ID:aidancasey,项目名称:Moksy,代码行数:101,代码来源:Program.cs


注:本文中的System.Proxy.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。