Skip to content

Instantly share code, notes, and snippets.

@felipeleusin
Created January 18, 2013 12:54
Show Gist options
  • Save felipeleusin/4564384 to your computer and use it in GitHub Desktop.
Save felipeleusin/4564384 to your computer and use it in GitHub Desktop.
Raven example using property-based Id
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Raven.Tests.Helpers;
using Xunit;
namespace ClassLibrary4
{
public class User
{
public string Id
{
get { return "users/" + Email.ToLowerInvariant(); }
}
public string Email { get; set; }
public string Name { get; set; }
}
public class UserAsyncTests : RavenTestBase
{
[Fact]
public async Task CanLoadAsync()
{
using (var store = NewDocumentStore())
{
using (var session = store.OpenAsyncSession())
{
session.Store(new User() {Name = "Foo", Email = "fulano@fulano.com"});
await session.SaveChangesAsync();
}
using (var session = store.OpenAsyncSession())
{
var user = await session.LoadAsync<User>("users/fulano@fulano.com");
Assert.NotNull(user);
Assert.Equal(user.Id, "users/" + user.Email);
Assert.Equal("Foo", user.Name);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment