Esempio n. 1
0
    public void CreateActivator_TypeActivatesModelType()
    {
        // Arrange
        var activatorProvider = new DefaultPageModelActivatorProvider();
        var actionDescriptor  = new CompiledPageActionDescriptor
        {
            ModelTypeInfo = typeof(ModelWithServices).GetTypeInfo(),
        };
        var serviceCollection = new ServiceCollection();
        var generator         = Mock.Of <IHtmlGenerator>();

        serviceCollection.AddSingleton(generator);
        var httpContext = new DefaultHttpContext
        {
            RequestServices = serviceCollection.BuildServiceProvider(),
        };
        var pageContext = new PageContext
        {
            HttpContext = httpContext
        };

        // Act
        var activator = activatorProvider.CreateActivator(actionDescriptor);
        var model     = activator(pageContext);

        // Assert
        var modelWithServices = Assert.IsType <ModelWithServices>(model);

        Assert.Same(generator, modelWithServices.Generator);
    }
Esempio n. 2
0
    public void CreateActivator_ThrowsIfModelTypeInfoOnActionDescriptorIsNull()
    {
        // Arrange
        var activatorProvider = new DefaultPageModelActivatorProvider();
        var actionDescriptor  = new CompiledPageActionDescriptor();

        // Act & Assert
        ExceptionAssert.ThrowsArgument(
            () => activatorProvider.CreateActivator(actionDescriptor),
            "actionDescriptor",
            "The 'ModelTypeInfo' property of 'actionDescriptor' must not be null.");
    }