public void CompareReadOnlyDbContextMissingView()
        {
            //SETUP
            var options = this.CreateUniqueClassOptions <ReadOnlyDbContext>(
                builder => builder.ReplaceService <IModelCacheKeyFactory, ReadOnlyModelCacheKeyFactory>());

            using var context = new ReadOnlyDbContext(options);
            context.Database.EnsureClean();
            context.Database.ExecuteSqlRaw(
                "CREATE OR ALTER VIEW MyView AS SELECT Id, MyDateTime FROM NormalClasses");

            var config = new CompareEfSqlConfig();

            config.IgnoreTheseErrors(
                "NOT CHECKED: Entity 'MappedToQuery', not mapped to database. Expected = <null>, found = MappedToQuery");
            var comparer = new CompareEfSql(config);

            //ATTEMPT
            var hasErrors = comparer.CompareEfWithDb(context);

            //VERIFY
            hasErrors.ShouldBeTrue();
            var errors = CompareLog.ListAllErrors(comparer.Logs).ToList();

            (errors.Count == 1).ShouldBeTrue(comparer.GetAllErrors);
            errors[0].ShouldEqual(
                "NOT IN DATABASE: MappedToView->Property 'MyString', column name. Expected = <null>");
        }
        public void CompareReadOnlyDbContextIgnoreNormalClasses()
        {
            //SETUP
            var options = this.CreateUniqueClassOptions <ReadOnlyDbContext>(
                builder => builder.ReplaceService <IModelCacheKeyFactory, ReadOnlyModelCacheKeyFactory>());

            using var context = new ReadOnlyDbContext(options);
            context.Database.EnsureClean();
            var filepath = TestData.GetFilePath("AddViewToDatabase.sql");

            context.ExecuteScriptFileInTransaction(filepath);

            var config = new CompareEfSqlConfig
            {
                TablesToIgnoreCommaDelimited = "NormalClasses"
            };

            var comparer = new CompareEfSql(config);

            //ATTEMPT
            var hasErrors = comparer.CompareEfWithDb(context);

            //VERIFY
            hasErrors.ShouldBeTrue();
            var errors = CompareLog.ListAllErrors(comparer.Logs).ToList();

            errors.Count.ShouldEqual(3);
            errors[0].ShouldEqual(
                "NOT CHECKED: Entity 'MappedToQuery', not mapped to database. Expected = <null>, found = MappedToQuery");
            errors[1].ShouldEqual(
                "NOT IN DATABASE: MappedToQuery->Entity 'NormalClass', table name. Expected = NormalClasses");
            errors[2].ShouldEqual(
                "NOT IN DATABASE: MappedToQuery->Entity 'MappedToView', table name. Expected = NormalClasses");
        }
        public void CompareReadOnlyDbContextDifferentColumnType()
        {
            //SETUP
            var options = this.CreateUniqueClassOptions <ReadOnlyDbContext>(
                builder => builder.ReplaceService <IModelCacheKeyFactory, ReadOnlyModelCacheKeyFactory>());

            using var context = new ReadOnlyDbContext(options, ReadOnlyDbContext.Configs.BadMappedToViewClass);
            context.Database.EnsureClean();
            context.Database.ExecuteSqlRaw(
                "CREATE OR ALTER VIEW MyView AS SELECT Id, MyDateTime, MyString FROM NormalClasses");

            var config = new CompareEfSqlConfig();

            config.IgnoreTheseErrors(
                "NOT CHECKED: Entity 'MappedToQuery', not mapped to database. Expected = <null>, found = MappedToQuery");
            var comparer = new CompareEfSql(config);

            //ATTEMPT
            var hasErrors = comparer.CompareEfWithDb(context);

            //VERIFY
            hasErrors.ShouldBeTrue();
            var errors = CompareLog.ListAllErrors(comparer.Logs).ToList();

            (errors.Count == 2).ShouldBeTrue(comparer.GetAllErrors);
            errors[0].ShouldEqual("DIFFERENT: MappedToViewBad->Property 'MyString', column type. Expected = int, found = nvarchar(max)");
            errors[1].ShouldEqual("DIFFERENT: MappedToViewBad->Property 'MyString', nullability. Expected = NOT NULL, found = NULL");
        }
Exemplo n.º 4
0
 public SubjectService(RollCallDbContext context,
                       UserManager <User> userManager, ReadOnlyDbContext readOnlyDbContext)
 {
     this.context           = context;
     this.userManager       = userManager;
     this.readOnlyDbContext = readOnlyDbContext;
 }
Exemplo n.º 5
0
 public SchoolClassService(RollCallDbContext context, ISubjectServices subjectServices, UserManager <User> userManager, ReadOnlyDbContext readOnlyDbContext)
 {
     this.context           = context;
     this.subjectServices   = subjectServices;
     this.userManager       = userManager;
     this.readOnlyDbContext = readOnlyDbContext;
 }
        public void CompareReadOnlyDbContextOk()
        {
            //SETUP
            var options = this.CreateUniqueClassOptions <ReadOnlyDbContext>(
                builder => builder.ReplaceService <IModelCacheKeyFactory, ReadOnlyModelCacheKeyFactory>());

            using var context = new ReadOnlyDbContext(options);
            context.Database.EnsureClean();
            context.Database.ExecuteSqlRaw(
                "CREATE OR ALTER VIEW MyView AS SELECT Id, MyDateTime, MyString FROM NormalClasses");

            var config = new CompareEfSqlConfig();

            config.IgnoreTheseErrors(
                "NOT CHECKED: Entity 'MappedToQuery', not mapped to database. Expected = <null>, found = MappedToQuery");
            var comparer = new CompareEfSql(config);

            //ATTEMPT
            var hasErrors = comparer.CompareEfWithDb(context);

            //VERIFY
            hasErrors.ShouldBeFalse(comparer.GetAllErrors);
        }
Exemplo n.º 7
0
 public AttendanceService(RollCallDbContext context, ReadOnlyDbContext readOnlyDbContext)
 {
     this.context           = context;
     this.readOnlyDbContext = readOnlyDbContext;
 }