public PersonRetreivalService(IPersonRepository personRepo, IWebApiContext api) { /* * So, we need to work with a DB connection and a web service client in this class. * Why not just create them here? * You could write: * _database = new DatabaseContext(); * * ...but, with that one line, you've intertwined your PersonRetreivalService logic with the * database logic. Now, if we want to write automated tests, you can't test PersonRetreivalService * without inherently testing the database methods as well. This migh sound good at first, but * the problem is, when your SyncPersons method fails the tests, was it because something went wrong * in this class or is it something in the database that is causing the problem? * * Also, if you create the web service client here, every time you run your tests, you depend on data * coming from the actual web service. That data is not static; it is not 100% known data. You cannot * predict the results when the data is not known. You cannot put in specific tests, like: * Get Person where Id == 1, and his FirstName should be 'Billy' * * So, the better solution is to require a database context in the constructor. That way, when we want * to perform automated testing, we can just send in some simple database object that we build ourselves * entirely for the purpose of testing. That database we pass in can contain a known set of data so that * we can predict the results! */ // set the local variables with the arguments from the constructor // Is this a real database, or one that's mocked up for testing? // I don't really care, as long as it works!!! _personRepo = personRepo ?? throw new ArgumentNullException(nameof(personRepo)); // same with the api. As long as whatever got passed in implements // the GetPersons method, I don't give a shit what it is!!! _api = api ?? throw new ArgumentNullException(nameof(api)); }
public static void AuditTrack(this AppStorageContext ctx, IWebApiContext workContext) { if (workContext == null) { return; } var now = DateTime.Now; var addedAuditedEntities = ctx.ChangeTracker.Entries <ReadModelBase>() .Where(p => p.State == EntityState.Added) .Select(p => p.Entity); var modifiedAuditedEntities = ctx.ChangeTracker.Entries <ReadModelBase>() .Where(p => p.State == EntityState.Modified) .Select(p => p.Entity); if (!modifiedAuditedEntities.Any() && !addedAuditedEntities.Any()) { return; } var currentUser = workContext.UserName ?? "System"; foreach (var added in addedAuditedEntities) { added.CreatedBy = currentUser; added.CreatedDate = now; added.Deleted = false; added.ModifiedBy = currentUser; added.ModifiedDate = now; } foreach (var modified in modifiedAuditedEntities) { modified.ModifiedBy = currentUser; modified.ModifiedDate = now; if (modified is ISoftDelete) { if (modified.Deleted.HasValue && modified.Deleted.Value) { modified.DeletedBy = currentUser; modified.DeletedDate = now; } } } }
protected BaseService(IWebApiContext context) { Context = context; }
public QuestionService(IWebApiContext context) : base(context) { }
public PhoneNumberService(IWebApiContext context) : base(context) { }
public TimeSlotService(IWebApiContext context) : base(context) { }
public DiaporamaImageService(IWebApiContext context) : base(context) { }
public StateService(IWebApiContext context) : base(context) { }
public UserService(IWebApiContext context) : base(context) { }
public AboutTextService(IWebApiContext context) : base(context) { }
public PermissionService(IWebApiContext context) : base(context) { }
public FuncionarioRepository(IWebApiContext context) { // Inicializa dados de conexão com o BD e GridFS _context = context; _gridFS = context.GridFS; }
public PhoneTypeService(IWebApiContext context) : base(context) { }
protected BaseCrudService(IWebApiContext context) : base(context) { }
public PersonalInformationService(IWebApiContext context) : base(context) { }
public RegistrationService(IWebApiContext context) : base(context) { }
public ActionTokenService(IWebApiContext context) : base(context) { }
public GlobalExceptionFilter(IWebApiContext apiContext) { _workContext = apiContext; }
public WebApiRepository(IWebApiContext context) { _context = context; }
public JobService(IWebApiContext context) : base(context) { }
public FollowUpService(IWebApiContext context) : base(context) { }
public AppointmentService(IWebApiContext context) : base(context) { }
public CustomerService(IWebApiContext context) : base(context) { }
public AppStorageContext(IOptions <StorageContextOptions> options, IWebApiContext workContext, IMediator mediator) : base(options) { _workContext = workContext; _mediator = mediator; }
public ResponseService(IWebApiContext context) : base(context) { }
public WebApiController(IWebApiContext context) { this.Context = context; }