/// <summary> /// Sets the rules engine data source from a Mongo DB database. /// </summary> /// <typeparam name="TContentType">The type of the content type.</typeparam> /// <typeparam name="TConditionType">The type of the condition type.</typeparam> /// <param name="rulesDataSourceSelector">The rules data source selector.</param> /// <param name="mongoClient">The mongo client.</param> /// <param name="mongoDbProviderSettings">The mongo database provider settings.</param> /// <returns></returns> /// <exception cref="ArgumentNullException"> /// rulesDataSourceSelector /// or /// mongoClient /// or /// mongoDbProviderSettings /// </exception> public static IConfiguredRulesEngineBuilder <TContentType, TConditionType> SetMongoDbDataSource <TContentType, TConditionType>( this IRulesDataSourceSelector <TContentType, TConditionType> rulesDataSourceSelector, IMongoClient mongoClient, MongoDbProviderSettings mongoDbProviderSettings) { if (rulesDataSourceSelector is null) { throw new ArgumentNullException(nameof(rulesDataSourceSelector)); } if (mongoClient is null) { throw new ArgumentNullException(nameof(mongoClient)); } if (mongoDbProviderSettings is null) { throw new ArgumentNullException(nameof(mongoDbProviderSettings)); } IContentSerializationProvider <TContentType> contentSerializationProvider = new DynamicToStrongTypeContentSerializationProvider <TContentType>(); IRuleFactory <TContentType, TConditionType> ruleFactory = new RuleFactory <TContentType, TConditionType>(contentSerializationProvider); MongoDbProviderRulesDataSource <TContentType, TConditionType> mongoDbProviderRulesDataSource = new MongoDbProviderRulesDataSource <TContentType, TConditionType>( mongoClient, mongoDbProviderSettings, ruleFactory); return(rulesDataSourceSelector.SetDataSource(mongoDbProviderRulesDataSource)); }
private static IRulesDataSource <TContentType, TConditionType> CreateRulesDataSourceTest <TContentType, TConditionType>( IMongoClient mongoClient, MongoDbProviderSettings mongoDbProviderSettings) { IContentSerializationProvider <TContentType> contentSerializationProvider = new DynamicToStrongTypeContentSerializationProvider <TContentType>(); IRuleFactory <TContentType, TConditionType> ruleFactory = new RuleFactory <TContentType, TConditionType>(contentSerializationProvider); return(new MongoDbProviderRulesDataSource <TContentType, TConditionType>( mongoClient, mongoDbProviderSettings, ruleFactory)); }
public void GetContentSerializer_GivenAnyContentTypeValue_ReturnsDynamicToStrongTypeContentSerializer() { // Arrange DynamicToStrongTypeContentSerializationProvider <ContentType> dynamicToStrongTypeContentSerializationProvider = new DynamicToStrongTypeContentSerializationProvider <ContentType>(); // Act IContentSerializer contentSerializer = dynamicToStrongTypeContentSerializationProvider.GetContentSerializer(ContentType.ContentTypeSample); // Assert contentSerializer.Should().NotBeNull() .And.BeOfType <DynamicToStrongTypeContentSerializer>(); }