Beispiel #1
0
 ///<summary>
 /// Applies the resulted mappings with this builder globaly (application context) to all repositories.
 ///</summary>
 public void ApplyMappingsGlobal()
 {
     foreach (var mapping in this._propertyMappings)
     {
         XmlRepository.AddPropertyMappingFor(typeof(TEntity), mapping);
     }
 }
Beispiel #2
0
        public void PropertyMappingPrototypeTest()
        {
            var mapping = new PropertyMapping();

            mapping.EntityType     = typeof(Person);
            mapping.PropertyType   = typeof(Guid);
            mapping.Name           = "Id";
            mapping.XmlMappingType = XmlMappingType.Attribute;

            XmlRepository.AddPropertyMappingFor(typeof(Person), mapping);

            var test = new PropertyMapping();

            test.EntityType     = typeof(Person);
            test.PropertyType   = typeof(string);
            test.Name           = "LastName";
            test.XmlMappingType = XmlMappingType.Element;

            XmlRepository.AddPropertyMappingFor(typeof(Person), test);

            var a = new PropertyMapping();

            a.EntityType     = typeof(Geek);
            a.PropertyType   = typeof(string);
            a.Name           = "SuperId";
            a.XmlMappingType = XmlMappingType.Attribute;

            XmlRepository.AddPropertyMappingFor(typeof(Geek), a);

            using (var repository = XmlRepository
                                    .Get(RepositoryFor <Person>
                                         .WithIdentity(p => p.Id)
                                         .WithDataProvider(new InMemoryDataProvider())))
            {
                var geek = new Geek
                {
                    Alias = "Jackal"
                };

                var peter = new Person
                {
                    FirstName = "Peter",
                    LastName  = "Bucher",
                    Birthday  = new DateTime(1983, 10, 17),
                    Friends   = new List <Geek>(new[] { geek, new Geek()
                                                        {
                                                            Alias = "YEAH"
                                                        } }),
                    Geek = geek
                };

                repository.SaveOnSubmit(peter);

                var loadedData = repository.LoadAll();

                Assert.That(loadedData.Count(), Is.EqualTo(1));
                Assert.That(loadedData.First().FirstName == "Peter");
                Assert.That(loadedData.First().Friends.Count, Is.EqualTo(2));
            }
        }