コード例 #1
0
 public void Setup()
 {
     _dictionary = Enumerable.Range(1, Size).ToDictionary(_ => "test " + _, _ => _);
     _readonlyDictionary = new ReadonlyDictionary<string, int>(_dictionary);
     _concurrentDictionary = new ConcurrentDictionary<string, int>(_dictionary);
     _immutableDictionary = _dictionary.ToImmutableDictionary();
 }
コード例 #2
0
        public ValueTask <User?> ExecuteAsync(User user, IServiceProvider serviceProvider,
                                              CancellationToken ct)
        {
            Validate <Validator> .It(this);

            var newUser = user;

            var existing = user.Properties.GetValueOrDefault(Property);

            if (!string.Equals(existing, PropertyValue, StringComparison.Ordinal))
            {
                var newProperties = new Dictionary <string, string>(user.Properties);

                if (PropertyValue == null)
                {
                    newProperties.Remove(Property);
                }
                else
                {
                    newProperties[Property] = PropertyValue;
                }

                newUser = newUser with
                {
                    Properties = new ReadonlyDictionary <string, string>(newProperties)
                };
            }

            return(new ValueTask <User?>(newUser));
        }
    }
コード例 #3
0
 public void Setup()
 {
     _dictionary           = Enumerable.Range(1, Size).ToDictionary(_ => "test " + _, _ => _);
     _readonlyDictionary   = new ReadonlyDictionary <string, int>(_dictionary);
     _concurrentDictionary = new ConcurrentDictionary <string, int>(_dictionary);
     _immutableDictionary  = _dictionary.ToImmutableDictionary();
 }
コード例 #4
0
 public UsesBarDependency(ReadonlyDictionary bar)
 {
     if (bar == null)
     {
         throw new ArgumentNullException("bar");
     }
     this.bar = bar;
 }
コード例 #5
0
        public void TryGetValue(string key)
        {
            var    underTest = new ReadonlyDictionary <string, string>(_sourceItems);
            string expectedValue;
            string testValue;

            Assert.Equal(_sourceItems.TryGetValue(key, out expectedValue), underTest.TryGetValue(key, out testValue));
            Assert.Equal(expectedValue, testValue);
        }
コード例 #6
0
        public void ReadonlyDictionaryContains()
        {
            var underTest = new ReadonlyDictionary <string, string>(_sourceItems);

            Assert.True(underTest.Contains(new KeyValuePair <string, string>("a", "1")));
            Assert.True(underTest.Contains(new KeyValuePair <string, string>("b", "2")));
            Assert.True(underTest.Contains(new KeyValuePair <string, string>("c", "3")));
            Assert.False(underTest.Contains(new KeyValuePair <string, string>("d", "4")));
            Assert.False(underTest.Contains(new KeyValuePair <string, string>("", "")));
        }
コード例 #7
0
        public void ReadonlyDictionaryContainsKey()
        {
            var underTest = new ReadonlyDictionary <string, string>(_sourceItems);

            Assert.True(underTest.ContainsKey("a"));
            Assert.True(underTest.ContainsKey("b"));
            Assert.True(underTest.ContainsKey("c"));
            Assert.False(underTest.ContainsKey("d"));
            Assert.False(underTest.ContainsKey(""));
        }
コード例 #8
0
        public void ReadonlyDictionaryCantChange()
        {
            var underTest = new ReadonlyDictionary <string, string>(new Dictionary <string, string> {
                { "a", "a" }
            });

            Assert.Throws <NotSupportedException>(() => underTest.Remove("b"));
            Assert.Throws <NotSupportedException>(() => underTest.Remove(new KeyValuePair <string, string>("b", "b")));
            Assert.Throws <NotSupportedException>(() => underTest.Add("b", "b"));
            Assert.Throws <NotSupportedException>(() => underTest.Add(new KeyValuePair <string, string>("b", "b")));
            Assert.Throws <NotSupportedException>(() => underTest.Clear());
            Assert.Throws <NotSupportedException>(() => underTest["a"] = "a");
        }
