Skip to content

Commit

Permalink
Change test to make it use the real Service
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-mrq authored and kbeaugrand committed Apr 16, 2024
1 parent 8778957 commit 4756237
Showing 1 changed file with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,44 @@ public async Task ExecuteLoRaDeviceMessageMustBeSuccessfullWhenParametersAreProv
}

[Test]
public void ExecuteLoRaDeviceMessageMustBeSuccessfullWhenParametersAndCommandAreProvided()
public async Task ExecuteLoRaDeviceMessageMustBeSuccessfullWhenParametersAndCommandAreProvided()
{
var command = "0113007801680100640064";
// Arrange
var deviceId = Fixture.Create<string>();

// Convert the hex frame to a byte array
var hexFrame = Enumerable.Range(0, command.Length / 2)
.Select(x => Convert.ToByte(command.Substring(x * 2, 2), 16))
.ToArray();
var commandHex = "0113007801680100640064";

var command = new DeviceModelCommandDto
{
Frame = commandHex,
Confirmed = Fixture.Create<bool>(),
Port = Fixture.Create<int>()
};

var expectedRawPayload = "ARMAeAFoAQBkAGQ=";

_ = MockHttpClient.When(HttpMethod.Post, $"/api/cloudtodevicemessage/{deviceId}")
.With(m =>
{
_ = m.Content.Should().BeAssignableTo<JsonContent>();
var body = (JsonContent) m.Content;
var loRaCloudToDeviceMessage = (LoRaCloudToDeviceMessage)body?.Value;
_ = loRaCloudToDeviceMessage?.Should().NotBeNull();
_ = loRaCloudToDeviceMessage?.Fport.Should().Be(command.Port);
_ = loRaCloudToDeviceMessage?.Confirmed.Should().Be(command.Confirmed);
_ = loRaCloudToDeviceMessage?.RawPayload.Should().Be(expectedRawPayload);
return true;
})
.Respond(HttpStatusCode.Created);

// Convert the byte array to a base64 string
var rawPayload = Convert.ToBase64String(hexFrame);
// Act
var result = await this.loRaWanManagementService.ExecuteLoRaDeviceMessage(deviceId, command);

Assert.AreEqual("ARMAeAFoAQBkAGQ=", rawPayload);
// Assert
_ = result.Should().NotBeNull();
_ = result.IsSuccessStatusCode.Should().BeTrue();
MockHttpClient.VerifyNoOutstandingRequest();
MockHttpClient.VerifyNoOutstandingExpectation();
}

[TestCase("CN_470_510_RP1")]
Expand Down

0 comments on commit 4756237

Please sign in to comment.