Skip to content

Commit

Permalink
Move unit tests to mstest
Browse files Browse the repository at this point in the history
  • Loading branch information
smithrobs committed Jun 30, 2017
1 parent faddc8b commit 542667f
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 63 deletions.
22 changes: 11 additions & 11 deletions Nexmo.Api.Test.Unit/AccountTest.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Nexmo.Api.Test.Unit
{
[TestFixture]
internal class AccountTest : MockedWebTest
[TestClass]
public class AccountTest : MockedWebTest
{
[Test]
[TestMethod]
public void should_get_account_balance()
{
SetExpect($"{RestUrl}/account/get-balance/{ApiKey}/{ApiSecret}",
SetExpect($"{RestUrl}/account/get-balance?api_key={ApiKey}&api_secret={ApiSecret}&",
"{\"value\":0.43}");
var balance = Account.GetBalance();
Assert.AreEqual(.43d, balance);
Assert.AreEqual(.43m, balance);
}

[Test]
[TestMethod]
public void should_get_pricing()
{
SetExpect($"{RestUrl}/account/get-pricing/outbound/{ApiKey}/{ApiSecret}/US",
SetExpect($"{RestUrl}/account/get-pricing/outbound/?country=US&api_key={ApiKey}&api_secret={ApiSecret}&",
@"{""country"":""US"",""name"":""United States"",""prefix"":""1"",""mt"":""0.00480000"",""networks"":[{""code"":""US-FIXED"",""network"":""United States of America Landline"",""mtPrice"":""0.00480000""},{""code"":""311340"",""network"":""Illinois Valley Cellular RSA 2-I Partnership"",""mtPrice"":""0.00480000""},{""code"":""311740"",""network"":""TelAlaska Cellular, Inc."",""mtPrice"":""0.00480000""},{""code"":""311910"",""network"":""SI WIRELESS, LLC"",""mtPrice"":""0.00480000""},{""code"":""310860"",""network"":""Five Star Wireless"",""mtPrice"":""0.00480000""},{""code"":""310760"",""network"":""Panhandle Telecommunications Systems, Inc."",""mtPrice"":""0.00480000""},{""code"":""310011"",""network"":""Northstar Technology, LLC"",""mtPrice"":""0.00480000""},{""code"":""311887"",""network"":""XO California, Inc."",""mtPrice"":""0.00480000""},{""code"":""311380"",""network"":""NEW DIMENSION WIRELESS LTD."",""mtPrice"":""0.00480000""},{""code"":""310300"",""network"":""Smart Call, LLC"",""mtPrice"":""0.00480000""},{""code"":""310004"",""network"":""Verizon Wireless"",""mtPrice"":""0.00480000""},{""code"":""US-VOIP"",""network"":""United States of America VoIP"",""mtPrice"":""0.00480000""},{""code"":""311580"",""network"":""United States Cellular Corp. - Maine"",""mtPrice"":""0.00480000""},{""code"":""311230"",""network"":""Cellular South, Inc."",""mtPrice"":""0.00480000""},{""code"":""310610"",""network"":""Epic Touch Co."",""mtPrice"":""0.00480000""},{""code"":""310060"",""network"":""New Cell, Inc. dba CeLLCom"",""mtPrice"":""0.00480000""},{""code"":""310870"",""network"":""Kaplan Telephone Company"",""mtPrice"":""0.00480000""},{""code"":""310750"",""network"":""East Kentucky Netwrk, LLC dba Appalachian Wireless"",""mtPrice"":""0.00480000""},{""code"":""311290"",""network"":""Pinpoint Wireless, Inc."",""mtPrice"":""0.00480000""},{""code"":""311330"",""network"":""Michigan Wireless, LLC dba Bug Tussel Wireless"",""mtPrice"":""0.00480000""},{""code"":""310710"",""network"":""ASTAC Wireless LLC"",""mtPrice"":""0.00480000""},{""code"":""311050"",""network"":""Wilkes Cellular, Inc."",""mtPrice"":""0.00480000""},{""code"":""310770"",""network"":""Iowa Wireless Services, Lp"",""mtPrice"":""0.00480000""},{""code"":""310100"",""network"":""Plateau Telecommunications, Inc."",""mtPrice"":""0.00480000""},{""code"":""311090"",""network"":""Flat Wireless, LLC"",""mtPrice"":""0.00480000""},{""code"":""311190"",""network"":""Cellular Properties, Inc."",""mtPrice"":""0.00480000""},{""code"":""311710"",""network"":""NORTHEAST WIRELESS NETWORKS, LLC"",""mtPrice"":""0.00480000""},{""code"":""311370"",""network"":""NACS Wireless, Inc."",""mtPrice"":""0.00480000""},{""code"":""311430"",""network"":""RSA 1 Limited Partnership dba Chat Mobility"",""mtPrice"":""0.00480000""},{""code"":""311100"",""network"":""Nex-Tech Wireless, LLC"",""mtPrice"":""0.00480000""},{""code"":""311240"",""network"":""Cordova Wireless Communications, Inc."",""mtPrice"":""0.00480000""},{""code"":""316011"",""network"":""Southern Communications Services"",""mtPrice"":""0.00480000""},{""code"":""310340"",""network"":""Westlink Communications, LLC"",""mtPrice"":""0.00480000""},{""code"":""311860"",""network"":""Uintah Basin Electronic Telecommunications"",""mtPrice"":""0.00480000""},{""code"":""311670"",""network"":""Pine Belt Cellular, Inc."",""mtPrice"":""0.00480000""},{""code"":""US-PREMIUM"",""network"":""United States Premium"",""mtPrice"":""0.00480000""},{""code"":""310570"",""network"":""MTPCS, LLC"",""mtPrice"":""0.00480000""},{""code"":""310180"",""network"":""CT Cube, L.P. dba West Central Cellular"",""mtPrice"":""0.00480000""},{""code"":""311080"",""network"":""Pine Telephone Co."",""mtPrice"":""0.00480000""},{""code"":""310130"",""network"":""Carolina West"",""mtPrice"":""0.00480000""},{""code"":""310580"",""network"":""Inland Cellular"",""mtPrice"":""0.00480000""},{""code"":""311040"",""network"":""Commnet Wireless, LLC"",""mtPrice"":""0.00480000""},{""code"":""316993"",""network"":""Cablevision Lightpath, Inc. - NY"",""mtPrice"":""0.00480000""},{""code"":""316995"",""network"":""Coral Wireless, LLC"",""mtPrice"":""0.00480000""},{""code"":""311410"",""network"":""Iowa RSA 2 Limited Partnership dba Chat Mobility"",""mtPrice"":""0.00480000""},{""code"":""310630"",""network"":""Choice Wireless LC"",""mtPrice"":""0.00480000""},{""code"":""311420"",""network"":""Northwest Missouri Cellular Limited Partnership"",""mtPrice"":""0.00480000""},{""code"":""310270"",""network"":""POWERTEL MEMPHIS LICENSES, INC."",""mtPrice"":""0.00480000""},{""code"":""31100"",""network"":""Mid-Tex Cellular Ltd."",""mtPrice"":""0.00480000""},{""code"":""311610"",""network"":""North Dakota Network Co dba SRT Wireless"",""mtPrice"":""0.00480000""},{""code"":""316884"",""network"":""Kentucky RSA 4 Cellular General Partnership"",""mtPrice"":""0.00480000""},{""code"":""310540"",""network"":""Oklahoma Western Telephone Company"",""mtPrice"":""0.00480000""},{""code"":""316885"",""network"":""Sagebrush Cellular, Inc."",""mtPrice"":""0.00480000""},{""code"":""316883"",""network"":""Virginia PCS Alliance, L.c."",""mtPrice"":""0.00480000""},{""code"":""312040"",""network"":""Custer Telephone Cooperative, Inc."",""mtPrice"":""0.00480000""},{""code"":""311650"",""network"":""United Wireless Communications, Inc."",""mtPrice"":""0.00480000""},{""code"":""310690"",""network"":""Keystone Wireless, LLC"",""mtPrice"":""0.00480000""},{""code"":""310120"",""network"":""SPRINT Spectrum L.P."",""mtPrice"":""0.00480000""},{""code"":""310020"",""network"":""Union Telephone Company"",""mtPrice"":""0.00480000""},{""code"":""311020"",""network"":""Chariton Valley Cellular"",""mtPrice"":""0.00480000""},{""code"":""311030"",""network"":""Indigo Wireless, Inc."",""mtPrice"":""0.00480000""},{""code"":""311310"",""network"":""New Mexico RSA 6-III Partnership dba Leaco Rural"",""mtPrice"":""0.00480000""},{""code"":""310023"",""network"":""Voicestream GSM I, LLC"",""mtPrice"":""0.00480000""},{""code"":""310320"",""network"":""Smith Bagley Inc. dba Cellular One of Ne Arizona"",""mtPrice"":""0.00480000""},{""code"":""311730"",""network"":""Proximity Mobility, LLC"",""mtPrice"":""0.00480000""},{""code"":""310260"",""network"":""T-mobile USA, Inc."",""mtPrice"":""0.00480000""},{""code"":""310450"",""network"":""N.E. Colorado Cellular, Inc."",""mtPrice"":""0.00480000""},{""code"":""310090"",""network"":""AT&T Mobility"",""mtPrice"":""0.00480000""},{""code"":""310740"",""network"":""Tracy Corporation Ii"",""mtPrice"":""0.00480000""},{""code"":""311690"",""network"":""Telebeeper of New Mexico"",""mtPrice"":""0.00480000""},{""code"":""310840"",""network"":""Telecom North America Mobile Inc"",""mtPrice"":""0.00480000""},{""code"":""310880"",""network"":""Advantage Cellular Systems, Inc."",""mtPrice"":""0.00480000""}]}");
var pricing = Account.GetPricing("US");

Assert.AreEqual("US-FIXED", pricing.networks[0].code);
Assert.AreEqual("United States of America Landline", pricing.networks[0].network);
}

[Test]
[TestMethod]
public void should_set_settings()
{
SetExpect($"{RestUrl}/account/settings",
Expand All @@ -38,7 +38,7 @@ public void should_set_settings()
Assert.AreEqual("http://dr.callbackurl.com", result.drCallbackUrl);
}

[Test]
[TestMethod]
public void should_topUp()
{
SetExpect($"{RestUrl}/account/top-up?trx=00X123456Y7890123Z&api_key={ApiKey}&api_secret={ApiSecret}&",
Expand All @@ -48,7 +48,7 @@ public void should_topUp()
// TODO
}

[Test]
[TestMethod]
public void should_get_numbers()
{
SetExpect($"{RestUrl}/account/numbers?api_key={ApiKey}&api_secret={ApiSecret}&",
Expand Down
16 changes: 8 additions & 8 deletions Nexmo.Api.Test.Unit/ApplicationTest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Net;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Nexmo.Api.Test.Unit
{
[TestFixture]
internal class ApplicationTest : MockedWebTest
[TestClass]
public class ApplicationTest : MockedWebTest
{
[Test]
[TestMethod]
public void should_create_application()
{
var appRequest = new ApplicationRequest
Expand All @@ -26,7 +26,7 @@ public void should_create_application()
Assert.AreEqual("ffffffff-ffff-ffff-ffff-ffffffffffff", result.id);
}

[Test]
[TestMethod]
public void should_get_list_of_applications()
{
SetExpect($"{ApiUrl}/v1/applications?page_size=10&page_index=0&api_key={ApiKey}&api_secret={ApiSecret}&",
Expand All @@ -37,7 +37,7 @@ public void should_get_list_of_applications()
Assert.AreEqual(1, results.Count);
}

[Test]
[TestMethod]
public void should_get_application()
{
var appId = "ffffffff-ffff-ffff-ffff-ffffffffffff";
Expand All @@ -50,7 +50,7 @@ public void should_get_application()
Assert.AreEqual(1, results.Count);
}

[Test]
[TestMethod]
public void should_update_application()
{
var appId = "ffffffff-ffff-ffff-ffff-ffffffffffff";
Expand All @@ -72,7 +72,7 @@ public void should_update_application()
Assert.AreEqual("woocsharptest", result.name);
}

[Test]
[TestMethod]
public void should_delete_application()
{
var appId = "ffffffff-ffff-ffff-ffff-ffffffffffff";
Expand Down
6 changes: 3 additions & 3 deletions Nexmo.Api.Test.Unit/JwtTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Nexmo.Api.Test.Unit
{
[TestFixture]
[TestClass]
public class JwtTest
{
[Test]
[TestMethod]
public void should_generate_jwt()
{
var tok = Jwt.CreateToken(Configuration.Instance.Settings["appSettings:Nexmo.Application.Id"], Configuration.Instance.Settings["appSettings:Nexmo.Application.Key"]);
Expand Down
14 changes: 7 additions & 7 deletions Nexmo.Api.Test.Unit/MockedWebTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Nexmo.Api.Test.Unit
{
[SetUpFixture]
internal class MockedWebTestSetup
[TestClass]
public class MockedWebTestSetup
{
[OneTimeSetUp]
public void Setup()
[AssemblyInitialize]
public static void AssemblyInit(TestContext context)
{
Configuration.Instance.ClientHandler = new FakeClientHandler();
}
}

internal class MockedWebTest
public class MockedWebTest
{
protected string ApiUrl = Configuration.Instance.Settings["appSettings:Nexmo.Url.Api"];
protected string RestUrl = Configuration.Instance.Settings["appSettings:Nexmo.Url.Rest"];
Expand All @@ -41,7 +41,7 @@ protected void SetExpectStatus(HttpStatusCode code)
}
}

internal class FakeClientHandler : HttpClientHandler
public class FakeClientHandler : HttpClientHandler
{
internal Stack<string> ExpectedUris { get; } = new Stack<string>();
internal Stack<string> ExpectedContent { get; } = new Stack<string>();
Expand Down
3 changes: 2 additions & 1 deletion Nexmo.Api.Test.Unit/Nexmo.Api.Test.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="1.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="1.0.2" />
<PackageReference Include="NUnit" Version="3.6.1" />
<PackageReference Include="MSTest.TestAdapter" Version="1.1.13" />
<PackageReference Include="MSTest.TestFramework" Version="1.1.13" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
Expand Down
10 changes: 5 additions & 5 deletions Nexmo.Api.Test.Unit/NumberInsightTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Nexmo.Api.Test.Unit
{
[TestFixture]
internal class NumberInsightTest : MockedWebTest
[TestClass]
public class NumberInsightTest : MockedWebTest
{
[Test]
[TestMethod]
public void should_send_basic_ni_request()
{
SetExpect($"{ApiUrl}/number/format/json",
Expand All @@ -22,7 +22,7 @@ public void should_send_basic_ni_request()
Assert.AreEqual("(555) 555-1212", result.national_format_number);
}

[Test]
[TestMethod]
public void should_send_standard_ni_request()
{
SetExpect($"{ApiUrl}/number/lookup/json",
Expand Down
14 changes: 7 additions & 7 deletions Nexmo.Api.Test.Unit/NumberTest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Linq;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Nexmo.Api.Test.Unit
{
[TestFixture]
internal class NumberTest : MockedWebTest
[TestClass]
public class NumberTest : MockedWebTest
{
[Test]
[TestMethod]
public void should_search_numbers()
{
SetExpect($"{RestUrl}/number/search/?country=US&api_key={ApiKey}&api_secret={ApiSecret}&",
Expand All @@ -21,7 +21,7 @@ public void should_search_numbers()
Assert.AreEqual(5, results.numbers.Count());
}

[Test]
[TestMethod]
public void should_buy_number()
{
SetExpect($"{RestUrl}/number/buy",
Expand All @@ -33,7 +33,7 @@ public void should_buy_number()
Assert.AreEqual("200", result.ErrorCode);
}

[Test]
[TestMethod]
public void should_update_number()
{
SetExpect($"{RestUrl}/number/update",
Expand All @@ -51,7 +51,7 @@ public void should_update_number()
Assert.AreEqual("200", result.ErrorCode);
}

[Test]
[TestMethod]
public void should_cancel_number()
{
SetExpect($"{RestUrl}/number/cancel",
Expand Down
8 changes: 4 additions & 4 deletions Nexmo.Api.Test.Unit/NumberVerifyTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Nexmo.Api.Test.Unit
{
[TestFixture]
internal class NumberVerifyTest : MockedWebTest
[TestClass]
public class NumberVerifyTest : MockedWebTest
{
[Test]
[TestMethod]
public void should_send_control()
{
SetExpect($"{ApiUrl}/verify/control/json?request_id=B41F2D19-913C-4BB3-B825-624E375D2C31&cmd=cancel&api_key={ApiKey}&api_secret={ApiSecret}&",
Expand Down
12 changes: 6 additions & 6 deletions Nexmo.Api.Test.Unit/SearchTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Nexmo.Api.Test.Unit
{
[TestFixture]
internal class SearchTest : MockedWebTest
[TestClass]
public class SearchTest : MockedWebTest
{
[Test]
[TestMethod]
public void should_get_message()
{
SetExpect($"{RestUrl}/search/message?id=03000000FFFFFFFF&api_key={ApiKey}&api_secret={ApiSecret}&",
Expand All @@ -18,7 +18,7 @@ public void should_get_message()
Assert.AreEqual("17775551213", msg.to);
}

[Test]
[TestMethod]
public void should_get_messages()
{
SetExpect($"{RestUrl}/search/messages?date=2015-12-31&to=17775551213&api_key={ApiKey}&api_secret={ApiSecret}&",
Expand All @@ -37,7 +37,7 @@ public void should_get_messages()
Assert.AreEqual("17775551213", msg.to);
}

[Test]
[TestMethod]
public void should_get_rejections()
{
SetExpect($"{RestUrl}/search/rejections?date=2015-12-31&to=17775551213&api_key={ApiKey}&api_secret={ApiSecret}&",
Expand Down
10 changes: 5 additions & 5 deletions Nexmo.Api.Test.Unit/ShortCodeTest.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Nexmo.Api.Test.Unit
{
[TestFixture]
internal class ShortCodeTest : MockedWebTest
[TestClass]
public class ShortCodeTest : MockedWebTest
{
[Test]
[TestMethod]
public void should_initiate_2fa()
{
var request = new ShortCode.TwoFactorAuthRequest
Expand All @@ -25,7 +25,7 @@ public void should_initiate_2fa()
Assert.AreEqual("15555551212", response.messages.First().to);
}

[Test]
[TestMethod]
public void should_initiate_alert()
{
var request = new ShortCode.AlertRequest
Expand Down
13 changes: 7 additions & 6 deletions Nexmo.Api.Test.Unit/SmsTest.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Nexmo.Api.Test.Unit
{
[TestFixture]
internal class SmsTest : MockedWebTest
[TestClass]
public class SmsTest : MockedWebTest
{
[Test]
[TestMethod]
public void should_send_sms()
{
SetExpect($"{RestUrl}/sms/json?from=98975&to=17775551212&text=this+is+a+test&api_key={ApiKey}&api_secret={ApiSecret}&",
"{\"message-count\": \"1\",\"messages\": [{\"to\": \"17775551212\",\"message-id\": \"02000000A3AF32FA\",\"status\": \"0\",\"remaining-balance\": \"7.55560000\",\"message-price\": \"0.00480000\",\"network\": \"310004\"}]}");
SetExpect($"{RestUrl}/sms/json",
"{\"message-count\": \"1\",\"messages\": [{\"to\": \"17775551212\",\"message-id\": \"02000000A3AF32FA\",\"status\": \"0\",\"remaining-balance\": \"7.55560000\",\"message-price\": \"0.00480000\",\"network\": \"310004\"}]}",
$"from=98975&to=17775551212&text=this+is+a+test&api_key={ApiKey}&api_secret={ApiSecret}&");

var results = SMS.Send(new SMS.SMSRequest
{
Expand Down

0 comments on commit 542667f

Please sign in to comment.