forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScopeStorageDictionaryTest.cs
More file actions
173 lines (142 loc) · 5.03 KB
/
Copy pathScopeStorageDictionaryTest.cs
File metadata and controls
173 lines (142 loc) · 5.03 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Web.WebPages.Scope;
using Microsoft.TestCommon;
namespace System.Web.WebPages.Test
{
public class ScopeStorageDictionaryTest
{
[Fact]
public void ScopeStorageDictionaryLooksUpLocalValuesFirst()
{
// Arrange
var stateStorage = GetChainedStorageStateDictionary();
// Act and Assert
Assert.Equal("f2", stateStorage["f"]);
}
[Fact]
public void ScopeStorageDictionaryOverridesParentValuesWithLocalValues()
{
// Arrange
var stateStorage = GetChainedStorageStateDictionary();
// Act and Assert
Assert.Equal("a2", stateStorage["a"]);
Assert.Equal("d2", stateStorage["d"]);
}
[Fact]
public void ScopeStorageDictionaryLooksUpParentValuesWhenNotFoundLocally()
{
// Arrange
var stateStorage = GetChainedStorageStateDictionary();
// Act and Assert
Assert.Equal("c0", stateStorage["c"]);
Assert.Equal("b1", stateStorage["b"]);
}
[Fact]
public void ScopeStorageDictionaryTreatsNullAsOrdinaryValues()
{
// Arrange
var stateStorage = GetChainedStorageStateDictionary();
stateStorage["b"] = null;
// Act and Assert
Assert.Null(stateStorage["b"]);
}
[Fact]
public void ContainsKeyReturnsTrueIfItContainsKey()
{
// Arrange
var scopeStorage = GetChainedStorageStateDictionary();
// Act and Assert
Assert.True(scopeStorage.ContainsKey("f"));
}
[Fact]
public void ContainsKeyReturnsTrueIfBaseContainsKey()
{
// Arrange
var scopeStorage = GetChainedStorageStateDictionary();
// Act and Assert
Assert.True(scopeStorage.ContainsKey("e"));
}
[Fact]
public void ContainsKeyReturnsFalseIfItDoesNotContainKeyAndBaseIsNull()
{
// Arrange
var scopeStorage = new ScopeStorageDictionary() { { "foo", "bar" } };
// Act and Assert
Assert.False(scopeStorage.ContainsKey("baz"));
}
[Fact]
public void CountReturnsCountFromCurrentAndBaseScope()
{
// Arrange
var scopeStorage = GetChainedStorageStateDictionary();
// Act and Assert
Assert.Equal(6, scopeStorage.Count);
}
[Fact]
public void ScopeStorageDictionaryGetsValuesFromCurrentAndBaseScope()
{
// Arrange
var scopeStorage = GetChainedStorageStateDictionary();
// Act and Assert
Assert.Equal("a2", scopeStorage["a"]);
Assert.Equal("b1", scopeStorage["b"]);
Assert.Equal("c0", scopeStorage["c"]);
Assert.Equal("d2", scopeStorage["d"]);
Assert.Equal("e1", scopeStorage["e"]);
Assert.Equal("f2", scopeStorage["f"]);
}
[Fact]
public void ClearRemovesAllItemsFromCurrentScope()
{
// Arrange
var dictionary = new ScopeStorageDictionary { { "foo", "bar" }, { "foo2", "bar2" } };
// Act
dictionary.Clear();
// Assert
Assert.Empty(dictionary);
}
[Fact]
public void ScopeStorageDictionaryIsNotReadOnly()
{
// Arrange
var dictionary = new ScopeStorageDictionary();
// Act and Assert
Assert.False(dictionary.IsReadOnly);
}
[Fact]
public void CopyToCopiesItemsToArrayAtSpecifiedIndex()
{
// Arrange
var dictionary = GetChainedStorageStateDictionary();
var array = new KeyValuePair<object, object>[8];
// Act
dictionary.CopyTo(array, 2);
// Assert
Assert.Equal("a", array[2].Key);
Assert.Equal("a2", array[2].Value);
Assert.Equal("f", array[4].Key);
Assert.Equal("f2", array[4].Value);
Assert.Equal("c", array[7].Key);
Assert.Equal("c0", array[7].Value);
}
private ScopeStorageDictionary GetChainedStorageStateDictionary()
{
var root = new ScopeStorageDictionary();
root["a"] = "a0";
root["b"] = "b0";
root["c"] = "c0";
var firstGen = new ScopeStorageDictionary(baseScope: root);
firstGen["a"] = "a1";
firstGen["b"] = "b1";
firstGen["d"] = "d1";
firstGen["e"] = "e1";
var secondGen = new ScopeStorageDictionary(baseScope: firstGen);
secondGen["a"] = "a2";
secondGen["d"] = "d2";
secondGen["f"] = "f2";
return secondGen;
}
}
}