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(); } }
public void ANewlyCreatedRepositoryDoesNotContainAnyEntities() { using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id))) { this.ExecuteLoadAsserts(repository, 0, false, false); } }
public void LoadByNullThrowsArgumentNullException() { using (var repository = XmlRepository.Get(RepositoryFor <Person> .WithIdentity(p => p.Id))) { Assert.Throws <ArgumentNullException>(() => repository.LoadBy(null)); } }
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")); } }
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)); }
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 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); } }
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)); } }
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); }
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); }
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)); } }
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)); } }
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)); } }
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(); } }
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); } }
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)); } }
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)); } }
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)); } }
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)); } }
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); }
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")); } }
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); }
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)); }
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)); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); this._userMappings = new Dictionary <Type, IList <IPropertyMapping> >(); this._mappedRepository = XmlRepository .XmlRepository .Get( RepositoryFor <Article> .WithIdentity(p => p.Id) .WithMappings(this._userMappings) .WithDataProvider(new InMemoryDataProvider(this.txtDefault.Text))); this.LoadMappingList(true); }
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(); } }
private void txtDefault_TextChanged(object sender, EventArgs e) { var defaultRepository = XmlRepository.XmlRepository.Get(RepositoryFor <Article> .WithIdentity(a => a.Id) .WithDataProvider( new InMemoryDataProvider( this.txtDefault.Text))); string test = defaultRepository.GetXmlRepresentation().ToString(); defaultRepository.DiscardChanges(); var articleList = defaultRepository.LoadAll(); this._mappedRepository.DataProvider = new InMemoryDataProvider(); this._mappedRepository.SaveOnSubmit(articleList); this.txtMapped.Text = this._mappedRepository.GetXmlRepresentation().ToString(); this._mappedRepository.DiscardChanges(); }
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); }