Beispiel #1
0
        public void Save()
        {
            var now = DateTime.Now;

            var version = new ContentVersion();

            version.Expired        = now;
            version.FuturePublish  = now;
            version.ItemCount      = 3;
            version.Published      = now;
            version.Saved          = now;
            version.SavedBy        = "Ben";
            version.State          = ContentState.Published;
            version.Title          = "Hello";
            version.VersionDataXml = "duh";
            version.VersionIndex   = 3;

            using (repository)
            {
                repository.SaveOrUpdate(version);
            }
            var read = repository.Get(version.ID);

            read.Expired.ShouldBe(now);
            read.FuturePublish.ShouldBe(now);
            read.ItemCount.ShouldBe(3);
            read.Published.ShouldBe(now);
            read.Saved.ShouldBe(now);
            read.SavedBy.ShouldBe("Ben");
            read.State.ShouldBe(ContentState.Published);
            read.Title.ShouldBe("Hello");
            read.VersionDataXml.ShouldBe("duh");
            read.VersionIndex.ShouldBe(3);
        }
Beispiel #2
0
        public void ARepositoryCanLoadGeekFriendCollectionFromPerson()
        {
            using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
            {
                var geekFriends = new List <Geek>
                {
                    new Geek {
                        Alias = "Peter"
                    },
                    new Geek()
                    {
                        Alias = "Golo"
                    }
                };

                var robertoId             = Guid.NewGuid();
                var personWithGeekFriends = new Person
                {
                    Id        = robertoId,
                    FirstName = "Roberto", Friends = geekFriends
                };

                repository.SaveOnSubmit(personWithGeekFriends);

                Assert.That(repository.LoadAll().Count(), Is.EqualTo(1));
                Assert.That(repository.LoadBy(p => p.Id == robertoId).Friends.Count, Is.EqualTo(2));
                Assert.That(repository.LoadAll().Single().Friends[0].Alias, Is.EqualTo("Peter"));
            }
        }
Beispiel #3
0
        public void sdfsdfsdf()
        {
            var repository = XmlRepository.Get(RepositoryFor <Person>
                                               .WithIdentity(p => p.Id)
                                               .WithDataProvider(new InMemoryDataProvider()));

            repository.SaveOnSubmit(new Person()
            {
                FirstName = "Peter"
            });
            repository.SaveOnSubmit(new Person()
            {
                FirstName = "Golo"
            });

            var test  = repository.LoadAll();
            var peter = repository.LoadBy(p => p.FirstName == "Peter");

            repository.DeleteOnSubmit(p => p.FirstName == "Peter");

            var test2 = repository.LoadAll();

            repository.SubmitChanges();

            repository.DataProvider = new InMemoryDataProvider();

            var sdfsdsdf = XmlRepository.Get(RepositoryFor <Person>
                                             .WithIdentity(p => p.Id));
        }
Beispiel #4
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));
            }
        }
        public void Update_ShouldSavesChanges_IfEntityExists()
        {
            string fileName = Guid.NewGuid().ToString("N") + ".xml";

            Guid       entityId = Guid.NewGuid();
            FakeEntity entity   = new FakeEntity()
            {
                Id = entityId, Name = entityId.ToString()
            };
            XmlRepository <FakeEntity> repository = new XmlRepository <FakeEntity>(fileName);

            repository.Add(entity);
            repository.SaveChanges();

            entity = new FakeEntity()
            {
                Id = entityId, Name = "NewValue"
            };

            repository = new XmlRepository <FakeEntity>(fileName);
            repository.Update(entity);
            repository.SaveChanges();

            repository = new XmlRepository <FakeEntity>(fileName);
            entity     = repository.Get(entityId);

            Assert.AreEqual("NewValue", entity.Name);
            File.Delete(fileName);
        }
Beispiel #6
0
        public void MappingBuilderAbstractionIntegration()
        {
            using (var builder = XmlRepository.GetPropertyMappingBuilderFor <Person>())
            {
                builder.Map(p => p.Id).ToAttribute("sexy");
                builder.Map(p => p.LastName).ToContent();
            }

            //// builder.Map(p => p.Geek).ToElement("TESTGEEK"); ??

            string xml = "<root></root>";

            var delegateProvider = new DelegateDataProvider(() => xml, data => xml = data);

            XmlRepository.DataProvider = delegateProvider;

            using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
            {
                var person = new Person
                {
                    FirstName = "Peter&",
                    LastName  = "Bucher",
                    Geek      = new Geek
                    {
                        Alias   = "YeahAlias",
                        SuperId = "test"
                    }
                };

                repository.SaveOnSubmit(person);
                repository.SubmitChanges();

                var data = repository.LoadAll();
            }
        }
Beispiel #7
0
 public void LoadByNullThrowsArgumentNullException()
 {
     using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
     {
         Assert.Throws <ArgumentNullException>(() => repository.LoadBy(null));
     }
 }
Beispiel #8
0
 public void ANewlyCreatedRepositoryDoesNotContainAnyEntities()
 {
     using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
     {
         this.ExecuteLoadAsserts(repository, 0, false, false);
     }
 }
Beispiel #9
0
        public void DataAvailableInProviderIsLoadAutomatically()
        {
            var getRepositoryThatWillBeReused = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id));

            var builder = XmlRepository.GetPropertyMappingBuilderFor <Person>();

            builder.Map(p => p.Id).ToAttribute();

            builder.ApplyMappingsGlobal();

            var prefilledInMemoryProvider = new InMemoryDataProvider(
                @"<root>
  <Person>
    <Id>c186fb12-dd38-4784-8b48-aad96a6510c4</Id>
    <LastName>Bucher</LastName>
    <FirstName>Peter</FirstName>
    <Geek>
      <Id>8f8b747e-3f16-4938-a384-980fc8aa8dd7</Id>
      <SuperId>test</SuperId>
      <Alias>Jackal</Alias>
    </Geek>
    <Friends></Friends>
    <Birthday>17.10.1983 00:00:00</Birthday>
  </Person>
</root>");

            using (var repository = XmlRepository.Get(RepositoryFor <Person>
                                                      .WithIdentity(p => p.Id)
                                                      .WithDataProvider(prefilledInMemoryProvider)))
            {
                var test = repository.LoadAll();

                Assert.That(repository.LoadAll(), Is.Not.Null);
            }
        }
Beispiel #10
0
 public void SaveOnSubmitNullThrowsArgumentNullException()
 {
     using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
     {
         Assert.Throws <ArgumentNullException>(() => repository.SaveOnSubmit((Person)null));
         Assert.Throws <ArgumentNullException>(() => repository.SaveOnSubmit((IEnumerable <Person>)null));
     }
 }
Beispiel #11
0
 public void SaveOnSubmitMultipleEntitiesSavesTheEntities()
 {
     using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
     {
         repository.SaveOnSubmit(new[] { this._peter, this._golo });
         this.ExecuteLoadAsserts(repository, 2, true, true);
     }
     this.ExecuteLoadAsserts(XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)), 2, true, true);
 }
Beispiel #12
0
 public void SaveOnSubmitAnEntitySavesTheEntity()
 {
     using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
     {
         repository.SaveOnSubmit(this._peter);
         this.ExecuteLoadAsserts(repository, 1, true, false);
     }
     this.ExecuteLoadAsserts(XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)), 1, true, false);
 }
Beispiel #13
0
        public void DeleteOnSubmitWithIdentityThrowsExceptionWhenNoEntityWasFound()
        {
            using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
            {
                repository.SaveOnSubmit(this._peter);
                this.ExecuteLoadAsserts(repository, 1, true, false);

                Assert.Throws <EntityNotFoundException>(() => repository.LoadBy(this._golo.Id));
            }
        }
Beispiel #14
0
        public void LoadByIdentityThrowsExceptionWhenNoEntitiesWereFound()
        {
            using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
            {
                repository.SaveOnSubmit(new[] { this._peter, this._golo });
                this.ExecuteLoadAsserts(repository, 2, true, true);

                Assert.Throws <EntityNotFoundException>(() => repository.LoadBy(Guid.Empty));
            }
        }
Beispiel #15
0
        public void LoadByLambdaThrowsExceptionWhenMoreThanOneEntityWasFound()
        {
            using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
            {
                repository.SaveOnSubmit(new[] { this._peter, this._golo });
                this.ExecuteLoadAsserts(repository, 2, true, true);

                Assert.Throws <EntityNotFoundException>(() => repository.LoadBy(p => true));
            }
        }
Beispiel #16
0
 public void InitializeDataProvider()
 {
     XmlRepository.DataMapper     = new ReflectionDataMapper();
     XmlRepository.DataSerializer = new XmlDataSerializer();
     XmlRepository.DataProvider   = new InMemoryDataProvider();
     using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
     {
         repository.DeleteAllOnSubmit();
     }
 }
Beispiel #17
0
        public void LoadAllByReturnsMultipleMatchingEntitiesWhenMoreThanOneEntityWasFound()
        {
            using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
            {
                repository.SaveOnSubmit(new[] { this._peter, this._golo });
                this.ExecuteLoadAsserts(repository, 2, true, true);

                var multipleEntities = repository.LoadAllBy(p => true);
                Assert.That(multipleEntities.Count(), Is.EqualTo(2));
            }
        }
Beispiel #18
0
        public void LoadAllByReturnsSingleMatchingEntityWhenOnlyOneEntityIsFound()
        {
            using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
            {
                repository.SaveOnSubmit(new[] { this._peter, this._golo });
                this.ExecuteLoadAsserts(repository, 2, true, true);

                var singleEntity = repository.LoadAllBy(p => p.LastName == this._golo.LastName);
                Assert.That(singleEntity.Count(), Is.EqualTo(1));
            }
        }
Beispiel #19
0
        public void LoadAllByReturnsEmptyCollectionWhenNoMatchingEntitiesWereFound()
        {
            using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
            {
                repository.SaveOnSubmit(this._peter);
                this.ExecuteLoadAsserts(repository, 1, true, false);

                var entities = repository.LoadAllBy(p => p.LastName == this._golo.LastName);
                Assert.That(entities.Count(), Is.EqualTo(0));
            }
        }
Beispiel #20
0
 public void DeleteOnSubmitWithIdentityRemovesMatchingEntities()
 {
     using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
     {
         repository.SaveOnSubmit(new[] { this._peter, this._golo });
         this.ExecuteLoadAsserts(repository, 2, true, true);
         repository.DeleteOnSubmit(this._golo.Id);
         this.ExecuteLoadAsserts(repository, 1, true, false);
     }
     this.ExecuteLoadAsserts(XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)), 1, true, false);
 }
Beispiel #21
0
        public void LoadAllReturnsAllEntities()
        {
            using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
            {
                repository.SaveOnSubmit(new[] { this._peter, this._golo });
                this.ExecuteLoadAsserts(repository, 2, true, true);

                var entities = repository.LoadAll();
                Assert.That(entities.Count(), Is.EqualTo(2));
            }
        }
Beispiel #22
0
        public void LoadByIdentityReturnsSingleMatchingEntityWhenOnlyOneEntityWasFound()
        {
            using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
            {
                repository.SaveOnSubmit(new[] { this._peter, this._golo });
                this.ExecuteLoadAsserts(repository, 2, true, true);

                var entities = repository.LoadBy(this._golo.Id);
                Assert.That(entities, Is.Not.Null);
            }
        }
Beispiel #23
0
        public void Get_GetAll_and_Update_should_throw_for_unknown_Type()
        {
            const string file = "\\somefile.xml";

            var repository = new XmlRepository(file, serializationProvider, pathResolver);

            Assert.Throws<InvalidOperationException>(() => repository.Get<MeetingRepository>(0));
            Assert.Throws<InvalidOperationException>(() => repository.GetAll<MeetingRepository>());
            Assert.Throws<InvalidOperationException>(() => repository.Update("", 0));

            new FileInfo(file).Delete();
        }
Beispiel #24
0
        public void ANewlyCreatedRepositoryWithNoDefaultQueryPropertySetInferesItFromTheLambdaExpression()
        {
            using (var repository = XmlRepository.Get(RepositoryFor <Geek> .WithIdentity(g => g.SuperId)))
            {
                repository.SaveOnSubmit(new Geek {
                    SuperId = "PeterId"
                });
                repository.SubmitChanges();

                var test = repository.LoadBy("PeterId");

                Assert.That(test.SuperId, Is.EqualTo("PeterId"));
            }
        }
Beispiel #25
0
        public void RunningLinqQueriesReturnsAllMatchingEntities()
        {
            using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
            {
                repository.SaveOnSubmit(new[] { this._peter, this._golo });
                this.ExecuteLoadAsserts(repository, 2, true, true);
            }

            var firstName =
                (from p in XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id))
                 where p.LastName == this._peter.LastName
                 select p.FirstName).Single();

            Assert.That(firstName, Is.EqualTo(this._peter.FirstName));
        }
Beispiel #26
0
 public void DiscardChangesRemovesNonSubmittedChanges()
 {
     using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
     {
         repository.SaveOnSubmit(this._peter);
         this.ExecuteLoadAsserts(repository, 1, true, false);
         repository.SubmitChanges();
         this.ExecuteLoadAsserts(repository, 1, true, false);
         repository.SaveOnSubmit(this._golo);
         this.ExecuteLoadAsserts(repository, 2, true, true);
         repository.DiscardChanges();
         this.ExecuteLoadAsserts(repository, 1, true, false);
     }
     this.ExecuteLoadAsserts(XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)), 1, true, false);
 }
Beispiel #27
0
        public void GetEnumeratorReturnsAnEnumerator()
        {
            using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id)))
            {
                repository.SaveOnSubmit(new[] { this._peter, this._golo });
                this.ExecuteLoadAsserts(repository, 2, true, true);

                int count = 0;
                foreach (var person in repository)
                {
                    Assert.That(person.Id, Is.Not.EqualTo(Guid.Empty));
                    count++;
                }
                Assert.That(count, Is.EqualTo(2));
            }
        }
Beispiel #28
0
        public void SupportOneToManyAndManyToOneThroughtInteractionOfMultipleRepositoriesWithinARepository()
        {
            var articleInBothCategories = new Article
            {
                Title = "Lambda auf Abwegen"
            };

            var articlesOne = new List <Article>
            {
                articleInBothCategories,
                new Article {
                    Title = "Frs Gemht"
                },
                new Article {
                    Title = "Schlechter aber rechter"
                }
            };

            var articlesTwo = new List <Article>
            {
                new Article {
                    Title = "Test Artikel"
                },
                articleInBothCategories,
                new Article {
                    Title = "Kren fllen"
                }
            };

            var categoryOne = new ArticleCategory
            {
                Name = "One"
            };

            using (var repository = XmlRepository.Get(RepositoryFor <ArticleCategory>
                                                      .WithIdentity(c => c.Id)
                                                      .WithDataProvider(new FileDataProvider(Environment.CurrentDirectory, ".xml"))))
            {
                categoryOne.Articles = articlesOne;

                repository.SaveOnSubmit(categoryOne);
                repository.SubmitChanges();

                var data = repository.LoadAll();
            }
        }
        public void Add_ShouldAddsEntity_WhenIdIsUnique()
        {
            string fileName = Guid.NewGuid().ToString("N") + ".xml";

            Guid       entityId = Guid.NewGuid();
            FakeEntity entity   = new FakeEntity()
            {
                Id = entityId, Name = entityId.ToString()
            };
            XmlRepository <FakeEntity> repository = new XmlRepository <FakeEntity>(fileName);

            repository.Add(entity);
            repository.SaveChanges();

            repository = new XmlRepository <FakeEntity>(fileName);
            entity     = repository.Get(entityId);

            Assert.AreEqual(entityId.ToString(), entity.Name);
            File.Delete(fileName);
        }
Beispiel #30
0
        public void RepositoryCanBeInstantiatedOnAllWaysWithoutReturningNullOrExceptionThrown()
        {
            var one = XmlRepository.Get(
                RepositoryFor <Person> .WithIdentity(p => p.Id));

            var two = XmlRepository.Get(RepositoryFor <Person>
                                        .WithIdentity(p => p.Id)
                                        .WithMappings(new Dictionary <Type, IList <IPropertyMapping> >()));

            var three = XmlRepository.Get(RepositoryFor <Person>
                                          .WithIdentity(p => p.Id)
                                          .WithDataProvider(new InMemoryDataProvider()));

            var four = XmlRepository.Get(RepositoryFor <Person>
                                         .WithIdentity(p => p.Id)
                                         .WithMappings(new Dictionary <Type, IList <IPropertyMapping> >())
                                         .WithDataProvider(new InMemoryDataProvider()));

            Assert.That(one, Is.Not.Null);
            Assert.That(two, Is.Not.Null);
            Assert.That(three, Is.Not.Null);
            Assert.That(four, Is.Not.Null);
        }