public async Task Invoke_CallProcessBatchAsync_WithBatchHandler() { // Arrange bool called = false; RequestDelegate next = context => { called = true; return(Task.CompletedTask); }; Mock <ODataBatchHandler> batchHandlerMock = new Mock <ODataBatchHandler>(); bool processed = false; batchHandlerMock.Setup(b => b.ProcessBatchAsync(It.IsAny <HttpContext>(), It.IsAny <RequestDelegate>())) .Returns(() => { processed = true; return(Task.CompletedTask); }); IServiceProvider sp = BuildServiceProvider(opt => opt.AddModel("odata", EdmCoreModel.Instance, batchHandlerMock.Object)); ODataBatchMiddleware middleware = new ODataBatchMiddleware(sp, next.Invoke); HttpContext context = new DefaultHttpContext(); context.Request.Path = new PathString("/odata/$batch"); // Act Assert.False(called); Assert.False(processed); await middleware.Invoke(context); // Assert Assert.False(called); Assert.True(processed); }
public void Ctor_NullBatchMapping_WithoutServiceProvider() { // Arrange ODataBatchMiddleware middleware = new ODataBatchMiddleware(null, null); // Act & Assert Assert.Null(middleware.BatchMapping); }
public void Ctor_NullBatchMapping_WithServiceProvider_WithBatchHandler() { // Arrange IServiceProvider sp = BuildServiceProvider(opt => opt.AddModel("odata", EdmCoreModel.Instance, new DefaultODataBatchHandler())); ODataBatchMiddleware middleware = new ODataBatchMiddleware(sp, null); // Act & Assert Assert.NotNull(middleware.BatchMapping); }
public void Ctor_NullBatchMapping_WithServiceProvider_WithoutBatchHandler() { // Arrange IServiceProvider sp = BuildServiceProvider(opt => opt.AddRouteComponents("odata", EdmCoreModel.Instance)); ODataBatchMiddleware middleware = new ODataBatchMiddleware(sp, null); // Act & Assert Assert.Null(middleware.BatchMapping); }
public ODataBatchMiddlewareTests() { _batchMiddleware = new ODataBatchMiddleware(CorsDelegate); _routeBuilder = RoutingConfigurationFactory.CreateWithRootContainer("odata"); _routeBuilder.MapODataServiceRoute("odata", "odata", b => { b.AddService <ODataBatchHandler>(ServiceLifetime.Singleton, implementationFactory => new TestODataBatchHandler()); }); }
public async Task Invoke_CallNextDelegate_WithoutBatchHandler() { // Arrange bool called = false; RequestDelegate next = context => { called = true; return(Task.CompletedTask); }; ODataBatchMiddleware middleware = new ODataBatchMiddleware(null, next.Invoke); HttpContext context = new DefaultHttpContext(); // Act Assert.False(called); await middleware.Invoke(context); // Assert Assert.True(called); }