public void TestParseValidResponse() { string rawResponse = VALID_RESPONSE; ScItemsResponse response = ScItemsParser.Parse(rawResponse, CancellationToken.None); Assert.AreEqual(1, response.ResultCount); ISitecoreItem item1 = response[0]; Assert.AreEqual("Home", item1.DisplayName); Assert.AreEqual("web", item1.Source.Database); Assert.AreEqual(true, item1.HasChildren); Assert.AreEqual("en", item1.Source.Language); Assert.AreEqual("{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}", item1.Id); string expectedFullId = "/{11111111-1111-1111-1111-111111111111}/{0DE95AE4-41AB-4D01-9EB0-67441B7C2450}/{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"; Assert.AreEqual(expectedFullId, item1.LongId); Assert.AreEqual("/sitecore/content/Home", item1.Path); Assert.AreEqual("Sample/Sample Item", item1.Template); Assert.AreEqual(1, item1.Source.VersionNumber); Assert.AreEqual(2, item1.FieldsCount); IField field1 = item1.Fields.ElementAt(0); Assert.AreEqual("{75577384-3C97-45DA-A847-81B00500E250}", field1.FieldId); IField field2 = item1.Fields.ElementAt(1); Assert.AreEqual("{A60ACD61-A6DB-4182-8329-C957982CEC74}", field2.FieldId); }
public void TestParseInvalidResponse() { string rawResponse = "{\n \"statusCode\": 200,\n \"result\": {\n \"Invalidtotaldount\": 0,\n \"InvalidresultCount\": 0,\n \"items\": []\n }\n}"; TestDelegate action = () => ScItemsParser.Parse(rawResponse, CancellationToken.None); // @adk.review : waybe we should we wrap this? Assert.Throws <JsonException>(action, "JsonException should be here"); }
public void TestParseInvalidResponse() { string rawResponse = "bla"; TestDelegate action = () => ScItemsParser.Parse(rawResponse, "web", CancellationToken.None); JsonReaderException exception = Assert.Throws <JsonReaderException>(action, "JsonReaderException should be here"); Assert.AreEqual("Unexpected character encountered while parsing value: b. Path '', line 0, position 0.", exception.Message); }
public void TestParseNullResponse() { ScItemsResponse response = ScItemsParser.Parse(null, "web", CancellationToken.None); Assert.NotNull(response); Assert.AreEqual(0, response.ResultCount); Assert.AreEqual(0, response.StatusCode); }
public void TestParseResponseWithEmptyItems() { string rawResponse = "{\n \"statusCode\": 200,\n \"result\": {\n \"totalCount\": 0,\n \"resultCount\": 0,\n \"items\": []\n }\n}"; ScItemsResponse response = ScItemsParser.Parse(rawResponse, CancellationToken.None); Assert.AreEqual(0, response.TotalCount); Assert.AreEqual(0, response.ResultCount); Assert.AreEqual(0, response.ResultCount); }
public void TestParseErrorResponse() { string rawResponse = "{\"statusCode\":401,\"error\":{\"message\":\"Access to the \\u0027master\\u0027 database is denied. Only members of the Sitecore Client Users role can switch databases.\"}}"; TestDelegate action = () => ScItemsParser.Parse(rawResponse, CancellationToken.None); WebApiJsonErrorException exception = Assert.Throws <WebApiJsonErrorException>(action, "ScResponseException should be here"); Assert.AreEqual(401, exception.Response.StatusCode); Assert.AreEqual("Access to the 'master' database is denied. Only members of the Sitecore Client Users role can switch databases.", exception.Response.Message); }
public void TestParseErrorResponse() { string rawResponse = "{\n\"Message\": \"An error has occurred.\"\n}"; TestDelegate action = () => ScItemsParser.Parse(rawResponse, "web", CancellationToken.None); ParserException exception = Assert.Throws <ParserException>(action, "ParserException should be here"); Assert.AreEqual("[Sitecore Mobile SDK] Data from the internet has unexpected format{\n \"Message\": \"An error has occurred.\"\n}", exception.Message); }
public virtual async Task <TResponse> ParseResponseDataAsync(string data, CancellationToken cancelToken) { Func <ScItemsResponse> syncParseResponse = () => { //TODO: @igk debug response output, remove later //Debug.WriteLine("RESPONSE: " + data); return(ScItemsParser.Parse(data, this.CurrentDb, this.statusCode, cancelToken)); }; return(await Task.Factory.StartNew(syncParseResponse, cancelToken) as TResponse); }
public void TestAll20XCodesAreValid() { string responseBegin = "{\"statusCode\":"; string responseEnd = ",\"result\":{\"totalCount\":0,\"resultCount\":0,\"items\":[]}}"; for (int i = 200; i < 300; ++i) { string rawResponse = responseBegin + i.ToString() + responseEnd; ScItemsResponse response = ScItemsParser.Parse(rawResponse, CancellationToken.None); Assert.AreEqual(0, response.ResultCount); } }
public void TestCancellationCausesOperationCanceledException() { TestDelegate testAction = async() => { var cancel = new CancellationTokenSource(); Task <ScItemsResponse> action = Task.Factory.StartNew(() => { int millisecondTimeout = 10; Thread.Sleep(millisecondTimeout); return(ScItemsParser.Parse(VALID_RESPONSE, cancel.Token)); }); cancel.Cancel(); await action; }; Assert.Catch <OperationCanceledException>(testAction); }
public void TestParseValidResponse() { string rawResponse = VALID_RESPONSE; ScItemsResponse response = ScItemsParser.Parse(rawResponse, "web", CancellationToken.None); Assert.AreEqual(1, response.ResultCount); ISitecoreItem item1 = response[0]; Assert.AreEqual("Home", item1.DisplayName); Assert.AreEqual("web", item1.Source.Database); Assert.AreEqual(true, item1.HasChildren); Assert.AreEqual("en", item1.Source.Language); Assert.AreEqual("110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9", item1.Id.ToUpperInvariant()); Assert.AreEqual("/sitecore/content/Home", item1.Path); Assert.AreEqual(1, item1.Source.VersionNumber); Assert.AreEqual(16, item1.FieldsCount); }
public void TestParseNullResponse() { TestDelegate action = () => ScItemsParser.Parse(null, CancellationToken.None); Assert.Throws <ArgumentException>(action, "cannot parse null response"); }
public void TestParseEmptyResponse() { TestDelegate action = () => ScItemsParser.Parse(string.Empty, CancellationToken.None); Assert.Throws <ArgumentException>(action, "cannot parse empty response"); }