Пример #1
0
        public void ProcessRequest_NoDefault_MatchExists()
        {
            // How many times was the handler called?
            int timesHandlerWasCalled = 0;

            DirtyTestClass conn = new DirtyTestClass();

            conn.RegisterRequestHandlerForType <Nest.SearchResponse <MockType> >((reqd, resd) => {
                resd.Stream     = ElastcsearchTestingTools.MockEmptyResponse;
                resd.StatusCode = 200;
                timesHandlerWasCalled++;
            });

            // The specific value here shouldn't matter.
            RequestData  req = RequestPlaceholder;
            ResponseData res = new ResponseData();

            conn.DoProcessing <Nest.SearchResponse <MockType> >(req, res);

            Assert.Equal(1, timesHandlerWasCalled);
            Assert.Equal(200, res.StatusCode);

            JToken actual;

            using (StreamReader sr = new StreamReader(res.Stream))
            {
                actual = JToken.Parse(sr.ReadToEnd());
            }

            JToken expected = JToken.Parse(ElastcsearchTestingTools.MockEmptyResponseString);

            Assert.Equal(expected, actual, new JTokenEqualityComparer());
        }
Пример #2
0
        public void ProcessRequest_NoHandlerRegistered()
        {
            DirtyTestClass conn = new DirtyTestClass();

            // The specific value here shouldn't matter.
            RequestData  req = RequestPlaceholder;
            ResponseData res = new ResponseData();

            Assert.Throws <ArgumentOutOfRangeException>(
                () => conn.DoProcessing <Nest.SearchResponse <MockType> >(req, res)
                );
        }
Пример #3
0
        public void ProcessRequest_ResponseError()
        {
            DirtyTestClass conn = new DirtyTestClass();

            conn.RegisterRequestHandlerForType <Nest.SearchResponse <MockType> >((reqd, resd) => {
                throw new NotImplementedException();
            });

            // The specific value here shouldn't matter.
            RequestData  req = RequestPlaceholder;
            ResponseData res = new ResponseData();

            // What matters here is that
            // a. The exception was thrown.
            // b. It's the same one.
            // Possibly b. doesn't matter as much, but if that asssumption changes,
            // it should be a deliberate change.
            Assert.Throws <NotImplementedException>(
                () => conn.DoProcessing <Nest.SearchResponse <MockType> >(req, res)
                );
        }
Пример #4
0
        public void ProcessRequest_UseDefault()
        {
            // How many times was the handler called?
            int timesHandlerWasCalled = 0;

            DirtyTestClass conn = new DirtyTestClass();

            conn.RegisterRequestHandlerForType <Nest.SearchResponse <MockType> >((reqd, resd) =>
            {
                throw new NotImplementedException();
            });
            conn.RegisterDefaultHandler((RequestData reqd, Object resd) =>
            {
                ((ResponseData)resd).Stream     = ElastcsearchTestingTools.MockEmptyResponse;
                ((ResponseData)resd).StatusCode = 200;
                timesHandlerWasCalled++;
            });

            // The specific value here shouldn't matter.
            RequestData  req = RequestPlaceholder;
            ResponseData res = new ResponseData();

            // MockType is registered, but we're looking for MockType2.
            conn.DoProcessing <Nest.SearchResponse <MockType2> >(req, res);

            Assert.Equal(1, timesHandlerWasCalled);
            Assert.Equal(200, res.StatusCode);

            JToken actual;

            using (StreamReader sr = new StreamReader(res.Stream))
            {
                actual = JToken.Parse(sr.ReadToEnd());
            }

            JToken expected = JToken.Parse(ElastcsearchTestingTools.MockEmptyResponseString);

            Assert.Equal(expected, actual, new JTokenEqualityComparer());
        }