Exemple #1
0
    public async Task ReceiveArrayWithComplexElements()
    {
        //Arrange
        var httpResponseMessage = await restApiClient.ExecuteStatementAsync(new KSqlDbStatement(@"
Drop type EventCategory;
Drop table Events;
"));

        //Act
        httpResponseMessage = await restApiClient.CreateTypeAsync <EventCategory>();

        httpResponseMessage = await restApiClient.CreateTableAsync <Event>(new EntityCreationMetadata()
        {
            KafkaTopic = "Events", Partitions = 1
        });

        var eventCategory = new EventCategory()
        {
            Name = "xyz"
        };

        var testEvent = new Event
        {
            Id         = 1,
            Places     = new[] { "Place1", "Place2" },
            Categories = new[] { eventCategory, new EventCategory {
                                     Name = "puk"
                                 } }
        };

        var semaphoreSlim = new SemaphoreSlim(0, 1);

        var receivedValues = new List <Event>();
        var subscription   = Context.CreateQueryStream <Event>().Take(1)
                             .Subscribe(value =>
        {
            receivedValues.Add(value);
        }, error =>
        {
            semaphoreSlim.Release();
        },
                                        () =>
        {
            semaphoreSlim.Release();
        });

        httpResponseMessage = await restApiClient.InsertIntoAsync(testEvent);

        string responseContent = await httpResponseMessage.Content.ReadAsStringAsync();

        //Assert
        await semaphoreSlim.WaitAsync(TimeSpan.FromSeconds(5));

        receivedValues.Count.Should().Be(1);
        receivedValues[0].Places.Length.Should().Be(2);
        receivedValues[0].Categories.ToArray()[0].Name.Should().Be("xyz");
        receivedValues[0].Categories.ToArray()[1].Name.Should().Be("puk");

        using (subscription) { }
    }
Exemple #2
0
    public async Task CreateTable()
    {
        //Arrange
        var metadata = GetEntityCreationMetadata(nameof(MyMoviesTable));

        //Act
        var httpResponseMessage = await restApiClient.CreateTableAsync <MyMoviesTable>(metadata, ifNotExists : true);

        //Assert
        httpResponseMessage.StatusCode.Should().Be(HttpStatusCode.OK);

        string responseContent = await httpResponseMessage.Content.ReadAsStringAsync();

        var responseObject = JsonSerializer.Deserialize <StatementResponse[]>(responseContent);
    }