Skip to content

Commit

Permalink
fix(icon-handling) - Add test for ToImageSource extension method to c…
Browse files Browse the repository at this point in the history
…heck if the icon handle is properly diposed
  • Loading branch information
lilla28 committed May 3, 2024
1 parent 25cb859 commit 78df126
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageVersion Include="xunit" Version="2.4.2" />
</ItemGroup>
</Project>
</Project>
4 changes: 3 additions & 1 deletion src/shell/dotnet/Shell.sln
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{DA
examples\module-catalog.json = examples\module-catalog.json
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiagnosticsExample", "..\..\..\examples\dotnet-diagnostics\DiagnosticsExample\DiagnosticsExample.csproj", "{24E64AFE-D2C5-487D-85F3-B0CE5AC0A128}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiagnosticsExample", "..\..\..\examples\dotnet-diagnostics\DiagnosticsExample\DiagnosticsExample.csproj", "{24E64AFE-D2C5-487D-85F3-B0CE5AC0A128}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{9173857E-84BF-4F8B-906B-39BCF0A8915B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
1 change: 1 addition & 0 deletions src/shell/dotnet/tests/Shell.Tests/Shell.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// /*
// * Morgan Stanley makes this available to you under the Apache License,
// * Version 2.0 (the "License"). You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0.
// *
// * See the NOTICE file distributed with this work for additional information
// * regarding copyright ownership. Unless required by applicable law or agreed
// * to in writing, software distributed under the License is distributed on an
// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// * or implied. See the License for the specific language governing permissions
// * and limitations under the License.
// */

using System.Drawing;
using FluentAssertions;

namespace MorganStanley.ComposeUI.Shell.Utilities;

public class IconUtilitiesTests
{
[Fact]
public void Bitmap_handle_is_no_longer_held_after_it_has_been_disposed()
{
var icon = new Icon(SystemIcons.Exclamation, 40, 40);
var bitmap = icon.ToBitmap();

var result = bitmap.ToImageSource();

result.Should().NotBeNull();

bitmap.Dispose();
icon.Dispose();

var action1 = () => bitmap.GetHbitmap();
var action2 = () => bitmap.GetHicon();
var action3 = () => icon.Handle;
var action4 = () => result;

action1.Should().Throw<ArgumentException>();
action2.Should().Throw<ArgumentException>();
action3.Should().Throw<ObjectDisposedException>();
action4.Should().NotThrow();
}
}

0 comments on commit 78df126

Please sign in to comment.