forked from nopSolutions/nopCommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Localization): Allow setting a Language resource to an empty str…
…ing value nopSolutions#6954
- Loading branch information
Showing
6 changed files
with
93 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
.../Nop.Tests/Nop.Web.Tests/Public/Validators/Localization/LanguageResourceValidatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using FluentValidation.Internal; | ||
using FluentValidation.TestHelper; | ||
using Moq; | ||
using Nop.Services.Localization; | ||
using Nop.Web.Areas.Admin.Models.Localization; | ||
using Nop.Web.Areas.Admin.Validators.Localization; | ||
using NUnit.Framework; | ||
|
||
namespace Nop.Tests.Nop.Web.Tests.Public.Validators.Localization; | ||
|
||
[TestFixture] | ||
public class LanguageResourceValidatorTests : BaseNopTest | ||
{ | ||
private LanguageResourceValidator _validator; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
var localizationServiceMock = new Mock<ILocalizationService>(); | ||
localizationServiceMock.Setup(x => x.GetResourceAsync(It.IsAny<string>())).ReturnsAsync("Mocked message"); | ||
_validator = new LanguageResourceValidator(localizationServiceMock.Object); | ||
} | ||
|
||
[Test] | ||
public void ShouldHaveErrorWhenResourceNameIsEmpty() | ||
{ | ||
var model = new LocaleResourceModel { ResourceName = string.Empty, ResourceValue = "Value" }; | ||
var result = _validator.TestValidate(model, DefaultValidationOptions()); | ||
result.ShouldHaveValidationErrorFor(x => x.ResourceName); | ||
} | ||
|
||
[Test] | ||
public void ShouldNotHaveErrorWhenResourceNameIsSpecified() | ||
{ | ||
var model = new LocaleResourceModel { ResourceName = "Name", ResourceValue = "Value" }; | ||
var result = _validator.TestValidate(model, DefaultValidationOptions()); | ||
result.ShouldNotHaveValidationErrorFor(x => x.ResourceName); | ||
} | ||
|
||
[Test] | ||
public void ShouldHaveErrorWhenResourceValueIsNull() | ||
{ | ||
var model = new LocaleResourceModel { ResourceName = "Name", ResourceValue = null }; | ||
var result = _validator.TestValidate(model, DefaultValidationOptions()); | ||
result.ShouldHaveValidationErrorFor(x => x.ResourceValue); | ||
} | ||
|
||
[Test] | ||
public void ShouldNotHaveErrorWhenResourceValueIsSpecified() | ||
{ | ||
var model = new LocaleResourceModel { ResourceName = "Name", ResourceValue = "Value" }; | ||
var result = _validator.TestValidate(model, DefaultValidationOptions()); | ||
result.ShouldNotHaveValidationErrorFor(x => x.ResourceValue); | ||
} | ||
|
||
private static Action<ValidationStrategy<LocaleResourceModel>> DefaultValidationOptions() | ||
{ | ||
return options=>options.IncludeAllRuleSets(); | ||
} | ||
} |