-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to generate public/internal setters for generated models for Testing scenarios #4392
Comments
Hi @NikiforovAll |
Thank you @baywet , As shown in the exemplary test, I want to mock IRequestAdapter so I need to create an instance of a class. Unfortunately, [Fact]
public async Task TrendingTopic_GetUS_SuccessAsync()
{
// Arrange
var adapter = Substitute.For<IRequestAdapter>();
adapter.SetupSendAsyncWithResponse(new TrendingTopics() { Value = [] });
var newsSearchApiClient = new NewsSearchApiClient(adapter);
// Act
var response = await newsSearchApiClient
.News
.Trendingtopics
.GetAsync(r => r.QueryParameters.Cc = "US");
// Assert
Assert.NotNull(response);
} I'm not sure if I understand how to properly mock Models in this case. |
I'd opt for removing any special treatment of readonly/writeonly properties from Open API spec, and just making all these fields In my case, I wanted to test a service that maps API responses (models generated with Kiota) to domain models. I need to be able to mock the Kiota models. It works with Autofixture, I suppose it uses reflection to achieve that, but in some cases it'd be nice to craft some mock manually. |
Thank you both for the additional context here. |
Yes, I understand the general recommendation of wrapping code and it is something that I would generally do, but I think it is still valuable to be able to mock I guess another option would be using |
But such a change would have the same effect as switching from private to public in some scenarios where the client is in the same project as the consuming code from a developer experience perspective. |
Hi,
I would like to be able to stub a client generated by Kiota. But, currently, the models has private setters, like this:
I use OpenAPI spec:
kiota search microsoft.com:cognitiveservices-NewsSearch
I would like to suggest adding a configuration that allows control aspects of model generation.
Thank you, I appreciate your work.
The text was updated successfully, but these errors were encountered: