Skip to content

Instantly share code, notes, and snippets.

View DavidSSL's full-sized avatar
💭
Set the status

DavidSSL

💭
Set the status
View GitHub Profile
using System.Web.Mvc;
using FakeItEasy;
using Machine.Specifications;
using Machine.Specifications.Mvc;
using MSpecMvcApplication.Controllers;
namespace MSpecMvcApplication.Tests.Controllers
{
[Subject(typeof(HomeController))]
public class when_the_home_controller_is_told_to_display_the_default_view
SELECT
dataInt -- this is the "Content" node id
FROM [someTable].[dbo].[cmsPropertyData] PD
INNER JOIN cmsMember mb on PD.contentNodeId = mb.nodeId
WHERE LoginName = 'someLoginName'
AND dataInt IS NOT NULL
AND PD.propertyTypeId = the document type id of the "Content" node (see cmsPropertyType table)
@DavidSSL
DavidSSL / TryCatch
Created September 21, 2012 20:07
Basic try catch block
try
{
//Code to perform some operation which could raise an exception
}
catch
{
//Code to handle any exception that occurred in the try block
}
@DavidSSL
DavidSSL / AnotherTryCatch
Created September 21, 2012 20:10
Another try catch
try
{
//Code to perform some operation
}
catch
{
//Code to handle any exception that occurred in the try block
// No throw statement
}
@DavidSSL
DavidSSL / TryCatchThrow
Created September 21, 2012 20:11
Try catch with throw
try
{
//Code to perform some operation
}
catch
{
//Code to handle any exception that occurred in the try block
throw; // the throw keyword will pass or throw the exception to the calling method
}
@DavidSSL
DavidSSL / PassingConcreteObj
Created March 16, 2013 18:44
Passing concrete object
public void SomeMethod(SomeObject obj)
{
obj.DoSomething();
}
@DavidSSL
DavidSSL / PassingInterface
Created March 16, 2013 18:49
Passing interface
public void SomeMethod(ISomeInterface interface)
{
interface.DoSomething();
}
@DavidSSL
DavidSSL / Tightly coupled code
Created March 17, 2013 15:16
Tightly coupled code example
class Program
{
static void Main()
{
Person person = new Person();
string dateOfBirth = "10 May 1989";
Console.WriteLine(person.GetAge(dateOfBirth));
}
}
@DavidSSL
DavidSSL / GetAfterPostReturnsCorrectStatusCodeWithPostedEntry
Created March 20, 2013 12:24
GetAfterPostReturnsCorrectStatusCodeWithPostedEntry
[Fact]
public void GetAfterPostReturnsCorrectStatusCodeWithPostedEntry()
{
using (var client = MyHttpClientFactory.Create())
{
var json = new
{
time = DateTimeOffset.Now
,
distance = 8500
@DavidSSL
DavidSSL / ReadAsJsonAsync
Created March 20, 2013 12:31
ReadAsJsonAsync
public static Task<dynamic> ReadAsJsonAsync(this HttpContent content)
{
if (content == null)
throw new ArgumentNullException("content");
return content.ReadAsStringAsync().ContinueWith(t =>
JsonConvert.DeserializeObject(t.Result));
}