public void AreEquals_NestedObjects_Fail()
        {
            const string expectedObject     = "{prop1:'value1', nested0:{}, nested: {key:'value'}}";
            const string actualObject       = "{prop1:'value1', nested0:{}, nested: {key:'value2'}}";
            var          assertionException =
                Assert.Throws <AssertionException>(() => AssertJson.AreEquals(expectedObject, actualObject));

            Assert.IsTrue(
                assertionException.Message.StartsWith(string.Format("  Property \"{0}\" does not match.", "nested.key")));
        }
        public void AreEquals_NestedArrays_Fail()
        {
            const string expectedObject     = "{prop1:'value1', arr:[1, '2', {key: 'value'}]}";
            const string actualObject       = "{prop1:'value1', arr:[1, '3', {key: 'value'}]}";
            var          assertionException =
                Assert.Throws <AssertionException>(() => AssertJson.AreEquals(expectedObject, actualObject));

            Assert.IsTrue(
                assertionException.Message.StartsWith(string.Format("  Property \"{0}\" does not match.", "arr[1]")));
        }
        public void AreEquals_ExcessProperty_Fail()
        {
            const string expectedObject     = "{name:'value'}";
            const string actualObject       = "{name:'value', excess:'yes'}";
            var          assertionException =
                Assert.Throws <AssertionException>(() => AssertJson.AreEquals(expectedObject, actualObject));

            Assert.AreEqual(assertionException.Message,
                            string.Format("Object  has excess properties: excess"));
        }
        public void AreEquals_NestedArraysDifferentLength_Fail()
        {
            const string expectedObject     = "{prop1:'value1', arr:[1, '2', {key: 'value'}, 5]}";
            const string actualObject       = "{prop1:'value1', arr:[1, '3', {key: 'value'}]}";
            var          assertionException =
                Assert.Throws <AssertionException>(() => AssertJson.AreEquals(expectedObject, actualObject));

            Assert.AreEqual(
                string.Format("Different arrays length at {0}. Expected: {1}, but was: {2}", "arr", "4", "3"),
                assertionException.Message);
        }
        public void AreEquals_UnequalIntPropertyValues_Fail()
        {
            const string expectedObject = "{prop1:'value1', int:15}";
            const string actualObject   = "{prop1:'value1', int:16}";

            var assertionException =
                Assert.Throws <AssertionException>(() => AssertJson.AreEquals(expectedObject, actualObject));

            Assert.IsTrue(
                assertionException.Message.StartsWith(string.Format("  Property \"{0}\" does not match.", "int")));
        }
        public void AreEquals_ComplexJson_Fail()
        {
            const string expectedObject =
                "{\"array\":[1,2,3],\"boolean\":true,\"null\":null,\"number\":123,\"object\":{\"a\":\"b\",\"c\":\"d\",\"e\":\"f\",\"test\":{\"arr\":[{\"key\":{\"diff\":\"val\"}},{}]},\"name\":\"value\"},\"string\":\"Hello World\"}";
            const string actualObject =
                "{\"array\":[1,2,3],\"boolean\":true,\"null\":null,\"number\":123,\"object\":{\"a\":\"b\",\"c\":\"d\",\"e\":\"f\",\"test\":{\"arr\":[{\"key\":{\"diff\":\"val2\"}},{}]},\"name\":\"value\"},\"string\":\"Hello World\"}";
            var assertionException =
                Assert.Throws <AssertionException>(() => AssertJson.AreEquals(expectedObject, actualObject));

            Assert.IsTrue(
                assertionException.Message.StartsWith(string.Format("  Property \"{0}\" does not match.",
                                                                    "object.test.arr[0].key.diff")));
        }
Beispiel #7
0
        //[TestMethodWithReport]
        public void TestGetAndAssertLongJson()
        {
            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "Accept", "application/json" }
            };

            RestClientHelper restClientHelper = new RestClientHelper();
            string           getUrl           = "http://localhost:1082/laptop-bag/webapi/api/all";
            IRestResponse    restResponse     = restClientHelper.PerformGetRequest(getUrl, headers);

            Assert.AreEqual(200, (int)restResponse.StatusCode);
            Assert.IsNotNull(restResponse.Content, "Content is Null/Empty");

            IRestResponse <List <Laptop> > restResponse1 = restClientHelper.PerformGetRequest <List <Laptop> >(getUrl, headers);

            Assert.AreEqual(200, (int)restResponse.StatusCode);
            Assert.IsNotNull(restResponse1.Data, "Content is Null/Empty");

            var actual = File.ReadAllText(Directory.GetCurrentDirectory() + "/Resource/Get/getall.json");

            AssertJson.AreEquals(restResponse.Content, actual);
        }
 public void AreEquals_EqualJsonStrings_Success()
 {
     AssertJson.AreEquals("{name:'value'}", "{name:'value'}");
 }