Skip to content

Instantly share code, notes, and snippets.

View chrisnicola's full-sized avatar

Chris Nicola chrisnicola

View GitHub Profile
protected static HttpPostedFileBase MockFileUpload(ControllerBase controller)
{
var request = MockRepository.GenerateStub<HttpRequestBase>();
var context = MockRepository.GenerateStub<HttpContextBase>();
var server = MockRepository.GenerateStub<HttpServerUtilityBase>();
var postedfile = MockRepository.GenerateMock<HttpPostedFileBase>();
var postedfilesKeyCollection = MockRepository.GenerateStub<HttpFileCollectionBase>();
var fakeFileKeys = new List<string> { "image", "file" };
context.Stub(ctx => ctx.Request).Return(request);
context.Stub(ctx => ctx.Server).Return(server);
@chrisnicola
chrisnicola / rrbug.cs
Created May 2, 2010 20:10
Restful routning bug
//This is the route definition
public class Routes : RouteSet{
public Routes() {
Map("").To<HomeController>(x => x.Index());
Area<HomeController>("", () =>
Map("").To<HomeController>(x => x.Index()));
Map("rss").To<FeedController>(x => x.Rss());
Map("atom").To<FeedController>(x => x.Atom());
Resources<PostController>(
() => {
<% using (Html.BeginForm("Create", "Login")) {%>
//Creates
<form action="/login/create" method="post">
<% using (Html.BeginForm<LoginController>(x => x.Create(Model))) {%>
//Creates
<form action="/Login/Create?model=Graphite.Web.Controllers.Login.LoginViewModel" method="post">
public abstract class DomainEventTestBase<T> : IEventHandler<T> where T : DomainEvent
{
protected T Result;
protected InProcessEventBus DomainEventBus;
#region IEventHandler<T> Members
public void Handle(T evnt)
{
Result = evnt;
00000000000000000003
5b406bc7-2f68-4e97-bfe2-75e179571b31;634163655158954274;Ncqrs.Eventing.Storage.NoDB.Tests.Fakes.CustomerCreatedEvent, Ncqrs.Eventing.Storage.NoDB.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null;1.0;adc02213-cde3-4eaf-942e-1ef4d5adb406;0;{ "Name": "Foo", "Age": 35}
59e9e60b-dba5-4b96-97a2-90ae64b17e48;634163655158974275;Ncqrs.Eventing.Storage.NoDB.Tests.Fakes.CustomerNameChanged, Ncqrs.Eventing.Storage.NoDB.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null;1.0;adc02213-cde3-4eaf-942e-1ef4d5adb406;1;{ "CustomerId": "adc02213-cde3-4eaf-942e-1ef4d5adb406", "NewName": "Name2"}
df092cec-9857-4f6c-b6ff-32110ebc0d75;634163655158984276;Ncqrs.Eventing.Storage.NoDB.Tests.Fakes.CustomerNameChanged, Ncqrs.Eventing.Storage.NoDB.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null;1.0;adc02213-cde3-4eaf-942e-1ef4d5adb406;2;{ "CustomerId": "adc02213-cde3-4eaf-942e-1ef4d5adb406", "NewName": "Name3"}
// ==UserScript==
// @author Chris
// @co-author None
// @name Timer
// @namespace myTest
// @description eRepublik Advanced Tools
// @version 1.0.0
// @include *
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==
//Apply selector to a random subset of source of size count and return the results
public static class ExtensionHelpers {
public static IEnumerable<TOut> SelectRandom<TSource, TOut>(this IEnumerable<TSource> source,
Func<TSource, TOut> selector,
int count) {
var rand = new Random((int) (DateTime.Now.Ticks % int.MaxValue));
for (var i = 0; i < count; i++)
yield return selector(source.ElementAt(rand.Next(source.Count())));
}
}
using System;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;
namespace Presentation.Helpers {
public static class TreeViewitemFinder {
public static TreeViewItem BringTreeViewItemIntoView(this TreeView treeView, TreeViewItemModel item) {
if (item == null) return null;
@chrisnicola
chrisnicola / DynamicExamples.cs
Created January 19, 2011 03:59
Some examples of how the dynamic keyword works
[Fact]
public void cant_pass_base_class_to_function_dynamically()
{
dynamic handler = new MessageHandler();
IMessage message = new Message();
handler.Handle(message);
}
[Fact]
public void can_pass_base_class_to_function_via_reflection()
using (OpenRastaConfiguration.Manual)
{
ResourceSpace.Has.ResourcesOfType<RetailStream>()
.AtUri("/streams/{id}").And.AtUri("/streams")
.HandledBy<RetailStreamHandler>()
.TranscodedBy<JsonRestCodec>().And.;
ResourceSpace.Has.ResourcesOfType<RetailStreamListItem[]>()
.AtUri("/streams")
.HandledBy<RetailStreamHandler>()