Skip to content

Instantly share code, notes, and snippets.

View ThomasArdal's full-sized avatar
🎢

Thomas Ardal ThomasArdal

🎢
View GitHub Profile
@ThomasArdal
ThomasArdal / gist:3183569
Created July 26, 2012 18:07
Simple AutoFixture usage
var fixture = new Fixture();
var model = fixture.CreateAnonymous<MyModel>();
@ThomasArdal
ThomasArdal / gist:3183580
Created July 26, 2012 18:09
A bit more advanced AutoFixture usage
var fixture = new Fixture();
var model =
fixture
.Build<MyModel>()
.Without(x => x.Id)
.CreateAnonymous();
@ThomasArdal
ThomasArdal / gist:4562879
Last active December 11, 2015 06:58
A test using the Verify-method of Moq.
[Test]
public void SomeTest() {
// Arrange
var mock = new Mock<IDependency>();
var sut = new ServiceUnderTest(mock.Object);
// Act
sut.DoIt();
// Assert
@ThomasArdal
ThomasArdal / gist:4563160
Created January 18, 2013 08:29
A test using callbacks instead of Verify from Moq.
[Test]
public void SomeTest() {
// Arrange
var mock = new Mock<IDependency>();
string string1 = null;
string string2 = null;
mock
.Setup(x => x.AMethodCall(It.IsAny<string>(), It.IsAny<string>()))
.Callback<string, string>((s1, s2) =>
{
@ThomasArdal
ThomasArdal / gist:5132711
Created March 11, 2013 08:10
Remote creation of IIS websites.
$username = "insert_username_here"
$password = ConvertTo-SecureString "insert_password_here" -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$password
$session = New-PSSession "insert_hostname_here" -Credential $credential
Invoke-Command -Session $session -ScriptBlock {
Set-ExecutionPolicy RemoteSigned
Import-Module WebAdministration
New-Item iis:\Sites\%teamcity.build.branch%.insert_local_name_here -bindings @{protocol="http";bindingInformation=":80:%teamcity.build.branch%.insert_local_name_here"} -physicalPath c:\inetpub\wwwroot\%teamcity.build.branch%.insert_local_name_here
Set-ItemProperty 'IIS:\Sites\%teamcity.build.branch%.insert_local_name_here' ApplicationPool "ASP.NET v4.0"
using System;
using System.Collections;
using System.Configuration;
using System.Globalization;
using Nest;
namespace Elmah.ElasticSearch
{
public class ElasticSearchLog : ErrorLog
{
var result =
LinkCheck
.On(x => x.Url(new Uri("http://www.hippovalidator.com")))
.AsBot(x => x.Google())
.OnRequest(req => ...)
.OnResponse(resp => ...)
.Start();
var links =
LinkCheck
.On(x => x.Url(new Uri(context.Url)))
.AsBot(bot => bot.Google())
.Start();
.Where(x => (int) x.StatusCode >= 400)
.Select(x => new ValidationIssue
{
Severity = SeverityEnum.Error,
Title = "The following link returned status code " +
public class IISExpressTest
{
[Test]
public void IISExpressIsNeverDisabled()
{
XNamespace @namespace = "http://schemas.microsoft.com/developer/msbuild/2003";
var document = XDocument.Load("path to your web project (csproj)");
var element =
document.Descendants(@namespace + "Project")
.First()
@ThomasArdal
ThomasArdal / gist:6761640
Created September 30, 2013 09:53
hello-node http server copied from http://howtonode.org/hello-node
// Load the http module to create an http server.
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, { "Content-Type": "text/plain" });
response.end("Hello World\n");
});
// Listen on port 8000, IP defaults to 127.0.0.1