public async Task CloudEventTableClient_CommitAsync_Test()
        {
            var tableName = GetTableName();

            var streamId = Guid.NewGuid();

            bool tran1, tran2;

            var client = new CloudEventTableClient(StorageAccount);

            client.Configuration.TableName = tableName;
            tran1 = await client.CommitAsync(
                new CloudEventLogPosition(0, 0),
                new[] {
                new CloudEventHeader(streamId, 1, 0, 2),
                new CloudEventHeader(streamId, 2, 0, 3)
            }
                );

            var client2 = new CloudEventTableClient(StorageAccount);

            client2.Configuration.TableName = tableName;
            tran2 = await client2.CommitAsync(
                new CloudEventLogPosition(0, 1),
                new[] {
                new CloudEventHeader(streamId, 1, 0, 2),
                new CloudEventHeader(streamId, 2, 0, 3)
            }
                );

            Assert.IsTrue(tran1);
            Assert.IsFalse(tran2);
        }
        public async Task CloudEventTableClient_GetLogSegmentedAsync_Test()
        {
            var tableName = GetTableName();

            var streamId = Guid.NewGuid();

            var client = new CloudEventTableClient(StorageAccount);

            client.Configuration.TableName = tableName;
            await client.CommitAsync(
                new CloudEventLogPosition(0, 0),
                new[] {
                new CloudEventHeader(streamId, 1, 0, 2),
                new CloudEventHeader(streamId, 2, 2, 3),
                new CloudEventHeader(streamId, 3, 5, 5),
                new CloudEventHeader(streamId, 4, 10, 7),
            }
                );

            var segment = await client.GetLogSegmentedAsync(new CloudEventLogPosition());

            Assert.AreEqual(0, segment.Results[0].Log);
            Assert.AreEqual(0, segment.Results[1].Log);
            Assert.AreEqual(0, segment.Results[2].Log);
            Assert.AreEqual(0, segment.Results[3].Log);

            Assert.AreEqual(0, segment.Results[0].Position);
            Assert.AreEqual(2, segment.Results[1].Position);
            Assert.AreEqual(5, segment.Results[2].Position);
            Assert.AreEqual(10, segment.Results[3].Position);
        }
        private CloudEventStore GetEventStoreClient()
        {
            var blobClient = new CloudEventBlobClient(StorageAccount)
            {
                Configuration = { ContainerName = GetContainerName() }
            };
            var tableClient = new CloudEventTableClient(StorageAccount)
            {
                Configuration = { TableName = GetTableName() }
            };

            return(new CloudEventStore(blobClient, tableClient));
        }
Exemplo n.º 4
0
        public CloudEventStore Create(string collectionName = "default")
        {
            if (StorageAccount == null)
            {
                throw new InvalidOperationException("storage account has not been set");
            }

            if (string.IsNullOrEmpty(collectionName))
            {
                throw new ArgumentException("collection name is null or empty", nameof(collectionName));
            }

            var blobClient = new CloudEventBlobClient(StorageAccount);

            blobClient.Configuration.ContainerName = "event-log" + "-" + collectionName;

            var tableClient = new CloudEventTableClient(StorageAccount);

            tableClient.Configuration.TableName = "EventStore" + char.ToUpperInvariant(collectionName[0]) + collectionName.Substring(1).ToLowerInvariant();

            var client = new CloudEventStore(blobClient, tableClient);

            return(client);
        }