Example #1
0
        public void TestCheckStoreRoomMissing()
        {
            OleDbOracleDaLayer ddl =
                new OleDbOracleDaLayer(
                    (OleDbDescriptor)
                    ConnectionDescriptor.LoadFromConfig(
                        new Config("..\\..\\Tests\\OracleDao.config", "OracleDaoConfig"), "DAO"));

            // Make sure the store room to test does not exist
            var colDef = new ClassMapColDefinition("Id", "Id", "INTEGER");
            var cm = new ClassMapping("test", "UNITTEST.StoreroomDoesNotExist", new List<ClassMapColDefinition>{colDef}, false);
            ddl.DeleteStoreRoom(cm);

            try
            {
                // Hasn't been added yet, should not exist
                Assert.IsTrue(
                    ddl.StoreRoomMissing(cm), "Oracle storeroom should not exist");

                ddl.CreateStoreRoom(cm);

                // Correct name, should exist
                Assert.IsFalse(
                    ddl.StoreRoomMissing(cm), "Oracle Storeroom should exist");
            }
            finally
            {
                // Delete the storeromm, no matter what
                ddl.DeleteStoreRoom(cm);
            }

            // Storeroom should be gone
            Assert.IsTrue(
                ddl.StoreRoomMissing(cm), "Oracle storeroom should not exist");
        }
        private ISubclassMapping CreateSubclass(ClassMapping mapping)
        {
            if (mapping.Discriminator == null)
                return new JoinedSubclassMapping();

            return new SubclassMapping();
        }
 /// <summary>
 /// Returns true if you need to call "CreateStoreRoom" before storing any
 /// data.  This method is "Missing" not "Exists" because implementations that
 /// do not use a store room can return "false" from this method without
 /// breaking either a user's app or the spirit of the method.
 /// 
 /// Store room typically corresponds to "table".
 /// Firebird doesn't appear to support the SQL standard information_schema.
 /// </summary>
 /// <returns>Returns true if you need to call "CreateStoreRoom"
 ///          before storing any data.</returns>
 public override bool StoreRoomMissing(ClassMapping mapping)
 {
     int count = SqlConnectionUtilities.XSafeIntQuery(_connDesc,
         "select count(*) from rdb$relations where rdb$relation_name = '" +
         mapping.Table.ToUpper() + "'", null);
     return count == 0;
 }
Example #4
0
        public Stream GetStream(ClassMapping clazz,string directory,out string fileName)
        {
            directoryForOutput = directory;
            if (!string.IsNullOrEmpty(directoryForOutput))
            {
                if (!Directory.Exists(directoryForOutput))
                    Directory.CreateDirectory(directoryForOutput);
            }

            try
            {
                fileName = GetFileName(clazz);
            }
            catch
            {
                fileName = clazz.GeneratedName + ".cs";
                log.Error("Error processing template for file name. " + fileName + " used.");
            }

            string toSave = Path.Combine(directoryForOutput, fileName);

            FileStream output = new FileStream(toSave, FileMode.Create, FileAccess.ReadWrite);
            log.Debug("Flushing output on file:" + output.Name);
            fileName = toSave;
            return output;
        }
 public override void because()
 {
     mappings = model.BuildMappings();
     target_mapping = mappings
         .SelectMany(x => x.Classes)
         .FirstOrDefault(x => x.Type == typeof(Target));
 }
