VoidPointer
Appsettings not mapping to Options class
I could probably have worded the question better, but please bear with me. Also, this is not my code, and probably has not been set up properly, but other team members are all really busy.
I see this in the
Program
class:
and then ` is defined as such:
```cs
public static IWebHost InitializeIdentityDb<TUser, TRole>(this IWebHost host)
{
using (var scope = host.Services.CreateScope())
{
var services = scope.ServiceProvider;
var options = services.GetRequiredService<IOptions<CassandraOptions>>();
...
var initializer = new DbInitializer(session);
initializer.Initialize<TUser, TRole>(options.Value);
return host;
}
}
```
Then
CassandraOptions is declared as:
```cs
public class CassandraOptions
{
public List<string> ContactPoints { get; set; }
public CassandraCredentials Credentials { get; set; }
public string KeyspaceName { get; set; }
public Dictionary<string, string> Replication { get; set; } = null;
public bool DurableWrites { get; set; } = true;
public CassandraQueryOptions Query { get; set; }
}
```
Now at my breakpoint on
initializer.Initialize<TUser, TRole>(options.Value), I see that
options is not populated. Colleagues reckon it's supposed to be populated from command line arguments, but how do I define nested values like
CassandraOptions` with command line params?16 replies
Postman Scripts to Compare Responses
(I know there are JS Discords, but the expertise here is just always so much better, and I'm not looking for language help.)
I have a VS2022 solution with two multi-project start-up configs, and I need to run Postman tests against both of these and compare responses. My first idea is to run a collection against an environment configured for one start-up, save the response JSON, and then either:
a) run the collection against another environment set up for the other start-up and use a post-request script to compare responses against those saved on the first environment.
b) run the collection twice, against the same environment, but automate starting up the solution once for each run, using a different start-up config each time and compare the response JSONs. This is preferable, because the projects used in each start-up currently have the same port numbers etc. It's quite an effort to create new launchsettings for each project, for each startup.
I've done some reading about saving response, but haven't found too much. JS isn't really an ideal tool for local disk access, so my first question is how to save the responses.
My second question is how to automate starting up VS2022 using different start-up configs, but this is a much lower priority question.
5 replies
✅ How to specify camel case for all response properties with Newtonsoft
This is the type of JSON I receive from an external API:
This I deserialize into this DTO:
Then I do some stuff, and return the same model from my own API.
AccountDetails
contains object
, because for each key, the external API returns a different set of properties, as we see in the json account_details.google
, and account_details.whatsapp
etc.
They appear in my response with the same snake case I received them with. I have even tried adding an action filter to add a NewtonsoftJsonOutputFormatter
set to camel case.
How can I force the dynamic properties to be camel case?11 replies
Stuck between using a MetadataLoadContext for reflection and using an assembly reference for testing
Following some advice here, and because it seems sensible, I switched to using a
MetadataLoadContext
to reflect types from a 3rd party compiled assembly, but now when it comes to testing a method that returns a Type, the most reliable way I have found so far of getting a reliable *expected * Type is to reference the assembly in my test project and use typeof
.
This means my expected Type comes from an assembly located in the build output, while my actual Type comes from the original location of the assembly of interest. So an assert.Equal on the two types fails. Right now I'm getting by with an assert.Equal on the type names, but that's flimsy.1 replies