Пример #1
0
        public async Task DataWrapperFilter_NotWrapStatueCodeOption()
        {
            // Arrange
            var httpContext = CreateFakeHttpContext("Get", 200);
            var objResult   = new ObjectResult("1234");
            var options     = Options.Create(new MiCakeAspNetOptions()
            {
                DataWrapperOptions = new DataWrapperOptions()
                {
                    NoWrapStatusCode = new List <int>()
                    {
                        200
                    }
                }
            });
            var resultExecutingContext = GetResourceExecutingContext(httpContext, objResult);
            var wrapperFilter          = new DataWrapperFilter(options, new DefaultWrapperExecutor());

            //action
            await wrapperFilter.OnResultExecutionAsync(resultExecutingContext,
                                                       () => Task.FromResult(CreateResultExecutedContext(resultExecutingContext)));

            //assert
            var resultInfo = resultExecutingContext.Result as ObjectResult;

            Assert.NotNull(resultInfo);
            Assert.False(resultInfo.Value is IResultDataWrapper);
        }
Пример #2
0
        public async Task DataWrapperFilter_NotObjectResult()
        {
            // Arrange
            var httpContext   = CreateFakeHttpContext("Get", 200);
            var noFoundResult = new NotFoundResult();
            var options       = Options.Create(new MiCakeAspNetOptions()
            {
                DataWrapperOptions = new DataWrapperOptions()
            });
            var resultExecutingContext = GetResourceExecutingContext(httpContext, noFoundResult);
            var wrapperFilter          = new DataWrapperFilter(options, new DefaultWrapperExecutor());

            //action
            await wrapperFilter.OnResultExecutionAsync(resultExecutingContext,
                                                       () => Task.FromResult(CreateResultExecutedContext(resultExecutingContext)));

            //assert
            var resultInfo = resultExecutingContext.Result as NotFoundResult;

            Assert.NotNull(resultInfo);
        }
Пример #3
0
        public async Task DataWrapperFilter_ObjectResult_UseWrapper()
        {
            // Arrange
            var          httpContext  = CreateFakeHttpContext("Get", 200);
            ObjectResult objectResult = new(1234);
            var          options      = Options.Create(new MiCakeAspNetOptions()
            {
                DataWrapperOptions = new DataWrapperOptions()
            });
            var resultExecutingContext = GetResourceExecutingContext(httpContext, objectResult);
            var wrapperFilter          = new DataWrapperFilter(options, new DefaultWrapperExecutor());

            //action
            await wrapperFilter.OnResultExecutionAsync(resultExecutingContext,
                                                       () => Task.FromResult(CreateResultExecutedContext(resultExecutingContext)));

            //assert
            Assert.NotNull(resultExecutingContext.Result);
            Assert.IsAssignableFrom <ObjectResult>(resultExecutingContext.Result);
            Assert.IsAssignableFrom <IResultDataWrapper>(((ObjectResult)resultExecutingContext.Result).Value);
        }
Пример #4
0
        public async Task DataWrapperFilter_ObjectResultStatusCodeIsNull()
        {
            // Arrange
            var httpContext = CreateFakeHttpContext("Get", 200);
            var objResult   = new ObjectResult("1234")
            {
                StatusCode = null
            };
            var options = Options.Create(new MiCakeAspNetOptions());
            var resultExecutingContext = GetResourceExecutingContext(httpContext, objResult);
            var wrapperFilter          = new DataWrapperFilter(options, new DefaultWrapperExecutor());

            //action
            await wrapperFilter.OnResultExecutionAsync(resultExecutingContext,
                                                       () => Task.FromResult(CreateResultExecutedContext(resultExecutingContext)));

            //assert
            var resultInfo = resultExecutingContext.Result as ObjectResult;

            Assert.NotNull(resultInfo);
            Assert.Equal(200, (resultInfo.Value as ApiResponse).StatusCode);
        }