Skip to content

Commit

Permalink
chore: Fixed some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
svrooij committed Dec 7, 2023
1 parent dd95f14 commit db8bc65
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion tests/Sonos.Base.Tests/Soap/SoapFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ public class SoapFactoryTests
</s:Body>
</s:Envelope>";

private const string xmlInputNextRequestNoIndentation = @"<?xml version=""1.0"" encoding=""utf-8""?><s:Envelope s:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/""><s:Body><u:Next xmlns:u=""urn:schemas-upnp-org:service:AVTransport:1""><InstanceID>0</InstanceID></u:Next></s:Body></s:Envelope>";

[Fact]
public void GeneratesXmlStream_AvTransportNextRequest_GeneratesExpectedXml()
{
using var stream = SoapFactory.GenerateXmlStream(nameof(Services.SonosService.AVTransport), "Next", new Services.AVTransportService.NextRequest());
using var reader = new StreamReader(stream);
var xml = reader.ReadToEnd();

Assert.Equal(xmlInputNextRequest, xml);
Assert.Equal(xmlInputNextRequestNoIndentation, xml);
}

[Fact]
Expand Down
1 change: 1 addition & 0 deletions tests/Sonos.Base.Tests/Sonos.Base.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="Xunit.DependencyInjection" Version="8.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
11 changes: 8 additions & 3 deletions tests/Sonos.Base.Tests/TestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ internal static bool VerifySonosRequest(this HttpRequestMessage message, string
bool bodyChecked = false;
if (requestBody != null)
{
var streamContent = message.Content as StreamContent;
var streamContent = message.Content as StringContent;

if (streamContent != null)
{
var content = streamContent.ReadAsStringAsync().GetAwaiter().GetResult();
var expectedContent = string.Format(SoapRequestFormat, service, action, requestBody);
var content = streamContent.ReadAsStringAsync().GetAwaiter().GetResult().RemoveXmlIndentation() ;
var expectedContent = string.Format(SoapRequestFormat, service, action, requestBody).RemoveXmlIndentation();
#if DEBUG
Assert.Equal(expectedContent, content);
#endif
Expand Down Expand Up @@ -190,5 +190,10 @@ internal static IServiceCollection AddMockedHttpClient(this IServiceCollection s
return services;
}

internal static string RemoveXmlIndentation(this string xml)
{
return string.Concat(xml.Split("\r\n").Select(l => l.Trim()));
}

}
}

0 comments on commit db8bc65

Please sign in to comment.