Skip to content

Commit

Permalink
Change tests from MbUnit to Xunit
Browse files Browse the repository at this point in the history
Change tests from MbUnit to Xunit.  Also requires a framework bump from
4 to 4.5.
  • Loading branch information
kianryan committed Dec 8, 2016
1 parent 9e0f485 commit 9e4f9be
Show file tree
Hide file tree
Showing 23 changed files with 509 additions and 437 deletions.
14 changes: 4 additions & 10 deletions SagePay.sln
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SagePay", "SagePay\SagePay.csproj", "{4642C400-385F-4462-8CD7-6F86E169DE67}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SagePayTest", "SagePayTest\SagePayTest.csproj", "{3C549D26-648D-4577-A7E5-2875D3B01DFB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_References", "_References", "{27AC9C86-D75C-45D7-A388-DA6637F84796}"
ProjectSection(SolutionItems) = preProject
_References\Gallio.dll = _References\Gallio.dll
_References\Gallio35.dll = _References\Gallio35.dll
_References\Gallio40.dll = _References\Gallio40.dll
_References\MbUnit.dll = _References\MbUnit.dll
_References\MbUnit35.dll = _References\MbUnit35.dll
_References\MbUnit40.dll = _References\MbUnit40.dll
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Documentation", "_Documentation", "{11F8BD30-F078-4011-86F5-5D9FF675CD97}"
ProjectSection(SolutionItems) = preProject
Expand Down
5 changes: 4 additions & 1 deletion SagePay/SagePay.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OrangeTentacle.SagePay</RootNamespace>
<AssemblyName>SagePay</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -21,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -29,6 +31,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down
14 changes: 7 additions & 7 deletions SagePayTest/App.config
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="SagePay" type="OrangeTentacle.SagePay.Configuration.SageConfiguration, SagePay" />
<section name="SagePay" type="OrangeTentacle.SagePay.Configuration.SageConfiguration, SagePay"/>
</configSections>

<SagePay default="Offline">
<add type="Offline" vendorName="orangetentacle" />
<add type="Simulator" vendorName="orangetentacle" />
<add type="Test" vendorName="orangetentacle" />
<add type="Live" vendorName="orangetentacle" />
<add type="Offline" vendorName="orangetentacle"/>
<add type="Simulator" vendorName="orangetentacle"/>
<add type="Test" vendorName="orangetentacle"/>
<add type="Live" vendorName="orangetentacle"/>
</SagePay>
</configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
12 changes: 6 additions & 6 deletions SagePayTest/Configuration/SageConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
using MbUnit.Framework;
using Xunit;
using OrangeTentacle.SagePay;

namespace OrangeTentacle.SagePayTest.Configuration
{
[TestFixture]

public class SageConfiguration
{
public const ProviderTypes CONFIG_TYPE = ProviderTypes.Offline;

[TestFixture]
internal class VendorName

public class VendorName
{
[Test]
[Fact]
public void FromConfigFile()
{
var section = SagePay.Configuration.SageConfiguration.GetSection(CONFIG_TYPE);
Assert.IsFalse(string.IsNullOrWhiteSpace(section.VendorName));
Assert.False(string.IsNullOrWhiteSpace(section.VendorName));
}
}
}
Expand Down
43 changes: 22 additions & 21 deletions SagePayTest/PathsAndTypes.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
using System;
using System.Collections.Generic;
using System.IO;
using MbUnit.Framework;
using System.Linq;
using System.Reflection;
using Xunit;
using OrangeTentacle.SagePay;
using OrangeTentacle.SagePay.Request.Payment;
using OrangeTentacle.SagePay.Request.Refund;

namespace OrangeTentacle.SagePayTest
{
[TestFixture]
internal class PathsAndTypes

public class PathsAndTypes
{

internal class PathMapping
public class PathMapping
{
public const string BASE_PATH = "../../Examples/";

Expand All @@ -28,7 +30,7 @@ public PathMapping(string filename, Type paymentType, Type refundType)
}
}

internal class ProviderMapping
public class ProviderMapping
{
public ProviderTypes ProviderType { get; set; }
public Type PaymentType { get; set; }
Expand All @@ -42,33 +44,32 @@ public ProviderMapping(ProviderTypes type, Type paymentType, Type refundType)
}
}

public static List<PathMapping> GetFiles()
public static IEnumerable<object[]> GetFiles()
{
var list = new List<PathMapping>();
list.Add(new PathMapping("App.config.default", typeof (OfflineSagePayment), typeof (OfflineSageRefund)));
list.Add(new PathMapping("App.config.live", typeof (LiveSagePayment), typeof (LiveSageRefund)));
list.Add(new PathMapping("App.config.test", typeof (TestSagePayment), typeof (TestSageRefund)));
list.Add(new PathMapping("App.config.simulator", typeof (SimulatorSagePayment), typeof (SimulatorSageRefund)));
list.Add(new PathMapping("App.config.offline", typeof (OfflineSagePayment), typeof (OfflineSageRefund)));
var list = new List<object[]>();
list.Add(new object[] { new PathMapping("App.config.default", typeof (OfflineSagePayment), typeof (OfflineSageRefund)) });
list.Add(new object[] { new PathMapping("App.config.live", typeof (LiveSagePayment), typeof (LiveSageRefund)) });
list.Add(new object[] { new PathMapping("App.config.test", typeof (TestSagePayment), typeof (TestSageRefund)) });
list.Add(new object[] { new PathMapping("App.config.simulator", typeof (SimulatorSagePayment), typeof (SimulatorSageRefund)) });
list.Add(new object[] { new PathMapping("App.config.offline", typeof (OfflineSagePayment), typeof (OfflineSageRefund))} );
return list;
}


public static List<ProviderMapping> GetProviders()
public static IEnumerable<object[]> GetProviders()
{
var list = new List<ProviderMapping>();
list.Add(new ProviderMapping(ProviderTypes.Live, typeof(LiveSagePayment), typeof(LiveSageRefund)));
list.Add(new ProviderMapping(ProviderTypes.Test, typeof(TestSagePayment), typeof(TestSageRefund)));
list.Add(new ProviderMapping(ProviderTypes.Simulator, typeof(SimulatorSagePayment), typeof(SimulatorSageRefund)));
list.Add(new ProviderMapping(ProviderTypes.Offline, typeof(OfflineSagePayment), typeof(OfflineSageRefund)));
var list = new List<object[]>();
list.Add(new object[] { new ProviderMapping(ProviderTypes.Live, typeof(LiveSagePayment), typeof(LiveSageRefund)) });
list.Add(new object[] { new ProviderMapping(ProviderTypes.Test, typeof(TestSagePayment), typeof(TestSageRefund)) });
list.Add(new object[] { new ProviderMapping(ProviderTypes.Simulator, typeof(SimulatorSagePayment), typeof(SimulatorSageRefund)) });
list.Add(new object[] { new ProviderMapping(ProviderTypes.Offline, typeof(OfflineSagePayment), typeof(OfflineSageRefund)) });
return list;
}

[Test]
[Factory("GetFiles")]
[Theory, MemberData("GetFiles")]
public void TestFilesExist(PathMapping mapping)
{
Assert.IsTrue(File.Exists(mapping.FileName));
Assert.True(File.Exists(mapping.FileName));
}
}
}
50 changes: 25 additions & 25 deletions SagePayTest/Request/Payment/OfflineSagePayment.cs
Original file line number Diff line number Diff line change
@@ -1,85 +1,85 @@
using System.Linq;
using MbUnit.Framework;
using Xunit;
using OrangeTentacle.SagePay;
using OrangeTentacle.SagePay.Request.Payment;
using OrangeTentacle.SagePay.Configuration;

