-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathTestContextExtensions.cs
55 lines (48 loc) · 1.75 KB
/
TestContextExtensions.cs
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
47
48
49
50
51
52
53
54
55
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Text;
namespace Meadow.UnitTestTemplate
{
internal static class TestContextExtensions
{
#region Constants
private const string TEST_INTERNAL_STATE_KEY = "InternalTestState";
#endregion
#region Functions
internal static InternalTestState GetInternalTestState(this TestContext testContext)
{
// Try to obtain our value.
object value = null;
bool success = testContext?.Properties?.TryGetValue(TEST_INTERNAL_STATE_KEY, out value) == true;
// If we could obtain our value, return it.
if (success && value != null)
{
return (InternalTestState)value;
}
else
{
// Create a new internal test state and return that.
return testContext.ResetInternalTestState();
}
}
internal static void SetInternalTestState(this TestContext testContext, InternalTestState internalTestState)
{
// Set our internal test state
if (testContext?.Properties != null)
{
testContext.Properties[TEST_INTERNAL_STATE_KEY] = internalTestState;
}
}
internal static InternalTestState ResetInternalTestState(this TestContext testContext)
{
// Create a new internal test state.
InternalTestState internalTestState = new InternalTestState();
// Set it in our test context.
SetInternalTestState(testContext, internalTestState);
// Return it
return internalTestState;
}
#endregion
}
}