Skip to content
Browse files

Added a failing test to demonstrate failing ad hoc projection

  • Loading branch information...
1 parent dbf60ee commit 11425e3c7324a353829930aedd3a5105f19c3eca @ArnoldZokas ArnoldZokas committed Jan 21, 2012
Showing with 70 additions and 0 deletions.
  1. +69 −0 Raven.Tests/Bugs/AdHocProjections.cs
  2. +1 −0 Raven.Tests/Raven.Tests.csproj
View
69 Raven.Tests/Bugs/AdHocProjections.cs
@@ -0,0 +1,69 @@
+using System.Linq;
+using Xunit;
+
+namespace Raven.Tests.Bugs
+{
+ public class AdHocProjections : LocalClientTest
+ {
+ [Fact]
+ public void Query_can_project_to_a_different_model()
+ {
+ using (var documentStore = NewDocumentStore())
+ {
+ using (var session = documentStore.OpenSession())
+ {
+ session.Store(new Entity
+ {
+ Id = 1,
+ Category = new Category { Title = "Category Title" }
+ });
+
+ session.SaveChanges();
+ }
+
+ using (var session = documentStore.OpenSession())
+ {
+ var viewModel = (from entity in session.Query<Entity>()
+ select new EntityViewModel
+ {
+ Id = entity.Id,
+ CategoryTitle = entity.Category.Title
+ }).SingleOrDefault();
+
+ Assert.NotNull(viewModel);
+ Assert.Equal(1, viewModel.Id);
+ Assert.Equal("Category Title", viewModel.CategoryTitle);
+ }
+ }
+ }
+
+ #region Nested type: Category
+
+ public class Category
+ {
+ public string Title { get; set; }
+ }
+
+ #endregion
+
+ #region Nested type: Entity
+
+ public class Entity
+ {
+ public int Id { get; set; }
+ public Category Category { get; set; }
+ }
+
+ #endregion
+
+ #region Nested type: EntityViewModel
+
+ public class EntityViewModel
+ {
+ public int Id { get; set; }
+ public string CategoryTitle { get; set; }
+ }
+
+ #endregion
+ }
+}
View
1 Raven.Tests/Raven.Tests.csproj
@@ -159,6 +159,7 @@
</Compile>
<Compile Include="Bugs\Account.cs" />
<Compile Include="Bugs\AccurateCount.cs" />
+ <Compile Include="Bugs\AdHocProjections.cs" />
<Compile Include="Bugs\AfterDeletingTheIndexStopsBeingStale.cs" />
<Compile Include="Bugs\AggressiveCaching.cs" />
<Compile Include="Bugs\AnalyzerPerField.cs" />

0 comments on commit 11425e3

Please sign in to comment.
Something went wrong with that request. Please try again.