Browse Source

Using the action descriptor DTO instead of mocking it.

pull/257/head
Alex Van Dyke 8 years ago
parent
commit
9eb755930b
  1. 6
      tests/Squidex.Tests/Pipeline/ActionContextLogAppenderTests.cs
  2. 4
      tests/Squidex.Tests/Pipeline/ApiCostTests.cs
  3. 4
      tests/Squidex.Tests/Pipeline/ApiExceptionFilterAttributeTests.cs
  4. 4
      tests/Squidex.Tests/Pipeline/AppApiTests.cs
  5. 4
      tests/Squidex.Tests/Pipeline/AppPermissionAttributeTests.cs
  6. 6
      tests/Squidex.Tests/Pipeline/CommandMiddlewares/EnrichWithSchemaIdCommandMiddlewareTests.cs
  7. 4
      tests/Squidex.Tests/Pipeline/FileCallbackResultTests.cs

6
tests/Squidex.Tests/Pipeline/ActionContextLogAppenderTests.cs

@ -24,7 +24,7 @@ namespace Squidex.Tests.Pipeline
{ {
private readonly Mock<IActionContextAccessor> actionContextAccessor = new Mock<IActionContextAccessor>(); private readonly Mock<IActionContextAccessor> actionContextAccessor = new Mock<IActionContextAccessor>();
private readonly Mock<HttpContext> httpContextMock = new Mock<HttpContext>(); private readonly Mock<HttpContext> httpContextMock = new Mock<HttpContext>();
private readonly Mock<ActionDescriptor> actionDescriptor = new Mock<ActionDescriptor>(); private readonly ActionDescriptor actionDescriptor = new ActionDescriptor();
private readonly RouteData routeData = new RouteData(); private readonly RouteData routeData = new RouteData();
private readonly Guid requestId = Guid.NewGuid(); private readonly Guid requestId = Guid.NewGuid();
private readonly IDictionary<object, object> items = new Dictionary<object, object>(); private readonly IDictionary<object, object> items = new Dictionary<object, object>();
@ -66,7 +66,7 @@ namespace Squidex.Tests.Pipeline
{ {
A.CallTo(() => request.Method).Returns(string.Empty); A.CallTo(() => request.Method).Returns(string.Empty);
httpContextMock.Setup(x => x.Request).Returns(request); httpContextMock.Setup(x => x.Request).Returns(request);
actionContext = new ActionContext(httpContextMock.Object, routeData, actionDescriptor.Object); actionContext = new ActionContext(httpContextMock.Object, routeData, actionDescriptor);
actionContextAccessor.Setup(x => x.ActionContext).Returns(actionContext); actionContextAccessor.Setup(x => x.ActionContext).Returns(actionContext);
sut = new ActionContextLogAppender(actionContextAccessor.Object); sut = new ActionContextLogAppender(actionContextAccessor.Object);
@ -78,7 +78,7 @@ namespace Squidex.Tests.Pipeline
A.CallTo(() => request.Method).Returns("Get"); A.CallTo(() => request.Method).Returns("Get");
httpContextMock.Setup(x => x.Items).Returns(items); httpContextMock.Setup(x => x.Items).Returns(items);
httpContextMock.Setup(x => x.Request).Returns(request); httpContextMock.Setup(x => x.Request).Returns(request);
actionContext = new ActionContext(httpContextMock.Object, routeData, actionDescriptor.Object); actionContext = new ActionContext(httpContextMock.Object, routeData, actionDescriptor);
actionContextAccessor.Setup(x => x.ActionContext).Returns(actionContext); actionContextAccessor.Setup(x => x.ActionContext).Returns(actionContext);
sut = new ActionContextLogAppender(actionContextAccessor.Object); sut = new ActionContextLogAppender(actionContextAccessor.Object);
} }

4
tests/Squidex.Tests/Pipeline/ApiCostTests.cs

@ -30,7 +30,7 @@ namespace Squidex.Tests.Pipeline
{ {
private readonly Mock<IActionContextAccessor> actionContextAccessor = new Mock<IActionContextAccessor>(); private readonly Mock<IActionContextAccessor> actionContextAccessor = new Mock<IActionContextAccessor>();
private readonly RouteData routeData = new RouteData(); private readonly RouteData routeData = new RouteData();
private readonly Mock<ActionDescriptor> actionDescriptor = new Mock<ActionDescriptor>(); private readonly ActionDescriptor actionDescriptor = new ActionDescriptor();
private readonly IAppPlansProvider appPlanProvider = A.Fake<IAppPlansProvider>(); private readonly IAppPlansProvider appPlanProvider = A.Fake<IAppPlansProvider>();
private readonly IUsageTracker usageTracker = A.Fake<IUsageTracker>(); private readonly IUsageTracker usageTracker = A.Fake<IUsageTracker>();
private readonly long usage = 1; private readonly long usage = 1;
@ -46,7 +46,7 @@ namespace Squidex.Tests.Pipeline
public ApiCostTests() public ApiCostTests()
{ {
var actionContext = new ActionContext(httpContextMock.Object, routeData, actionDescriptor.Object); var actionContext = new ActionContext(httpContextMock.Object, routeData, actionDescriptor);
actionContextAccessor.Setup(x => x.ActionContext).Returns(actionContext); actionContextAccessor.Setup(x => x.ActionContext).Returns(actionContext);
context = new ActionExecutingContext(actionContext, new List<IFilterMetadata>(), new Dictionary<string, object>(), null); context = new ActionExecutingContext(actionContext, new List<IFilterMetadata>(), new Dictionary<string, object>(), null);
context.Filters.Add(new ServiceFilterAttribute(typeof(ApiCostsFilter))); context.Filters.Add(new ServiceFilterAttribute(typeof(ApiCostsFilter)));

4
tests/Squidex.Tests/Pipeline/ApiExceptionFilterAttributeTests.cs

@ -22,7 +22,7 @@ namespace Squidex.Tests.Pipeline
public class ApiExceptionFilterAttributeTests public class ApiExceptionFilterAttributeTests
{ {
private readonly Mock<HttpContext> httpContextMock = new Mock<HttpContext>(); private readonly Mock<HttpContext> httpContextMock = new Mock<HttpContext>();
private readonly Mock<ActionDescriptor> actionDescriptor = new Mock<ActionDescriptor>(); private readonly ActionDescriptor actionDescriptor = new ActionDescriptor();
private readonly RouteData routeData = new RouteData(); private readonly RouteData routeData = new RouteData();
private readonly ApiExceptionFilterAttribute sut = new ApiExceptionFilterAttribute(); private readonly ApiExceptionFilterAttribute sut = new ApiExceptionFilterAttribute();
private readonly ExceptionContext context; private readonly ExceptionContext context;
@ -30,7 +30,7 @@ namespace Squidex.Tests.Pipeline
public ApiExceptionFilterAttributeTests() public ApiExceptionFilterAttributeTests()
{ {
actionContext = new ActionContext(httpContextMock.Object, routeData, actionDescriptor.Object); actionContext = new ActionContext(httpContextMock.Object, routeData, actionDescriptor);
context = new ExceptionContext(actionContext, new List<IFilterMetadata>()); context = new ExceptionContext(actionContext, new List<IFilterMetadata>());
} }

4
tests/Squidex.Tests/Pipeline/AppApiTests.cs

@ -31,7 +31,7 @@ namespace Squidex.Tests.Pipeline
{ {
private readonly Mock<IActionContextAccessor> actionContextAccessor = new Mock<IActionContextAccessor>(); private readonly Mock<IActionContextAccessor> actionContextAccessor = new Mock<IActionContextAccessor>();
private readonly RouteData routeData = new RouteData(); private readonly RouteData routeData = new RouteData();
private readonly Mock<ActionDescriptor> actionDescriptor = new Mock<ActionDescriptor>(); private readonly ActionDescriptor actionDescriptor = new ActionDescriptor();
private readonly IAppPlansProvider appPlanProvider = A.Fake<IAppPlansProvider>(); private readonly IAppPlansProvider appPlanProvider = A.Fake<IAppPlansProvider>();
private readonly IUsageTracker usageTracker = A.Fake<IUsageTracker>(); private readonly IUsageTracker usageTracker = A.Fake<IUsageTracker>();
private readonly long usage = 1; private readonly long usage = 1;
@ -47,7 +47,7 @@ namespace Squidex.Tests.Pipeline
public AppApiTests() public AppApiTests()
{ {
var actionContext = new ActionContext(httpContextMock.Object, routeData, actionDescriptor.Object); var actionContext = new ActionContext(httpContextMock.Object, routeData, actionDescriptor);
actionContextAccessor.Setup(x => x.ActionContext).Returns(actionContext); actionContextAccessor.Setup(x => x.ActionContext).Returns(actionContext);
context = new ActionExecutingContext(actionContext, new List<IFilterMetadata>(), new Dictionary<string, object>(), null); context = new ActionExecutingContext(actionContext, new List<IFilterMetadata>(), new Dictionary<string, object>(), null);
context.Filters.Add(new AppApiAttribute()); context.Filters.Add(new AppApiAttribute());

4
tests/Squidex.Tests/Pipeline/AppPermissionAttributeTests.cs

@ -32,7 +32,7 @@ namespace Squidex.Tests.Pipeline
{ {
private readonly Mock<HttpContext> httpContextMock = new Mock<HttpContext>(); private readonly Mock<HttpContext> httpContextMock = new Mock<HttpContext>();
private readonly Mock<ClaimsPrincipal> mockUser = new Mock<ClaimsPrincipal>(); private readonly Mock<ClaimsPrincipal> mockUser = new Mock<ClaimsPrincipal>();
private readonly Mock<ActionDescriptor> actionDescriptor = new Mock<ActionDescriptor>(); private readonly ActionDescriptor actionDescriptor = new ActionDescriptor();
private readonly Mock<IActionContextAccessor> actionContextAccessor = new Mock<IActionContextAccessor>(); private readonly Mock<IActionContextAccessor> actionContextAccessor = new Mock<IActionContextAccessor>();
private readonly IAppEntity appEntity = A.Fake<IAppEntity>(); private readonly IAppEntity appEntity = A.Fake<IAppEntity>();
private readonly ClaimsIdentity identity = new ClaimsIdentity(); private readonly ClaimsIdentity identity = new ClaimsIdentity();
@ -48,7 +48,7 @@ namespace Squidex.Tests.Pipeline
public AppPermissionAttributeTests() public AppPermissionAttributeTests()
{ {
actionContext = new ActionContext(httpContextMock.Object, routeData, actionDescriptor.Object); actionContext = new ActionContext(httpContextMock.Object, routeData, actionDescriptor);
actionContextAccessor.Setup(x => x.ActionContext).Returns(actionContext); actionContextAccessor.Setup(x => x.ActionContext).Returns(actionContext);
clientClaim = new Claim("client_id", $"test:clientId"); clientClaim = new Claim("client_id", $"test:clientId");
subjectClaim = new Claim("sub", "user"); subjectClaim = new Claim("sub", "user");

6
tests/Squidex.Tests/Pipeline/CommandMiddlewares/EnrichWithSchemaIdCommandMiddlewareTests.cs

@ -5,7 +5,6 @@
// All rights reserved. Licensed under the MIT license. // All rights reserved. Licensed under the MIT license.
// ========================================================================== // ==========================================================================
using System; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using FakeItEasy; using FakeItEasy;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
@ -17,7 +16,6 @@ using Moq;
using Squidex.Domain.Apps.Core; using Squidex.Domain.Apps.Core;
using Squidex.Domain.Apps.Core.Schemas; using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Entities; using Squidex.Domain.Apps.Entities;
using Squidex.Domain.Apps.Entities.Apps.Commands;
using Squidex.Domain.Apps.Entities.Contents.Commands; using Squidex.Domain.Apps.Entities.Contents.Commands;
using Squidex.Domain.Apps.Entities.Schemas; using Squidex.Domain.Apps.Entities.Schemas;
using Squidex.Domain.Apps.Entities.Schemas.State; using Squidex.Domain.Apps.Entities.Schemas.State;
@ -33,7 +31,7 @@ namespace Squidex.Tests.Pipeline.CommandMiddlewares
private readonly Mock<IActionContextAccessor> actionContextAccessor = new Mock<IActionContextAccessor>(); private readonly Mock<IActionContextAccessor> actionContextAccessor = new Mock<IActionContextAccessor>();
private readonly ICommandBus commandBus = A.Fake<ICommandBus>(); private readonly ICommandBus commandBus = A.Fake<ICommandBus>();
private readonly Mock<HttpContext> httpContextMock = new Mock<HttpContext>(); private readonly Mock<HttpContext> httpContextMock = new Mock<HttpContext>();
private readonly Mock<ActionDescriptor> actionDescriptor = new Mock<ActionDescriptor>(); private readonly ActionDescriptor actionDescriptor = new ActionDescriptor();
private readonly IAppProvider appProvider = A.Fake<IAppProvider>(); private readonly IAppProvider appProvider = A.Fake<IAppProvider>();
private readonly Guid appId = Guid.NewGuid(); private readonly Guid appId = Guid.NewGuid();
private readonly string appName = "app"; private readonly string appName = "app";
@ -116,7 +114,7 @@ namespace Squidex.Tests.Pipeline.CommandMiddlewares
A.CallTo(() => appProvider.GetSchemaAsync(appId, schemaName)).Returns(schema); A.CallTo(() => appProvider.GetSchemaAsync(appId, schemaName)).Returns(schema);
} }
var actionContext = new ActionContext(httpContextMock.Object, routeData, actionDescriptor.Object); var actionContext = new ActionContext(httpContextMock.Object, routeData, actionDescriptor);
actionContextAccessor.Setup(x => x.ActionContext).Returns(actionContext); actionContextAccessor.Setup(x => x.ActionContext).Returns(actionContext);
return new EnrichWithSchemaIdCommandMiddleware(appProvider, actionContextAccessor.Object); return new EnrichWithSchemaIdCommandMiddleware(appProvider, actionContextAccessor.Object);
} }

4
tests/Squidex.Tests/Pipeline/FileCallbackResultTests.cs

@ -24,7 +24,7 @@ namespace Squidex.Tests.Pipeline
{ {
private readonly ILoggerFactory loggerFactory = A.Fake<ILoggerFactory>(); private readonly ILoggerFactory loggerFactory = A.Fake<ILoggerFactory>();
private readonly ActionContext context; private readonly ActionContext context;
private readonly Mock<ActionDescriptor> actionDescriptor = new Mock<ActionDescriptor>(); private readonly ActionDescriptor actionDescriptor = new ActionDescriptor();
private readonly Mock<HttpContext> httpContext = new Mock<HttpContext>(); private readonly Mock<HttpContext> httpContext = new Mock<HttpContext>();
private readonly Mock<HttpRequest> requestMock = new Mock<HttpRequest>(); private readonly Mock<HttpRequest> requestMock = new Mock<HttpRequest>();
private readonly Mock<HttpResponse> responseMock = new Mock<HttpResponse>(); private readonly Mock<HttpResponse> responseMock = new Mock<HttpResponse>();
@ -42,7 +42,7 @@ namespace Squidex.Tests.Pipeline
httpContext.Setup(x => x.Request).Returns(requestMock.Object); httpContext.Setup(x => x.Request).Returns(requestMock.Object);
httpContext.Setup(x => x.Response).Returns(responseMock.Object); httpContext.Setup(x => x.Response).Returns(responseMock.Object);
context = new ActionContext(httpContext.Object, new RouteData(), actionDescriptor.Object); context = new ActionContext(httpContext.Object, new RouteData(), actionDescriptor);
callback = async bodyStream => { callbackWasCalled = true; }; callback = async bodyStream => { callbackWasCalled = true; };
callbackExecutor = new FileCallbackResultExecutor(loggerFactory); callbackExecutor = new FileCallbackResultExecutor(loggerFactory);
sut = new FileCallbackResult("text/plain", "test.txt", callback); sut = new FileCallbackResult("text/plain", "test.txt", callback);

Loading…
Cancel
Save