Skip to content

Instantly share code, notes, and snippets.

View RhysC's full-sized avatar

Rhys Campbell RhysC

  • Perth; Australia
View GitHub Profile
@RhysC
RhysC / Sample.cs
Created October 16, 2012 01:22
EF DB Context not persisting Child record
public class Parent
{
public Parent()
{
Children = new HashSet<Child>();
}
public int ParentId { get; set; }
public string Name { get; set; }
public ICollection<Child> Children { get; set; }
}
@RhysC
RhysC / Sample1.cs
Created October 16, 2012 04:12
Most Simple Relational EF sample
using System;
using System.Collections.Generic;
using System.Data.Entity;
namespace EFConsoleApplication.Basic
{
public class Parent
{
public Parent()
{
@RhysC
RhysC / Temcity.linq
Created November 29, 2012 08:55
Team city linq query over http
void Main()
{
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
var results = from project in TeamCityWebRequest.GetTeamCityProjects()
from build in TeamCityWebRequest.GetTeamCityBuilds(project)
select new {project, build};
results.Dump();
}
public class TeamCityWebRequest
@RhysC
RhysC / TimeZones.linq
Created November 29, 2012 09:34
Time zones for relevant States
var dt = DateTime.UtcNow;
var utcOffset = new DateTimeOffset(dt, TimeSpan.Zero);
//TimeZoneInfo.GetSystemTimeZones() - provides timezone identifiers
(from t in new []{
new {Name = "UK", TimeZoneId= "GMT Standard Time"},
new {Name = "WA", TimeZoneId= "W. Australia Standard Time"},
new {Name = "NT", TimeZoneId= "AUS Central Standard Time"},
new {Name = "NSW", TimeZoneId= "E. Australia Standard Time"},
new {Name = "VIC", TimeZoneId= "E. Australia Standard Time"},
new {Name = "ACT", TimeZoneId= "E. Australia Standard Time"},
@RhysC
RhysC / MachineSetup.ps1
Last active May 25, 2016 08:13
Dev machine PC set up **NB* *: You must have your execution policy set to unrestricted for this to work (Set-ExecutionPolicy Unrestricted). There have been reports that RemoteSigned is enough for the install to workUses Chocolatey and PS-Get to do the heavy lifting TAGS chocolatey setup build
$ErrorActionPreference = "Stop"
Set-ExecutionPolicy RemoteSigned
ECHO "Installing PsGet and PS plugins"
iex ((new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1"))
Install-Module pscx
Install-Module psake
ECHO "FINISHED - Installing PsGet and PS plugins - FINISHED"
@RhysC
RhysC / build.ps1
Created December 30, 2012 03:49
sample psake script for migrations
Properties {
$build_dir = Split-Path $psake.build_script_file
$build_artifacts_dir = "$build_dir\..\BuildArtifacts\"
$code_dir = "$build_dir\..\"
$soln = "$build_dir\..\AgentHoney.Azure.sln"
$nuget_package_dir = "$build_dir\..\..\Packages"
$database_server = ".\SqlExpress"
$database_instance = "AgentHoney_AutoTestDb"
$ef_tools_ouput = "$build_artifacts_dir\Tools\EF\"
}
@RhysC
RhysC / RouteFixture.cs
Created March 5, 2013 09:26
Testing ASP.net MVC routes does not need to be hard or require external testing libraries. this uses XUnit and Nsubstitue. refactoring out the RequestPath and the assertion and you have a very simple test fixture.
public class RouteFixture
{
private readonly HttpContextBase _httpContextMock;
private readonly RouteCollection _routes;
public RouteFixture()
{
_routes = new RouteCollection();
RouteConfig.RegisterRoutes(_routes);
@RhysC
RhysC / MVC View Model Fixture.cs
Created March 5, 2013 10:41
Simple attribute testing on MVC ViewModel
public class PesonalDetailsFixture
{
[Fact]
public void RequiredPropertiesAreMarkedAsSo()
{
PropertyOn<PersonalData, string>(x => x.Title).Has<RequiredAttribute>();
PropertyOn<PersonalData, string>(x => x.FirstName).Has<RequiredAttribute>();
PropertyOn<PersonalData, string>(x => x.LastName).Has<RequiredAttribute>();
PropertyOn<PersonalData, DateTime>(x => x.DateOfBirth).Has<RequiredAttribute>();
PropertyOn<PersonalData, string>(x => x.Email).Has<RequiredAttribute>();
@RhysC
RhysC / DynamicCsv.cs
Created March 15, 2013 09:50
CSV reader from http://www.thinqlinq.com/default/LINQ-to-CSV-using-DynamicObject.aspx. Ported to c# with basic usage example at the bottom (using xunit). Uses dynamic to provide the field names based on headers. Have changed the default of changing spaces to underscores to just removing them.
using System;
using System.Dynamic;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using Xunit;
namespace YourNamespace
{
public class DynamicCsv : DynamicObject
@RhysC
RhysC / DeafultWebFormInputValidator
Created March 16, 2013 06:59
html forms validation based on the teststack.seleno page model. Faked out page and assert, need to adjust to fit. This is designed to work with DynamicCsv Gist.
//Will need some rework and some decent test runs. IDeally generate the start of the csv too.
public class PageFormTestInput<T> where T : new()
{
private const string isFormValidFieldName = "IsFormValid";
private readonly dynamic input;
public PageFormTestInput(dynamic input)
{
this.input = input;
}