Ejemplo n.º 1
0
        public async void PSPMeasFetchTest()
        {
            string connStr = Configuration["psplabelsdbinfo:ConnectionString"];

            Assert.NotNull(connStr);

            DbContextOptionsBuilder <PSPMeasDbContext> builder = new DbContextOptionsBuilder <PSPMeasDbContext>().UseSqlServer(connStr);

            PSPMeasDbContext measDbContext = new PSPMeasDbContext(builder.Options);

            List <PspMeasurement> measurements = await measDbContext.PspDbMeasurements.ToListAsync();

            Assert.NotNull(measurements);
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //
            // Configure pspmeasurements from other project
            //
            PSPMeasDbContext.FluentMethods(modelBuilder);

            //
            // Configure label checks
            //
            // Configure primary key
            modelBuilder.Entity <LabelCheck>().HasKey(l => l.Id);
            //Configure NotNull Columns
            modelBuilder.Entity <LabelCheck>().Property(l => l.CheckType).IsRequired();
            modelBuilder.Entity <LabelCheck>().Property(l => l.ConsiderStartTime).IsRequired().HasDefaultValue(LabelCheckUtils.DefaultCheckConsiderStartTime);
            modelBuilder.Entity <LabelCheck>().Property(l => l.ConsiderEndTime).IsRequired().HasDefaultValue(LabelCheckUtils.DefaultCheckConsiderEndTime);
            modelBuilder.Entity <LabelCheck>().Property(l => l.PspMeasurementId).IsRequired();
            //Configure foriegn keys
            modelBuilder.Entity <LabelCheck>().HasOne(l => l.PspMeasurement).WithMany().HasForeignKey(l => l.PspMeasurementId);
            // set seeds
            //modelBuilder.Entity<LabelCheck>().HasData(DbInitializer.GetLabelSeeds());

            //
            // Configure label check results
            //
            // Configure table name
            modelBuilder.Entity <LabelCheckResult>().ToTable("LabelCheckResults");
            // Configure primary key
            modelBuilder.Entity <LabelCheckResult>().HasKey(r => r.Id);
            //Configure NotNull Columns
            modelBuilder.Entity <LabelCheckResult>().Property(r => r.IsSuccessful).IsRequired();
            modelBuilder.Entity <LabelCheckResult>().Property(r => r.LabelCheckId).IsRequired();
            modelBuilder.Entity <LabelCheckResult>().Property(r => r.CheckProcessStartTime).IsRequired();
            modelBuilder.Entity <LabelCheckResult>().Property(r => r.CheckProcessEndTime).IsRequired();
            //Configure foriegn keys
            modelBuilder.Entity <LabelCheckResult>().HasOne(r => r.LabelCheck).WithMany().HasForeignKey(r => r.LabelCheckId);

            //
            // Configure label check params
            //
            // Configure primary key
            modelBuilder.Entity <LabelCheckParam>().HasKey(r => r.Id);
            //Configure foriegn keys
            modelBuilder.Entity <LabelCheckParam>().HasOne(r => r.LabelCheck).WithMany(l => l.LabelCheckParams).HasForeignKey(r => r.LabelCheckId);
            //Configure uniqueness constraint
            modelBuilder.Entity <LabelCheckParam>().HasIndex(p => new { p.Name, p.LabelCheckId }).IsUnique();
        }
Ejemplo n.º 3
0
        public void PSPLabelsDBConnTest()
        {
            string connStr = Configuration["psplabelsdbinfo:ConnectionString"];

            Assert.NotNull(connStr);

            DbContextOptionsBuilder <PSPMeasDbContext> builder = new DbContextOptionsBuilder <PSPMeasDbContext>().UseSqlServer(connStr);

            PSPMeasDbContext measDbContext = new PSPMeasDbContext(builder.Options);
            DbConnection     conn          = measDbContext.Database.GetDbConnection();
            bool             isError       = false;

            try
            {
                conn.Open();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                isError = true;
            }
            finally
            {
                //close the connection
                conn.Close();

                // free the resources
                conn.Dispose();
            }
            if (isError)
            {
                Assert.True(false);
            }
            else
            {
                Assert.True(true);
            }
        }
Ejemplo n.º 4
0
 public PSPMeasRepo(PSPMeasDbContext dbContext)
 {
     _dbContext = dbContext;
 }