-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better Collection and ReadOnlyCollection support
New generators, additional tests
- Loading branch information
Showing
16 changed files
with
280 additions
and
80 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using Soenneker.Utils.AutoBogus.Context; | ||
using Soenneker.Utils.AutoBogus.Extensions; | ||
using Soenneker.Utils.AutoBogus.Generators.Abstract; | ||
|
||
namespace Soenneker.Utils.AutoBogus.Generators.Types; | ||
|
||
internal sealed class CollectionGenerator<TType> : IAutoFakerGenerator | ||
{ | ||
object IAutoFakerGenerator.Generate(AutoFakerContext context) | ||
{ | ||
Collection<TType> collection; | ||
|
||
if (context.CachedType.IsInterface) | ||
{ | ||
collection = []; | ||
} | ||
else | ||
{ | ||
try | ||
{ | ||
collection = context.CachedType.CreateInstance<Collection<TType>>(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
collection = []; | ||
} | ||
} | ||
|
||
List<TType> items = context.GenerateMany<TType>(); | ||
|
||
for (var i = 0; i < items.Count; i++) | ||
{ | ||
TType item = items[i]; | ||
collection.Add(item); | ||
} | ||
|
||
return collection; | ||
} | ||
} |
This file contains 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,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using Soenneker.Utils.AutoBogus.Context; | ||
using Soenneker.Utils.AutoBogus.Extensions; | ||
using Soenneker.Utils.AutoBogus.Generators.Abstract; | ||
|
||
namespace Soenneker.Utils.AutoBogus.Generators.Types; | ||
|
||
internal sealed class ReadOnlyCollectionGenerator<TType> : IAutoFakerGenerator | ||
{ | ||
object IAutoFakerGenerator.Generate(AutoFakerContext context) | ||
{ | ||
List<TType> items = context.GenerateMany<TType>(); | ||
|
||
try | ||
{ | ||
ReadOnlyCollection<TType> collection = new ReadOnlyCollection<TType>(items); | ||
return collection; | ||
} | ||
catch (Exception ex) | ||
{ | ||
return null!; | ||
} | ||
} | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.