namespace OrangeTentacle.SagePayTest.Request.Payment
{
[TestFixture]

public class OfflineSagePayment
{
[TestFixture]
internal class Constructor

public class Constructor
{
[Test]
[Fact]
public void ConfigureFromConfig()
{
var request = new SagePay.Request.Payment.OfflineSagePayment();
var section = SagePay.Configuration.SageConfiguration.GetSection(ProviderTypes.Offline);


Assert.AreEqual(section.VendorName, request.Vendor.VendorName);
Assert.Equal(section.VendorName, request.Vendor.VendorName);
}

[Test]
[Fact]
public void ConfigureFromConstructor()
{
var name = "bob";
var request = new SagePay.Request.Payment.OfflineSagePayment(name);

Assert.AreEqual(name, request.Vendor.VendorName);
Assert.Equal(name, request.Vendor.VendorName);
}
}

[TestFixture]
internal class Validate

public class Validate
{
[Test]
[Fact]
public void ReturnsErrors()
{
var request = new SagePay.Request.Payment.OfflineSagePayment();
request.Transaction = PaymentRequest.SampleRequest();
request.Transaction.CV2 = "12";
var errors = request.Validate();

Assert.AreEqual(1, errors.Count);
Assert.AreEqual("CV2", errors.First().Field);
Assert.IsFalse(request.IsValid);
Assert.Equal(1, errors.Count);
Assert.Equal("CV2", errors.First().Field);
Assert.False(request.IsValid);
}

[Test]
[Fact]
public void SetsIsValid()
{
var request = new SagePay.Request.Payment.OfflineSagePayment();
request.Transaction = PaymentRequest.SampleRequest();
var errors = request.Validate();

Assert.AreEqual(0, errors.Count);
Assert.IsTrue(request.IsValid);
Assert.Equal(0, errors.Count);
Assert.True(request.IsValid);
}
}

[TestFixture]
internal class Send

public class Send
{
[Test]
[AssertException(typeof (SageException))]
public void ThrowsAnExceptionIfInvalid()
[Fact]
public void ThInlineDatasAnExceptionIfInvalid()
{
var request = new SagePay.Request.Payment.OfflineSagePayment();
var response = request.Send();

Assert.Throws<SageException>(() => request.Send());
}

[Test]
[Fact]
public void EmitsAResponseIsValid()
{
var request = new SagePay.Request.Payment.OfflineSagePayment();
request.Transaction = PaymentRequest.SampleRequest();
request.Validate();

var response = request.Send();
Assert.IsNotNull(response);
Assert.NotNull(response);
}
}
}
Expand Down
Loading

0 comments on commit 9e4f9be

Please sign in to comment.