Skip to content

Instantly share code, notes, and snippets.

View theorigin's full-sized avatar

Andy Robinson theorigin

View GitHub Profile
@theorigin
theorigin / merge_lookups.sql
Created July 23, 2012 07:42
SQL Server MERGE statement
MERGE INTO Lookups AS Target
USING (VALUES
(0, N'Lookup Number 0'),
(1, N'Lookup Number 1'),
(2, N'Lookup Number 2'),
(3, N'Lookup Number 3'),
(4, N'Lookup Number 4'),
(5, N'Lookup Number 5'),
(6, N'Lookup Number 6')
)
@theorigin
theorigin / Index.cs
Created August 4, 2012 15:06
Json TDD Controller
public ActionResult Index(InputModel model)
{
return Json(new
{
total = 1234,
page = 1,
rows = new List
{
new
{
@theorigin
theorigin / gist:3258269
Created August 4, 2012 15:08
Json TDD Unit Test
[Test]
public void SomeTest()
{
var viewResult = this.controller.Index(new InputModelBuilder().Build()) as JsonResult;
viewResult.Should().NotBeNull();
var data = viewResult.Data;
var pageNumber = data.GetType().GetProperty("page").GetValue(data, null);
@theorigin
theorigin / gist:3258274
Created August 4, 2012 15:09
Json TDD Refactor
private object GetValue(object source, string propertyName)
{
return source.GetType().GetProperty(propertyName).GetValue(source, null);
}
@theorigin
theorigin / gist:3258279
Created August 4, 2012 15:10
Json TDD Example Call
this.GetValue(data, "page").Should().Be(1);
@theorigin
theorigin / gist:3258287
Created August 4, 2012 15:11
Json TDD get at rows
var rows = (List<object><p>
)data.GetType().GetProperty("rows").GetValue(data, null);&nbsp;
rows.Count.Should().Be(1);
this.GetValue(rows[0], "id").Should().Be("98732312");
var cell = rows[0].GetType().GetProperty("cell").GetValue(rows[0], null);
this.GetValue(cell, "prop1").Should().Be("a");
@echo off
echo Pre req checks...
echo|set /p=... Running as ADMIN ...
reg query "HKU\S-1-5-19" >nul 2>&1
if %errorlevel% == 1 echo FAILED : Not runing as ADMIN
if %errorlevel% == 0 echo Passed
echo|set /p=... SQL Server ...
osql.exe -? >nul 2>&1
public class SomeViewModelBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
int currentPage = 1;
int itemsPerPage = 8;
var page = bindingContext.ValueProvider.GetValue("page");
if (page != null)
[Test]
public void ShouldReturnModelWithValuesSetCorrectly()
{
var formCollection = new NameValueCollection
{
{ "page", "5" },
{ "rp", "8" },
{ "query", "smith" },
{ "sortname", "sname" },
{ "sortorder", "sorder" }
@theorigin
theorigin / gist:5344279
Created April 9, 2013 09:16
RegEx to wrap [ ] around text. For example when you need to turn a single JSON object into an array.
/// A description of the regular expression:
///
/// Beginning of line or string
/// [1]: A numbered capture group. [[^[].*[^]]]
/// [^[].*[^]]
/// Any character that is NOT in this class: [[]
/// Any character, any number of repetitions
/// Any character that is NOT in this class: []]
/// End of line or string