Exemple #1
0
        public void WhenUsingSharedDatabaseAndMigrator_ShouldOnlyMigrateTheFirstTime()
        {
            using (var db = new TempDBLocalDb())
            {
                var sql = ENTITY_PERSISTENCE_CONTEXT_SQL;
                EntityPersistenceTester.CreateFor <SomeEntityWithDecimalValue>()
                .WithContext <EntityPersistenceContext>()
                .WithDbMigrator(cs => new DbSchemaImporter(cs, sql))
                .WithSharedDatabase(db)
                .ShouldPersistAndRecall();

                // need to clear for the test to work again
                using (var ctx = new EntityPersistenceContext(db.CreateConnection()))
                {
                    ctx.EntitiesWithDecimalValues.Clear();
                    ctx.SaveChangesWithErrorReporting();
                }

                Assert.DoesNotThrow(() =>
                {
                    EntityPersistenceTester.CreateFor <SomeEntityWithDecimalValue>()
                    .WithContext <EntityPersistenceContext>()
                    .WithDbMigrator(cs => new DbSchemaImporter(cs, sql))
                    .WithSharedDatabase(db)
                    .ShouldPersistAndRecall();
                });
            }
        }
Exemple #2
0
        private static ValidationContext GetValidationContext(object o, EntityPersistenceContext context)
        {
            var items = new Dictionary <object, object> {
                { ContextKey, context }
            };

            return(new ValidationContext(o, null, items));
        }
 internal static IEnumerable<ValidationResult> DoMemberValidation(object o, EntityPersistenceContext context)
 {
     //cascade validation through all entity components associated with the entity
     var validationResults = new List<ValidationResult>();
     //validate entity
     var validationContext = GetValidationContext(o, context);
     Validator.TryValidateObject(o,
         validationContext, 
         validationResults, 
         context.ValidateProperties);
     //validate entity components
     return validationResults;
 }
Exemple #4
0
        internal static IEnumerable <ValidationResult> DoMemberValidation(object o, EntityPersistenceContext context)
        {
            //cascade validation through all entity components associated with the entity
            var validationResults = new List <ValidationResult>();
            //validate entity
            var validationContext = GetValidationContext(o, context);

            Validator.TryValidateObject(o,
                                        validationContext,
                                        validationResults,
                                        context.ValidateProperties);
            //validate entity components
            return(validationResults);
        }
 private static ValidationContext GetValidationContext(object o, EntityPersistenceContext context)
 {
     var items = new Dictionary<object, object> { { ContextKey, context } };
     return new ValidationContext(o, null, items);
 }