Skip to content

Instantly share code, notes, and snippets.

@t-ashula
Last active August 29, 2015 14:16
Show Gist options
  • Save t-ashula/d2b0e8f98e3a7b351c76 to your computer and use it in GitHub Desktop.
Save t-ashula/d2b0e8f98e3a7b351c76 to your computer and use it in GitHub Desktop.
mono + NSubstitute + xunit
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using NSubstitute;
[assembly: InternalsVisibleTo("nsub.test")]
namespace nsub
{
public static class MyCommon
{
public static _Assembly EntryAssembly { get; internal set; }
static MyCommon()
{
MyCommon.EntryAssembly = Assembly.GetExecutingAssembly();
}
public static string GetAssemblyName()
{
return MyCommon.EntryAssembly.GetName().Name;
}
}
#if EXE
public static class Progoram
{
public static void Main(string[] args)
{
Console.WriteLine("AssemblyName:<{0}>", MyCommon.GetAssemblyName());
Console.WriteLine("mock with NSubstitute");
var mockAssembly = Substitute.For<_Assembly>();
mockAssembly.GetName().Returns(new AssemblyName("foobar"));
MyCommon.EntryAssembly = mockAssembly;
Console.WriteLine("AssemblyName:<{0}>", MyCommon.GetAssemblyName());
}
}
#endif
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using NSubstitute;
using Xunit;
using Xunit.Extensions;
namespace nsub.test
{
public class MyCommonTest
{
[Fact]
public void GetAssemblyNameTest()
{
var mockAssembly = Substitute.For<_Assembly>();
mockAssembly.GetName().Returns(new AssemblyName("foobar"));
MyCommon.EntryAssembly = mockAssembly;
Assert.Equal("foobar", MyCommon.GetAssemblyName());
}
}
}
#!/bin/sh
if [ ! -e NSubstitute.dll ]; then
rm -rf N NSubstitute.*
wget http://nsubstitute.github.io/downloads/NSubstitute.1.8.1.0.zip -O NSubstitute.zip
mkdir -p N
unzip -d N NSubstitute.zip
cp N/lib/net45/NSubstitute.dll .
fi
if [ ! -e xunit.dll ]; then
rm -rf X xunit*
wget "http://download-codeplex.sec.s-msft.com/Download/Release?ProjectName=xunit&DownloadId=721411&FileTime=130218470669600000&Build=20959" -O xunit-build-1705.zip
mkdir -p X
unzip -d X xunit-build-1705.zip
cp X/xunit.* .
fi
mcs -target:exe -r:NSubstitute.dll -define:EXE nsub.cs
mcs -target:library -r:NSubstitute.dll nsub.cs
mcs -target:library -r:nsub.dll -r:NSubstitute.dll -r:xunit.dll -r:xunit.extensions.dll nsub.test.cs
echo "direct"
mono nsub.exe
echo "with xunit"
mono xunit.console.clr4.x86.exe nsub.test.dll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment