Skip to content

Instantly share code, notes, and snippets.

@shiftkey
shiftkey / gist:1256866
Created October 2, 2011 00:31
WinRT doesn't like field names being similar
public class MyClass
{
private string mystring;
private string myString;
}
// reports an error when creating a WinRT library:
// Field names cannot differ only by case: 'MyClass.mystring' , 'MyClass.myString'.
public class MyClass
@shiftkey
shiftkey / gist:1257069
Created October 2, 2011 04:57
Windows Runtime and Constructor/Method Overloads
// ..
public CustomException(MyClass error)
: this(error.Message, error, null, null)
{
}
public CustomException(MyClass error, Exception innerException, Uri url)
: this(error.Message, error, innerException, url)
@shiftkey
shiftkey / gist:1274786
Created October 10, 2011 07:03
This is why you don't use DateTime
[TestMethod]
public void Subtract_WhenUsingDifferentTimeZones_AreEqual()
{
// working from my local timezone of +10
var myTime = new DateTime(2011, 10, 10, 18, 0, 0, 0, DateTimeKind.Local);
var utcTime = new DateTime(2011, 10, 10, 8, 0, 0, 0, DateTimeKind.Utc);
var difference = myTime - utcTime;
Assert.AreEqual(TimeSpan.Zero, difference); // we get 10 hours here
@shiftkey
shiftkey / test.cs
Created October 13, 2011 02:07 — forked from anonymous/test.cs
Good test/ bad test?
[TestMethod]
public void GetContextId_OnSecondRun_ReturnsStoredContextId() // "should" is a grey phrase
{
const string firstId = "200"; // context is used a lot in the test - removed here
const string secondId = "400"; // and i isolate these from my arrange for readability
// arrange
var record = new ContextRecord();
fakeRecordGenerator.Generate().Returns(record); // overuse of "Record" in here? necessary?
fakeContextService.CreateContext(record).Returns(firstId);
@shiftkey
shiftkey / gist:1283196
Created October 13, 2011 02:37
Experiment with alternative syntax to ?? and ? :
public int Floor(int value)
{
return value.Unless(v => v < 0, () => 0);
}
public static T Unless<T>(this T obj, Func<T, bool> term, Func<T> result)
{
if (term(obj))
return result();
@shiftkey
shiftkey / gist:1321405
Created October 28, 2011 01:27
DbUp Setup Changes
Version 1:
var upgrader = new DatabaseUpgrader(
Settings.Default.MyDbConnectionString,
new EmbeddedScriptProvider(typeof(Program).Assembly)
);
Version 2:
Func<IDbConnection> connectionFactory = () => new SqlConnection(Settings.Default.Database);
@shiftkey
shiftkey / gist:1321532
Created October 28, 2011 03:07
MEF vNext Registration for ASP.NET MVC 3
// add these namespaces for MEF
using System.ComponentModel.Composition.Registration;
using System.ComponentModel.Composition.Web.Mvc;
protected void Application_Start()
{
var assemblies = new List<Assembly> { typeof(MvcApplication).Assembly };
var catalog = new MvcApplicationCatalog(assemblies); // in-built conventions
CompositionProvider.SetCatalog(catalog);
@shiftkey
shiftkey / gist:1321588
Created October 28, 2011 03:58
Repro - Open Generics Not Supported in MEF v2 Preview 4?
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition.Registration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace System.ComponentModel.Composition
{
[TestClass]
public class RegistrationBuilderTestBF
{
public interface IRepository<out T> {
@shiftkey
shiftkey / AppBootstrapper.cs
Created November 10, 2011 00:20
Using an AutofacBootstrapper in a Silverlight Application
using Autofac;
using Caliburn.Micro.Autofac;
namespace SampleApplication
{
public class AppBootstrapper : AutofacBootstrapper<IShell>
{
protected override void ConfigureContainer(ContainerBuilder builder)
{
var thisAssembly = typeof(App).Assembly;
@shiftkey
shiftkey / App.xaml.cs
Created November 10, 2011 00:23
Registering the bootstrapper in a Silverlight Application
public App()
{
Startup += Application_Startup;
Exit += Application_Exit;
UnhandledException += Application_UnhandledException;
var bootstrapper = new AppBootstrapper();
Resources.Add("Bootstrapper", bootstrapper);
InitializeComponent();