Skip to content

Commit cbba63c

Browse files
committed
Make sure the Setup of the AppBuilder is only done once.
1 parent 49d2142 commit cbba63c

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using System.Threading;
5+
using Avalonia;
6+
7+
namespace Magick.NET.AvaloniaMediaImaging.Tests
8+
{
9+
internal static class AppBuilderHelper
10+
{
11+
private static readonly SemaphoreSlim _lock = new(1);
12+
private static bool _setupDone;
13+
14+
public static void Setup()
15+
{
16+
if (_setupDone)
17+
return;
18+
19+
_lock.Wait();
20+
21+
try
22+
{
23+
24+
if (_setupDone)
25+
return;
26+
27+
_setupDone = true;
28+
29+
AppBuilder
30+
.Configure<Application>()
31+
.UsePlatformDetect()
32+
.SetupWithoutStarting();
33+
}
34+
finally
35+
{
36+
_lock.Release();
37+
}
38+
}
39+
}
40+
}

tests/Magick.NET.AvaloniaMediaImaging.Tests/IMagickImageExtentionsTests/TheToWriteableBitmapMethod.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ public class TheToWriteableBitmapMethod
1515
[Fact]
1616
public void ShouldReturnWriteableBitmap()
1717
{
18-
AppBuilder
19-
.Configure<Application>()
20-
.UsePlatformDetect()
21-
.SetupWithoutStarting();
18+
AppBuilderHelper.Setup();
2219

2320
using var input = new MagickImage(Files.MagickNETIconPNG);
2421
using var bitmap = input.ToWriteableBitmap();

tests/Magick.NET.AvaloniaMediaImaging.Tests/IMagickImageExtentionsTests/TheToWriteableBitmapWithDensityMethod.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ public class TheToWriteableBitmapWithDensityMethod
1515
[Fact]
1616
public void ShouldReturnWriteableBitmap()
1717
{
18-
AppBuilder
19-
.Configure<Application>()
20-
.UsePlatformDetect()
21-
.SetupWithoutStarting();
18+
AppBuilderHelper.Setup();
2219

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

0 commit comments

Comments
 (0)