Example #6
0
        /// <summary>
        /// Create the data reader.
        /// </summary>
        /// <param name="layer">Layer creating it.</param>
        /// <param name="mapping">Mapping for the class stored in the data store.</param>
        /// <param name="criteria">Criteria for which instances you want.</param>
        /// <param name="objects">Iterator over the list of objects.</param>
        public MemoryDataReader(UnqueryableDaLayer layer, ClassMapping mapping, DaoCriteria criteria,
            IEnumerator<MemoryObject> objects)
            : base(layer, mapping, criteria, GetConfig(mapping))
        {
            _objects = objects;

            PreProcessSorts();
        }
        public void ShouldMapByteArrayAsBinaryBlob()
        {
            var mapping = new ClassMapping { Type = typeof(Target) };

            mapper.Map(mapping, typeof(Target).GetProperty("Version"));

            mapping.Version.Type.ShouldEqual(new TypeReference("BinaryBlob"));
        }
        public void ShouldMapByteArrayAsNotNull()
        {
            var mapping = new ClassMapping { Type = typeof(Target) };

            mapper.Map(mapping, typeof(Target).GetProperty("Version").ToMember());

            SpecificationExtensions.ShouldBeTrue(mapping.Version.Columns.All(x => x.NotNull == true));
        }
        public void ShouldMapInheritedByteArray()
        {
            var mapping = new ClassMapping { Type = typeof(SubTarget) };

            mapper.Map(mapping, typeof(SubTarget).GetProperty("Version"));

            Assert.That(mapping.Version, Is.Not.Null);
        }
        public void ShouldMapByteArrayAsTimestampSqlType()
        {
            var mapping = new ClassMapping { Type = typeof(Target) };

            mapper.Map(mapping, typeof(Target).GetProperty("Version"));

            mapping.Version.Columns.All(x => x.SqlType == "timestamp").ShouldBeTrue();
        }
Example #11
0
        public ClassInspector(ClassMapping mapping)
        {
            this.mapping = mapping;

            propertyMappings.Map(x => x.LazyLoad, x => x.Lazy);
            propertyMappings.Map(x => x.ReadOnly, x => x.Mutable);
            propertyMappings.Map(x => x.EntityType, x => x.Type);
        }
        public void ShouldSetContainingEntityType()
        {
            var mapping = new ClassMapping { Type = typeof(Target) };

            mapper.Map(mapping, typeof(Target).GetProperty("Version").ToMember());

            mapping.Version.ContainingEntityType.ShouldEqual(typeof(Target));
        }
        public void ShouldMapByteArrayAsNotNull()
        {
            var mapping = new ClassMapping { Type = typeof(Target) };

            mapper.Map(mapping, typeof(Target).GetProperty("Version"));

            mapping.Version.Columns.All(x => x.NotNull == true).ShouldBeTrue();
        }
        public void ShouldMapByteArrayWithUnsavedValueOfNull()
        {
            var mapping = new ClassMapping { Type = typeof(Target) };

            mapper.Map(mapping, typeof(Target).GetProperty("Version"));

            mapping.Version.UnsavedValue.ShouldEqual(null);
        }
        public void ShouldWriteBag()
        {
            var mapping = new ClassMapping();

            mapping.AddCollection(new BagMapping());

            writer.VerifyXml(mapping)
                .Element("bag").Exists();
        }
        public void ShouldWriteAny()
        {
            var mapping = new ClassMapping();

            mapping.AddAny(new AnyMapping());

            writer.VerifyXml(mapping)
                .Element("any").Exists();
        }
        public void ShouldSetContainingEntityType()
        {
            var mapping = new ClassMapping();
            mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));

            mapper.Map(mapping, typeof(Target).GetProperty("Version").ToMember());

            mapping.Version.ContainingEntityType.ShouldEqual(typeof(Target));
        }
        public void ShouldMapInheritedByteArray()
        {
            var mapping = new ClassMapping();
            mapping.Set(x => x.Type, Layer.Defaults, typeof(SubTarget));

            mapper.Map(mapping, typeof(SubTarget).GetProperty("Version").ToMember());

            Assert.That(mapping.Version, Is.Not.Null);
        }
        public void ShouldMapByteArrayWithUnsavedValueOfNull()
        {
            var mapping = new ClassMapping();
            mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));

            mapper.Map(mapping, typeof(Target).GetProperty("Version").ToMember());

            mapping.Version.UnsavedValue.ShouldEqual(null);
        }
        public void ShouldMapByteArrayAsNotNull()
        {
            var mapping = new ClassMapping();
            mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));

            mapper.Map(mapping, typeof(Target).GetProperty("Version").ToMember());

            mapping.Version.Columns.All(x => x.NotNull).ShouldBeTrue();
        }
        public void ShouldMapByteArrayAsBinaryBlob()
        {
            var mapping = new ClassMapping();
            mapping.Set(x => x.Type, Layer.Defaults, typeof(Target));

            mapper.Map(mapping, typeof(Target).GetProperty("Version").ToMember());

            mapping.Version.Type.ShouldEqual(new TypeReference("BinaryBlob"));
        }
        public void ShouldWriteCache()
        {
            var mapping = new ClassMapping();

            mapping.Cache = new CacheMapping();

            writer.VerifyXml(mapping)
                .Element("cache").Exists();
        }
        public DiscriminatorMapping(ClassMapping parentClass)
        {
            ParentClass = parentClass;

            attributes = new AttributeStore<DiscriminatorMapping>();
            attributes.SetDefault(x => x.NotNull, true);
            attributes.SetDefault(x => x.Insert, true);
            attributes.SetDefault(x => x.Type, typeof(string));
        }
        public override void ProcessClass(ClassMapping mapping)
        {
            var subclasses = FindClosestSubclasses(mapping.Type);

            foreach (var provider in subclasses)
                mapping.AddSubclass(provider.GetSubclassMapping(CreateSubclass(mapping)));

            base.ProcessClass(mapping);
        }
        public void ShouldWriteSqlUpdate()
        {
            var mapping = new ClassMapping();

            mapping.AddStoredProcedure(new StoredProcedureMapping("sql-update", "update ABC"));

            writer.VerifyXml(mapping)
                .Element("sql-update").Exists();
        }
        public void ShouldMapHashSetAsSet()
        {
            var classMapping = new ClassMapping();
            classMapping.Set(x => x.Type, Layer.Defaults, typeof(PropertyTarget));

            mapper.Map(classMapping, typeof(PropertyTarget).GetProperty("HashSet").ToMember());

            classMapping.Collections
                .First().Collection.ShouldEqual(Collection.Set);
        }
Example #27
0
        public ClassMapping Map(Type classType, List<AutoMapType> types)
        {
            var classMap = new ClassMapping { Type = classType };

            classMap.SetDefaultValue(x => x.Name, classType.AssemblyQualifiedName);
            classMap.SetDefaultValue(x => x.TableName, GetDefaultTableName(classType));

            mappingTypes = types;
            return (ClassMapping)MergeMap(classType, classMap, new List<string>());
        }
        public override void ProcessClass(ClassMapping mapping)
        {
            var subclasses = subclassProviders
                .Select(x => x.GetSubclassMapping(CreateSubclass(mapping)))
                .Where(x => x.Type.BaseType == mapping.Type);

            foreach (var subclass in subclasses)
                mapping.AddSubclass(subclass);

            base.ProcessClass(mapping);
        }
Example #29
0
        public ClassMapping Map(Type classType, List<AutoMapType> types)
        {
            var classMap = new ClassMapping();

            classMap.Set(x => x.Type, Layer.Defaults, classType);
            classMap.Set(x => x.Name, Layer.Defaults, classType.AssemblyQualifiedName);
            classMap.Set(x => x.TableName, Layer.Defaults, GetDefaultTableName(classType));

            mappingTypes = types;
            return (ClassMapping)MergeMap(classType, classMap, new List<Member>());
        }
        public void CanAddClassMappings()
        {
            var hibMap = new HibernateMapping();
            var classMap1 = new ClassMapping();
            var classMap2 = new ClassMapping();

            hibMap.AddClass(classMap1);
            hibMap.AddClass(classMap2);

            hibMap.Classes.ShouldContain(classMap1);
            hibMap.Classes.ShouldContain(classMap2);
        }