|
| 1 | +// Copyright (c) Six Labors. |
| 2 | +// Licensed under the Apache License, Version 2.0. |
| 3 | + |
| 4 | +using System.Collections.Generic; |
| 5 | +using SixLabors.ImageSharp.Web.Commands; |
| 6 | +using Xunit; |
| 7 | + |
| 8 | +namespace SixLabors.ImageSharp.Web.Tests.Commands |
| 9 | +{ |
| 10 | + public class CommandCollectionTests |
| 11 | + { |
| 12 | + [Fact] |
| 13 | + public void CanAddCommands() |
| 14 | + { |
| 15 | + CommandCollection collection = new(); |
| 16 | + collection.Add(new("a", "b")); |
| 17 | + Assert.Single(collection); |
| 18 | + } |
| 19 | + |
| 20 | + [Fact] |
| 21 | + public void CanReadCommands() |
| 22 | + { |
| 23 | + const string key = "a"; |
| 24 | + const string value = "b"; |
| 25 | + CommandCollection collection = new(); |
| 26 | + collection.Add(new(key, value)); |
| 27 | + |
| 28 | + Assert.Equal(value, collection[key]); |
| 29 | + } |
| 30 | + |
| 31 | + [Fact] |
| 32 | + public void CanInsertCommands() |
| 33 | + { |
| 34 | + KeyValuePair<string, string> kv1 = new("a", "b"); |
| 35 | + KeyValuePair<string, string> kv2 = new("c", "d"); |
| 36 | + |
| 37 | + CommandCollection collection = new(); |
| 38 | + collection.Add(kv1); |
| 39 | + Assert.Single(collection); |
| 40 | + |
| 41 | + collection.Insert(0, kv2); |
| 42 | + Assert.Equal(2, collection.Count); |
| 43 | + |
| 44 | + Assert.Equal(kv1.Value, collection[kv1.Key]); |
| 45 | + Assert.Equal(kv2.Value, collection[kv2.Key]); |
| 46 | + |
| 47 | + Assert.Equal(1, collection.IndexOf(kv1)); |
| 48 | + Assert.Equal(0, collection.IndexOf(kv2)); |
| 49 | + } |
| 50 | + |
| 51 | + [Fact] |
| 52 | + public void CanRemoveCommands() |
| 53 | + { |
| 54 | + KeyValuePair<string, string> kv1 = new("a", "b"); |
| 55 | + KeyValuePair<string, string> kv2 = new("c", "d"); |
| 56 | + CommandCollection collection = new(); |
| 57 | + |
| 58 | + collection.Add(kv1); |
| 59 | + collection.Add(kv2); |
| 60 | + |
| 61 | + Assert.Equal(2, collection.Count); |
| 62 | + |
| 63 | + collection.Remove(kv1); |
| 64 | + |
| 65 | + Assert.Single(collection); |
| 66 | + Assert.Equal(kv2.Value, collection[kv2.Key]); |
| 67 | + } |
| 68 | + |
| 69 | + [Fact] |
| 70 | + public void CanClearCommands() |
| 71 | + { |
| 72 | + KeyValuePair<string, string> kv1 = new("a", "b"); |
| 73 | + KeyValuePair<string, string> kv2 = new("c", "d"); |
| 74 | + CommandCollection collection = new(); |
| 75 | + |
| 76 | + collection.Add(kv1); |
| 77 | + collection.Add(kv2); |
| 78 | + |
| 79 | + Assert.Equal(2, collection.Count); |
| 80 | + |
| 81 | + collection.Clear(); |
| 82 | + |
| 83 | + Assert.Empty(collection); |
| 84 | + } |
| 85 | + } |
| 86 | +} |
0 commit comments