Ejemplo n.º 1
0
        public void OnUseRestTest_ValidateCookies()
        {
            var classTest = new ClassTest();

            var restTest = new RT("./test.json");

            restTest.OnTestFinished += classTest.OnFinished;

            _server.ResponseCookies.Add("Country", "EUA");

            restTest.Start();

            Assert.AreEqual(Status.Ok, classTest.Results["cookie test"].Status);
            Assert.AreEqual(string.Empty, classTest.Results["cookie test"].Error);

            Assert.AreEqual(Status.Fail, classTest.Results["cookie test error"].Status);
            var expected          = "Cookie => expected { \"country\": \"wrong cookie\", \"cookie1\": \"value1\" } received { \"Country\": \"EUA\", \"cookie1\": \"value1\" }";
            var expectedFormatted = new TextFormatter(expected).RemoveAllSpaces().ToString();
            var actualFormatted   = new TextFormatter(classTest.Results["cookie test error"].Error).RemoveAllSpaces().ToString();

            Assert.AreEqual(expectedFormatted, actualFormatted);

            Assert.AreEqual(Status.Ok, classTest.Results["no cookie validation"].Status);
            Assert.AreEqual(string.Empty, classTest.Results["no cookie validation"].Error);
        }
Ejemplo n.º 2
0
        public void OnUseRestTest_ValidateHeader()
        {
            var classTest = new ClassTest();

            var restTest = new RT("./header_validation.json");

            restTest.OnTestFinished += classTest.OnFinished;

            _server.ResponseHeader.Add("Content-Type", "application/json");

            restTest.Start();

            //Assert.AreEqual(Status.Ok, classTest.Results["header validation"].Status);
            //Assert.AreEqual(string.Empty, classTest.Results["header validation"].Error);

            Assert.AreEqual(Status.Fail, classTest.Results["header wrong validation"].Status);
            var expected         = "Header => expected { \"custom-header\": \"custom-value\", \"Server\": \"Microsoft-HTTPAPI/2.0\", \"Date\": \"${ANY}\", \"Content-Length\": \"0\" } received { \"Server\": \"Microsoft-HTTPAPI/2.0\", \"Date\": \"${ANY}\", \"Content-Length\": \"0\", \"Content-Type\": \"application/json\" }";
            var expectedFormated = new TextFormatter(expected).RemoveAllSpaces().ToString();

            // Replace date from test
            var actual         = Regex.Replace(classTest.Results["header wrong validation"].Error, "received.*\"Date\":.*GMT", "received { \"Server\": \"Microsoft-HTTPAPI/2.0\", \"Date\": \"${ANY}");
            var actualFormated = new TextFormatter(actual).RemoveAllSpaces().ToString();

            Assert.AreEqual(expectedFormated, actualFormated);
        }
Ejemplo n.º 3
0
        public void OnUseRestTest_ValidateStatus()
        {
            var classTest = new ClassTest();

            var restTest = new RT("./test.json");

            restTest.OnTestFinished += classTest.OnFinished;

            restTest.Start();
            Assert.AreEqual(Status.Ok, classTest.Results["validation status 200"].Status);
            Assert.AreEqual(string.Empty, classTest.Results["validation status 200"].Error);

            Assert.AreEqual(Status.Fail, classTest.Results["validation status wrong port"].Status);
            Assert.IsTrue(classTest.Results["validation status wrong port"].Error.Contains("General error"));

            Assert.AreEqual(Status.Ok, classTest.Results["without status validation. Status 200"].Status);
            Assert.AreEqual(string.Empty, classTest.Results["without status validation. Status 200"].Error);
        }
Ejemplo n.º 4
0
        public void OnUseRestTest_ValidateBody()
        {
            var classTest = new ClassTest();

            var restTest = new RT("./test.json");

            restTest.OnTestFinished += classTest.OnFinished;

            _server.ResponseBody = "{\"responseStr\": \"any\", \"responseInt\": 19 }";

            restTest.Start();
            Assert.AreEqual(Status.Ok, classTest.Results["validation body"].Status);
            Assert.AreEqual(string.Empty, classTest.Results["validation body"].Error);

            Assert.AreEqual(Status.Fail, classTest.Results["wrong validation body"].Status);
            Assert.AreEqual(RemoveNewLine($"Body => expected {{\"responseStr\": \"wrong response\", \"responseInt\": 19}} received {_server.ResponseBody}").Replace(" ", ""),
                            RemoveNewLine(classTest.Results["wrong validation body"].Error).Replace(" ", ""));

            Assert.AreEqual(Status.Ok, classTest.Results["no body validation"].Status);
            Assert.AreEqual(string.Empty, classTest.Results["no body validation"].Error);
        }