Skip to content

Commit

Permalink
Updating constructs
Browse files Browse the repository at this point in the history
  • Loading branch information
mnording committed Feb 6, 2017
1 parent 4d8e374 commit 2429a5a
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 10 deletions.
25 changes: 23 additions & 2 deletions Offline/Entities/MerchantConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,36 @@ public class MerchantConfig:Klarna.Entities.MerchantConfig
/// <param name="server">What server is being targeted?</param>
public MerchantConfig(CultureInfo locale, string currency, string country, string sharedSecret,string merchantId,Server server)
{
VerifyCountries(currency,country);
SetCommonParams(locale,currency,country,sharedSecret,merchantId,server);
}
/// <summary>
///
/// </summary>
/// <param name="locale">The locale of the purchase</param>
/// <param name="currency">The currency of the purchase ISO 4217</param>
/// <param name="country">2 letter country code ISO 3166-1 alpha-2</param>
/// <param name="sharedSecret">The sharedsecret between you and Klarna</param>
/// <param name="merchantId">The merchant ID provided by Klarna</param>
/// <param name="server">What server is being targeted?</param>
public MerchantConfig(CultureInfo culture, string sharedSecret, string merchantId, Server server)
{
var region = new RegionInfo(culture.LCID);
var country = region.TwoLetterISORegionName;
var currency = region.ISOCurrencySymbol;
SetCommonParams(culture, currency, country, sharedSecret, merchantId, server);
}

private void SetCommonParams(CultureInfo locale, string currency, string country, string sharedSecret, string merchantId, Server server)
{
VerifyCountries(currency, country);
this.locale = locale.Name;
purchaseCountry = country;
purchaseCurrency = currency;
this.merchantId = merchantId;
this.sharedSecret = sharedSecret;
this.server = server;
}

}
private void VerifyCountries(string currency, string country)
{
if (currency == null) throw new ArgumentNullException(nameof(currency));
Expand Down
2 changes: 1 addition & 1 deletion Offline/Offline.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Mnording.Klarna, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Mnording.Klarna.Core.2.0.0\lib\net45\Mnording.Klarna.dll</HintPath>
<HintPath>..\packages\Mnording.Klarna.Core.2.0.1\lib\net45\Mnording.Klarna.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
Expand Down
2 changes: 1 addition & 1 deletion Offline/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="libphonenumber-csharp" version="7.7.4" targetFramework="net45" />
<package id="Mnording.Klarna.Core" version="2.0.0" targetFramework="net45" />
<package id="Mnording.Klarna.Core" version="2.0.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
</packages>
94 changes: 88 additions & 6 deletions OfflineTest/MerchantConfigTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Klarna.Offline.Entities;

Expand All @@ -11,37 +12,118 @@ public class MerchantConfigTest
[ExpectedException(typeof(ArgumentException))]
public void MustNotBeAbleToInitWrongCountry()
{
var t = new MerchantConfig(new System.Globalization.CultureInfo(1),"SEK","DE","test","test",MerchantConfig.Server.Live);
var t = new MerchantConfig(new System.Globalization.CultureInfo(1), "SEK", "DE", "test", "test",
MerchantConfig.Server.Live);
}

[TestMethod]
public void MustBeAbleToInitWithSweden()
{
var t = new MerchantConfig(new System.Globalization.CultureInfo(1), "SEK", "SE", "test", "test", MerchantConfig.Server.Live);
var t = new MerchantConfig(new System.Globalization.CultureInfo(1), "SEK", "SE", "test", "test",
MerchantConfig.Server.Live);
Assert.AreNotEqual(null, t);
}

[TestMethod]
public void MustBeAbleToInitWithFinland()
{
var t = new MerchantConfig(new System.Globalization.CultureInfo(1), "EUR", "FI", "test", "test", MerchantConfig.Server.Live);
var t = new MerchantConfig(new System.Globalization.CultureInfo(1), "EUR", "FI", "test", "test",
MerchantConfig.Server.Live);
Assert.AreNotEqual(null, t);
}

[TestMethod]
public void MustBeAbleToInitWithNorway()
{
var t = new MerchantConfig(new System.Globalization.CultureInfo(1), "NOK", "NO", "test", "test", MerchantConfig.Server.Live);
var t = new MerchantConfig(new System.Globalization.CultureInfo(1), "NOK", "NO", "test", "test",
MerchantConfig.Server.Live);
Assert.AreNotEqual(null, t);
}

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void MustNotBeAbleToInitWrongCurrency()
{
var t = new MerchantConfig(new System.Globalization.CultureInfo(1), "EUR", "SE", "test", "test", MerchantConfig.Server.Live);
var t = new MerchantConfig(new System.Globalization.CultureInfo(1), "EUR", "SE", "test", "test",
MerchantConfig.Server.Live);
}

[TestMethod]
public void MustBeAbleToInitWithSwedishSEK()
{
var t = new MerchantConfig(new System.Globalization.CultureInfo(1), "SEK", "SE", "test", "test", MerchantConfig.Server.Live);
var t = new MerchantConfig(new System.Globalization.CultureInfo(1), "SEK", "SE", "test", "test",
MerchantConfig.Server.Live);
Assert.AreNotEqual(null, t);
}

/*####################### 2nd Construct Test ######################### */

[TestMethod]
public void MustBeAbleToInitWithSwedenSettingCountry()
{
var t = new MerchantConfig(CultureInfo.CreateSpecificCulture("sv-se"), "test", "test",
MerchantConfig.Server.Live);
Assert.AreEqual("SE", t.Country);
}
[TestMethod]
public void MustBeAbleToInitWithSwedenOnlySettingCurrency()
{
var t = new MerchantConfig(CultureInfo.CreateSpecificCulture("sv-se"), "test", "test",
MerchantConfig.Server.Live);
Assert.AreEqual("SEK", t.Currency);
}
[TestMethod]
public void MustBeAbleToInitWithSwedenOnlySettingLocale()
{
var t = new MerchantConfig(CultureInfo.CreateSpecificCulture("sv-se"), "test", "test",
MerchantConfig.Server.Live);
Assert.AreEqual("sv-SE", t.Locale);
}

[TestMethod]
public void MustBeAbleToInitWithFinlandSettingCountry()
{
var t = new MerchantConfig(CultureInfo.CreateSpecificCulture("fi-fi"), "test", "test",
MerchantConfig.Server.Live);
Assert.AreEqual("FI", t.Country);
}
[TestMethod]
public void MustBeAbleToInitWithFinlandSettingCurrency()
{
var t = new MerchantConfig(CultureInfo.CreateSpecificCulture("fi-fi"), "test", "test",
MerchantConfig.Server.Live);
Assert.AreEqual("EUR", t.Currency);
}
[TestMethod]
public void MustBeAbleToInitWithFinlandSettingLocale()
{
var t = new MerchantConfig(CultureInfo.CreateSpecificCulture("fi-fi"), "test", "test",
MerchantConfig.Server.Live);
Assert.AreEqual("fi-FI", t.Locale);
}

[TestMethod]
public void MustBeAbleToInitWithNorwaySettingCountry()
{
var t = new MerchantConfig(CultureInfo.CreateSpecificCulture("nb-no"), "test", "test",
MerchantConfig.Server.Live);
Assert.AreEqual("NO", t.Country);
}
[TestMethod]
public void MustBeAbleToInitWithNorwaySettingCurrency()
{
var t = new MerchantConfig(CultureInfo.CreateSpecificCulture("nb-no"), "test", "test",
MerchantConfig.Server.Live);
Assert.AreEqual("NOK", t.Currency);
}

[TestMethod]
public void MustBeAbleToInitWithNorwaySettingLocale()
{
var t = new MerchantConfig(CultureInfo.CreateSpecificCulture("nb-no"), "test", "test",
MerchantConfig.Server.Live);
Assert.AreEqual("nb-NO", t.Locale);
}
}

}

0 comments on commit 2429a5a

Please sign in to comment.