public async Task SendAsyncTransformsSimpleEvents() { var sourceEvents = new[] { new EventData(Encoding.UTF8.GetBytes("FirstValue")), new EventData(Encoding.UTF8.GetBytes("Second")), new EventData(new byte[] { 0x11, 0x22, 0x33 }) }; var options = new EventBatchingOptions(); var mock = new ObservableSenderMock(new ClientMock(), null); var sender = new TrackOneEventSender(() => mock); await sender.SendAsync(sourceEvents, options, CancellationToken.None); Assert.That(mock.SendCalledWithParameters, Is.Not.Null, "The Send request should have been delegated."); var sentEvents = mock.SendCalledWithParameters.Events.ToArray(); Assert.That(sentEvents.Length, Is.EqualTo(sourceEvents.Length), "The number of events sent should match the number of source events."); // The events should not only be structurally equivilent, the ordering of them should be preserved. Compare the // sequence in order and validate that the events in each position are equivilent. for (var index = 0; index < sentEvents.Length; ++index) { Assert.That(TrackOneComparer.IsEventDataEquivalent(sentEvents[index], sourceEvents[index]), Is.True, $"The sequence of events sent should match; they differ at index: { index }"); } }
public async Task SenderIsConstructedCorrectly() { var partition = "123"; var mock = new ObservableSenderMock(new ClientMock(), partition); var sender = new TrackOneEventSender(() => mock); // Invoke an operation to force the sender to be lazily instantiated. Otherwise, // construction does not happen. await sender.SendAsync(new[] { new EventData(new byte[] { 0x12, 0x22 }) }, new EventBatchingOptions(), default); Assert.That(mock.ConstructedWithPartition, Is.EqualTo(partition)); }
public async Task SendAsyncForwardsThePartitionHashKey(string expectedHashKey) { var options = new EventBatchingOptions { PartitionKey = expectedHashKey }; var mock = new ObservableSenderMock(new ClientMock(), null); var sender = new TrackOneEventSender(() => mock); await sender.SendAsync(new[] { new EventData(new byte[] { 0x43 }) }, options, CancellationToken.None); Assert.That(mock.SendCalledWithParameters, Is.Not.Null, "The Send request should have been delegated."); (_, var actualHashKey) = mock.SendCalledWithParameters; Assert.That(actualHashKey, Is.EqualTo(expectedHashKey), "The partition hash key should have been forwarded."); }
public async Task CloseAsyncDoesNotDelegateIfTheSenderWasNotCreated() { var mock = new ObservableSenderMock(new ClientMock(), null); var sender = new TrackOneEventSender(() => mock); await sender.CloseAsync(default);