コード例 #9
0
        public void Initialize()
        {
            Dictionary <string, KeyTermRule> dictionary = new Dictionary <string, KeyTermRule>();

            m_regexRules = null;
            foreach (KeyTermRule keyTermRule in Items.Where(rule => !String.IsNullOrEmpty(rule.id)))
            {
                if (keyTermRule.IsRegEx)
                {
                    if (m_regexRules == null)
                    {
                        m_regexRules = new List <Regex>();
                    }
                    m_regexRules.Add(new Regex(keyTermRule.id, RegexOptions.Compiled));
                }
                else
                {
                    dictionary[keyTermRule.id] = keyTermRule;
                }
            }
            m_rulesDictionary = new ReadonlyDictionary <string, KeyTermRule>(dictionary);
        }
コード例 #10
0
 public override void Write(Utf8JsonWriter writer, ReadonlyDictionary <TKey, TValue> value, JsonSerializerOptions options)
 {
     JsonSerializer.Serialize(writer, value, innerType, options);
 }
コード例 #11
0
        public async ValueTask <App?> ExecuteAsync(App app, IServiceProvider serviceProvider,
                                                   CancellationToken ct)
        {
            var integrationManager = serviceProvider.GetRequiredService <IIntegrationManager>();

            ConfiguredIntegration configured;

            if (app.Integrations.TryGetValue(Id, out var previousIntegration))
            {
                Validate <UpdateValidator> .It(this);

                configured = previousIntegration with {
                    Properties = Properties
                };
            }
            else
            {
                Validate <CreateValidator> .It(this);

                configured = new ConfiguredIntegration(Type, Properties);
            }

            if (Is.Changed(Test, configured.Test))
            {
                configured = configured with {
                    Test = Test
                };
            }

            if (Is.Changed(Enabled, configured.Enabled))
            {
                configured = configured with {
                    Enabled = Enabled.Value
                };
            }

            if (Is.Changed(Priority, configured.Priority))
            {
                configured = configured with {
                    Priority = Priority.Value
                };
            }

            if (Is.Changed(Condition, configured.Condition))
            {
                configured = configured with {
                    Condition = Condition
                };
            }

            await integrationManager.ValidateAsync(configured, ct);

            await integrationManager.HandleConfiguredAsync(Id, app, configured, previousIntegration, ct);

            var newIntegrations = new Dictionary <string, ConfiguredIntegration>(app.Integrations)
            {
                [Id] = configured
            };

            var newApp = app with
            {
                Integrations = newIntegrations.ToReadonlyDictionary()
            };

            return(newApp);
        }
    }
}
コード例 #12
0
        public void EmptyReadonlyDictionaryContains(string key)
        {
            var underTest = new ReadonlyDictionary <string, string>(_emptySourceItems);

            Assert.False(underTest.ContainsKey(key));
        }
コード例 #13
0
        public void ReadonlyDictionaryCountEqualsSourceSetCount()
        {
            var underTest = new ReadonlyDictionary <string, string>(_sourceItems);

            Assert.Equal(_sourceItems.Count, underTest.Count);
        }
コード例 #14
0
        public void ReadonlyDictionaryValuesEqualsSourceSetValues()
        {
            var underTest = new ReadonlyDictionary <string, string>(_sourceItems);

            Assert.Equal(_sourceItems.Values.ToList(), underTest.Values.ToList());
        }
コード例 #15
0
        public void GetEnumeratorEqualsSourceSetEnumerator()
        {
            var underTest = new ReadonlyDictionary <string, string>(_sourceItems);

            Assert.Equal(_sourceItems.GetEnumerator(), underTest.GetEnumerator());
        }
コード例 #16
0
        public void ReadonlyDictionaryIndexerNonExistingItems()
        {
            var underTest = new ReadonlyDictionary <string, string>(_sourceItems);

            Assert.Throws <KeyNotFoundException>(() => underTest["not"]);
        }
コード例 #17
0
        protected override void SerializeValue(BsonSerializationContext context, BsonSerializationArgs args, ReadonlyDictionary <TKey, TValue> value)
        {
            var inner = new Dictionary <TKey, TValue>(value);

            BsonSerializer.Serialize(context.Writer, innerType, inner);
        }
コード例 #18
0
        public void ReadonlyDictionaryIndexerExistingItems(string key)
        {
            var underTest = new ReadonlyDictionary <string, string>(_sourceItems);

            Assert.Equal(_sourceItems[key], underTest[key]);
        }