Beispiel #1
0
        public void FactoryMethod_Succeeds()
        {
            var activator = new ModelActivator(null);
            var source    = new ListConfiguration(typeof(Request), typeof(Item), typeof(Result))
            {
                ModelActivatorConfiguration = new ModelActivatorConfiguration(_ => new Request())
            };

            var result = activator.CreateInstance(source);

            result.Should().BeOfType <Request>();
        }
Beispiel #2
0
        public void FactoryType_Service_Succeeds()
        {
            var serviceProvider = new ServiceCollection().AddSingleton <Factory>().BuildServiceProvider();
            var httpContext     = new Mock <HttpContext>();
            var hca             = new Mock <IHttpContextAccessor>();

            hca.SetupGet(x => x.HttpContext).Returns(httpContext.Object);
            httpContext.SetupGet(x => x.RequestServices).Returns(serviceProvider);

            var activator = new ModelActivator(hca.Object);
            var source    = new ListConfiguration(typeof(Request), typeof(Item), typeof(Result))
            {
                ModelActivatorConfiguration = new ModelActivatorConfiguration(typeof(Factory))
            };

            var result = activator.CreateInstance(source);

            result.Should().BeOfType <Request>();
        }