Skip to content

Commit 007ff30

Browse files
committed
Remove redundant tests
1 parent 85d608b commit 007ff30

File tree

4 files changed

+15
-623
lines changed

4 files changed

+15
-623
lines changed

test/OpenApiClientTests/ResourceFieldValidation/NullableReferenceTypesOff/ModelStateValidationOff/CreateResourceTests.cs

Lines changed: 3 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -144,47 +144,7 @@ public async Task Cannot_omit_attribute(string attributePropertyName, string jso
144144
[Theory]
145145
[InlineData(nameof(ResourceRelationshipsInPostRequest.ToOne), "toOne")]
146146
[InlineData(nameof(ResourceRelationshipsInPostRequest.RequiredToOne), "requiredToOne")]
147-
public async Task Can_clear_relationship_with_partial_attribute_serialization(string relationshipPropertyName, string jsonPropertyName)
148-
{
149-
// Arrange
150-
var requestDocument = new ResourcePostRequestDocument
151-
{
152-
Data = new ResourceDataInPostRequest
153-
{
154-
Attributes = _fakers.PostAttributes.Generate(),
155-
Relationships = new ResourceRelationshipsInPostRequest
156-
{
157-
ToOne = _fakers.NullableToOne.Generate(),
158-
RequiredToOne = _fakers.NullableToOne.Generate(),
159-
ToMany = _fakers.ToMany.Generate(),
160-
RequiredToMany = _fakers.ToMany.Generate()
161-
}
162-
}
163-
};
164-
165-
SetDataPropertyToNull(requestDocument.Data.Relationships, relationshipPropertyName);
166-
167-
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
168-
var apiClient = new NrtOffMsvOffClient(wrapper.HttpClient);
169-
170-
using IDisposable _ = apiClient.WithPartialAttributeSerialization<ResourcePostRequestDocument, ResourceAttributesInPostRequest>(requestDocument);
171-
172-
// Act
173-
await ApiResponse.TranslateAsync(async () => await apiClient.PostResourceAsync(requestDocument));
174-
175-
// Assert
176-
JsonElement document = wrapper.GetRequestBodyAsJson();
177-
178-
document.Should().ContainPath($"data.relationships.{jsonPropertyName}.data").With(relationshipDataObject =>
179-
{
180-
relationshipDataObject.ValueKind.Should().Be(JsonValueKind.Null);
181-
});
182-
}
183-
184-
[Theory]
185-
[InlineData(nameof(ResourceRelationshipsInPostRequest.ToOne), "toOne")]
186-
[InlineData(nameof(ResourceRelationshipsInPostRequest.RequiredToOne), "requiredToOne")]
187-
public async Task Can_clear_relationship_without_partial_attribute_serialization(string relationshipPropertyName, string jsonPropertyName)
147+
public async Task Can_clear_relationship(string relationshipPropertyName, string jsonPropertyName)
188148
{
189149
// Arrange
190150
var requestDocument = new ResourcePostRequestDocument
@@ -222,7 +182,7 @@ public async Task Can_clear_relationship_without_partial_attribute_serialization
222182
[Theory]
223183
[InlineData(nameof(ResourceRelationshipsInPostRequest.ToMany), "toMany")]
224184
[InlineData(nameof(ResourceRelationshipsInPostRequest.RequiredToMany), "requiredToMany")]
225-
public async Task Cannot_clear_relationship_with_partial_attribute_serialization(string relationshipPropertyName, string jsonPropertyName)
185+
public async Task Cannot_clear_relationship(string relationshipPropertyName, string jsonPropertyName)
226186
{
227187
// Arrange
228188
var requestDocument = new ResourcePostRequestDocument
@@ -245,8 +205,6 @@ public async Task Cannot_clear_relationship_with_partial_attribute_serialization
245205
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
246206
var apiClient = new NrtOffMsvOffClient(wrapper.HttpClient);
247207

248-
using IDisposable _ = apiClient.WithPartialAttributeSerialization<ResourcePostRequestDocument, ResourceAttributesInPostRequest>(requestDocument);
249-
250208
// Act
251209
Func<Task<ResourcePrimaryResponseDocument?>> action = async () => await apiClient.PostResourceAsync(requestDocument);
252210

@@ -257,86 +215,10 @@ public async Task Cannot_clear_relationship_with_partial_attribute_serialization
257215
$"Cannot write a null value for property 'data'. Property requires a value. Path 'data.relationships.{jsonPropertyName}'.");
258216
}
259217

260-
[Theory]
261-
[InlineData(nameof(ResourceRelationshipsInPostRequest.ToMany), "toMany")]
262-
[InlineData(nameof(ResourceRelationshipsInPostRequest.RequiredToMany), "requiredToMany")]
263-
public async Task Cannot_clear_relationship_without_partial_attribute_serialization(string relationshipPropertyName, string jsonPropertyName)
264-
{
265-
// Arrange
266-
var requestDocument = new ResourcePostRequestDocument
267-
{
268-
Data = new ResourceDataInPostRequest
269-
{
270-
Attributes = _fakers.PostAttributes.Generate(),
271-
Relationships = new ResourceRelationshipsInPostRequest
272-
{
273-
ToOne = _fakers.NullableToOne.Generate(),
274-
RequiredToOne = _fakers.NullableToOne.Generate(),
275-
ToMany = _fakers.ToMany.Generate(),
276-
RequiredToMany = _fakers.ToMany.Generate()
277-
}
278-
}
279-
};
280-
281-
SetDataPropertyToNull(requestDocument.Data.Relationships, relationshipPropertyName);
282-
283-
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
284-
var apiClient = new NrtOffMsvOffClient(wrapper.HttpClient);
285-
286-
// Act
287-
Func<Task<ResourcePrimaryResponseDocument?>> action = async () => await apiClient.PostResourceAsync(requestDocument);
288-
289-
// Assert
290-
ExceptionAssertions<JsonSerializationException> assertion = await action.Should().ThrowExactlyAsync<JsonSerializationException>();
291-
292-
assertion.Which.Message.Should().Be(
293-
$"Cannot write a null value for property 'data'. Property requires a value. Path 'data.relationships.{jsonPropertyName}'.");
294-
}
295-
296-
[Theory]
297-
[InlineData(nameof(ResourceRelationshipsInPostRequest.ToOne), "toOne")]
298-
[InlineData(nameof(ResourceRelationshipsInPostRequest.ToMany), "toMany")]
299-
public async Task Can_omit_relationship_with_partial_attribute_serialization(string relationshipPropertyName, string jsonPropertyName)
300-
{
301-
// Arrange
302-
var requestDocument = new ResourcePostRequestDocument
303-
{
304-
Data = new ResourceDataInPostRequest
305-
{
306-
Attributes = _fakers.PostAttributes.Generate(),
307-
Relationships = new ResourceRelationshipsInPostRequest
308-
{
309-
ToOne = _fakers.NullableToOne.Generate(),
310-
RequiredToOne = _fakers.NullableToOne.Generate(),
311-
ToMany = _fakers.ToMany.Generate(),
312-
RequiredToMany = _fakers.ToMany.Generate()
313-
}
314-
}
315-
};
316-
317-
SetPropertyToInitialValue(requestDocument.Data.Relationships, relationshipPropertyName);
318-
319-
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
320-
var apiClient = new NrtOffMsvOffClient(wrapper.HttpClient);
321-
322-
using IDisposable _ = apiClient.WithPartialAttributeSerialization<ResourcePostRequestDocument, ResourceAttributesInPostRequest>(requestDocument);
323-
324-
// Act
325-
await ApiResponse.TranslateAsync(async () => await apiClient.PostResourceAsync(requestDocument));
326-
327-
// Assert
328-
JsonElement document = wrapper.GetRequestBodyAsJson();
329-
330-
document.Should().ContainPath("data.relationships").With(relationshipsObject =>
331-
{
332-
relationshipsObject.Should().NotContainPath(jsonPropertyName);
333-
});
334-
}
335-
336218
[Theory]
337219
[InlineData(nameof(ResourceRelationshipsInPostRequest.ToOne), "toOne")]
338220
[InlineData(nameof(ResourceRelationshipsInPostRequest.ToMany), "toMany")]
339-
public async Task Can_omit_relationship_without_partial_attribute_serialization(string relationshipPropertyName, string jsonPropertyName)
221+
public async Task Can_omit_relationship(string relationshipPropertyName, string jsonPropertyName)
340222
{
341223
// Arrange
342224
var requestDocument = new ResourcePostRequestDocument

test/OpenApiClientTests/ResourceFieldValidation/NullableReferenceTypesOff/ModelStateValidationOn/CreateResourceTests.cs

Lines changed: 4 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -181,46 +181,7 @@ public async Task Cannot_omit_attribute(string attributePropertyName, string jso
181181

182182
[Theory]
183183
[InlineData(nameof(ResourceRelationshipsInPostRequest.ToOne), "toOne")]
184-
public async Task Can_clear_relationship_with_partial_attribute_serialization(string relationshipPropertyName, string jsonPropertyName)
185-
{
186-
// Arrange
187-
var requestDocument = new ResourcePostRequestDocument
188-
{
189-
Data = new ResourceDataInPostRequest
190-
{
191-
Attributes = _fakers.PostAttributes.Generate(),
192-
Relationships = new ResourceRelationshipsInPostRequest
193-
{
194-
ToOne = _fakers.NullableToOne.Generate(),
195-
RequiredToOne = _fakers.ToOne.Generate(),
196-
ToMany = _fakers.ToMany.Generate(),
197-
RequiredToMany = _fakers.ToMany.Generate()
198-
}
199-
}
200-
};
201-
202-
SetDataPropertyToNull(requestDocument.Data.Relationships, relationshipPropertyName);
203-
204-
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
205-
var apiClient = new NrtOffMsvOnClient(wrapper.HttpClient);
206-
207-
using IDisposable _ = apiClient.WithPartialAttributeSerialization<ResourcePostRequestDocument, ResourceAttributesInPostRequest>(requestDocument);
208-
209-
// Act
210-
await ApiResponse.TranslateAsync(async () => await apiClient.PostResourceAsync(requestDocument));
211-
212-
// Assert
213-
JsonElement document = wrapper.GetRequestBodyAsJson();
214-
215-
document.Should().ContainPath($"data.relationships.{jsonPropertyName}.data").With(relationshipDataObject =>
216-
{
217-
relationshipDataObject.ValueKind.Should().Be(JsonValueKind.Null);
218-
});
219-
}
220-
221-
[Theory]
222-
[InlineData(nameof(ResourceRelationshipsInPostRequest.ToOne), "toOne")]
223-
public async Task Can_clear_relationship_without_partial_attribute_serialization(string relationshipPropertyName, string jsonPropertyName)
184+
public async Task Can_clear_relationship(string relationshipPropertyName, string jsonPropertyName)
224185
{
225186
// Arrange
226187
var requestDocument = new ResourcePostRequestDocument
@@ -259,46 +220,7 @@ public async Task Can_clear_relationship_without_partial_attribute_serialization
259220
[InlineData(nameof(ResourceRelationshipsInPostRequest.RequiredToOne), "requiredToOne")]
260221
[InlineData(nameof(ResourceRelationshipsInPostRequest.ToMany), "toMany")]
261222
[InlineData(nameof(ResourceRelationshipsInPostRequest.RequiredToMany), "requiredToMany")]
262-
public async Task Cannot_clear_relationship_with_partial_attribute_serialization(string relationshipPropertyName, string jsonPropertyName)
263-
{
264-
// Arrange
265-
var requestDocument = new ResourcePostRequestDocument
266-
{
267-
Data = new ResourceDataInPostRequest
268-
{
269-
Attributes = _fakers.PostAttributes.Generate(),
270-
Relationships = new ResourceRelationshipsInPostRequest
271-
{
272-
ToOne = _fakers.NullableToOne.Generate(),
273-
RequiredToOne = _fakers.ToOne.Generate(),
274-
ToMany = _fakers.ToMany.Generate(),
275-
RequiredToMany = _fakers.ToMany.Generate()
276-
}
277-
}
278-
};
279-
280-
SetDataPropertyToNull(requestDocument.Data.Relationships, relationshipPropertyName);
281-
282-
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
283-
var apiClient = new NrtOffMsvOnClient(wrapper.HttpClient);
284-
285-
using IDisposable _ = apiClient.WithPartialAttributeSerialization<ResourcePostRequestDocument, ResourceAttributesInPostRequest>(requestDocument);
286-
287-
// Act
288-
Func<Task<ResourcePrimaryResponseDocument?>> action = async () => await apiClient.PostResourceAsync(requestDocument);
289-
290-
// Assert
291-
ExceptionAssertions<JsonSerializationException> assertion = await action.Should().ThrowExactlyAsync<JsonSerializationException>();
292-
293-
assertion.Which.Message.Should().Be(
294-
$"Cannot write a null value for property 'data'. Property requires a value. Path 'data.relationships.{jsonPropertyName}'.");
295-
}
296-
297-
[Theory]
298-
[InlineData(nameof(ResourceRelationshipsInPostRequest.RequiredToOne), "requiredToOne")]
299-
[InlineData(nameof(ResourceRelationshipsInPostRequest.ToMany), "toMany")]
300-
[InlineData(nameof(ResourceRelationshipsInPostRequest.RequiredToMany), "requiredToMany")]
301-
public async Task Cannot_clear_relationship_without_partial_attribute_serialization(string relationshipPropertyName, string jsonPropertyName)
223+
public async Task Cannot_clear_relationship(string relationshipPropertyName, string jsonPropertyName)
302224
{
303225
// Arrange
304226
var requestDocument = new ResourcePostRequestDocument
@@ -335,48 +257,7 @@ public async Task Cannot_clear_relationship_without_partial_attribute_serializat
335257
[InlineData(nameof(ResourceRelationshipsInPostRequest.ToOne), "toOne")]
336258
[InlineData(nameof(ResourceRelationshipsInPostRequest.ToMany), "toMany")]
337259
[InlineData(nameof(ResourceRelationshipsInPostRequest.RequiredToMany), "requiredToMany")]
338-
public async Task Can_omit_relationship_with_partial_attribute_serialization(string relationshipPropertyName, string jsonPropertyName)
339-
{
340-
// Arrange
341-
var requestDocument = new ResourcePostRequestDocument
342-
{
343-
Data = new ResourceDataInPostRequest
344-
{
345-
Attributes = _fakers.PostAttributes.Generate(),
346-
Relationships = new ResourceRelationshipsInPostRequest
347-
{
348-
ToOne = _fakers.NullableToOne.Generate(),
349-
RequiredToOne = _fakers.ToOne.Generate(),
350-
ToMany = _fakers.ToMany.Generate(),
351-
RequiredToMany = _fakers.ToMany.Generate()
352-
}
353-
}
354-
};
355-
356-
SetPropertyToInitialValue(requestDocument.Data.Relationships, relationshipPropertyName);
357-
358-
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
359-
var apiClient = new NrtOffMsvOnClient(wrapper.HttpClient);
360-
361-
using IDisposable _ = apiClient.WithPartialAttributeSerialization<ResourcePostRequestDocument, ResourceAttributesInPostRequest>(requestDocument);
362-
363-
// Act
364-
await ApiResponse.TranslateAsync(async () => await apiClient.PostResourceAsync(requestDocument));
365-
366-
// Assert
367-
JsonElement document = wrapper.GetRequestBodyAsJson();
368-
369-
document.Should().ContainPath("data.relationships").With(relationshipsObject =>
370-
{
371-
relationshipsObject.Should().NotContainPath(jsonPropertyName);
372-
});
373-
}
374-
375-
[Theory]
376-
[InlineData(nameof(ResourceRelationshipsInPostRequest.ToOne), "toOne")]
377-
[InlineData(nameof(ResourceRelationshipsInPostRequest.ToMany), "toMany")]
378-
[InlineData(nameof(ResourceRelationshipsInPostRequest.RequiredToMany), "requiredToMany")]
379-
public async Task Can_omit_relationship_without_partial_attribute_serialization(string relationshipPropertyName, string jsonPropertyName)
260+
public async Task Can_omit_relationship(string relationshipPropertyName, string jsonPropertyName)
380261
{
381262
// Arrange
382263
var requestDocument = new ResourcePostRequestDocument
@@ -413,44 +294,7 @@ public async Task Can_omit_relationship_without_partial_attribute_serialization(
413294

414295
[Theory]
415296
[InlineData(nameof(ResourceRelationshipsInPostRequest.RequiredToOne), "requiredToOne")]
416-
public async Task Cannot_omit_relationship_with_partial_attribute_serialization(string relationshipPropertyName, string jsonPropertyName)
417-
{
418-
// Arrange
419-
var requestDocument = new ResourcePostRequestDocument
420-
{
421-
Data = new ResourceDataInPostRequest
422-
{
423-
Attributes = _fakers.PostAttributes.Generate(),
424-
Relationships = new ResourceRelationshipsInPostRequest
425-
{
426-
ToOne = _fakers.NullableToOne.Generate(),
427-
RequiredToOne = _fakers.ToOne.Generate(),
428-
ToMany = _fakers.ToMany.Generate(),
429-
RequiredToMany = _fakers.ToMany.Generate()
430-
}
431-
}
432-
};
433-
434-
SetPropertyToInitialValue(requestDocument.Data.Relationships, relationshipPropertyName);
435-
436-
using var wrapper = FakeHttpClientWrapper.Create(HttpStatusCode.NoContent, null);
437-
var apiClient = new NrtOffMsvOnClient(wrapper.HttpClient);
438-
439-
using IDisposable _ = apiClient.WithPartialAttributeSerialization<ResourcePostRequestDocument, ResourceAttributesInPostRequest>(requestDocument);
440-
441-
// Act
442-
Func<Task<ResourcePrimaryResponseDocument?>> action = async () => await apiClient.PostResourceAsync(requestDocument);
443-
444-
// Assert
445-
ExceptionAssertions<JsonSerializationException> assertion = await action.Should().ThrowExactlyAsync<JsonSerializationException>();
446-
447-
assertion.Which.Message.Should().Be(
448-
$"Cannot write a null value for property 'id'. Property requires a value. Path 'data.relationships.{jsonPropertyName}.data'.");
449-
}
450-
451-
[Theory]
452-
[InlineData(nameof(ResourceRelationshipsInPostRequest.RequiredToOne), "requiredToOne")]
453-
public async Task Cannot_omit_relationship_without_partial_attribute_serialization(string relationshipPropertyName, string jsonPropertyName)
297+
public async Task Cannot_omit_relationship(string relationshipPropertyName, string jsonPropertyName)
454298
{
455299
// Arrange
456300
var requestDocument = new ResourcePostRequestDocument

0 commit comments

Comments
 (0)