diff options
author | crupest <crupest@outlook.com> | 2019-03-17 21:57:24 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-03-17 21:57:24 +0800 |
commit | ec9efc7edc3133459612e6e799e68a454e8148ba (patch) | |
tree | b569f8e3bbfe75bf22e90486b5289b9b772aaefc /Timeline/ClientApp/src/app/test-utilities/storage.mock.ts | |
parent | cfc1a24bcb782721780eb79cc45260db16ffad64 (diff) | |
download | timeline-ec9efc7edc3133459612e6e799e68a454e8148ba.tar.gz timeline-ec9efc7edc3133459612e6e799e68a454e8148ba.tar.bz2 timeline-ec9efc7edc3133459612e6e799e68a454e8148ba.zip |
Add unit test.
Diffstat (limited to 'Timeline/ClientApp/src/app/test-utilities/storage.mock.ts')
-rw-r--r-- | Timeline/ClientApp/src/app/test-utilities/storage.mock.ts | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Timeline/ClientApp/src/app/test-utilities/storage.mock.ts b/Timeline/ClientApp/src/app/test-utilities/storage.mock.ts new file mode 100644 index 00000000..0ba5aa35 --- /dev/null +++ b/Timeline/ClientApp/src/app/test-utilities/storage.mock.ts @@ -0,0 +1,28 @@ +import { Mock } from './mock'; +import { nullIfUndefined } from '../utilities/language-untilities'; + +export function createMockStorage(): Mock<Storage> { + const map: { [key: string]: string } = {}; + return { + get length(): number { + return Object.keys(map).length; + }, + key(index: number): string | null { + const keys = Object.keys(map); + if (index >= keys.length) { return null; } + return keys[index]; + }, + clear() { + Object.keys(map).forEach(key => delete map.key); + }, + getItem(key: string): string | null { + return nullIfUndefined(map[key]); + }, + setItem(key: string, value: string) { + map[key] = value; + }, + removeItem(key: string) { + delete map[key]; + } + }; +} |