public void Can_replicate_to_sql_when_document_is_updated()
{
CreateRdbmsSchema();
using (var session = documentStore.OpenSession())
{
session.Store(new IndexReplicationDestination
{
Id = "Raven/IndexReplication/Questions/Votes",
ColumnsMapping =
{
{"Title", "Title"},
{"UpVotes", "UpVotes"},
{"DownVotes", "DownVotes"},
{"Date", "Date"},
},
ConnectionStringName = ConnectionString.Name,
PrimaryKeyColumnName = "Id",
TableName = "QuestionSummaries"
});
session.SaveChanges();
}
using (var session = documentStore.OpenSession())
{
var q = new Question
{
Id = "questions/1",
Title = "How to replicate to SQL Server?",
Votes = new[]
{
new Vote{ Up = true, Comment = "Good!"},
new Vote{ Up = false, Comment = "Nah!"},
new Vote{ Up = true, Comment = "Nice..."},
}
};
session.Store(q);
session.SaveChanges();
}
using (var session = documentStore.OpenSession())
{
session.Advanced.LuceneQuery<Question>("Questions/Votes")
.WaitForNonStaleResults()
.SelectFields<QuestionSummary>("__document_id", "Title", "UpVotes", "DownVotes")
.ToList();
}
using (var session = documentStore.OpenSession())
{
var q = new Question
{
Id = "questions/1",
Title = "How to replicate to SQL Server!?",
Votes = new[]
{
new Vote{ Up = true, Comment = "Good!"},
new Vote{ Up = false, Comment = "Nah!"},
new Vote{ Up = true, Comment = "Nice..."},
new Vote{ Up = false, Comment = "No!"},
}
};
session.Store(q);
session.SaveChanges();
}
using (var session = documentStore.OpenSession())
{
session.Advanced.LuceneQuery<Question>("Questions/Votes")
.WaitForNonStaleResults()
.SelectFields<QuestionSummary>("__document_id", "Title", "UpVotes", "DownVotes")
.ToList();
}
var providerFactory = DbProviderFactories.GetFactory(ConnectionString.ProviderName);
using (var con = providerFactory.CreateConnection())
{
con.ConnectionString = ConnectionString.ConnectionString;
con.Open();
using (var dbCommand = con.CreateCommand())
{
dbCommand.CommandText = "SELECT * FROM QuestionSummaries";
using (var reader = dbCommand.ExecuteReader())
{
Assert.True(reader.Read());
Assert.Equal("questions/1", reader["Id"]);
Assert.Equal("How to replicate to SQL Server!?", reader["Title"]);
Assert.Equal(2, reader["UpVotes"]);
Assert.Equal(2, reader["DownVotes"]);
Assert.Equal(new DateTime(2000,1,1), reader["Date"]);
}
}
}
}