@@ -18,6 +18,7 @@ internal abstract class AutoFixtureBase<TFixture> : AutoFixtureBase
1818 /// <param name="field">The field.</param>
1919 /// <param name="value">The value.</param>
2020 /// <returns>The fixture.</returns>
21+ /// <exception cref="InvalidOperationException">Throws if it cannot cast the fixture.</exception>
2122 protected TFixture With < TField > ( ref TField field , TField value )
2223 {
2324 field = value ;
@@ -32,6 +33,7 @@ protected TFixture With<TField>(ref TField field, TField value)
3233 /// <param name="field">The field.</param>
3334 /// <param name="values">The values.</param>
3435 /// <returns>The fixture.</returns>
36+ /// <exception cref="InvalidOperationException">Throws if it cannot cast the fixture.</exception>
3537 protected TFixture With < TField > ( ref Collection < TField > ? field , IEnumerable < TField > ? values )
3638 {
3739 if ( values == null )
@@ -46,34 +48,36 @@ protected TFixture With<TField>(ref Collection<TField>? field, IEnumerable<TFiel
4648 }
4749
4850 /// <summary>
49- /// Adds the specified list of fields to the fixture.
51+ /// Adds the specified field to the fixture.
5052 /// </summary>
5153 /// <typeparam name="TFixture">The type of the fixture.</typeparam>
5254 /// <typeparam name="TField">The type of the field.</typeparam>
5355 /// <param name="field">The field.</param>
54- /// <param name="values ">The values .</param>
56+ /// <param name="value ">The value .</param>
5557 /// <returns>The fixture.</returns>
56- protected TFixture With < TField > ( ref List < TField > ? field , IEnumerable < TField > ? values )
58+ /// <exception cref="InvalidOperationException">Throws if it cannot cast the fixture.</exception>
59+ protected TFixture With < TField > ( ref Collection < TField > ? field , TField value )
5760 {
58- if ( values == null )
59- field = null ;
60- else
61- field ? . AddRange ( values ) ;
62-
61+ field ? . Add ( value ) ;
6362 return this as TFixture ?? throw new InvalidOperationException ( ) ;
6463 }
6564
6665 /// <summary>
67- /// Adds the specified field to the fixture.
66+ /// Adds the specified list of fields to the fixture.
6867 /// </summary>
6968 /// <typeparam name="TFixture">The type of the fixture.</typeparam>
7069 /// <typeparam name="TField">The type of the field.</typeparam>
7170 /// <param name="field">The field.</param>
72- /// <param name="value ">The value .</param>
71+ /// <param name="values ">The values .</param>
7372 /// <returns>The fixture.</returns>
74- protected TFixture With < TField > ( ref Collection < TField > ? field , TField value )
73+ /// <exception cref="InvalidOperationException">Throws if it cannot cast the fixture.</exception>
74+ protected TFixture With < TField > ( ref List < TField > ? field , IEnumerable < TField > ? values )
7575 {
76- field ? . Add ( value ) ;
76+ if ( values == null )
77+ field = null ;
78+ else
79+ field ? . AddRange ( values ) ;
80+
7781 return this as TFixture ?? throw new InvalidOperationException ( ) ;
7882 }
7983
@@ -85,6 +89,7 @@ protected TFixture With<TField>(ref Collection<TField>? field, TField value)
8589 /// <param name="field">The field.</param>
8690 /// <param name="value">The value.</param>
8791 /// <returns>The fixture.</returns>
92+ /// <exception cref="InvalidOperationException">Throws if it cannot cast the fixture.</exception>
8893 protected TFixture With < TField > ( ref List < TField > ? field , TField value )
8994 {
9095 field ? . Add ( value ) ;
@@ -100,6 +105,7 @@ protected TFixture With<TField>(ref List<TField>? field, TField value)
100105 /// <param name="dictionary">The dictionary.</param>
101106 /// <param name="keyValuePair">The key value pair.</param>
102107 /// <returns>The fixture.</returns>
108+ /// <exception cref="InvalidOperationException">Throws if it cannot cast the fixture.</exception>
103109 protected TFixture With < TKey , TField > (
104110 ref Dictionary < TKey , TField > dictionary ,
105111 KeyValuePair < TKey , TField > keyValuePair
@@ -122,6 +128,7 @@ KeyValuePair<TKey, TField> keyValuePair
122128 /// <param name="key">The key.</param>
123129 /// <param name="value">The value.</param>
124130 /// <returns>The fixture.</returns>
131+ /// <exception cref="InvalidOperationException">Throws if it cannot cast the fixture.</exception>
125132 protected TFixture With < TKey , TField > ( ref Dictionary < TKey , TField > dictionary , TKey key , TField value )
126133 where TKey : notnull
127134 {
@@ -140,6 +147,7 @@ protected TFixture With<TKey, TField>(ref Dictionary<TKey, TField> dictionary, T
140147 /// <param name="dictionary">The dictionary.</param>
141148 /// <param name="keyValuePair">The key value pair.</param>
142149 /// <returns>The fixture.</returns>
150+ /// <exception cref="InvalidOperationException">Throws if it cannot cast the fixture.</exception>
143151 protected TFixture With < TKey , TField > (
144152 ref Dictionary < TKey , TField > dictionary ,
145153 Dictionary < TKey , TField > keyValuePair
@@ -149,5 +157,21 @@ Dictionary<TKey, TField> keyValuePair
149157 dictionary = keyValuePair ;
150158 return this as TFixture ?? throw new InvalidOperationException ( ) ;
151159 }
160+
161+ /// <summary>
162+ /// Adds the specified lazy field to the fixture.
163+ /// </summary>
164+ /// <param name="field">The field.</param>
165+ /// <param name="value">The value.</param>
166+ /// <typeparam name="TFixture">The type of the fixture.</typeparam>
167+ /// <typeparam name="TField">The type of the field.</typeparam>
168+ /// <returns></returns>
169+ /// <returns>The fixture.</returns>
170+ /// <exception cref="InvalidOperationException">Throws if it cannot cast the fixture.</exception>
171+ protected TFixture With < TField > ( ref Lazy < TField > field , TField value )
172+ {
173+ field = new ( ( ) => value ) ;
174+ return this as TFixture ?? throw new InvalidOperationException ( ) ;
175+ }
152176 }
153- }
177+ }
0 commit comments