Пример #1
0
    public void CreateReleaser_ReturnsNullIfControllerIsNotDisposable()
    {
        // Arrange
        var activator         = new DefaultControllerActivator(Mock.Of <ITypeActivatorCache>());
        var activatorProvider = new ControllerActivatorProvider(activator);
        var descriptor        = new ControllerActionDescriptor
        {
            ControllerTypeInfo = typeof(TestController).GetTypeInfo(),
        };

        // Act
        var releaseDelegate = activatorProvider.CreateReleaser(descriptor);

        // Assert
        Assert.Null(releaseDelegate);
    }
Пример #2
0
    public void CreateReleaser_ReturnsDelegateThatDisposesInstance()
    {
        // Arrange
        var activator         = new DefaultControllerActivator(Mock.Of <ITypeActivatorCache>());
        var activatorProvider = new ControllerActivatorProvider(activator);
        var descriptor        = new ControllerActionDescriptor
        {
            ControllerTypeInfo = typeof(DisposableController).GetTypeInfo(),
        };
        var controller = new DisposableController();

        // Act
        var releaseDelegate = activatorProvider.CreateReleaser(descriptor);

        // Assert
        Assert.NotNull(releaseDelegate);
        releaseDelegate(new ControllerContext(), controller);
        Assert.True(controller.Disposed);
    }
Пример #3
0
    public void CreateReleaser_InvokesIControllerActivator_IfItIsNotDefaultControllerActivator()
    {
        // Arrange
        var expected  = new object();
        var activator = new Mock <IControllerActivator>();

        activator.Setup(a => a.Release(It.IsAny <ControllerContext>(), expected))
        .Verifiable();
        var activatorProvider = new ControllerActivatorProvider(activator.Object);
        var descriptor        = new ControllerActionDescriptor
        {
            ControllerTypeInfo = typeof(object).GetTypeInfo(),
        };

        // Act
        var releaseDelegate = activatorProvider.CreateReleaser(descriptor);

        releaseDelegate(new ControllerContext(), expected);

        // Assert
        activator.Verify();
    }