From 07b05bbbb4027f380094178647ee5c00402ecf50 Mon Sep 17 00:00:00 2001 From: Mikhail Rassudishkin <80324838+mrassudishkin@users.noreply.github.com> Date: Tue, 29 Aug 2023 20:25:25 +0300 Subject: [PATCH] VT-6136 Shopify: Shopify quantity not matching quantity in SV (#34) * VT-6136 : ignore case for enum * 1.9.0.0 * VT-6136 : updated to TestCase * VT-6136 : added more tests for Blank --- src/Global/GlobalAssemblyInfo.cs | 2 +- .../ProductVariant/ShopifyProductVariant.cs | 2 +- .../Models/ShopifyProductVariantTests.cs | 42 +++++++++++++++++++ .../ShopifyAccessTests.csproj | 1 + 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/ShopifyAccessTests/ShopifyAccessTests/Products/Models/ShopifyProductVariantTests.cs diff --git a/src/Global/GlobalAssemblyInfo.cs b/src/Global/GlobalAssemblyInfo.cs index 4170c5f..ba28f97 100644 --- a/src/Global/GlobalAssemblyInfo.cs +++ b/src/Global/GlobalAssemblyInfo.cs @@ -22,4 +22,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[ assembly : AssemblyVersion( "1.8.0.0" ) ] \ No newline at end of file +[ assembly : AssemblyVersion( "1.9.0.0" ) ] \ No newline at end of file diff --git a/src/ShopifyAccess/Models/ProductVariant/ShopifyProductVariant.cs b/src/ShopifyAccess/Models/ProductVariant/ShopifyProductVariant.cs index a57a680..f63d1fa 100644 --- a/src/ShopifyAccess/Models/ProductVariant/ShopifyProductVariant.cs +++ b/src/ShopifyAccess/Models/ProductVariant/ShopifyProductVariant.cs @@ -19,7 +19,7 @@ public InventoryManagementEnum InventoryManagement { get { - if ( Enum.TryParse< InventoryManagementEnum >( RawInventoryManagement, out var inventoryManagement ) ) + if ( Enum.TryParse< InventoryManagementEnum >( RawInventoryManagement, true, out var inventoryManagement ) ) { return inventoryManagement; } diff --git a/src/ShopifyAccessTests/ShopifyAccessTests/Products/Models/ShopifyProductVariantTests.cs b/src/ShopifyAccessTests/ShopifyAccessTests/Products/Models/ShopifyProductVariantTests.cs new file mode 100644 index 0000000..abb7ff4 --- /dev/null +++ b/src/ShopifyAccessTests/ShopifyAccessTests/Products/Models/ShopifyProductVariantTests.cs @@ -0,0 +1,42 @@ +using FluentAssertions; +using NUnit.Framework; +using ServiceStack.Text; +using ShopifyAccess.Models.ProductVariant; + +namespace ShopifyAccessTests.Products.Models +{ + [ TestFixture ] + public class ShopifyProductVariantTests + { + [ TestCase( "" ) ] + [ TestCase( null ) ] + [ TestCase( "Blank" ) ] + [ TestCase( "blank" ) ] + [ TestCase( "strange_status" ) ] + public void Deserialize_ReturnsBlankInventoryManagement( string rawInventoryManagement ) + { + // Arrange + var json = "{\"id\":1,\"inventory_management\":\"" + rawInventoryManagement + "\",\"inventory_item_id\":0,\"weight\":0,\"price\":0,\"updated_at\":\"\\/Date(-62135596800000-0000)\\/\"}"; + + // Act + var shopifyProductVariant = JsonSerializer.DeserializeFromString< ShopifyProductVariant >( json ); + + // Assert + shopifyProductVariant.InventoryManagement.Should().Be( InventoryManagementEnum.Blank ); + } + + [ TestCase( "Shopify" ) ] + [ TestCase( "shopify" ) ] + public void Deserialize_ReturnsShopifyInventoryManagement( string rawInventoryManagement ) + { + // Arrange + var json = "{\"id\":1,\"inventory_management\":\"" + rawInventoryManagement + "\",\"inventory_item_id\":0,\"weight\":0,\"price\":0,\"updated_at\":\"\\/Date(-62135596800000-0000)\\/\"}"; + + // Act + var shopifyProductVariant = JsonSerializer.DeserializeFromString< ShopifyProductVariant >( json ); + + // Assert + shopifyProductVariant.InventoryManagement.Should().Be( InventoryManagementEnum.Shopify ); + } + } +} \ No newline at end of file diff --git a/src/ShopifyAccessTests/ShopifyAccessTests/ShopifyAccessTests.csproj b/src/ShopifyAccessTests/ShopifyAccessTests/ShopifyAccessTests.csproj index 2598844..84aef1d 100644 --- a/src/ShopifyAccessTests/ShopifyAccessTests/ShopifyAccessTests.csproj +++ b/src/ShopifyAccessTests/ShopifyAccessTests/ShopifyAccessTests.csproj @@ -109,6 +109,7 @@ +