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(); }
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)); } }
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(); }
public UsesBarDependency(ReadonlyDictionary bar) { if (bar == null) { throw new ArgumentNullException("bar"); } this.bar = bar; }
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); }
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>("", ""))); }
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("")); }
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"); }
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); }
public override void Write(Utf8JsonWriter writer, ReadonlyDictionary <TKey, TValue> value, JsonSerializerOptions options) { JsonSerializer.Serialize(writer, value, innerType, options); }
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); } } }
public void EmptyReadonlyDictionaryContains(string key) { var underTest = new ReadonlyDictionary <string, string>(_emptySourceItems); Assert.False(underTest.ContainsKey(key)); }
public void ReadonlyDictionaryCountEqualsSourceSetCount() { var underTest = new ReadonlyDictionary <string, string>(_sourceItems); Assert.Equal(_sourceItems.Count, underTest.Count); }
public void ReadonlyDictionaryValuesEqualsSourceSetValues() { var underTest = new ReadonlyDictionary <string, string>(_sourceItems); Assert.Equal(_sourceItems.Values.ToList(), underTest.Values.ToList()); }
public void GetEnumeratorEqualsSourceSetEnumerator() { var underTest = new ReadonlyDictionary <string, string>(_sourceItems); Assert.Equal(_sourceItems.GetEnumerator(), underTest.GetEnumerator()); }
public void ReadonlyDictionaryIndexerNonExistingItems() { var underTest = new ReadonlyDictionary <string, string>(_sourceItems); Assert.Throws <KeyNotFoundException>(() => underTest["not"]); }
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); }
public void ReadonlyDictionaryIndexerExistingItems(string key) { var underTest = new ReadonlyDictionary <string, string>(_sourceItems); Assert.Equal(_sourceItems[key], underTest[key]); }