コード例 #1
0
 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();
 }
コード例 #2
0
        public FarmLoggerProviderTests()
        {
            var builder = new ServiceCollection();

            builder.AddScoped(_ => FarmMasterContext.InMemory());
            builder.AddSingleton <FarmLoggerProvider>();

            this._services = builder;
        }
コード例 #3
0
        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;
        }
コード例 #4
0
        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());
        }
コード例 #5
0
        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
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
        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;
        }
コード例 #9
0
 public FarmMasterSettingsAccessor(FarmMasterContext context)
 {
     this._context = context;
 }