Beispiel #1
0
        public void SelfLinkNotIncludedOnErrorTest()
        {
            var logger = new Mock <ILogger <SelfLinksFilterAttribute> >();
            var target = new SelfLinksFilterAttribute(logger.Object);

            var responseObject = ApiResponse.OK().WithError(error => error.Status = System.Net.HttpStatusCode.Forbidden).AsItemResponse();

            var context = CreateResultExecutingContext(responseObject);

            target.OnResultExecuting(context);

            var result = (context.Result as ObjectResult).Value as IApiResponse;

            var expected = 0;
            var actual   = result.Links?.Count(l => l.Key == JsonApiConstants.SelfLinkKey) ?? 0;

            Assert.Equal(expected, actual);
        }
Beispiel #2
0
        public void SelfLinkNotIncludedOnEmptyTest()
        {
            var logger = new Mock <ILogger <SelfLinksFilterAttribute> >();
            var target = new SelfLinksFilterAttribute(logger.Object);

            var responseObject = ApiResponse.OK().AsResponse();

            var context = CreateResultExecutingContext(responseObject);

            target.OnResultExecuting(context);

            var result = (context.Result as ObjectResult).Value as IApiResponse;

            var expected = 0;
            var actual   = result.Links?.Count(l => l.Key == JsonApiConstants.SelfLinkKey) ?? 0;

            Assert.Equal(expected, actual);
        }
Beispiel #3
0
        public void SelfLinkIncludedTest()
        {
            var logger = new Mock <ILogger <SelfLinksFilterAttribute> >();
            var target = new SelfLinksFilterAttribute(logger.Object);

            var responseObject = ApiResponse.OK().WithResource("mock", "Mock result data", "0").AsItemResponse();

            var context = CreateResultExecutingContext(responseObject);

            target.OnResultExecuting(context);

            var result = (context.Result as ObjectResult).Value as IApiResponse;

            var expected = 1;
            var actual   = result.Links?.Count(l => l.Key == JsonApiConstants.SelfLinkKey);

            Assert.Equal(expected, actual);
        }