Skip to content

Instantly share code, notes, and snippets.

View isidore's full-sized avatar

Llewellyn Falco isidore

View GitHub Profile
/// DON'T USE ASYNC
[TestMethod]
public async Task TestHttp()
{
var response = await new HttpClient().GetAsync("http://www.google.com/");
Assert.AreEqual(response.StatusCode, HttpStatusCode.OK);
}
/// Prefer to use .Result
@isidore
isidore / gist:25ef2cd8ab7492311172
Last active August 29, 2015 14:02
AsyncExceptions
[Test]
public void TestAsyncExceptions()
{
int a = 0;
AsyncApprovals.VerifyException(async () => 1/a);
}
// NOTE: If async is creating inconsient stack traces, consider a scrubber
AsyncApprovals.VerifyException(async () => 1/a,
@isidore
isidore / gist:17921d43012ff77829f7
Last active August 29, 2015 14:03
WpfBindings
Binding myBinding = new Binding(TestViewModel.MyPropertyPropertyName);
WpfBindingsAssert.BindsWithoutError(viewModel, () =>
{
// ... create control and initalize bindings
// (This will happen once the reporting and logging has been setup)
var textBox = new TextBox();
textBox.SetBinding(TextBox.TextProperty, myBinding);
return textBox;
});
package org.xp2015.smells;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
package com.spun.triangles.test;
import static org.junit.Assert.assertEquals;
import java.util.Random;
import org.junit.Test;
/**
* Theory based kata
@isidore
isidore / ifstructure.cs
Last active July 30, 2016 20:22
If structure
string result;
result = Win();
if (result != null)
{
return result;
}
result = Advantage();
if (result != null)
{
return result;
@isidore
isidore / Passin.cs
Created July 30, 2016 10:24
Pass In
string result;
result = Win();
result = Advantage(result);
result = ScoreNormal(result);
result = ScorePerson1(result);
result = ScorePerson2(result);
result = ScoreTie(result);
return result;
@isidore
isidore / leaking.cs
Created July 30, 2016 10:28
leaking
public string Advantage(string previousResult)
{
if (previousResult != null)
{
return previousResult;
}
return new Func<string>[]
{
Win,
Advantage,
ScoreNormal,
ScorePerson1,
ScorePerson2,
ScoreTie
}.FirstNonNull();
private IEnumerable<string> ProcessScores()
{
yield return Win();
yield return Advantage();
yield return ScoreNormal();
yield return person2.ScoreOpponentHasntScored(person1);
yield return person1.ScoreOpponentHasntScored(person2);
yield return ScoreTie();
throw new Exception("Unreachable code was executed");
}