Skip to content

Commit b8c5acc

Browse files
Refactor code to remove nullable types and ensure required properties are accessed directly
1 parent 457c2ba commit b8c5acc

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

src/Examples/OpenApiNSwagClientExample/PeopleMessageFormatter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ private static string WritePeople(ApiResponse<PersonCollectionResponseDocument?>
3636

3737
private static void WritePerson(DataInPersonResponse person, ICollection<ResourceInResponse> includes, StringBuilder builder)
3838
{
39-
ICollection<TodoItemIdentifierInResponse> assignedTodoItems = person.Relationships?.AssignedTodoItems?.Data ?? [];
39+
ICollection<TodoItemIdentifierInResponse> assignedTodoItems = person.Relationships.AssignedTodoItems?.Data ?? [];
4040

41-
builder.AppendLine($" Person {person.Id}: {person.Attributes?.DisplayName} with {assignedTodoItems.Count} assigned todo-items:");
41+
builder.AppendLine($" Person {person.Id}: {person.Attributes.DisplayName} with {assignedTodoItems.Count} assigned todo-items:");
4242
WriteRelatedTodoItems(assignedTodoItems, includes, builder);
4343
}
4444

@@ -48,9 +48,9 @@ private static void WriteRelatedTodoItems(IEnumerable<TodoItemIdentifierInRespon
4848
foreach (TodoItemIdentifierInResponse todoItemIdentifier in todoItemIdentifiers)
4949
{
5050
DataInTodoItemResponse includedTodoItem = includes.OfType<DataInTodoItemResponse>().Single(include => include.Id == todoItemIdentifier.Id);
51-
ICollection<TagIdentifierInResponse> tags = includedTodoItem.Relationships?.Tags?.Data ?? [];
51+
ICollection<TagIdentifierInResponse> tags = includedTodoItem.Relationships.Tags?.Data ?? [];
5252

53-
builder.AppendLine($" TodoItem {includedTodoItem.Id}: {includedTodoItem.Attributes?.Description} with {tags.Count} tags:");
53+
builder.AppendLine($" TodoItem {includedTodoItem.Id}: {includedTodoItem.Attributes.Description} with {tags.Count} tags:");
5454
WriteRelatedTags(tags, includes, builder);
5555
}
5656
}
@@ -60,7 +60,7 @@ private static void WriteRelatedTags(IEnumerable<TagIdentifierInResponse> tagIde
6060
foreach (TagIdentifierInResponse tagIdentifier in tagIdentifiers)
6161
{
6262
DataInTagResponse includedTag = includes.OfType<DataInTagResponse>().Single(include => include.Id == tagIdentifier.Id);
63-
builder.AppendLine($" Tag {includedTag.Id}: {includedTag.Attributes?.Name}");
63+
builder.AppendLine($" Tag {includedTag.Id}: {includedTag.Attributes.Name}");
6464
}
6565
}
6666
}

src/Examples/OpenApiNSwagClientExample/Worker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private async Task SendOperationsRequestAsync(CancellationToken cancellationToke
165165

166166
ApiResponse<OperationsResponseDocument> operationsResponse = await _apiClient.PostOperationsAsync(operationsRequest, cancellationToken);
167167

168-
var newTodoItem = (DataInTodoItemResponse)operationsResponse.Result.Atomic_results.ElementAt(3).Data!;
169-
Console.WriteLine($"Created todo-item with ID {newTodoItem.Id}: {newTodoItem.Attributes!.Description}.");
168+
var newTodoItem = (DataInTodoItemResponse)operationsResponse.Result.Atomic_results.ElementAt(3).Data;
169+
Console.WriteLine($"Created todo-item with ID {newTodoItem.Id}: {newTodoItem.Attributes.Description}.");
170170
}
171171
}

test/OpenApiTests/AtomicOperations/OperationsFakers.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,18 @@ public OperationsFakers(IServiceProvider serviceProvider)
4545
.MakeDeterministic()
4646
.CustomInstantiator(faker =>
4747
{
48-
var dbContext = ResolveDbContext(serviceProvider);
48+
OperationsDbContext dbContext = ResolveDbContext(serviceProvider);
49+
4950
return new Enrollment(dbContext)
5051
{
51-
Student = new Student { Name = faker.Name.FullName() },
52-
Course = new Course { Subject = faker.Commerce.Department() },
52+
Student = new Student
53+
{
54+
Name = faker.Name.FullName()
55+
},
56+
Course = new Course
57+
{
58+
Subject = faker.Commerce.Department()
59+
},
5360
EnrolledAt = faker.Date.PastDateOnly(),
5461
GraduatedAt = faker.Date.RecentDateOnly()
5562
};

0 commit comments

Comments
 (0)