-
-
Notifications
You must be signed in to change notification settings - Fork 337
feat: Add ability to override enumerable builder values #1506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ae26843
feat: Add ability to override enumerable builder values
HofmeisterAn 6e6f70e
feat: Add WithCommand(ComposableEnumerable<string>) builder API
HofmeisterAn 930e69b
docs: Explain composing command arguments
HofmeisterAn a8fe7ec
chore: Update docs
HofmeisterAn b2b8fe2
chore: Rename class
HofmeisterAn 07411e9
chore: Move classes to different directory
HofmeisterAn 323c263
chore: Apply suggestions
HofmeisterAn 18cf3a8
fix: Use correct ComposableEnumerable default impl
HofmeisterAn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/Testcontainers/Configurations/Commons/AppendDictionary`2.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| namespace DotNet.Testcontainers.Configurations | ||
| { | ||
| using System.Collections.Generic; | ||
| using JetBrains.Annotations; | ||
| using DotNet.Testcontainers.Builders; | ||
|
|
||
| /// <summary> | ||
| /// Represents a composable dictionary that combines its elements by appending | ||
| /// the elements of another dictionary with overwriting existing keys. | ||
| /// </summary> | ||
| /// <typeparam name="TKey">The type of keys in the dictionary.</typeparam> | ||
| /// <typeparam name="TValue">The type of values in the dictionary.</typeparam> | ||
| [PublicAPI] | ||
| public sealed class AppendDictionary<TKey, TValue> : ComposableDictionary<TKey, TValue> | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AppendDictionary{TKey,TValue}" /> class. | ||
| /// </summary> | ||
| /// <param name="dictionary">The dictionary whose elements are copied to the new dictionary.</param> | ||
| public AppendDictionary(IReadOnlyDictionary<TKey, TValue> dictionary) | ||
| : base(dictionary) | ||
| { | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override ComposableDictionary<TKey, TValue> Compose(IReadOnlyDictionary<TKey, TValue> other) | ||
| { | ||
| return new AppendDictionary<TKey, TValue>(BuildConfiguration.Combine(other, this)); | ||
| } | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
src/Testcontainers/Configurations/Commons/AppendEnumerable`1.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| namespace DotNet.Testcontainers.Configurations | ||
| { | ||
| using System.Collections.Generic; | ||
| using JetBrains.Annotations; | ||
| using DotNet.Testcontainers.Builders; | ||
|
|
||
| /// <summary> | ||
| /// Represents a composable collection that combines its elements by appending | ||
| /// the elements of another collection. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of elements in the collection.</typeparam> | ||
| [PublicAPI] | ||
| public sealed class AppendEnumerable<T> : ComposableEnumerable<T> | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AppendEnumerable{T}" /> class. | ||
| /// </summary> | ||
| /// <param name="collection">The collection of items. If <c>null</c>, an empty collection is used.</param> | ||
| public AppendEnumerable(IEnumerable<T> collection) | ||
| : base(collection) | ||
| { | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override ComposableEnumerable<T> Compose(IEnumerable<T> other) | ||
| { | ||
| return new AppendEnumerable<T>(BuildConfiguration.Combine(other, this)); | ||
| } | ||
| } | ||
| } |
66 changes: 66 additions & 0 deletions
66
src/Testcontainers/Configurations/Commons/ComposableDictionary`2.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| namespace DotNet.Testcontainers.Configurations | ||
| { | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Collections.ObjectModel; | ||
| using JetBrains.Annotations; | ||
|
|
||
| /// <summary> | ||
| /// Represents an immutable dictionary that defines a custom strategy for | ||
| /// composing its elements with those of another dictionary. This class is | ||
| /// intended to be inherited by implementations that specify how two dictionaries | ||
| /// should be combined. | ||
| /// </summary> | ||
| /// <typeparam name="TKey">The type of keys in the dictionary.</typeparam> | ||
| /// <typeparam name="TValue">The type of values in the dictionary.</typeparam> | ||
| [PublicAPI] | ||
| public abstract class ComposableDictionary<TKey, TValue> : IReadOnlyDictionary<TKey, TValue> | ||
| { | ||
| private readonly IReadOnlyDictionary<TKey, TValue> _dictionary; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ComposableDictionary{TKey, TValue}" /> class. | ||
| /// </summary> | ||
| /// <param name="dictionary">The dictionary of items. If <c>null</c>, an empty dictionary is used.</param> | ||
| protected ComposableDictionary(IReadOnlyDictionary<TKey, TValue> dictionary) | ||
| { | ||
| _dictionary = dictionary ?? new ReadOnlyDictionary<TKey, TValue>(new Dictionary<TKey, TValue>()); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Combines the current dictionary with the specified dictionary according to | ||
| /// the composition strategy defined by the class. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The <paramref name="other" /> parameter corresponds to the previous builder | ||
| /// configuration. | ||
| /// </remarks> | ||
| /// <param name="other">The incoming dictionary to compose with this dictionary.</param> | ||
| /// <returns>A new <see cref="IReadOnlyDictionary{TKey, TValue}" /> that contains the result of the composition.</returns> | ||
| public abstract ComposableDictionary<TKey, TValue> Compose([NotNull] IReadOnlyDictionary<TKey, TValue> other); | ||
|
|
||
| /// <inheritdoc /> | ||
| public IEnumerable<TKey> Keys => _dictionary.Keys; | ||
|
|
||
| /// <inheritdoc /> | ||
| public IEnumerable<TValue> Values => _dictionary.Values; | ||
|
|
||
| /// <inheritdoc /> | ||
| public int Count => _dictionary.Count; | ||
|
|
||
| /// <inheritdoc /> | ||
| public TValue this[TKey key] => _dictionary[key]; | ||
|
|
||
| /// <inheritdoc /> | ||
| public bool ContainsKey(TKey key) => _dictionary.ContainsKey(key); | ||
|
|
||
| /// <inheritdoc /> | ||
| public bool TryGetValue(TKey key, out TValue value) => _dictionary.TryGetValue(key, out value); | ||
|
|
||
| /// <inheritdoc /> | ||
| public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() => _dictionary.GetEnumerator(); | ||
|
|
||
| /// <inheritdoc /> | ||
| IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
| } | ||
| } |
53 changes: 53 additions & 0 deletions
53
src/Testcontainers/Configurations/Commons/ComposableEnumerable`1.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| namespace DotNet.Testcontainers.Configurations | ||
| { | ||
| using System; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using JetBrains.Annotations; | ||
|
|
||
| /// <summary> | ||
| /// Represents an immutable collection that defines a custom strategy for | ||
| /// composing its elements with those of another collection. This class is | ||
| /// intended to be inherited by implementations that specify how two collections | ||
| /// should be combined. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of the elements in the collection.</typeparam> | ||
| [PublicAPI] | ||
| public abstract class ComposableEnumerable<T> : IEnumerable<T> | ||
| { | ||
| private readonly IEnumerable<T> _collection; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ComposableEnumerable{T}" /> class. | ||
| /// </summary> | ||
| /// <param name="collection">The collection of items. If <c>null</c>, an empty collection is used.</param> | ||
| protected ComposableEnumerable(IEnumerable<T> collection) | ||
| { | ||
| _collection = collection ?? Array.Empty<T>(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Combines the current collection with the specified collection according to | ||
| /// the composition strategy defined by the class. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The <paramref name="other" /> parameter corresponds to the previous builder | ||
| /// configuration. | ||
| /// </remarks> | ||
| /// <param name="other">The incoming collection to compose with this collection.</param> | ||
| /// <returns>A new <see cref="IEnumerable{T}" /> that contains the result of the composition.</returns> | ||
| public abstract ComposableEnumerable<T> Compose([NotNull] IEnumerable<T> other); | ||
|
|
||
| /// <summary> | ||
| /// Returns an enumerator that iterates through the collection. | ||
| /// </summary> | ||
| /// <returns>An enumerator for the current collection.</returns> | ||
| public IEnumerator<T> GetEnumerator() => _collection.GetEnumerator(); | ||
|
|
||
| /// <summary> | ||
| /// Returns an enumerator that iterates through the collection. | ||
| /// </summary> | ||
| /// <returns>An enumerator for the current collection.</returns> | ||
| IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.