Skip to content

Commit 2b50ada

Browse files
author
Alexander van Delft
committed
Always support MessagePack deserialization as a DefaultRequestHeader and fix unit tests accordingly
1 parent 34d3816 commit 2b50ada

File tree

3 files changed

+10
-38
lines changed

3 files changed

+10
-38
lines changed

CDP4ServicesDal.NetCore.Tests/CdpServicesDalTestFixture.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,11 @@ public void VerifyThatDalThatIsNotOpenCannotBeClosed()
255255
Assert.Throws<InvalidOperationException>(() => this.dal.Close());
256256
}
257257

258-
[TestCase(true)]
259-
[TestCase(false)]
258+
[Test]
260259
[Category("WebServicesDependent")]
261-
public async Task VerifyThatReadReturnsCorrectDTO(bool isMessagePackSupported)
260+
public async Task VerifyThatReadReturnsCorrectDTO()
262261
{
263-
this.dal = new CdpServicesDal(isMessagePackSupported);
262+
this.dal = new CdpServicesDal();
264263

265264
var returned = (await this.dal.Open(this.credentials, this.cancelationTokenSource.Token)).ToList();
266265
Assert.That(returned, Is.Not.Null);

CDP4ServicesDal.Tests/CdpServicesDalTestFixture.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,11 @@ public void VerifyThatDalThatIsNotOpenCannotBeClosed()
232232
Assert.Throws<InvalidOperationException>(() => this.dal.Close());
233233
}
234234

235-
[TestCase(true)]
236-
[TestCase(false)]
235+
[Test]
237236
[Category("WebServicesDependent")]
238-
public async Task VerifyThatReadReturnsCorrectDTO(bool isMessagePackSupported)
237+
public async Task VerifyThatReadReturnsCorrectDTO()
239238
{
240-
this.dal = new CdpServicesDal(isMessagePackSupported);
239+
this.dal = new CdpServicesDal();
241240

242241
var returned = (await this.dal.Open(this.credentials, this.cancelationTokenSource.Token)).ToList();
243242
Assert.That(returned, Is.Not.Null);

CDP4ServicesDal/CdpServicesDal.cs

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,13 @@ public class CdpServicesDal : Dal
8989
/// </summary>
9090
private HttpClient httpClient;
9191

92-
/// <summary>
93-
/// Asserts that the MessagePack deserialization should be used or not
94-
/// </summary>
95-
private readonly bool isMessagePackSupported;
96-
97-
/// <summary>
98-
/// Initializes a new instance of the <see cref="CdpServicesDal"/> class.
99-
/// </summary>
100-
public CdpServicesDal(): this(true)
101-
{
102-
// Default constructor
103-
}
104-
10592
/// <summary>
10693
/// Initializes a new instance of the <see cref="CdpServicesDal"/> class.
10794
/// </summary>
108-
/// <param name="isMessagePackSupported">Asserts that the MessagePack deserialization should be used or not. Supported by default</param>
109-
public CdpServicesDal(bool isMessagePackSupported)
95+
public CdpServicesDal()
11096
{
11197
this.Cdp4DalJsonSerializer = new Cdp4DalJsonSerializer(this.MetaDataProvider, this.DalVersion, false);
11298
this.MessagePackSerializer = new MessagePackSerializer();
113-
114-
this.isMessagePackSupported = isMessagePackSupported;
11599
}
116100

117101
/// <summary>
@@ -120,15 +104,9 @@ public CdpServicesDal(bool isMessagePackSupported)
120104
/// <param name="httpClient">
121105
/// The (injected) <see cref="HttpClient"/>
122106
/// </param>
123-
/// <param name="isMessagePackSupported">Asserts that the MessagePack deserialization should be used or not. Supported by default</param>
124-
public CdpServicesDal(HttpClient httpClient, bool isMessagePackSupported = true) : this(isMessagePackSupported)
107+
public CdpServicesDal(HttpClient httpClient) : this()
125108
{
126-
if (httpClient == null)
127-
{
128-
throw new ArgumentNullException(nameof(httpClient));
129-
}
130-
131-
this.httpClient = httpClient;
109+
this.httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
132110
}
133111

134112
/// <summary>
@@ -1106,11 +1084,7 @@ private HttpClient CreateHttpClient(Credentials credentials, HttpClient injected
11061084
result.BaseAddress = credentials.Uri;
11071085
result.DefaultRequestHeaders.Accept.Clear();
11081086
result.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
1109-
1110-
if (this.isMessagePackSupported)
1111-
{
1112-
result.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/msgpack"));
1113-
}
1087+
result.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/msgpack"));
11141088

11151089
result.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes($"{credentials.UserName}:{credentials.Password}")));
11161090
result.DefaultRequestHeaders.Add(Headers.AcceptCdpVersion, Headers.AcceptCdpVersionValue);

0 commit comments

Comments
 (0)