示例#1
0
        public static HistoricalCaseNote AddCaseNoteForASpecificPersonToDb(HistoricalDataContext context, long personId, bool includeNoteContent = true)
        {
            var faker = new Faker();

            var noteTypeCode        = faker.Random.String2(5);
            var noteTypeDescription = faker.Random.String2(15);
            var noteType            = HistoricalTestHelper.CreateDatabaseNoteType(noteTypeCode, noteTypeDescription);

            context.HistoricalNoteTypes.Add(noteType);
            var savedWorker = HistoricalTestHelper.CreateDatabaseWorker();

            context.HistoricalWorkers.Add(savedWorker);

            var caseNoteId    = faker.Random.Long(min: 1);
            var savedCaseNote = HistoricalTestHelper.CreateDatabaseCaseNote(caseNoteId, personId, savedWorker, noteType);

            context.HistoricalCaseNotes.Add(savedCaseNote);
            context.SaveChanges();

            return(new HistoricalCaseNote
            {
                CreatedBy = $"{savedWorker.FirstNames} {savedWorker.LastNames}",
                CreatedByWorker = savedCaseNote.CreatedByWorker,
                Id = savedCaseNote.Id,
                LastUpdatedBy = savedCaseNote.LastUpdatedBy,
                Note = includeNoteContent == true ? savedCaseNote.Note : null,
                PersonId = savedCaseNote.PersonId,
                Title = savedCaseNote.Title,
                CreatedOn = savedCaseNote.CreatedOn,
                NoteType = noteType.Description,
                HistoricalNoteType = noteType
            });
        }
示例#2
0
        public static HistoricalWorker AddWorkerToDatabase(HistoricalDataContext socialCareContext)
        {
            var worker = HistoricalTestHelper.CreateDatabaseWorker();

            socialCareContext.HistoricalWorkers.Add(worker);
            socialCareContext.SaveChanges();

            return(worker);
        }
示例#3
0
        public static HistoricalVisit AddVisitToDatabase(HistoricalDataContext socialCareContext, HistoricalWorker?worker = null)
        {
            var visitInformation = HistoricalTestHelper.CreateDatabaseVisit(worker: worker);

            socialCareContext.HistoricalVisits.Add(visitInformation);
            socialCareContext.SaveChanges();

            return(visitInformation);
        }
示例#4
0
        public void RunBeforeAnyTests()
        {
            var builder = new DbContextOptionsBuilder <HistoricalDataContext>();

            builder.UseNpgsql(ConnectionString.HistoricalDataTestDatabase());
            HistoricalSocialCareContext = new HistoricalDataContext(builder.Options);

            //context is configured to be read only on production
            HistoricalSocialCareContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;

            HistoricalSocialCareContext.Database.EnsureCreated();
            _transaction = HistoricalSocialCareContext.Database.BeginTransaction();
        }
    public static void MyTest()
    {
        // create the data context (to get data from)
        var ds = new UniversalDataSource(
            new FooDataSource(),
            new BarDataSource()
            );
        var realTimeDataContext   = new RealTimeDataContext(ds);
        var historicalDataContext = new HistoricalDataContext(ds, DateTime.MinValue);
        var fooId = new FooIdentifier("onetuhoenthuo");
        var barId = new BarIdentifier("onetuhoenthuo");

        // testing dispatch
        Assert.AreEqual(-1, realTimeDataContext.GetValue(fooId));
        Assert.AreEqual(-2, historicalDataContext.GetValue(fooId));
        Assert.AreEqual(-3, realTimeDataContext.GetValue(barId));
        Assert.AreEqual(-4, historicalDataContext.GetValue(barId));
    }
示例#6
0
        protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            builder.ConfigureAppConfiguration(b => b.AddEnvironmentVariables());
            builder.ConfigureServices(services =>
            {
                var dbBuilder = new DbContextOptionsBuilder <DatabaseContext>();
                dbBuilder.UseNpgsql(_connection);
                var context = new DatabaseContext(dbBuilder.Options);
                services.AddSingleton(context);

                var historicalDataDbBuilder = new DbContextOptionsBuilder <HistoricalDataContext>();
                historicalDataDbBuilder.UseNpgsql(_historicalDataDbConnection);
                var historicalDataContext = new HistoricalDataContext(historicalDataDbBuilder.Options);
                services.AddSingleton(historicalDataContext);

                var serviceProvider     = services.BuildServiceProvider();
                var dbContext           = serviceProvider.GetRequiredService <DatabaseContext>();
                var historicalDbContext = serviceProvider.GetRequiredService <HistoricalDataContext>();

                dbContext.Database.EnsureCreated();
                historicalDataContext.Database.EnsureCreated();
            });
        }
示例#7
0
        public static HistoricalCaseNote AddCaseNoteWithNoteTypeAndWorkerToDatabase(HistoricalDataContext socialCareContext)
        {
            var noteType = HistoricalTestHelper.CreateDatabaseNoteType();
            var worker   = HistoricalTestHelper.CreateDatabaseWorker();
            var caseNote = HistoricalTestHelper.CreateDatabaseCaseNote(createdWorker: worker, noteType: noteType);

            socialCareContext.HistoricalWorkers.Add(worker);
            socialCareContext.HistoricalCaseNotes.Add(caseNote);
            socialCareContext.SaveChanges();

            return(new HistoricalCaseNote
            {
                CreatedBy = $"{worker.FirstNames} {worker.LastNames}",
                CreatedByWorker = caseNote.CreatedByWorker,
                Id = caseNote.Id,
                LastUpdatedBy = caseNote.LastUpdatedBy,
                Note = caseNote.Note,
                PersonId = caseNote.PersonId,
                Title = caseNote.Title,
                CreatedOn = caseNote.CreatedOn,
                NoteType = noteType.Type,
                HistoricalNoteType = noteType
            });
        }
 public HistoricalDataGateway(HistoricalDataContext databaseContext)
 {
     _databaseContext = databaseContext;
 }