mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
Add validation to prevent empty/null names in ImageResizer settings
Co-authored-by: yeelam-gordon <73506701+yeelam-gordon@users.noreply.github.com>
This commit is contained in:
@@ -69,7 +69,14 @@ public partial class ImageSize : INotifyPropertyChanged, IHasId
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
set => SetProperty(ref _name, value);
|
||||
set
|
||||
{
|
||||
// Prevent setting empty or null names
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
SetProperty(ref _name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[JsonPropertyName("fit")]
|
||||
|
||||
@@ -313,5 +313,44 @@ namespace ViewModelTests
|
||||
Assert.AreEqual(50, imageSize.Width);
|
||||
Assert.AreEqual(50, imageSize.Height);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ImageSizeNameShouldNotBeSetToEmptyOrNull()
|
||||
{
|
||||
// arrange
|
||||
ImageSize imageSize = new ImageSize()
|
||||
{
|
||||
Id = 0,
|
||||
Name = "Original Name",
|
||||
Fit = ResizeFit.Fit,
|
||||
Width = 100,
|
||||
Height = 100,
|
||||
Unit = ResizeUnit.Pixel,
|
||||
};
|
||||
|
||||
// Act - try to set name to empty string
|
||||
imageSize.Name = string.Empty;
|
||||
|
||||
// Assert - name should remain unchanged
|
||||
Assert.AreEqual("Original Name", imageSize.Name);
|
||||
|
||||
// Act - try to set name to null
|
||||
imageSize.Name = null;
|
||||
|
||||
// Assert - name should remain unchanged
|
||||
Assert.AreEqual("Original Name", imageSize.Name);
|
||||
|
||||
// Act - try to set name to whitespace only
|
||||
imageSize.Name = " ";
|
||||
|
||||
// Assert - name should remain unchanged
|
||||
Assert.AreEqual("Original Name", imageSize.Name);
|
||||
|
||||
// Act - set name to valid value
|
||||
imageSize.Name = "New Valid Name";
|
||||
|
||||
// Assert - name should be updated
|
||||
Assert.AreEqual("New Valid Name", imageSize.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user