public async Task WithChildPopulationTest() { PostAnalyzer analyzer = new PostAnalyzer(); analyzer.ServiceName = "PostsService"; FluentOlapConfiguration.ServiceDefinitions = new ServiceDefinitions { ["PostsService"] = new HttpService("https://jsonplaceholder.typicode.com/posts/{PostId}"), ["UsersService"] = new HttpService("https://jsonplaceholder.typicode.com/users/{userId}"), }; analyzer.Property(p => p.userId).GetFromService("UsersService", new AnalyticalObject <User>()); PopulationResult rs = await analyzer.PopulateAsync(new HttpServiceOptions { Parameters = new { PostId = 1 } } ); foreach (string key in analyzer.TypeMap.Keys) { // -1 because of the "DoesNotExist" property. Assert.IsTrue(rs.Keys.Count() >= analyzer.TypeMap.Count() - 1); } }
public async Task WithMissingChildPopulationTest() { PostAnalyzer analyzer = new PostAnalyzer(); analyzer.ServiceName = "PostsService"; FluentOlapConfiguration.ServiceDefinitions = new ServiceDefinitions { ["PostsService"] = new HttpService("https://jsonplaceholder.typicode.com/posts/{PostId}"), ["UsersService"] = new HttpService("https://jsonplaceholder.typicode.com/users/{userId}"), }; analyzer.Property(p => p.userId).GetFromService("UsersService", new AnalyticalObject <User>()); PopulationResult rs = await analyzer.PopulateAsync(new HttpServiceOptions { Parameters = new { PostId = 0 } } ); Assert.IsTrue(!rs.Keys.Any()); }
public async Task ShadowPropertyInsertionTest() { MySqlConnection connection = new MySqlConnection(config.GetConnectionString("TestConnection")); await connection.RunCommandAsync("DROP TABLE IF EXISTS Post"); await connection.RunCommandAsync("DROP TABLE IF EXISTS AnalyzedModelHashes"); FluentOlapConfiguration.ServiceDefinitions = new ServiceDefinitions { ["PostsService"] = new HttpService("https://jsonplaceholder.typicode.com/posts/{PostId}"), ["ArbitraryUserService"] = new HttpService("https://jsonplaceholder.typicode.com/users/1"), }; PostAnalyzer analyzer = new PostAnalyzer(); analyzer.GetFromService("PostsService"); analyzer.Property("arbitaryUser", new AnalyticalObject <User>()) .GetFromService("ArbitraryUserService", new AnalyticalObject <User>()); PopulationResult result = await analyzer.PopulateAsync(new HttpServiceOptions { Parameters = new { PostId = 1 } }); DataIngester ingester = new DataIngester(new MariaDbProvider(MariaDbTableEngine.InnoDB, new Dictionary <InternalType, string>() { [InternalType.STRING] = "TEXT", [InternalType.INTEGER] = "BIGINT", [InternalType.FLOAT] = "FLOAT", [InternalType.BOOLEAN] = "BOOLEAN", [InternalType.DATETIME] = "DATETIME" })); await ingester.Insert(result, connection); string username = await connection.RunCommandGetString("select * from Post", "user_username"); Assert.AreEqual(username, "Bret"); await connection.RunCommandAsync("DROP TABLE Post"); await connection.RunCommandAsync("DROP TABLE AnalyzedModelHashes"); }
public async Task BasicPopulationTest() { FluentOlapConfiguration.ServiceDefinitions = new ServiceDefinitions { ["PostsService"] = new HttpService("https://jsonplaceholder.typicode.com/posts/{PostId}") }; PostAnalyzer analyzer = new PostAnalyzer(); analyzer.ServiceName = "PostsService"; PopulationResult rs = await analyzer.PopulateAsync(new HttpServiceOptions { Parameters = new { PostId = 1 } } ); foreach (string key in rs.Keys) { Assert.IsTrue(analyzer.TypeMap.Keys.Count >= rs.Keys.Count()); } }
public async Task ChangingSchemaTest() { MySqlConnection connection = new MySqlConnection(config.GetConnectionString("TestConnection")); await connection.RunCommandAsync("DROP TABLE IF EXISTS Post"); await connection.RunCommandAsync("DROP TABLE IF EXISTS AnalyzedModelHashes"); FluentOlapConfiguration.ServiceDefinitions = new ServiceDefinitions { ["PostsService"] = new HttpService("https://jsonplaceholder.typicode.com/posts/{PostId}"), ["UsersService"] = new HttpService("https://jsonplaceholder.typicode.com/users/{userId}"), }; PostAnalyzer analyzer = new PostAnalyzer(); analyzer.GetFromService("PostsService"); analyzer.Property(p => p.userId).GetFromService("UsersService", new AnalyticalObject <User>()); analyzer.Remove(p => p.Body); PopulationResult result = await analyzer.PopulateAsync(new HttpServiceOptions { Parameters = new { PostId = 1 } }); DataIngester ingester = new DataIngester(new MariaDbProvider(MariaDbTableEngine.InnoDB, new Dictionary <InternalType, string>() { [InternalType.STRING] = "TEXT", [InternalType.INTEGER] = "BIGINT", [InternalType.FLOAT] = "FLOAT", [InternalType.BOOLEAN] = "BOOLEAN", [InternalType.DATETIME] = "DATETIME" })); await ingester.Insert(result, connection); string username = await connection.RunCommandGetString("select * from Post", "user_username"); Assert.AreEqual(username, "Bret"); analyzer.Property(p => p.Body); PopulationResult result2 = await analyzer.PopulateAsync(new HttpServiceOptions { Parameters = new { PostId = 1 } }); await ingester.Insert(result2, connection); string body = await connection.RunCommandGetString("select * from Post where Id=2", "post_body"); string bodyFromApi = "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"; Assert.AreEqual(body, bodyFromApi); await connection.RunCommandAsync("DROP TABLE Post"); await connection.RunCommandAsync("DROP TABLE AnalyzedModelHashes"); }