Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickchampion/54fe02ce54b4c7315ef87d678b4fb94c to your computer and use it in GitHub Desktop.
Save nickchampion/54fe02ce54b4c7315ef87d678b4fb94c to your computer and use it in GitHub Desktop.
using System;
using NUnit.Framework;
using Raven.Abstractions.Replication;
using Raven.Client;
using Raven.Client.Document;
namespace Marketplace.Tests.Unit
{
[TestFixture]
public class RavenFailingTest
{
[Test]
public void CanLoadAndSaveUser()
{
var store = GetStore();
var id = Guid.NewGuid().ToString();
using (var session = store.OpenSession(new OpenSessionOptions
{
Database = "Marketplace",
ForceReadFromMaster = true
}))
{
session.Store(new TestUser
{
Id = id,
FirstName = "Nick",
LastName = "Test",
Email = "test@email.com"
});
session.SaveChanges();
}
using (var session = store.OpenSession(new OpenSessionOptions
{
Database = "Marketplace",
ForceReadFromMaster = true
}))
{
session.Advanced.UseOptimisticConcurrency = true;
var user = session.Load<TestUser>(id);
user.LastName = Guid.NewGuid().ToString();
session.SaveChanges();
}
store.Dispose();
}
private IDocumentStore GetStore()
{
var store = new DocumentStore
{
Url = "",
ApiKey = null,
ResourceManagerId = Guid.NewGuid(),
EnlistInDistributedTransactions = false,
Conventions =
{
IndexAndTransformerReplicationMode = IndexAndTransformerReplicationMode.Indexes | IndexAndTransformerReplicationMode.Transformers,
FailoverBehavior = FailoverBehavior.ReadFromAllWriteToLeaderWithFailovers
}
};
store.Initialize();
return store;
}
}
public class TestUser
{
public string Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment