diff --git a/PayNLSdk.Tests/Api/Alliance/AddInvoiceRequestTests.cs b/PayNLSdk.Tests/Api/Alliance/AddInvoiceRequestTests.cs index e0809ee..0f79832 100644 --- a/PayNLSdk.Tests/Api/Alliance/AddInvoiceRequestTests.cs +++ b/PayNLSdk.Tests/Api/Alliance/AddInvoiceRequestTests.cs @@ -1,17 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Shouldly; +using Xunit; namespace PayNLSdk.Tests.Api.Alliance { - [TestClass] public class AddInvoiceRequestTests { - private PAYNLSDK.API.Alliance.AddInvoice.Request _sut; + private readonly PAYNLSDK.API.Alliance.AddInvoice.Request _sut; - [TestInitialize] - public void TestInitialize() + public AddInvoiceRequestTests() { _sut = new PAYNLSDK.API.Alliance.AddInvoice.Request( "Dummy", @@ -19,27 +15,27 @@ public void TestInitialize() "Dummy", "Dummy", 12345 - ); + ); } - - [TestMethod] + + [Fact] public void GetParameters_ReturnMandatoryProperties_OnCalled() { // Arrange - + // Act var parameters = _sut.GetParameters(); // Assert - Assert.IsNotNull(parameters["serviceId"]); - Assert.IsNotNull(parameters["merchantId"]); - Assert.IsNotNull(parameters["invoiceId"]); - Assert.IsNotNull(parameters["amount"]); - Assert.IsNotNull(parameters["description"]); + parameters["serviceId"].ShouldNotBeNull(); + parameters["merchantId"].ShouldNotBeNull(); + parameters["invoiceId"].ShouldNotBeNull(); + parameters["amount"].ShouldNotBeNull(); + parameters["description"].ShouldNotBeNull(); } #region Optional parameters - [TestMethod] + [Fact] public void MakeYesterday_internalPropertySet_True() { // Arrange @@ -48,10 +44,10 @@ public void MakeYesterday_internalPropertySet_True() _sut.MakeYesterday = true; // Assert - Assert.AreEqual("true", _sut.GetParameters()["makeYesterday"]); + _sut.GetParameters()["makeYesterday"].ShouldBe("true"); } - [TestMethod] + [Fact] public void MakeYesterday_propertyNotAvailableInInParameters_PropertyIsNotSet() { // Arrange @@ -61,10 +57,10 @@ public void MakeYesterday_propertyNotAvailableInInParameters_PropertyIsNotSet() var parameter = _sut.GetParameters()["makeYesterday"]; // Assert - Assert.IsNull(parameter); + parameter.ShouldBeNull(); } - [TestMethod] + [Fact] public void InvoiceUrl_internalPropertySet_True() { // Arrange @@ -74,10 +70,10 @@ public void InvoiceUrl_internalPropertySet_True() _sut.InvoiceUrl = httpUrlToInvoice; // Assert - Assert.AreEqual(httpUrlToInvoice, _sut.GetParameters()["invoiceUrl"]); + _sut.GetParameters()["invoiceUrl"].ShouldBe(httpUrlToInvoice); } - [TestMethod] + [Fact] public void InvoiceUrl_propertyNotAvailableInInParameters_PropertyIsNotSet() { // Arrange @@ -85,9 +81,8 @@ public void InvoiceUrl_propertyNotAvailableInInParameters_PropertyIsNotSet() // Act var parameter = _sut.GetParameters()["invoiceUrl"]; - // Assert - Assert.IsNull(parameter); + parameter.ShouldBeNull(); } #endregion } diff --git a/PayNLSdk.Tests/Api/Statistics/GetStatsTests.cs b/PayNLSdk.Tests/Api/Statistics/GetStatsTests.cs index c14b57d..0c4de38 100644 --- a/PayNLSdk.Tests/Api/Statistics/GetStatsTests.cs +++ b/PayNLSdk.Tests/Api/Statistics/GetStatsTests.cs @@ -1,27 +1,26 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; -using PayNLSdk.API.Statistics.GetManagement; +using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics.CodeAnalysis; using System.Linq; +using NSubstitute; +using PayNLSdk.API.Statistics.GetManagement; +using Shouldly; +using Xunit; namespace PayNLSdk.Tests.Api.Statistics { - [TestClass] [SuppressMessage("ReSharper", "RedundantNameQualifier", Justification = "We need to be sure the correct object is called in the tests")] public class GetStatsRequestTests { - private PayNLSdk.API.Statistics.GetManagement.Request _sut; + private readonly PayNLSdk.API.Statistics.GetManagement.Request _sut; - [TestInitialize] - public void TestInitialize() + public GetStatsRequestTests() { _sut = new PayNLSdk.API.Statistics.GetManagement.Request(); } - [TestMethod] + [Fact] public void Ctor_FilterPropertyNotTempty_Always() { // Arrange @@ -30,11 +29,11 @@ public void Ctor_FilterPropertyNotTempty_Always() // Act // Assert - Assert.IsNotNull(_sut.Filters); - Assert.AreEqual(0, _sut.Filters.Count); + _sut.Filters.ShouldNotBeNull(); + _sut.Filters.Count.ShouldBe(0); } - [TestMethod] + [Fact] public void Ctor_GroupByPropertyNotTempty_Always() { // Arrange @@ -43,11 +42,11 @@ public void Ctor_GroupByPropertyNotTempty_Always() // Act // Assert - Assert.IsNotNull(_sut.GroupByFieldNames); - Assert.AreEqual(0, _sut.GroupByFieldNames.Count); + _sut.GroupByFieldNames.ShouldNotBeNull(); + _sut.GroupByFieldNames.Count.ShouldBe(0); } - [TestMethod] + [Fact] public void GetParameters_ContainsGroupBy_IfSortByFieldNamesPropertyIsUsed() { // Arrange @@ -57,11 +56,10 @@ public void GetParameters_ContainsGroupBy_IfSortByFieldNamesPropertyIsUsed() var result = _sut.GetParameters(); // Assert - Assert.AreEqual("ABC", result.Get("groupBy[0]")); - + result.Get("groupBy[0]").ShouldBe("ABC"); } - [TestMethod] + [Fact] public void GetParameters_ContainsFilters_MultipleFiltersAdded() { // Arrange @@ -72,70 +70,70 @@ public void GetParameters_ContainsFilters_MultipleFiltersAdded() var result = _sut.GetParameters(); // Assert - Assert.IsTrue(GetWithPartialKey(result, "filterType[").Contains("KEY1")); - Assert.IsTrue(GetWithPartialKey(result, "filterType[").Contains("KEY2")); - Assert.IsTrue(GetWithPartialKey(result, "filterValue[").Contains("VAL1")); - Assert.IsTrue(GetWithPartialKey(result, "filterValue[").Contains("VAL2")); + GetWithPartialKey(result, "filterType[").ShouldContain("KEY1"); + GetWithPartialKey(result, "filterType[").ShouldContain("KEY2"); + GetWithPartialKey(result, "filterValue[").ShouldContain("VAL1"); + GetWithPartialKey(result, "filterValue[").ShouldContain("VAL2"); } - [TestMethod] + [Fact] public void Create_CorrectStartEndDate_LastWeek() { // Arrange - var dateTime = new Mock(); - dateTime.SetupGet(p => p.Now).Returns(new DateTime(2018, 12, 11)); + var dateTime = Substitute.For(); + dateTime.Now.Returns(new DateTime(2018, 12, 11)); // Act - var result = Request.Create(dateTime.Object, Request.StatsPeriod.LastWeek); + var result = Request.Create(dateTime, Request.StatsPeriod.LastWeek); // Assert - Assert.AreEqual(new DateTime(2018,12,3), result.StartDate); - Assert.AreEqual(new DateTime(2018,12,9), result.EndDate); + result.StartDate.ShouldBe(new DateTime(2018, 12, 3)); + result.EndDate.ShouldBe(new DateTime(2018, 12, 9)); } - [TestMethod] + [Fact] public void Create_CorrectStartEndDate_LastMonth() { // Arrange - var dateTime = new Mock(); - dateTime.SetupGet(p => p.Now).Returns(new DateTime(2018, 12, 11)); + var dateTime = Substitute.For(); + dateTime.Now.Returns(new DateTime(2018, 12, 11)); // Act - var result = Request.Create(dateTime.Object, Request.StatsPeriod.LastMonth); + var result = Request.Create(dateTime, Request.StatsPeriod.LastMonth); // Assert - Assert.AreEqual(new DateTime(2018, 11, 1), result.StartDate); - Assert.AreEqual(new DateTime(2018, 11, 30), result.EndDate); + result.StartDate.ShouldBe(new DateTime(2018, 11, 1)); + result.EndDate.ShouldBe(new DateTime(2018, 11, 30)); } - [TestMethod] + [Fact] public void Create_CorrectStartEndDate_ThisWeek() { // Arrange - var dateTime = new Mock(); - dateTime.SetupGet(p => p.Now).Returns(new DateTime(2018, 12, 11)); + var dateTime = Substitute.For(); + dateTime.Now.Returns(new DateTime(2018, 12, 11)); // Act - var result = Request.Create(dateTime.Object, Request.StatsPeriod.ThisWeek); + var result = Request.Create(dateTime, Request.StatsPeriod.ThisWeek); // Assert - Assert.AreEqual(new DateTime(2018, 12, 10), result.StartDate); - Assert.AreEqual(new DateTime(2018, 12, 16), result.EndDate); + result.StartDate.ShouldBe(new DateTime(2018, 12, 10)); + result.EndDate.ShouldBe(new DateTime(2018, 12, 16)); } - [TestMethod] + [Fact] public void Create_CorrectStartEndDate_ThisMonth() { // Arrange - var dateTime = new Mock(); - dateTime.SetupGet(p => p.Now).Returns(new DateTime(2018, 12, 11)); + var dateTime = Substitute.For(); + dateTime.Now.Returns(new DateTime(2018, 12, 11)); // Act - var result = Request.Create(dateTime.Object, Request.StatsPeriod.ThisMonth); + var result = Request.Create(dateTime, Request.StatsPeriod.ThisMonth); // Assert - Assert.AreEqual(new DateTime(2018, 12, 1), result.StartDate); - Assert.AreEqual(new DateTime(2018, 12, 11), result.EndDate); + result.StartDate.ShouldBe(new DateTime(2018, 12, 1)); + result.EndDate.ShouldBe(new DateTime(2018, 12, 11)); } /// diff --git a/PayNLSdk.Tests/Api/Transaction/TransactionRefundTests.cs b/PayNLSdk.Tests/Api/Transaction/TransactionRefundTests.cs index ce28148..89e1fd3 100644 --- a/PayNLSdk.Tests/Api/Transaction/TransactionRefundTests.cs +++ b/PayNLSdk.Tests/Api/Transaction/TransactionRefundTests.cs @@ -1,14 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Shouldly; +using Xunit; namespace PayNLSdk.Tests.Api.Transaction { - [TestClass] public class TransactionRefundTests { - [TestMethod] + [Fact] public void Request_AmountInCents_PassedInAsDecimal() { // Arrange @@ -22,10 +19,10 @@ public void Request_AmountInCents_PassedInAsDecimal() var result = sut.GetParameters(); // Assert - Assert.AreEqual("350", result["amount"]); + result["amount"].ShouldBe("350"); } - [TestMethod] + [Fact] public void Request_NoAmountSupplied_NoParameterWithAmount() { // Arrange @@ -39,9 +36,7 @@ public void Request_NoAmountSupplied_NoParameterWithAmount() var result = sut.GetParameters(); // Assert - Assert.IsNull(result["amount"]); + result["amount"].ShouldBeNull(); } - - } } diff --git a/PayNLSdk.Tests/ExtentionMethods/DateTimeTests.cs b/PayNLSdk.Tests/ExtentionMethods/DateTimeTests.cs index ac1e1f3..b64bf1c 100644 --- a/PayNLSdk.Tests/ExtentionMethods/DateTimeTests.cs +++ b/PayNLSdk.Tests/ExtentionMethods/DateTimeTests.cs @@ -1,36 +1,28 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; using PayNLSdk.ExtentionMethods; +using Shouldly; +using Xunit; namespace PayNLSdk.Tests.ExtentionMethods { - [TestClass] public class DateTimeTests { - [TestInitialize] - public void TestInitialize() - { - - } - - [TestMethod] + [Fact] public void LastMonthFirstDay_February_CurrentlyMarch() { // Arrange - var initialDate = new DateTime(2018,2,5); + var initialDate = new DateTime(2018, 2, 5); // Act var result = initialDate.LastMonthFirstDay(); // Assert - Assert.AreEqual(2018, result.Year); - Assert.AreEqual(1, result.Month); - Assert.AreEqual(1, result.Day); + result.Year.ShouldBe(2018); + result.Month.ShouldBe(1); + result.Day.ShouldBe(1); } - [TestMethod] + [Fact] public void LastMonthFirstDay_DecemberPreviousYear_CurrentlyFirstJanuary() { // Arrange @@ -40,12 +32,12 @@ public void LastMonthFirstDay_DecemberPreviousYear_CurrentlyFirstJanuary() var result = initialDate.LastMonthFirstDay(); // Assert - Assert.AreEqual(2017, result.Year); - Assert.AreEqual(12, result.Month); - Assert.AreEqual(1, result.Day); + result.Year.ShouldBe(2017); + result.Month.ShouldBe(12); + result.Day.ShouldBe(1); } - [TestMethod] + [Fact] public void LastMonthFirstDay_PreviousMonth_LastDayOfTheMonth() { // Arrange @@ -55,26 +47,26 @@ public void LastMonthFirstDay_PreviousMonth_LastDayOfTheMonth() var result = initialDate.LastMonthFirstDay(); // Assert - Assert.AreEqual(2017, result.Year); - Assert.AreEqual(12, result.Month); - Assert.AreEqual(1, result.Day); + result.Year.ShouldBe(2017); + result.Month.ShouldBe(12); + result.Day.ShouldBe(1); } - [TestMethod] + [Fact] public void LastWeek_PreviousMonday_TodaySaturday() { // Arrange - var initialDate = new DateTime(2018,10,13); + var initialDate = new DateTime(2018, 10, 13); // Act var result = initialDate.LastWeek(DayOfWeek.Monday); // Assert - Assert.AreEqual(new DateTime(2018,10,1), result); - Assert.AreEqual(DayOfWeek.Monday, result.DayOfWeek); + result.ShouldBe(new DateTime(2018, 10, 1)); + result.DayOfWeek.ShouldBe(DayOfWeek.Monday); } - [TestMethod] + [Fact] public void LastWeek_PreviousMonday_TodayMonday() { // Arrange @@ -84,11 +76,11 @@ public void LastWeek_PreviousMonday_TodayMonday() var result = initialDate.LastWeek(DayOfWeek.Monday); // Assert - Assert.AreEqual(new DateTime(2018, 12, 3), result); - Assert.AreEqual(DayOfWeek.Monday, result.DayOfWeek); + result.ShouldBe(new DateTime(2018, 12, 3)); + result.DayOfWeek.ShouldBe(DayOfWeek.Monday); } - [TestMethod] + [Fact] public void LastWeek_PreviousMonday_TodaySunday() { // Arrange @@ -98,11 +90,11 @@ public void LastWeek_PreviousMonday_TodaySunday() var result = initialDate.LastWeek(DayOfWeek.Monday); // Assert - Assert.AreEqual(new DateTime(2018, 11, 26), result); - Assert.AreEqual(DayOfWeek.Monday, result.DayOfWeek); + result.ShouldBe(new DateTime(2018, 11, 26)); + result.DayOfWeek.ShouldBe(DayOfWeek.Monday); } - [TestMethod] + [Fact] public void LastMonthLastDay_Lastday_normalconditions() { // Arrange @@ -112,13 +104,12 @@ public void LastMonthLastDay_Lastday_normalconditions() var result = initialDate.LastMonthLastDay(); // Assert - Assert.AreEqual(2018, result.Year); - Assert.AreEqual(6, result.Month); - Assert.AreEqual(30, result.Day); + result.Year.ShouldBe(2018); + result.Month.ShouldBe(6); + result.Day.ShouldBe(30); } - - [TestMethod] + [Fact] public void LastMonthLastDay_31DecemberPreviousYear_CurrentlyFirstJanuary() { // Arrange @@ -128,12 +119,12 @@ public void LastMonthLastDay_31DecemberPreviousYear_CurrentlyFirstJanuary() var result = initialDate.LastMonthLastDay(); // Assert - Assert.AreEqual(2017, result.Year); - Assert.AreEqual(12, result.Month); - Assert.AreEqual(31, result.Day); + result.Year.ShouldBe(2017); + result.Month.ShouldBe(12); + result.Day.ShouldBe(31); } - [TestMethod] + [Fact] public void LastMonthLastDay_1March_LeapYear() { // Arrange @@ -143,9 +134,9 @@ public void LastMonthLastDay_1March_LeapYear() var result = initialDate.LastMonthLastDay(); // Assert - Assert.AreEqual(2004, result.Year); - Assert.AreEqual(2, result.Month); - Assert.AreEqual(29, result.Day); + result.Year.ShouldBe(2004); + result.Month.ShouldBe(2); + result.Day.ShouldBe(29); } } } diff --git a/PayNLSdk.Tests/PayNLSdk.Tests.csproj b/PayNLSdk.Tests/PayNLSdk.Tests.csproj index a31c450..815524c 100644 --- a/PayNLSdk.Tests/PayNLSdk.Tests.csproj +++ b/PayNLSdk.Tests/PayNLSdk.Tests.csproj @@ -1,18 +1,19 @@ - + net8.0 false Debug;Release;AppVeyor - - - - - - - - + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/PayNLSdk.Tests/ServiceTests.cs b/PayNLSdk.Tests/ServiceTests.cs index cd7dc04..d18f2c2 100644 --- a/PayNLSdk.Tests/ServiceTests.cs +++ b/PayNLSdk.Tests/ServiceTests.cs @@ -1,51 +1,45 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; +using NSubstitute; using PAYNLSDK; using PAYNLSDK.Net; +using Xunit; namespace PayNLSdk.Tests { - [TestClass] public class ServiceTests { - private Mock _iClientMock; - private Service _sut; + private readonly IClient _client; + private readonly Service _sut; - [TestInitialize] - public void TestInitialize() + public ServiceTests() { - _iClientMock = new Mock(); - _sut = new Service(_iClientMock.Object); + _client = Substitute.For(); + _sut = new Service(_client); } - [TestMethod] + [Fact] public void GetCategories_withoutParams() { // Arrange // Act - var result = _sut.GetCategories(); + _sut.GetCategories(); // Assert - _iClientMock.Verify( - o => o.PerformRequest(It.IsAny()), - Times.Once); + _client.Received(1).PerformRequest(Arg.Any()); // Assert.IsNotNull(result); // UNTESTABLE CURRENTLY } - [TestMethod] + [Fact] public void GetCategories_withParams() { // Arrange - int paymentOptionId = 1; + const int paymentOptionId = 1; // Act - var result = _sut.GetCategories(paymentOptionId); + _sut.GetCategories(paymentOptionId); // Assert - _iClientMock.Verify( - o => o.PerformRequest(It.IsAny()), - Times.Once); + _client.Received(1).PerformRequest(Arg.Any()); // Assert.IsNotNull(result); // UNTESTABLE CURRENTLY } } diff --git a/PayNLSdk.Tests/Utilities/ValidationTests.cs b/PayNLSdk.Tests/Utilities/ValidationTests.cs index d07422c..ff8f403 100644 --- a/PayNLSdk.Tests/Utilities/ValidationTests.cs +++ b/PayNLSdk.Tests/Utilities/ValidationTests.cs @@ -1,45 +1,33 @@ using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; using PAYNLSDK.Utilities; +using Shouldly; +using Xunit; namespace PayNLSdk.Tests.Utilities { - [TestClass] public class ValidationTests { - [TestMethod] + [Fact] public void IsNotEmpty_DoesNotThrow_AbcInput() { // Arrange var input = "abc"; - // Act - try - { - ParameterValidator.IsNotEmpty(input, "someParamName"); - } - catch (ArgumentException) - { - Assert.Fail("should not throw"); - } - - // Assert + // Act & Assert + Should.NotThrow(() => ParameterValidator.IsNotEmpty(input, "someParamName")); } - [ExpectedException(typeof(ArgumentException), "We expected an exception")] - [TestMethod] + [Fact] public void IsNotEmpty_ThrowsException_EmptyString() { // Arrange - var input = ""; + var input = string.Empty; - // Act - ParameterValidator.IsNotEmpty(input, "someParamName"); - - // Assert + // Act & Assert + Should.Throw(() => ParameterValidator.IsNotEmpty(input, "someParamName")); } - [TestMethod] + [Fact] public void IsEmpty_False_AbcInput() { // Arrange @@ -47,22 +35,22 @@ public void IsEmpty_False_AbcInput() // Act var result = ParameterValidator.IsEmpty(input); - + // Assert - Assert.IsFalse(result); + result.ShouldBeFalse(); } - [TestMethod] + [Fact] public void IsEmpty_True_EmptyString() { // Arrange - var input = ""; + var input = string.Empty; // Act var result = ParameterValidator.IsEmpty(input); // Assert - Assert.IsTrue(result); + result.ShouldBeTrue(); } } }