diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ac81f27..2d9e8a0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,12 +12,17 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4.1.1 + - name: Ursa Unit Test + run: dotnet test ./tests/Test.Ursa - name: Ursa Headless Test run: dotnet test ./tests/HeadlessTest.Ursa + ubuntu: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4.1.1 + - name: Ursa Unit Test + run: dotnet test ./tests/Test.Ursa - name: Ursa Headless Test - run: dotnet test ./tests/HeadlessTest.Ursa \ No newline at end of file + run: dotnet test ./tests/HeadlessTest.Ursa diff --git a/src/Ursa/Controls/ImageViewer/ImageViewer.cs b/src/Ursa/Controls/ImageViewer/ImageViewer.cs index e0abde2..021151f 100644 --- a/src/Ursa/Controls/ImageViewer/ImageViewer.cs +++ b/src/Ursa/Controls/ImageViewer/ImageViewer.cs @@ -163,8 +163,9 @@ public class ImageViewer: TemplatedControl private void OnStretchChanged(AvaloniaPropertyChangedEventArgs args) { + if (_image is null) return; var stretch = args.GetNewValue(); - Scale = GetScaleRatio(Width / _image!.Width, Height / _image!.Height, stretch); + Scale = GetScaleRatio(Width / _image.Width, Height / _image.Height, stretch); _sourceMinScale = _image is not null ? Math.Min(Width * MinScale / _image.Width, Height * MinScale / _image.Height) : MinScale; } diff --git a/tests/Test.Ursa/ImageViewerTests/Stretch_Initial_Value/StretchValueTest.cs b/tests/Test.Ursa/ImageViewerTests/Stretch_Initial_Value/StretchValueTest.cs new file mode 100644 index 0000000..c187394 --- /dev/null +++ b/tests/Test.Ursa/ImageViewerTests/Stretch_Initial_Value/StretchValueTest.cs @@ -0,0 +1,17 @@ +using Avalonia.Controls; +using Avalonia.Media; +using Ursa.Controls; + +namespace Test.Ursa.Controls.ImageViewerTests.Stretch_Initial_Value; + +public class StretchValueTest +{ + [Fact] + public void Stretch_Initial_Value_Does_Not_Crash() + { + ImageViewer iv = new ImageViewer() + { + Stretch = Stretch.UniformToFill + }; + } +} \ No newline at end of file