Esempio n. 1
0
    public RequestTest requestTest(string arithmeticOperator, int testNum)
    {
        RequestTest requestTest = new RequestTest();

        requestTest.send(arithmeticOperator, testNum);
        return(requestTest);
    }
        public static RequestTest Test(string url)
        {
            var test = new RequestTest()
            {
                Url = url
            };
            var sw      = new Stopwatch();
            var request = WebRequest.CreateHttp(test.Url);

            request.AllowAutoRedirect = true;
            request.Method            = "HEAD";
            request.Headers.Add("Accept-Language: ru-RU, en; q = 0.5");
            try
            {
                sw.Start();
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    sw.Stop();
                    test.Time       = (int)sw.ElapsedMilliseconds;
                    test.StatusCode = response.StatusCode;
                }
                return(test);
            }
            catch (WebException ex)
            {
                test.StatusCode = ((HttpWebResponse)ex.Response).StatusCode;
                return(test);
            }
        }
        public RequestTest Test(Uri uri)
        {
            var test = new RequestTest()
            {
                Url = uri.ToString()
            };
            var sw      = new Stopwatch();
            var request = _requestCreator.Create(uri);

            request.CookieContainer = _cookieContainer;
            try
            {
                sw.Start();
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    test.Time       = (int)sw.ElapsedMilliseconds;
                    test.StatusCode = response.StatusCode;
                }
                return(test);
            }
            catch (WebException ex)
            {
                test.StatusCode = ((HttpWebResponse)ex.Response).StatusCode;
                return(test);
            }
        }
        public IHttpActionResult PutRequestTest(int id, RequestTest requestTest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != requestTest.Id)
            {
                return(BadRequest());
            }

            db.Entry(requestTest).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RequestTestExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult GetRequestTest(int id)
        {
            RequestTest requestTest = db.RequestTests.Find(id);

            if (requestTest == null)
            {
                return(NotFound());
            }

            return(Ok(requestTest));
        }
        public async Task PostRequestTestTest_RejectsInvalidModel()
        {
            var sut         = new RequestTestsController();
            var requestTest = new RequestTest();

            sut.Configuration = new System.Web.Http.HttpConfiguration();
            sut.Request       = new System.Net.Http.HttpRequestMessage();
            sut.Validate(requestTest);
            var sutResult = sut.PostRequestTest(requestTest);
            var result    = await sutResult.ExecuteAsync(CancellationToken.None);

            Assert.AreEqual(false, result.IsSuccessStatusCode);
        }
        public IHttpActionResult DeleteRequestTest(int id)
        {
            RequestTest requestTest = db.RequestTests.Find(id);

            if (requestTest == null)
            {
                return(NotFound());
            }

            db.RequestTests.Remove(requestTest);
            db.SaveChanges();

            return(Ok(requestTest));
        }
        public IHttpActionResult PostRequestTest(RequestTest requestTest)
        {
            if (requestTest == null)
            {
                ModelState.AddModelError("Global", "No body posted.");
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //db.RequestTests.Add(requestTest);
            //db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = requestTest.Id }, requestTest));
        }
        public async Task PostRequestTestTest_WithNull_ReturnsBadRequest()
        {
            var         sut         = new RequestTestsController();
            RequestTest requestTest = null;

            sut.Configuration = new System.Web.Http.HttpConfiguration();
            sut.Request       = new System.Net.Http.HttpRequestMessage();
            sut.Validate(requestTest);
            var sutResult = sut.PostRequestTest(requestTest);
            var result    = await sutResult.ExecuteAsync(CancellationToken.None);

            var statusCode = result.StatusCode;
            var content    = await result.Content.ReadAsStringAsync();

            Assert.AreEqual(System.Net.HttpStatusCode.BadRequest, statusCode);
        }
Esempio n. 10
0
        public void EntityTestByFile(string pFileName)
        {
            // Load test data
            var lNsiSuite      = LoadData.GetData(pFileName);
            var lNsiEntityList = lNsiSuite.EntityList;

            if (lNsiEntityList.Count > 0)
            {
                // Enter to request
                Assert.True(RequestTest.EnterToRequest(lNsiSuite.RequestId), "No enter into nsi request");

                string lLastId = "";

                // Execute test for every entity from test file
                foreach (NsiEntity lEntity in lNsiEntityList)
                {
                    // If entity id is "lastadd" then assign lId from lastId
                    if (lEntity.IdIsLastAdd())
                    {
                        if (lLastId.Length == 0)
                        {
                            Console.WriteLine("Skip test " + lEntity.ToString());
                            continue;
                        }
                        lEntity.Id = lLastId;
                    }

                    // Declare entity
                    EntityTestFactory entityTestFactory = new EntityTestFactory();

                    // Execute test for entity
                    string lAddId = entityTestFactory.Test(lEntity);

                    // Assign last entity id
                    if (lAddId.Length > 0)
                    {
                        lLastId = lAddId;
                    }
                }
            }
            else
            {
                Assert.Fail("Пустой файл данных \"" + pFileName + "\"");
            }
        }
            public override ErrorList Validate()
            {
                var result = new ErrorList();

                result.AddRange(base.Validate());

                if (Encounter != null)
                {
                    result.AddRange(Encounter.Validate());
                }
                if (RequestOrderId != null)
                {
                    result.AddRange(RequestOrderId.Validate());
                }
                if (ReceiverOrderId != null)
                {
                    result.AddRange(ReceiverOrderId.Validate());
                }
                if (RequestTest != null)
                {
                    RequestTest.ForEach(elem => result.AddRange(elem.Validate()));
                }
                if (BodySite != null)
                {
                    result.AddRange(BodySite.Validate());
                }
                if (Requester != null)
                {
                    result.AddRange(Requester.Validate());
                }
                if (ClinicalInfoElement != null)
                {
                    result.AddRange(ClinicalInfoElement.Validate());
                }

                return(result);
            }
Esempio n. 12
0
        protected T RunTest <T>(string test, object data)
        {
            logger.Entry($"Test {test} started");

            var request = new RequestTest {
                Name = test, Data = data
            };
            var message = new CommandMessage {
                Command = Commands.TestCase, Data = request
            };

            var response = pipeClient.RunCommand(message) as ResponseTest;

            logger.Entry($"Test {test} completed");

            Assert.NotNull(response, "Null response from test command.");
            Assert.True(response.Result, "Failed result from test command.");
            if (response.Data is T responseData)
            {
                return(responseData);
            }

            Assert.Fail("Invalid response data from test command.");
            return(default);
Esempio n. 13
0
        private void menuItemCopySessionAsTestCase_Click(object sender, EventArgs e)
        {
            Fiddler.Session[] sessions = FiddlerApplication.UI.GetSelectedSessions();
            if (sessions == null || sessions.Length == 0)
            {
                return;
            }

            List <RequestTest> list = new List <HttpTest.RequestTest>(sessions.Length);

            // 获取所有的请求内容
            foreach (Fiddler.Session session in sessions)
            {
                string lineHeaders = session.oRequest.headers.ToString(true, false, true);
                lineHeaders = FilterRequestHeader(lineHeaders);
                string postData = session.GetRequestBodyAsString();


                RequestTest test = new RequestTest();
                list.Add(test);

                if (IsWithoutPostData(session.RequestMethod))
                {
                    test.Request = "\r\n" + lineHeaders;
                }
                else
                {
                    test.Request = "\r\n" + lineHeaders + "\r\n" + postData + "\r\n";
                }

                test.Category = string.Empty;
                test.Title    = string.Empty;
                test.Response = new ResponseAssert();


                if (session.bHasResponse)
                {
                    test.Response.StatusCode = session.ResponseHeaders.HTTPResponseCode;
                    test.Response.Headers    = new List <ResponseHeaderAssert>();
                    test.Response.Body       = new List <ResponseBodyAssert>();

                    // 默认用 Content-Type 做为示例
                    var header = session.ResponseHeaders.FirstOrDefault(x => x.Name == "Content-Type");
                    if (header != null)
                    {
                        test.Response.Headers.Add(new ResponseHeaderAssert {
                            Name       = header.Name,
                            AssertMode = "==",
                            Value      = header.Value
                        });
                    }
                    else
                    {
                        // 增加一个空模板
                        test.Response.Headers.Add(new ResponseHeaderAssert {
                            Name       = "header_Name",
                            AssertMode = "",
                            Value      = "this_is_placeholder"                         // 加下划线方便双击选择
                        });
                    }

                    // 增加一个空模板
                    test.Response.Body.Add(new ResponseBodyAssert {
                        Name       = "Text",
                        AssertMode = "",
                        Value      = "this_is_placeholder"                     // 加下划线方便双击选择
                    });
                }
            }


            string xml = ClownFish.Base.Xml.XmlHelper.XmlSerialize(list, Encoding.UTF8);

            try {
                Clipboard.SetText(xml);
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message, "ClownFish.FiddlerPulgin", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }