Created
May 23, 2013 08:28
-
-
Save ayende/5633507 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Linq; | |
| using Raven.Abstractions.Smuggler; | |
| using Raven.Client.Indexes; | |
| using Raven.Database.Smuggler; | |
| using Raven.Tests.Helpers; | |
| using Xunit; | |
| namespace RavenTests | |
| { | |
| public class ConcurrencyTests : RavenTestBase | |
| { | |
| [Fact] | |
| public void CanSaveImplicitChangesToDocumentsFromAQuery_UsingDunpFile() | |
| { | |
| using (var store = NewDocumentStore()) | |
| { | |
| new Sections().Execute(store); | |
| using (var session = store.OpenSession()) | |
| { | |
| session.Store(new SectionData{Id = "sections/1", Referencing = null}); | |
| session.Store(new SectionData { Id = "sections/2", Referencing = "sections/1" }); | |
| session.SaveChanges(); | |
| } | |
| WaitForIndexing(store); | |
| using (var session = store.OpenSession()) | |
| { | |
| session.Advanced.UseOptimisticConcurrency = true; | |
| var foos = session.Query<SectionData>().ToList(); | |
| foreach (var sectionData in foos) | |
| { | |
| sectionData.Count++; | |
| } | |
| session.SaveChanges(); | |
| } | |
| } | |
| } | |
| public class SectionData | |
| { | |
| public string Id { get; set; } | |
| public string Referencing { get; set; } | |
| public int Count { get; set; } | |
| } | |
| public class Sections : AbstractIndexCreationTask<SectionData> | |
| { | |
| public Sections() | |
| { | |
| Map = datas => | |
| from data in datas | |
| select new | |
| { | |
| _ = LoadDocument<SectionData>(data.Referencing) | |
| }; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment