Skip to content

Instantly share code, notes, and snippets.

@kijanawoodard
Created July 20, 2012 20:16
Show Gist options
  • Save kijanawoodard/3152992 to your computer and use it in GitHub Desktop.
Save kijanawoodard/3152992 to your computer and use it in GitHub Desktop.
SectionWithTagNameIndexFailingTest
using System;
using System.Collections.Generic;
using System.Linq;
using Raven.Abstractions.Indexing;
using Raven.Client;
using Raven.Client.Embedded;
using Raven.Client.Indexes;
using Raven.Client.Linq;
using Xunit;
namespace RavenIssues
{
public class SectionWithTagNameIndexFailingTest
{
public IDocumentStore DocumentStore { get; set; }
public IDocumentSession DocumentSession { get; set; }
public SectionWithTagNameIndexFailingTest()
{
DocumentStore = new EmbeddableDocumentStore(){RunInMemory = true};
DocumentStore.Initialize();
IndexCreation.CreateIndexes(typeof(SectionWithTagNameIndexFailing).Assembly, DocumentStore);
using (var session = DocumentStore.OpenSession())
{
var tag = new Tag();
tag.Name = "test";
tag.IsChildFriendly = false;
session.Store(tag);
var section = new OnlineStoreSection();
section.Audience = new TargetAudience();
section.Audience.Ages = new[] { 1, 2, 3, 4, 5 };
section.Audience.Sexes = new[] { "Male", "Female", "Unsure" };
section.Tags = new string[] { tag.Id };
session.Store(section);
session.SaveChanges();
}
}
[Fact]
public void Should_Give_Me_AllMales()
{
using (var session = DocumentStore.OpenSession())
{
var results = session.Query<OnlineStoreSection, SectionWithTagNameIndexFailing>()
.Customize(x => x.WaitForNonStaleResults())
.Where(x => x.Audience.Sexes.Any(s => s == "Male"))
.ToList();
Assert.NotNull(results);
Assert.Equal(1, results.Count());
var first = results.First();
Assert.Contains("tags/1", first.Tags);
}
}
public class SectionWithTagNameIndexFailing : AbstractIndexCreationTask<OnlineStoreSection>
{
public SectionWithTagNameIndexFailing()
{
Map = results => from result in results
select new
{
Audience_Sexes = result.Audience.Sexes,
Audience_Ages = result.Audience.Ages,
result.CreatedOn,
result.Id,
result.LocationId,
result.OnlineStoreId,
result.Tags,
result.Url
};
Indexes.Add(a => a.Audience.Sexes, FieldIndexing.Analyzed);
}
}
public class Tag
{
public string Id { get; set; }
public string Name { get; set; }
public bool IsChildFriendly { get; set; }
}
public class OnlineStoreSection
{
public string Id { get; set; }
public DateTime CreatedOn { get; set; }
public string OnlineStoreId { get; set; }
public string LocationId { get; set; }
public ICollection<string> Tags { get; set; }
public string Url { get; set; }
public TargetAudience Audience { get; set; }
}
public class TargetAudience
{
public IEnumerable<string> Sexes { get; set; }
public IEnumerable<int> Ages { get; set; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment