Exemple #1
0
    public void CreateAsyncReleaser_ReturnsNullForModelsThatDoNotImplementDisposable(Type pageType)
    {
        // Arrange
        var context          = new PageContext();
        var activator        = new DefaultPageModelActivatorProvider();
        var actionDescriptor = new CompiledPageActionDescriptor
        {
            PageTypeInfo = pageType.GetTypeInfo(),
        };

        // Act
        var releaser = activator.CreateAsyncReleaser(actionDescriptor);

        // Assert
        Assert.Null(releaser);
    }
Exemple #2
0
    public async Task CreateAsyncReleaser_CreatesDelegateThatDisposesAsyncDisposableTypes()
    {
        // Arrange
        var context     = new PageContext();
        var viewContext = new ViewContext();
        var activator   = new DefaultPageModelActivatorProvider();
        var model       = new AsyncDisposableModel();

        // Act & Assert
        var disposer = activator.CreateAsyncReleaser(new CompiledPageActionDescriptor
        {
            ModelTypeInfo = model.GetType().GetTypeInfo()
        });

        Assert.NotNull(disposer);
        await disposer(context, model);

        // Assert
        Assert.True(model.Disposed);
    }