File tree Expand file tree Collapse file tree 11 files changed +106
-2
lines changed
src/EntityFrameworkCore.AutoFixture Expand file tree Collapse file tree 11 files changed +106
-2
lines changed Original file line number Diff line number Diff line change 33
44namespace EntityFrameworkCore . AutoFixture . Core
55{
6+ /// <summary>
7+ /// Customizes AutoFixture to resolve database context options from fixture.
8+ /// </summary>
69 public class DbContextCustomization : ICustomization
710 {
11+ /// <inheritdoc />
812 public virtual void Customize ( IFixture fixture )
913 {
1014 if ( fixture is null ) throw new ArgumentNullException ( nameof ( fixture ) ) ;
Original file line number Diff line number Diff line change 55
66namespace EntityFrameworkCore . AutoFixture . Core
77{
8+ /// <summary>
9+ /// Creates options builders from the current context.
10+ /// </summary>
811 public class DbContextOptionsSpecimenBuilder : ISpecimenBuilder
912 {
13+ /// <summary>
14+ /// Creates a new <see cref="DbContextOptionsBuilder"/> instance.
15+ /// </summary>
1016 public DbContextOptionsSpecimenBuilder ( )
1117 : this ( new IsDbContextOptionsSpecification ( ) )
1218 {
1319 }
1420
21+ /// <summary>
22+ /// Creates a new <see cref="DbContextOptionsBuilder"/> instance.
23+ /// </summary>
24+ /// <param name="optionsSpecification">The options builder specification.</param>
25+ /// <exception cref="ArgumentNullException">When <paramref name="optionsSpecification"/> is <see langword="null" />.</exception>
1526 public DbContextOptionsSpecimenBuilder ( IRequestSpecification optionsSpecification )
1627 {
1728 this . OptionsSpecification = optionsSpecification
1829 ?? throw new ArgumentNullException ( nameof ( optionsSpecification ) ) ;
1930 }
2031
32+ /// <summary>
33+ /// Gets the optiosn specification.
34+ /// </summary>
2135 public IRequestSpecification OptionsSpecification { get ; }
2236
37+ /// <inheritdoc />
2338 public object Create ( object request , ISpecimenContext context )
2439 {
2540 if ( context == null ) throw new ArgumentNullException ( nameof ( context ) ) ;
Original file line number Diff line number Diff line change @@ -4,6 +4,12 @@ namespace EntityFrameworkCore.AutoFixture.Core
44{
55 public interface IOptionsBuilder
66 {
7+ /// <summary>
8+ /// Builds a database context options instance for a <paramref name="type"/>.
9+ /// </summary>
10+ /// <param name="type">The database context type.</param>
11+ /// <returns>Returns a <see cref="Microsoft.EntityFrameworkCore.DbContextOptions{TContext}"/> instance,
12+ /// casted to <see cref="object" />.</returns>
713 object Build ( Type type ) ;
814 }
915}
Original file line number Diff line number Diff line change 55
66namespace EntityFrameworkCore . AutoFixture . Core
77{
8+ /// <summary>
9+ /// Creates database options builders for a <see cref="DbContext"/> type.
10+ /// </summary>
811 public abstract class OptionsBuilder : IOptionsBuilder
912 {
13+ /// <summary>
14+ /// Builds a database context options instance for a <paramref name="type"/>.
15+ /// </summary>
16+ /// <typeparam name="TContext">the database context type.</typeparam>
17+ /// <returns>Returns a <see cref="DbContextOptions{TContext}"/> instance,
18+ /// casted to <see cref="object" />.</returns>
1019 public abstract DbContextOptions < TContext > Build < TContext > ( ) where TContext : DbContext ;
1120
21+ /// <inheritdoc />
1222 public virtual object Build ( Type type )
1323 {
1424 if ( type == null ) throw new ArgumentNullException ( nameof ( type ) ) ;
Original file line number Diff line number Diff line change 44
55namespace EntityFrameworkCore . AutoFixture . InMemory
66{
7+ /// <summary>
8+ /// Customizes AutoFixture to create in memory database contexts.
9+ /// </summary>
710 public class InMemoryContextCustomization : DbContextCustomization
811 {
12+ /// <inheritdoc />
913 public override void Customize ( IFixture fixture )
1014 {
1115 if ( fixture is null ) throw new ArgumentNullException ( nameof ( fixture ) ) ;
Original file line number Diff line number Diff line change 44
55namespace EntityFrameworkCore . AutoFixture . InMemory
66{
7+ /// <summary>
8+ /// Creates database context options.
9+ /// </summary>
710 public class InMemoryOptionsBuilder : OptionsBuilder
811 {
12+ /// <summary>
13+ /// Creates a <see cref="InMemoryOptionsBuilder"/> instance.
14+ /// </summary>
15+ /// <param name="databaseName">The name of the database.</param>
16+ /// <exception cref="ArgumentNullException">When <paramref name="databaseName"/> is null.</exception>
917 public InMemoryOptionsBuilder ( string databaseName )
1018 {
1119 this . DatabaseName = databaseName
1220 ?? throw new ArgumentNullException ( nameof ( databaseName ) ) ;
1321 }
1422
23+ /// <summary>
24+ /// Creates a <see cref="InMemoryOptionsBuilder"/> instance.
25+ /// </summary>
1526 public InMemoryOptionsBuilder ( )
1627 : this ( Guid . NewGuid ( ) . ToString ( ) )
1728 {
1829 }
1930
31+ /// <summary>
32+ /// Gets the database name.
33+ /// </summary>
2034 public string DatabaseName { get ; }
2135
36+ /// <inheritdoc />
2237 public override DbContextOptions < TContext > Build < TContext > ( )
2338 => new DbContextOptionsBuilder < TContext > ( )
2439 . UseInMemoryDatabase ( this . DatabaseName )
Original file line number Diff line number Diff line change 44
55namespace EntityFrameworkCore . AutoFixture . InMemory
66{
7+ /// <summary>
8+ /// Creates in-memory options builders.
9+ /// </summary>
710 public class InMemoryOptionsSpecimenBuilder : ISpecimenBuilder
811 {
9- public IRequestSpecification OptionsSpecification { get ; }
10-
12+ /// <summary>
13+ /// Creates a <see cref="InMemoryOptionsSpecimenBuilder"/> instance.
14+ /// </summary>
15+ /// <param name="optionsSpecification">The options builder specification.</param>
16+ /// <exception cref="ArgumentNullException">When <paramref name="optionsSpecification"/> is <see langword="null" />.</exception>
1117 public InMemoryOptionsSpecimenBuilder ( IRequestSpecification optionsSpecification )
1218 {
1319 this . OptionsSpecification = optionsSpecification
1420 ?? throw new ArgumentNullException ( nameof ( optionsSpecification ) ) ;
1521 }
1622
23+ /// <summary>
24+ /// Creates a <see cref="InMemoryOptionsSpecimenBuilder"/> instance.
25+ /// </summary>
1726 public InMemoryOptionsSpecimenBuilder ( )
1827 : this ( new IsOptionsBuilder ( ) )
1928 {
2029 }
2130
31+ /// <summary>
32+ /// Gets the options specification.
33+ /// </summary>
34+ public IRequestSpecification OptionsSpecification { get ; }
35+
36+ /// <inheritdoc />
2237 public object Create ( object request , ISpecimenContext context )
2338 {
2439 if ( context == null ) throw new ArgumentNullException ( nameof ( context ) ) ;
Original file line number Diff line number Diff line change 44
55namespace EntityFrameworkCore . AutoFixture . Sqlite
66{
7+ /// <summary>
8+ /// Creates <see cref="SqliteConnection"/> instances.
9+ /// </summary>
710 public class SqliteConnectionSpecimenBuilder : ISpecimenBuilder
811 {
912 public SqliteConnectionSpecimenBuilder ( IRequestSpecification connectionSpecification )
@@ -19,6 +22,7 @@ public SqliteConnectionSpecimenBuilder()
1922
2023 public IRequestSpecification ConnectionSpecification { get ; }
2124
25+ /// <inheritdoc />
2226 public object Create ( object request , ISpecimenContext context )
2327 {
2428 if ( context == null ) throw new ArgumentNullException ( nameof ( context ) ) ;
Original file line number Diff line number Diff line change 44
55namespace EntityFrameworkCore . AutoFixture . Sqlite
66{
7+ /// <summary>
8+ /// Customizes AutoFixture to create sqlite Entity Framework database ontexts.
9+ /// </summary>
710 public class SqliteContextCustomization : DbContextCustomization
811 {
12+ /// <inheritdoc />
913 public override void Customize ( IFixture fixture )
1014 {
1115 if ( fixture is null ) throw new ArgumentNullException ( nameof ( fixture ) ) ;
Original file line number Diff line number Diff line change 55
66namespace EntityFrameworkCore . AutoFixture . Sqlite
77{
8+ /// <summary>
9+ /// Creates <see cref="DbContextOptions{TContext}"/> using SQLite.
10+ /// </summary>
811 public class SqliteOptionsBuilder : OptionsBuilder
912 {
1013 public SqliteOptionsBuilder ( SqliteConnection connection )
@@ -13,8 +16,17 @@ public SqliteOptionsBuilder(SqliteConnection connection)
1316 ?? throw new ArgumentNullException ( nameof ( connection ) ) ;
1417 }
1518
19+ /// <summary>
20+ /// Gets the database connection.
21+ /// </summary>
1622 public SqliteConnection Connection { get ; }
1723
24+ /// <summary>
25+ /// Builds default <see cref="DbContextOptions{TContext}"/>,
26+ /// using the SQLite connection.
27+ /// </summary>
28+ /// <typeparam name="TContext"></typeparam>
29+ /// <returns>Returns a <see cref="DbContextOptions{TContext}" /> instance.</returns>
1830 public override DbContextOptions < TContext > Build < TContext > ( )
1931 => new DbContextOptionsBuilder < TContext > ( )
2032 . UseSqlite ( this . Connection )
You can’t perform that action at this time.
0 commit comments