Пример #1
0
        public Start(GingerAction act)
        {
            InitializeComponent();

            mAct = act;

            ActionParam AP2 = mAct.GetOrCreateParam("Port", "1234");

            Port.BindControl(AP2);

            ActionParam AP3 = mAct.GetOrCreateParam("DynamicPort", "false");

            DynamicPortCheckBox.BindControl(AP3);
        }
Пример #2
0
        public Stop(GingerAction act)
        {
            InitializeComponent();
            mAct = act;
            ActionParam AP1 = mAct.GetOrCreateParam("ProviderID");

            ProviderID.BindControl(AP1);
        }
Пример #3
0
        public LoadInteractionsFile(GingerAction act)
        {
            InitializeComponent();

            mAct = act;

            ActionParam AP1 = mAct.GetOrCreateParam("FileName");

            FileName.BindControl(AP1);
        }
Пример #4
0
        public override void RunAction(GingerAction act)
        {
            switch (act.ID)
            {
            case cStart:
                if (SV != null)
                {
                    SV.MockProviderService.Stop();
                }
                string port = "0";
                if (!Boolean.Parse(act.GetOrCreateParam("DynamicPort").Value.ToString()))
                {
                    port = act.GetOrCreateParam("Port").GetValueAsString();
                }
                SV = new ServiceVirtualization(int.Parse(port));

                act.ExInfo = "Mock Service Started: " + SV.MockProviderServiceBaseUri;

                break;

            case cStop:
                if (SV == null)
                {
                    act.Error += "Error: Service Virtualization not started yet";
                    return;
                }

                SV.MockProviderService.Stop();
                SV          = null;
                act.ExInfo += "Mock Server stopped";
                break;

            case cLoadInteractionsFile:
                if (SV == null)
                {
                    act.Error += "Error: Service Virtualization not started yet";
                    return;
                }
                string s = act.GetOrCreateParam("FileName").GetValueAsString();
                if (s.StartsWith("~"))
                {
                    s = Path.GetFullPath(s.Replace("~", act.SolutionFolder));
                }
                if (File.Exists(s))
                {
                    int count = SV.LoadInteractions(s);
                    act.ExInfo += "Interaction file loaded: '" + s + "', " + count + " Interactions loaded";
                    act.AddOutput("Interaction Loaded", count + "");
                }
                else
                {
                    act.Error += "Interaction file not found - " + s;
                }
                break;

            case cLoadInteractionsFolder:
                if (SV == null)
                {
                    act.Error += "Error: Service Virtualization not started yet";
                    return;
                }
                break;

            case cClearInteractions:
                if (SV == null)
                {
                    act.Error += "Error: Service Virtualization not started yet";
                    return;
                }
                SV.ClearInteractions();
                act.ExInfo += "Interactions cleared";
                break;

            case cAddInteraction:
                if (SV == null)
                {
                    act.Error += "Error: Service Virtualization not started yet";
                    return;
                }

                //TODO: get it from the edit page
                ProviderServiceInteraction PSI = new ProviderServiceInteraction();
                PSI.ProviderState = act.GetOrCreateParam("ProviderState").GetValueAsString();
                PSI.Description   = act.GetOrCreateParam("Description").GetValueAsString();
                PSI.Request       = new ProviderServiceRequest();


                string HTTPType = act.GetOrCreateParam("RequestType").GetValueAsString();
                switch (HTTPType)
                {
                case "Get":
                    PSI.Request.Method = HttpVerb.Get;
                    break;

                case "Post":
                    PSI.Request.Method = HttpVerb.Post;
                    break;

                case "PUT":
                    PSI.Request.Method = HttpVerb.Put;
                    break;

                    //TODO: add all the rest and include default for err
                }

                PSI.Request.Path = act.GetOrCreateParam("Path").GetValueAsString();
                Dictionary <string, string> d = new Dictionary <string, string>();
                d.Add("Accept", "application/json");      //TODO: fixme
                PSI.Request.Headers = d;
                PSI.Response        = new ProviderServiceResponse();
                PSI.Response.Status = 200;                                //TODO: fixme
                Dictionary <string, string> r = new Dictionary <string, string>();
                r.Add("Content-Type", "application/json; charset=utf-8"); //TODO: fixme
                PSI.Response.Headers = r;
                PSI.Response.Body    = act.GetOrCreateParam("ResposneBody").GetValueAsString();

                SV.AddInteraction(PSI);

                act.ExInfo += "Interaction added";

                break;

            case cSaveInteractions:
                SV.SaveInteractions();
                act.ExInfo += "Interactions saved to file";
                // TODO: add file name to ex info
                break;

            default:
                act.Error += "Unknown PlugIn action ID - " + act.ID;
                break;
            }
        }
        public AddInteractionEditPage(GingerAction act)
        {
            InitializeComponent();

            mAct = act;

            ActionParam AP1 = mAct.GetOrCreateParam("ProviderState");

            ProviderStateTextBox.BindControl(AP1);

            ActionParam AP2 = mAct.GetOrCreateParam("Description");

            DescriptionTextBox.BindControl(AP2);

            List <ComboBoxListItem> HTTPMethodList = new List <ComboBoxListItem>();

            HTTPMethodList.Add(new ComboBoxListItem()
            {
                Text = "Get", Value = "Get"
            });
            HTTPMethodList.Add(new ComboBoxListItem()
            {
                Text = "Head", Value = "Head"
            });
            HTTPMethodList.Add(new ComboBoxListItem()
            {
                Text = "Not Set", Value = "NotSet"
            });
            HTTPMethodList.Add(new ComboBoxListItem()
            {
                Text = "Patch", Value = "Patch"
            });
            HTTPMethodList.Add(new ComboBoxListItem()
            {
                Text = "Post", Value = "Post"
            });
            HTTPMethodList.Add(new ComboBoxListItem()
            {
                Text = "Put", Value = "Put"
            });

            ActionParam AP3 = mAct.GetOrCreateParam("RequestTypeComboBox");

            RequestMethodComboBox.BindControl(AP3, HTTPMethodList);

            ActionParam AP5 = mAct.GetOrCreateParam("Path");

            PathTextBox.BindControl(AP5);

            List <ComboBoxListItem> StatusList = new List <ComboBoxListItem>();

            StatusList.Add(new ComboBoxListItem()
            {
                Text = "OK", Value = "200"
            });
            StatusList.Add(new ComboBoxListItem()
            {
                Text = "Created", Value = "201"
            });
            StatusList.Add(new ComboBoxListItem()
            {
                Text = "No Content", Value = "204"
            });
            StatusList.Add(new ComboBoxListItem()
            {
                Text = "Not Modified", Value = "304"
            });
            StatusList.Add(new ComboBoxListItem()
            {
                Text = "Bad Request", Value = "400"
            });
            StatusList.Add(new ComboBoxListItem()
            {
                Text = "Unauthorized", Value = "401"
            });
            StatusList.Add(new ComboBoxListItem()
            {
                Text = "Forbidden", Value = "403"
            });
            StatusList.Add(new ComboBoxListItem()
            {
                Text = "Not Found", Value = "404"
            });
            StatusList.Add(new ComboBoxListItem()
            {
                Text = "Conflict", Value = "409"
            });
            StatusList.Add(new ComboBoxListItem()
            {
                Text = "Internal Server Error", Value = "500"
            });
            StatusList.Add(new ComboBoxListItem()
            {
                Text = "Service Unavailable", Value = "503"
            });

            //TODO: after the above most common enable the user to see all available http code: http://www.restapitutorial.com/httpstatuscodes.html

            //TODO: fill the rest
            ActionParam AP4 = mAct.GetOrCreateParam("Status");

            ResponseStatusComboBox.BindControl(AP4, StatusList);
            RequestHeadersGrid.ItemsSource  = RequestHeaders;
            RepsonseHeadersGrid.ItemsSource = ResponseHeaders;
        }