Skip to content

Instantly share code, notes, and snippets.

@ritalin
ritalin / AbstractLocalSyncRunner.cs
Created June 15, 2012 05:47
awaitable runner host (deleved from /gists/2880770)
public class AbstractLocalSyncRunner {
protected AbstractLocalSyncRunner() {
}
protected virtual void RunAsyncCore(ILocalSynchronizationContextRef inLocalContext, Func<SynchronizationContext, Task> inTestAction) {
inLocalContext.Start();
try {
inLocalContext.Reference.Post(obj => {
var task = inTestAction(inLocalContext.Reference);
@ritalin
ritalin / AssertPlus.cs
Created June 13, 2012 02:48
Awaitable Assert.Throws implementation.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
namespace Samples {
public static class AssertPlus {
@ritalin
ritalin / AssertRequired.cs
Created June 11, 2012 07:34
A helper class testing the pre-requred fixture.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
namespace Samples {
public class AssertRequired<TResult> where TResult : class, new() {
@ritalin
ritalin / ComplexBusinessOperations-1.cs
Created June 6, 2012 08:53 — forked from gamlerhart/ComplexBusinessOperations-1.cs
Unit Testing, Part II, Synchronisation Issues
public class ComplexBusinessOperations
{
private int moneyEarnedSoFar;
public int MoneyEarnedSoFar
{
get { return moneyEarnedSoFar; }
}
public void EarnMoney(int investment)
@ritalin
ritalin / ComplexBusinessOperations-1.cs
Created June 6, 2012 08:52 — forked from gamlerhart/ComplexBusinessOperations-1.cs
Unit Testing, Part II, Synchronisation Issues
public class ComplexBusinessOperations
{
private int moneyEarnedSoFar;
public int MoneyEarnedSoFar
{
get { return moneyEarnedSoFar; }
}
public void EarnMoney(int investment)
@ritalin
ritalin / gist:2425645
Created April 20, 2012 03:18
A Helper method converting AggregateException to the internal exception for NUnit
// In CUI test runner, to use await syntax at the test code is involved skipping test.
// So It nessesary to wait using Task#Wait() method.
// In Assert#Throws method for NUnit, threfore, expected exception is not thrown but AggregateException.
// Following method is conversion AggregateException to the internal exception.
private TestDelegate ResolveAggregateException(Action inTestAction) {
return () => {
try {
inTestAction();
}
catch (AggregateException ex) {
@ritalin
ritalin / PropertyCategoryMapper.cs
Created April 19, 2012 04:04 — forked from anonymous/PropertyTagMapper.cs
A helper class to extract property-names of ViewModel for MVVM.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Samples {
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class PropertyCategoryAttribute : System.Attribute {
public PropertyCategoryAttribute(Type inTagType) {
this.Tag = inTagType;
@ritalin
ritalin / dupstr.fs
Created April 10, 2012 16:10
Maximum Duplication String Problem for F#
//
// Maximum Duplication String Problem for F#
//
let dupstr s =
// generate suffix list
let tails (s:string) =
let rec tailsimpl (s:string) i list =
match i with
| -1 -> list
@ritalin
ritalin / LimittedStringExtensions.cs
Created April 6, 2012 08:04
Limitted String for .NET
namespace Sample {
public static class LimittedStringExtensions {
public string LimmitedString(this string inSelf, int inMaxLen) {
if (inSelf.Length > inMaxLen) {
throw new Exception("長すぎwwwワロタwww");
}
return inSelf;
}
}
@ritalin
ritalin / BlankPage.xaml
Created March 26, 2012 04:02 — forked from anonymous/BlankPage.xaml
For metro style app, unable to use attachable property defined by other assembly.
<!--
<Page
x:Class="APTest.App.BlankPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:APTest.App"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:fw="clr-namespace:AP.Framework;assembly=AP.Framework"