Skip to content

Instantly share code, notes, and snippets.

@markrendle
markrendle / databasefactory.cs
Created October 12, 2012 14:30
DatabaseFactory class for Simple.Data + Impromptu
static class DatabaseFactory
{
public static IDatabase Create()
{
Database.UseMockAdapter(CreateMockAdapter());
// This single line of code applies all these interfaces
return Impromptu.ActLike<IDatabase>(Database.Open());
}
@markrendle
markrendle / tests.cs
Created October 12, 2012 14:31
Tests for Simple.Data + Impromptu
[TestFixture]
public class CustomerTest
{
[Test]
public void TestInsert()
{
var db = DatabaseFactory.Create();
var customer = db.Customers.Insert(name: "Megadodo", location: "Ursa Minor Beta");
Assert.AreEqual(1, customer.Id);
Assert.AreEqual("Megadodo", customer.Name);
@markrendle
markrendle / interfaces.cs
Created October 12, 2012 14:31
Interfaces for Simple.Data + Impromptu
public interface IDatabase
{
ICustomers Customers { get; }
IEmployees Employees { get; }
}
public interface ICustomers
{
ICustomer Get(int id);
[UseNamedArgument]
@markrendle
markrendle / azureteamcitydb.sql
Created November 13, 2012 16:20
Schema for TeamCity DB in SQL Azure
/* DISCLAIMER
This script is published only as a reference.
No warranty is implied or offered.
If you use this and bad things happen, it's not my fault.
*/
/****** Object: Table [dbo].[action_history] Script Date: 13/11/2012 16:12:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
@markrendle
markrendle / awaitall.cs
Created February 5, 2013 16:56
Await All using operator overloads
namespace AwaitChain
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
class Program
@markrendle
markrendle / StringSerializerTests.cs
Created March 10, 2013 13:52
An example set of unit tests from Zudio
namespace Zudio.Common.Tests
{
using System.Linq;
using Xunit;
public class StringSerializerTests
{
[Fact]
public void SerializesNoStrings()
{
@markrendle
markrendle / 1-CallByValue.msil
Last active December 15, 2015 20:28
Call-By-Ref vs Call-By-Value
IL_0001: ldstr "bar"
IL_0006: stloc.0 // str
IL_0007: ldarg.0
IL_0008: ldloc.0 // ldloc loads the variable onto the stack
IL_0009: call UserQuery.Foo
Foo:
IL_0000: nop
IL_0001: ldarg.1
IL_0002: callvirt System.String.ToUpper
var account = new CloudStorageAccount(credentials);
var tasks = new List<Task>();
foreach (var blobPath in blobPaths)
{
var client = account.CreateCloudBlobClient();
var blob = await client.GetBlobReferenceFromServerAsync(blobPath);
tasks.Add(blob.DeleteIfExistsAsync());
}
await Task.WhenAll(tasks);
@markrendle
markrendle / abc.txt
Last active February 4, 2017 05:11
Updated version of Mads Kristensen's commonHTML5Types.xsd with added tags for form parts (e.g. ng-pattern) and AngularJS 1.1.4. Actual hard work and clevers by Mads: http://madskristensen.net/post/AngularJS-Intellisense-in-Visual-Studio-2012.aspx
1. Back up C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Packages\schemas\html\commonHTML5Types.xsd
2. Delete C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Packages\schemas\html\commonHTML5Types.bin if it exists
3. Replace it with the file below.
4. Restart Visual Studio 2012.
CREATE PROCEDURE [dbo].[FindAllUsers]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT * FROM tblUsers ORDER BY [name]