Skip to content

Instantly share code, notes, and snippets.

@scottlaw1
scottlaw1 / gist:3089921
Created Jul 11, 2012
Inserting stored procedure results into a table variable
View gist:3089921
CREATE PROC test_proc
AS
SET NOCOUNT ON
SELECT TOP 10 id, name FROM employee
declare @sometable as table([id] int, name varchar(64))
INSERT INTO @sometable
exec test_proc
@scottlaw1
scottlaw1 / gist:3089941
Created Jul 11, 2012
Create comma-delimited list of values with LINQ aggregate
View gist:3089941
int[] numbers = new[] {1, 5, 8, 26, 35, 42};
var result = numbers.Aggregate("", (current, item) => current + item.ToString() + ",");
@scottlaw1
scottlaw1 / gist:3089962
Created Jul 11, 2012
AppleScript + RSVP Emails = Wedding Guests Address Book Group
View gist:3089962
tell application "Mail"
set selectedMessages to selection
if (count of selectedMessages) is equal to 0 then
display alert "No Messages Selected" message "Select the messages you want to add to 'wedding guests' address book group before running this script."
else
set weddingGuests to {}
repeat with eachMessage in selectedMessages
set emailSender to (extract name from sender of eachMessage) as string
@scottlaw1
scottlaw1 / MissingFileTest.cs
Created Nov 23, 2012
XUnit test for missing files
View MissingFileTest.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Xunit;
namespace Isas.Shared.Tests
{
@scottlaw1
scottlaw1 / AutoMapperTest.cs
Created Jan 17, 2013
Revision to an XUnit test for identifying bad mappings. Unlike the standard test (which would fail after the first bad/missing mapping), this will print out all the unmapped property names in the solution in context with the mapping they belong to.
View AutoMapperTest.cs
[Fact]
public void AssertConfigurationIsValid()
{
try
{
Mapper.AssertConfigurationIsValid();
}
catch (AutoMapperConfigurationException amce)
{
foreach (var e in amce.Errors)
@scottlaw1
scottlaw1 / gist:5960394
Created Jul 9, 2013
XUnit test class for finding derived types that are missing an explicit public no-arg constructor
View gist:5960394
public class SomeTypeTest
{
/// <summary>
/// <remarks>A bit of a hack, but if this test fails, the last type name written to the console/debug output
/// is the one missing an explicit public no-arg constructor.</remarks>
/// </summary>
[Fact]
public void AllTypesDerivedFromSomeTypeHavePublicNoArgConstructors()
{
var type = typeof(Enumeration);
@scottlaw1
scottlaw1 / LINQPad Code Generation Example
Created Mar 19, 2014
An example of a program written in LINQPad for code generation of classes used in an ASP.NET MVC project.
View LINQPad Code Generation Example
void Main()
{
string aclTemplates = @"
using System;
using Acme.Web.Areas.Area1.Controllers.{0};
using Acme.Web.Infrastructure.Acl;
namespace Ltss.Web.Areas.Acme.Acl.{0}
{{
public class Acme{0}AclRegistry : AbstractAccessControlRegistry<{0}Controller>
@scottlaw1
scottlaw1 / UnitTestBase.cs
Created Jun 29, 2014
Example of abstract class I use for unit testing with XUnit
View UnitTestBase.cs
public abstract class UnitTestBase : IUseFixture<UnitTestFixture>{
public void SetFixture(UnitTestFixture data){
Fixture = data;
AdditionalFixtureConfiguration();
}
protected UnitTestFixture Fixture {get;set;}
public virtual void AdditionalFixtureConfiguration(){
@scottlaw1
scottlaw1 / gist:ca7996c4ce97453fa9d5
Created Jan 2, 2015
Bad Form Submit vs Not Bad Form Submit
View gist:ca7996c4ce97453fa9d5
<!--BAD-->
<!-- The following button tag will submit the form named "formName" TWICE -->
<button type="submit" onclick="$('#formName').submit()">Assign</button>
<!--Not Bad-->
<!-- The following button tag will submit the form named "formName" ONCE -->
<button type="button" onclick="$('#formName').submit()">Assign</button>
@scottlaw1
scottlaw1 / ValueObjectTest.cs
Created Feb 24, 2015
XUnit test for interface implementation
View ValueObjectTest.cs
public class ValueObjectTest
{
[Fact]
public void AllValueObjectsImplementIEquatable()
{
var typeToFind = typeof (IValueObject);
var typesFound = AppDomain.CurrentDomain.GetAssemblies().ToList()
.SelectMany(s => s.GetTypes())
.Where(typeToFind.IsAssignableFrom);