public FarmLoggerProvider(IServiceScopeFactory scopeFactory) { // The logger should be the only part of the codebase that *creates* new logs, so having a persistant // db context shouldn't cause issues (i.e. id conflicts). this._scope = scopeFactory.CreateScope(); this._db = this._scope.ServiceProvider.GetRequiredService <FarmMasterContext>(); this._instances = new Dictionary <string, FarmLogger>(); this._entryCounter = new Counter(); }
public FarmLoggerProviderTests() { var builder = new ServiceCollection(); builder.AddScoped(_ => FarmMasterContext.InMemory()); builder.AddSingleton <FarmLoggerProvider>(); this._services = builder; }
public FarmLogger(string categoryName, FarmMasterContext db, Counter counter) { if (db == null) { throw new ArgumentNullException(nameof(db), "DI didn't work :("); } this._categoryName = categoryName; this._counter = counter; this._db = db; }
public async Task BasicCrud() { var db = FarmMasterContext.InMemory(); var species = new SpeciesManager(db); var uow = new DbContextUnitOfWork <FarmMasterContext>(db); var goat = new Species { GestrationPeriod = TimeSpan.FromDays(121), Name = "Goat" }; // C & R (DbSet) using (var scope = uow.Begin()) { var result = await species.CreateAsync(goat); Assert.True(result.Succeeded); scope.Commit(); } Assert.NotEmpty(db.Species); Assert.Same(goat, db.Species.First()); // U & R (Query) using (var scope = uow.Begin()) { goat.GestrationPeriod = TimeSpan.FromDays(1); species.Update(goat); scope.Commit(); } Assert.Equal(TimeSpan.FromDays(1), species.Query().AsNoTracking().First().GestrationPeriod); // D & R (ById exist and not exist) var id = goat.SpeciesId; var valueResult = await species.GetByIdAsync(id); Assert.True(valueResult.Succeeded); Assert.Same(goat, valueResult.Value); using (var scope = uow.Begin()) { species.Delete(goat); scope.Commit(); } Assert.Empty(db.Species); valueResult = await species.GetByIdAsync(id); Assert.False(valueResult.Succeeded); Assert.Contains("1", valueResult.GatherErrorMessages().First()); }
protected override void ConfigWithDatabase(EmailSenderConfig options, FarmMasterContext db) { var settings = db.Settings.FirstOrDefault(); if (settings == null) { return; } options.Layout = new EmailTemplate(this._layoutTemplate); options.Smtp.Server = settings.SmtpServer; options.Smtp.Port = settings.SmtpPort; options.Smtp.Username = settings.SmtpUsername; options.Smtp.Password = settings.SmtpPassword; // CURRENTLY STORED UNENCRYPTED }
public RootGraphQLMutation( IHttpContextAccessor context, UserManager <ApplicationUser> users, GraphQLUserContextAccessor accessor, FarmMasterContext fmDb, IdentityContext idDb, IAuthorizationService auth, IEnumerable <IGraphQLMutationProvider> providers ) : base(context, users, accessor, fmDb, idDb, auth) { foreach (var provider in providers) { provider.AddMutations(this); } }
public RootGraphQLQuery( // Required for RootBase IHttpContextAccessor context, UserManager <ApplicationUser> users, GraphQLUserContextAccessor accessor, FarmMasterContext fmDb, IdentityContext idDb, IAuthorizationService auth, // Extern providers IEnumerable <IGraphQLQueryProvider> providers ) : base(context, users, accessor, fmDb, idDb, auth) { foreach (var provider in providers) { provider.AddQueries(this); } }
public RootBase( IHttpContextAccessor context, UserManager <ApplicationUser> users, GraphQLUserContextAccessor accessor, FarmMasterContext fmDb, IdentityContext idDb, IAuthorizationService auth ) { var user = users.GetUserAsync(context.HttpContext.User).Result; accessor.Context = new DataAccessUserContext(user, context.HttpContext.User, auth); if (user == null) { throw new ExecutionError("You are not logged in"); } this.DataContext = accessor.Context; this.FarmMasterDb = fmDb; this.IdentityDb = idDb; this.UserManager = users; }
public FarmMasterSettingsAccessor(FarmMasterContext context) { this._context = context; }