|
1 | | -using System; |
| 1 | +// Copyright (c) Microsoft. All rights reserved. |
| 2 | +// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
2 | 6 | using System.Threading; |
3 | 7 | using System.Threading.Tasks; |
| 8 | +using FluentAssertions; |
4 | 9 | using Microsoft.VisualStudio.TestTools.UnitTesting; |
5 | 10 | using NSubstitute; |
6 | 11 |
|
@@ -352,5 +357,33 @@ public void ModuleClient_InvokeMethodAsyncWithoutBodyShouldNotThrow() |
352 | 357 | // act |
353 | 358 | _ = new MethodInvokeRequest(request.Name, request.DataAsJson, request.ResponseTimeout, request.ConnectionTimeout); |
354 | 359 | } |
| 360 | + |
| 361 | + [TestMethod] |
| 362 | + public async Task SendEventBatchToOutputSetOutputNameIfNotSet() |
| 363 | + { |
| 364 | + // arrange |
| 365 | + var moduleClient = ModuleClient.CreateFromConnectionString(FakeConnectionString, TransportType.Mqtt_Tcp_Only); |
| 366 | + |
| 367 | + var innerHandler = Substitute.For<IDelegatingHandler>(); |
| 368 | + innerHandler.SendEventAsync(Arg.Any<Message>(), Arg.Any<CancellationToken>()).Returns(Task.FromResult(0)); |
| 369 | + moduleClient.InnerHandler = innerHandler; |
| 370 | + |
| 371 | + // act |
| 372 | + var messageWithoutOutputName = new Message(); |
| 373 | + var messageWithOutputName = new Message(); |
| 374 | + |
| 375 | + messageWithOutputName.SystemProperties.Remove(MessageSystemPropertyNames.OutputName); |
| 376 | + string initialOutputName = "someInitialOutputName"; |
| 377 | + messageWithOutputName.SystemProperties.Add(MessageSystemPropertyNames.OutputName, initialOutputName); |
| 378 | + |
| 379 | + string newOutputName = "someNewOutputName"; |
| 380 | + await moduleClient.SendEventBatchAsync(newOutputName, new List<Message> { messageWithoutOutputName, messageWithOutputName }).ConfigureAwait(false); |
| 381 | + |
| 382 | + // assert |
| 383 | + messageWithoutOutputName.SystemProperties.Keys.Should().Contain(MessageSystemPropertyNames.OutputName); |
| 384 | + messageWithoutOutputName.SystemProperties[MessageSystemPropertyNames.OutputName].Should().Equals(newOutputName); |
| 385 | + messageWithOutputName.SystemProperties.Keys.Should().Contain(MessageSystemPropertyNames.OutputName); |
| 386 | + messageWithOutputName.SystemProperties[MessageSystemPropertyNames.OutputName].Should().Equals(newOutputName); |
| 387 | + } |
355 | 388 | } |
356 | 389 | } |
0 commit comments