Skip to content

Commit

Permalink
Added fix and regression test for issue SevenSpikes#11
Browse files Browse the repository at this point in the history
  • Loading branch information
poyker committed Dec 20, 2016
1 parent fe82c69 commit 28f1f4b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions Nop.Plugin.Api.Tests/Nop.Plugin.Api.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
<Compile Include="ServicesTests\Customers\CustomerApiServiceTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SetUp.cs" />
<Compile Include="ValidatorTests\TypeValidatorTests_IsValid.cs" />
<Compile Include="ValidatorTests\FieldsValidatorTests_GetValidFields.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
31 changes: 31 additions & 0 deletions Nop.Plugin.Api.Tests/ValidatorTests/TypeValidatorTests_IsValid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using Nop.Plugin.Api.DTOs.Products;
using NUnit.Framework;
using Nop.Plugin.Api.Tests.SerializersTests.DummyObjects;
using Nop.Plugin.Api.Validators;

namespace Nop.Plugin.Api.Tests.ValidatorTests
{
public class TypeValidatorTests_IsValid
{
[Test]
[SetCulture("de-de")]
[Description("Regression test for issue #11 - https://github.com/SevenSpikes/api-plugin-for-nopcommerce/issues/11")]
public void WhenCurrentCultureUsesCommaAsDecimalPoint_ShouldProperlyValidateProductPrice()
{
//Arange
Dictionary<string, object> properties = new Dictionary<string, object>();
properties.Add("price", 33.33);

var cut = new TypeValidator<ProductDto>();

//Act
bool result = cut.IsValid(properties);

// Assert
Assert.IsTrue(result);
}
}
}
3 changes: 2 additions & 1 deletion Nop.Plugin.Api/Validators/TypeValidator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Reflection;
using AutoMapper.Configuration;
using Newtonsoft.Json;
Expand Down Expand Up @@ -109,7 +110,7 @@ private bool IsCurrentPropertyValid(Type type, object value)
// This is needed because the isValid method does not work well if the value it is trying to validate is object.
if (value != null)
{
valueToValidate = value.ToString();
valueToValidate = string.Format(CultureInfo.InvariantCulture, "{0}", value);
}

if (!converter.IsValid(valueToValidate)) isCurrentPropertyValid = false;
Expand Down

0 comments on commit 28f1f4b

Please sign in to comment.