コード例 #1
0
        public void WhenErrorIsNotRestErrorThenReturnsAnotherError()
        {
            // Arrange
            string        bodyContents = "{\"@class\": 'Clase', \"MessageError\": \"MessageError\", \"Otro\": \"Otro\"}";
            IRestResponse response     = new RestResponse()
            {
                StatusCode  = HttpStatusCode.InternalServerError,
                ContentType = "application/json",
                Content     = bodyContents
            };
            var jsonConverter       = new JsonSerializer();
            var jsonErrorSerializer = new JsonSerializer();

            jsonErrorSerializer.Settings.MissingMemberHandling           = Newtonsoft.Json.MissingMemberHandling.Error;
            jsonErrorSerializer.Settings.ContractResolver.ObjectContract = new RequiredAttributesObjectContract(RequiredLevel.AllowNull);

            var processor = new ProcessorStructure <int, IJsonSerializer>(
                new RestExceptionProcessor <int>().Default());

            ProcessorUtilities.SetErrorSerializerForStructure(processor, jsonErrorSerializer);

            // Act
            try
            {
                Assert.IsTrue(processor.CanProcess(response));
                var res = processor.Process(response, jsonConverter);
            }
            // arrange
            catch (RestException ex)
            {
                Assert.AreEqual(HttpStatusCode.InternalServerError, ex.HttpError.StatusCode);
                Assert.AreEqual(bodyContents, ex.HttpError.Details);
                throw;
            }

            Assert.IsTrue(processor.CanProcess(response));
        }
コード例 #2
0
            public void WhenErrorThenReturnLeft()
            {
                // Arrange
                IRestResponse response = new RestResponse()
                {
                    StatusCode  = HttpStatusCode.InternalServerError,
                    ContentType = "application/json",
                    Content     = "{'StatusCode': 400, 'Message': 'Message', 'Details': 'Details'}"
                };
                var processor = new ProcessorStructure <EitherStrict <RestBusinessError, OptionStrict <int> >, IJsonSerializer>(
                    new EitherRestErrorProcessor <OptionStrict <int> >().Default()
                    .AddProcessors(new OptionAsNotFoundProcessor <int>()
                                   .AddProcessors(new SuccessProcessor <int>().Default()))
                    );

                ProcessorUtilities.SetErrorSerializerForStructure(processor, jsonConverter);

                // Act
                Assert.IsTrue(processor.CanProcess(response));
                var res = processor.Process(response, jsonConverter);

                // Assert
                Assert.IsTrue(res.IsLeft);
            }
コード例 #3
0
            public void WhenNotFoundThenReturnNothing()
            {
                // Arrange
                IRestResponse response = new RestResponse()
                {
                    StatusCode  = HttpStatusCode.NotFound,
                    ContentType = "application/json"
                };
                var processor = new ProcessorStructure <EitherStrict <RestBusinessError, OptionStrict <int> >, IJsonSerializer>(
                    new EitherRestErrorProcessor <OptionStrict <int> >().Default()
                    .AddProcessors(new OptionAsNotFoundProcessor <int>()
                                   .AddProcessors(new SuccessProcessor <int>().Default()))
                    );

                ProcessorUtilities.SetErrorSerializerForStructure(processor, jsonConverter);

                // Act
                Assert.IsTrue(processor.CanProcess(response));
                var res = processor.Process(response, jsonConverter);

                // Assert
                Assert.IsTrue(res.IsRight);
                Assert.IsFalse(res.Right.HasValue);
            }
コード例 #4
0
 protected override TResult ProcessSub(IRestResponse response, TSerializer serializer)
 {
     return(ProcessorStructure.Process(response, serializer));
 }
コード例 #5
0
 protected override string ProcessSub(IRestResponse response, IJsonSerializer serializer)
 {
     return(ProcessorStructure.Process(response, serializer));
 }
コード例 #6
0
        protected override TError ProcessSub(IRestResponse response, TSerializer serializer)
        {
            var errorRest = ProcessorStructure.Process(response, serializer);

            return(errorConverterProvider.ProvideError(errorRest, response));
        }
コード例 #7
0
        protected override TResult ProcessSub(IRestResponse response, TSerializer serializer)
        {
            var error = ProcessorStructure.Process(response, serializer);

            throw exceptionProvider.ProvideException(error);
        }