Skip to content

Commit

Permalink
Make sure the Setup of the AppBuilder is only done once.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Jan 10, 2025
1 parent 49d2142 commit cbba63c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
40 changes: 40 additions & 0 deletions tests/Magick.NET.AvaloniaMediaImaging.Tests/AppBuilderHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

using System.Threading;
using Avalonia;

namespace Magick.NET.AvaloniaMediaImaging.Tests
{
internal static class AppBuilderHelper
{
private static readonly SemaphoreSlim _lock = new(1);
private static bool _setupDone;

public static void Setup()
{
if (_setupDone)
return;

_lock.Wait();

try
{

if (_setupDone)
return;

_setupDone = true;

AppBuilder
.Configure<Application>()
.UsePlatformDetect()
.SetupWithoutStarting();
}
finally
{
_lock.Release();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ public class TheToWriteableBitmapMethod
[Fact]
public void ShouldReturnWriteableBitmap()
{
AppBuilder
.Configure<Application>()
.UsePlatformDetect()
.SetupWithoutStarting();
AppBuilderHelper.Setup();

using var input = new MagickImage(Files.MagickNETIconPNG);
using var bitmap = input.ToWriteableBitmap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ public class TheToWriteableBitmapWithDensityMethod
[Fact]
public void ShouldReturnWriteableBitmap()
{
AppBuilder
.Configure<Application>()
.UsePlatformDetect()
.SetupWithoutStarting();
AppBuilderHelper.Setup();

using var input = new MagickImage(Files.MagickNETIconPNG);
input.Density = new Density(150, 300);
Expand Down

0 comments on commit cbba63c

Please sign in to comment.