public void DecodeResponse()
        {
            CollectionResponseDecoder <Greeting, EmptyRecord> decoder = new CollectionResponseDecoder <Greeting, EmptyRecord>();

            Dictionary <string, object> data = new Dictionary <string, object>()
            {
                {
                    "elements", new List <object>()
                    {
                        new Dictionary <string, object>()
                        {
                            { "id", 123 },
                            { "message", "hello" },
                            { "tone", "FRIENDLY" }
                        },
                        new Dictionary <string, object>()
                        {
                            { "id", 234 },
                            { "message", "world" },
                            { "tone", "SINCERE" }
                        }
                    }
                },
                {
                    "paging", new Dictionary <string, object>()
                    {
                        { "count", 0 },
                        { "start", 0 },
                        { "links", new List <object>()
                          {
                          } }
                    }
                }
            };

            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "foo", "bar" }
            };

            HttpResponse      httpResponse      = new HttpResponse(200, headers, null, null);
            TransportResponse transportResponse = new TransportResponse(data, httpResponse);

            CollectionResponse <Greeting, EmptyRecord> response = decoder.DecodeResponse(transportResponse);

            Assert.AreEqual(2, response.elements.Count);
            Assert.AreEqual("bar", response.headers["foo"][0]);

            Assert.IsNotNull(response.paging);
            Assert.IsNull(response.metadata);

            Assert.AreEqual(123, response.elements[0].id);
            Assert.AreEqual("hello", response.elements[0].message);
            Assert.AreEqual(Tone.Symbol.FRIENDLY, response.elements[0].tone.symbol);

            Assert.AreEqual(234, response.elements[1].id);
            Assert.AreEqual("world", response.elements[1].message);
            Assert.AreEqual(Tone.Symbol.SINCERE, response.elements[1].tone.symbol);
        }
示例#2
0
 public FinderRequest(Dictionary <string, List <string> > headers, Dictionary <string, object> queryParams, string methodName, string baseUrlTemplate, Dictionary <string, object> pathKeys)
     : base(ResourceMethod.FINDER, null, headers, queryParams, baseUrlTemplate, pathKeys)
 {
     this.methodName = methodName;
     responseDecoder = new CollectionResponseDecoder <TEntity, TMeta>();
 }