forked from UbiquityDotNET/Llvm.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisposableActionTests.cs
More file actions
46 lines (39 loc) · 1.63 KB
/
Copy pathDisposableActionTests.cs
File metadata and controls
46 lines (39 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) Ubiquity.NET Contributors. All rights reserved.
// Licensed under the Apache-2.0 WITH LLVM-exception license. See the LICENSE.md file in the project root for full license information.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Ubiquity.NET.Extensions.UT
{
[TestClass]
public sealed class DisposableActionTests
{
[TestMethod]
public void DisposableAction_CreateNOP_succeeds( )
{
using var disp = DisposableAction.CreateNOP();
Assert.IsNotNull(disp);
}
[TestMethod]
public void DisposableAction_with_null_Action_throws( )
{
var ex = Assert.ThrowsExactly<ArgumentNullException>(static ()=>
{
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
// Testing explicit case of null param.
using var x = new DisposableAction(null);
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
} );
Assert.IsNotNull( ex );
Assert.AreEqual("null", ex.ParamName);
}
[TestMethod]
[System.Diagnostics.CodeAnalysis.SuppressMessage( "IDisposableAnalyzers.Correctness", "IDISP017:Prefer using", Justification = "Explicit testing" )]
public void DisposableAction_called_correctly()
{
bool actionCalled = false;
var raiiAction = new DisposableAction( ()=> actionCalled = true );
raiiAction.Dispose(); // Should trigger call to action
Assert.IsTrue(actionCalled);
}
}
}