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));
 }
 protected override string ProcessSub(IRestResponse response, IJsonSerializer serializer)
 {
     return(ProcessorStructure.Process(response, serializer));
 }
        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);
        }