Exemple #1
0
        public static CustomResponseDataBuilder <TE> RegisterExceptionWithCustomResponse <TE>(
            this IServiceCollection services)
            where TE : Exception
        {
            var responseOptionsBuilder = new CustomResponseDataBuilder <TE>();

            services.AddTransient <IExceptionHandler <TE>, ExceptionHandler <TE> >(s =>
                                                                                   new ExceptionHandler <TE>(responseOptionsBuilder.GetResponseOptions));
            return(responseOptionsBuilder);
        }
Exemple #2
0
        public void GetResponseData_NoAdditionalSetup_EmptyObject()
        {
            //Arrange
            var responseDataBuilder = new CustomResponseDataBuilder <Exception>();
            var expectedData        = new ResponseData()
            {
                StatusCode = 500,
                Body       = new object()
            };

            //Act
            var responseData = responseDataBuilder.GetResponseOptions(new Exception(), new ResponseContext());

            //Assert
            responseData.Should().BeEquivalentTo(expectedData);
        }
Exemple #3
0
        public void GetResponseData_FunctionPassed_ObjectReturned(int statusCode, TestResponseObject testResponseObject)
        {
            //Arrange
            var responseDataBuilder = new CustomResponseDataBuilder <Exception>()
                                      .WithStatusCode(e => statusCode)
                                      .WithBody((e, ro) => testResponseObject);
            var expectedData = new ResponseData()
            {
                StatusCode = statusCode,
                Body       = testResponseObject
            };

            //Act
            var responseData = responseDataBuilder.GetResponseOptions(new Exception(), new ResponseContext());

            //Assert
            responseData.Should().BeEquivalentTo(expectedData);
        }