|
1 | | -using System; |
| 1 | +using System; |
2 | 2 | using System.Diagnostics.CodeAnalysis; |
3 | 3 |
|
4 | | -namespace Bunit |
| 4 | +namespace Bunit.Rendering |
5 | 5 | { |
6 | | - /// <summary> |
7 | | - /// Represents a single parameter supplied to an <see cref="Microsoft.AspNetCore.Components.IComponent"/> |
8 | | - /// component under test. |
9 | | - /// </summary> |
10 | | - [SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "<Pending>")] |
11 | | - public readonly struct ComponentParameter : IEquatable<ComponentParameter> |
12 | | - { |
13 | | - /// <summary> |
14 | | - /// Gets the name of the parameter. Can be null if the parameter is for an unnamed cascading value. |
15 | | - /// </summary> |
16 | | - public string? Name { get; } |
| 6 | + /// <summary> |
| 7 | + /// Represents a single parameter supplied to an <see cref="Microsoft.AspNetCore.Components.IComponent"/> |
| 8 | + /// component under test. |
| 9 | + /// </summary> |
| 10 | + [SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "<Pending>")] |
| 11 | + public readonly struct ComponentParameter : IEquatable<ComponentParameter> |
| 12 | + { |
| 13 | + /// <summary> |
| 14 | + /// Gets the name of the parameter. Can be null if the parameter is for an unnamed cascading value. |
| 15 | + /// </summary> |
| 16 | + public string? Name { get; } |
17 | 17 |
|
18 | | - /// <summary> |
19 | | - /// Gets the value being supplied to the component. |
20 | | - /// </summary> |
21 | | - public object? Value { get; } |
| 18 | + /// <summary> |
| 19 | + /// Gets the value being supplied to the component. |
| 20 | + /// </summary> |
| 21 | + public object? Value { get; } |
22 | 22 |
|
23 | | - /// <summary> |
24 | | - /// Gets a value to indicate whether the parameter is for use by a <see cref="Microsoft.AspNetCore.Components.CascadingValue{TValue}"/>. |
25 | | - /// </summary> |
26 | | - public bool IsCascadingValue { get; } |
| 23 | + /// <summary> |
| 24 | + /// Gets a value to indicate whether the parameter is for use by a <see cref="Microsoft.AspNetCore.Components.CascadingValue{TValue}"/>. |
| 25 | + /// </summary> |
| 26 | + public bool IsCascadingValue { get; } |
27 | 27 |
|
28 | | - private ComponentParameter(string? name, object? value, bool isCascadingValue) |
29 | | - { |
30 | | - if (isCascadingValue && value is null) |
31 | | - throw new ArgumentNullException(nameof(value), "Cascading values cannot be set to null"); |
| 28 | + private ComponentParameter(string? name, object? value, bool isCascadingValue) |
| 29 | + { |
| 30 | + if (isCascadingValue && value is null) |
| 31 | + throw new ArgumentNullException(nameof(value), "Cascading values cannot be set to null"); |
32 | 32 |
|
33 | | - if (!isCascadingValue && name is null) |
34 | | - throw new ArgumentNullException(nameof(name), "A parameters name cannot be set to null"); |
| 33 | + if (!isCascadingValue && name is null) |
| 34 | + throw new ArgumentNullException(nameof(name), "A parameters name cannot be set to null"); |
35 | 35 |
|
36 | | - Name = name; |
37 | | - Value = value; |
38 | | - IsCascadingValue = isCascadingValue; |
39 | | - } |
| 36 | + Name = name; |
| 37 | + Value = value; |
| 38 | + IsCascadingValue = isCascadingValue; |
| 39 | + } |
40 | 40 |
|
41 | | - /// <summary> |
42 | | - /// Create a parameter for a component under test. |
43 | | - /// </summary> |
44 | | - /// <param name="name">Name of the parameter to pass to the component</param> |
45 | | - /// <param name="value">Value or null to pass the component</param> |
46 | | - public static ComponentParameter CreateParameter(string name, object? value) |
47 | | - => new ComponentParameter(name, value, false); |
| 41 | + /// <summary> |
| 42 | + /// Create a parameter for a component under test. |
| 43 | + /// </summary> |
| 44 | + /// <param name="name">Name of the parameter to pass to the component</param> |
| 45 | + /// <param name="value">Value or null to pass the component</param> |
| 46 | + public static ComponentParameter CreateParameter(string name, object? value) |
| 47 | + => new ComponentParameter(name, value, false); |
48 | 48 |
|
49 | | - /// <summary> |
50 | | - /// Create a Cascading Value parameter for a component under test. |
51 | | - /// </summary> |
52 | | - /// <param name="name">A optional name for the cascading value</param> |
53 | | - /// <param name="value">The cascading value</param> |
54 | | - public static ComponentParameter CreateCascadingValue(string? name, object value) |
55 | | - => new ComponentParameter(name, value, true); |
| 49 | + /// <summary> |
| 50 | + /// Create a Cascading Value parameter for a component under test. |
| 51 | + /// </summary> |
| 52 | + /// <param name="name">A optional name for the cascading value</param> |
| 53 | + /// <param name="value">The cascading value</param> |
| 54 | + public static ComponentParameter CreateCascadingValue(string? name, object value) |
| 55 | + => new ComponentParameter(name, value, true); |
56 | 56 |
|
57 | | - /// <summary> |
58 | | - /// Create a parameter for a component under test. |
59 | | - /// </summary> |
60 | | - /// <param name="input">A name/value pair for the parameter</param> |
61 | | - public static implicit operator ComponentParameter((string name, object? value) input) |
62 | | - => CreateParameter(input.name, input.value); |
| 57 | + /// <summary> |
| 58 | + /// Create a parameter for a component under test. |
| 59 | + /// </summary> |
| 60 | + /// <param name="input">A name/value pair for the parameter</param> |
| 61 | + public static implicit operator ComponentParameter((string name, object? value) input) |
| 62 | + => CreateParameter(input.name, input.value); |
63 | 63 |
|
64 | | - /// <summary> |
65 | | - /// Create a parameter or cascading value for a component under test. |
66 | | - /// </summary> |
67 | | - /// <param name="input">A name/value/isCascadingValue triple for the parameter</param> |
68 | | - public static implicit operator ComponentParameter((string? name, object? value, bool isCascadingValue) input) |
69 | | - => new ComponentParameter(input.name, input.value, input.isCascadingValue); |
| 64 | + /// <summary> |
| 65 | + /// Create a parameter or cascading value for a component under test. |
| 66 | + /// </summary> |
| 67 | + /// <param name="input">A name/value/isCascadingValue triple for the parameter</param> |
| 68 | + public static implicit operator ComponentParameter((string? name, object? value, bool isCascadingValue) input) |
| 69 | + => new ComponentParameter(input.name, input.value, input.isCascadingValue); |
70 | 70 |
|
71 | | - /// <inheritdoc/> |
72 | | - public bool Equals(ComponentParameter other) |
73 | | - => string.Equals(Name, other.Name, StringComparison.Ordinal) && Value == other.Value && IsCascadingValue == other.IsCascadingValue; |
| 71 | + /// <inheritdoc/> |
| 72 | + public bool Equals(ComponentParameter other) |
| 73 | + => string.Equals(Name, other.Name, StringComparison.Ordinal) && Value == other.Value && IsCascadingValue == other.IsCascadingValue; |
74 | 74 |
|
75 | | - /// <inheritdoc/> |
76 | | - public override bool Equals(object obj) => obj is ComponentParameter other && Equals(other); |
| 75 | + /// <inheritdoc/> |
| 76 | + public override bool Equals(object obj) => obj is ComponentParameter other && Equals(other); |
77 | 77 |
|
78 | | - /// <inheritdoc/> |
79 | | - public override int GetHashCode() => HashCode.Combine(Name, Value, IsCascadingValue); |
| 78 | + /// <inheritdoc/> |
| 79 | + public override int GetHashCode() => HashCode.Combine(Name, Value, IsCascadingValue); |
80 | 80 |
|
81 | | - /// <inheritdoc/> |
82 | | - public static bool operator ==(ComponentParameter left, ComponentParameter right) => left.Equals(right); |
| 81 | + /// <inheritdoc/> |
| 82 | + public static bool operator ==(ComponentParameter left, ComponentParameter right) => left.Equals(right); |
83 | 83 |
|
84 | | - /// <inheritdoc/> |
85 | | - public static bool operator !=(ComponentParameter left, ComponentParameter right) => !(left == right); |
86 | | - } |
| 84 | + /// <inheritdoc/> |
| 85 | + public static bool operator !=(ComponentParameter left, ComponentParameter right) => !(left == right); |
| 86 | + } |
87 | 87 | } |
0 commit comments