public void Create_RegisteredService_Succeeds()
        {
            var serviceProvider = new ServiceCollection()
                                  .AddSingleton <ISearchActivator <TextSearch>, TextSearchActivator>()
                                  .BuildServiceProvider();
            var factory = new SearchActivatorFactory(serviceProvider);

            var actual = factory.Create(typeof(TextSearch));

            actual.Should().BeOfType <TextSearchActivator>();
        }
        public void Create_Fallback_Succeeds()
        {
            var mock = new Mock <IServiceProvider>();

            var factory = new SearchActivatorFactory(mock.Object);

            var actual = factory.Create(typeof(TextSearch));

            actual.Should().BeOfType <FallbackSearchActivator>();

            mock.Verify(x => x.GetService(It.IsAny <Type>()), Times.Once);
        }
        public void Create_Caching_Succeeds()
        {
            var mock = new Mock <IServiceProvider>();

            mock.Setup(x => x.GetService(It.IsAny <Type>()))
            .Returns(new TextSearchActivator());

            var factory = new SearchActivatorFactory(mock.Object);

            var actual1 = factory.Create(typeof(TextSearch));
            var actual2 = factory.Create(typeof(TextSearch));

            actual1.Should().BeOfType <TextSearchActivator>();
            actual2.Should().BeOfType <TextSearchActivator>();

            mock.Verify(x => x.GetService(It.IsAny <Type>()), Times.Once);
        }
        public SearchActivatorTests()
        {
            var definition = new ListExpression <Request, Item, Result>();

            definition
            .Search(x => x.Text, x => x.ActivateUsing(() => new TextSearch()))
            .Search(x => x.Integer, x => x.ActivateUsing(sp => new IntegerSearchActivator()))
            .Property(x => x.Foo, x => x.DefaultValue("Test"))
            .Property(x => x.Bar, x => x.Ignore());


            var mock = new Mock <IOptions <GenericSearchOptions> >();

            mock.Setup(x => x.Value)
            .Returns(new GenericSearchOptions());
            var options = mock.Object;

            var factory = new ListConfigurationFactory(new SearchConfigurationFactory(new PascalCasePropertyPathFinder()),
                                                       new PageConfigurationFactory(options),
                                                       new RowsConfigurationFactory(options),
                                                       new SortColumnConfigurationFactory(options),
                                                       new SortDirectionConfigurationFactory(options),
                                                       new PropertyConfigurationFactory(),
                                                       new PostRedirectGetConfigurationFactory(options),
                                                       new TransferValuesConfigurationFactory(options),
                                                       new ModelActivatorConfigurationFactory(options));

            var configuration = factory.Create(definition);

            var serviceProvider = new ServiceCollection().BuildServiceProvider();

            model = new Request();

            var activatorFactory = new SearchActivatorFactory(serviceProvider);
            var activator        = new ModelPropertyActivator(activatorFactory, serviceProvider);

            activator.Activate(configuration, model);
        }