Skip to content

Instantly share code, notes, and snippets.

View bradoyler's full-sized avatar
👋
say hi

brad oyler bradoyler

👋
say hi
View GitHub Profile
@bradoyler
bradoyler / Authentication.cs
Created November 23, 2012 17:43
Unit/Integration Testing MVC with RavenDb (using MS Test)
using System.Security.Principal;
namespace MyApp.Models.Authentication
{
public class CustomIdentity : GenericIdentity, ICustomIdentity
{
public CustomIdentity(string userId, string displayName)
: base(string.IsNullOrEmpty(displayName) ? string.Empty : displayName, "Forms")
{
UserId = userId;
@bradoyler
bradoyler / controller.cs
Created November 24, 2012 05:35
RavenDB setup for MVC controller
public IDocumentSession session { get; protected set; }
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
session = MvcApplication.Store.OpenSession();
}
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
if (filterContext.IsChildAction)
return;
@bradoyler
bradoyler / HttpContextFactory.cs
Created November 28, 2012 21:05
A way to get a HttpContext that is able to be mocked out via HttpContextBase
public class HttpContextFactory
{
private static HttpContextBase context;
public HttpContextFactory() {}
public void setHttpContext(HttpContextBase c)
{
context = c;
}
@bradoyler
bradoyler / gist:4192338
Created December 3, 2012 03:02
IoC container for RavenDB within MemFlex project
using System;
using System.Configuration;
using System.Linq;
using System.Web.Mvc;
using FlexProviders.Aspnet;
using FlexProviders.Membership;
using FlexProviders.Raven;
using FlexProviders.Roles;
using LogMeIn.Models;
using Raven.Client;
x.ForSingletonOf<IDocumentStore>().Use(() => {
var ds= new DocumentStore();
ds.ConnectionStringName = "Raven";
ds.Initialize();
return ds;
});
x.For<IDocumentSession>().HybridHttpOrThreadLocalScoped().Use(ctx =>
{
return ctx.GetInstance<IDocumentStore>().OpenSession();
@bradoyler
bradoyler / HomeController.cs
Created December 7, 2012 14:30
Simple example Controller for RavenDB using StructureMap
private readonly IDocumentSession session;
public HomeController(IDocumentSession s)
{
session = s;
}
public ActionResult Index()
{
var tempObject = Tuple.Create("Hello World!", DateTime.Now);
@bradoyler
bradoyler / PeopleIndex.cs
Created December 11, 2012 19:36
Multi-map index creation with RavenDB
public class PeopleIndex : AbstractMultiMapIndexCreationTask
{
public PeopleIndex()
{
AddMap<User>(users => from user in users select new { user.Name });
AddMap<Person>(p => from person in p select new { person.Name });
}
}
@bradoyler
bradoyler / PeopleController.cs
Created December 11, 2012 19:40
Querying multi-map index from MVC Controller using dynamics
private IDocumentSession _session;
public PeopleController(IDocumentSession session)
{
_session = session;
}
public ActionResult Index()
{ // insert a User & a Person into RavenDB
_session.Store(new User { Email = "user@domain.co", Name = "user 1", UserName = "user1" });
_session.Store(new Person { Email = "person@domain.co", Name = "person 1", PersonName = "person1" });
@bradoyler
bradoyler / Models.cs
Created December 11, 2012 19:48
the User and People Models
public class User
{
public string Name { get; set; }
public string Email { get; set; }
public string UserName { get; set; }
}
public class Person
{
public string Name { get; set; }
@bradoyler
bradoyler / gist:4269238
Created December 12, 2012 16:24
Joining a table to a large List<int> using LINQ
List<int> contactIds=MyContactIds() //count of contactIds is more than 2100 rows
var profiles = db.Profiles.AsEnumerable()
.Join(contactIds, p => p.ContactId, ci => ci, (p, ci) => p)
.ToList();