From 2c9293ccae1f973fd6087e30dcebcb745d136eac Mon Sep 17 00:00:00 2001 From: Benjamin Gottschalk Date: Thu, 28 Jul 2022 09:57:00 +0200 Subject: [PATCH 01/11] added IntegrationTestSettings.cs --- .../IntegrationTests/IntegrationTestSettings.cs | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Billbee.Api.Client.Test/IntegrationTests/IntegrationTestSettings.cs diff --git a/Billbee.Api.Client.Test/IntegrationTests/IntegrationTestSettings.cs b/Billbee.Api.Client.Test/IntegrationTests/IntegrationTestSettings.cs new file mode 100644 index 0000000..b90a0de --- /dev/null +++ b/Billbee.Api.Client.Test/IntegrationTests/IntegrationTestSettings.cs @@ -0,0 +1,6 @@ +namespace Billbee.Api.Client.Test.IntegrationTests; + +public static class IntegrationTestSettings +{ + public static bool RunIntegrationTests = false; +} \ No newline at end of file From 49e40f7797c243653c0d743f0f396709ba22db3a Mon Sep 17 00:00:00 2001 From: Benjamin Gottschalk Date: Wed, 3 Aug 2022 09:48:34 +0200 Subject: [PATCH 02/11] added missing endpoints --- Billbee.Api.Client.Test/.gitignore | 1 + Billbee.Api.Client.Test/ApiClientTest.cs | 147 ++++++++++++++++ Billbee.Api.Client.Test/ApiSyncTest.cs | 115 +++++++++++++ .../Billbee.Api.Client.Test.csproj | 24 +++ ...tomaticProvisionEndPointIntegrationTest.cs | 21 +++ .../CloudStoragesEndPointIntegrationTest.cs | 14 ++ .../EventEndPointIntegrationTest.cs | 14 ++ .../Helpers/CrudHelpers.cs | 108 ++++++++++++ .../Helpers/IntegrationTestHelpers.cs | 46 +++++ .../Helpers/IntegrationTestSettings.cs | 9 + .../Helpers/RequiresApiAccessAttribute.cs | 6 + .../Helpers/TestData.cs | 93 +++++++++++ .../SearchEndPointIntegrationTest.cs | 14 ++ .../WebhookEndPointIntegrationTest.cs | 123 ++++++++++++++ .../CustomerAddressesEndPointTest.cs | 82 +++++++++ .../EndPointTests/CustomerEndPointTest.cs | 65 ++++++++ .../EndPointTests/EnumEndPointTest.cs | 55 ++++++ .../EndPointTests/OrderEndPointTest.cs | 37 +++++ .../EndPointTests/ProductEndPointTest.cs | 49 +++++- .../EndPointTests/ShipmentEndPointTest.cs | 17 +- .../EndPointTests/WebhookEndPointTest.cs | 2 +- .../IntegrationTestSettings.cs | 6 - Billbee.Api.Client.Test/TestHelpers.cs | 1 + Billbee.Api.Client.Test/Usings.cs | 1 + Billbee.Api.Client.Test/config.test.json | 7 + Billbee.Api.Client.Test/readme.txt | 6 + Billbee.Api.Client/ApiClient.cs | 20 ++- Billbee.Api.Client/ApiMappingAttribute.cs | 30 ++++ Billbee.Api.Client/BillbeeRestClient.cs | 157 +++++++++++++----- .../Endpoint/AutomaticProvisionEndPoint.cs | 5 +- .../Endpoint/CloudStoragesEndPoint.cs | 1 + .../Endpoint/CustomerAddressesEndPoint.cs | 54 ++++++ .../Endpoint/CustomerEndPoint.cs | 30 ++++ Billbee.Api.Client/Endpoint/EnumEndPoint.cs | 40 +++++ Billbee.Api.Client/Endpoint/EventEndPoint.cs | 1 + .../Interfaces/ICustomerAddressesEndPoint.cs | 37 +++++ .../Endpoint/Interfaces/ICustomerEndPoint.cs | 29 ++++ .../Endpoint/Interfaces/IEnumEndPoint.cs | 32 ++++ .../Endpoint/Interfaces/IOrderEndPoint.cs | 14 ++ .../Endpoint/Interfaces/IProductEndPoint.cs | 19 +++ .../Endpoint/Interfaces/IShipmentEndPoint.cs | 18 +- .../Endpoint/Interfaces/IWebhookEndPoint.cs | 4 +- Billbee.Api.Client/Endpoint/OrderEndPoint.cs | 28 ++++ .../Endpoint/ProductEndPoint.cs | 40 ++++- Billbee.Api.Client/Endpoint/SearchEndPoint.cs | 1 + .../Endpoint/ShipmentEndPoint.cs | 39 ++++- .../Endpoint/WebhookEndPoint.cs | 11 +- Billbee.Api.Client/Enums/PaymentTypeEnum.cs | 3 + Billbee.Api.Client/Enums/ShipmentTypeEnum.cs | 8 + .../Enums/ShippingCarrierEnum.cs | 25 +++ Billbee.Api.Client/IApiClient.cs | 10 ++ Billbee.Api.Client/Model/CustomerAddress.cs | 2 +- Billbee.Api.Client/Model/EnumEntry.cs | 8 + .../Model/ParsePlaceholdersQuery.cs | 26 +++ .../Model/ParsePlaceholdersResult.cs | 7 + Billbee.Api.Client/Model/Shipment.cs | 110 ++++-------- Billbee.Api.Client/Model/ShipmentPost.cs | 92 ++++++++++ 57 files changed, 1814 insertions(+), 150 deletions(-) create mode 100644 Billbee.Api.Client.Test/.gitignore create mode 100644 Billbee.Api.Client.Test/ApiClientTest.cs create mode 100644 Billbee.Api.Client.Test/ApiSyncTest.cs create mode 100644 Billbee.Api.Client.Test/Billbee.Api.Client.Test.csproj create mode 100644 Billbee.Api.Client.Test/EndPointIntegrationTests/AutomaticProvisionEndPointIntegrationTest.cs create mode 100644 Billbee.Api.Client.Test/EndPointIntegrationTests/CloudStoragesEndPointIntegrationTest.cs create mode 100644 Billbee.Api.Client.Test/EndPointIntegrationTests/EventEndPointIntegrationTest.cs create mode 100644 Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs create mode 100644 Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/IntegrationTestHelpers.cs create mode 100644 Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/IntegrationTestSettings.cs create mode 100644 Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/RequiresApiAccessAttribute.cs create mode 100644 Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/TestData.cs create mode 100644 Billbee.Api.Client.Test/EndPointIntegrationTests/SearchEndPointIntegrationTest.cs create mode 100644 Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs create mode 100644 Billbee.Api.Client.Test/EndPointTests/CustomerAddressesEndPointTest.cs create mode 100644 Billbee.Api.Client.Test/EndPointTests/EnumEndPointTest.cs delete mode 100644 Billbee.Api.Client.Test/IntegrationTests/IntegrationTestSettings.cs create mode 100644 Billbee.Api.Client.Test/Usings.cs create mode 100644 Billbee.Api.Client.Test/config.test.json create mode 100644 Billbee.Api.Client.Test/readme.txt create mode 100644 Billbee.Api.Client/ApiMappingAttribute.cs create mode 100644 Billbee.Api.Client/Endpoint/CustomerAddressesEndPoint.cs create mode 100644 Billbee.Api.Client/Endpoint/EnumEndPoint.cs create mode 100644 Billbee.Api.Client/Endpoint/Interfaces/ICustomerAddressesEndPoint.cs create mode 100644 Billbee.Api.Client/Endpoint/Interfaces/IEnumEndPoint.cs create mode 100644 Billbee.Api.Client/Enums/ShipmentTypeEnum.cs create mode 100644 Billbee.Api.Client/Enums/ShippingCarrierEnum.cs create mode 100644 Billbee.Api.Client/Model/EnumEntry.cs create mode 100644 Billbee.Api.Client/Model/ParsePlaceholdersQuery.cs create mode 100644 Billbee.Api.Client/Model/ParsePlaceholdersResult.cs create mode 100644 Billbee.Api.Client/Model/ShipmentPost.cs diff --git a/Billbee.Api.Client.Test/.gitignore b/Billbee.Api.Client.Test/.gitignore new file mode 100644 index 0000000..983d205 --- /dev/null +++ b/Billbee.Api.Client.Test/.gitignore @@ -0,0 +1 @@ +config.prod.json \ No newline at end of file diff --git a/Billbee.Api.Client.Test/ApiClientTest.cs b/Billbee.Api.Client.Test/ApiClientTest.cs new file mode 100644 index 0000000..4680df3 --- /dev/null +++ b/Billbee.Api.Client.Test/ApiClientTest.cs @@ -0,0 +1,147 @@ +using System.Reflection; +using System.Text; +using Billbee.Api.Client.EndPoint; +using Billbee.Api.Client.Enums; + +namespace Billbee.Api.Client.Test; + +[TestClass] +public class ApiClientTest +{ + [TestMethod] + public void InitTest() + { + var uut = new ApiClient(); + + Assert.IsNotNull(uut); + Assert.IsNotNull(uut.Configuration); + Assert.IsNull(uut.Configuration.Username); + Assert.IsNull(uut.Configuration.Password); + Assert.IsNull(uut.Configuration.ApiKey); + Assert.AreEqual("https://app.billbee.io/api/v1", uut.Configuration.BaseUrl); + Assert.AreEqual(ErrorHandlingEnum.ThrowException, uut.Configuration.ErrorHandlingBehaviour); + + Assert.IsNotNull(uut.AutomaticProvision); + Assert.IsNotNull(uut.CloudStorages); + Assert.IsNotNull(uut.Customer); + Assert.IsNotNull(uut.Events); + Assert.IsNotNull(uut.Orders); + Assert.IsNotNull(uut.Products); + Assert.IsNotNull(uut.Search); + Assert.IsNotNull(uut.Shipment); + Assert.IsNotNull(uut.Webhooks); + } + + [TestMethod] + public void InitWithConfigTest() + { + var config = new ApiConfiguration + { + Username = "myUser", + Password = "myPwd", + ApiKey = "myApiKey", + BaseUrl = "myBaseUrl", + ErrorHandlingBehaviour = ErrorHandlingEnum.ReturnErrorContent + }; + + var uut = new ApiClient(config); + + Assert.IsNotNull(uut); + Assert.IsNotNull(uut.Configuration); + Assert.AreEqual("myUser", uut.Configuration.Username); + Assert.AreEqual("myPwd", uut.Configuration.Password); + Assert.AreEqual("myApiKey", uut.Configuration.ApiKey); + Assert.AreEqual("myBaseUrl", uut.Configuration.BaseUrl); + Assert.AreEqual(ErrorHandlingEnum.ReturnErrorContent, uut.Configuration.ErrorHandlingBehaviour); + } + + [TestMethod] + public void InitWithConfigFileTest() + { + var fiDll = new FileInfo(Assembly.GetExecutingAssembly().Location); + var path = Path.Combine(fiDll.Directory.FullName, "../../../config.test"); + var uut = new ApiClient(path); + + Assert.IsNotNull(uut); + Assert.IsNotNull(uut.Configuration); + Assert.AreEqual("myUserFromFile", uut.Configuration.Username); + Assert.AreEqual("myPwdFromFile", uut.Configuration.Password); + Assert.AreEqual("myApiKeyFromFile", uut.Configuration.ApiKey); + Assert.AreEqual("myBaseUrlFromFile", uut.Configuration.BaseUrl); + Assert.AreEqual(ErrorHandlingEnum.ReturnErrorContent, uut.Configuration.ErrorHandlingBehaviour); + } + + private class TypeMapping + { + public TypeMapping(string uutClass, string uutTypeName, string testTypeName, bool foundMapping) + { + UutClass = uutClass; + UutTypeName = uutTypeName; + TestTypeName = testTypeName; + FoundMapping = foundMapping; + } + + public string UutClass { get; } + public string UutTypeName { get; } + public string TestTypeName { get; } + public bool FoundMapping { get; } + } + + [TestMethod] + public void UnitTestsForAllEndpointsTest() + { + CheckTestMethods("Test", "Test"); + } + + [TestMethod] + public void IntegrationTestsForAllEndpointsTest() + { + CheckTestMethods( "IntegrationTest", "_IntegrationTest"); + } + + private void CheckTestMethods(string testClassPostfix, string testMethodPostfix) + { + var clientAssembly = Assembly.Load("Billbee.Api.Client"); + var clientTypes = clientAssembly.GetTypes(); + var testAssembly = Assembly.GetExecutingAssembly(); + var testTypes = testAssembly.GetTypes(); + + var typeMappingsTestMethods = new List(); + foreach (var clientType in clientTypes) + { + var clientTypeName = clientType.Name; + if (clientType.Namespace == null || !clientType.Namespace.StartsWith("Billbee.Api.Client.EndPoint")) + { + continue; + } + + var testTypeName = clientType.Name + testClassPostfix; + var testType = testTypes.FirstOrDefault(t => t.IsClass && t.IsPublic && t.Name == testTypeName && t.GetCustomAttributes().Any(a => a is TestClassAttribute)); + + var bindingFlags = BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance; + var clientMethods = clientType.GetMethods(bindingFlags); + var testMethods = testType.GetMethods(bindingFlags).Where(m => m.GetCustomAttributes().Any(a => a is TestMethodAttribute)).ToList(); + foreach (var clientMethod in clientMethods) + { + var clientMethodName = clientMethod.Name; + + var testMethodName = clientMethodName + testMethodPostfix; + var foundMapping = testMethods.Any(t => t.Name == testMethodName); + if (clientTypeName != nameof(EnumEndPoint)) + { + typeMappingsTestMethods.Add(new TypeMapping(clientTypeName, clientMethodName, testMethodName, foundMapping)); + } + } + } + + Console.WriteLine($"#SdkMethods={typeMappingsTestMethods.Count}, #{testMethodPostfix}Methods={typeMappingsTestMethods.Count(t => t.FoundMapping)}"); + Console.WriteLine(); + Console.WriteLine($"Test implemented,ClassName,UutTypeName,TestTypeName"); + foreach (var typeMapping in typeMappingsTestMethods) + { + Console.WriteLine($"{typeMapping.FoundMapping},{typeMapping.UutClass},{typeMapping.UutTypeName},{typeMapping.TestTypeName}"); + } + + Assert.IsTrue(typeMappingsTestMethods.All(t => t.FoundMapping)); + } +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/ApiSyncTest.cs b/Billbee.Api.Client.Test/ApiSyncTest.cs new file mode 100644 index 0000000..0d01679 --- /dev/null +++ b/Billbee.Api.Client.Test/ApiSyncTest.cs @@ -0,0 +1,115 @@ +using System.Diagnostics; +using System.Reflection; +using Microsoft.OpenApi; +using Microsoft.OpenApi.Extensions; +using Microsoft.OpenApi.Models; +using Microsoft.OpenApi.Readers; + +namespace Billbee.Api.Client.Test; + +[TestClass] +public class ApiSyncTest +{ + [DebuggerDisplay("{Path}:{HttpOperation}")] + public class ApiOperation + { + public string Path { get; set; } + public HttpOperation HttpOperation { get; set; } + + public override string ToString() => $"{Path}:{HttpOperation}"; + } + + [TestMethod] + public async Task ApiSyncCheckTest() + { + var sdkOps = GetSdkOperations(); + var apiOps = await GetApiOperations(); + + var missingSdkOps = new List(); + foreach (var apiOp in apiOps) + { + if (!sdkOps.Any(sdkOp => sdkOp.Path == apiOp.Path && sdkOp.HttpOperation == apiOp.HttpOperation)) + { + missingSdkOps.Add(apiOp); + } + } + + Console.WriteLine($"#ApiOps={apiOps.Count}, #SdkOps={sdkOps.Count}, #MissingSdkOps={missingSdkOps.Count}"); + + if (missingSdkOps.Count > 0) + { + Console.WriteLine("Missing Sdk Operations:"); + foreach (var missingSdkOp in missingSdkOps) + { + Console.WriteLine(missingSdkOp.ToString()); + } + } + + Assert.AreEqual(0, missingSdkOps.Count); + } + + private async Task> GetApiOperations() + { + var apiOps = new List(); + var openApiDoc = await GetOpenApiDoc(); + foreach (var path in openApiDoc.Paths) + { + foreach (var op in path.Value.Operations) + { + if (Enum.TryParse(op.Key.ToString(), out HttpOperation httpOperation)) + { + var apiOp = new ApiOperation + { + Path = path.Key, + HttpOperation = httpOperation + }; + apiOps.Add(apiOp); + } + else + { + Assert.Fail("unknown Path.OperationType"); + } + } + } + + return apiOps; + } + + private static List GetSdkOperations() + { + var sdkOps = new List(); + var endpointTypes = Assembly.GetAssembly(typeof(ApiClient))!.GetTypes() + .Where(t => t.Namespace == "Billbee.Api.Client.EndPoint"); + foreach (var endpoint in endpointTypes) + { + foreach (var methodInfo in endpoint.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | + BindingFlags.Public)) + { + if (methodInfo.GetCustomAttributes(true).FirstOrDefault(x => x is ApiMappingAttribute) is + ApiMappingAttribute apiMappingAttr) + { + var op = new ApiOperation + { + Path = apiMappingAttr.ApiPath, + HttpOperation = apiMappingAttr.HttpOperation + }; + sdkOps.Add(op); + } + } + } + + return sdkOps; + } + + private async Task GetOpenApiDoc() + { + var httpClient = new HttpClient + { + BaseAddress = new Uri("https://app.billbee.io/") + }; + + var stream = await httpClient.GetStreamAsync("/swagger/docs/v1"); + + return new OpenApiStreamReader().Read(stream, out var diagnostic); + } +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/Billbee.Api.Client.Test.csproj b/Billbee.Api.Client.Test/Billbee.Api.Client.Test.csproj new file mode 100644 index 0000000..cc2e731 --- /dev/null +++ b/Billbee.Api.Client.Test/Billbee.Api.Client.Test.csproj @@ -0,0 +1,24 @@ + + + + net6.0 + enable + enable + + false + + + + + + + + + + + + + + + + diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/AutomaticProvisionEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/AutomaticProvisionEndPointIntegrationTest.cs new file mode 100644 index 0000000..ce46900 --- /dev/null +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/AutomaticProvisionEndPointIntegrationTest.cs @@ -0,0 +1,21 @@ +using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; + +namespace Billbee.Api.Client.Test.EndPointIntegrationTests; + +[TestClass] +public class AutomaticProvisionEndPointIntegrationTest +{ + [TestMethod] + [RequiresApiAccess] + public void CreateAccount_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void TermsInfo_IntegrationTest() + { + Assert.Inconclusive(); + } +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/CloudStoragesEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/CloudStoragesEndPointIntegrationTest.cs new file mode 100644 index 0000000..01c7a9a --- /dev/null +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/CloudStoragesEndPointIntegrationTest.cs @@ -0,0 +1,14 @@ +using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; + +namespace Billbee.Api.Client.Test.EndPointIntegrationTests; + +[TestClass] +public class CloudStoragesEndPointIntegrationTest +{ + [TestMethod] + [RequiresApiAccess] + public void GetCloudStorageList_IntegrationTest() + { + Assert.Inconclusive(); + } +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/EventEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/EventEndPointIntegrationTest.cs new file mode 100644 index 0000000..0c65c0b --- /dev/null +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/EventEndPointIntegrationTest.cs @@ -0,0 +1,14 @@ +using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; + +namespace Billbee.Api.Client.Test.EndPointIntegrationTests; + +[TestClass] +public class EventEndPointIntegrationTest +{ + [TestMethod] + [RequiresApiAccess] + public void GetEvents_IntegrationTest() + { + Assert.Inconclusive(); + } +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs new file mode 100644 index 0000000..5659a00 --- /dev/null +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs @@ -0,0 +1,108 @@ +using Billbee.Api.Client.Model; + +namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; + +public static class CrudHelpers +{ + public static List GetAll(Func> func) + { + string typeName = typeof(T).Name; + + Console.WriteLine(); + Console.WriteLine($"Get all {typeName}s..."); + + var result = func(); + Assert.IsNotNull(result); + Console.WriteLine($"Got {result.Count} {typeName}s"); + + return result; + } + + public static T Create(Func func) + { + string typeName = typeof(T).Name; + + Console.WriteLine(); + Console.WriteLine($"Create new {typeName}..."); + + dynamic result = func(); + var createdItem = result; + Assert.IsNotNull(createdItem); + Console.WriteLine($"{typeName} created, id={createdItem.Id}"); + + return createdItem; + } + + public static T GetOne(Func func, dynamic id) + { + string typeName = typeof(T).Name; + + Console.WriteLine(); + Console.WriteLine($"Get {typeName} with id={id}..."); + + var result = func(id); + var gotItem = result; + Assert.IsNotNull(gotItem); + Assert.AreEqual(id, gotItem.Id); + Console.WriteLine($"Got {typeName}, id={gotItem.Id}"); + + return gotItem; + } + + public static void DeleteOne(Action func, dynamic id) + { + string typeName = typeof(T).Name; + + Console.WriteLine(); + Console.WriteLine($"Delete {typeName} with id={id}"); + + func(id); + Console.WriteLine($"Deleted {typeName}"); + } + + public static void DeleteAll(Action func) + { + string typeName = typeof(T).Name; + + Console.WriteLine(); + Console.WriteLine($"Delete all {typeName}s"); + + func(); + Console.WriteLine($"Deleted all {typeName}s"); + } + + public static void GetOneExpectException(Func func, dynamic id) + { + string typeName = typeof(T).Name; + + Console.WriteLine(); + Console.WriteLine($"Get {typeName} with id={id}..."); + + Assert.ThrowsException(() => func(id)); + Console.WriteLine($"{typeName} could not be found (as expected)"); + } + + public static T Put(Func func, dynamic item) + { + string typeName = typeof(T).Name; + + Console.WriteLine(); + Console.WriteLine($"Put {typeName} with id={item.Id}..."); + + var updatedItem = func(item); + Console.WriteLine($"Got {typeName}, id={updatedItem.Id}"); + + return updatedItem; + } + + public static void Put(Action func, dynamic item) + { + string typeName = typeof(T).Name; + + Console.WriteLine(); + Console.WriteLine($"Put {typeName} with id={item.Id}..."); + + func(item); + Console.WriteLine($"Done"); + } +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/IntegrationTestHelpers.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/IntegrationTestHelpers.cs new file mode 100644 index 0000000..4a6077f --- /dev/null +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/IntegrationTestHelpers.cs @@ -0,0 +1,46 @@ +using System.Reflection; + +namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; + +public static class IntegrationTestHelpers +{ + public static void CheckAccess(string testContextManagedType, string testContextManagedMethod) + { + if (!IntegrationTestSettings.RunIntegrationTests) + { + Assert.Inconclusive( + $"This test is an integration-test. But integration-tests are disable currently (see property {nameof(IntegrationTestSettings)}{nameof(IntegrationTestSettings.RunIntegrationTests)})."); + return; + } + + var type = Assembly.GetExecutingAssembly().GetType(testContextManagedType); + var mi = type.GetMethod(testContextManagedMethod); + bool requiresApiAccess = mi.GetCustomAttributes().Any(); + if (requiresApiAccess && !IntegrationTestSettings.AllowReadWriteAccessToBillbeeApi) + { + Assert.Inconclusive( + $"This test is an integration-test and requires api-access. But api-access is not granted currently (see property {nameof(IntegrationTestSettings)}{nameof(IntegrationTestSettings.AllowReadWriteAccessToBillbeeApi)})."); + } + } + + public static ApiClient ApiClient + { + get + { + var fiDll = new FileInfo(Assembly.GetExecutingAssembly().Location); + var di = new DirectoryInfo(Path.Combine(fiDll.Directory.FullName, "../../../")); + var path = Path.Combine(di.FullName, "config.prod"); + if (!File.Exists(path + ".json")) + { + Assert.Fail( + $"This test requires api-access, but the required config-file could not be found: '{path}.json'"); + } + + Thread.Sleep(500); // throttle api-calls when executing multiple tests + var apiClient = new ApiClient(path, null, IntegrationTestSettings.AllowReadWriteAccessToBillbeeApi); + Assert.IsTrue(apiClient.TestConfiguration()); + + return apiClient; + } + } +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/IntegrationTestSettings.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/IntegrationTestSettings.cs new file mode 100644 index 0000000..d044354 --- /dev/null +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/IntegrationTestSettings.cs @@ -0,0 +1,9 @@ +namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; + +public static class IntegrationTestSettings +{ + public static bool RunIntegrationTests = false; + + // !!! be careful: setting the following property to 'true' will potentially add/change/delete parts your billbee data !!! + public static bool AllowReadWriteAccessToBillbeeApi = false; +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/RequiresApiAccessAttribute.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/RequiresApiAccessAttribute.cs new file mode 100644 index 0000000..9bd6a8a --- /dev/null +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/RequiresApiAccessAttribute.cs @@ -0,0 +1,6 @@ +namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; + +public class RequiresApiAccessAttribute : Attribute +{ + +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/TestData.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/TestData.cs new file mode 100644 index 0000000..853e396 --- /dev/null +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/TestData.cs @@ -0,0 +1,93 @@ +using Billbee.Api.Client.Model; + +namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; + +public static class TestData +{ + public static CustomerAddress CustomerAddress => + new CustomerAddress + { + FirstName = "John", + LastName = "Doe", + Street = "Mustergasse", + Housenumber = "1", + Zip = "12345", + City = "Musterstadt", + AddressType = 1, + CountryCode = "DE", + CustomerId = 0 + }; + + public static Product Product => new Product + { + Title = new List + { + new MultiLanguageString() + { + Text = "the Title", + LanguageCode = "de" + } + }, + Type = 0, + Images = new List(), + InvoiceText = new List + { + new MultiLanguageString() + { + Text = "invoice text", + LanguageCode = "de" + } + }, + }; + + public static Webhook WebHook => new Webhook + { + Id = null, + WebHookUri = "https://webhook.site/5290627f-b5e3-4123-a715-26a721054617?noecho", + Secret = "4e4451af-63c5-44f4-a3c5-1dcf8617fc5c", + Description = "A simple description", + IsPaused = true, + Filters = new List { "order.created" }, + Headers = new Dictionary + { { "TestHeader", "TestHeaderValue" }, { "Another Testheader", "Another Value" } }, + Properties = new Dictionary() + }; + + public static CustomerForCreation Customer => new CustomerForCreation + { + Name = "John Doe", + Address = TestData.CustomerAddress, + Email = "john@doe.com", + DefaultMailAddress = new CustomerMetaData + { + Value = "john@doe.com", + TypeId = 1, + }, + Type = 0 + }; + + public static ShipmentWithLabel GetShipmentWithLabel(long orderId, string printerName, long productId, long providerId) => new ShipmentWithLabel + { + OrderId = orderId, + Dimension = new ShipmentDimensions + { + height = 10, + length = 10, + width = 10, + }, + ClientReference = "clientRef", + PrinterName = printerName, + ProductId = productId, + ProviderId = providerId, + ShipDate = DateTime.Now, + WeightInGram = 500, + ChangeStateToSend = true + }; + + public static CustomerAddress GetCustomerAddress(long? customerId) + { + var address = CustomerAddress; + address.CustomerId = customerId; + return address; + } +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/SearchEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/SearchEndPointIntegrationTest.cs new file mode 100644 index 0000000..9ffff39 --- /dev/null +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/SearchEndPointIntegrationTest.cs @@ -0,0 +1,14 @@ +using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; + +namespace Billbee.Api.Client.Test.EndPointIntegrationTests; + +[TestClass] +public class SearchEndPointIntegrationTest +{ + [TestMethod] + [RequiresApiAccess] + public void SearchTerm_IntegrationTest() + { + Assert.Inconclusive(); + } +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs new file mode 100644 index 0000000..1813655 --- /dev/null +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs @@ -0,0 +1,123 @@ +using Billbee.Api.Client.Model; +using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; + +namespace Billbee.Api.Client.Test.EndPointIntegrationTests; + +[TestClass] +public class WebhookEndPointIntegrationTest +{ + public TestContext TestContext { get; set; } + private long _webhookCountBeforeTest = -1; + private long _webhookCoundExpectedAfterTest = -1; + + [TestInitialize] + public void TestInitialize() + { + IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod); + + var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); + Assert.IsNotNull(result); + + _webhookCountBeforeTest = result.Count; + _webhookCoundExpectedAfterTest = result.Count; + } + + [TestCleanup] + public void TestCleanup() + { + var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); + Assert.IsNotNull(result); + + Assert.AreEqual(_webhookCoundExpectedAfterTest, result.Count); + } + + [TestMethod] + [RequiresApiAccess] + public void GetFilters_IntegrationTest() + { + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetFilters()); + } + + [TestMethod] + [RequiresApiAccess] + public void GetWebhooks_IntegrationTest() + { + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); + } + + [TestMethod] + [RequiresApiAccess] + public void GetWebhook_IntegrationTest() + { + var webhook = CrudHelpers.Create(() => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(TestData.WebHook)); + CrudHelpers.GetOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhook(id), webhook.Id); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.DeleteWebhook(id), webhook.Id); + } + + [TestMethod] + [RequiresApiAccess] + public void CreateWebhook_IntegrationTest() + { + Webhook webhook = CrudHelpers.Create(() => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(TestData.WebHook)); + Assert.AreEqual(TestData.WebHook.WebHookUri, webhook.WebHookUri); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.DeleteWebhook(id), webhook.Id); + } + + [TestMethod] + [RequiresApiAccess] + public void DeleteAllWebhooks_IntegrationTest() + { + if (_webhookCountBeforeTest > 0) + { + Assert.Inconclusive("The connected account contains webhooks. Cannot execute this test-method, because it would delete all existing webhooks."); + } + + CrudHelpers.Create(() => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(TestData.WebHook)); + CrudHelpers.Create(() => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(TestData.WebHook)); + var webhooks = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); + Assert.AreEqual(2, webhooks.Count); + + CrudHelpers.DeleteAll(() => IntegrationTestHelpers.ApiClient.Webhooks.DeleteAllWebhooks()); + + webhooks = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); + Assert.AreEqual(0, webhooks.Count); + + _webhookCoundExpectedAfterTest = 0; + } + + [TestMethod] + [RequiresApiAccess] + public void DeleteWebhook_IntegrationTest() + { + Webhook webhook = CrudHelpers.Create(() => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(TestData.WebHook)); + var webhooks = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); + Assert.IsTrue(webhooks.Count > 0); + + var webhookToDelete = webhook; + Assert.IsNotNull(webhookToDelete); + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.DeleteWebhook(id), webhookToDelete.Id); + + CrudHelpers.GetOneExpectException((id) => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhook(id), webhookToDelete.Id); + } + + [TestMethod] + [RequiresApiAccess] + public void UpdateWebhook_IntegrationTest() + { + Webhook webhook = CrudHelpers.Create(() => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(TestData.WebHook)); + webhook = CrudHelpers.GetOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhook(id), webhook.Id); + + webhook.Description = "modified"; + CrudHelpers.Put((webhook) => IntegrationTestHelpers.ApiClient.Webhooks.UpdateWebhook(webhook), webhook); + + webhook = CrudHelpers.GetOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhook(id), webhook.Id); + Assert.AreEqual("modified", webhook.Description); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.DeleteWebhook(id), webhook.Id); + } +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointTests/CustomerAddressesEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/CustomerAddressesEndPointTest.cs new file mode 100644 index 0000000..d4d7bb6 --- /dev/null +++ b/Billbee.Api.Client.Test/EndPointTests/CustomerAddressesEndPointTest.cs @@ -0,0 +1,82 @@ +using System.Collections.Specialized; +using System.Linq.Expressions; +using Billbee.Api.Client.EndPoint; +using Billbee.Api.Client.Model; + +namespace Billbee.Api.Client.Test.EndPointTests; + +[TestClass] +public class CustomerAddressesEndPointTest +{ + [TestMethod] + public void GetCustomerAddressesTest() + { + var testCustomerAddress = new CustomerAddress { Id = 4711 }; + var page = 1; + var pageSize = 5; + NameValueCollection parameters = new NameValueCollection + { + { "page", page.ToString() }, + { "pageSize", pageSize.ToString() } + }; + + Expression> expression = x => x.Get>>($"/customer-addresses", parameters); + object mockResult = TestHelpers.GetApiPagedResult(new List { testCustomerAddress }); + TestHelpers.RestClientMockTest(expression, mockResult, (restClient) => + { + var uut = new CustomerAddressesEndPoint(restClient); + var result = uut.GetCustomerAddresses(page, pageSize); + Assert.IsNotNull(result.Data); + }); + } + + [TestMethod] + public void GetCustomerAddressTest() + { + var testCustomerAddress = new CustomerAddress { Id = 4711 }; + + Expression> expression = x => x.Get>($"/customer-addresses/{testCustomerAddress.Id}", null); + object mockResult = TestHelpers.GetApiResult(testCustomerAddress); + TestHelpers.RestClientMockTest(expression, mockResult, (restClient) => + { + var uut = new CustomerAddressesEndPoint(restClient); + var result = uut.GetCustomerAddress(testCustomerAddress.Id.Value); + Assert.IsNotNull(result.Data); + }); + } + + [TestMethod] + public void AddCustomerAddressTest() + { + var testCustomerAddress = new CustomerAddress { Id = 4711 }; + + Expression> expression = x => x.Post>($"/customer-addresses", testCustomerAddress, null); + object mockResult = TestHelpers.GetApiResult(testCustomerAddress); + TestHelpers.RestClientMockTest(expression, mockResult, (restClient) => + { + var uut = new CustomerAddressesEndPoint(restClient); + var result = uut.AddCustomerAddress(testCustomerAddress); + Assert.IsNotNull(result.Data); + }); + } + + [TestMethod] + public void UpdateCustomerAddressTest() + { + var testCustomerAddress = new CustomerAddress { Id = 4711 }; + + Expression> expression = x => x.Put>($"/customer-addresses/{testCustomerAddress.Id}", testCustomerAddress, null); + object mockResult = TestHelpers.GetApiResult(testCustomerAddress); + TestHelpers.RestClientMockTest(expression, mockResult, (restClient) => + { + var uut = new CustomerAddressesEndPoint(restClient); + + testCustomerAddress.Id = null; + Assert.ThrowsException(() => uut.UpdateCustomerAddress(testCustomerAddress)); + + testCustomerAddress.Id = 4711; + var result = uut.UpdateCustomerAddress(testCustomerAddress); + Assert.IsNotNull(result.Data); + }); + } +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointTests/CustomerEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/CustomerEndPointTest.cs index 8ef1ba3..5d92009 100644 --- a/Billbee.Api.Client.Test/EndPointTests/CustomerEndPointTest.cs +++ b/Billbee.Api.Client.Test/EndPointTests/CustomerEndPointTest.cs @@ -129,4 +129,69 @@ public void GetAddressesForCustomerTest() Assert.AreEqual(1, result.Data.Count); }); } + + [TestMethod] + public void AddAddressToCustomerTest() + { + var testCustomer = new Customer { Id = 4711 }; + var testCustomerAddress = new CustomerAddress { Id = 4712, CustomerId = testCustomer.Id }; + Expression> expression = x => x.Post>($"/customers/{testCustomer.Id}/addresses", testCustomerAddress, null); + object mockResult = TestHelpers.GetApiResult(testCustomerAddress); + TestHelpers.RestClientMockTest(expression, mockResult, (restClient) => + { + var uut = new CustomerEndPoint(restClient); + var result = uut.AddAddressToCustomer(testCustomerAddress); + Assert.IsNotNull(result.Data); + }); + } + + [TestMethod] + public void GetCustomerAddressTest() + { + var testCustomerAddress = new CustomerAddress { Id = 4711 }; + + Expression> expression = x => x.Get>($"/customers/addresses/{testCustomerAddress.Id}", null); + object mockResult = TestHelpers.GetApiResult(testCustomerAddress); + TestHelpers.RestClientMockTest(expression, mockResult, (restClient) => + { + var uut = new CustomerEndPoint(restClient); + var result = uut.GetCustomerAddress(testCustomerAddress.Id.Value); + Assert.IsNotNull(result.Data); + }); + } + + [TestMethod] + public void UpdateCustomerAddressTest() + { + var testCustomerAddress = new CustomerAddress { Id = 4711 }; + + Expression> expression = x => x.Put>($"/customers/addresses/{testCustomerAddress.Id}", testCustomerAddress, null); + object mockResult = TestHelpers.GetApiResult(testCustomerAddress); + TestHelpers.RestClientMockTest(expression, mockResult, (restClient) => + { + var uut = new CustomerEndPoint(restClient); + var result = uut.UpdateCustomerAddress(testCustomerAddress); + Assert.IsNotNull(result.Data); + }); + } + + + [TestMethod] + public void PatchCustomerAddressTest() + { + var testCustomerAddress = new CustomerAddress { Id = 4711 }; + + var fieldsToPatch = new Dictionary + { + { "FirstName", "Foo" } + }; + Expression> expression = x => x.Patch>($"/customers/addresses/{testCustomerAddress.Id}", null, fieldsToPatch); + object mockResult = TestHelpers.GetApiResult(testCustomerAddress); + TestHelpers.RestClientMockTest(expression, mockResult, (restClient) => + { + var uut = new CustomerEndPoint(restClient); + var result = uut.PatchCustomerAddress(testCustomerAddress.Id.Value, fieldsToPatch); + Assert.IsNotNull(result.Data); + }); + } } \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointTests/EnumEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/EnumEndPointTest.cs new file mode 100644 index 0000000..6b20d45 --- /dev/null +++ b/Billbee.Api.Client.Test/EndPointTests/EnumEndPointTest.cs @@ -0,0 +1,55 @@ +using System.Linq.Expressions; +using Billbee.Api.Client.EndPoint; +using Billbee.Api.Client.Endpoint.Interfaces; +using Billbee.Api.Client.Enums; +using Billbee.Api.Client.Model; + +namespace Billbee.Api.Client.Test.EndPointTests; + +[TestClass] +public class EnumEndPointTest +{ + [TestMethod] + public void GetPaymentTypesTest() + { + ExecuteEnumTest("paymenttypes", x => x.GetPaymentTypes()); + } + + [TestMethod] + public void GetShippingCarriersTest() + { + ExecuteEnumTest("shippingcarriers", x => x.GetShippingCarriers()); + } + + [TestMethod] + public void GetShipmentTypesTest() + { + ExecuteEnumTest("shipmenttypes", x => x.GetShipmentTypes()); + } + + [TestMethod] + public void GetOrderStatesTest() + { + ExecuteEnumTest("orderstates", x => x.GetOrderStates()); + } + + private void ExecuteEnumTest(string endpoint, Func> endpointFunc) + { + var testEnumEntryList = new List + { + new() { Id = 1, Name = "entry1" }, + new() { Id = 2, Name = "entry2" }, + }; + + Expression> expression = x => + x.Get>($"/enums/{endpoint}", null); + object mockResult = testEnumEntryList; + TestHelpers.RestClientMockTest(expression, mockResult, (restClient) => + { + var uut = new EnumEndPoint(restClient); + var result = endpointFunc(uut); + Assert.IsNotNull(result); + Assert.AreEqual(2, result.Count); + }); + } +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointTests/OrderEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/OrderEndPointTest.cs index f4c868e..e15228e 100644 --- a/Billbee.Api.Client.Test/EndPointTests/OrderEndPointTest.cs +++ b/Billbee.Api.Client.Test/EndPointTests/OrderEndPointTest.cs @@ -349,4 +349,41 @@ public void CreateEventAtOrderTest() restClientMock.Verify(x => x.Post($"/orders/{orderId}/trigger-event", It.IsAny())); } + + [TestMethod] + public void GetLayoutsTest() + { + var testLayoutList = new List + { + new() { Id = 1, Name = "layout1", Type = ReportTemplates.Invoice }, + new() { Id = 2, Name = "layout2", Type = ReportTemplates.Label }, + }; + + Expression> expression = x => x.Get>>($"/layouts", null); + object mockResult = TestHelpers.GetApiResult(testLayoutList); + TestHelpers.RestClientMockTest(expression, mockResult, (restClient) => + { + var uut = new OrderEndPoint(restClient); + var result = uut.GetLayouts(); + Assert.IsNotNull(result.Data); + Assert.AreEqual(2, result.Data.Count); + }); + } + + [TestMethod] + public void ParsePlaceholdersTest() + { + var restClientMock = new Mock(); + var uut = new OrderEndPoint(restClientMock.Object); + + var orderId = 4711; + var parsePlaceholdersQuery = new ParsePlaceholdersQuery + { + TextToParse = "This is my text for Order {{id}}" + }; + + uut.ParsePlaceholders(orderId, parsePlaceholdersQuery); + + restClientMock.Verify(x => x.Post($"/orders/{orderId}/parse-placeholders", It.IsAny(), null)); + } } \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointTests/ProductEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/ProductEndPointTest.cs index fd2837f..2f98f2d 100644 --- a/Billbee.Api.Client.Test/EndPointTests/ProductEndPointTest.cs +++ b/Billbee.Api.Client.Test/EndPointTests/ProductEndPointTest.cs @@ -190,8 +190,6 @@ public void GetCustomFieldTest() [TestMethod] public void GetPatchableProductFieldsTest() { - long id = 4711; - Expression> expression = x => x.Get>>($"/products/PatchableFields", null); var mockResult = TestHelpers.GetApiResult(new List { "foo", "bar" }); TestHelpers.RestClientMockTest(expression, mockResult, (restClient) => @@ -226,7 +224,6 @@ public void GetArticleImagesTest() { var testArticleImage = new ArticleImage(); long id = 4711; - var fieldsToPatch = new Dictionary { { "foo", "val" }, { "bar", "val2" } }; Expression> expression = x => x.Get>>($"/products/{id}/images", null); var mockResult = TestHelpers.GetApiResult(new List { testArticleImage }); @@ -365,4 +362,50 @@ public void DeleteMultipleArticleImagesTest() }); } + [TestMethod] + public void AddProductTest() + { + var testProduct = new Product(); + + Expression> expression = x => x.Post>($"/products", testProduct, null); + var mockResult = TestHelpers.GetApiResult(testProduct); + TestHelpers.RestClientMockTest(expression, mockResult, (restClient) => + { + var uut = new ProductEndPoint(restClient); + var result = uut.AddProduct(testProduct); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Data); + }); + } + + [TestMethod] + public void DeleteProductTest() + { + long productId = 4712; + + var restClientMock = new Mock(); + var uut = new ProductEndPoint(restClientMock.Object); + uut.DeleteProduct(productId); + restClientMock.Verify(x => x.Delete($"/products/{productId}", null, ParameterType.QueryString)); + } + + [TestMethod] + public void GetCategoriesTest() + { + var testCategoryList = new List + { + new() { Name = "cat1", Id = 1 }, + new() { Name = "cat2", Id = 2 } + }; + Expression> expression = x => x.Get>>($"/products/category", null); + var mockResult = TestHelpers.GetApiResult(testCategoryList); + TestHelpers.RestClientMockTest(expression, mockResult, (restClient) => + { + var uut = new ProductEndPoint(restClient); + var result = uut.GetCategories(); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Data); + Assert.AreEqual(2, result.Data.Count); + }); + } } \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointTests/ShipmentEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/ShipmentEndPointTest.cs index 7f78da6..02a6899 100644 --- a/Billbee.Api.Client.Test/EndPointTests/ShipmentEndPointTest.cs +++ b/Billbee.Api.Client.Test/EndPointTests/ShipmentEndPointTest.cs @@ -25,6 +25,21 @@ public void GetShippingProviderTest() Assert.AreEqual(1, result.Count); }); } + + [TestMethod] + public void GetShipmentsTest() + { + var testShipment = new Shipment(); + + Expression> expression = x => x.Get>>($"/shipment/shipments", It.IsAny()); + object mockResult = TestHelpers.GetApiPagedResult(new List { testShipment }); + TestHelpers.RestClientMockTest(expression, mockResult, (restClient) => + { + var uut = new ShipmentEndPoint(restClient); + var result = uut.GetShipments(1, 20); + Assert.AreEqual(1, result.Data.Count); + }); + } [TestMethod] public void PostShipmentTest() @@ -48,7 +63,7 @@ public void ShipOrderWithLabelTest() var testShipmentWithLabel = new ShipmentWithLabel(); var testShipmentWithLabelResult = new ShipmentWithLabelResult(); - Expression> expression = x => x.Post>($"/shipment/shipment", testShipmentWithLabel, null); + Expression> expression = x => x.Post>($"/shipment/shipwithlabel", testShipmentWithLabel, null); object mockResult = TestHelpers.GetApiResult(testShipmentWithLabelResult); TestHelpers.RestClientMockTest(expression, mockResult, (restClient) => { diff --git a/Billbee.Api.Client.Test/EndPointTests/WebhookEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/WebhookEndPointTest.cs index c802634..f8de192 100644 --- a/Billbee.Api.Client.Test/EndPointTests/WebhookEndPointTest.cs +++ b/Billbee.Api.Client.Test/EndPointTests/WebhookEndPointTest.cs @@ -135,6 +135,6 @@ public void CreateWebhookTest() testWebHook.Secret = "0123456789012345678901234567890123456789"; uut.CreateWebhook(testWebHook); - restClientMock.Verify(x => x.Post("/webhooks", testWebHook)); + restClientMock.Verify(x => x.Post("/webhooks", testWebHook, null)); } } \ No newline at end of file diff --git a/Billbee.Api.Client.Test/IntegrationTests/IntegrationTestSettings.cs b/Billbee.Api.Client.Test/IntegrationTests/IntegrationTestSettings.cs deleted file mode 100644 index b90a0de..0000000 --- a/Billbee.Api.Client.Test/IntegrationTests/IntegrationTestSettings.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Billbee.Api.Client.Test.IntegrationTests; - -public static class IntegrationTestSettings -{ - public static bool RunIntegrationTests = false; -} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/TestHelpers.cs b/Billbee.Api.Client.Test/TestHelpers.cs index 741812c..1528a16 100644 --- a/Billbee.Api.Client.Test/TestHelpers.cs +++ b/Billbee.Api.Client.Test/TestHelpers.cs @@ -1,4 +1,5 @@ using System.Linq.Expressions; +using System.Reflection; using Billbee.Api.Client.Model; using Moq; diff --git a/Billbee.Api.Client.Test/Usings.cs b/Billbee.Api.Client.Test/Usings.cs new file mode 100644 index 0000000..ab67c7e --- /dev/null +++ b/Billbee.Api.Client.Test/Usings.cs @@ -0,0 +1 @@ +global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file diff --git a/Billbee.Api.Client.Test/config.test.json b/Billbee.Api.Client.Test/config.test.json new file mode 100644 index 0000000..80cd23e --- /dev/null +++ b/Billbee.Api.Client.Test/config.test.json @@ -0,0 +1,7 @@ +{ + "Username": "myUserFromFile", + "Password": "myPwdFromFile", + "ApiKey": "myApiKeyFromFile", + "BaseUrl": "myBaseUrlFromFile", + "errorHandlingBehaviour": 1 +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/readme.txt b/Billbee.Api.Client.Test/readme.txt new file mode 100644 index 0000000..140b572 --- /dev/null +++ b/Billbee.Api.Client.Test/readme.txt @@ -0,0 +1,6 @@ +The folder EndPointTests contains UnitTests for each endpoint, where the api is mocked. +Thus, these UnitTests do not access the Billbee Api. + +The folder EndPointIntegrationTests contains UnitTests for each endpoint, which DO require access to the Billbee Api. +It's required to provide a file named 'config.prod.json' on the project-level of this UnitTest project. +To protect your Billbee data, these UnitTests will not be executed by default. diff --git a/Billbee.Api.Client/ApiClient.cs b/Billbee.Api.Client/ApiClient.cs index 94d374e..c4339f0 100644 --- a/Billbee.Api.Client/ApiClient.cs +++ b/Billbee.Api.Client/ApiClient.cs @@ -10,26 +10,24 @@ namespace Billbee.Api.Client /// public class ApiClient : IApiClient { - private ILogger _logger; - private BillbeeRestClient _restClient; + private IBillbeeRestClient _restClient; - public ApiClient(ApiConfiguration configuration = null, ILogger logger = null) + public ApiClient(ApiConfiguration configuration = null, ILogger logger = null, bool allowReadWrite = true) { var config = configuration ?? new ApiConfiguration(); - _init(config, logger); + _init(config, logger, allowReadWrite); } - public ApiClient(string configurationPath, ILogger logger = null) + public ApiClient(string configurationPath, ILogger logger = null, bool allowReadWrite = true) { var config = LoadConfigFromFile(configurationPath); - _init(config, logger); + _init(config, logger, allowReadWrite); } - private void _init(ApiConfiguration configuration, ILogger logger) + private void _init(ApiConfiguration configuration, ILogger logger, bool allowReadWrite = true) { - _logger = logger; Configuration = configuration; - _restClient = new BillbeeRestClient(_logger, Configuration); + _restClient = new BillbeeRestClient(logger, Configuration, allowReadWrite); } public ApiConfiguration Configuration { get; private set; } @@ -46,11 +44,15 @@ private void _init(ApiConfiguration configuration, ILogger logger) public ICustomerEndPoint Customer => new CustomerEndPoint(_restClient); + public ICustomerAddressesEndPoint CustomerAddresses => new CustomerAddressesEndPoint(_restClient); + public ISearchEndPoint Search => new SearchEndPoint(_restClient); public IOrderEndPoint Orders => new OrderEndPoint(_restClient); public ICloudStoragesEndPoint CloudStorages => new CloudStoragesEndPoint(_restClient); + + public IEnumEndPoint Enums => new EnumEndPoint(_restClient); public bool TestConfiguration() { diff --git a/Billbee.Api.Client/ApiMappingAttribute.cs b/Billbee.Api.Client/ApiMappingAttribute.cs new file mode 100644 index 0000000..f4cdc51 --- /dev/null +++ b/Billbee.Api.Client/ApiMappingAttribute.cs @@ -0,0 +1,30 @@ +using System; +using System.Net.Http; + +namespace Billbee.Api.Client +{ + public enum HttpOperation + { + Get = 0, + Post, + Put, + Patch, + Delete, + Head, + Options, + Trace + } + + [AttributeUsage(AttributeTargets.Method)] + public class ApiMappingAttribute : Attribute + { + public ApiMappingAttribute(string apiPath, HttpOperation httpOperation) + { + ApiPath = apiPath; + HttpOperation = httpOperation; + } + + public string ApiPath { get; set; } + public HttpOperation HttpOperation { get; set; } + } +} \ No newline at end of file diff --git a/Billbee.Api.Client/BillbeeRestClient.cs b/Billbee.Api.Client/BillbeeRestClient.cs index 9b58cb2..a5b96b6 100644 --- a/Billbee.Api.Client/BillbeeRestClient.cs +++ b/Billbee.Api.Client/BillbeeRestClient.cs @@ -16,14 +16,18 @@ namespace Billbee.Api.Client internal class BillbeeRestClient : IBillbeeRestClient { private readonly ApiConfiguration _config; + private readonly bool _allowRead; + private readonly bool _allowWrite; private readonly ILogger _logger; private readonly DataFormat _requestFormat; private readonly Dictionary _additionalHeaders; - public BillbeeRestClient(ILogger logger, ApiConfiguration config) + public BillbeeRestClient(ILogger logger, ApiConfiguration config, bool allowRead = true, bool allowWrite = true) { _logger = logger; _config = config; + _allowRead = allowRead; + _allowWrite = allowRead && allowWrite; _requestFormat = DataFormat.Json; _additionalHeaders = null; } @@ -32,6 +36,8 @@ public BillbeeRestClient(ILogger logger, ApiConfiguration config) public HttpStatusCode Get(string resource) { + _checkReadAccess(); + var c = _createRestClient(); var req = _createRestRequest(resource, null); return c.Get(req).StatusCode; @@ -41,6 +47,8 @@ public T Get( string resource, NameValueCollection parameter = null) where T : new() { + _checkReadAccess(); + return _requestResourceInternal(resource, parameter); } @@ -53,6 +61,11 @@ private T _requestResourceInternal( int sleepTimeMs = 1000, Action> preDeserializeHook = null, NameValueCollection headerParameter = null) where T : new() { + if (!_allowRead) + { + return default(T); + } + var c = _createRestClient(); var req = _createRestRequest(resource, parameter); @@ -81,6 +94,8 @@ private T _requestResourceInternal( public string Put(string resource, NameValueCollection parameter = null) { + _checkWriteAccess(); + var c = _createRestClient(); var req = _createRestRequest(resource, parameter); var response = c.Put(req); @@ -91,6 +106,8 @@ public string Put(string resource, NameValueCollection parameter = null) public string Put(string resource, dynamic data, NameValueCollection parameter = null) { + _checkWriteAccess(); + var c = _createRestClient(); var req = _createRestRequest(resource, parameter); if (data != null) @@ -103,6 +120,8 @@ public string Put(string resource, dynamic data, NameValueCollection parameter = public T Put(string resource, NameValueCollection parameter = null) where T : new() { + _checkWriteAccess(); + var c = _createRestClient(); var req = _createRestRequest(resource, parameter); var response = c.Put(req); @@ -113,6 +132,8 @@ public string Put(string resource, dynamic data, NameValueCollection parameter = public T Put(string resource, dynamic data, NameValueCollection parameter = null) where T : new() { + _checkWriteAccess(); + var c = _createRestClient(); var req = _createRestRequest(resource, parameter); if (data != null) @@ -124,6 +145,8 @@ public string Put(string resource, dynamic data, NameValueCollection parameter = } public async Task PutAsync(string resource, NameValueCollection parameter = null) { + _checkWriteAccess(); + var c = _createRestClient(); var req = _createRestRequest(resource, parameter); req.Method = Method.PUT; @@ -134,6 +157,8 @@ public async Task PutAsync(string resource, NameValueCollection paramete public async Task PutAsync(string resource, dynamic data) { + _checkWriteAccess(); + var c = _createRestClient(); var req = _createRestRequest(resource, null); req.Method = Method.PUT; @@ -145,6 +170,8 @@ public async Task PutAsync(string resource, dynamic data) public async Task PutAsync(string resource, dynamic data) where T : new() { + _checkWriteAccess(); + var c = _createRestClient(); var req = _createRestRequest(resource, null); req.Method = Method.PUT; @@ -160,6 +187,8 @@ public async Task PutAsync(string resource, dynamic data) public string Patch(string resource, NameValueCollection parameter = null, dynamic data = null) { + _checkWriteAccess(); + var c = _createRestClient(); var req = _createRestRequest(resource, parameter); if (data != null) @@ -175,6 +204,8 @@ public string Patch(string resource, NameValueCollection parameter = null, dynam public T Patch(string resource, NameValueCollection parameter = null, dynamic data = null) where T : new() { + _checkWriteAccess(); + var c = _createRestClient(); var req = _createRestRequest(resource, parameter); @@ -192,16 +223,17 @@ public string Patch(string resource, NameValueCollection parameter = null, dynam #endregion #region post - - public async Task PostAsync( + + private string Post( string resource, NameValueCollection parameter = null, List files = null, - ParameterType paramType = ParameterType.QueryString, - string acceptHeaderValue = "application/json") + ParameterType paramType = ParameterType.QueryString) { + _checkWriteAccess(); + var c = _createRestClient(); - var req = _createRestRequest(resource, parameter, paramType, acceptHeaderValue); + var req = _createRestRequest(resource, parameter, paramType); if (files != null) { @@ -211,18 +243,61 @@ public async Task PostAsync( } } - var response = await c.ExecutePostAsync(req).ConfigureAwait(false); + var response = c.Post(req); _throwWhenErrResponse(response, resource); return response.Content; } - private string Post( + + public T Post( string resource, NameValueCollection parameter = null, List files = null, ParameterType paramType = ParameterType.QueryString) { + _checkWriteAccess(); + + var resStr = Post(resource, parameter, files, paramType); + return JsonConvert.DeserializeObject(resStr); + } + + public string Post(string resource, dynamic data) + { + _checkWriteAccess(); + var c = _createRestClient(); - var req = _createRestRequest(resource, parameter, paramType); + var req = _createRestRequest(resource, null); + req.AddBody(data); + var response = c.Post(req); + _throwWhenErrResponse(response, resource); + return response.Content; + } + + public T Post(string resource, dynamic data, NameValueCollection parameters = null) where T : new() + { + _checkWriteAccess(); + + var c = _createRestClient(); + var req = parameters != null + ? _createRestRequest(resource, parameters) + : _createRestRequest(resource, null); + req.AddBody(data); + var response = c.Post(req); + _throwWhenErrResponse(response, resource); + + return JsonConvert.DeserializeObject(response.Content); + } + + public async Task PostAsync( + string resource, + NameValueCollection parameter = null, + List files = null, + ParameterType paramType = ParameterType.QueryString, + string acceptHeaderValue = "application/json") + { + _checkWriteAccess(); + + var c = _createRestClient(); + var req = _createRestRequest(resource, parameter, paramType, acceptHeaderValue); if (files != null) { @@ -232,23 +307,15 @@ private string Post( } } - var response = c.Post(req); + var response = await c.ExecutePostAsync(req).ConfigureAwait(false); _throwWhenErrResponse(response, resource); return response.Content; } - - public T Post( - string resource, - NameValueCollection parameter = null, - List files = null, - ParameterType paramType = ParameterType.QueryString) - { - var resStr = Post(resource, parameter, files, paramType); - return JsonConvert.DeserializeObject(resStr); - } - + public async Task PostAsync(string resource, dynamic data) { + _checkWriteAccess(); + var c = _createRestClient(); var req = _createRestRequest(resource, null); req.AddBody(data); @@ -263,6 +330,8 @@ public async Task PostAsync( NameValueCollection parameter = null, ParameterType paramType = ParameterType.QueryString) where T : new() { + _checkWriteAccess(); + var c = _createRestClient(); var req = _createRestRequest(resource, parameter); if (data != null) @@ -272,29 +341,6 @@ public async Task PostAsync( return response.Data; } - public string Post(string resource, dynamic data) - { - var c = _createRestClient(); - var req = _createRestRequest(resource, null); - req.AddBody(data); - var response = c.Post(req); - _throwWhenErrResponse(response, resource); - return response.Content; - } - - public T Post(string resource, dynamic data, NameValueCollection parameters = null) where T : new() - { - var c = _createRestClient(); - var req = parameters != null - ? _createRestRequest(resource, parameters) - : _createRestRequest(resource, null); - req.AddBody(data); - var response = c.Post(req); - _throwWhenErrResponse(response, resource); - - return JsonConvert.DeserializeObject(response.Content); - } - #endregion #region delete @@ -304,6 +350,8 @@ public void Delete( NameValueCollection parameter = null, ParameterType paramType = ParameterType.QueryString) { + _checkWriteAccess(); + var c = _createRestClient(); var req = _createRestRequest(resource, parameter, paramType); var response = c.Delete(req); @@ -313,8 +361,26 @@ public void Delete( #endregion #region private methods + + private void _checkReadAccess() + { + if (!_allowRead) + { + throw new UnauthorizedAccessException( + "RestClient was configured without required read permission"); + } + } + + private void _checkWriteAccess() + { + if (!_allowWrite) + { + throw new UnauthorizedAccessException( + "RestClient was configured without required write permission"); + } + } - /// + /// /// Retries a network request up to 4 times when throttled /// /// @@ -397,6 +463,7 @@ private string _parseError(IRestResponse response) } catch { + // left intentionally blank } errMsg = errMsg ?? ($"Anfrage fehlgeschlagen: {response.StatusCode} {response.StatusDescription}"); diff --git a/Billbee.Api.Client/Endpoint/AutomaticProvisionEndPoint.cs b/Billbee.Api.Client/Endpoint/AutomaticProvisionEndPoint.cs index 5924570..0accd0f 100644 --- a/Billbee.Api.Client/Endpoint/AutomaticProvisionEndPoint.cs +++ b/Billbee.Api.Client/Endpoint/AutomaticProvisionEndPoint.cs @@ -1,4 +1,5 @@ -using Billbee.Api.Client.Endpoint.Interfaces; +using System.Net.Http; +using Billbee.Api.Client.Endpoint.Interfaces; using Billbee.Api.Client.Model; namespace Billbee.Api.Client.EndPoint @@ -13,11 +14,13 @@ internal AutomaticProvisionEndPoint(IBillbeeRestClient restClient) _restClient = restClient; } + [ApiMapping("/api/v1/automaticprovision/createaccount", HttpOperation.Post)] public ApiResult CreateAccount(Account createAccountContainer) { return _restClient.Post>("/automaticprovision/createaccount", createAccountContainer); } + [ApiMapping("/api/v1/automaticprovision/termsinfo", HttpOperation.Get)] public ApiResult TermsInfo() { return _restClient.Get>("/automaticprovision/termsinfo"); diff --git a/Billbee.Api.Client/Endpoint/CloudStoragesEndPoint.cs b/Billbee.Api.Client/Endpoint/CloudStoragesEndPoint.cs index 90b7cd4..6970ce4 100644 --- a/Billbee.Api.Client/Endpoint/CloudStoragesEndPoint.cs +++ b/Billbee.Api.Client/Endpoint/CloudStoragesEndPoint.cs @@ -18,6 +18,7 @@ internal CloudStoragesEndPoint(IBillbeeRestClient restClient) _restClient = restClient; } + [ApiMapping("/api/v1/cloudstorages", HttpOperation.Get)] public ApiResult> GetCloudStorageList() { return _restClient.Get>>($"/cloudstorages"); diff --git a/Billbee.Api.Client/Endpoint/CustomerAddressesEndPoint.cs b/Billbee.Api.Client/Endpoint/CustomerAddressesEndPoint.cs new file mode 100644 index 0000000..0535dad --- /dev/null +++ b/Billbee.Api.Client/Endpoint/CustomerAddressesEndPoint.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using Billbee.Api.Client.Endpoint.Interfaces; +using Billbee.Api.Client.Model; + +namespace Billbee.Api.Client.EndPoint +{ + /// + public class CustomerAddressesEndPoint : ICustomerAddressesEndPoint + { + private readonly IBillbeeRestClient _restClient; + + internal CustomerAddressesEndPoint(IBillbeeRestClient restClient) + { + _restClient = restClient; + } + + [ApiMapping("/api/v1/customer-addresses", HttpOperation.Get)] + public ApiPagedResult> GetCustomerAddresses(int page, int pageSize) + { + var parameters = new NameValueCollection + { + { "page", page.ToString() }, + { "pageSize", pageSize.ToString() } + }; + + return _restClient.Get>>("/customer-addresses", parameters); + } + + [ApiMapping("/api/v1/customer-addresses/{id}", HttpOperation.Get)] + public ApiResult GetCustomerAddress(long customerAddressId) + { + return _restClient.Get>($"/customer-addresses/{customerAddressId}"); + } + + [ApiMapping("/api/v1/customer-addresses", HttpOperation.Post)] + public ApiResult AddCustomerAddress(CustomerAddress customerAddress) + { + return _restClient.Post>("/customer-addresses", customerAddress); + } + + [ApiMapping("/api/v1/customer-addresses/{id}", HttpOperation.Put)] + public ApiResult UpdateCustomerAddress(CustomerAddress customerAddress) + { + if(customerAddress.Id == null || customerAddress.Id <= 0) + { + throw new InvalidValueException("Id must not be null."); + } + + return _restClient.Put>($"/customer-addresses/{customerAddress.Id.Value}", customerAddress); + } + } +} \ No newline at end of file diff --git a/Billbee.Api.Client/Endpoint/CustomerEndPoint.cs b/Billbee.Api.Client/Endpoint/CustomerEndPoint.cs index a40486b..e566871 100644 --- a/Billbee.Api.Client/Endpoint/CustomerEndPoint.cs +++ b/Billbee.Api.Client/Endpoint/CustomerEndPoint.cs @@ -19,6 +19,7 @@ internal CustomerEndPoint(IBillbeeRestClient restClient) _restClient = restClient; } + [ApiMapping("/api/v1/customers", HttpOperation.Get)] public ApiPagedResult> GetCustomerList(int page, int pageSize) { NameValueCollection parameters = new NameValueCollection(); @@ -28,16 +29,19 @@ public ApiPagedResult> GetCustomerList(int page, int pageSize) return _restClient.Get>>($"/customers", parameters); } + [ApiMapping("/api/v1/customers", HttpOperation.Post)] public ApiResult AddCustomer(CustomerForCreation customer) { return _restClient.Post>($"/customers", customer); } + [ApiMapping("/api/v1/customers/{id}", HttpOperation.Get)] public ApiResult GetCustomer(long id) { return _restClient.Get>($"/customers/{id}"); } + [ApiMapping("/api/v1/customers/{id}", HttpOperation.Put)] public ApiResult UpdateCustomer(Customer customer) { if (customer.Id == null) @@ -48,6 +52,7 @@ public ApiResult UpdateCustomer(Customer customer) } + [ApiMapping("/api/v1/customers/{id}/orders", HttpOperation.Get)] public ApiPagedResult> GetOrdersForCustomer(long id, int page, int pageSize) { NameValueCollection parameters = new NameValueCollection(); @@ -56,6 +61,7 @@ public ApiPagedResult> GetOrdersForCustomer(long id, int page, int p return _restClient.Get>>($"/customers/{id}/orders", parameters); } + [ApiMapping("/api/v1/customers/{id}/addresses", HttpOperation.Get)] public ApiPagedResult> GetAddressesForCustomer(long id, int page, int pageSize) { NameValueCollection parameters = new NameValueCollection(); @@ -63,5 +69,29 @@ public ApiPagedResult> GetAddressesForCustomer(long id, in parameters.Add("pageSize", pageSize.ToString()); return _restClient.Get>>($"/customers/{id}/addresses", parameters); } + + [ApiMapping("/api/v1/customers/{id}/addresses", HttpOperation.Post)] + public ApiResult AddAddressToCustomer(CustomerAddress customerAddress) + { + return _restClient.Post>($"/customers/{customerAddress.CustomerId}/addresses", customerAddress); + } + + [ApiMapping("/api/v1/customers/addresses/{id}", HttpOperation.Get)] + public ApiResult GetCustomerAddress(long customerAddressId) + { + return _restClient.Get>($"/customers/addresses/{customerAddressId}"); + } + + [ApiMapping("/api/v1/customers/addresses/{id}", HttpOperation.Put)] + public ApiResult UpdateCustomerAddress(CustomerAddress customerAddress) + { + return _restClient.Put>($"/customers/addresses/{customerAddress.Id}", customerAddress); + } + + [ApiMapping("/api/v1/customers/addresses/{id}", HttpOperation.Patch)] + public ApiResult PatchCustomerAddress(long customerAddressId, Dictionary fieldsToPatch) + { + return _restClient.Patch>($"/customers/addresses/{customerAddressId}", null, fieldsToPatch); + } } } diff --git a/Billbee.Api.Client/Endpoint/EnumEndPoint.cs b/Billbee.Api.Client/Endpoint/EnumEndPoint.cs new file mode 100644 index 0000000..636131d --- /dev/null +++ b/Billbee.Api.Client/Endpoint/EnumEndPoint.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using Billbee.Api.Client.Endpoint.Interfaces; +using Billbee.Api.Client.Model; + +namespace Billbee.Api.Client.EndPoint +{ + public class EnumEndPoint : IEnumEndPoint + { + private readonly IBillbeeRestClient _restClient; + + internal EnumEndPoint(IBillbeeRestClient restClient) + { + _restClient = restClient; + } + + [ApiMapping("/api/v1/enums/paymenttypes", HttpOperation.Get)] + public List GetPaymentTypes() + { + return _restClient.Get>("/enums/paymenttypes"); + } + + [ApiMapping("/api/v1/enums/shippingcarriers", HttpOperation.Get)] + public List GetShippingCarriers() + { + return _restClient.Get>("/enums/shippingcarriers"); + } + + [ApiMapping("/api/v1/enums/shipmenttypes", HttpOperation.Get)] + public List GetShipmentTypes() + { + return _restClient.Get>("/enums/shipmenttypes"); + } + + [ApiMapping("/api/v1/enums/orderstates", HttpOperation.Get)] + public List GetOrderStates() + { + return _restClient.Get>("/enums/orderstates"); + } + } +} \ No newline at end of file diff --git a/Billbee.Api.Client/Endpoint/EventEndPoint.cs b/Billbee.Api.Client/Endpoint/EventEndPoint.cs index cc7906b..040bf1e 100644 --- a/Billbee.Api.Client/Endpoint/EventEndPoint.cs +++ b/Billbee.Api.Client/Endpoint/EventEndPoint.cs @@ -17,6 +17,7 @@ internal EventEndPoint(IBillbeeRestClient restClient) _restClient = restClient; } + [ApiMapping("/api/v1/events", HttpOperation.Get)] public ApiPagedResult> GetEvents( DateTime? minDate = null, DateTime? maxDate = null, diff --git a/Billbee.Api.Client/Endpoint/Interfaces/ICustomerAddressesEndPoint.cs b/Billbee.Api.Client/Endpoint/Interfaces/ICustomerAddressesEndPoint.cs new file mode 100644 index 0000000..7b04bf9 --- /dev/null +++ b/Billbee.Api.Client/Endpoint/Interfaces/ICustomerAddressesEndPoint.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using Billbee.Api.Client.Model; + +namespace Billbee.Api.Client.Endpoint.Interfaces +{ + /// + /// Endpoint to access customer addresses + /// + public interface ICustomerAddressesEndPoint + { + /// + /// Queries a list of customers addresses + /// + /// page number + /// page size + /// List of customers on the given page. + ApiPagedResult> GetCustomerAddresses(int page, int pageSize); + + /// + /// Gets a single customer address by its id + /// customer address id + /// + ApiResult GetCustomerAddress(long customerAddressId); + + /// + /// Creates a new customer address + /// customer address model + /// + ApiResult AddCustomerAddress(CustomerAddress customerAddress); + + /// + /// Updates a new customer address + /// + /// customer address model + ApiResult UpdateCustomerAddress(CustomerAddress customerAddress); + } +} \ No newline at end of file diff --git a/Billbee.Api.Client/Endpoint/Interfaces/ICustomerEndPoint.cs b/Billbee.Api.Client/Endpoint/Interfaces/ICustomerEndPoint.cs index 70b7c58..bb5cb7a 100644 --- a/Billbee.Api.Client/Endpoint/Interfaces/ICustomerEndPoint.cs +++ b/Billbee.Api.Client/Endpoint/Interfaces/ICustomerEndPoint.cs @@ -54,5 +54,34 @@ public interface ICustomerEndPoint /// Count of entries per page /// Resultset of the queried page of addresses. ApiPagedResult> GetAddressesForCustomer(long id, int page, int pageSize); + + /// + /// Create new address for a specific customer + /// + /// The new customerAddress + /// The created customerAddress + ApiResult AddAddressToCustomer(CustomerAddress customerAddress); + + /// + /// Gets a specific customer addresses + /// + /// Id of the customer address + /// The specific customer address + ApiResult GetCustomerAddress(long customerAddressId); + + /// + /// Updates all fields of an address + /// + /// The customer address + /// The updated customer address + ApiResult UpdateCustomerAddress(CustomerAddress customerAddress); + + /// + /// Updates one or more fields of an address + /// + /// The id of the customer address to be updated + /// /// Dictionary which uses the field name as key and the new value as value. + /// The updated customer address + ApiResult PatchCustomerAddress(long customerAddressId, Dictionary fieldsToPatch); } } \ No newline at end of file diff --git a/Billbee.Api.Client/Endpoint/Interfaces/IEnumEndPoint.cs b/Billbee.Api.Client/Endpoint/Interfaces/IEnumEndPoint.cs new file mode 100644 index 0000000..a472528 --- /dev/null +++ b/Billbee.Api.Client/Endpoint/Interfaces/IEnumEndPoint.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using Billbee.Api.Client.Model; + +namespace Billbee.Api.Client.Endpoint.Interfaces +{ + public interface IEnumEndPoint + { + /// + /// Gets a list of all payment types + /// + /// The list of all payment types + List GetPaymentTypes(); + + /// + /// Gets a list of all shipping carriers + /// + /// The list of all shipping carriers + List GetShippingCarriers(); + + /// + /// Gets a list of all shipment types + /// + /// The list of all shipment types + List GetShipmentTypes(); + + /// + /// Gets a list of all order states + /// + /// The list of all order states + List GetOrderStates(); + } +} \ No newline at end of file diff --git a/Billbee.Api.Client/Endpoint/Interfaces/IOrderEndPoint.cs b/Billbee.Api.Client/Endpoint/Interfaces/IOrderEndPoint.cs index 09c2126..1a5d204 100644 --- a/Billbee.Api.Client/Endpoint/Interfaces/IOrderEndPoint.cs +++ b/Billbee.Api.Client/Endpoint/Interfaces/IOrderEndPoint.cs @@ -173,5 +173,19 @@ ApiResult> GetInvoiceList( /// Name of the event to trigger /// If set, the trigger will by delayed for the given number of minutes void CreateEventAtOrder(long orderId, string eventName, uint delayInMinutes = 0); + + /// + /// Gets a list of layout templates + /// + /// The list of layout templates + ApiResult> GetLayouts(); + + /// + /// Parses a text and replaces all placeholders + /// + /// The id of the order to parse + /// The text to be parsed + /// The parsed text + ParsePlaceholdersResult ParsePlaceholders(long orderId, ParsePlaceholdersQuery parsePlaceholdersQuery); } } \ No newline at end of file diff --git a/Billbee.Api.Client/Endpoint/Interfaces/IProductEndPoint.cs b/Billbee.Api.Client/Endpoint/Interfaces/IProductEndPoint.cs index b0992c9..1658b4b 100644 --- a/Billbee.Api.Client/Endpoint/Interfaces/IProductEndPoint.cs +++ b/Billbee.Api.Client/Endpoint/Interfaces/IProductEndPoint.cs @@ -63,6 +63,25 @@ public interface IProductEndPoint /// ApiResult GetProduct(string id, ProductIdType type = ProductIdType.id); + /// + /// Adds a new product + /// + /// + /// + ApiResult AddProduct(Product product); + + /// + /// Deletes one product, identified by the given id. + /// + /// Id of the product to delete. + void DeleteProduct(long id); + + /// + /// Requests a list of all categories + /// + /// List of Categories + ApiResult> GetCategories(); + /// /// Requests a list of all custom fields, usable in products /// diff --git a/Billbee.Api.Client/Endpoint/Interfaces/IShipmentEndPoint.cs b/Billbee.Api.Client/Endpoint/Interfaces/IShipmentEndPoint.cs index df8e408..d1764a6 100644 --- a/Billbee.Api.Client/Endpoint/Interfaces/IShipmentEndPoint.cs +++ b/Billbee.Api.Client/Endpoint/Interfaces/IShipmentEndPoint.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Billbee.Api.Client.Model; using Billbee.Api.Client.Model.Rechnungsdruck.WebApp.Model.Api; @@ -9,6 +10,21 @@ namespace Billbee.Api.Client.Endpoint.Interfaces /// public interface IShipmentEndPoint { + /// + /// Get a list of all shipments optionally filtered by date. + /// + /// Specifies the page to request. + /// Specifies the pageSize. Defaults to 50, max value is 250 + /// Specifies the oldest shipment date to include in the response + /// Specifies the newest shipment date to include in the response + /// Get shipments for this order only. + /// Get Shipments with a shipment greater or equal than this id. New shipments have a greater id than older shipments. + /// Get Shippings for the specified shipping provider only. + /// A list of shipments. + ApiPagedResult> GetShipments(int page = 1, int pageSize = 50, DateTime? createdAtMin = null, + DateTime? createdAtMax = null, long? orderId = null, long? minimumShipmentId = null, + long? shippingProviderId = null); + /// /// Requests a list of all available shipping providers and their products. /// diff --git a/Billbee.Api.Client/Endpoint/Interfaces/IWebhookEndPoint.cs b/Billbee.Api.Client/Endpoint/Interfaces/IWebhookEndPoint.cs index 707ba09..11d3fbc 100644 --- a/Billbee.Api.Client/Endpoint/Interfaces/IWebhookEndPoint.cs +++ b/Billbee.Api.Client/Endpoint/Interfaces/IWebhookEndPoint.cs @@ -48,7 +48,7 @@ public interface IWebhookEndPoint /// Registers a new webhook with the given information /// /// The details of the webhook to register. The property Id must be null. - /// The Id of the registered webhook - void CreateWebhook(Webhook webhook); + /// The registered webhook + Webhook CreateWebhook(Webhook webhook); } } \ No newline at end of file diff --git a/Billbee.Api.Client/Endpoint/OrderEndPoint.cs b/Billbee.Api.Client/Endpoint/OrderEndPoint.cs index 7ae294b..657f315 100644 --- a/Billbee.Api.Client/Endpoint/OrderEndPoint.cs +++ b/Billbee.Api.Client/Endpoint/OrderEndPoint.cs @@ -18,31 +18,37 @@ internal OrderEndPoint(IBillbeeRestClient restClient) _restClient = restClient; } + [ApiMapping("/api/v1/orders/{id}", HttpOperation.Get)] public ApiResult GetOrder(string id, int articleTitleSource = 0) { return _restClient.Get>($"/orders/{id}?articleTitleSource={articleTitleSource}"); } + [ApiMapping("/api/v1/orders/PatchableFields", HttpOperation.Get)] public ApiResult> GetPatchableFields() { return _restClient.Get>>("/orders/PatchableFields"); } + [ApiMapping("/api/v1/orders/{id}", HttpOperation.Patch)] public ApiResult PatchOrder(long id, Dictionary fieldsToPatch) { return _restClient.Patch>($"/orders/{id}", data: fieldsToPatch); } + [ApiMapping("/api/v1/orders/findbyextref/{extRef}", HttpOperation.Get)] public ApiResult GetOrderByExternalReference(string id) { return _restClient.Get>($"/orders/findbyextref/{id}"); } + [ApiMapping("/api/v1/orders/find/{id}/{partner}", HttpOperation.Get)] public ApiResult GetOrderByExternalIdAndPartner(string partner, string id) { return _restClient.Get>($"/orders/find/{id}/{partner}"); } + [ApiMapping("/api/v1/orders", HttpOperation.Get)] public ApiPagedResult> GetOrderList(DateTime? minOrderDate = null, DateTime? maxOrderDate = null, int page = 1, @@ -116,6 +122,7 @@ public ApiPagedResult> GetOrderList(DateTime? minOrderDate = null, return _restClient.Get>>("/orders", parameters); } + [ApiMapping("/api/v1/orders/invoices", HttpOperation.Get)] public ApiResult> GetInvoiceList( DateTime? minInvoiceDate = null, DateTime? maxInvoiceDate = null, @@ -186,6 +193,7 @@ public ApiResult> GetInvoiceList( return _restClient.Get>>("/orders/invoices", parameters); } + [ApiMapping("/api/v1/orders", HttpOperation.Post)] public ApiResult PostNewOrder(Order order, long shopId) { NameValueCollection parameters = new NameValueCollection(); @@ -194,21 +202,25 @@ public ApiResult PostNewOrder(Order order, long shopId) return _restClient.Post>("/orders", order, parameters); } + [ApiMapping("/api/v1/orders/{id}/tags", HttpOperation.Post)] public ApiResult AddTags(List tags, long orderId) { return _restClient.Post>($"/orders/{orderId}/tags", new { Tags = tags }); } + [ApiMapping("/api/v1/orders/{id}/tags", HttpOperation.Put)] public ApiResult UpdateTags(List tags, long orderId) { return _restClient.Put>($"/orders/{orderId}/tags", new { Tags = tags }); } + [ApiMapping("/api/v1/orders/{id}/shipment", HttpOperation.Post)] public void AddShipment(OrderShipment shipment) { _restClient.Post($"/orders/{shipment.OrderId}/shipment", shipment); } + [ApiMapping("/api/v1/orders/CreateDeliveryNote/{id}", HttpOperation.Post)] public ApiResult CreateDeliveryNote(long orderId, bool includePdf = false, long? sendToCloudId = null) { NameValueCollection parameters = new NameValueCollection(); @@ -220,6 +232,7 @@ public ApiResult CreateDeliveryNote(long orderId, bool includePdf return _restClient.Post>($"/orders/CreateDeliveryNote/{orderId}", parameters); } + [ApiMapping("/api/v1/orders/CreateInvoice/{id}", HttpOperation.Post)] public ApiResult CreateInvoice(long orderId, bool includePdf = false, long? templateId = null, long? sendToCloudId = null) { NameValueCollection parameters = new NameValueCollection(); @@ -234,16 +247,19 @@ public ApiResult CreateInvoice(long orderId, bool includePdf = false, l return _restClient.Post>($"/orders/CreateInvoice/{orderId}", parameters); } + [ApiMapping("/api/v1/orders/{id}/orderstate", HttpOperation.Put)] public void ChangeOrderState(long id, OrderStateEnum state) { _restClient.Put($"/orders/{id}/orderstate", new { NewStateId = (int)state }, null); } + [ApiMapping("/api/v1/orders/{id}/send-message", HttpOperation.Post)] public void SendMailForOrder(long orderId, SendMessage message) { _restClient.Post($"/orders/{orderId}/send-message", message); } + [ApiMapping("/api/v1/orders/{id}/trigger-event", HttpOperation.Post)] public void CreateEventAtOrder(long orderId, string eventName, uint delayInMinutes = 0) { var model = new TriggerEventContainer @@ -254,5 +270,17 @@ public void CreateEventAtOrder(long orderId, string eventName, uint delayInMinut _restClient.Post($"/orders/{orderId}/trigger-event", model); } + + [ApiMapping("/api/v1/layouts", HttpOperation.Get)] + public ApiResult> GetLayouts() + { + return _restClient.Get>>($"/layouts"); + } + + [ApiMapping("/api/v1/orders/{id}/parse-placeholders", HttpOperation.Post)] + public ParsePlaceholdersResult ParsePlaceholders(long orderId, ParsePlaceholdersQuery parsePlaceholdersQuery) + { + return _restClient.Post($"/orders/{orderId}/parse-placeholders", parsePlaceholdersQuery); + } } } diff --git a/Billbee.Api.Client/Endpoint/ProductEndPoint.cs b/Billbee.Api.Client/Endpoint/ProductEndPoint.cs index 0a85b1f..6cdc186 100644 --- a/Billbee.Api.Client/Endpoint/ProductEndPoint.cs +++ b/Billbee.Api.Client/Endpoint/ProductEndPoint.cs @@ -17,21 +17,25 @@ internal ProductEndPoint(IBillbeeRestClient restClient) _restClient = restClient; } + [ApiMapping("/api/v1/products/stocks", HttpOperation.Get)] public ApiResult> GetStocks() { return _restClient.Get>>("/products/stocks"); } + [ApiMapping("/api/v1/products/updatestockmultiple", HttpOperation.Post)] public List> UpdateStockMultiple(List updateStockList) { return _restClient.Post>>("/products/updatestockmultiple", updateStockList); } + [ApiMapping("/api/v1/products/updatestock", HttpOperation.Post)] public ApiResult UpdateStock(UpdateStock updateStockModel) { return _restClient.Post>("/products/updatestock", updateStockModel); } + [ApiMapping("/api/v1/products/reservedamount", HttpOperation.Get)] public ApiResult GetReservedAmount(string id, string lookupBy = "id", long? stockId = null) { NameValueCollection parameters = new NameValueCollection(); @@ -45,11 +49,13 @@ public ApiResult GetReservedAmount(string id, string lo return _restClient.Get>($"/products/reservedamount", parameters); } + [ApiMapping("/api/v1/products/updatestockcode", HttpOperation.Post)] public ApiResult UpdateStockCode(UpdateStockCode updateStockCodeModel) { return _restClient.Post>("/products/updatestockcode", updateStockCodeModel); } + [ApiMapping("/api/v1/products", HttpOperation.Get)] public ApiPagedResult> GetProducts(int page, int pageSize, DateTime? minCreatedAt = null) { NameValueCollection parameters = new NameValueCollection(); @@ -63,6 +69,7 @@ public ApiPagedResult> GetProducts(int page, int pageSize, DateTim return _restClient.Get>>($"/products", parameters); } + [ApiMapping("/api/v1/products/{id}", HttpOperation.Get)] public ApiResult GetProduct(string id, ProductIdType type = ProductIdType.id) { NameValueCollection parameters = new NameValueCollection(); @@ -71,7 +78,26 @@ public ApiResult GetProduct(string id, ProductIdType type = ProductIdTy return _restClient.Get>($"/products/{id}", parameters); } + + [ApiMapping("/api/v1/products", HttpOperation.Post)] + public ApiResult AddProduct(Product product) + { + return _restClient.Post>($"/products", product); + } + + [ApiMapping("/api/v1/products/{id}", HttpOperation.Delete)] + public void DeleteProduct(long id) + { + _restClient.Delete($"/products/{id}"); + } + + [ApiMapping("/api/v1/products/category", HttpOperation.Get)] + public ApiResult> GetCategories() + { + return _restClient.Get>>($"/products/category"); + } + [ApiMapping("/api/v1/products/custom-fields", HttpOperation.Get)] public ApiPagedResult> GetCustomFields(int page, int pageSize) { NameValueCollection parameters = new NameValueCollection(); @@ -81,36 +107,43 @@ public ApiPagedResult> GetCustomFields(int pa return _restClient.Get>>($"/products/custom-fields", parameters); } + [ApiMapping("/api/v1/products/custom-fields/{id}", HttpOperation.Get)] public ApiResult GetCustomField(long id) { return _restClient.Get>($"/products/custom-fields/{id}"); } + [ApiMapping("/api/v1/products/PatchableFields", HttpOperation.Get)] public ApiResult> GetPatchableProductFields() { return _restClient.Get>>($"/products/PatchableFields"); } - + + [ApiMapping("/api/v1/products/{id}", HttpOperation.Patch)] public ApiResult PatchArticle(long id, Dictionary fieldsToPatch) { return _restClient.Patch>($"/products/{id}", data: fieldsToPatch); } + [ApiMapping("/api/v1/products/{productId}/images", HttpOperation.Get)] public ApiResult> GetArticleImages(long id) { return _restClient.Get>>($"/products/{id}/images"); } + [ApiMapping("/api/v1/products/{productId}/images/{imageId}", HttpOperation.Get)] public ApiResult GetArticleImage(long articleId, long imageId) { return _restClient.Get>($"/products/{articleId}/images/{imageId}"); } + [ApiMapping("/api/v1/products/images/{imageId}", HttpOperation.Get)] public ApiResult GetArticleImage(long imageId) { return _restClient.Get>($"/products/images/{imageId}"); } + [ApiMapping("/api/v1/products/{productId}/images/{imageId}", HttpOperation.Put)] public ApiResult AddArticleImage(ArticleImage image) { if (image.Id != 0) @@ -121,6 +154,7 @@ public ApiResult AddArticleImage(ArticleImage image) return _restClient.Put>($"/products/{image.ArticleId}/images/{image.Id}", image); } + [ApiMapping("/api/v1/products/{productId}/images/{imageId}", HttpOperation.Put)] public ApiResult UpdateArticleImage(ArticleImage image) { if (image.Id == 0) @@ -131,6 +165,7 @@ public ApiResult UpdateArticleImage(ArticleImage image) return _restClient.Put>($"/products/{image.ArticleId}/images/{image.Id}", image); } + [ApiMapping("/api/v1/products/{productId}/images", HttpOperation.Put)] public ApiResult> AddMultipleArticleImages(long articleId, List images, bool replace = false) { NameValueCollection parameters = new NameValueCollection(); @@ -138,16 +173,19 @@ public ApiResult> AddMultipleArticleImages(long articleId, Li return _restClient.Put>>($"/products/{articleId}/images", images, parameters); } + [ApiMapping("/api/v1/products/{productId}/images/{imageId}", HttpOperation.Delete)] public void DeleteArticleImage(long articleId, long imageId) { _restClient.Delete($"/products/{articleId}/images/{imageId}"); } + [ApiMapping("/api/v1/products/images/{imageId}", HttpOperation.Delete)] public void DeleteArticleImage(long imageId) { _restClient.Delete($"/products/images/{imageId}"); } + [ApiMapping("/api/v1/products/images/delete", HttpOperation.Post)] public ApiResult DeleteMultipleArticleImages(List imageIds) { return _restClient.Post>($"/products/images/delete", imageIds); diff --git a/Billbee.Api.Client/Endpoint/SearchEndPoint.cs b/Billbee.Api.Client/Endpoint/SearchEndPoint.cs index 811d0c8..b6518e5 100644 --- a/Billbee.Api.Client/Endpoint/SearchEndPoint.cs +++ b/Billbee.Api.Client/Endpoint/SearchEndPoint.cs @@ -18,6 +18,7 @@ internal SearchEndPoint(IBillbeeRestClient restClient) _restClient = restClient; } + [ApiMapping("/api/v1/search", HttpOperation.Post)] public ApiResult SearchTerm(Search search) { return _restClient.Post>($"/search", search ); diff --git a/Billbee.Api.Client/Endpoint/ShipmentEndPoint.cs b/Billbee.Api.Client/Endpoint/ShipmentEndPoint.cs index b35f017..44ddc4f 100644 --- a/Billbee.Api.Client/Endpoint/ShipmentEndPoint.cs +++ b/Billbee.Api.Client/Endpoint/ShipmentEndPoint.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; using System.Net; using Billbee.Api.Client.Endpoint.Interfaces; using Billbee.Api.Client.Model; @@ -15,27 +17,62 @@ internal ShipmentEndPoint(IBillbeeRestClient restClient) { _restClient = restClient; } + + [ApiMapping("/api/v1/shipment/shipments", HttpOperation.Get)] + public ApiPagedResult> GetShipments(int page = 1, int pageSize = 50, DateTime? createdAtMin = null, DateTime? createdAtMax = null, long? orderId = null, long? minimumShipmentId = null, long? shippingProviderId = null) + { + NameValueCollection parameters = new NameValueCollection(); + parameters.Add("page", page.ToString()); + parameters.Add("pageSize", pageSize.ToString()); + if (createdAtMin != null) + { + parameters.Add("createdAtMin", createdAtMin.Value.ToString("yyyy-MM-dd")); + } + if (createdAtMax != null) + { + parameters.Add("createdAtMax", createdAtMax.Value.ToString("yyyy-MM-dd")); + } + if (orderId != null) + { + parameters.Add("orderId", orderId.Value.ToString()); + } + if (minimumShipmentId != null) + { + parameters.Add("minimumShipmentId", minimumShipmentId.Value.ToString()); + } + if (shippingProviderId != null) + { + parameters.Add("shippingProviderId", shippingProviderId.Value.ToString()); + } + + return _restClient.Get>>($"/shipment/shipments", parameters); + } + [ApiMapping("/api/v1/shipment/shippingproviders", HttpOperation.Get)] public List GetShippingProvider() { return _restClient.Get>("/shipment/shippingproviders"); } + [ApiMapping("/api/v1/shipment/shipment", HttpOperation.Post)] public ApiResult PostShipment(PostShipment shipment) { return _restClient.Post>("/shipment/shipment", shipment); } + [ApiMapping("/api/v1/shipment/shipwithlabel", HttpOperation.Post)] public ApiResult ShipOrderWithLabel(ShipmentWithLabel shipmentRequest) { return _restClient.Post>("/shipment/shipwithlabel", shipmentRequest); } + [ApiMapping("/api/v1/shipment/shippingcarriers", HttpOperation.Get)] public List GetShippingCarriers() { return _restClient.Get>("/shipment/shippingcarriers"); } + [ApiMapping("/api/v1/shipment/ping", HttpOperation.Get)] internal bool Ping() { var result = _restClient.Get("/shipment/ping"); diff --git a/Billbee.Api.Client/Endpoint/WebhookEndPoint.cs b/Billbee.Api.Client/Endpoint/WebhookEndPoint.cs index 44a0d90..d59889b 100644 --- a/Billbee.Api.Client/Endpoint/WebhookEndPoint.cs +++ b/Billbee.Api.Client/Endpoint/WebhookEndPoint.cs @@ -14,11 +14,13 @@ internal WebhookEndPoint(IBillbeeRestClient restClient) _restClient = restClient; } + [ApiMapping("/api/v1/webhooks", HttpOperation.Delete)] public void DeleteAllWebhooks() { _restClient.Delete("/webhooks"); } + [ApiMapping("/api/v1/webhooks/{id}", HttpOperation.Delete)] public void DeleteWebhook(string id) { if (string.IsNullOrWhiteSpace(id)) @@ -29,11 +31,13 @@ public void DeleteWebhook(string id) _restClient.Delete($"/webhooks/{id}"); } + [ApiMapping("/api/v1/webhooks", HttpOperation.Get)] public List GetWebhooks() { return _restClient.Get>("/webhooks"); } + [ApiMapping("/api/v1/webhooks/{id}", HttpOperation.Get)] public Webhook GetWebhook(string id) { if (string.IsNullOrWhiteSpace(id)) @@ -44,6 +48,7 @@ public Webhook GetWebhook(string id) return _restClient.Get($"/webhooks/{id}"); } + [ApiMapping("/api/v1/webhooks/{id}", HttpOperation.Put)] public void UpdateWebhook(Webhook webhook) { if (string.IsNullOrWhiteSpace(webhook.Id )) @@ -54,12 +59,14 @@ public void UpdateWebhook(Webhook webhook) _restClient.Put($"/webhooks/{webhook.Id}", webhook); } + [ApiMapping("/api/v1/webhooks/filters", HttpOperation.Get)] public List GetFilters() { return _restClient.Get>("/webhooks/filters"); } - public void CreateWebhook(Webhook webhook) + [ApiMapping("/api/v1/webhooks", HttpOperation.Post)] + public Webhook CreateWebhook(Webhook webhook) { if (webhook.Id != null) { @@ -71,7 +78,7 @@ public void CreateWebhook(Webhook webhook) throw new InvalidValueException($"Property secret is malformed. It must meet the following criteria: Not null or whitespaces only, between 32 and 64 charackters long."); } - _restClient.Post("/webhooks", webhook); + return _restClient.Post("/webhooks", webhook); } } } diff --git a/Billbee.Api.Client/Enums/PaymentTypeEnum.cs b/Billbee.Api.Client/Enums/PaymentTypeEnum.cs index a9632b3..b8322c5 100644 --- a/Billbee.Api.Client/Enums/PaymentTypeEnum.cs +++ b/Billbee.Api.Client/Enums/PaymentTypeEnum.cs @@ -120,5 +120,8 @@ public enum PaymentTypeEnum MollieEPS = 123, CrefoPayPrepaid = 124, MollieBancontact = 125, + MolliePrzelewy24 = 126, + MollieKlarnaRatenkauf =127, + MollieKlarnaSliceit =128, } } diff --git a/Billbee.Api.Client/Enums/ShipmentTypeEnum.cs b/Billbee.Api.Client/Enums/ShipmentTypeEnum.cs new file mode 100644 index 0000000..15b4f6b --- /dev/null +++ b/Billbee.Api.Client/Enums/ShipmentTypeEnum.cs @@ -0,0 +1,8 @@ +namespace Billbee.Api.Client.Enums +{ + public enum ShipmentTypeEnum + { + Shipment, + Retoure + } +} \ No newline at end of file diff --git a/Billbee.Api.Client/Enums/ShippingCarrierEnum.cs b/Billbee.Api.Client/Enums/ShippingCarrierEnum.cs new file mode 100644 index 0000000..9657736 --- /dev/null +++ b/Billbee.Api.Client/Enums/ShippingCarrierEnum.cs @@ -0,0 +1,25 @@ +namespace Billbee.Api.Client.Enums +{ + public enum ShippingCarrierEnum + { + other, + dhlExpress, + dhl, + hermes, + dpd, + ups, + gls, + dpag, + OePost, + fedex, + generalOvernight, + tnt, + liefery, + iloxx, + parcel_one, + cargo_international, + pin_mail, + usPostalService, + amazon_logistics, + } +} \ No newline at end of file diff --git a/Billbee.Api.Client/IApiClient.cs b/Billbee.Api.Client/IApiClient.cs index 8b8fb45..f168ca3 100644 --- a/Billbee.Api.Client/IApiClient.cs +++ b/Billbee.Api.Client/IApiClient.cs @@ -44,6 +44,11 @@ public interface IApiClient /// ICustomerEndPoint Customer { get; } + /// + /// EndPoint to access customer addresses + /// + ICustomerAddressesEndPoint CustomerAddresses { get; } + /// /// EndPoint for searches in customers, orders and products /// @@ -58,6 +63,11 @@ public interface IApiClient /// EndPoint to access cloud storages /// ICloudStoragesEndPoint CloudStorages { get; } + + /// + /// EndPoint to access enum values + /// + IEnumEndPoint Enums { get; } /// /// Validates, that access to the api is possible with the given configuration diff --git a/Billbee.Api.Client/Model/CustomerAddress.cs b/Billbee.Api.Client/Model/CustomerAddress.cs index fedbb20..1885ffb 100644 --- a/Billbee.Api.Client/Model/CustomerAddress.cs +++ b/Billbee.Api.Client/Model/CustomerAddress.cs @@ -3,12 +3,12 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using Billbee.Api.Client.Enums; namespace Billbee.Api.Client.Model { public class CustomerAddress { - public long? Id { get; set; } /// /// 1 = Invoiceaddress diff --git a/Billbee.Api.Client/Model/EnumEntry.cs b/Billbee.Api.Client/Model/EnumEntry.cs new file mode 100644 index 0000000..0c0f577 --- /dev/null +++ b/Billbee.Api.Client/Model/EnumEntry.cs @@ -0,0 +1,8 @@ +namespace Billbee.Api.Client.Model +{ + public class EnumEntry + { + public int Id { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/Billbee.Api.Client/Model/ParsePlaceholdersQuery.cs b/Billbee.Api.Client/Model/ParsePlaceholdersQuery.cs new file mode 100644 index 0000000..952bae5 --- /dev/null +++ b/Billbee.Api.Client/Model/ParsePlaceholdersQuery.cs @@ -0,0 +1,26 @@ +namespace Billbee.Api.Client.Model +{ + public class ParsePlaceholdersQuery + { + /// + /// The text to parse and replace the placeholders in. + /// + public string TextToParse { get; set; } + + /// + /// If true, the string will be handled as html. + /// + public bool IsHtml { get; set; } = false; + + /// + /// The ISO 639-1 code of the target language. Using default if not set. + /// + public string Language { get; set; } = null; + + /// + /// If true, then the placeholder values are trimmed after usage. + /// + public bool Trim { get; set; } = false; + + } +} \ No newline at end of file diff --git a/Billbee.Api.Client/Model/ParsePlaceholdersResult.cs b/Billbee.Api.Client/Model/ParsePlaceholdersResult.cs new file mode 100644 index 0000000..e303f54 --- /dev/null +++ b/Billbee.Api.Client/Model/ParsePlaceholdersResult.cs @@ -0,0 +1,7 @@ +namespace Billbee.Api.Client.Model +{ + public class ParsePlaceholdersResult + { + public string Result { get; set; } + } +} \ No newline at end of file diff --git a/Billbee.Api.Client/Model/Shipment.cs b/Billbee.Api.Client/Model/Shipment.cs index 2b1ffc0..40435db 100644 --- a/Billbee.Api.Client/Model/Shipment.cs +++ b/Billbee.Api.Client/Model/Shipment.cs @@ -1,92 +1,50 @@ using System; -using System.Collections.Generic; using Billbee.Api.Client.Enums; namespace Billbee.Api.Client.Model { - namespace Rechnungsdruck.WebApp.Model.Api + /// + /// Represents a single shipment. + /// + public class Shipment { /// - /// Conainer, to create a shipment without context to a billbee order. + /// The billbee internal id of the shipment /// - public class PostShipment - { - /// - /// Name of the shipping provider, to use - /// - public string ProviderName { get; set; } + public long BillbeeId { get; set; } - /// - /// Product code of the shipping provider for the product, to use as shipment method - /// - public string ProductCode { get; set; } + /// The id of this shipment + public string ShippingId { get; set; } - /// - /// Name of the cloud printer, to send the labels to - /// - public string PrinterName { get; set; } - - /// - /// The id of a connected Cloudprinter to sent the export docs to - /// - public long? PrinterIdForExportDocs { get; set; } + /// The name of the shipping provider + public string Shipper { get; set; } - /// - /// List of services, to attach to the shipping product - /// - public List Services { get; set; } + /// The creation date + public DateTime? Created { get; set; } - /// - /// Address of the adressee - /// - public ShipmentAddress ReceiverAddress { get; set; } - - /// - /// Reference number for this parcel - /// - public string ClientReference { get; set; } - - /// - /// Number of the customer, this parcel should be send to. - /// - public string CustomerNumber { get; set; } - - /// - /// gross weight of the parcel - /// - public decimal? WeightInGram { get; set; } - - /// - /// Total gross value of the parcel - /// - public decimal OrderSum { get; set; } - - /// - /// Currency code, of the currency, the order was made in. < - /// - public string OrderCurrencyCode { get; set; } + /// + /// The url to track this shipment + /// + public string TrackingUrl { get; set; } - /// - /// For export parcels, the content has to be defined - /// - public string Content { get; set; } + /// + /// The id of the used shipping provider + /// + public long? ShippingProviderId { get; set; } - /// - /// Date and time of shipment - /// - public DateTime? ShipDate { get; set; } + /// + /// The id of the used shipping provider product + /// + public long? ShippingProviderProductId { get; set; } - /// - /// The Id of the carrier, the parcel will be send with - /// - public byte shippingCarrier { get; set; } - - /// - /// The value of the shipments content (net) - /// - public decimal TotalNet { get; set; } - - public ShipmentDimensions Dimension { get; set; } - } + /// + /// The carrier used to ship the parcel with + /// + public ShippingCarrierEnum? ShippingCarrier { get; set; } + + /// + /// Shipment Type, 0 if Shipment, 1 if Retoure + /// + public ShipmentTypeEnum? ShipmentType { get; set; } } -} +} \ No newline at end of file diff --git a/Billbee.Api.Client/Model/ShipmentPost.cs b/Billbee.Api.Client/Model/ShipmentPost.cs new file mode 100644 index 0000000..2b1ffc0 --- /dev/null +++ b/Billbee.Api.Client/Model/ShipmentPost.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using Billbee.Api.Client.Enums; + +namespace Billbee.Api.Client.Model +{ + namespace Rechnungsdruck.WebApp.Model.Api + { + /// + /// Conainer, to create a shipment without context to a billbee order. + /// + public class PostShipment + { + /// + /// Name of the shipping provider, to use + /// + public string ProviderName { get; set; } + + /// + /// Product code of the shipping provider for the product, to use as shipment method + /// + public string ProductCode { get; set; } + + /// + /// Name of the cloud printer, to send the labels to + /// + public string PrinterName { get; set; } + + /// + /// The id of a connected Cloudprinter to sent the export docs to + /// + public long? PrinterIdForExportDocs { get; set; } + + /// + /// List of services, to attach to the shipping product + /// + public List Services { get; set; } + + /// + /// Address of the adressee + /// + public ShipmentAddress ReceiverAddress { get; set; } + + /// + /// Reference number for this parcel + /// + public string ClientReference { get; set; } + + /// + /// Number of the customer, this parcel should be send to. + /// + public string CustomerNumber { get; set; } + + /// + /// gross weight of the parcel + /// + public decimal? WeightInGram { get; set; } + + /// + /// Total gross value of the parcel + /// + public decimal OrderSum { get; set; } + + /// + /// Currency code, of the currency, the order was made in. < + /// + public string OrderCurrencyCode { get; set; } + + /// + /// For export parcels, the content has to be defined + /// + public string Content { get; set; } + + /// + /// Date and time of shipment + /// + public DateTime? ShipDate { get; set; } + + /// + /// The Id of the carrier, the parcel will be send with + /// + public byte shippingCarrier { get; set; } + + /// + /// The value of the shipments content (net) + /// + public decimal TotalNet { get; set; } + + public ShipmentDimensions Dimension { get; set; } + } + } +} From 4b32a9af8c2866ba292de03fc9eb6d2b60f9fcce Mon Sep 17 00:00:00 2001 From: Benjamin Gottschalk Date: Thu, 4 Aug 2022 08:22:39 +0200 Subject: [PATCH 03/11] added Endpoint Tests --- ...tomaticProvisionEndPointIntegrationTest.cs | 94 ++++++- .../CloudStoragesEndPointIntegrationTest.cs | 10 +- ...ustomerAddressesEndPointIntegrationTest.cs | 102 ++++++++ .../CustomerEndPointIntegrationTest.cs | 182 ++++++++++++++ .../EnumEndPointIntegrationTest.cs | 133 ++++++++++ .../EventEndPointIntegrationTest.cs | 11 +- .../Helpers/CrudHelpers.cs | 107 +++++++- .../Helpers/IntegrationTestHelpers.cs | 32 ++- .../Helpers/TestData.cs | 93 ------- .../SearchEndPointIntegrationTest.cs | 28 ++- .../WebhookEndPointIntegrationTest.cs | 231 ++++++++++-------- .../EndPointTests/SearchEndPointTest.cs | 1 + 12 files changed, 788 insertions(+), 236 deletions(-) create mode 100644 Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs create mode 100644 Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs create mode 100644 Billbee.Api.Client.Test/EndPointIntegrationTests/EnumEndPointIntegrationTest.cs delete mode 100644 Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/TestData.cs diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/AutomaticProvisionEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/AutomaticProvisionEndPointIntegrationTest.cs index ce46900..f78020e 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/AutomaticProvisionEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/AutomaticProvisionEndPointIntegrationTest.cs @@ -1,21 +1,89 @@ -using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; +using System.Net; +using Billbee.Api.Client.Model; +using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; -namespace Billbee.Api.Client.Test.EndPointIntegrationTests; - -[TestClass] -public class AutomaticProvisionEndPointIntegrationTest +namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers { - [TestMethod] - [RequiresApiAccess] - public void CreateAccount_IntegrationTest() + public static partial class TestData { - Assert.Inconclusive(); + public static Account Account(string name) => new Account + { + EMail = "john+" + name + "@test.com", + Password = "1Ufuyk2s", + AcceptTerms = true, + Address = new Account.UserAddress + { + Company = "Test Company GmbH", + Name = name, + Address1 = "Paulinenstr. 4", + Address2 = "address 2", + Zip = "12345", + City = "Flipstadt", + Country = "DE", + VatId = name + "-VatId" + }, + AffiliateCouponCode = "affiliateCouponCode", + Vat1Rate = 19, + Vat2Rate = 7, + DefaultVatMode = 0, + DefaultCurrrency = "EUR", + DefaultVatIndex = 0 + }; } +} - [TestMethod] - [RequiresApiAccess] - public void TermsInfo_IntegrationTest() +namespace Billbee.Api.Client.Test.EndPointIntegrationTests +{ + [TestClass] + public class AutomaticProvisionEndPointIntegrationTest { - Assert.Inconclusive(); + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + { + IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod); + } + + [TestMethod] + [RequiresApiAccess] + public void CreateAccount_IntegrationTest() + { + var account = TestData.Account(Guid.NewGuid().ToString()); + var result = + CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.AutomaticProvision.CreateAccount(x), + account, false); + var createUserResult = result.Data; + Assert.IsNotNull(createUserResult.Password); + Assert.IsNotNull(createUserResult.UserId); + } + + [TestMethod] + [RequiresApiAccess] + public async Task TermsInfo_IntegrationTest() + { + var result = IntegrationTestHelpers.ApiClient.AutomaticProvision.TermsInfo(); + Assert.IsNotNull(result); + + var termsResult = result.Data; + + Assert.IsNotNull(termsResult); + Assert.IsNotNull(termsResult.LinkToTermsWebPage); + await _checkLink(termsResult.LinkToTermsWebPage); + Assert.IsNotNull(termsResult.LinkToPrivacyWebPage); + await _checkLink(termsResult.LinkToPrivacyWebPage); + + Assert.AreEqual(string.Empty, termsResult.LinkToTermsHtmlContent); + Assert.AreEqual(string.Empty, termsResult.LinkToPrivacyHtmlContent); + } + + private async Task _checkLink(string url) + { + var httpClient = new HttpClient(); + var response = await httpClient.GetAsync(url); + response.EnsureSuccessStatusCode(); + + Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); + } } } \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/CloudStoragesEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/CloudStoragesEndPointIntegrationTest.cs index 01c7a9a..78f1410 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/CloudStoragesEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/CloudStoragesEndPointIntegrationTest.cs @@ -5,10 +5,18 @@ namespace Billbee.Api.Client.Test.EndPointIntegrationTests; [TestClass] public class CloudStoragesEndPointIntegrationTest { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + { + IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod); + } + [TestMethod] [RequiresApiAccess] public void GetCloudStorageList_IntegrationTest() { - Assert.Inconclusive(); + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.CloudStorages.GetCloudStorageList()); } } \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs new file mode 100644 index 0000000..22f2779 --- /dev/null +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs @@ -0,0 +1,102 @@ +using Billbee.Api.Client.Model; +using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; + +namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers +{ + public static partial class TestData + { + public static CustomerAddress CustomerAddress => + new CustomerAddress + { + FirstName = "John", + LastName = "Doe", + Street = "Mustergasse", + Housenumber = "1", + Zip = "12345", + City = "Musterstadt", + AddressType = 1, + CountryCode = "DE", + CustomerId = 0 + }; + + public static CustomerAddress GetCustomerAddress(long? customerId) + { + var address = CustomerAddress; + address.CustomerId = customerId; + return address; + } + } +} + +namespace Billbee.Api.Client.Test.EndPointIntegrationTests +{ + [TestClass] + public class CustomerAddressesEndPointIntegrationTest + { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + { + IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod); + } + + [TestMethod] + [RequiresApiAccess] + public void GetCustomerAddresses_IntegrationTest() + { + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.CustomerAddresses.GetCustomerAddresses(1, 5)); + } + + [TestMethod] + [RequiresApiAccess] + public void GetCustomerAddress_IntegrationTest() + { + var customer = + CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), + TestData.Customer).Data; + + var customerAddress = + CrudHelpers.CreateApiResult( + a => IntegrationTestHelpers.ApiClient.CustomerAddresses.AddCustomerAddress(a), + TestData.GetCustomerAddress(customer.Id)).Data; + CrudHelpers.GetOneApiResult( + (id) => IntegrationTestHelpers.ApiClient.CustomerAddresses.GetCustomerAddress(id), + customerAddress.Id!.Value); + } + + [TestMethod] + [RequiresApiAccess] + public void AddCustomerAddress_IntegrationTest() + { + GetCustomerAddress_IntegrationTest(); + } + + [TestMethod] + [RequiresApiAccess] + public void UpdateCustomerAddress_IntegrationTest() + { + var customer = + CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), + TestData.Customer).Data; + + var customerAddress = + CrudHelpers.CreateApiResult( + a => IntegrationTestHelpers.ApiClient.CustomerAddresses.AddCustomerAddress(a), + TestData.GetCustomerAddress(customer.Id)).Data; + var result = CrudHelpers.GetOneApiResult( + (id) => IntegrationTestHelpers.ApiClient.CustomerAddresses.GetCustomerAddress(id), + customerAddress.Id!.Value); + var address = result.Data; + + address.LastName = "Modified"; + CrudHelpers.Put( + c => IntegrationTestHelpers.ApiClient.CustomerAddresses.UpdateCustomerAddress(c), + address); + CrudHelpers.GetOneApiResult( + (id) => IntegrationTestHelpers.ApiClient.CustomerAddresses.GetCustomerAddress(id), + customerAddress.Id!.Value); + Assert.AreEqual("Modified", address.LastName); + } + } +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs new file mode 100644 index 0000000..5c19254 --- /dev/null +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs @@ -0,0 +1,182 @@ +using Billbee.Api.Client.Model; +using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; + +namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers +{ + public static partial class TestData + { + public static CustomerForCreation Customer => new CustomerForCreation + { + Name = "John Doe", + Address = TestData.CustomerAddress, + Email = "john@doe.com", + Type = 0 + }; + } +} + +namespace Billbee.Api.Client.Test.EndPointIntegrationTests +{ + [TestClass] + public class CustomerEndPointIntegrationTest + { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + { + IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod); + } + + [TestMethod] + [RequiresApiAccess] + public void GetCustomerList_IntegrationTest() + { + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Customer.GetCustomerList(1, int.MaxValue)); + } + + [TestMethod] + [RequiresApiAccess] + public void AddCustomer_IntegrationTest() + { + var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), + TestData.Customer); + Assert.AreEqual("john@doe.com", customer.Data.Email); + + CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Customer.GetCustomer(id), + customer.Data.Id!.Value); + } + + [TestMethod] + [RequiresApiAccess] + public void AddAddressToCustomer_IntegrationTest() + { + var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), + TestData.Customer); + + var customerAddress = TestData.GetCustomerAddress(customer.Data.Id); + var result = + CrudHelpers.CreateApiResult(a => IntegrationTestHelpers.ApiClient.Customer.AddAddressToCustomer(a), + customerAddress); + Assert.IsNotNull(result.Data); + } + + [TestMethod] + [RequiresApiAccess] + public void GetCustomerAddress_IntegrationTest() + { + var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), + TestData.Customer); + + var address = CrudHelpers.GetAll(() => + IntegrationTestHelpers.ApiClient.Customer.GetAddressesForCustomer(customer.Data.Id.Value, 1, 5)) + .Data + .FirstOrDefault(); + CrudHelpers.GetOneApiResult( + (id) => IntegrationTestHelpers.ApiClient.Customer.GetCustomerAddress(id), address!.Id!.Value); + } + + [TestMethod] + [RequiresApiAccess] + public void UpdateCustomerAddress_IntegrationTest() + { + var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), + TestData.Customer); + + var address = CrudHelpers.GetAll(() => + IntegrationTestHelpers.ApiClient.Customer.GetAddressesForCustomer(customer!.Data!.Id!.Value, 1, 5)) + .Data + .FirstOrDefault(); + Assert.AreEqual(TestData.CustomerAddress.FirstName, address!.FirstName); + + address.FirstName = "Modified"; + var result = CrudHelpers.Put( + c => IntegrationTestHelpers.ApiClient.Customer.UpdateCustomerAddress(c), + address); + + Assert.AreEqual("Modified", result.Data.FirstName); + } + + [TestMethod] + [RequiresApiAccess] + public void PatchCustomerAddress_IntegrationTest() + { + var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), + TestData.Customer); + Assert.IsNotNull(customer); + + var address = CrudHelpers.GetAll(() => + IntegrationTestHelpers.ApiClient.Customer.GetAddressesForCustomer(customer.Data!.Id!.Value, 1, 5)) + .Data + .FirstOrDefault(); + Assert.AreEqual(TestData.CustomerAddress.FirstName, address!.FirstName); + + var fieldsToPatch = new Dictionary + { + { "FirstName", "Modified" } + }; + var result = CrudHelpers.Patch( + (id, fields) => IntegrationTestHelpers.ApiClient.Customer.PatchCustomerAddress(id, fields), + address.Id!.Value, fieldsToPatch); + + Assert.AreEqual("Modified", result.Data.FirstName); + } + + [TestMethod] + [RequiresApiAccess] + public void GetCustomer_IntegrationTest() + { + var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), + TestData.Customer); + Assert.IsNotNull(customer); + + CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Customer.GetCustomer(id), + customer!.Data!.Id!.Value); + } + + [TestMethod] + [RequiresApiAccess] + public void UpdateCustomer_IntegrationTest() + { + var result = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), + TestData.Customer); + result = CrudHelpers.GetOneApiResult( + (id) => IntegrationTestHelpers.ApiClient.Customer.GetCustomer(id), result!.Data.Id!.Value); + var customer = result.Data; + + Assert.AreNotEqual("Modified", customer.Name); + customer.Name = "Modified"; + CrudHelpers.Put((x) => IntegrationTestHelpers.ApiClient.Customer.UpdateCustomer(x), customer); + + result = CrudHelpers.GetOneApiResult( + (id) => IntegrationTestHelpers.ApiClient.Customer.GetCustomer(id), result!.Data.Id!.Value); + Assert.AreEqual("Modified", result.Data.Name); + } + + [TestMethod] + [RequiresApiAccess] + public void GetOrdersForCustomer_IntegrationTest() + { + var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), + TestData.Customer); + Assert.IsNotNull(customer); + + CrudHelpers.GetAll(() => + IntegrationTestHelpers.ApiClient.Customer.GetOrdersForCustomer(customer.Data!.Id!.Value, 1, 5)).Data + .FirstOrDefault(); + } + + [TestMethod] + [RequiresApiAccess] + public void GetAddressesForCustomer_IntegrationTest() + { + var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), + TestData.Customer); + Assert.IsNotNull(customer); + + var result = CrudHelpers.GetAll(() => + IntegrationTestHelpers.ApiClient.Customer.GetAddressesForCustomer(customer.Data!.Id!.Value, 1, 5)); + Assert.IsTrue(result.Data.Count > 0); + } + } +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/EnumEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/EnumEndPointIntegrationTest.cs new file mode 100644 index 0000000..e94461b --- /dev/null +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/EnumEndPointIntegrationTest.cs @@ -0,0 +1,133 @@ +using Billbee.Api.Client.Endpoint.Interfaces; +using Billbee.Api.Client.Enums; +using Billbee.Api.Client.Model; +using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; + +namespace Billbee.Api.Client.Test.EndPointIntegrationTests; + +[TestClass] +public class EnumEndPointIntegrationTest +{ + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + { + IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod); + } + + [TestMethod] + [RequiresApiAccess] + public void GetPaymentTypes_IntegrationTest() + { + ExecuteEnumSyncTest(x => x.GetPaymentTypes()); + } + + [TestMethod] + [RequiresApiAccess] + public void GetShippingCarriers_IntegrationTest() + { + ExecuteEnumSyncTest(x => x.GetShippingCarriers()); + } + + [TestMethod] + [RequiresApiAccess] + public void GetShipmentTypes_IntegrationTest() + { + ExecuteEnumSyncTest(x => x.GetShipmentTypes()); + } + + [TestMethod] + [RequiresApiAccess] + public void GetOrderStates_IntegrationTest() + { + ExecuteEnumSyncTest(x => x.GetOrderStates()); + } + + private void ExecuteEnumSyncTest(Func> endpointFunc) where T: struct, System.Enum + { + var apiEnumEntries = endpointFunc(IntegrationTestHelpers.ApiClient.Enums); + + // enum entries in api, but not in sdk + var missingSdkPaymentTypes = _getMissingSdkEnumEntries(apiEnumEntries); + + // enum entries in api and sdk, but with wrong number in sdk + var sdkEnumEntriesWithWrongNumber = _getSdkEnumEntriesWithWrongNumber(apiEnumEntries); + + // enum entries in sdk, but not in api + var deprecatedSdkPaymentTypes = _getDeprecatedSdkEnumEntries(apiEnumEntries); + + Assert.AreEqual(0, missingSdkPaymentTypes.Count); + Assert.AreEqual(0, sdkEnumEntriesWithWrongNumber.Count); + Assert.AreEqual(0, deprecatedSdkPaymentTypes.Count()); + } + + private List _getMissingSdkEnumEntries(List apiEnumEntries) where T: struct, System.Enum + { + var result = apiEnumEntries + .Where(apiEnumEntry => !Enum.TryParse(apiEnumEntry.Name, out T _)) + .OrderBy(x => x.Id) + .ToList(); + + if (result.Count > 0) + { + Console.WriteLine("Missing sdk enum entries:"); + foreach (var enumEntry in result) + { + Console.WriteLine($"{enumEntry.Name}: {enumEntry.Id}"); + } + } + + return result; + } + + private Dictionary _getSdkEnumEntriesWithWrongNumber(List apiEnumEntries) where T: struct, System.Enum + { + var result = apiEnumEntries + .Where(apiEnumEntry => Enum.TryParse(apiEnumEntry.Name, out T sdkEnumEntry)) + .Select(apiEnumEntry => + { + Enum.TryParse(apiEnumEntry.Name, out T sdkEnumEntry); + return new KeyValuePair(sdkEnumEntry, (apiEnumEntry.Id, Convert.ToInt32(sdkEnumEntry))); + }) + .Where(x => x.Value.Item1 != x.Value.Item2) + .OrderBy(x => x.Value.Item1) + .ToDictionary(x => x.Key, x => x.Value); + + + if (result.Count > 0) + { + Console.WriteLine("Sdk enum entries with wrong number:"); + foreach (var pair in result) + { + Console.WriteLine($"{pair.Key}: expected:{pair.Value.Item1}, actual:{pair.Value.Item2}"); + } + } + + return result; + } + + private IEnumerable _getDeprecatedSdkEnumEntries(List apiEnumEntries) where T: struct, System.Enum + { + var result = new List(); + foreach (var sdkEnumEntry in Enum.GetValues()) + { + var apiEnumEntry = apiEnumEntries.FirstOrDefault(x => x.Id == Convert.ToInt32(sdkEnumEntry)); + if (apiEnumEntry == null) + { + result.Add(sdkEnumEntry); + } + } + + if (result.Count > 0) + { + Console.WriteLine("Deprecated sdk enum entries:"); + foreach (var enumEntry in result) + { + Console.WriteLine($"{enumEntry}: {Convert.ToInt32(enumEntry)}"); + } + } + + return result; + } +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/EventEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/EventEndPointIntegrationTest.cs index 0c65c0b..8119c03 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/EventEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/EventEndPointIntegrationTest.cs @@ -5,10 +5,19 @@ namespace Billbee.Api.Client.Test.EndPointIntegrationTests; [TestClass] public class EventEndPointIntegrationTest { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + { + IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod); + } + [TestMethod] [RequiresApiAccess] public void GetEvents_IntegrationTest() { - Assert.Inconclusive(); + var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Events.GetEvents()); + Assert.IsTrue(result.Data.Count > 0); } } \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs index 5659a00..7dd3d62 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs @@ -17,20 +17,64 @@ public static List GetAll(Func> func) return result; } + + public static ApiPagedResult> GetAll(Func>> func) + { + string typeName = typeof(T).Name; + + Console.WriteLine(); + Console.WriteLine($"Get all {typeName}s..."); + + var result = func(); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Data); + Console.WriteLine($"Got {result.Data.Count} {typeName}s"); + + return result; + } + + public static ApiResult> GetAll(Func>> func) + { + string typeName = typeof(T).Name; + + Console.WriteLine(); + Console.WriteLine($"Get all {typeName}s..."); + + var result = func(); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Data); + Console.WriteLine($"Got {result.Data.Count} {typeName}s"); + + return result; + } + + public static T Create(Func func, TCreate newItem) + { + string typeName = typeof(T).Name; + + Console.WriteLine(); + Console.WriteLine($"Create new {typeName}..."); + + dynamic result = func(newItem); + Assert.IsNotNull(result); + Console.WriteLine($"{typeName} created, id={result.Id}"); - public static T Create(Func func) + return result; + } + + public static ApiResult CreateApiResult(Func> func, TCreate newItem, bool hasId = true) { string typeName = typeof(T).Name; Console.WriteLine(); Console.WriteLine($"Create new {typeName}..."); - dynamic result = func(); - var createdItem = result; - Assert.IsNotNull(createdItem); - Console.WriteLine($"{typeName} created, id={createdItem.Id}"); + dynamic result = func(newItem); + Assert.IsNotNull(result); + Assert.IsNotNull(result!.Data); + Console.WriteLine(hasId ? $"{typeName} created, id={result.Data.Id}" : $"{typeName} created"); - return createdItem; + return result; } public static T GetOne(Func func, dynamic id) @@ -48,7 +92,24 @@ public static T GetOne(Func func, dynamic id) return gotItem; } + + public static ApiResult GetOneApiResult(Func> func, dynamic id) + { + string typeName = typeof(T).Name; + + Console.WriteLine(); + Console.WriteLine($"Get {typeName} with id={id}..."); + + var result = func(id); + var gotItem = result; + Assert.IsNotNull(gotItem); + Assert.IsNotNull(gotItem.Data); + Assert.AreEqual(id.ToString(), gotItem.Data.Id.ToString()); + Console.WriteLine($"Got {typeName}, id={gotItem.Data.Id}"); + return gotItem; + } + public static void DeleteOne(Action func, dynamic id) { string typeName = typeof(T).Name; @@ -81,8 +142,19 @@ public static void GetOneExpectException(Func func, dynamic id) Assert.ThrowsException(() => func(id)); Console.WriteLine($"{typeName} could not be found (as expected)"); } + + public static void Put(Action func, dynamic item) + { + string typeName = typeof(T).Name; + + Console.WriteLine(); + Console.WriteLine($"Put {typeName} with id={item.Id}..."); - public static T Put(Func func, dynamic item) + func(item); + Console.WriteLine($"Done"); + } + + public static ApiResult Put(Func> func, dynamic item) { string typeName = typeof(T).Name; @@ -90,19 +162,30 @@ public static T Put(Func func, dynamic item) Console.WriteLine($"Put {typeName} with id={item.Id}..."); var updatedItem = func(item); - Console.WriteLine($"Got {typeName}, id={updatedItem.Id}"); + Assert.IsNotNull(updatedItem); + Assert.IsNotNull(updatedItem.Data); + Console.WriteLine($"Got {typeName}, id={updatedItem.Data.Id}"); return updatedItem; } - public static void Put(Action func, dynamic item) + public static ApiResult Patch(Func, ApiResult> func, dynamic id, Dictionary fieldsToPatch) { string typeName = typeof(T).Name; Console.WriteLine(); - Console.WriteLine($"Put {typeName} with id={item.Id}..."); + Console.WriteLine($"Patch {typeName} with id={id}..."); + Console.WriteLine($" Patched fields:"); + foreach (var fields in fieldsToPatch) + { + Console.WriteLine($" {fields.Key}: {fields.Value}"); + } - func(item); - Console.WriteLine($"Done"); + var patchedItem = func(id, fieldsToPatch); + Assert.IsNotNull(patchedItem); + Assert.IsNotNull(patchedItem.Data); + Console.WriteLine($"Got {typeName}, id={patchedItem.Data.Id}"); + + return patchedItem; } } \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/IntegrationTestHelpers.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/IntegrationTestHelpers.cs index 4a6077f..a8086aa 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/IntegrationTestHelpers.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/IntegrationTestHelpers.cs @@ -4,6 +4,8 @@ namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; public static class IntegrationTestHelpers { + private static ApiClient? _apiClient; + public static void CheckAccess(string testContextManagedType, string testContextManagedMethod) { if (!IntegrationTestSettings.RunIntegrationTests) @@ -14,8 +16,8 @@ public static void CheckAccess(string testContextManagedType, string testContext } var type = Assembly.GetExecutingAssembly().GetType(testContextManagedType); - var mi = type.GetMethod(testContextManagedMethod); - bool requiresApiAccess = mi.GetCustomAttributes().Any(); + var mi = type!.GetMethod(testContextManagedMethod); + bool requiresApiAccess = mi!.GetCustomAttributes().Any(); if (requiresApiAccess && !IntegrationTestSettings.AllowReadWriteAccessToBillbeeApi) { Assert.Inconclusive( @@ -27,20 +29,24 @@ public static ApiClient ApiClient { get { - var fiDll = new FileInfo(Assembly.GetExecutingAssembly().Location); - var di = new DirectoryInfo(Path.Combine(fiDll.Directory.FullName, "../../../")); - var path = Path.Combine(di.FullName, "config.prod"); - if (!File.Exists(path + ".json")) + if (_apiClient == null) { - Assert.Fail( - $"This test requires api-access, but the required config-file could not be found: '{path}.json'"); - } + var fiDll = new FileInfo(Assembly.GetExecutingAssembly().Location); + var di = new DirectoryInfo(Path.Combine(fiDll!.Directory!.FullName, "../../../")); + var path = Path.Combine(di.FullName, "config.prod"); + if (!File.Exists(path + ".json")) + { + Assert.Fail( + $"This test requires api-access, but the required config-file could not be found: '{path}.json'"); + } + _apiClient = new ApiClient(path, null, IntegrationTestSettings.AllowReadWriteAccessToBillbeeApi); + Assert.IsTrue(_apiClient.TestConfiguration()); + } + Thread.Sleep(500); // throttle api-calls when executing multiple tests - var apiClient = new ApiClient(path, null, IntegrationTestSettings.AllowReadWriteAccessToBillbeeApi); - Assert.IsTrue(apiClient.TestConfiguration()); - - return apiClient; + + return _apiClient; } } } \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/TestData.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/TestData.cs deleted file mode 100644 index 853e396..0000000 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/TestData.cs +++ /dev/null @@ -1,93 +0,0 @@ -using Billbee.Api.Client.Model; - -namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; - -public static class TestData -{ - public static CustomerAddress CustomerAddress => - new CustomerAddress - { - FirstName = "John", - LastName = "Doe", - Street = "Mustergasse", - Housenumber = "1", - Zip = "12345", - City = "Musterstadt", - AddressType = 1, - CountryCode = "DE", - CustomerId = 0 - }; - - public static Product Product => new Product - { - Title = new List - { - new MultiLanguageString() - { - Text = "the Title", - LanguageCode = "de" - } - }, - Type = 0, - Images = new List(), - InvoiceText = new List - { - new MultiLanguageString() - { - Text = "invoice text", - LanguageCode = "de" - } - }, - }; - - public static Webhook WebHook => new Webhook - { - Id = null, - WebHookUri = "https://webhook.site/5290627f-b5e3-4123-a715-26a721054617?noecho", - Secret = "4e4451af-63c5-44f4-a3c5-1dcf8617fc5c", - Description = "A simple description", - IsPaused = true, - Filters = new List { "order.created" }, - Headers = new Dictionary - { { "TestHeader", "TestHeaderValue" }, { "Another Testheader", "Another Value" } }, - Properties = new Dictionary() - }; - - public static CustomerForCreation Customer => new CustomerForCreation - { - Name = "John Doe", - Address = TestData.CustomerAddress, - Email = "john@doe.com", - DefaultMailAddress = new CustomerMetaData - { - Value = "john@doe.com", - TypeId = 1, - }, - Type = 0 - }; - - public static ShipmentWithLabel GetShipmentWithLabel(long orderId, string printerName, long productId, long providerId) => new ShipmentWithLabel - { - OrderId = orderId, - Dimension = new ShipmentDimensions - { - height = 10, - length = 10, - width = 10, - }, - ClientReference = "clientRef", - PrinterName = printerName, - ProductId = productId, - ProviderId = providerId, - ShipDate = DateTime.Now, - WeightInGram = 500, - ChangeStateToSend = true - }; - - public static CustomerAddress GetCustomerAddress(long? customerId) - { - var address = CustomerAddress; - address.CustomerId = customerId; - return address; - } -} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/SearchEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/SearchEndPointIntegrationTest.cs index 9ffff39..d2f4963 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/SearchEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/SearchEndPointIntegrationTest.cs @@ -1,14 +1,38 @@ -using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; +using Billbee.Api.Client.Model; +using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; +using Newtonsoft.Json; +using RestSharp.Serialization.Json; +using JsonSerializer = System.Text.Json.JsonSerializer; namespace Billbee.Api.Client.Test.EndPointIntegrationTests; [TestClass] public class SearchEndPointIntegrationTest { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + { + IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod); + } + [TestMethod] [RequiresApiAccess] public void SearchTerm_IntegrationTest() { - Assert.Inconclusive(); + var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); + Assert.IsNotNull(customer); + + var search = new Search + { + Term = "john", + Type = new List { "customer" } + }; + var result = IntegrationTestHelpers.ApiClient.Search.SearchTerm(search); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Data); + Assert.IsNotNull(result.Data.Customers); + Assert.IsTrue(result.Data.Customers.Count > 0); } } \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs index 1813655..f89d39e 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs @@ -1,123 +1,152 @@ using Billbee.Api.Client.Model; using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; -namespace Billbee.Api.Client.Test.EndPointIntegrationTests; - -[TestClass] -public class WebhookEndPointIntegrationTest +namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers { - public TestContext TestContext { get; set; } - private long _webhookCountBeforeTest = -1; - private long _webhookCoundExpectedAfterTest = -1; - - [TestInitialize] - public void TestInitialize() + public static partial class TestData { - IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod); - - var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); - Assert.IsNotNull(result); - - _webhookCountBeforeTest = result.Count; - _webhookCoundExpectedAfterTest = result.Count; + public static Webhook WebHook => new Webhook + { + Id = null, + WebHookUri = "https://webhook.site/5290627f-b5e3-4123-a715-26a721054617?noecho", + Secret = "4e4451af-63c5-44f4-a3c5-1dcf8617fc5c", + Description = "A simple description", + IsPaused = true, + Filters = new List { "order.created" }, + Headers = new Dictionary + { { "TestHeader", "TestHeaderValue" }, { "Another Testheader", "Another Value" } }, + Properties = new Dictionary() + }; } +} - [TestCleanup] - public void TestCleanup() +namespace Billbee.Api.Client.Test.EndPointIntegrationTests +{ + [TestClass] + public class WebhookEndPointIntegrationTest { - var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); - Assert.IsNotNull(result); + public TestContext TestContext { get; set; } + private long _countBeforeTest = -1; + private long _countExpectedAfterTest = -1; - Assert.AreEqual(_webhookCoundExpectedAfterTest, result.Count); - } + [TestInitialize] + public void TestInitialize() + { + IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod); - [TestMethod] - [RequiresApiAccess] - public void GetFilters_IntegrationTest() - { - CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetFilters()); - } + var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); + _countBeforeTest = result.Count; + _countExpectedAfterTest = result.Count; + } - [TestMethod] - [RequiresApiAccess] - public void GetWebhooks_IntegrationTest() - { - CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); - } + [TestCleanup] + public void TestCleanup() + { + var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); + Assert.AreEqual(_countExpectedAfterTest, result.Count); + } - [TestMethod] - [RequiresApiAccess] - public void GetWebhook_IntegrationTest() - { - var webhook = CrudHelpers.Create(() => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(TestData.WebHook)); - CrudHelpers.GetOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhook(id), webhook.Id); - - // cleanup - CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.DeleteWebhook(id), webhook.Id); - } + [TestMethod] + [RequiresApiAccess] + public void GetFilters_IntegrationTest() + { + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetFilters()); + } - [TestMethod] - [RequiresApiAccess] - public void CreateWebhook_IntegrationTest() - { - Webhook webhook = CrudHelpers.Create(() => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(TestData.WebHook)); - Assert.AreEqual(TestData.WebHook.WebHookUri, webhook.WebHookUri); - - // cleanup - CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.DeleteWebhook(id), webhook.Id); - } + [TestMethod] + [RequiresApiAccess] + public void GetWebhooks_IntegrationTest() + { + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); + } - [TestMethod] - [RequiresApiAccess] - public void DeleteAllWebhooks_IntegrationTest() - { - if (_webhookCountBeforeTest > 0) + [TestMethod] + [RequiresApiAccess] + public void GetWebhook_IntegrationTest() { - Assert.Inconclusive("The connected account contains webhooks. Cannot execute this test-method, because it would delete all existing webhooks."); + var webhook = CrudHelpers.Create(w => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(w), + TestData.WebHook); + CrudHelpers.GetOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhook(id), webhook.Id); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.DeleteWebhook(id), + webhook.Id); } - - CrudHelpers.Create(() => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(TestData.WebHook)); - CrudHelpers.Create(() => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(TestData.WebHook)); - var webhooks = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); - Assert.AreEqual(2, webhooks.Count); - - CrudHelpers.DeleteAll(() => IntegrationTestHelpers.ApiClient.Webhooks.DeleteAllWebhooks()); - - webhooks = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); - Assert.AreEqual(0, webhooks.Count); - - _webhookCoundExpectedAfterTest = 0; - } - [TestMethod] - [RequiresApiAccess] - public void DeleteWebhook_IntegrationTest() - { - Webhook webhook = CrudHelpers.Create(() => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(TestData.WebHook)); - var webhooks = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); - Assert.IsTrue(webhooks.Count > 0); + [TestMethod] + [RequiresApiAccess] + public void CreateWebhook_IntegrationTest() + { + var webhook = CrudHelpers.Create(w => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(w), + TestData.WebHook); + Assert.AreEqual(TestData.WebHook.WebHookUri, webhook.WebHookUri); - var webhookToDelete = webhook; - Assert.IsNotNull(webhookToDelete); - CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.DeleteWebhook(id), webhookToDelete.Id); + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.DeleteWebhook(id), + webhook.Id); + } - CrudHelpers.GetOneExpectException((id) => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhook(id), webhookToDelete.Id); - } + [TestMethod] + [RequiresApiAccess] + public void DeleteAllWebhooks_IntegrationTest() + { + if (_countBeforeTest > 0) + { + Assert.Inconclusive( + "The connected account contains webhooks. Cannot execute this test-method, because it would delete all existing webhooks."); + } - [TestMethod] - [RequiresApiAccess] - public void UpdateWebhook_IntegrationTest() - { - Webhook webhook = CrudHelpers.Create(() => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(TestData.WebHook)); - webhook = CrudHelpers.GetOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhook(id), webhook.Id); - - webhook.Description = "modified"; - CrudHelpers.Put((webhook) => IntegrationTestHelpers.ApiClient.Webhooks.UpdateWebhook(webhook), webhook); - - webhook = CrudHelpers.GetOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhook(id), webhook.Id); - Assert.AreEqual("modified", webhook.Description); - - // cleanup - CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.DeleteWebhook(id), webhook.Id); + CrudHelpers.Create(w => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(w), TestData.WebHook); + CrudHelpers.Create(w => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(w), TestData.WebHook); + var webhooks = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); + Assert.AreEqual(2, webhooks.Count); + + CrudHelpers.DeleteAll(() => IntegrationTestHelpers.ApiClient.Webhooks.DeleteAllWebhooks()); + + webhooks = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); + Assert.AreEqual(0, webhooks.Count); + + _countExpectedAfterTest = 0; + } + + [TestMethod] + [RequiresApiAccess] + public void DeleteWebhook_IntegrationTest() + { + var webhook = CrudHelpers.Create(w => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(w), + TestData.WebHook); + var webhooks = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); + Assert.IsTrue(webhooks.Count > 0); + + var webhookToDelete = webhook; + Assert.IsNotNull(webhookToDelete); + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.DeleteWebhook(id), + webhookToDelete.Id); + + CrudHelpers.GetOneExpectException((id) => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhook(id), + webhookToDelete.Id); + } + + [TestMethod] + [RequiresApiAccess] + public void UpdateWebhook_IntegrationTest() + { + var webhook = CrudHelpers.Create(w => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(w), + TestData.WebHook); + webhook = CrudHelpers.GetOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhook(id), + webhook.Id); + + webhook.Description = "modified"; + CrudHelpers.Put((webhook) => IntegrationTestHelpers.ApiClient.Webhooks.UpdateWebhook(webhook), + webhook); + + webhook = CrudHelpers.GetOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhook(id), + webhook.Id); + Assert.AreEqual("modified", webhook.Description); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Webhooks.DeleteWebhook(id), + webhook.Id); + } } } \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointTests/SearchEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/SearchEndPointTest.cs index 90a8b3a..6a6020c 100644 --- a/Billbee.Api.Client.Test/EndPointTests/SearchEndPointTest.cs +++ b/Billbee.Api.Client.Test/EndPointTests/SearchEndPointTest.cs @@ -27,6 +27,7 @@ public void SearchTermTest() { var uut = new SearchEndPoint(restClient); var result = uut.SearchTerm(search); + Assert.IsNotNull(result); Assert.IsNotNull(result.Data); }); } From f825bfcbe49103180e46f4c944e233e8523493dc Mon Sep 17 00:00:00 2001 From: Benjamin Gottschalk Date: Thu, 4 Aug 2022 10:48:11 +0200 Subject: [PATCH 04/11] added integration tests --- .../Helpers/CrudHelpers.cs | 13 +- .../OrderEndPointIntegrationTest.cs | 155 +++++++ .../ProductEndPointIntegrationTest.cs | 432 ++++++++++++++++++ .../ShipmentEndPointIntegrationTest.cs | 140 ++++++ 4 files changed, 737 insertions(+), 3 deletions(-) create mode 100644 Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs create mode 100644 Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs create mode 100644 Billbee.Api.Client.Test/EndPointIntegrationTests/ShipmentEndPointIntegrationTest.cs diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs index 7dd3d62..3356be5 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs @@ -93,7 +93,7 @@ public static T GetOne(Func func, dynamic id) return gotItem; } - public static ApiResult GetOneApiResult(Func> func, dynamic id) + public static ApiResult GetOneApiResult(Func> func, dynamic id, bool hasId = true) { string typeName = typeof(T).Name; @@ -104,8 +104,15 @@ public static ApiResult GetOneApiResult(Func> func, var gotItem = result; Assert.IsNotNull(gotItem); Assert.IsNotNull(gotItem.Data); - Assert.AreEqual(id.ToString(), gotItem.Data.Id.ToString()); - Console.WriteLine($"Got {typeName}, id={gotItem.Data.Id}"); + if (hasId) + { + Assert.AreEqual(id.ToString(), gotItem.Data.Id.ToString()); + Console.WriteLine($"Got {typeName}, id={gotItem.Data.Id}"); + } + else + { + Console.WriteLine($"Got {typeName}"); + } return gotItem; } diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs new file mode 100644 index 0000000..26d8ac2 --- /dev/null +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs @@ -0,0 +1,155 @@ +using Billbee.Api.Client.Model; +using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; + +namespace Billbee.Api.Client.Test.EndPointIntegrationTests; + +[TestClass] +public class OrderEndPointIntegrationTest +{ + public TestContext TestContext { get; set; } + private long _countExpectedAfterTest = -1; + + [TestInitialize] + public void TestInitialize() + { + IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod); + + var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Orders.GetOrderList(page: 1, pageSize: int.MaxValue)); + _countExpectedAfterTest = result.Data.Count; + } + + [TestCleanup] + public void TestCleanup() + { + var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Orders.GetOrderList(page: 1, pageSize: int.MaxValue)); + Assert.AreEqual(_countExpectedAfterTest, result.Data.Count); + } + + [TestMethod] + [RequiresApiAccess] + public void GetLayouts_IntegrationTest() + { + var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Orders.GetLayouts()); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Data); + } + + [TestMethod] + [RequiresApiAccess] + public void GetOrder_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void GetPatchableFields_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void PatchOrder_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void GetOrderByExternalReference_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void GetOrderByExternalIdAndPartner_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void GetOrderList_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void GetInvoiceList_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void PostNewOrder_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void AddTags_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void UpdateTags_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void AddShipment_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void CreateDeliveryNote_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void CreateInvoice_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void ChangeOrderState_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void SendMailForOrder_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void CreateEventAtOrder_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void ParsePlaceholders_IntegrationTest() + { + Assert.Inconclusive(); + } +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs new file mode 100644 index 0000000..0183179 --- /dev/null +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs @@ -0,0 +1,432 @@ +using System.Net.Http.Headers; +using Billbee.Api.Client.Model; +using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; + +namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers +{ + public static partial class TestData + { + public static Product Product => new Product + { + Title = new List + { + new MultiLanguageString() + { + Text = "the Title", + LanguageCode = "de" + } + }, + Type = 0, + Images = new List(), + InvoiceText = new List + { + new MultiLanguageString() + { + Text = "invoice text", + LanguageCode = "de" + } + }, + SKU = "4711", + }; + + public static ArticleImage ArticleImage => new ArticleImage + { + Position = 1 + }; + + public static ArticleImage GetArticleImage(long productId) + { + var ret = ArticleImage; + ret.ArticleId = productId; + return ret; + } + } +} + +namespace Billbee.Api.Client.Test.EndPointIntegrationTests +{ + [TestClass] + public class ProductEndPointIntegrationTest + { + public TestContext TestContext { get; set; } + private long _countExpectedAfterTest = -1; + + [TestInitialize] + public void TestInitialize() + { + IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod); + + var result = + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetProducts(1, int.MaxValue)); + _countExpectedAfterTest = result.Data.Count; + } + + [TestCleanup] + public void TestCleanup() + { + var result = + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetProducts(1, int.MaxValue)); + Assert.AreEqual(_countExpectedAfterTest, result.Data.Count); + } + + [TestMethod] + [RequiresApiAccess] + public void GetCategories_IntegrationTest() + { + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetCategories()); + } + + [TestMethod] + [RequiresApiAccess] + public void AddProduct_IntegrationTest() + { + var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), + TestData.Product); + var product = result.Data; + Assert.IsNotNull(product); + Assert.IsNotNull(product.Id); + Assert.AreEqual(TestData.Product.Title.First().Text, product.Title.First().Text); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), + product.Id); + } + + [TestMethod] + [RequiresApiAccess] + public void DeleteProduct_IntegrationTest() + { + var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), + TestData.Product); + var createdProduct = result.Data; + Assert.IsNotNull(createdProduct); + Assert.IsNotNull(createdProduct.Id); + + CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Products.GetProduct(id), + createdProduct.Id.ToString()!); + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), + createdProduct.Id); + CrudHelpers.GetOneExpectException((id) => IntegrationTestHelpers.ApiClient.Products.GetProduct(id), + createdProduct.Id.ToString()!); + } + + [TestMethod] + [RequiresApiAccess] + public void GetStocks_IntegrationTest() + { + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetStocks()); + } + + [TestMethod] + [RequiresApiAccess] + public void UpdateStockMultiple_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void UpdateStock_IntegrationTest() + { + var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), + TestData.Product); + var createdProduct = result.Data; + Assert.IsNotNull(createdProduct); + Assert.IsNotNull(createdProduct.Id); + + Assert.AreEqual(null, createdProduct.StockCurrent); + + var updateStock = new UpdateStock + { + OldQuantity = 0, + NewQuantity = 1, + Sku = TestData.Product.SKU, + Reason = "Wareneingang" + }; + var updateStockResult = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.UpdateStock(x), updateStock, false); + Console.WriteLine($"CurrentStock={updateStockResult.Data.CurrentStock}"); + + var updatedProductResult = CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Products.GetProduct(id), + createdProduct.Id.ToString()!); + Assert.AreEqual(1, updatedProductResult.Data.StockCurrent); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), + createdProduct.Id); + } + + [TestMethod] + [RequiresApiAccess] + public void GetReservedAmount_IntegrationTest() + { + var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), + TestData.Product); + var createdProduct = result.Data; + Assert.IsNotNull(createdProduct); + Assert.IsNotNull(createdProduct.Id); + + var reservedResult = CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Products.GetReservedAmount(id), + createdProduct.Id.ToString()!, false); + Console.WriteLine($"ReservedAmount={reservedResult.Data.ReservedAmount}"); + Assert.AreEqual(0M, reservedResult.Data.ReservedAmount); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), + createdProduct.Id); + } + + [TestMethod] + [RequiresApiAccess] + public void UpdateStockCode_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void GetProducts_IntegrationTest() + { + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetProducts(1, int.MaxValue)); + } + + [TestMethod] + [RequiresApiAccess] + public void GetProduct_IntegrationTest() + { + var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), + TestData.Product); + var createdProduct = result.Data; + Assert.IsNotNull(createdProduct); + Assert.IsNotNull(createdProduct.Id); + + CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Products.GetProduct(id), + createdProduct.Id.ToString()!); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), + createdProduct.Id); + } + + [TestMethod] + [RequiresApiAccess] + public void GetCustomFields_IntegrationTest() + { + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetCustomFields(1, int.MaxValue)); + } + + [TestMethod] + [RequiresApiAccess] + public void GetCustomField_IntegrationTest() + { + var customField = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetCustomFields(1, int.MaxValue)).Data.FirstOrDefault(); + Assert.IsNotNull(customField); + + CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Products.GetCustomField(id), + customField!.Id!.Value); + } + + [TestMethod] + [RequiresApiAccess] + public void GetPatchableProductFields_IntegrationTest() + { + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetPatchableProductFields()); + } + + [TestMethod] + [RequiresApiAccess] + public void PatchArticle_IntegrationTest() + { + Assert.Inconclusive(); + } + + [TestMethod] + [RequiresApiAccess] + public void GetArticleImages_IntegrationTest() + { + var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), + TestData.Product); + var createdProduct = result.Data; + Assert.IsNotNull(createdProduct); + Assert.IsNotNull(createdProduct.Id); + + var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); + CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), + articleImage); + + var imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct!.Id!.Value)); + Assert.AreEqual(1, imagesResult.Data.Count); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), + createdProduct!.Id!.Value); + } + + [TestMethod] + [RequiresApiAccess] + public void GetArticleImage_IntegrationTest() + { + var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), + TestData.Product); + var createdProduct = result.Data; + Assert.IsNotNull(createdProduct); + Assert.IsNotNull(createdProduct.Id); + + var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); + var resultImage = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), + articleImage); + + CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Products.GetArticleImage(id), + resultImage.Data.Id); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), + createdProduct!.Id!.Value); + } + + [TestMethod] + [RequiresApiAccess] + public void AddArticleImage_IntegrationTest() + { + var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), + TestData.Product); + var createdProduct = result.Data; + Assert.IsNotNull(createdProduct); + Assert.IsNotNull(createdProduct.Id); + + var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); + var resultImage = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), + articleImage); + Assert.AreEqual((byte)1, resultImage.Data.Position); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), + createdProduct!.Id!.Value); + } + + [TestMethod] + [RequiresApiAccess] + public void UpdateArticleImage_IntegrationTest() + { + var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), + TestData.Product); + var createdProduct = result.Data; + Assert.IsNotNull(createdProduct); + Assert.IsNotNull(createdProduct.Id); + + var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); + var resultImage = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), + articleImage); + Assert.AreEqual((byte)1, resultImage.Data.Position); + + var updatedArticleImage = resultImage.Data; + updatedArticleImage.Position = 2; + var updateResult = CrudHelpers.Put(x => IntegrationTestHelpers.ApiClient.Products.UpdateArticleImage(x), + updatedArticleImage); + Assert.AreEqual((byte)2, updateResult.Data.Position); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), + createdProduct!.Id!.Value); + } + + [TestMethod] + [RequiresApiAccess] + public void AddMultipleArticleImages_IntegrationTest() + { + var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), + TestData.Product); + var createdProduct = result.Data; + Assert.IsNotNull(createdProduct); + Assert.IsNotNull(createdProduct.Id); + + var imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct!.Id!.Value)); + Assert.AreEqual(0, imagesResult.Data.Count); + + var articleImages = new List + { + TestData.GetArticleImage(createdProduct.Id.Value), + TestData.GetArticleImage(createdProduct.Id.Value), + TestData.GetArticleImage(createdProduct.Id.Value) + }; + Console.WriteLine(); + Console.WriteLine($"Adding multiple ArticleImages (3)"); + IntegrationTestHelpers.ApiClient.Products.AddMultipleArticleImages(createdProduct.Id.Value, articleImages); + Console.WriteLine($"Added multiple ArticleImages"); + + imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct!.Id!.Value)); + Assert.AreEqual(3, imagesResult.Data.Count); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), + createdProduct!.Id!.Value); + } + + [TestMethod] + [RequiresApiAccess] + public void DeleteArticleImage_IntegrationTest() + { + var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), + TestData.Product); + var createdProduct = result.Data; + Assert.IsNotNull(createdProduct); + Assert.IsNotNull(createdProduct.Id); + + var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); + var resultImage = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), + articleImage); + + var imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct!.Id!.Value)); + Assert.AreEqual(1, imagesResult.Data.Count); + + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteArticleImage(id), + resultImage.Data.Id); + + imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct!.Id!.Value)); + Assert.AreEqual(0, imagesResult.Data.Count); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), + createdProduct!.Id!.Value); + } + + [TestMethod] + [RequiresApiAccess] + public void DeleteMultipleArticleImages_IntegrationTest() + { + var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), + TestData.Product); + var createdProduct = result.Data; + Assert.IsNotNull(createdProduct); + Assert.IsNotNull(createdProduct.Id); + + var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); + var resultImage1 = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), + articleImage); + var resultImage2 = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), + articleImage); + var resultImage3 = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), + articleImage); + + var imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct!.Id!.Value)); + Assert.AreEqual(3, imagesResult.Data.Count); + + Console.WriteLine(); + Console.WriteLine($"Delete multiple ArticleImages with Ids={resultImage1.Data.Id},{resultImage2.Data.Id}"); + var deleteResult = IntegrationTestHelpers.ApiClient.Products.DeleteMultipleArticleImages(new List + { resultImage1.Data.Id, resultImage2.Data.Id }); + Console.WriteLine($"Deleted multiple ArticleImages"); + Assert.IsNotNull(deleteResult); + Assert.IsNotNull(deleteResult.Data); + Assert.AreEqual(2, deleteResult.Data.Deleted.Count); + Assert.AreEqual(0, deleteResult.Data.NotFound.Count); + + imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct!.Id!.Value)); + Assert.AreEqual(1, imagesResult.Data.Count); + Assert.IsTrue(imagesResult.Data.Any(x => x.Id == resultImage3.Data.Id)); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), + createdProduct!.Id!.Value); + } + } +} \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/ShipmentEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/ShipmentEndPointIntegrationTest.cs new file mode 100644 index 0000000..ced68a4 --- /dev/null +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/ShipmentEndPointIntegrationTest.cs @@ -0,0 +1,140 @@ +using Billbee.Api.Client.Model; +using Billbee.Api.Client.Model.Rechnungsdruck.WebApp.Model.Api; +using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; + +namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers +{ + public static partial class TestData + { + public static ShipmentWithLabel GetShipmentWithLabel(long orderId, string printerName, long productId, long providerId) => new ShipmentWithLabel + { + OrderId = orderId, + Dimension = new ShipmentDimensions + { + height = 10, + length = 10, + width = 10, + }, + ClientReference = "clientRef", + PrinterName = printerName, + ProductId = productId, + ProviderId = providerId, + ShipDate = DateTime.Now, + WeightInGram = 500, + ChangeStateToSend = true, + }; + + public static PostShipment GetPostShipment(string printerName, string providerName, byte shippingCarrier, string productCode) => + new PostShipment + { + Dimension = new ShipmentDimensions + { + height = 10, + length = 10, + width = 10, + }, + ClientReference = "clientRef", + PrinterName = printerName, + ProviderName = providerName, + ShipDate = DateTime.Now, + WeightInGram = 500, + shippingCarrier = shippingCarrier, + Services = new List(), + ReceiverAddress = new ShipmentAddress + { + FirstName = "John", + LastName = "Doe", + Street = "Teststraße", + Housenumber = "1", + Zip = "12345", + City = "Teststadt", + CountryCode = "DE", + Email = "john@doe.com", + Telephone = "0123456789", + }, + OrderSum = 10.0M, + OrderCurrencyCode = "EUR", + TotalNet = 8.40M, + ProductCode = productCode, + }; + } +} + +namespace Billbee.Api.Client.Test.EndPointIntegrationTests +{ + [TestClass] + public class ShipmentEndPointIntegrationTest + { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + { + IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod); + } + + [TestMethod] + [RequiresApiAccess] + public void GetShipments_IntegrationTest() + { + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Shipment.GetShipments()); + } + + [TestMethod] + [RequiresApiAccess] + public void GetShippingProvider_IntegrationTest() + { + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Shipment.GetShippingProvider()); + } + + [TestMethod] + [RequiresApiAccess] + public void ShipOrderWithLabel_IntegrationTest() + { + var provider = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Shipment.GetShippingProvider()) + .First(); + var printer = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.CloudStorages.GetCloudStorageList()) + .Data + .First(x => x.UsedAsPrinter); + + var orderId = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Orders.GetOrderList()).Data.First() + .BillBeeOrderId; + var providerId = provider.id; + var productId = provider.products.First().id; + + var shipmentWithLabel = TestData.GetShipmentWithLabel(orderId.Value, printer.Name, productId, providerId); + var result = CrudHelpers.CreateApiResult( + s => IntegrationTestHelpers.ApiClient.Shipment.ShipOrderWithLabel(s), shipmentWithLabel, false); + Assert.AreEqual(shipmentWithLabel.OrderId, result.Data.OrderId); + } + + [TestMethod] + [RequiresApiAccess] + public void PostShipment_IntegrationTest() + { + var provider = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Shipment.GetShippingProvider()) + .First(); + var printer = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.CloudStorages.GetCloudStorageList()) + .Data + .First(x => x.UsedAsPrinter); + var carrier = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Shipment.GetShippingCarriers()) + .First(); + var carriers = IntegrationTestHelpers.ApiClient.Shipment.GetShippingCarriers().Select(x => $"{x.Id}:{x.Name}"); + Console.WriteLine(carriers); + + var postShipment = TestData.GetPostShipment(printer.Name, provider.name, carrier.Id, provider.products.First().productName); + var shipment = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Shipment.PostShipment(x), + postShipment, false); + Console.WriteLine($"Shipment created, ShippingId={shipment.Data.ShippingId}"); + + Assert.IsFalse(string.IsNullOrWhiteSpace(shipment.Data.ShippingId)); + } + + [TestMethod] + [RequiresApiAccess] + public void GetShippingCarriers_IntegrationTest() + { + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Shipment.GetShippingCarriers()); + } + } +} \ No newline at end of file From 8c8f36bad0d36ade992f927d9113910863d41df6 Mon Sep 17 00:00:00 2001 From: Benjamin Gottschalk Date: Thu, 4 Aug 2022 12:08:28 +0200 Subject: [PATCH 05/11] fix merge --- Billbee.Api.Client/Endpoint/WebhookEndPoint.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Billbee.Api.Client/Endpoint/WebhookEndPoint.cs b/Billbee.Api.Client/Endpoint/WebhookEndPoint.cs index 598f9bc..d59889b 100644 --- a/Billbee.Api.Client/Endpoint/WebhookEndPoint.cs +++ b/Billbee.Api.Client/Endpoint/WebhookEndPoint.cs @@ -78,7 +78,7 @@ public Webhook CreateWebhook(Webhook webhook) throw new InvalidValueException($"Property secret is malformed. It must meet the following criteria: Not null or whitespaces only, between 32 and 64 charackters long."); } - _restClient.Post("/webhooks", webhook); + return _restClient.Post("/webhooks", webhook); } } } From 632a3f430affe80dbb81aca84e333a1fe9046f87 Mon Sep 17 00:00:00 2001 From: Benjamin Gottschalk Date: Thu, 4 Aug 2022 12:26:19 +0200 Subject: [PATCH 06/11] fixed warnings --- Billbee.Api.Client.Demo/Program.cs | 12 ++++++------ Billbee.Api.Client.Test/ApiClientTest.cs | 3 +++ Billbee.Api.Client.Test/ApiSyncTest.cs | 2 +- .../AutomaticProvisionEndPointIntegrationTest.cs | 2 ++ .../CloudStoragesEndPointIntegrationTest.cs | 2 ++ .../CustomerAddressesEndPointIntegrationTest.cs | 6 +++++- .../CustomerEndPointIntegrationTest.cs | 5 +++++ .../EnumEndPointIntegrationTest.cs | 2 ++ .../EventEndPointIntegrationTest.cs | 2 ++ .../EndPointIntegrationTests/Helpers/CrudHelpers.cs | 4 ++-- .../OrderEndPointIntegrationTest.cs | 2 ++ .../ProductEndPointIntegrationTest.cs | 2 ++ .../SearchEndPointIntegrationTest.cs | 2 ++ .../ShipmentEndPointIntegrationTest.cs | 3 +++ .../WebhookEndPointIntegrationTest.cs | 2 ++ 15 files changed, 41 insertions(+), 10 deletions(-) diff --git a/Billbee.Api.Client.Demo/Program.cs b/Billbee.Api.Client.Demo/Program.cs index 2aa0218..72bda32 100644 --- a/Billbee.Api.Client.Demo/Program.cs +++ b/Billbee.Api.Client.Demo/Program.cs @@ -13,7 +13,7 @@ namespace Billbee.Api.Client.Demo /// /// To use this demo, you have to enable the API in your account. Please refer to https://www.billbee.de/api/ for further information. /// - internal class Program + internal static class Program { private static int Main() { @@ -91,7 +91,7 @@ private static int Main() // Requesting a specific webhook if (webHooks.Count > 0) { - var webhook = client.Webhooks.GetWebhook(webHooks.FirstOrDefault().Id); + var webhook = client.Webhooks.GetWebhook(webHooks.FirstOrDefault()!.Id); // Updating webhook webhook.IsPaused = false; @@ -117,7 +117,7 @@ private static int Main() if (customFields.Data.Count > 0) { - var firstCustomField = client.Products.GetCustomField(customFields.Data.First().Id.Value); + var firstCustomField = client.Products.GetCustomField(customFields.Data.First()!.Id!.Value); } // Artificial brake to prevent throttling @@ -177,7 +177,7 @@ private static int Main() if (products.Data.Count > 0) { - var articleId = products.Data.First().Id.Value; + var articleId = products.Data.First()!.Id!.Value; var articleImages = client.Products.GetArticleImages(articleId); @@ -221,7 +221,7 @@ private static int Main() if (customers.Data.Count > 0) { - var customer = client.Customer.GetCustomer(customers.Data.First().Id.Value); + var customer = client.Customer.GetCustomer(customers.Data.First()!.Id!.Value); customer.Data.Name = "Tobias Tester"; @@ -230,7 +230,7 @@ private static int Main() // Artificial brake to prevent throttling Thread.Sleep(1000); - var customerOrder = client.Customer.GetOrdersForCustomer(customer.Data.Id.Value, 1, 50); + var customerOrder = client.Customer.GetOrdersForCustomer(customer.Data.Id!.Value, 1, 50); var customerAddresses = client.Customer.GetAddressesForCustomer(customer.Data.Id.Value, 1, 50); } diff --git a/Billbee.Api.Client.Test/ApiClientTest.cs b/Billbee.Api.Client.Test/ApiClientTest.cs index 4680df3..73403fd 100644 --- a/Billbee.Api.Client.Test/ApiClientTest.cs +++ b/Billbee.Api.Client.Test/ApiClientTest.cs @@ -59,6 +59,8 @@ public void InitWithConfigTest() public void InitWithConfigFileTest() { var fiDll = new FileInfo(Assembly.GetExecutingAssembly().Location); + Assert.IsNotNull(fiDll); + Assert.IsNotNull(fiDll.Directory); var path = Path.Combine(fiDll.Directory.FullName, "../../../config.test"); var uut = new ApiClient(path); @@ -117,6 +119,7 @@ private void CheckTestMethods(string testClassPostfix, string testMethodPostfix) var testTypeName = clientType.Name + testClassPostfix; var testType = testTypes.FirstOrDefault(t => t.IsClass && t.IsPublic && t.Name == testTypeName && t.GetCustomAttributes().Any(a => a is TestClassAttribute)); + Assert.IsNotNull(testType); var bindingFlags = BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance; var clientMethods = clientType.GetMethods(bindingFlags); diff --git a/Billbee.Api.Client.Test/ApiSyncTest.cs b/Billbee.Api.Client.Test/ApiSyncTest.cs index 0d01679..0b60bec 100644 --- a/Billbee.Api.Client.Test/ApiSyncTest.cs +++ b/Billbee.Api.Client.Test/ApiSyncTest.cs @@ -13,7 +13,7 @@ public class ApiSyncTest [DebuggerDisplay("{Path}:{HttpOperation}")] public class ApiOperation { - public string Path { get; set; } + public string Path { get; set; } = null!; public HttpOperation HttpOperation { get; set; } public override string ToString() => $"{Path}:{HttpOperation}"; diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/AutomaticProvisionEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/AutomaticProvisionEndPointIntegrationTest.cs index f78020e..679fae1 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/AutomaticProvisionEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/AutomaticProvisionEndPointIntegrationTest.cs @@ -37,7 +37,9 @@ namespace Billbee.Api.Client.Test.EndPointIntegrationTests [TestClass] public class AutomaticProvisionEndPointIntegrationTest { +#pragma warning disable CS8618 public TestContext TestContext { get; set; } +#pragma warning restore CS8618 [TestInitialize] public void TestInitialize() diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/CloudStoragesEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/CloudStoragesEndPointIntegrationTest.cs index 78f1410..bec124a 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/CloudStoragesEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/CloudStoragesEndPointIntegrationTest.cs @@ -5,7 +5,9 @@ namespace Billbee.Api.Client.Test.EndPointIntegrationTests; [TestClass] public class CloudStoragesEndPointIntegrationTest { +#pragma warning disable CS8618 public TestContext TestContext { get; set; } +#pragma warning restore CS8618 [TestInitialize] public void TestInitialize() diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs index 22f2779..38c362e 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs @@ -33,7 +33,9 @@ namespace Billbee.Api.Client.Test.EndPointIntegrationTests [TestClass] public class CustomerAddressesEndPointIntegrationTest { +#pragma warning disable CS8618 public TestContext TestContext { get; set; } +#pragma warning restore CS8618 [TestInitialize] public void TestInitialize() @@ -45,7 +47,9 @@ public void TestInitialize() [RequiresApiAccess] public void GetCustomerAddresses_IntegrationTest() { - CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.CustomerAddresses.GetCustomerAddresses(1, 5)); + var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.CustomerAddresses.GetCustomerAddresses(1, 5)); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Data); } [TestMethod] diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs index 5c19254..87e6718 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs @@ -20,7 +20,9 @@ namespace Billbee.Api.Client.Test.EndPointIntegrationTests [TestClass] public class CustomerEndPointIntegrationTest { +#pragma warning disable CS8618 public TestContext TestContext { get; set; } +#pragma warning restore CS8618 [TestInitialize] public void TestInitialize() @@ -67,6 +69,9 @@ public void GetCustomerAddress_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); + Assert.IsNotNull(customer); + Assert.IsNotNull(customer.Data); + Assert.IsNotNull(customer.Data.Id); var address = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Customer.GetAddressesForCustomer(customer.Data.Id.Value, 1, 5)) diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/EnumEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/EnumEndPointIntegrationTest.cs index e94461b..790d9ea 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/EnumEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/EnumEndPointIntegrationTest.cs @@ -8,7 +8,9 @@ namespace Billbee.Api.Client.Test.EndPointIntegrationTests; [TestClass] public class EnumEndPointIntegrationTest { +#pragma warning disable CS8618 public TestContext TestContext { get; set; } +#pragma warning restore CS8618 [TestInitialize] public void TestInitialize() diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/EventEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/EventEndPointIntegrationTest.cs index 8119c03..2682f06 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/EventEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/EventEndPointIntegrationTest.cs @@ -5,7 +5,9 @@ namespace Billbee.Api.Client.Test.EndPointIntegrationTests; [TestClass] public class EventEndPointIntegrationTest { +#pragma warning disable CS8618 public TestContext TestContext { get; set; } +#pragma warning restore CS8618 [TestInitialize] public void TestInitialize() diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs index 3356be5..8f85447 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs @@ -48,7 +48,7 @@ public static ApiResult> GetAll(Func>> func) return result; } - public static T Create(Func func, TCreate newItem) + public static T Create(Func func, TCreate newItem) where T: notnull { string typeName = typeof(T).Name; @@ -57,7 +57,7 @@ public static T Create(Func func, TCreate newItem) dynamic result = func(newItem); Assert.IsNotNull(result); - Console.WriteLine($"{typeName} created, id={result.Id}"); + Console.WriteLine($"{typeName} created, id={result!.Id}"); return result; } diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs index 26d8ac2..b9f3c21 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs @@ -6,7 +6,9 @@ namespace Billbee.Api.Client.Test.EndPointIntegrationTests; [TestClass] public class OrderEndPointIntegrationTest { +#pragma warning disable CS8618 public TestContext TestContext { get; set; } +#pragma warning restore CS8618 private long _countExpectedAfterTest = -1; [TestInitialize] diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs index 0183179..6c4e111 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs @@ -48,7 +48,9 @@ namespace Billbee.Api.Client.Test.EndPointIntegrationTests [TestClass] public class ProductEndPointIntegrationTest { +#pragma warning disable CS8618 public TestContext TestContext { get; set; } +#pragma warning restore CS8618 private long _countExpectedAfterTest = -1; [TestInitialize] diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/SearchEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/SearchEndPointIntegrationTest.cs index d2f4963..5a41ffd 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/SearchEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/SearchEndPointIntegrationTest.cs @@ -9,7 +9,9 @@ namespace Billbee.Api.Client.Test.EndPointIntegrationTests; [TestClass] public class SearchEndPointIntegrationTest { +#pragma warning disable CS8618 public TestContext TestContext { get; set; } +#pragma warning restore CS8618 [TestInitialize] public void TestInitialize() diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/ShipmentEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/ShipmentEndPointIntegrationTest.cs index ced68a4..c9e6183 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/ShipmentEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/ShipmentEndPointIntegrationTest.cs @@ -65,7 +65,9 @@ namespace Billbee.Api.Client.Test.EndPointIntegrationTests [TestClass] public class ShipmentEndPointIntegrationTest { +#pragma warning disable CS8618 public TestContext TestContext { get; set; } +#pragma warning restore CS8618 [TestInitialize] public void TestInitialize() @@ -99,6 +101,7 @@ public void ShipOrderWithLabel_IntegrationTest() var orderId = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Orders.GetOrderList()).Data.First() .BillBeeOrderId; + Assert.IsNotNull(orderId); var providerId = provider.id; var productId = provider.products.First().id; diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs index f89d39e..fbb0622 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs @@ -25,7 +25,9 @@ namespace Billbee.Api.Client.Test.EndPointIntegrationTests [TestClass] public class WebhookEndPointIntegrationTest { +#pragma warning disable CS8618 public TestContext TestContext { get; set; } +#pragma warning restore CS8618 private long _countBeforeTest = -1; private long _countExpectedAfterTest = -1; From f0d6524d0e2096a5a1768609745dbdaa196a1763 Mon Sep 17 00:00:00 2001 From: Benjamin Gottschalk Date: Fri, 5 Aug 2022 09:43:37 +0200 Subject: [PATCH 07/11] added integration tests --- .../ProductEndPointIntegrationTest.cs | 189 ++++++++++++------ .../WebhookEndPointIntegrationTest.cs | 2 + 2 files changed, 130 insertions(+), 61 deletions(-) diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs index 6c4e111..d67e428 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs @@ -27,6 +27,14 @@ public static partial class TestData } }, SKU = "4711", + Description = new List + { + new MultiLanguageString + { + Text = "desc", + LanguageCode = "de" + } + } }; public static ArticleImage ArticleImage => new ArticleImage @@ -66,6 +74,8 @@ public void TestInitialize() [TestCleanup] public void TestCleanup() { + IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod); + var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetProducts(1, int.MaxValue)); Assert.AreEqual(_countExpectedAfterTest, result.Data.Count); @@ -87,6 +97,7 @@ public void AddProduct_IntegrationTest() var product = result.Data; Assert.IsNotNull(product); Assert.IsNotNull(product.Id); + Assert.AreEqual(TestData.Product.SKU, product.SKU); Assert.AreEqual(TestData.Product.Title.First().Text, product.Title.First().Text); // cleanup @@ -98,16 +109,12 @@ public void AddProduct_IntegrationTest() [RequiresApiAccess] public void DeleteProduct_IntegrationTest() { - var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), - TestData.Product); - var createdProduct = result.Data; - Assert.IsNotNull(createdProduct); - Assert.IsNotNull(createdProduct.Id); + var createdProduct = _createProduct(); CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Products.GetProduct(id), createdProduct.Id.ToString()!); CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - createdProduct.Id); + createdProduct.Id!.Value); CrudHelpers.GetOneExpectException((id) => IntegrationTestHelpers.ApiClient.Products.GetProduct(id), createdProduct.Id.ToString()!); } @@ -123,18 +130,58 @@ public void GetStocks_IntegrationTest() [RequiresApiAccess] public void UpdateStockMultiple_IntegrationTest() { - Assert.Inconclusive(); + var product1 = _createProduct("4711"); + var product2 = _createProduct("4712"); + + Assert.AreEqual(null, product1.StockCurrent); + Assert.AreEqual(null, product2.StockCurrent); + + var updateStocks = new List + { + new UpdateStock + { + Reason = "Wareneingang", + Sku = product1.SKU, + NewQuantity = 1 + }, + new UpdateStock + { + Reason = "Wareneingang", + Sku = product2.SKU, + NewQuantity = 1 + } + }; + + var results = IntegrationTestHelpers.ApiClient.Products.UpdateStockMultiple(updateStocks); + foreach (var result in results) + { + Assert.IsTrue(result.Success); + } + + var updatedProduct1Result = CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Products.GetProduct(id), + product1.Id.ToString()!); + var updatedProduct1 = updatedProduct1Result.Data; + Assert.IsNotNull(updatedProduct1); + Assert.AreEqual(1, updatedProduct1.StockCurrent); + + var updatedProduct2Result = CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Products.GetProduct(id), + product2.Id.ToString()!); + var updatedProduct2 = updatedProduct2Result.Data; + Assert.IsNotNull(updatedProduct2); + Assert.AreEqual(1, updatedProduct2.StockCurrent); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), + product1.Id!.Value); + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), + product2.Id!.Value); } [TestMethod] [RequiresApiAccess] public void UpdateStock_IntegrationTest() { - var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), - TestData.Product); - var createdProduct = result.Data; - Assert.IsNotNull(createdProduct); - Assert.IsNotNull(createdProduct.Id); + var createdProduct = _createProduct(); Assert.AreEqual(null, createdProduct.StockCurrent); @@ -150,7 +197,9 @@ public void UpdateStock_IntegrationTest() var updatedProductResult = CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Products.GetProduct(id), createdProduct.Id.ToString()!); - Assert.AreEqual(1, updatedProductResult.Data.StockCurrent); + var updatedProduct = updatedProductResult.Data; + Assert.IsNotNull(updatedProduct); + Assert.AreEqual(1, updatedProduct.StockCurrent); // cleanup CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), @@ -161,11 +210,7 @@ public void UpdateStock_IntegrationTest() [RequiresApiAccess] public void GetReservedAmount_IntegrationTest() { - var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), - TestData.Product); - var createdProduct = result.Data; - Assert.IsNotNull(createdProduct); - Assert.IsNotNull(createdProduct.Id); + var createdProduct = _createProduct(); var reservedResult = CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Products.GetReservedAmount(id), createdProduct.Id.ToString()!, false); @@ -181,7 +226,25 @@ public void GetReservedAmount_IntegrationTest() [RequiresApiAccess] public void UpdateStockCode_IntegrationTest() { - Assert.Inconclusive(); + var createdProduct = _createProduct(); + Assert.IsTrue(string.IsNullOrEmpty(createdProduct.StockCode)); + + var updateStockCode = new UpdateStockCode + { + Sku = "4711", + StockCode = "bar" + }; + var updateResult = IntegrationTestHelpers.ApiClient.Products.UpdateStockCode(updateStockCode); + Assert.IsNotNull(updateResult); + Assert.AreEqual((int)ApiResult.ErrorCodeEnum.NoError, (int)updateResult.ErrorCode); + + var getResult = CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Products.GetProduct(id), + createdProduct.Id.ToString()!); + Assert.AreEqual("bar", getResult.Data.StockCode); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), + createdProduct.Id); } [TestMethod] @@ -195,11 +258,7 @@ public void GetProducts_IntegrationTest() [RequiresApiAccess] public void GetProduct_IntegrationTest() { - var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), - TestData.Product); - var createdProduct = result.Data; - Assert.IsNotNull(createdProduct); - Assert.IsNotNull(createdProduct.Id); + var createdProduct = _createProduct(); CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Products.GetProduct(id), createdProduct.Id.ToString()!); @@ -231,25 +290,41 @@ public void GetCustomField_IntegrationTest() [RequiresApiAccess] public void GetPatchableProductFields_IntegrationTest() { - CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetPatchableProductFields()); + var patchableFields = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetPatchableProductFields()); + Console.WriteLine("Patchable Product Fields:"); + foreach (var field in patchableFields.Data) + { + Console.WriteLine(field); + } } [TestMethod] [RequiresApiAccess] public void PatchArticle_IntegrationTest() { - Assert.Inconclusive(); + var createdProduct = _createProduct(); + Assert.AreEqual(TestData.Product.Description.First().Text, createdProduct!.Description.First().Text); + + var fieldsToPatch = new Dictionary + { + { "Description", "Modified" } + }; + var patchResult = CrudHelpers.Patch( + (id, fields) => IntegrationTestHelpers.ApiClient.Products.PatchArticle(id, fields), + createdProduct.Id.Value, fieldsToPatch); + + Assert.AreEqual("Modified", patchResult.Data.Description.First().Text); + + // cleanup + CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), + createdProduct!.Id!.Value); } [TestMethod] [RequiresApiAccess] public void GetArticleImages_IntegrationTest() { - var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), - TestData.Product); - var createdProduct = result.Data; - Assert.IsNotNull(createdProduct); - Assert.IsNotNull(createdProduct.Id); + var createdProduct = _createProduct(); var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), @@ -267,11 +342,7 @@ public void GetArticleImages_IntegrationTest() [RequiresApiAccess] public void GetArticleImage_IntegrationTest() { - var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), - TestData.Product); - var createdProduct = result.Data; - Assert.IsNotNull(createdProduct); - Assert.IsNotNull(createdProduct.Id); + var createdProduct = _createProduct(); var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); var resultImage = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), @@ -289,11 +360,7 @@ public void GetArticleImage_IntegrationTest() [RequiresApiAccess] public void AddArticleImage_IntegrationTest() { - var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), - TestData.Product); - var createdProduct = result.Data; - Assert.IsNotNull(createdProduct); - Assert.IsNotNull(createdProduct.Id); + var createdProduct = _createProduct(); var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); var resultImage = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), @@ -309,11 +376,7 @@ public void AddArticleImage_IntegrationTest() [RequiresApiAccess] public void UpdateArticleImage_IntegrationTest() { - var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), - TestData.Product); - var createdProduct = result.Data; - Assert.IsNotNull(createdProduct); - Assert.IsNotNull(createdProduct.Id); + var createdProduct = _createProduct(); var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); var resultImage = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), @@ -335,11 +398,7 @@ public void UpdateArticleImage_IntegrationTest() [RequiresApiAccess] public void AddMultipleArticleImages_IntegrationTest() { - var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), - TestData.Product); - var createdProduct = result.Data; - Assert.IsNotNull(createdProduct); - Assert.IsNotNull(createdProduct.Id); + var createdProduct = _createProduct(); var imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct!.Id!.Value)); Assert.AreEqual(0, imagesResult.Data.Count); @@ -367,11 +426,7 @@ public void AddMultipleArticleImages_IntegrationTest() [RequiresApiAccess] public void DeleteArticleImage_IntegrationTest() { - var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), - TestData.Product); - var createdProduct = result.Data; - Assert.IsNotNull(createdProduct); - Assert.IsNotNull(createdProduct.Id); + var createdProduct = _createProduct(); var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); var resultImage = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), @@ -395,11 +450,7 @@ public void DeleteArticleImage_IntegrationTest() [RequiresApiAccess] public void DeleteMultipleArticleImages_IntegrationTest() { - var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), - TestData.Product); - var createdProduct = result.Data; - Assert.IsNotNull(createdProduct); - Assert.IsNotNull(createdProduct.Id); + var createdProduct = _createProduct(); var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); var resultImage1 = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), @@ -430,5 +481,21 @@ public void DeleteMultipleArticleImages_IntegrationTest() CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), createdProduct!.Id!.Value); } + + private Product _createProduct(string sku = null) + { + var product = TestData.Product; + if (!string.IsNullOrWhiteSpace(sku)) + { + product.SKU = sku; + } + var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), + product); + var createdProduct = result.Data; + Assert.IsNotNull(createdProduct); + Assert.IsNotNull(createdProduct.Id); + + return createdProduct; + } } } \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs index fbb0622..95d2026 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs @@ -44,6 +44,8 @@ public void TestInitialize() [TestCleanup] public void TestCleanup() { + IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod); + var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); Assert.AreEqual(_countExpectedAfterTest, result.Count); } From 1b91d6c54ed59065b83501a98712cf575b075d61 Mon Sep 17 00:00:00 2001 From: Benjamin Gottschalk Date: Mon, 8 Aug 2022 10:45:50 +0200 Subject: [PATCH 08/11] - fixed return-type of OrderEndPoint.PatchOrder() method - added unit- and integration-tests #57 --- .../Helpers/CrudHelpers.cs | 15 +- .../OrderEndPointIntegrationTest.cs | 423 ++++++++++++------ .../ProductEndPointIntegrationTest.cs | 32 +- .../EndPointTests/OrderEndPointTest.cs | 6 +- .../Endpoint/Interfaces/IOrderEndPoint.cs | 9 +- Billbee.Api.Client/Endpoint/OrderEndPoint.cs | 11 +- 6 files changed, 344 insertions(+), 152 deletions(-) diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs index 8f85447..3ad9bb2 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs @@ -175,8 +175,21 @@ public static ApiResult Put(Func> func, dynamic item) return updatedItem; } - + + public static ApiResult Patch(Func, ApiResult> func, dynamic id, + Dictionary fieldsToPatch) + { + return _patch(func, id, fieldsToPatch); + } + public static ApiResult Patch(Func, ApiResult> func, dynamic id, Dictionary fieldsToPatch) + { + return _patch(func, id, fieldsToPatch); + } + + private static ApiResult _patch(Func, ApiResult> func, + dynamic id, + Dictionary fieldsToPatch) where TKey : notnull { string typeName = typeof(T).Name; diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs index b9f3c21..eb7d86e 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs @@ -1,157 +1,324 @@ -using Billbee.Api.Client.Model; +using Billbee.Api.Client.Enums; +using Billbee.Api.Client.Model; using Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers; -namespace Billbee.Api.Client.Test.EndPointIntegrationTests; +namespace Billbee.Api.Client.Test.EndPointIntegrationTests.Helpers +{ + public static partial class TestData + { + public static Order Order => new Order + { + UpdatedAt = DateTime.Now, + CreatedAt = DateTime.Now, + VatMode = VatModeEnum.DisplayVat, + TaxRate1 = 19.0M, + TaxRate2 = 7.0M, + OrderNumber = "12345", + OrderItems = new List + { + new OrderItem { + TotalPrice = 10M, + Quantity = 1, + Product = new OrderItemProduct + { + Title = "Test Product", + Weight = 500, + SKU = "4711" + } + } + } + }; + } +} -[TestClass] -public class OrderEndPointIntegrationTest +namespace Billbee.Api.Client.Test.EndPointIntegrationTests { + [TestClass] + public class OrderEndPointIntegrationTest + { #pragma warning disable CS8618 - public TestContext TestContext { get; set; } + public TestContext TestContext { get; set; } #pragma warning restore CS8618 - private long _countExpectedAfterTest = -1; - [TestInitialize] - public void TestInitialize() - { - IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod); + [TestInitialize] + public void TestInitialize() + { + IntegrationTestHelpers.CheckAccess(TestContext.ManagedType, TestContext.ManagedMethod); + } - var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Orders.GetOrderList(page: 1, pageSize: int.MaxValue)); - _countExpectedAfterTest = result.Data.Count; - } + [TestMethod] + [RequiresApiAccess] + public void GetLayouts_IntegrationTest() + { + var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Orders.GetLayouts()); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Data); + } - [TestCleanup] - public void TestCleanup() - { - var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Orders.GetOrderList(page: 1, pageSize: int.MaxValue)); - Assert.AreEqual(_countExpectedAfterTest, result.Data.Count); - } + [TestMethod] + [RequiresApiAccess] + public void GetOrder_IntegrationTest() + { + PostNewOrder_IntegrationTest(); + } - [TestMethod] - [RequiresApiAccess] - public void GetLayouts_IntegrationTest() - { - var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Orders.GetLayouts()); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Data); - } + [TestMethod] + [RequiresApiAccess] + public void GetPatchableFields_IntegrationTest() + { + var patchableFields = + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Orders.GetPatchableFields()); + Console.WriteLine("Patchable Order Fields:"); + foreach (var field in patchableFields.Data) + { + Console.WriteLine(field); + } + } - [TestMethod] - [RequiresApiAccess] - public void GetOrder_IntegrationTest() - { - Assert.Inconclusive(); - } + [TestMethod] + [RequiresApiAccess] + public void PatchOrder_IntegrationTest() + { + var order = _createOrder(); + Assert.AreEqual(TestData.Order.SellerComment, order.SellerComment); + + var fieldsToPatch = new Dictionary + { + { "SellerComment", "Modified" } + }; + var patchResult = CrudHelpers.Patch( + (id, fields) => IntegrationTestHelpers.ApiClient.Orders.PatchOrder(id, fields), + order.BillBeeOrderId!.Value, fieldsToPatch); + + Assert.AreEqual("Modified", patchResult.Data.SellerComment); + } - [TestMethod] - [RequiresApiAccess] - public void GetPatchableFields_IntegrationTest() - { - Assert.Inconclusive(); - } + [TestMethod] + [RequiresApiAccess] + public void GetOrderByExternalReference_IntegrationTest() + { + var extRef = Guid.NewGuid().ToString(); + var order = _createOrder(extRef); + + var orderResult = CrudHelpers.GetOneApiResult(e => IntegrationTestHelpers.ApiClient.Orders.GetOrderByExternalReference(e), + extRef, false); + Assert.IsNotNull(orderResult); + Assert.AreEqual(order.BillBeeOrderId, orderResult.Data.BillBeeOrderId); + } - [TestMethod] - [RequiresApiAccess] - public void PatchOrder_IntegrationTest() - { - Assert.Inconclusive(); - } + [TestMethod] + [RequiresApiAccess] + public void GetOrderByExternalIdAndPartner_IntegrationTest() + { + Assert.Inconclusive(); + } - [TestMethod] - [RequiresApiAccess] - public void GetOrderByExternalReference_IntegrationTest() - { - Assert.Inconclusive(); - } + [TestMethod] + [RequiresApiAccess] + public void GetOrderList_IntegrationTest() + { + var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Orders.GetOrderList()); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Data); + } - [TestMethod] - [RequiresApiAccess] - public void GetOrderByExternalIdAndPartner_IntegrationTest() - { - Assert.Inconclusive(); - } + [TestMethod] + [RequiresApiAccess] + public void GetInvoiceList_IntegrationTest() + { + var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Orders.GetInvoiceList()); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Data); + } - [TestMethod] - [RequiresApiAccess] - public void GetOrderList_IntegrationTest() - { - Assert.Inconclusive(); - } + [TestMethod] + [RequiresApiAccess] + public void PostNewOrder_IntegrationTest() + { + var order = _createOrder(); + + var orderResult = CrudHelpers.GetOneApiResult(id => IntegrationTestHelpers.ApiClient.Orders.GetOrder(id), + order.BillBeeOrderId!.Value.ToString(), false); + Assert.IsNotNull(orderResult); + Assert.AreEqual(order.BillBeeOrderId, orderResult.Data.BillBeeOrderId); + } - [TestMethod] - [RequiresApiAccess] - public void GetInvoiceList_IntegrationTest() - { - Assert.Inconclusive(); - } + [TestMethod] + [RequiresApiAccess] + public void AddTags_IntegrationTest() + { + _createOrderWithTags(); + } - [TestMethod] - [RequiresApiAccess] - public void PostNewOrder_IntegrationTest() - { - Assert.Inconclusive(); - } + [TestMethod] + [RequiresApiAccess] + public void UpdateTags_IntegrationTest() + { + var order = _createOrderWithTags(); - [TestMethod] - [RequiresApiAccess] - public void AddTags_IntegrationTest() - { - Assert.Inconclusive(); - } + var updatedTags = new List { "tag3", "tag4" }; + var result = IntegrationTestHelpers.ApiClient.Orders.UpdateTags(updatedTags, order.BillBeeOrderId!.Value); + Assert.IsNotNull(result); + Assert.AreEqual((int)ApiResult.ErrorCodeEnum.NoError, (int)result.ErrorCode); + + var orderResult = CrudHelpers.GetOneApiResult(id => IntegrationTestHelpers.ApiClient.Orders.GetOrder(id), + order.BillBeeOrderId.Value.ToString(), false); + Assert.IsNotNull(orderResult); + Assert.IsFalse(orderResult.Data.Tags.Contains("tag1")); + Assert.IsFalse(orderResult.Data.Tags.Contains("tag2")); + Assert.IsTrue(orderResult.Data.Tags.Contains("tag3")); + Assert.IsTrue(orderResult.Data.Tags.Contains("tag4")); + + } - [TestMethod] - [RequiresApiAccess] - public void UpdateTags_IntegrationTest() - { - Assert.Inconclusive(); - } + [TestMethod] + [RequiresApiAccess] + public void AddShipment_IntegrationTest() + { + var provider = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Shipment.GetShippingProvider()) + .First(); + var productId = provider.products.First().id; + var carrier = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Shipment.GetShippingCarriers()) + .First(); + + var order = _createOrder(); + var orderShipment = new OrderShipment + { + Comment = "comment", + CarrierId = carrier.Id, + OrderId = order.BillBeeOrderId!.Value, + ShippingId = "123", + ShippingProviderId = provider.id, + ShippingProviderProductId = productId + }; + IntegrationTestHelpers.ApiClient.Orders.AddShipment(orderShipment); + } - [TestMethod] - [RequiresApiAccess] - public void AddShipment_IntegrationTest() - { - Assert.Inconclusive(); - } + [TestMethod] + [RequiresApiAccess] + public void CreateDeliveryNote_IntegrationTest() + { + var order = _createOrder(); + var result = IntegrationTestHelpers.ApiClient.Orders.CreateDeliveryNote(order.BillBeeOrderId!.Value); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Data); + Assert.AreEqual(order.OrderNumber, result.Data.OrderNumber); + } - [TestMethod] - [RequiresApiAccess] - public void CreateDeliveryNote_IntegrationTest() - { - Assert.Inconclusive(); - } + [TestMethod] + [RequiresApiAccess] + public void CreateInvoice_IntegrationTest() + { + var order = _createOrder(); + + // throws an exception, because no invoice has been created yet for this new order + Assert.ThrowsException(() => IntegrationTestHelpers.ApiClient.Orders.CreateInvoice(order.BillBeeOrderId!.Value)); + } - [TestMethod] - [RequiresApiAccess] - public void CreateInvoice_IntegrationTest() - { - Assert.Inconclusive(); - } + [TestMethod] + [RequiresApiAccess] + public void ChangeOrderState_IntegrationTest() + { + var order = _createOrder(); + + var newState = OrderStateEnum.Bestaetigt; + Console.WriteLine($"Old state: {order.State.ToString()}"); + Assert.AreNotEqual(newState, order.State); + + IntegrationTestHelpers.ApiClient.Orders.ChangeOrderState(order.BillBeeOrderId!.Value, newState); + + var orderResult = CrudHelpers.GetOneApiResult(id => IntegrationTestHelpers.ApiClient.Orders.GetOrder(id), + order.BillBeeOrderId.Value.ToString(), false); + Assert.IsNotNull(orderResult); + Assert.IsNotNull(orderResult.Data); + Console.WriteLine($"New state: {order.State.ToString()}"); + Assert.AreEqual(newState, orderResult.Data.State); + } - [TestMethod] - [RequiresApiAccess] - public void ChangeOrderState_IntegrationTest() - { - Assert.Inconclusive(); - } + [TestMethod] + [RequiresApiAccess] + public void SendMailForOrder_IntegrationTest() + { + var order = _createOrder(); + var sendMessage = new SendMessage + { + Subject = new List + { + new MultiLanguageString + { + Text = "Foo", + LanguageCode = "DE" + } + }, + Body = new List + { + new MultiLanguageString + { + Text = "Bar", + LanguageCode = "DE" + } + } + }; + + IntegrationTestHelpers.ApiClient.Orders.SendMailForOrder(order.BillBeeOrderId!.Value, sendMessage); + } - [TestMethod] - [RequiresApiAccess] - public void SendMailForOrder_IntegrationTest() - { - Assert.Inconclusive(); - } + [TestMethod] + [RequiresApiAccess] + public void CreateEventAtOrder_IntegrationTest() + { + var order = _createOrder(); + IntegrationTestHelpers.ApiClient.Orders.CreateEventAtOrder(order.BillBeeOrderId!.Value, "myEvent"); + } - [TestMethod] - [RequiresApiAccess] - public void CreateEventAtOrder_IntegrationTest() - { - Assert.Inconclusive(); - } + [TestMethod] + [RequiresApiAccess] + public void ParsePlaceholders_IntegrationTest() + { + var order = _createOrder(); + + var parsePlaceholdersQuery = new ParsePlaceholdersQuery + { + TextToParse = "This is my text for Order {OrderNumber}" + }; + var result = IntegrationTestHelpers.ApiClient.Orders.ParsePlaceholders(order.BillBeeOrderId!.Value, parsePlaceholdersQuery); + Assert.IsNotNull(result); + Assert.AreEqual($"This is my text for Order {order.OrderNumber}", result.Result); + } - [TestMethod] - [RequiresApiAccess] - public void ParsePlaceholders_IntegrationTest() - { - Assert.Inconclusive(); + private Order _createOrder(string? extRef = null) + { + var testOrder = TestData.Order; + if (!string.IsNullOrWhiteSpace(extRef)) + { + testOrder.OrderNumber = extRef; + } + var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Orders.PostNewOrder(w), + testOrder); + var order = result.Data; + Assert.IsNotNull(order); + Assert.AreEqual(testOrder.OrderNumber, order.OrderNumber); + Assert.IsNotNull(order.BillBeeOrderId); + Console.WriteLine($"Order created, BillbeeOrderId={order.BillBeeOrderId}"); + return order; + } + + private Order _createOrderWithTags() + { + var order = _createOrder(); + + var tags = new List { "tag1", "tag2" }; + var result = IntegrationTestHelpers.ApiClient.Orders.AddTags(tags, order.BillBeeOrderId!.Value); + Assert.IsNotNull(result); + Assert.AreEqual((int)ApiResult.ErrorCodeEnum.NoError, (int)result.ErrorCode); + + var orderResult = CrudHelpers.GetOneApiResult(id => IntegrationTestHelpers.ApiClient.Orders.GetOrder(id), + order.BillBeeOrderId.Value.ToString(), false); + Assert.IsNotNull(orderResult); + Assert.IsTrue(orderResult.Data.Tags.Contains("tag1")); + Assert.IsTrue(orderResult.Data.Tags.Contains("tag2")); + + return orderResult.Data; + } } } \ No newline at end of file diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs index d67e428..097f873 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs @@ -203,7 +203,7 @@ public void UpdateStock_IntegrationTest() // cleanup CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - createdProduct.Id); + createdProduct!.Id!); } [TestMethod] @@ -219,7 +219,7 @@ public void GetReservedAmount_IntegrationTest() // cleanup CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - createdProduct.Id); + createdProduct!.Id!); } [TestMethod] @@ -244,7 +244,7 @@ public void UpdateStockCode_IntegrationTest() // cleanup CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - createdProduct.Id); + createdProduct!.Id!); } [TestMethod] @@ -265,7 +265,7 @@ public void GetProduct_IntegrationTest() // cleanup CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - createdProduct.Id); + createdProduct!.Id!); } [TestMethod] @@ -311,7 +311,7 @@ public void PatchArticle_IntegrationTest() }; var patchResult = CrudHelpers.Patch( (id, fields) => IntegrationTestHelpers.ApiClient.Products.PatchArticle(id, fields), - createdProduct.Id.Value, fieldsToPatch); + createdProduct!.Id!.Value, fieldsToPatch); Assert.AreEqual("Modified", patchResult.Data.Description.First().Text); @@ -326,7 +326,7 @@ public void GetArticleImages_IntegrationTest() { var createdProduct = _createProduct(); - var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); + var articleImage = TestData.GetArticleImage(createdProduct!.Id!.Value); CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), articleImage); @@ -344,7 +344,7 @@ public void GetArticleImage_IntegrationTest() { var createdProduct = _createProduct(); - var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); + var articleImage = TestData.GetArticleImage(createdProduct!.Id!.Value); var resultImage = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), articleImage); @@ -362,7 +362,7 @@ public void AddArticleImage_IntegrationTest() { var createdProduct = _createProduct(); - var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); + var articleImage = TestData.GetArticleImage(createdProduct!.Id!.Value); var resultImage = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), articleImage); Assert.AreEqual((byte)1, resultImage.Data.Position); @@ -378,7 +378,7 @@ public void UpdateArticleImage_IntegrationTest() { var createdProduct = _createProduct(); - var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); + var articleImage = TestData.GetArticleImage(createdProduct!.Id!.Value); var resultImage = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), articleImage); Assert.AreEqual((byte)1, resultImage.Data.Position); @@ -405,13 +405,13 @@ public void AddMultipleArticleImages_IntegrationTest() var articleImages = new List { - TestData.GetArticleImage(createdProduct.Id.Value), - TestData.GetArticleImage(createdProduct.Id.Value), - TestData.GetArticleImage(createdProduct.Id.Value) + TestData.GetArticleImage(createdProduct!.Id!.Value), + TestData.GetArticleImage(createdProduct!.Id!.Value), + TestData.GetArticleImage(createdProduct!.Id!.Value) }; Console.WriteLine(); Console.WriteLine($"Adding multiple ArticleImages (3)"); - IntegrationTestHelpers.ApiClient.Products.AddMultipleArticleImages(createdProduct.Id.Value, articleImages); + IntegrationTestHelpers.ApiClient.Products.AddMultipleArticleImages(createdProduct!.Id!.Value, articleImages); Console.WriteLine($"Added multiple ArticleImages"); imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct!.Id!.Value)); @@ -428,7 +428,7 @@ public void DeleteArticleImage_IntegrationTest() { var createdProduct = _createProduct(); - var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); + var articleImage = TestData.GetArticleImage(createdProduct!.Id!.Value); var resultImage = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), articleImage); @@ -452,7 +452,7 @@ public void DeleteMultipleArticleImages_IntegrationTest() { var createdProduct = _createProduct(); - var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); + var articleImage = TestData.GetArticleImage(createdProduct!.Id!.Value); var resultImage1 = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), articleImage); var resultImage2 = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), @@ -482,7 +482,7 @@ public void DeleteMultipleArticleImages_IntegrationTest() createdProduct!.Id!.Value); } - private Product _createProduct(string sku = null) + private Product _createProduct(string sku = null!) { var product = TestData.Product; if (!string.IsNullOrWhiteSpace(sku)) diff --git a/Billbee.Api.Client.Test/EndPointTests/OrderEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/OrderEndPointTest.cs index e15228e..ff9e49a 100644 --- a/Billbee.Api.Client.Test/EndPointTests/OrderEndPointTest.cs +++ b/Billbee.Api.Client.Test/EndPointTests/OrderEndPointTest.cs @@ -50,8 +50,8 @@ public void PatchOrderTest() { "SellerComment", "my comment..." } }; - Expression> expression = x => x.Patch>($"/orders/{orderId}", null, It.IsAny()); - object mockResult = TestHelpers.GetApiResult(new object()); + Expression>> expression = x => x.Patch>($"/orders/{orderId}", null, It.IsAny()); + var mockResult = TestHelpers.GetApiResult(new Order()); TestHelpers.RestClientMockTest(expression, mockResult, (restClient) => { var uut = new OrderEndPoint(restClient); @@ -379,7 +379,7 @@ public void ParsePlaceholdersTest() var orderId = 4711; var parsePlaceholdersQuery = new ParsePlaceholdersQuery { - TextToParse = "This is my text for Order {{id}}" + TextToParse = "This is my text for Order {OrderNumber}" }; uut.ParsePlaceholders(orderId, parsePlaceholdersQuery); diff --git a/Billbee.Api.Client/Endpoint/Interfaces/IOrderEndPoint.cs b/Billbee.Api.Client/Endpoint/Interfaces/IOrderEndPoint.cs index 1a5d204..97ed927 100644 --- a/Billbee.Api.Client/Endpoint/Interfaces/IOrderEndPoint.cs +++ b/Billbee.Api.Client/Endpoint/Interfaces/IOrderEndPoint.cs @@ -30,7 +30,7 @@ public interface IOrderEndPoint /// The id of the order to patch. /// Name-Value pairs of fields, to be patched. /// - ApiResult PatchOrder(long id, Dictionary fieldsToPatch); + ApiResult PatchOrder(long id, Dictionary fieldsToPatch); /// /// Selects an order by it's external id @@ -109,6 +109,13 @@ ApiResult> GetInvoiceList( /// ApiResult PostNewOrder(Order order, long shopId); + /// + /// Creates a new order + /// + /// An order object, to create in billbee + /// + ApiResult PostNewOrder(Order order); + /// /// Reset the tags on an order and add the given ones. /// All previuosly added tags will be deleted. diff --git a/Billbee.Api.Client/Endpoint/OrderEndPoint.cs b/Billbee.Api.Client/Endpoint/OrderEndPoint.cs index 657f315..4744683 100644 --- a/Billbee.Api.Client/Endpoint/OrderEndPoint.cs +++ b/Billbee.Api.Client/Endpoint/OrderEndPoint.cs @@ -31,9 +31,9 @@ public ApiResult> GetPatchableFields() } [ApiMapping("/api/v1/orders/{id}", HttpOperation.Patch)] - public ApiResult PatchOrder(long id, Dictionary fieldsToPatch) + public ApiResult PatchOrder(long id, Dictionary fieldsToPatch) { - return _restClient.Patch>($"/orders/{id}", data: fieldsToPatch); + return _restClient.Patch>($"/orders/{id}", data: fieldsToPatch); } [ApiMapping("/api/v1/orders/findbyextref/{extRef}", HttpOperation.Get)] @@ -201,7 +201,12 @@ public ApiResult PostNewOrder(Order order, long shopId) return _restClient.Post>("/orders", order, parameters); } - + + public ApiResult PostNewOrder(Order order) + { + return _restClient.Post>("/orders", order, null); + } + [ApiMapping("/api/v1/orders/{id}/tags", HttpOperation.Post)] public ApiResult AddTags(List tags, long orderId) { From 8e341cf3983b25876b95609356c6b805c04f5799 Mon Sep 17 00:00:00 2001 From: Benjamin Gottschalk Date: Tue, 9 Aug 2022 12:25:15 +0200 Subject: [PATCH 09/11] removed null forgiving operators --- Billbee.Api.Client.Test/ApiSyncTest.cs | 3 +- ...ustomerAddressesEndPointIntegrationTest.cs | 8 +- .../CustomerEndPointIntegrationTest.cs | 49 ++++++++--- .../Helpers/CrudHelpers.cs | 4 +- .../Helpers/IntegrationTestHelpers.cs | 11 ++- .../OrderEndPointIntegrationTest.cs | 35 +++++--- .../ProductEndPointIntegrationTest.cs | 86 +++++++++++-------- 7 files changed, 127 insertions(+), 69 deletions(-) diff --git a/Billbee.Api.Client.Test/ApiSyncTest.cs b/Billbee.Api.Client.Test/ApiSyncTest.cs index 0b60bec..9cf485a 100644 --- a/Billbee.Api.Client.Test/ApiSyncTest.cs +++ b/Billbee.Api.Client.Test/ApiSyncTest.cs @@ -78,8 +78,9 @@ private async Task> GetApiOperations() private static List GetSdkOperations() { var sdkOps = new List(); - var endpointTypes = Assembly.GetAssembly(typeof(ApiClient))!.GetTypes() + var endpointTypes = Assembly.GetAssembly(typeof(ApiClient))?.GetTypes() .Where(t => t.Namespace == "Billbee.Api.Client.EndPoint"); + Assert.IsNotNull(endpointTypes); foreach (var endpoint in endpointTypes) { foreach (var methodInfo in endpoint.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs index 38c362e..6aef6ab 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs @@ -64,9 +64,10 @@ public void GetCustomerAddress_IntegrationTest() CrudHelpers.CreateApiResult( a => IntegrationTestHelpers.ApiClient.CustomerAddresses.AddCustomerAddress(a), TestData.GetCustomerAddress(customer.Id)).Data; + Assert.IsNotNull(customerAddress.Id); CrudHelpers.GetOneApiResult( (id) => IntegrationTestHelpers.ApiClient.CustomerAddresses.GetCustomerAddress(id), - customerAddress.Id!.Value); + customerAddress.Id.Value); } [TestMethod] @@ -88,9 +89,10 @@ public void UpdateCustomerAddress_IntegrationTest() CrudHelpers.CreateApiResult( a => IntegrationTestHelpers.ApiClient.CustomerAddresses.AddCustomerAddress(a), TestData.GetCustomerAddress(customer.Id)).Data; + Assert.IsNotNull(customerAddress.Id); var result = CrudHelpers.GetOneApiResult( (id) => IntegrationTestHelpers.ApiClient.CustomerAddresses.GetCustomerAddress(id), - customerAddress.Id!.Value); + customerAddress.Id.Value); var address = result.Data; address.LastName = "Modified"; @@ -99,7 +101,7 @@ public void UpdateCustomerAddress_IntegrationTest() address); CrudHelpers.GetOneApiResult( (id) => IntegrationTestHelpers.ApiClient.CustomerAddresses.GetCustomerAddress(id), - customerAddress.Id!.Value); + customerAddress.Id.Value); Assert.AreEqual("Modified", address.LastName); } } diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs index 87e6718..3f5036f 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs @@ -44,9 +44,10 @@ public void AddCustomer_IntegrationTest() var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); Assert.AreEqual("john@doe.com", customer.Data.Email); + Assert.IsNotNull(customer.Data.Id); CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Customer.GetCustomer(id), - customer.Data.Id!.Value); + customer.Data.Id.Value); } [TestMethod] @@ -77,8 +78,11 @@ public void GetCustomerAddress_IntegrationTest() IntegrationTestHelpers.ApiClient.Customer.GetAddressesForCustomer(customer.Data.Id.Value, 1, 5)) .Data .FirstOrDefault(); + Assert.IsNotNull(address); + Assert.IsNotNull(address.Id); + CrudHelpers.GetOneApiResult( - (id) => IntegrationTestHelpers.ApiClient.Customer.GetCustomerAddress(id), address!.Id!.Value); + (id) => IntegrationTestHelpers.ApiClient.Customer.GetCustomerAddress(id), address.Id.Value); } [TestMethod] @@ -87,12 +91,16 @@ public void UpdateCustomerAddress_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); + Assert.IsNotNull(customer); + Assert.IsNotNull(customer.Data); + Assert.IsNotNull(customer.Data.Id); var address = CrudHelpers.GetAll(() => - IntegrationTestHelpers.ApiClient.Customer.GetAddressesForCustomer(customer!.Data!.Id!.Value, 1, 5)) + IntegrationTestHelpers.ApiClient.Customer.GetAddressesForCustomer(customer.Data.Id.Value, 1, 5)) .Data .FirstOrDefault(); - Assert.AreEqual(TestData.CustomerAddress.FirstName, address!.FirstName); + Assert.IsNotNull(address); + Assert.AreEqual(TestData.CustomerAddress.FirstName, address.FirstName); address.FirstName = "Modified"; var result = CrudHelpers.Put( @@ -109,12 +117,16 @@ public void PatchCustomerAddress_IntegrationTest() var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); Assert.IsNotNull(customer); + Assert.IsNotNull(customer.Data); + Assert.IsNotNull(customer.Data.Id); var address = CrudHelpers.GetAll(() => - IntegrationTestHelpers.ApiClient.Customer.GetAddressesForCustomer(customer.Data!.Id!.Value, 1, 5)) + IntegrationTestHelpers.ApiClient.Customer.GetAddressesForCustomer(customer.Data.Id.Value, 1, 5)) .Data .FirstOrDefault(); - Assert.AreEqual(TestData.CustomerAddress.FirstName, address!.FirstName); + Assert.IsNotNull(address); + Assert.IsNotNull(address.Id); + Assert.AreEqual(TestData.CustomerAddress.FirstName, address.FirstName); var fieldsToPatch = new Dictionary { @@ -122,7 +134,7 @@ public void PatchCustomerAddress_IntegrationTest() }; var result = CrudHelpers.Patch( (id, fields) => IntegrationTestHelpers.ApiClient.Customer.PatchCustomerAddress(id, fields), - address.Id!.Value, fieldsToPatch); + address.Id.Value, fieldsToPatch); Assert.AreEqual("Modified", result.Data.FirstName); } @@ -134,9 +146,11 @@ public void GetCustomer_IntegrationTest() var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); Assert.IsNotNull(customer); + Assert.IsNotNull(customer.Data); + Assert.IsNotNull(customer.Data.Id); CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Customer.GetCustomer(id), - customer!.Data!.Id!.Value); + customer.Data.Id.Value); } [TestMethod] @@ -145,16 +159,23 @@ public void UpdateCustomer_IntegrationTest() { var result = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); + Assert.IsNotNull(result); + Assert.IsNotNull(result.Data); + Assert.IsNotNull(result.Data.Id); + result = CrudHelpers.GetOneApiResult( - (id) => IntegrationTestHelpers.ApiClient.Customer.GetCustomer(id), result!.Data.Id!.Value); + (id) => IntegrationTestHelpers.ApiClient.Customer.GetCustomer(id), result.Data.Id.Value); var customer = result.Data; + Assert.IsNotNull(result); + Assert.IsNotNull(result.Data); + Assert.IsNotNull(result.Data.Id); Assert.AreNotEqual("Modified", customer.Name); customer.Name = "Modified"; CrudHelpers.Put((x) => IntegrationTestHelpers.ApiClient.Customer.UpdateCustomer(x), customer); result = CrudHelpers.GetOneApiResult( - (id) => IntegrationTestHelpers.ApiClient.Customer.GetCustomer(id), result!.Data.Id!.Value); + (id) => IntegrationTestHelpers.ApiClient.Customer.GetCustomer(id), result.Data.Id.Value); Assert.AreEqual("Modified", result.Data.Name); } @@ -165,9 +186,11 @@ public void GetOrdersForCustomer_IntegrationTest() var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); Assert.IsNotNull(customer); + Assert.IsNotNull(customer.Data); + Assert.IsNotNull(customer.Data.Id); CrudHelpers.GetAll(() => - IntegrationTestHelpers.ApiClient.Customer.GetOrdersForCustomer(customer.Data!.Id!.Value, 1, 5)).Data + IntegrationTestHelpers.ApiClient.Customer.GetOrdersForCustomer(customer.Data.Id.Value, 1, 5)).Data .FirstOrDefault(); } @@ -178,9 +201,11 @@ public void GetAddressesForCustomer_IntegrationTest() var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); Assert.IsNotNull(customer); + Assert.IsNotNull(customer.Data); + Assert.IsNotNull(customer.Data.Id); var result = CrudHelpers.GetAll(() => - IntegrationTestHelpers.ApiClient.Customer.GetAddressesForCustomer(customer.Data!.Id!.Value, 1, 5)); + IntegrationTestHelpers.ApiClient.Customer.GetAddressesForCustomer(customer.Data.Id.Value, 1, 5)); Assert.IsTrue(result.Data.Count > 0); } } diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs index 3ad9bb2..29d8282 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/Helpers/CrudHelpers.cs @@ -57,7 +57,7 @@ public static T Create(Func func, TCreate newItem) where dynamic result = func(newItem); Assert.IsNotNull(result); - Console.WriteLine($"{typeName} created, id={result!.Id}"); + Console.WriteLine($"{typeName} created, id={result.Id}"); return result; } @@ -71,7 +71,7 @@ public static ApiResult CreateApiResult(Func().Any(); + Assert.IsNotNull(type); + var mi = type.GetMethod(testContextManagedMethod); + Assert.IsNotNull(mi); + bool requiresApiAccess = mi.GetCustomAttributes().Any(); if (requiresApiAccess && !IntegrationTestSettings.AllowReadWriteAccessToBillbeeApi) { Assert.Inconclusive( @@ -31,8 +33,9 @@ public static ApiClient ApiClient { if (_apiClient == null) { - var fiDll = new FileInfo(Assembly.GetExecutingAssembly().Location); - var di = new DirectoryInfo(Path.Combine(fiDll!.Directory!.FullName, "../../../")); + var fiDll = new FileInfo(Assembly.GetExecutingAssembly().Location); + Assert.IsNotNull(fiDll.Directory); + var di = new DirectoryInfo(Path.Combine(fiDll.Directory.FullName, "../../../")); var path = Path.Combine(di.FullName, "config.prod"); if (!File.Exists(path + ".json")) { diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs index eb7d86e..27a03c3 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs @@ -80,6 +80,7 @@ public void GetPatchableFields_IntegrationTest() public void PatchOrder_IntegrationTest() { var order = _createOrder(); + Assert.IsNotNull(order.BillBeeOrderId); Assert.AreEqual(TestData.Order.SellerComment, order.SellerComment); var fieldsToPatch = new Dictionary @@ -88,7 +89,7 @@ public void PatchOrder_IntegrationTest() }; var patchResult = CrudHelpers.Patch( (id, fields) => IntegrationTestHelpers.ApiClient.Orders.PatchOrder(id, fields), - order.BillBeeOrderId!.Value, fieldsToPatch); + order.BillBeeOrderId.Value, fieldsToPatch); Assert.AreEqual("Modified", patchResult.Data.SellerComment); } @@ -136,9 +137,10 @@ public void GetInvoiceList_IntegrationTest() public void PostNewOrder_IntegrationTest() { var order = _createOrder(); + Assert.IsNotNull(order.BillBeeOrderId); var orderResult = CrudHelpers.GetOneApiResult(id => IntegrationTestHelpers.ApiClient.Orders.GetOrder(id), - order.BillBeeOrderId!.Value.ToString(), false); + order.BillBeeOrderId.Value.ToString(), false); Assert.IsNotNull(orderResult); Assert.AreEqual(order.BillBeeOrderId, orderResult.Data.BillBeeOrderId); } @@ -155,9 +157,10 @@ public void AddTags_IntegrationTest() public void UpdateTags_IntegrationTest() { var order = _createOrderWithTags(); + Assert.IsNotNull(order.BillBeeOrderId); var updatedTags = new List { "tag3", "tag4" }; - var result = IntegrationTestHelpers.ApiClient.Orders.UpdateTags(updatedTags, order.BillBeeOrderId!.Value); + var result = IntegrationTestHelpers.ApiClient.Orders.UpdateTags(updatedTags, order.BillBeeOrderId.Value); Assert.IsNotNull(result); Assert.AreEqual((int)ApiResult.ErrorCodeEnum.NoError, (int)result.ErrorCode); @@ -181,12 +184,13 @@ public void AddShipment_IntegrationTest() var carrier = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Shipment.GetShippingCarriers()) .First(); - var order = _createOrder(); + var order = _createOrder(); + Assert.IsNotNull(order.BillBeeOrderId); var orderShipment = new OrderShipment { Comment = "comment", CarrierId = carrier.Id, - OrderId = order.BillBeeOrderId!.Value, + OrderId = order.BillBeeOrderId.Value, ShippingId = "123", ShippingProviderId = provider.id, ShippingProviderProductId = productId @@ -199,7 +203,8 @@ public void AddShipment_IntegrationTest() public void CreateDeliveryNote_IntegrationTest() { var order = _createOrder(); - var result = IntegrationTestHelpers.ApiClient.Orders.CreateDeliveryNote(order.BillBeeOrderId!.Value); + Assert.IsNotNull(order.BillBeeOrderId); + var result = IntegrationTestHelpers.ApiClient.Orders.CreateDeliveryNote(order.BillBeeOrderId.Value); Assert.IsNotNull(result); Assert.IsNotNull(result.Data); Assert.AreEqual(order.OrderNumber, result.Data.OrderNumber); @@ -210,9 +215,10 @@ public void CreateDeliveryNote_IntegrationTest() public void CreateInvoice_IntegrationTest() { var order = _createOrder(); + Assert.IsNotNull(order.BillBeeOrderId); // throws an exception, because no invoice has been created yet for this new order - Assert.ThrowsException(() => IntegrationTestHelpers.ApiClient.Orders.CreateInvoice(order.BillBeeOrderId!.Value)); + Assert.ThrowsException(() => IntegrationTestHelpers.ApiClient.Orders.CreateInvoice(order.BillBeeOrderId.Value)); } [TestMethod] @@ -220,12 +226,13 @@ public void CreateInvoice_IntegrationTest() public void ChangeOrderState_IntegrationTest() { var order = _createOrder(); + Assert.IsNotNull(order.BillBeeOrderId); var newState = OrderStateEnum.Bestaetigt; Console.WriteLine($"Old state: {order.State.ToString()}"); Assert.AreNotEqual(newState, order.State); - IntegrationTestHelpers.ApiClient.Orders.ChangeOrderState(order.BillBeeOrderId!.Value, newState); + IntegrationTestHelpers.ApiClient.Orders.ChangeOrderState(order.BillBeeOrderId.Value, newState); var orderResult = CrudHelpers.GetOneApiResult(id => IntegrationTestHelpers.ApiClient.Orders.GetOrder(id), order.BillBeeOrderId.Value.ToString(), false); @@ -240,6 +247,7 @@ public void ChangeOrderState_IntegrationTest() public void SendMailForOrder_IntegrationTest() { var order = _createOrder(); + Assert.IsNotNull(order.BillBeeOrderId); var sendMessage = new SendMessage { Subject = new List @@ -260,7 +268,7 @@ public void SendMailForOrder_IntegrationTest() } }; - IntegrationTestHelpers.ApiClient.Orders.SendMailForOrder(order.BillBeeOrderId!.Value, sendMessage); + IntegrationTestHelpers.ApiClient.Orders.SendMailForOrder(order.BillBeeOrderId.Value, sendMessage); } [TestMethod] @@ -268,7 +276,8 @@ public void SendMailForOrder_IntegrationTest() public void CreateEventAtOrder_IntegrationTest() { var order = _createOrder(); - IntegrationTestHelpers.ApiClient.Orders.CreateEventAtOrder(order.BillBeeOrderId!.Value, "myEvent"); + Assert.IsNotNull(order.BillBeeOrderId); + IntegrationTestHelpers.ApiClient.Orders.CreateEventAtOrder(order.BillBeeOrderId.Value, "myEvent"); } [TestMethod] @@ -276,12 +285,13 @@ public void CreateEventAtOrder_IntegrationTest() public void ParsePlaceholders_IntegrationTest() { var order = _createOrder(); + Assert.IsNotNull(order.BillBeeOrderId); var parsePlaceholdersQuery = new ParsePlaceholdersQuery { TextToParse = "This is my text for Order {OrderNumber}" }; - var result = IntegrationTestHelpers.ApiClient.Orders.ParsePlaceholders(order.BillBeeOrderId!.Value, parsePlaceholdersQuery); + var result = IntegrationTestHelpers.ApiClient.Orders.ParsePlaceholders(order.BillBeeOrderId.Value, parsePlaceholdersQuery); Assert.IsNotNull(result); Assert.AreEqual($"This is my text for Order {order.OrderNumber}", result.Result); } @@ -306,9 +316,10 @@ private Order _createOrder(string? extRef = null) private Order _createOrderWithTags() { var order = _createOrder(); + Assert.IsNotNull(order.BillBeeOrderId); var tags = new List { "tag1", "tag2" }; - var result = IntegrationTestHelpers.ApiClient.Orders.AddTags(tags, order.BillBeeOrderId!.Value); + var result = IntegrationTestHelpers.ApiClient.Orders.AddTags(tags, order.BillBeeOrderId.Value); Assert.IsNotNull(result); Assert.AreEqual((int)ApiResult.ErrorCodeEnum.NoError, (int)result.ErrorCode); diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs index 097f873..91a9b50 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs @@ -110,11 +110,12 @@ public void AddProduct_IntegrationTest() public void DeleteProduct_IntegrationTest() { var createdProduct = _createProduct(); + Assert.IsNotNull(createdProduct.Id); CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Products.GetProduct(id), createdProduct.Id.ToString()!); CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - createdProduct.Id!.Value); + createdProduct.Id.Value); CrudHelpers.GetOneExpectException((id) => IntegrationTestHelpers.ApiClient.Products.GetProduct(id), createdProduct.Id.ToString()!); } @@ -131,7 +132,9 @@ public void GetStocks_IntegrationTest() public void UpdateStockMultiple_IntegrationTest() { var product1 = _createProduct("4711"); + Assert.IsNotNull(product1.Id); var product2 = _createProduct("4712"); + Assert.IsNotNull(product2.Id); Assert.AreEqual(null, product1.StockCurrent); Assert.AreEqual(null, product2.StockCurrent); @@ -172,9 +175,9 @@ public void UpdateStockMultiple_IntegrationTest() // cleanup CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - product1.Id!.Value); + product1.Id.Value); CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - product2.Id!.Value); + product2.Id.Value); } [TestMethod] @@ -182,6 +185,7 @@ public void UpdateStockMultiple_IntegrationTest() public void UpdateStock_IntegrationTest() { var createdProduct = _createProduct(); + Assert.IsNotNull(createdProduct.Id); Assert.AreEqual(null, createdProduct.StockCurrent); @@ -203,7 +207,7 @@ public void UpdateStock_IntegrationTest() // cleanup CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - createdProduct!.Id!); + createdProduct.Id!); } [TestMethod] @@ -211,6 +215,7 @@ public void UpdateStock_IntegrationTest() public void GetReservedAmount_IntegrationTest() { var createdProduct = _createProduct(); + Assert.IsNotNull(createdProduct.Id); var reservedResult = CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Products.GetReservedAmount(id), createdProduct.Id.ToString()!, false); @@ -219,7 +224,7 @@ public void GetReservedAmount_IntegrationTest() // cleanup CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - createdProduct!.Id!); + createdProduct.Id!); } [TestMethod] @@ -227,6 +232,7 @@ public void GetReservedAmount_IntegrationTest() public void UpdateStockCode_IntegrationTest() { var createdProduct = _createProduct(); + Assert.IsNotNull(createdProduct.Id); Assert.IsTrue(string.IsNullOrEmpty(createdProduct.StockCode)); var updateStockCode = new UpdateStockCode @@ -244,7 +250,7 @@ public void UpdateStockCode_IntegrationTest() // cleanup CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - createdProduct!.Id!); + createdProduct.Id); } [TestMethod] @@ -259,13 +265,14 @@ public void GetProducts_IntegrationTest() public void GetProduct_IntegrationTest() { var createdProduct = _createProduct(); + Assert.IsNotNull(createdProduct.Id); CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Products.GetProduct(id), createdProduct.Id.ToString()!); // cleanup CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - createdProduct!.Id!); + createdProduct.Id); } [TestMethod] @@ -281,9 +288,10 @@ public void GetCustomField_IntegrationTest() { var customField = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetCustomFields(1, int.MaxValue)).Data.FirstOrDefault(); Assert.IsNotNull(customField); + Assert.IsNotNull(customField.Id); CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Products.GetCustomField(id), - customField!.Id!.Value); + customField.Id.Value); } [TestMethod] @@ -303,7 +311,8 @@ public void GetPatchableProductFields_IntegrationTest() public void PatchArticle_IntegrationTest() { var createdProduct = _createProduct(); - Assert.AreEqual(TestData.Product.Description.First().Text, createdProduct!.Description.First().Text); + Assert.IsNotNull(createdProduct.Id); + Assert.AreEqual(TestData.Product.Description.First().Text, createdProduct.Description.First().Text); var fieldsToPatch = new Dictionary { @@ -311,13 +320,13 @@ public void PatchArticle_IntegrationTest() }; var patchResult = CrudHelpers.Patch( (id, fields) => IntegrationTestHelpers.ApiClient.Products.PatchArticle(id, fields), - createdProduct!.Id!.Value, fieldsToPatch); + createdProduct.Id.Value, fieldsToPatch); Assert.AreEqual("Modified", patchResult.Data.Description.First().Text); // cleanup CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - createdProduct!.Id!.Value); + createdProduct.Id.Value); } [TestMethod] @@ -325,17 +334,18 @@ public void PatchArticle_IntegrationTest() public void GetArticleImages_IntegrationTest() { var createdProduct = _createProduct(); + Assert.IsNotNull(createdProduct.Id); - var articleImage = TestData.GetArticleImage(createdProduct!.Id!.Value); + var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), articleImage); - var imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct!.Id!.Value)); + var imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct.Id.Value)); Assert.AreEqual(1, imagesResult.Data.Count); // cleanup CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - createdProduct!.Id!.Value); + createdProduct.Id.Value); } [TestMethod] @@ -343,8 +353,9 @@ public void GetArticleImages_IntegrationTest() public void GetArticleImage_IntegrationTest() { var createdProduct = _createProduct(); + Assert.IsNotNull(createdProduct.Id); - var articleImage = TestData.GetArticleImage(createdProduct!.Id!.Value); + var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); var resultImage = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), articleImage); @@ -353,7 +364,7 @@ public void GetArticleImage_IntegrationTest() // cleanup CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - createdProduct!.Id!.Value); + createdProduct.Id.Value); } [TestMethod] @@ -361,15 +372,16 @@ public void GetArticleImage_IntegrationTest() public void AddArticleImage_IntegrationTest() { var createdProduct = _createProduct(); + Assert.IsNotNull(createdProduct.Id); - var articleImage = TestData.GetArticleImage(createdProduct!.Id!.Value); + var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); var resultImage = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), articleImage); Assert.AreEqual((byte)1, resultImage.Data.Position); // cleanup CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - createdProduct!.Id!.Value); + createdProduct.Id.Value); } [TestMethod] @@ -377,8 +389,9 @@ public void AddArticleImage_IntegrationTest() public void UpdateArticleImage_IntegrationTest() { var createdProduct = _createProduct(); + Assert.IsNotNull(createdProduct.Id); - var articleImage = TestData.GetArticleImage(createdProduct!.Id!.Value); + var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); var resultImage = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), articleImage); Assert.AreEqual((byte)1, resultImage.Data.Position); @@ -391,7 +404,7 @@ public void UpdateArticleImage_IntegrationTest() // cleanup CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - createdProduct!.Id!.Value); + createdProduct.Id.Value); } [TestMethod] @@ -399,27 +412,28 @@ public void UpdateArticleImage_IntegrationTest() public void AddMultipleArticleImages_IntegrationTest() { var createdProduct = _createProduct(); + Assert.IsNotNull(createdProduct.Id); - var imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct!.Id!.Value)); + var imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct.Id.Value)); Assert.AreEqual(0, imagesResult.Data.Count); var articleImages = new List { - TestData.GetArticleImage(createdProduct!.Id!.Value), - TestData.GetArticleImage(createdProduct!.Id!.Value), - TestData.GetArticleImage(createdProduct!.Id!.Value) + TestData.GetArticleImage(createdProduct.Id.Value), + TestData.GetArticleImage(createdProduct.Id.Value), + TestData.GetArticleImage(createdProduct.Id.Value) }; Console.WriteLine(); Console.WriteLine($"Adding multiple ArticleImages (3)"); - IntegrationTestHelpers.ApiClient.Products.AddMultipleArticleImages(createdProduct!.Id!.Value, articleImages); + IntegrationTestHelpers.ApiClient.Products.AddMultipleArticleImages(createdProduct.Id.Value, articleImages); Console.WriteLine($"Added multiple ArticleImages"); - imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct!.Id!.Value)); + imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct.Id.Value)); Assert.AreEqual(3, imagesResult.Data.Count); // cleanup CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - createdProduct!.Id!.Value); + createdProduct.Id.Value); } [TestMethod] @@ -427,23 +441,24 @@ public void AddMultipleArticleImages_IntegrationTest() public void DeleteArticleImage_IntegrationTest() { var createdProduct = _createProduct(); + Assert.IsNotNull(createdProduct.Id); - var articleImage = TestData.GetArticleImage(createdProduct!.Id!.Value); + var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); var resultImage = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), articleImage); - var imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct!.Id!.Value)); + var imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct.Id.Value)); Assert.AreEqual(1, imagesResult.Data.Count); CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteArticleImage(id), resultImage.Data.Id); - imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct!.Id!.Value)); + imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct.Id.Value)); Assert.AreEqual(0, imagesResult.Data.Count); // cleanup CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - createdProduct!.Id!.Value); + createdProduct.Id.Value); } [TestMethod] @@ -451,8 +466,9 @@ public void DeleteArticleImage_IntegrationTest() public void DeleteMultipleArticleImages_IntegrationTest() { var createdProduct = _createProduct(); + Assert.IsNotNull(createdProduct.Id); - var articleImage = TestData.GetArticleImage(createdProduct!.Id!.Value); + var articleImage = TestData.GetArticleImage(createdProduct.Id.Value); var resultImage1 = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), articleImage); var resultImage2 = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), @@ -460,7 +476,7 @@ public void DeleteMultipleArticleImages_IntegrationTest() var resultImage3 = CrudHelpers.CreateApiResult(x => IntegrationTestHelpers.ApiClient.Products.AddArticleImage(x), articleImage); - var imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct!.Id!.Value)); + var imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct.Id.Value)); Assert.AreEqual(3, imagesResult.Data.Count); Console.WriteLine(); @@ -473,13 +489,13 @@ public void DeleteMultipleArticleImages_IntegrationTest() Assert.AreEqual(2, deleteResult.Data.Deleted.Count); Assert.AreEqual(0, deleteResult.Data.NotFound.Count); - imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct!.Id!.Value)); + imagesResult = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetArticleImages(createdProduct.Id.Value)); Assert.AreEqual(1, imagesResult.Data.Count); Assert.IsTrue(imagesResult.Data.Any(x => x.Id == resultImage3.Data.Id)); // cleanup CrudHelpers.DeleteOne((id) => IntegrationTestHelpers.ApiClient.Products.DeleteProduct(id), - createdProduct!.Id!.Value); + createdProduct.Id.Value); } private Product _createProduct(string sku = null!) From c8724d1c021e063010f57fbee721228ce2eb355e Mon Sep 17 00:00:00 2001 From: Benjamin Gottschalk Date: Tue, 9 Aug 2022 13:43:06 +0200 Subject: [PATCH 10/11] rename test-methods --- Billbee.Api.Client.Test/ApiClientTest.cs | 20 ++++---- Billbee.Api.Client.Test/ApiSyncTest.cs | 2 +- ...tomaticProvisionEndPointIntegrationTest.cs | 4 +- .../CloudStoragesEndPointIntegrationTest.cs | 2 +- ...ustomerAddressesEndPointIntegrationTest.cs | 10 ++-- .../CustomerEndPointIntegrationTest.cs | 20 ++++---- .../EnumEndPointIntegrationTest.cs | 19 ++++---- .../EventEndPointIntegrationTest.cs | 2 +- .../OrderEndPointIntegrationTest.cs | 38 +++++++-------- .../ProductEndPointIntegrationTest.cs | 42 ++++++++--------- .../SearchEndPointIntegrationTest.cs | 2 +- .../ShipmentEndPointIntegrationTest.cs | 10 ++-- .../WebhookEndPointIntegrationTest.cs | 14 +++--- .../AutomaticProvisionEndPointTest.cs | 4 +- .../CloudStoragesEndPointTest.cs | 2 +- .../CustomerAddressesEndPointTest.cs | 8 ++-- .../EndPointTests/CustomerEndPointTest.cs | 20 ++++---- .../EndPointTests/EnumEndPointTest.cs | 18 ++++---- .../EndPointTests/EventEndPointTest.cs | 2 +- .../EndPointTests/OrderEndPointTest.cs | 36 +++++++-------- .../EndPointTests/ProductEndPointTest.cs | 46 +++++++++---------- .../EndPointTests/SearchEndPointTest.cs | 2 +- .../EndPointTests/ShipmentEndPointTest.cs | 12 ++--- .../EndPointTests/WebhookEndPointTest.cs | 14 +++--- 24 files changed, 176 insertions(+), 173 deletions(-) diff --git a/Billbee.Api.Client.Test/ApiClientTest.cs b/Billbee.Api.Client.Test/ApiClientTest.cs index 73403fd..49983cc 100644 --- a/Billbee.Api.Client.Test/ApiClientTest.cs +++ b/Billbee.Api.Client.Test/ApiClientTest.cs @@ -9,7 +9,7 @@ namespace Billbee.Api.Client.Test; public class ApiClientTest { [TestMethod] - public void InitTest() + public void ApiClient_Init_Test() { var uut = new ApiClient(); @@ -33,7 +33,7 @@ public void InitTest() } [TestMethod] - public void InitWithConfigTest() + public void ApiClient_InitWithConfig_Test() { var config = new ApiConfiguration { @@ -56,7 +56,7 @@ public void InitWithConfigTest() } [TestMethod] - public void InitWithConfigFileTest() + public void ApiClient_InitWithConfigFile_Test() { var fiDll = new FileInfo(Assembly.GetExecutingAssembly().Location); Assert.IsNotNull(fiDll); @@ -90,18 +90,18 @@ public TypeMapping(string uutClass, string uutTypeName, string testTypeName, boo } [TestMethod] - public void UnitTestsForAllEndpointsTest() + public void CheckAllTests_UnitTestsForAllEndpointsTest() { - CheckTestMethods("Test", "Test"); + _checkTestMethods("Test", "_Test"); } [TestMethod] - public void IntegrationTestsForAllEndpointsTest() + public void CheckAllTests_IntegrationTestsForAllEndpointsTest() { - CheckTestMethods( "IntegrationTest", "_IntegrationTest"); + _checkTestMethods( "IntegrationTest", "_IntegrationTest"); } - private void CheckTestMethods(string testClassPostfix, string testMethodPostfix) + private void _checkTestMethods(string testClassPostfix, string testMethodPostfix) { var clientAssembly = Assembly.Load("Billbee.Api.Client"); var clientTypes = clientAssembly.GetTypes(); @@ -117,6 +117,8 @@ private void CheckTestMethods(string testClassPostfix, string testMethodPostfix) continue; } + var entityNamePrefix = clientTypeName.Substring(0, clientTypeName.IndexOf("EndPoint")) + "_"; + var testTypeName = clientType.Name + testClassPostfix; var testType = testTypes.FirstOrDefault(t => t.IsClass && t.IsPublic && t.Name == testTypeName && t.GetCustomAttributes().Any(a => a is TestClassAttribute)); Assert.IsNotNull(testType); @@ -128,7 +130,7 @@ private void CheckTestMethods(string testClassPostfix, string testMethodPostfix) { var clientMethodName = clientMethod.Name; - var testMethodName = clientMethodName + testMethodPostfix; + var testMethodName = entityNamePrefix + clientMethodName + testMethodPostfix; var foundMapping = testMethods.Any(t => t.Name == testMethodName); if (clientTypeName != nameof(EnumEndPoint)) { diff --git a/Billbee.Api.Client.Test/ApiSyncTest.cs b/Billbee.Api.Client.Test/ApiSyncTest.cs index 9cf485a..fb51f3a 100644 --- a/Billbee.Api.Client.Test/ApiSyncTest.cs +++ b/Billbee.Api.Client.Test/ApiSyncTest.cs @@ -20,7 +20,7 @@ public class ApiOperation } [TestMethod] - public async Task ApiSyncCheckTest() + public async Task Api_SyncCheck_Test() { var sdkOps = GetSdkOperations(); var apiOps = await GetApiOperations(); diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/AutomaticProvisionEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/AutomaticProvisionEndPointIntegrationTest.cs index 679fae1..fa8308b 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/AutomaticProvisionEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/AutomaticProvisionEndPointIntegrationTest.cs @@ -49,7 +49,7 @@ public void TestInitialize() [TestMethod] [RequiresApiAccess] - public void CreateAccount_IntegrationTest() + public void AutomaticProvision_CreateAccount_IntegrationTest() { var account = TestData.Account(Guid.NewGuid().ToString()); var result = @@ -62,7 +62,7 @@ public void CreateAccount_IntegrationTest() [TestMethod] [RequiresApiAccess] - public async Task TermsInfo_IntegrationTest() + public async Task AutomaticProvision_TermsInfo_IntegrationTest() { var result = IntegrationTestHelpers.ApiClient.AutomaticProvision.TermsInfo(); Assert.IsNotNull(result); diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/CloudStoragesEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/CloudStoragesEndPointIntegrationTest.cs index bec124a..7372f5c 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/CloudStoragesEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/CloudStoragesEndPointIntegrationTest.cs @@ -17,7 +17,7 @@ public void TestInitialize() [TestMethod] [RequiresApiAccess] - public void GetCloudStorageList_IntegrationTest() + public void CloudStorages_GetCloudStorageList_IntegrationTest() { CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.CloudStorages.GetCloudStorageList()); } diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs index 6aef6ab..347707f 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs @@ -45,7 +45,7 @@ public void TestInitialize() [TestMethod] [RequiresApiAccess] - public void GetCustomerAddresses_IntegrationTest() + public void CustomerAddresses_GetCustomerAddresses_IntegrationTest() { var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.CustomerAddresses.GetCustomerAddresses(1, 5)); Assert.IsNotNull(result); @@ -54,7 +54,7 @@ public void GetCustomerAddresses_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void GetCustomerAddress_IntegrationTest() + public void CustomerAddresses_GetCustomerAddress_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), @@ -72,14 +72,14 @@ public void GetCustomerAddress_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void AddCustomerAddress_IntegrationTest() + public void CustomerAddresses_AddCustomerAddress_IntegrationTest() { - GetCustomerAddress_IntegrationTest(); + CustomerAddresses_GetCustomerAddress_IntegrationTest(); } [TestMethod] [RequiresApiAccess] - public void UpdateCustomerAddress_IntegrationTest() + public void CustomerAddresses_UpdateCustomerAddress_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs index 3f5036f..03f3c6e 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs @@ -32,14 +32,14 @@ public void TestInitialize() [TestMethod] [RequiresApiAccess] - public void GetCustomerList_IntegrationTest() + public void Customer_GetCustomerList_IntegrationTest() { CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Customer.GetCustomerList(1, int.MaxValue)); } [TestMethod] [RequiresApiAccess] - public void AddCustomer_IntegrationTest() + public void Customer_AddCustomer_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); @@ -52,7 +52,7 @@ public void AddCustomer_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void AddAddressToCustomer_IntegrationTest() + public void Customer_AddAddressToCustomer_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); @@ -66,7 +66,7 @@ public void AddAddressToCustomer_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void GetCustomerAddress_IntegrationTest() + public void Customer_GetCustomerAddress_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); @@ -87,7 +87,7 @@ public void GetCustomerAddress_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void UpdateCustomerAddress_IntegrationTest() + public void Customer_UpdateCustomerAddress_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); @@ -112,7 +112,7 @@ public void UpdateCustomerAddress_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void PatchCustomerAddress_IntegrationTest() + public void Customer_PatchCustomerAddress_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); @@ -141,7 +141,7 @@ public void PatchCustomerAddress_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void GetCustomer_IntegrationTest() + public void Customer_GetCustomer_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); @@ -155,7 +155,7 @@ public void GetCustomer_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void UpdateCustomer_IntegrationTest() + public void Customer_UpdateCustomer_IntegrationTest() { var result = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); @@ -181,7 +181,7 @@ public void UpdateCustomer_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void GetOrdersForCustomer_IntegrationTest() + public void Customer_GetOrdersForCustomer_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); @@ -196,7 +196,7 @@ public void GetOrdersForCustomer_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void GetAddressesForCustomer_IntegrationTest() + public void Customer_GetAddressesForCustomer_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/EnumEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/EnumEndPointIntegrationTest.cs index 790d9ea..c04c821 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/EnumEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/EnumEndPointIntegrationTest.cs @@ -20,33 +20,34 @@ public void TestInitialize() [TestMethod] [RequiresApiAccess] - public void GetPaymentTypes_IntegrationTest() + [TestCategory("EnumEndPoint")] + public void Enum_GetPaymentTypes_IntegrationTest() { - ExecuteEnumSyncTest(x => x.GetPaymentTypes()); + _executeEnumSyncTest(x => x.GetPaymentTypes()); } [TestMethod] [RequiresApiAccess] - public void GetShippingCarriers_IntegrationTest() + public void Enum_GetShippingCarriers_IntegrationTest() { - ExecuteEnumSyncTest(x => x.GetShippingCarriers()); + _executeEnumSyncTest(x => x.GetShippingCarriers()); } [TestMethod] [RequiresApiAccess] - public void GetShipmentTypes_IntegrationTest() + public void Enum_GetShipmentTypes_IntegrationTest() { - ExecuteEnumSyncTest(x => x.GetShipmentTypes()); + _executeEnumSyncTest(x => x.GetShipmentTypes()); } [TestMethod] [RequiresApiAccess] - public void GetOrderStates_IntegrationTest() + public void Enum_GetOrderStates_IntegrationTest() { - ExecuteEnumSyncTest(x => x.GetOrderStates()); + _executeEnumSyncTest(x => x.GetOrderStates()); } - private void ExecuteEnumSyncTest(Func> endpointFunc) where T: struct, System.Enum + private void _executeEnumSyncTest(Func> endpointFunc) where T: struct, System.Enum { var apiEnumEntries = endpointFunc(IntegrationTestHelpers.ApiClient.Enums); diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/EventEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/EventEndPointIntegrationTest.cs index 2682f06..9f92c7f 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/EventEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/EventEndPointIntegrationTest.cs @@ -17,7 +17,7 @@ public void TestInitialize() [TestMethod] [RequiresApiAccess] - public void GetEvents_IntegrationTest() + public void Event_GetEvents_IntegrationTest() { var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Events.GetEvents()); Assert.IsTrue(result.Data.Count > 0); diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs index 27a03c3..9e51f10 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/OrderEndPointIntegrationTest.cs @@ -48,7 +48,7 @@ public void TestInitialize() [TestMethod] [RequiresApiAccess] - public void GetLayouts_IntegrationTest() + public void Order_GetLayouts_IntegrationTest() { var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Orders.GetLayouts()); Assert.IsNotNull(result); @@ -57,14 +57,14 @@ public void GetLayouts_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void GetOrder_IntegrationTest() + public void Order_GetOrder_IntegrationTest() { - PostNewOrder_IntegrationTest(); + Order_PostNewOrder_IntegrationTest(); } [TestMethod] [RequiresApiAccess] - public void GetPatchableFields_IntegrationTest() + public void Order_GetPatchableFields_IntegrationTest() { var patchableFields = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Orders.GetPatchableFields()); @@ -77,7 +77,7 @@ public void GetPatchableFields_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void PatchOrder_IntegrationTest() + public void Order_PatchOrder_IntegrationTest() { var order = _createOrder(); Assert.IsNotNull(order.BillBeeOrderId); @@ -96,7 +96,7 @@ public void PatchOrder_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void GetOrderByExternalReference_IntegrationTest() + public void Order_GetOrderByExternalReference_IntegrationTest() { var extRef = Guid.NewGuid().ToString(); var order = _createOrder(extRef); @@ -109,14 +109,14 @@ public void GetOrderByExternalReference_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void GetOrderByExternalIdAndPartner_IntegrationTest() + public void Order_GetOrderByExternalIdAndPartner_IntegrationTest() { Assert.Inconclusive(); } [TestMethod] [RequiresApiAccess] - public void GetOrderList_IntegrationTest() + public void Order_GetOrderList_IntegrationTest() { var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Orders.GetOrderList()); Assert.IsNotNull(result); @@ -125,7 +125,7 @@ public void GetOrderList_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void GetInvoiceList_IntegrationTest() + public void Order_GetInvoiceList_IntegrationTest() { var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Orders.GetInvoiceList()); Assert.IsNotNull(result); @@ -134,7 +134,7 @@ public void GetInvoiceList_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void PostNewOrder_IntegrationTest() + public void Order_PostNewOrder_IntegrationTest() { var order = _createOrder(); Assert.IsNotNull(order.BillBeeOrderId); @@ -147,14 +147,14 @@ public void PostNewOrder_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void AddTags_IntegrationTest() + public void Order_AddTags_IntegrationTest() { _createOrderWithTags(); } [TestMethod] [RequiresApiAccess] - public void UpdateTags_IntegrationTest() + public void Order_UpdateTags_IntegrationTest() { var order = _createOrderWithTags(); Assert.IsNotNull(order.BillBeeOrderId); @@ -176,7 +176,7 @@ public void UpdateTags_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void AddShipment_IntegrationTest() + public void Order_AddShipment_IntegrationTest() { var provider = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Shipment.GetShippingProvider()) .First(); @@ -200,7 +200,7 @@ public void AddShipment_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void CreateDeliveryNote_IntegrationTest() + public void Order_CreateDeliveryNote_IntegrationTest() { var order = _createOrder(); Assert.IsNotNull(order.BillBeeOrderId); @@ -212,7 +212,7 @@ public void CreateDeliveryNote_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void CreateInvoice_IntegrationTest() + public void Order_CreateInvoice_IntegrationTest() { var order = _createOrder(); Assert.IsNotNull(order.BillBeeOrderId); @@ -223,7 +223,7 @@ public void CreateInvoice_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void ChangeOrderState_IntegrationTest() + public void Order_ChangeOrderState_IntegrationTest() { var order = _createOrder(); Assert.IsNotNull(order.BillBeeOrderId); @@ -244,7 +244,7 @@ public void ChangeOrderState_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void SendMailForOrder_IntegrationTest() + public void Order_SendMailForOrder_IntegrationTest() { var order = _createOrder(); Assert.IsNotNull(order.BillBeeOrderId); @@ -273,7 +273,7 @@ public void SendMailForOrder_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void CreateEventAtOrder_IntegrationTest() + public void Order_CreateEventAtOrder_IntegrationTest() { var order = _createOrder(); Assert.IsNotNull(order.BillBeeOrderId); @@ -282,7 +282,7 @@ public void CreateEventAtOrder_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void ParsePlaceholders_IntegrationTest() + public void Order_ParsePlaceholders_IntegrationTest() { var order = _createOrder(); Assert.IsNotNull(order.BillBeeOrderId); diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs index 91a9b50..0bc4030 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs @@ -83,14 +83,14 @@ public void TestCleanup() [TestMethod] [RequiresApiAccess] - public void GetCategories_IntegrationTest() + public void Product_GetCategories_IntegrationTest() { CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetCategories()); } [TestMethod] [RequiresApiAccess] - public void AddProduct_IntegrationTest() + public void Product_AddProduct_IntegrationTest() { var result = CrudHelpers.CreateApiResult(w => IntegrationTestHelpers.ApiClient.Products.AddProduct(w), TestData.Product); @@ -107,7 +107,7 @@ public void AddProduct_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void DeleteProduct_IntegrationTest() + public void Product_DeleteProduct_IntegrationTest() { var createdProduct = _createProduct(); Assert.IsNotNull(createdProduct.Id); @@ -122,14 +122,14 @@ public void DeleteProduct_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void GetStocks_IntegrationTest() + public void Product_GetStocks_IntegrationTest() { CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetStocks()); } [TestMethod] [RequiresApiAccess] - public void UpdateStockMultiple_IntegrationTest() + public void Product_UpdateStockMultiple_IntegrationTest() { var product1 = _createProduct("4711"); Assert.IsNotNull(product1.Id); @@ -182,7 +182,7 @@ public void UpdateStockMultiple_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void UpdateStock_IntegrationTest() + public void Product_UpdateStock_IntegrationTest() { var createdProduct = _createProduct(); Assert.IsNotNull(createdProduct.Id); @@ -212,7 +212,7 @@ public void UpdateStock_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void GetReservedAmount_IntegrationTest() + public void Product_GetReservedAmount_IntegrationTest() { var createdProduct = _createProduct(); Assert.IsNotNull(createdProduct.Id); @@ -229,7 +229,7 @@ public void GetReservedAmount_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void UpdateStockCode_IntegrationTest() + public void Product_UpdateStockCode_IntegrationTest() { var createdProduct = _createProduct(); Assert.IsNotNull(createdProduct.Id); @@ -255,14 +255,14 @@ public void UpdateStockCode_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void GetProducts_IntegrationTest() + public void Product_GetProducts_IntegrationTest() { CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetProducts(1, int.MaxValue)); } [TestMethod] [RequiresApiAccess] - public void GetProduct_IntegrationTest() + public void Product_GetProduct_IntegrationTest() { var createdProduct = _createProduct(); Assert.IsNotNull(createdProduct.Id); @@ -277,14 +277,14 @@ public void GetProduct_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void GetCustomFields_IntegrationTest() + public void Product_GetCustomFields_IntegrationTest() { CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetCustomFields(1, int.MaxValue)); } [TestMethod] [RequiresApiAccess] - public void GetCustomField_IntegrationTest() + public void Product_GetCustomField_IntegrationTest() { var customField = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetCustomFields(1, int.MaxValue)).Data.FirstOrDefault(); Assert.IsNotNull(customField); @@ -296,7 +296,7 @@ public void GetCustomField_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void GetPatchableProductFields_IntegrationTest() + public void Product_GetPatchableProductFields_IntegrationTest() { var patchableFields = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Products.GetPatchableProductFields()); Console.WriteLine("Patchable Product Fields:"); @@ -308,7 +308,7 @@ public void GetPatchableProductFields_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void PatchArticle_IntegrationTest() + public void Product_PatchArticle_IntegrationTest() { var createdProduct = _createProduct(); Assert.IsNotNull(createdProduct.Id); @@ -331,7 +331,7 @@ public void PatchArticle_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void GetArticleImages_IntegrationTest() + public void Product_GetArticleImages_IntegrationTest() { var createdProduct = _createProduct(); Assert.IsNotNull(createdProduct.Id); @@ -350,7 +350,7 @@ public void GetArticleImages_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void GetArticleImage_IntegrationTest() + public void Product_GetArticleImage_IntegrationTest() { var createdProduct = _createProduct(); Assert.IsNotNull(createdProduct.Id); @@ -369,7 +369,7 @@ public void GetArticleImage_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void AddArticleImage_IntegrationTest() + public void Product_AddArticleImage_IntegrationTest() { var createdProduct = _createProduct(); Assert.IsNotNull(createdProduct.Id); @@ -386,7 +386,7 @@ public void AddArticleImage_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void UpdateArticleImage_IntegrationTest() + public void Product_UpdateArticleImage_IntegrationTest() { var createdProduct = _createProduct(); Assert.IsNotNull(createdProduct.Id); @@ -409,7 +409,7 @@ public void UpdateArticleImage_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void AddMultipleArticleImages_IntegrationTest() + public void Product_AddMultipleArticleImages_IntegrationTest() { var createdProduct = _createProduct(); Assert.IsNotNull(createdProduct.Id); @@ -438,7 +438,7 @@ public void AddMultipleArticleImages_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void DeleteArticleImage_IntegrationTest() + public void Product_DeleteArticleImage_IntegrationTest() { var createdProduct = _createProduct(); Assert.IsNotNull(createdProduct.Id); @@ -463,7 +463,7 @@ public void DeleteArticleImage_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void DeleteMultipleArticleImages_IntegrationTest() + public void Product_DeleteMultipleArticleImages_IntegrationTest() { var createdProduct = _createProduct(); Assert.IsNotNull(createdProduct.Id); diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/SearchEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/SearchEndPointIntegrationTest.cs index 5a41ffd..6d41b60 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/SearchEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/SearchEndPointIntegrationTest.cs @@ -21,7 +21,7 @@ public void TestInitialize() [TestMethod] [RequiresApiAccess] - public void SearchTerm_IntegrationTest() + public void Search_SearchTerm_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); Assert.IsNotNull(customer); diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/ShipmentEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/ShipmentEndPointIntegrationTest.cs index c9e6183..ac8fdb7 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/ShipmentEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/ShipmentEndPointIntegrationTest.cs @@ -77,21 +77,21 @@ public void TestInitialize() [TestMethod] [RequiresApiAccess] - public void GetShipments_IntegrationTest() + public void Shipment_GetShipments_IntegrationTest() { CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Shipment.GetShipments()); } [TestMethod] [RequiresApiAccess] - public void GetShippingProvider_IntegrationTest() + public void Shipment_GetShippingProvider_IntegrationTest() { CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Shipment.GetShippingProvider()); } [TestMethod] [RequiresApiAccess] - public void ShipOrderWithLabel_IntegrationTest() + public void Shipment_ShipOrderWithLabel_IntegrationTest() { var provider = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Shipment.GetShippingProvider()) .First(); @@ -113,7 +113,7 @@ public void ShipOrderWithLabel_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void PostShipment_IntegrationTest() + public void Shipment_PostShipment_IntegrationTest() { var provider = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Shipment.GetShippingProvider()) .First(); @@ -135,7 +135,7 @@ public void PostShipment_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void GetShippingCarriers_IntegrationTest() + public void Shipment_GetShippingCarriers_IntegrationTest() { CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Shipment.GetShippingCarriers()); } diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs index 95d2026..6f8417d 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/WebhookEndPointIntegrationTest.cs @@ -52,21 +52,21 @@ public void TestCleanup() [TestMethod] [RequiresApiAccess] - public void GetFilters_IntegrationTest() + public void Webhook_GetFilters_IntegrationTest() { CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetFilters()); } [TestMethod] [RequiresApiAccess] - public void GetWebhooks_IntegrationTest() + public void Webhook_GetWebhooks_IntegrationTest() { CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.Webhooks.GetWebhooks()); } [TestMethod] [RequiresApiAccess] - public void GetWebhook_IntegrationTest() + public void Webhook_GetWebhook_IntegrationTest() { var webhook = CrudHelpers.Create(w => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(w), TestData.WebHook); @@ -79,7 +79,7 @@ public void GetWebhook_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void CreateWebhook_IntegrationTest() + public void Webhook_CreateWebhook_IntegrationTest() { var webhook = CrudHelpers.Create(w => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(w), TestData.WebHook); @@ -92,7 +92,7 @@ public void CreateWebhook_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void DeleteAllWebhooks_IntegrationTest() + public void Webhook_DeleteAllWebhooks_IntegrationTest() { if (_countBeforeTest > 0) { @@ -115,7 +115,7 @@ public void DeleteAllWebhooks_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void DeleteWebhook_IntegrationTest() + public void Webhook_DeleteWebhook_IntegrationTest() { var webhook = CrudHelpers.Create(w => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(w), TestData.WebHook); @@ -133,7 +133,7 @@ public void DeleteWebhook_IntegrationTest() [TestMethod] [RequiresApiAccess] - public void UpdateWebhook_IntegrationTest() + public void Webhook_UpdateWebhook_IntegrationTest() { var webhook = CrudHelpers.Create(w => IntegrationTestHelpers.ApiClient.Webhooks.CreateWebhook(w), TestData.WebHook); diff --git a/Billbee.Api.Client.Test/EndPointTests/AutomaticProvisionEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/AutomaticProvisionEndPointTest.cs index 4703033..2206130 100644 --- a/Billbee.Api.Client.Test/EndPointTests/AutomaticProvisionEndPointTest.cs +++ b/Billbee.Api.Client.Test/EndPointTests/AutomaticProvisionEndPointTest.cs @@ -10,7 +10,7 @@ namespace Billbee.Api.Client.Test.EndPointTests; public class AutomaticProvisionEndPointTest { [TestMethod] - public void CreateAccountTest() + public void AutomaticProvision_CreateAccount_Test() { var testAccount = new Account(); var testCreateUserResult = new CreateUserResult @@ -31,7 +31,7 @@ public void CreateAccountTest() } [TestMethod] - public void TermsInfoTest() + public void AutomaticProvision_TermsInfo_Test() { var testTermsResult = new TermsResult(); diff --git a/Billbee.Api.Client.Test/EndPointTests/CloudStoragesEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/CloudStoragesEndPointTest.cs index 529a607..cef4eb8 100644 --- a/Billbee.Api.Client.Test/EndPointTests/CloudStoragesEndPointTest.cs +++ b/Billbee.Api.Client.Test/EndPointTests/CloudStoragesEndPointTest.cs @@ -10,7 +10,7 @@ namespace Billbee.Api.Client.Test.EndPointTests; public class CloudStoragesEndPointTest { [TestMethod] - public void GetCloudStorageListTest() + public void CloudStorages_GetCloudStorageList_Test() { var testCloudStorage = new CloudStorage(); diff --git a/Billbee.Api.Client.Test/EndPointTests/CustomerAddressesEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/CustomerAddressesEndPointTest.cs index d4d7bb6..03f8ce5 100644 --- a/Billbee.Api.Client.Test/EndPointTests/CustomerAddressesEndPointTest.cs +++ b/Billbee.Api.Client.Test/EndPointTests/CustomerAddressesEndPointTest.cs @@ -9,7 +9,7 @@ namespace Billbee.Api.Client.Test.EndPointTests; public class CustomerAddressesEndPointTest { [TestMethod] - public void GetCustomerAddressesTest() + public void CustomerAddresses_GetCustomerAddresses_Test() { var testCustomerAddress = new CustomerAddress { Id = 4711 }; var page = 1; @@ -31,7 +31,7 @@ public void GetCustomerAddressesTest() } [TestMethod] - public void GetCustomerAddressTest() + public void CustomerAddresses_GetCustomerAddress_Test() { var testCustomerAddress = new CustomerAddress { Id = 4711 }; @@ -46,7 +46,7 @@ public void GetCustomerAddressTest() } [TestMethod] - public void AddCustomerAddressTest() + public void CustomerAddresses_AddCustomerAddress_Test() { var testCustomerAddress = new CustomerAddress { Id = 4711 }; @@ -61,7 +61,7 @@ public void AddCustomerAddressTest() } [TestMethod] - public void UpdateCustomerAddressTest() + public void CustomerAddresses_UpdateCustomerAddress_Test() { var testCustomerAddress = new CustomerAddress { Id = 4711 }; diff --git a/Billbee.Api.Client.Test/EndPointTests/CustomerEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/CustomerEndPointTest.cs index 5d92009..b4fe8c3 100644 --- a/Billbee.Api.Client.Test/EndPointTests/CustomerEndPointTest.cs +++ b/Billbee.Api.Client.Test/EndPointTests/CustomerEndPointTest.cs @@ -10,7 +10,7 @@ namespace Billbee.Api.Client.Test.EndPointTests; public class CustomerEndPointTest { [TestMethod] - public void GetCustomerListTest() + public void Customer_GetCustomerList_Test() { var testCustomer = new Customer { Id = 4711 }; var page = 1; @@ -32,7 +32,7 @@ public void GetCustomerListTest() } [TestMethod] - public void AddCustomerTest() + public void Customer_AddCustomer_Test() { var testCustomer = new Customer { Id = 4711 }; var customerForCreation = new CustomerForCreation(); @@ -48,7 +48,7 @@ public void AddCustomerTest() } [TestMethod] - public void GetCustomerTest() + public void Customer_GetCustomer_Test() { var testCustomer = new Customer { Id = 4711 }; @@ -63,7 +63,7 @@ public void GetCustomerTest() } [TestMethod] - public void UpdateCustomerTest() + public void Customer_UpdateCustomer_Test() { var testCustomer = new Customer { Id = 4711 }; @@ -83,7 +83,7 @@ public void UpdateCustomerTest() } [TestMethod] - public void GetOrdersForCustomerTest() + public void Customer_GetOrdersForCustomer_Test() { var testCustomer = new Customer { Id = 4711 }; var testOrder = new Order(); @@ -107,7 +107,7 @@ public void GetOrdersForCustomerTest() } [TestMethod] - public void GetAddressesForCustomerTest() + public void Customer_GetAddressesForCustomer_Test() { var testCustomer = new Customer { Id = 4711 }; var testCustomerAddress = new CustomerAddress(); @@ -131,7 +131,7 @@ public void GetAddressesForCustomerTest() } [TestMethod] - public void AddAddressToCustomerTest() + public void Customer_AddAddressToCustomer_Test() { var testCustomer = new Customer { Id = 4711 }; var testCustomerAddress = new CustomerAddress { Id = 4712, CustomerId = testCustomer.Id }; @@ -146,7 +146,7 @@ public void AddAddressToCustomerTest() } [TestMethod] - public void GetCustomerAddressTest() + public void Customer_GetCustomerAddress_Test() { var testCustomerAddress = new CustomerAddress { Id = 4711 }; @@ -161,7 +161,7 @@ public void GetCustomerAddressTest() } [TestMethod] - public void UpdateCustomerAddressTest() + public void Customer_UpdateCustomerAddress_Test() { var testCustomerAddress = new CustomerAddress { Id = 4711 }; @@ -177,7 +177,7 @@ public void UpdateCustomerAddressTest() [TestMethod] - public void PatchCustomerAddressTest() + public void Customer_PatchCustomerAddress_Test() { var testCustomerAddress = new CustomerAddress { Id = 4711 }; diff --git a/Billbee.Api.Client.Test/EndPointTests/EnumEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/EnumEndPointTest.cs index 6b20d45..2e6293f 100644 --- a/Billbee.Api.Client.Test/EndPointTests/EnumEndPointTest.cs +++ b/Billbee.Api.Client.Test/EndPointTests/EnumEndPointTest.cs @@ -10,30 +10,30 @@ namespace Billbee.Api.Client.Test.EndPointTests; public class EnumEndPointTest { [TestMethod] - public void GetPaymentTypesTest() + public void Enum_GetPaymentTypes_Test() { - ExecuteEnumTest("paymenttypes", x => x.GetPaymentTypes()); + _executeEnumTest("paymenttypes", x => x.GetPaymentTypes()); } [TestMethod] - public void GetShippingCarriersTest() + public void Enum_GetShippingCarriers_Test() { - ExecuteEnumTest("shippingcarriers", x => x.GetShippingCarriers()); + _executeEnumTest("shippingcarriers", x => x.GetShippingCarriers()); } [TestMethod] - public void GetShipmentTypesTest() + public void Enum_GetShipmentTypes_Test() { - ExecuteEnumTest("shipmenttypes", x => x.GetShipmentTypes()); + _executeEnumTest("shipmenttypes", x => x.GetShipmentTypes()); } [TestMethod] - public void GetOrderStatesTest() + public void Enum_GetOrderStates_Test() { - ExecuteEnumTest("orderstates", x => x.GetOrderStates()); + _executeEnumTest("orderstates", x => x.GetOrderStates()); } - private void ExecuteEnumTest(string endpoint, Func> endpointFunc) + private void _executeEnumTest(string endpoint, Func> endpointFunc) { var testEnumEntryList = new List { diff --git a/Billbee.Api.Client.Test/EndPointTests/EventEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/EventEndPointTest.cs index 41c0d76..3eec556 100644 --- a/Billbee.Api.Client.Test/EndPointTests/EventEndPointTest.cs +++ b/Billbee.Api.Client.Test/EndPointTests/EventEndPointTest.cs @@ -11,7 +11,7 @@ namespace Billbee.Api.Client.Test.EndPointTests; public class EventEndPointTest { [TestMethod] - public void GetEventsTest() + public void Event_GetEvents_Test() { var testEvent = new Event(); DateTime? minDate = DateTime.Now.AddDays(-2); diff --git a/Billbee.Api.Client.Test/EndPointTests/OrderEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/OrderEndPointTest.cs index ff9e49a..1f1e14e 100644 --- a/Billbee.Api.Client.Test/EndPointTests/OrderEndPointTest.cs +++ b/Billbee.Api.Client.Test/EndPointTests/OrderEndPointTest.cs @@ -12,7 +12,7 @@ namespace Billbee.Api.Client.Test.EndPointTests; public class OrderEndPointTest { [TestMethod] - public void GetOrderTest() + public void Order_GetOrder_Test() { var testOrder = new Order(); var id = "4711"; @@ -29,7 +29,7 @@ public void GetOrderTest() } [TestMethod] - public void GetPatchableFieldsTest() + public void Order_GetPatchableFields_Test() { Expression> expression = x => x.Get>>($"/orders/PatchableFields", null); object mockResult = TestHelpers.GetApiResult( new List { "SellerComment", "Foo" }); @@ -42,7 +42,7 @@ public void GetPatchableFieldsTest() } [TestMethod] - public void PatchOrderTest() + public void Order_PatchOrder_Test() { var orderId = 4711; var fieldsToPatch = new Dictionary @@ -61,7 +61,7 @@ public void PatchOrderTest() } [TestMethod] - public void GetOrderByExternalReferenceTest() + public void Order_GetOrderByExternalReference_Test() { var testOrder = new Order(); var extRef = "extRef"; @@ -77,7 +77,7 @@ public void GetOrderByExternalReferenceTest() } [TestMethod] - public void GetOrderByExternalIdAndPartnerTest() + public void Order_GetOrderByExternalIdAndPartner_Test() { var testOrder = new Order(); var partner = "thePartner"; @@ -94,7 +94,7 @@ public void GetOrderByExternalIdAndPartnerTest() } [TestMethod] - public void GetOrderListTest() + public void Order_GetOrderList_Test() { var testOrder = new Order(); DateTime? minOrderDate = DateTime.Now.AddDays(-2); @@ -147,7 +147,7 @@ public void GetOrderListTest() } [TestMethod] - public void GetInvoiceListTest() + public void Order_GetInvoiceList_Test() { var testInvoiceDetail = new InvoiceDetail(); DateTime? minInvoiceDate = DateTime.Now.AddDays(-2); @@ -201,7 +201,7 @@ public void GetInvoiceListTest() [TestMethod] - public void PostNewOrderTest() + public void Order_PostNewOrder_Test() { var testOrder = new Order(); var testOrderResult = new OrderResult(); @@ -219,7 +219,7 @@ public void PostNewOrderTest() } [TestMethod] - public void AddTagsTest() + public void Order_AddTags_Test() { var orderId = 4711; var tags = new List { "tag1", "tag2" }; @@ -235,7 +235,7 @@ public void AddTagsTest() } [TestMethod] - public void UpdateTagsTest() + public void Order_UpdateTags_Test() { var orderId = 4711; var tags = new List { "tag1", "tag2" }; @@ -251,7 +251,7 @@ public void UpdateTagsTest() } [TestMethod] - public void AddShipmentTest() + public void Order_AddShipment_Test() { var testOrderShipment = new OrderShipment(); @@ -265,7 +265,7 @@ public void AddShipmentTest() } [TestMethod] - public void CreateDeliveryNoteTest() + public void Order_CreateDeliveryNote_Test() { var orderId = 4711; var includePdf = true; @@ -287,7 +287,7 @@ public void CreateDeliveryNoteTest() } [TestMethod] - public void CreateInvoiceTest() + public void Order_CreateInvoice_Test() { var orderId = 4711; var includePdf = true; @@ -310,7 +310,7 @@ public void CreateInvoiceTest() } [TestMethod] - public void ChangeOrderStateTest() + public void Order_ChangeOrderState_Test() { var orderId = 4711; @@ -324,7 +324,7 @@ public void ChangeOrderStateTest() } [TestMethod] - public void SendMailForOrderTest() + public void Order_SendMailForOrder_Test() { var testSendMessage = new SendMessage(); var orderId = 4711; @@ -337,7 +337,7 @@ public void SendMailForOrderTest() } [TestMethod] - public void CreateEventAtOrderTest() + public void Order_CreateEventAtOrder_Test() { var restClientMock = new Mock(); var uut = new OrderEndPoint(restClientMock.Object); @@ -351,7 +351,7 @@ public void CreateEventAtOrderTest() } [TestMethod] - public void GetLayoutsTest() + public void Order_GetLayouts_Test() { var testLayoutList = new List { @@ -371,7 +371,7 @@ public void GetLayoutsTest() } [TestMethod] - public void ParsePlaceholdersTest() + public void Order_ParsePlaceholders_Test() { var restClientMock = new Mock(); var uut = new OrderEndPoint(restClientMock.Object); diff --git a/Billbee.Api.Client.Test/EndPointTests/ProductEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/ProductEndPointTest.cs index 2f98f2d..f5aae49 100644 --- a/Billbee.Api.Client.Test/EndPointTests/ProductEndPointTest.cs +++ b/Billbee.Api.Client.Test/EndPointTests/ProductEndPointTest.cs @@ -12,7 +12,7 @@ namespace Billbee.Api.Client.Test.EndPointTests; public class ProductEndPointTest { [TestMethod] - public void GetStocksTest() + public void Product_GetStocks_Test() { var testStock = new Stock(); @@ -28,7 +28,7 @@ public void GetStocksTest() } [TestMethod] - public void UpdateStockMultipleTest() + public void Product_UpdateStockMultiple_Test() { var testCurrentStockInfo = new CurrentStockInfo(); var testUpdateStock = new UpdateStock(); @@ -45,7 +45,7 @@ public void UpdateStockMultipleTest() } [TestMethod] - public void UpdateStockTest() + public void Product_UpdateStock_Test() { var testCurrentStockInfo = new CurrentStockInfo(); var testUpdateStock = new UpdateStock(); @@ -62,7 +62,7 @@ public void UpdateStockTest() } [TestMethod] - public void GetReservedAmountTest() + public void Product_GetReservedAmount_Test() { var testGetReservedAmountResult = new GetReservedAmountResult(); @@ -88,7 +88,7 @@ public void GetReservedAmountTest() } [TestMethod] - public void UpdateStockCodeTest() + public void Product_UpdateStockCode_Test() { var testUpdateStockCode = new UpdateStockCode(); @@ -104,7 +104,7 @@ public void UpdateStockCodeTest() } [TestMethod] - public void GetProductsTest() + public void Product_GetProducts_Test() { var testProduct = new Product(); int page = 1; @@ -129,7 +129,7 @@ public void GetProductsTest() } [TestMethod] - public void GetProductTest() + public void Product_GetProduct_Test() { var testProduct = new Product(); string id = "4711"; @@ -148,7 +148,7 @@ public void GetProductTest() } [TestMethod] - public void GetCustomFieldsTest() + public void Product_GetCustomFields_Test() { var testArticleCustomFieldDefinition = new ArticleCustomFieldDefinition(); int page = 1; @@ -171,7 +171,7 @@ public void GetCustomFieldsTest() } [TestMethod] - public void GetCustomFieldTest() + public void Product_GetCustomField_Test() { var testArticleCustomFieldDefinition = new ArticleCustomFieldDefinition(); long id = 4711; @@ -188,7 +188,7 @@ public void GetCustomFieldTest() } [TestMethod] - public void GetPatchableProductFieldsTest() + public void Product_GetPatchableProductFields_Test() { Expression> expression = x => x.Get>>($"/products/PatchableFields", null); var mockResult = TestHelpers.GetApiResult(new List { "foo", "bar" }); @@ -202,7 +202,7 @@ public void GetPatchableProductFieldsTest() } [TestMethod] - public void PatchArticleTest() + public void Product_PatchArticle_Test() { var testProduct = new Product(); long id = 4711; @@ -220,7 +220,7 @@ public void PatchArticleTest() } [TestMethod] - public void GetArticleImagesTest() + public void Product_GetArticleImages_Test() { var testArticleImage = new ArticleImage(); long id = 4711; @@ -237,7 +237,7 @@ public void GetArticleImagesTest() } [TestMethod] - public void GetArticleImageTest() + public void Product_GetArticleImage_Test() { var testArticleImage = new ArticleImage(); long articleId = 4711; @@ -255,7 +255,7 @@ public void GetArticleImageTest() } [TestMethod] - public void GetArticleImage2Test() + public void Product_GetArticleImage2_Test() { var testArticleImage = new ArticleImage(); long imageId = 4712; @@ -272,7 +272,7 @@ public void GetArticleImage2Test() } [TestMethod] - public void AddArticleImageTest() + public void Product_AddArticleImage_Test() { var testArticleImage = new ArticleImage { Id = 0, ArticleId = 4712 }; @@ -288,7 +288,7 @@ public void AddArticleImageTest() } [TestMethod] - public void UpdateArticleImageTest() + public void Product_UpdateArticleImage_Test() { var testArticleImage = new ArticleImage { Id = 4711, ArticleId = 4712 }; @@ -304,7 +304,7 @@ public void UpdateArticleImageTest() } [TestMethod] - public void AddMultipleArticleImagesTest() + public void Product_AddMultipleArticleImages_Test() { var testArticleImage = new ArticleImage { Id = 4711, ArticleId = 4712 }; var images = new List { testArticleImage }; @@ -323,7 +323,7 @@ public void AddMultipleArticleImagesTest() } [TestMethod] - public void DeleteArticleImageTest() + public void Product_DeleteArticleImage_Test() { long articleId = 4711; long imageId = 4712; @@ -335,7 +335,7 @@ public void DeleteArticleImageTest() } [TestMethod] - public void DeleteArticleImage2Test() + public void Product_DeleteArticleImage2_Test() { long imageId = 4712; @@ -346,7 +346,7 @@ public void DeleteArticleImage2Test() } [TestMethod] - public void DeleteMultipleArticleImagesTest() + public void Product_DeleteMultipleArticleImages_Test() { var testDeletedImages = new DeletedImages(); var imageIds = new List { 4711, 4712 }; @@ -363,7 +363,7 @@ public void DeleteMultipleArticleImagesTest() } [TestMethod] - public void AddProductTest() + public void Product_AddProduct_Test() { var testProduct = new Product(); @@ -379,7 +379,7 @@ public void AddProductTest() } [TestMethod] - public void DeleteProductTest() + public void Product_DeleteProduct_Test() { long productId = 4712; @@ -390,7 +390,7 @@ public void DeleteProductTest() } [TestMethod] - public void GetCategoriesTest() + public void Product_GetCategories_Test() { var testCategoryList = new List { diff --git a/Billbee.Api.Client.Test/EndPointTests/SearchEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/SearchEndPointTest.cs index 6a6020c..af81f52 100644 --- a/Billbee.Api.Client.Test/EndPointTests/SearchEndPointTest.cs +++ b/Billbee.Api.Client.Test/EndPointTests/SearchEndPointTest.cs @@ -12,7 +12,7 @@ public class SearchEndPointTest private static SearchResult CreateTestSearchResult() => new(); [TestMethod] - public void SearchTermTest() + public void Search_SearchTerm_Test() { var testSearchResult = CreateTestSearchResult(); var search = new Search diff --git a/Billbee.Api.Client.Test/EndPointTests/ShipmentEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/ShipmentEndPointTest.cs index 02a6899..315f5a5 100644 --- a/Billbee.Api.Client.Test/EndPointTests/ShipmentEndPointTest.cs +++ b/Billbee.Api.Client.Test/EndPointTests/ShipmentEndPointTest.cs @@ -12,7 +12,7 @@ namespace Billbee.Api.Client.Test.EndPointTests; public class ShipmentEndPointTest { [TestMethod] - public void GetShippingProviderTest() + public void Shipment_GetShippingProvider_Test() { var testShippingProvider = new ShippingProvider(); @@ -27,7 +27,7 @@ public void GetShippingProviderTest() } [TestMethod] - public void GetShipmentsTest() + public void Shipment_GetShipments_Test() { var testShipment = new Shipment(); @@ -42,7 +42,7 @@ public void GetShipmentsTest() } [TestMethod] - public void PostShipmentTest() + public void Shipment_PostShipment_Test() { var testShipmentResult = new ShipmentResult(); var testPostShipment = new PostShipment(); @@ -58,7 +58,7 @@ public void PostShipmentTest() } [TestMethod] - public void ShipOrderWithLabelTest() + public void Shipment_ShipOrderWithLabel_Test() { var testShipmentWithLabel = new ShipmentWithLabel(); var testShipmentWithLabelResult = new ShipmentWithLabelResult(); @@ -74,7 +74,7 @@ public void ShipOrderWithLabelTest() } [TestMethod] - public void GetShippingCarriersTest() + public void Shipment_GetShippingCarriers_Test() { var testShippingCarrier = new ShippingCarrier(); @@ -89,7 +89,7 @@ public void GetShippingCarriersTest() } [TestMethod] - public void PingTest() + public void Shipment_Ping_Test() { var restClientMock = new Mock(); restClientMock diff --git a/Billbee.Api.Client.Test/EndPointTests/WebhookEndPointTest.cs b/Billbee.Api.Client.Test/EndPointTests/WebhookEndPointTest.cs index f8de192..0ace527 100644 --- a/Billbee.Api.Client.Test/EndPointTests/WebhookEndPointTest.cs +++ b/Billbee.Api.Client.Test/EndPointTests/WebhookEndPointTest.cs @@ -32,7 +32,7 @@ private static Webhook CreateTestWebHook() }; [TestMethod] - public void GetWebhooksTest() + public void Webhook_GetWebhooks_Test() { var testWebHook = CreateTestWebHook(); @@ -49,7 +49,7 @@ public void GetWebhooksTest() } [TestMethod] - public void GetWebhookTest() + public void Webhook_GetWebhook_Test() { var testWebHook = CreateTestWebHook(); @@ -64,7 +64,7 @@ public void GetWebhookTest() } [TestMethod] - public void GetFiltersTest() + public void Webhook_GetFilters_Test() { Expression> expression = x => x.Get>("/webhooks/filters", null); object mockResult = new List { TestWebHookFilter }; @@ -77,7 +77,7 @@ public void GetFiltersTest() } [TestMethod] - public void DeleteAllWebhooksTest() + public void Webhook_DeleteAllWebhooks_Test() { var restClientMock = new Mock(); restClientMock @@ -90,7 +90,7 @@ public void DeleteAllWebhooksTest() } [TestMethod] - public void DeleteWebhookTest() + public void Webhook_DeleteWebhook_Test() { var testWebHook = CreateTestWebHook(); var restClientMock = new Mock(); @@ -104,7 +104,7 @@ public void DeleteWebhookTest() } [TestMethod] - public void UpdateWebhookTest() + public void Webhook_UpdateWebhook_Test() { var testWebHook = CreateTestWebHook(); var restClientMock = new Mock(); @@ -118,7 +118,7 @@ public void UpdateWebhookTest() } [TestMethod] - public void CreateWebhookTest() + public void Webhook_CreateWebhook_Test() { var testWebHook = CreateTestWebHook(); testWebHook.Id = "4711"; From 14b884445ef53aec6816816a494a5e9a57246946 Mon Sep 17 00:00:00 2001 From: Benjamin Gottschalk Date: Thu, 11 Aug 2022 11:56:37 +0200 Subject: [PATCH 11/11] rework due to PR-Review --- ...ustomerAddressesEndPointIntegrationTest.cs | 4 +--- .../CustomerEndPointIntegrationTest.cs | 19 +------------------ .../ProductEndPointIntegrationTest.cs | 2 +- Billbee.Api.Client.Test/TestHelpers.cs | 1 - Billbee.Api.Client/Model/CustomerAddress.cs | 9 +-------- 5 files changed, 4 insertions(+), 31 deletions(-) diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs index 347707f..3240a87 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerAddressesEndPointIntegrationTest.cs @@ -47,9 +47,7 @@ public void TestInitialize() [RequiresApiAccess] public void CustomerAddresses_GetCustomerAddresses_IntegrationTest() { - var result = CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.CustomerAddresses.GetCustomerAddresses(1, 5)); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Data); + CrudHelpers.GetAll(() => IntegrationTestHelpers.ApiClient.CustomerAddresses.GetCustomerAddresses(1, 5)); } [TestMethod] diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs index 03f3c6e..e20c5dc 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/CustomerEndPointIntegrationTest.cs @@ -70,8 +70,6 @@ public void Customer_GetCustomerAddress_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); - Assert.IsNotNull(customer); - Assert.IsNotNull(customer.Data); Assert.IsNotNull(customer.Data.Id); var address = CrudHelpers.GetAll(() => @@ -91,8 +89,6 @@ public void Customer_UpdateCustomerAddress_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); - Assert.IsNotNull(customer); - Assert.IsNotNull(customer.Data); Assert.IsNotNull(customer.Data.Id); var address = CrudHelpers.GetAll(() => @@ -116,8 +112,6 @@ public void Customer_PatchCustomerAddress_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); - Assert.IsNotNull(customer); - Assert.IsNotNull(customer.Data); Assert.IsNotNull(customer.Data.Id); var address = CrudHelpers.GetAll(() => @@ -145,8 +139,6 @@ public void Customer_GetCustomer_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); - Assert.IsNotNull(customer); - Assert.IsNotNull(customer.Data); Assert.IsNotNull(customer.Data.Id); CrudHelpers.GetOneApiResult((id) => IntegrationTestHelpers.ApiClient.Customer.GetCustomer(id), @@ -159,15 +151,11 @@ public void Customer_UpdateCustomer_IntegrationTest() { var result = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); - Assert.IsNotNull(result); - Assert.IsNotNull(result.Data); Assert.IsNotNull(result.Data.Id); result = CrudHelpers.GetOneApiResult( (id) => IntegrationTestHelpers.ApiClient.Customer.GetCustomer(id), result.Data.Id.Value); var customer = result.Data; - Assert.IsNotNull(result); - Assert.IsNotNull(result.Data); Assert.IsNotNull(result.Data.Id); Assert.AreNotEqual("Modified", customer.Name); @@ -185,13 +173,10 @@ public void Customer_GetOrdersForCustomer_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); - Assert.IsNotNull(customer); - Assert.IsNotNull(customer.Data); Assert.IsNotNull(customer.Data.Id); CrudHelpers.GetAll(() => - IntegrationTestHelpers.ApiClient.Customer.GetOrdersForCustomer(customer.Data.Id.Value, 1, 5)).Data - .FirstOrDefault(); + IntegrationTestHelpers.ApiClient.Customer.GetOrdersForCustomer(customer.Data.Id.Value, 1, 5)); } [TestMethod] @@ -200,8 +185,6 @@ public void Customer_GetAddressesForCustomer_IntegrationTest() { var customer = CrudHelpers.CreateApiResult(c => IntegrationTestHelpers.ApiClient.Customer.AddCustomer(c), TestData.Customer); - Assert.IsNotNull(customer); - Assert.IsNotNull(customer.Data); Assert.IsNotNull(customer.Data.Id); var result = CrudHelpers.GetAll(() => diff --git a/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs b/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs index 0bc4030..485c1cd 100644 --- a/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs +++ b/Billbee.Api.Client.Test/EndPointIntegrationTests/ProductEndPointIntegrationTest.cs @@ -187,7 +187,7 @@ public void Product_UpdateStock_IntegrationTest() var createdProduct = _createProduct(); Assert.IsNotNull(createdProduct.Id); - Assert.AreEqual(null, createdProduct.StockCurrent); + Assert.IsNull(createdProduct.StockCurrent); var updateStock = new UpdateStock { diff --git a/Billbee.Api.Client.Test/TestHelpers.cs b/Billbee.Api.Client.Test/TestHelpers.cs index 1528a16..741812c 100644 --- a/Billbee.Api.Client.Test/TestHelpers.cs +++ b/Billbee.Api.Client.Test/TestHelpers.cs @@ -1,5 +1,4 @@ using System.Linq.Expressions; -using System.Reflection; using Billbee.Api.Client.Model; using Moq; diff --git a/Billbee.Api.Client/Model/CustomerAddress.cs b/Billbee.Api.Client/Model/CustomerAddress.cs index 1885ffb..63fce10 100644 --- a/Billbee.Api.Client/Model/CustomerAddress.cs +++ b/Billbee.Api.Client/Model/CustomerAddress.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Billbee.Api.Client.Enums; - -namespace Billbee.Api.Client.Model +namespace Billbee.Api.Client.Model { public class CustomerAddress {