private IQbservable <Location> CreateStreamSource(bool shouldPluralizeStreamName = true) { contextOptions.ShouldPluralizeStreamName = shouldPluralizeStreamName; var context = new TestableDbProvider(contextOptions); return(context.CreateQueryStream <Location>()); }
private IQbservable <City> CreateQbservable() { var context = new TestableDbProvider(TestParameters.KsqlDBUrl); context.KSqlDbProviderMock.Setup(c => c.Run <int>(It.IsAny <object>(), It.IsAny <CancellationToken>())).Returns(GetTestValues); context.KSqlDbProviderMock.Setup(c => c.Run <long>(It.IsAny <object>(), It.IsAny <CancellationToken>())).Returns(GetDecimalTestValues); return(context.CreateQueryStream <City>()); }
public async Task DisposeAsync_ServiceProviderIsNull_ContextWasDisposed() { //Arrange var context = new TestableDbProvider <string>(TestParameters.KsqlDBUrl); //Act await context.DisposeAsync().ConfigureAwait(false); //Assert context.IsDisposed.Should().BeTrue(); }
public void CreateStreamSet_CalledMultipleTimes_KSqlQueryGeneratorBuildKSqlWasNotCalled() { //Arrange var context = new TestableDbProvider <string>(TestParameters.KsqlDBUrl); //Act var subscription = context.CreateQueryStream <string>().Subscribe(_ => {}); //Assert context.KSqlQueryGenerator.Verify(c => c.BuildKSql(It.IsAny <Expression>(), It.IsAny <QueryContext>()), Times.Once); }
public async Task NothingWasAdded_SaveChangesAsync_WasNotCalled() { //Arrange var context = new TestableDbProvider <string>(TestParameters.KsqlDBUrl); //Act var response = await context.SaveChangesAsync(); //Assert response.Should().BeNull(); }
public override void TestInitialize() { base.TestInitialize(); var httpClientFactory = Mock.Of <IHttpClientFactory>(); var httpClient = FakeHttpClient.CreateWithResponse(StatementResponse); Mock.Get(httpClientFactory).Setup(c => c.CreateClient()).Returns(() => httpClient); DbProvider = new TestableDbProvider(TestParameters.KsqlDBUrl, httpClientFactory); }
public void CreateStreamSet_Subscribe_KSqlDbProvidersRunWasCalled() { //Arrange var context = new TestableDbProvider <string>(TestParameters.KsqlDBUrl); //Act var streamSet = context.CreateQueryStream <string>().Subscribe(_ => {}); //Assert streamSet.Should().NotBeNull(); context.KSqlDbProviderMock.Verify(c => c.Run <string>(It.IsAny <object>(), It.IsAny <CancellationToken>()), Times.Once); }
public void AddWithInsertProperties() { //Arrange var context = new TestableDbProvider <string>(TestParameters.KsqlDBUrl); var entity = new Tweet(); var insertProperties = new InsertProperties(); //Act context.Add(entity, insertProperties); //Assert context.KSqlDbRestApiClientMock.Verify(c => c.ToInsertStatement(entity, insertProperties), Times.Once); }
public void SetAutoOffsetReset_Subscribe_ProcessingGuarantee() { //Arrange var contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl); contextOptions.SetAutoOffsetReset(AutoOffsetReset.Latest); var context = new TestableDbProvider <string>(contextOptions); //Act var subscription = context.CreateQueryStream <string>().Subscribe(_ => {}); //Assert context.KSqlDbProviderMock.Verify(c => c.Run <string>(It.Is <QueryStreamParameters>(c => c["auto.offset.reset"] == "latest"), It.IsAny <CancellationToken>()), Times.Once); }
public void CreateStreamSet_Subscribe_ProcessingGuarantee() { //Arrange var contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl); contextOptions.SetProcessingGuarantee(ProcessingGuarantee.ExactlyOnce); var context = new TestableDbProvider <string>(contextOptions); //Act var subscription = context.CreateQueryStream <string>().Subscribe(_ => {}); //Assert context.KSqlDbProviderMock.Verify(c => c.Run <string>(It.Is <QueryStreamParameters>(c => c[KSqlDbConfigs.ProcessingGuarantee] == "exactly_once"), It.IsAny <CancellationToken>()), Times.Once); }
public void CreateStreamSet_Subscribe_KSqlQueryGenerator() { //Arrange var contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl); contextOptions.QueryStreamParameters["auto.offset.reset"] = "latest"; var context = new TestableDbProvider <string>(contextOptions); //Act var subscription = context.CreateQueryStream <string>().Subscribe(_ => {}, e => {}); //Assert context.KSqlDbProviderMock.Verify(c => c.Run <string>(It.Is <QueryStreamParameters>(parameters => parameters["auto.offset.reset"] == "latest"), It.IsAny <CancellationToken>()), Times.Once); }
public void AddTwice_SaveChangesAsyncWasNotCalled() { //Arrange var context = new TestableDbProvider <string>(TestParameters.KsqlDBUrl); var entity = new Tweet(); context.KSqlDbRestApiClientMock.Setup(c => c.ToInsertStatement(entity, null)).Returns(new KSqlDbStatement("Insert Into")); //Act context.Add(entity); context.Add(entity); //Assert context.KSqlDbRestApiClientMock.Verify(c => c.ToInsertStatement(entity, null), Times.Exactly(2)); context.KSqlDbRestApiClientMock.Verify(c => c.ExecuteStatementAsync(It.IsAny <KSqlDbStatement>(), It.IsAny <CancellationToken>()), Times.Never); }
public async Task AddAndSaveChangesAsync() { //Arrange var context = new TestableDbProvider <string>(TestParameters.KsqlDBUrl); var entity = new Tweet(); context.KSqlDbRestApiClientMock.Setup(c => c.ToInsertStatement(entity, null)).Returns(new KSqlDbStatement("Insert Into")); //Act context.Add(entity); await context.SaveChangesAsync(); //Assert context.KSqlDbRestApiClientMock.Verify(c => c.ToInsertStatement(entity, null), Times.Once); context.KSqlDbRestApiClientMock.Verify(c => c.ExecuteStatementAsync(It.IsAny <KSqlDbStatement>(), It.IsAny <CancellationToken>()), Times.Once); }
public void CreateQuery_RawKSQL_ReturnAsyncEnumerable() { //Arrange string ksql = "SELECT * FROM tweetsTest EMIT CHANGES LIMIT 2;"; QueryParameters queryParameters = new QueryParameters { Sql = ksql, [QueryParameters.AutoOffsetResetPropertyName] = "earliest", }; var context = new TestableDbProvider <string>(TestParameters.KsqlDBUrl); //Act var source = context.CreateQuery <string>(queryParameters); //Assert source.Should().NotBeNull(); }
public void WithOffsetResetPolicy_Subscribe_QueryOptionsWereTakenFromContext() { //Arrange var contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl); var context = new TestableDbProvider <string>(contextOptions) { RegisterKSqlQueryGenerator = false }; //Act var subscription = context.CreateQueryStream <string>().WithOffsetResetPolicy(AutoOffsetReset.Latest).Subscribe(_ => {}); //Assert // context.KSqldbProviderMock.Verify(c => c.Run<string>(It.Is<IQueryParameters>(c => c["auto.offset.reset"] == "latest"), It.IsAny<CancellationToken>()), Times.Once); context.KSqlDbProviderMock.Verify(c => c.Run <string>(It.Is <QueryStreamParameters>(c => c.AutoOffsetReset == AutoOffsetReset.Latest), It.IsAny <CancellationToken>()), Times.Once); subscription.Dispose(); }
public void GroupByCompoundKey_BuildKSql_PrintsQuery() { //Arrange var context = new TestableDbProvider(TestParameters.KsqlDBUrl); //https://kafka-tutorials.confluent.io/finding-distinct-events/ksql.html var grouping = context.CreateQueryStream <Click>() .GroupBy(c => new { c.IP_ADDRESS, c.URL, c.TIMESTAMP }) .WindowedBy(new TimeWindows(Duration.OfMinutes(2))) .Having(c => c.Count(g => c.Key.IP_ADDRESS) == 1) .Select(g => new { g.Key.IP_ADDRESS, g.Key.URL, g.Key.TIMESTAMP }) .Take(3); //Act var ksql = grouping.ToQueryString(); //Assert string expectedKSql = @"SELECT IP_ADDRESS, URL, TIMESTAMP FROM Clicks WINDOW TUMBLING (SIZE 2 MINUTES) GROUP BY IP_ADDRESS, URL, TIMESTAMP HAVING COUNT(IP_ADDRESS) = 1 EMIT CHANGES LIMIT 3;"; ksql.Should().BeEquivalentTo(expectedKSql); }
public void CreateStreamSet_Subscribe_QueryOptionsWereTakenFromContext() { //Arrange var contextOptions = new KSqlDBContextOptions(TestParameters.KsqlDBUrl) { QueryStreamParameters = { ["auto.offset.reset"] = "latest" } }; var context = new TestableDbProvider <string>(contextOptions); //Act var subscription = context.CreateQueryStream <string>().Subscribe(_ => {}); //Assert context.KSqlDbProviderMock.Verify(c => c.Run <string>(It.Is <QueryStreamParameters>(c => c["auto.offset.reset"] == "latest"), It.IsAny <CancellationToken>()), Times.Once); subscription.Dispose(); }
private IQbservable <Tweet> CreateTweetsStreamSource() { var context = new TestableDbProvider(contextOptions); return(context.CreateQueryStream <Tweet>()); }
public override void TestInitialize() { base.TestInitialize(); DbProvider = new TestableDbProvider(TestParameters.KsqlDBUrl, PullQueryResponse); }