ross
Dotnet code generator web api question
I've been trying out the API code generator in visual studio/dotnet, and I had a question about some of the CRUD methods it generates:
What's the purpose of checking if
_context.Vehicles == null
? Like I understand that you obviously won't be able to add and saveChanges if it were null, but I can't think of a circumstance where it would be null and that check would apply? I see that check is done in Get, GetById, Post, and Delete. Just curious!14 replies
[XUnit, Moq, EFCore] Unit Testing Question
Hi folks, needing some advice on this approach. This is my first real go at unit testing, so wanted to make sure I'm off in the right direction.
My app works as so: Frontend calls API, API calls service class, service class has direct access to dbContext. Simples.
So here's an example of one of my service classes and a method, and the unit test:
Service class:
Test class:
So, am I doing anything wrong?
14 replies
Multiple classes defining same props vs inherit from base class
Say I have multiple service classes, here's two as an example:
Instead of repeating the two private properties and the ctor on every service class, would it be acceptable to create a base class which the service classes inherit from? E.g:
I'm just approaching this from a DRY point of view. Technically I'm still repeating myself with the ctor in every service class, but it just seems cleaner? Some guidance would be much appreciated
6 replies