Created
November 21, 2012 03:09
-
-
Save mattjohnsonpint/4122775 to your computer and use it in GitHub Desktop.
Tests showing issue with .Any
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
using Raven.Client.Embedded; | |
using Xunit; | |
namespace RavenTests | |
{ | |
public class Tests | |
{ | |
[Fact] | |
public void Test1() | |
{ | |
var documentStore = new EmbeddableDocumentStore { RunInMemory = true }; | |
documentStore.Initialize(); | |
using (var session = documentStore.OpenSession()) | |
{ | |
session.Store( | |
new ResourceEntry { | |
Key = "helloworld", | |
Text = "hello world", | |
Translations = new[] { | |
new ResourceEntry.Translation { CultureCode = "es-ES", Text = "hola mundo" }, | |
new ResourceEntry.Translation { CultureCode = "de-DE", Text = "hallo welt" }, | |
new ResourceEntry.Translation { CultureCode = "fr-FR", Text = "bonjour tout le monde" } | |
} | |
}); | |
session.SaveChanges(); | |
} | |
using (var session = documentStore.OpenSession()) | |
{ | |
var nonTranslatedEntries = | |
session.Query<ResourceEntry>() | |
.Customize(x => x.WaitForNonStaleResults()) | |
.Where(e => e.Translations == null || | |
!e.Translations.Any(t => t.CultureCode == "es-ES" && t.Text != null)) | |
.ToList(); | |
Assert.Equal(0, nonTranslatedEntries.Count); | |
} | |
} | |
[Fact] | |
public void Test2() | |
{ | |
var documentStore = new EmbeddableDocumentStore { RunInMemory = true }; | |
documentStore.Initialize(); | |
using (var session = documentStore.OpenSession()) | |
{ | |
session.Store( | |
new ResourceEntry { | |
Key = "helloworld", | |
Text = "hello world", | |
Translations = new[] { | |
new ResourceEntry.Translation { CultureCode = "es-ES", Text = "hola mundo" } | |
} | |
}); | |
session.SaveChanges(); | |
} | |
using (var session = documentStore.OpenSession()) | |
{ | |
var nonTranslatedEntries = | |
session.Query<ResourceEntry>() | |
.Customize(x => x.WaitForNonStaleResults()) | |
.Where(e => e.Translations == null || | |
!e.Translations.Any(t => t.CultureCode == "es-ES" && t.Text != null)) | |
.ToList(); | |
Assert.Equal(0, nonTranslatedEntries.Count); | |
} | |
} | |
[Fact] | |
public void Test3() | |
{ | |
var documentStore = new EmbeddableDocumentStore { RunInMemory = true }; | |
documentStore.Initialize(); | |
using (var session = documentStore.OpenSession()) | |
{ | |
session.Store( | |
new ResourceEntry { | |
Key = "helloworld", | |
Text = "hello world", | |
Translations = new[] { | |
new ResourceEntry.Translation { CultureCode = "es-ES", Text = null }, | |
new ResourceEntry.Translation { CultureCode = "de-DE", Text = "hallo welt" }, | |
new ResourceEntry.Translation { CultureCode = "fr-FR", Text = "bonjour tout le monde" } | |
} | |
}); | |
session.SaveChanges(); | |
} | |
using (var session = documentStore.OpenSession()) | |
{ | |
var nonTranslatedEntries = | |
session.Query<ResourceEntry>() | |
.Customize(x => x.WaitForNonStaleResults()) | |
.Where(e => e.Translations == null || | |
!e.Translations.Any(t => t.CultureCode == "es-ES" && t.Text != null)) | |
.ToList(); | |
Assert.Equal(1, nonTranslatedEntries.Count); | |
} | |
} | |
[Fact] | |
public void Test4() | |
{ | |
var documentStore = new EmbeddableDocumentStore { RunInMemory = true }; | |
documentStore.Initialize(); | |
using (var session = documentStore.OpenSession()) | |
{ | |
session.Store( | |
new ResourceEntry { | |
Key = "helloworld", | |
Text = "hello world", | |
Translations = new[] { | |
new ResourceEntry.Translation { CultureCode = "de-DE", Text = "hallo welt" }, | |
new ResourceEntry.Translation { CultureCode = "fr-FR", Text = "bonjour tout le monde" } | |
} | |
}); | |
session.SaveChanges(); | |
} | |
using (var session = documentStore.OpenSession()) | |
{ | |
var nonTranslatedEntries = | |
session.Query<ResourceEntry>() | |
.Customize(x => x.WaitForNonStaleResults()) | |
.Where(e => e.Translations == null || | |
!e.Translations.Any(t => t.CultureCode == "es-ES" && t.Text != null)) | |
.ToList(); | |
Assert.Equal(1, nonTranslatedEntries.Count); | |
} | |
} | |
public class ResourceEntry | |
{ | |
public string Key { get; set; } | |
public string Text { get; set; } | |
public IList<Translation> Translations { get; set; } | |
public class Translation | |
{ | |
public string CultureCode { get; set; } | |
public string Text { get; set; } | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment