Skip to content

Instantly share code, notes, and snippets.

@ayende
Created May 23, 2013 08:28
Show Gist options
  • Select an option

  • Save ayende/5633507 to your computer and use it in GitHub Desktop.

Select an option

Save ayende/5633507 to your computer and use it in GitHub Desktop.
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