├── .editorconfig
├── .gitignore
├── CONTRIBUTING.md
├── CustomDictionary.xml
├── LICENSE
├── MicroLite.Tests
├── App.config
├── Builder
│ ├── DeleteSqlBuilderTests.cs
│ ├── InsertSqlBuilderTests.cs
│ ├── RawWhereBuilderTests.cs
│ ├── SelectSqlBuilderTests.cs
│ ├── SqlBuilderTests.cs
│ ├── StoredProcedureSqlBuilderTests.cs
│ └── UpdateSqlBuilderTests.cs
├── Characters
│ ├── FirebirdSqlCharactersTests.cs
│ ├── MsSqlCharactersTests.cs
│ ├── MySqlCharactersTests.cs
│ ├── PostgreSqlCharactersTests.cs
│ ├── SQLiteCharactersTests.cs
│ └── SqlCharactersTests.cs
├── Collections
│ └── StackCollectionTests.cs
├── Configuration
│ ├── ConfigurationExtensionsTests.cs
│ ├── ConfigureExtensionsTests.cs
│ ├── ConfigureTests.cs
│ └── FluentConfigurationTests.cs
├── Core
│ ├── IncludeManyTests.cs
│ ├── IncludeScalarTests.cs
│ ├── IncludeSingleTests.cs
│ ├── ReadOnlySessionTests.cs
│ ├── SessionBaseTests.cs
│ ├── SessionFactoryTests.cs
│ ├── SessionTests.cs
│ └── TransactionTests.cs
├── Dialect
│ ├── FirebirdSqlDialectTests.cs
│ ├── MsSql2005DialectTests.cs
│ ├── MsSql2012DialectTests.cs
│ ├── MySqlDialectTests.cs
│ ├── PostgreSqlDialectTests.cs
│ ├── SQLiteDialectTests.cs
│ └── SqlDialectTests.cs
├── Driver
│ ├── DbDriverTests.cs
│ ├── FirebirdDbDriverTests.cs
│ ├── MsSqlDbDriverTests.cs
│ ├── MySqlDbDriverTests.cs
│ ├── PostgreSqlDbDriverTests.cs
│ └── SQLiteDbDriverTests.cs
├── Listeners
│ └── IdentifierStrategyListenerTests.cs
├── Logging
│ └── LogManagerTests.cs
├── Mapping
│ ├── Attributes
│ │ ├── AttributeMappingConventionTests.cs
│ │ ├── ColumnAttributeTests.cs
│ │ ├── IdentifierAttributeTests.cs
│ │ └── TableAttributeTests.cs
│ ├── ColumnInfoTests.cs
│ ├── ConventionMappingConventionTests.cs
│ ├── ConventionMappingSettingsTests.cs
│ ├── ExpandoObjectInfoTests.cs
│ ├── Inflection
│ │ ├── EnglishInflectionServiceTests.cs
│ │ └── InflectionServiceTests.cs
│ ├── LowercaseWithUnderscoresConventionMappingSettingsTests.cs
│ ├── ObjectInfoTests.cs
│ ├── PocoObjectInfoTests.cs
│ ├── TableInfoTests.cs
│ ├── TupleObjectInfoTests.cs
│ └── UppercaseWithUnderscoresConventionMappingSettingsTests.cs
├── MicroLite.Tests.csproj
├── ObjectDeltaTests.cs
├── PagedResultTests.cs
├── PagingOptionsTests.cs
├── ParameterNameComparerTests.cs
├── Properties
│ └── AssemblyInfo.cs
├── SqlArgumentTests.cs
├── SqlQueryTests.cs
├── SqlStringTests.cs
├── SqlUtilityTests.cs
├── TestEntities
│ ├── CreditCard.cs
│ ├── Customer.cs
│ ├── CustomerStatus.cs
│ ├── Invoice.cs
│ ├── MockDbCommandWrapper.cs
│ ├── MockDbConnectionWrapper.cs
│ ├── MockDbDataReaderWrapper.cs
│ └── MockDbTransactionWrapper.cs
├── TypeConverters
│ ├── EnumTypeConverterTests.cs
│ ├── ObjectTypeConverterTests.cs
│ ├── TimeSpanTypeConverterTest.cs
│ ├── TypeConverterCollectionTests.cs
│ ├── TypeConverterTests.cs
│ ├── UriTypeConverterTests.cs
│ └── XDocumentTypeConverterTests.cs
├── UnitTest.cs
└── packages.config
├── MicroLite.sln
├── MicroLite.snk
├── MicroLite
├── Builder
│ ├── DeleteSqlBuilder.cs
│ ├── InsertSqlBuilder.cs
│ ├── RawWhereBuilder.cs
│ ├── SelectSqlBuilder.cs
│ ├── SqlBuilder.cs
│ ├── SqlBuilderBase.cs
│ ├── StoredProcedureSqlBuilder.cs
│ ├── Syntax
│ │ ├── IToSqlQuery.cs
│ │ ├── IWithParameter.cs
│ │ ├── Read
│ │ │ ├── IAndOrOrderBy.cs
│ │ │ ├── IFunctionOrFrom.cs
│ │ │ ├── IGroupBy.cs
│ │ │ ├── IHavingOrOrderBy.cs
│ │ │ ├── IOrderBy.cs
│ │ │ ├── ISelectFrom.cs
│ │ │ ├── IWhereExists.cs
│ │ │ ├── IWhereOrOrderBy.cs
│ │ │ ├── IWhereSingleColumn.cs
│ │ │ └── _Read.cd
│ │ └── Write
│ │ │ ├── IAndOr.cs
│ │ │ ├── IDeleteFrom.cs
│ │ │ ├── IInsertColumn.cs
│ │ │ ├── IInsertIntoTable.cs
│ │ │ ├── IInsertValue.cs
│ │ │ ├── ISetOrWhere.cs
│ │ │ ├── IUpdate.cs
│ │ │ ├── IWhere.cs
│ │ │ ├── IWhereSingleColumn.cs
│ │ │ └── _Write.cd
│ ├── UpdateSqlBuilder.cs
│ ├── WriteSqlBuilderBase.cs
│ └── _SqlBuilders.cd
├── Characters
│ ├── FirebirdSqlCharacters.cs
│ ├── MsSqlCharacters.cs
│ ├── MySqlCharacters.cs
│ ├── PostgreSqlCharacters.cs
│ ├── SQLiteCharacters.cs
│ ├── SqlCharacters.cs
│ └── _SqlCharacters.cd
├── Clauses.cs
├── Collections
│ └── StackCollection{T}.cs
├── Configuration
│ ├── ConfigurationException.cs
│ ├── ConfigurationExtensions.cs
│ ├── Configure.cs
│ ├── ConfigureExtensions.cs
│ ├── FluentConfiguration.cs
│ ├── IConfigureConnection.cs
│ ├── IConfigureExtensions.cs
│ ├── ICreateSessionFactory.cs
│ └── _Configuration.cd
├── ConnectionScope.cs
├── Core
│ ├── ISessionBase.cs
│ ├── Include.cs
│ ├── IncludeMany.cs
│ ├── IncludeScalar.cs
│ ├── IncludeSingle.cs
│ ├── ReadOnlySession.cs
│ ├── Session.cs
│ ├── SessionBase.cs
│ ├── SessionFactory.cs
│ ├── Transaction.cs
│ ├── _Includes.cd
│ └── _Session.cd
├── Dialect
│ ├── FirebirdSqlDialect.cs
│ ├── ISqlDialect.cs
│ ├── MsSql2005Dialect.cs
│ ├── MsSql2012Dialect.cs
│ ├── MySqlDialect.cs
│ ├── PostgreSqlDialect.cs
│ ├── SQLiteDialect.cs
│ ├── SqlDialect.cs
│ └── _SqlDialect.cd
├── Driver
│ ├── DbDriver.cs
│ ├── FirebirdDbDriver.cs
│ ├── IDbDriver.cs
│ ├── MsSqlDbDriver.cs
│ ├── MySqlDbDriver.cs
│ ├── PostgreSqlDbDriver.cs
│ ├── SQLiteDbDriver.cs
│ └── _Driver.cd
├── ExceptionMessages.Designer.cs
├── ExceptionMessages.resx
├── FrameworkExtensions
│ └── StringExtensions.cs
├── IAdvancedReadOnlySession.cs
├── IAdvancedSession.cs
├── IInclude.cs
├── IIncludeMany.cs
├── IIncludeSession.cs
├── IReadOnlySession.cs
├── ISession.cs
├── ISessionFactory.cs
├── ITransaction.cs
├── Infrastructure
│ ├── IHaveReadOnlySession.cs
│ └── IHaveSession.cs
├── Listeners
│ ├── IDeleteListener.cs
│ ├── IInsertListener.cs
│ ├── IUpdateListener.cs
│ ├── IdentifierStrategyListener.cs
│ ├── Listener.cs
│ ├── SessionListeners.cs
│ └── _Listeners.cd
├── Logging
│ ├── EmptyLog.cs
│ ├── ILog.cs
│ ├── LogManager.cs
│ ├── LogMessages.Designer.cs
│ ├── LogMessages.resx
│ └── _Logging.cd
├── Mapping
│ ├── Attributes
│ │ ├── AttributeMappingConvention.cs
│ │ ├── ColumnAttribute.cs
│ │ ├── IdentifierAttribute.cs
│ │ ├── TableAttribute.cs
│ │ └── _MappingAttributes.cd
│ ├── ColumnInfo.cs
│ ├── ConventionMappingConvention.cs
│ ├── ConventionMappingSettings.cs
│ ├── DelegateFactory.cs
│ ├── ExpandoObjectInfo.cs
│ ├── ILGeneratorExtensions.cs
│ ├── IMappingConvention.cs
│ ├── IObjectInfo.cs
│ ├── IdentifierStrategy.cs
│ ├── Inflection
│ │ ├── EnglishInflectionService.cs
│ │ ├── IInflectionService.cs
│ │ ├── InflectionService.cs
│ │ └── _Inflection.cd
│ ├── LowercaseWithUnderscoresConventionMappingSettings.cs
│ ├── MappingException.cs
│ ├── MemberInfoExtensions.cs
│ ├── ObjectInfo.cs
│ ├── ObjectInfoExtensions.cs
│ ├── PocoObjectInfo.cs
│ ├── TableInfo.cs
│ ├── TupleObjectInfo.cs
│ ├── UppercaseWithUnderscoresConventionMappingSettings.cs
│ ├── _MappingConvention.cd
│ └── _ObjectInfo.cd
├── MicroLite.csproj
├── MicroLiteException.cs
├── ObjectDelta.cs
├── PagedResult.cs
├── PagingOptions.cs
├── ParameterNameComparer.cs
├── Properties
│ └── AssemblyInfo.cs
├── SqlArgument.cs
├── SqlQuery.cs
├── SqlString.cs
├── SqlUtility.cs
├── TypeConverters
│ ├── EnumTypeConverter.cs
│ ├── ITypeConverter.cs
│ ├── ObjectTypeConverter.cs
│ ├── TimeSpanTypeConverter.cs
│ ├── TypeConverter.cs
│ ├── TypeConverterCollection.cs
│ ├── UriTypeConverter.cs
│ ├── XDocumentTypeConverter.cs
│ └── _TypeConverters.cd
└── _Session.cd
├── README.md
├── azure-pipelines.yml
├── nuget.config
└── stylecop.json
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Contributing to MicroLite
2 | =========================
3 |
4 | There are a number of ways you can contribute to the MicroLite project:
5 |
6 | * Identifying defects - send us a failing unit test
7 | * Fixing defects - send us a fix and supporting unit test(s)
8 | * Implementing features - send us code and unit tests for any enhancement listed in the [issues list](https://github.com/TrevorPilley/MicroLite/issues)
9 |
10 | _note: if the defect is one you have identified, please add it as an issue before sending a fix_
11 |
12 | In order to contribute any code, you will need to fork the MicroLite repository and then:
13 |
14 | * If the change you want to make is to identify a defect, work in develop, add a failing unit test and send a pull request to the develop branch in the main MicroLite repository.
15 | * If the change you want to make is to fix a defect, work in master, add the fix and unit test(s) and send a pull request to both the develop and master branches in the main MicroLite repository.
16 | * If you want to implement a feature, you will either need to work in the development branch or the feature branch if one exists for the specific feature you want to work on and then send a pull request to the corresponding branch in the main MicroLite repository.
--------------------------------------------------------------------------------
/CustomDictionary.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | en-GB
9 | Enum
10 | Lite
11 | Ms
12 | My
13 | Nullable
14 | Poco
15 | Postgre
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | Db
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/MicroLite.Tests/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/MicroLite.Tests/Builder/RawWhereBuilderTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.Builder
2 | {
3 | using System;
4 | using MicroLite.Builder;
5 | using MicroLite.Builder.Syntax.Read;
6 | using Moq;
7 | using Xunit;
8 |
9 | ///
10 | /// Unit Tests for the class.
11 | ///
12 | public class RawWhereBuilderTests
13 | {
14 | [Fact]
15 | public void ApplyToEnsuresParametersAreRenumberedAndAllArgumentsAreAppended()
16 | {
17 | var rawWhereBuilder = new RawWhereBuilder();
18 | rawWhereBuilder.Append("ForeName = @p0 AND Surname = @p1", "Fred", "Flintstone")
19 | .Append(" AND Created > @p0", DateTime.Today)
20 | .Append(" AND LastLogin IS NOT NULL");
21 |
22 | var mockSqlBuilder = new Mock();
23 |
24 | rawWhereBuilder.ApplyTo(mockSqlBuilder.Object);
25 |
26 | mockSqlBuilder.Verify(
27 | x => x.Where("ForeName = @p0 AND Surname = @p1 AND Created > @p2 AND LastLogin IS NOT NULL", "Fred", "Flintstone", DateTime.Today),
28 | Times.Once());
29 | }
30 |
31 | [Fact]
32 | public void ApplyToThrowsArgumentNullExceptionForNullSqlBuilder()
33 | {
34 | var rawWhereBuilder = new RawWhereBuilder();
35 |
36 | var exception = Assert.Throws(() => rawWhereBuilder.ApplyTo(null));
37 |
38 | Assert.Equal("selectFrom", exception.ParamName);
39 | }
40 |
41 | [Fact]
42 | public void ToStringReturnsInnerSql()
43 | {
44 | var rawWhereBuilder = new RawWhereBuilder();
45 | rawWhereBuilder.Append("Forename = @p0", "Fred");
46 |
47 | Assert.Equal("Forename = @p0", rawWhereBuilder.ToString());
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/Builder/StoredProcedureSqlBuilderTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.Builder
2 | {
3 | using System;
4 | using System.Data;
5 | using MicroLite.Builder;
6 | using MicroLite.Characters;
7 | using Xunit;
8 |
9 | ///
10 | /// Unit Tests for the class.
11 | ///
12 | public class StoredProcedureSqlBuilderTests
13 | {
14 | [Fact]
15 | public void Execute()
16 | {
17 | var sqlBuilder = new StoredProcedureSqlBuilder(new TestSqlCharacters(), "GetCustomerInvoices");
18 |
19 | var sqlQuery = sqlBuilder
20 | .WithParameter("@CustomerId", 7633245)
21 | .WithParameter("@StartDate", DateTime.Today.AddMonths(-3))
22 | .WithParameter("@EndDate", DateTime.Today)
23 | .ToSqlQuery();
24 |
25 | Assert.Equal("INVOKE GetCustomerInvoices @CustomerId,@StartDate,@EndDate", sqlQuery.CommandText);
26 |
27 | Assert.Equal(3, sqlQuery.Arguments.Count);
28 |
29 | Assert.Equal(DbType.Int32, sqlQuery.Arguments[0].DbType);
30 | Assert.Equal(7633245, sqlQuery.Arguments[0].Value);
31 |
32 | Assert.Equal(DbType.DateTime2, sqlQuery.Arguments[1].DbType);
33 | Assert.Equal(DateTime.Today.AddMonths(-3), sqlQuery.Arguments[1].Value);
34 |
35 | Assert.Equal(DbType.DateTime2, sqlQuery.Arguments[2].DbType);
36 | Assert.Equal(DateTime.Today, sqlQuery.Arguments[2].Value);
37 | }
38 |
39 | ///
40 | /// Overrides the base properties with non standard values for testing.
41 | ///
42 | private sealed class TestSqlCharacters : SqlCharacters
43 | {
44 | public override string StoredProcedureInvocationCommand
45 | {
46 | get
47 | {
48 | return "INVOKE";
49 | }
50 | }
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/Characters/FirebirdSqlCharactersTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.Characters
2 | {
3 | using MicroLite.Characters;
4 | using Xunit;
5 |
6 | ///
7 | /// Unit Tests for the class.
8 | ///
9 | public class FirebirdSqlCharactersTests
10 | {
11 | [Fact]
12 | public void InstanceReturnsTheSameInstanceEachTime()
13 | {
14 | var characters1 = FirebirdSqlCharacters.Instance;
15 | var characters2 = FirebirdSqlCharacters.Instance;
16 |
17 | Assert.Same(characters1, characters2);
18 | }
19 |
20 | [Fact]
21 | public void LeftDelimiterReturnsCorrectValue()
22 | {
23 | Assert.Equal("\"", FirebirdSqlCharacters.Instance.LeftDelimiter);
24 | }
25 |
26 | [Fact]
27 | public void RightDelimiterReturnsCorrectValue()
28 | {
29 | Assert.Equal("\"", FirebirdSqlCharacters.Instance.RightDelimiter);
30 | }
31 |
32 | [Fact]
33 | public void SqlParameterReturnsAtSign()
34 | {
35 | Assert.Equal("@", FirebirdSqlCharacters.Instance.SqlParameter);
36 | }
37 |
38 | [Fact]
39 | public void SupportsNamedParametersReturnsTrue()
40 | {
41 | Assert.True(FirebirdSqlCharacters.Instance.SupportsNamedParameters);
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/Characters/MsSqlCharactersTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.Characters
2 | {
3 | using MicroLite.Characters;
4 | using Xunit;
5 |
6 | ///
7 | /// Unit Tests for the class.
8 | ///
9 | public class MsSqlCharactersTests
10 | {
11 | [Fact]
12 | public void InstanceReturnsTheSameInstanceEachTime()
13 | {
14 | var characters1 = MsSqlCharacters.Instance;
15 | var characters2 = MsSqlCharacters.Instance;
16 |
17 | Assert.Same(characters1, characters2);
18 | }
19 |
20 | [Fact]
21 | public void LeftDelimiterReturnsCorrectValue()
22 | {
23 | Assert.Equal("[", MsSqlCharacters.Instance.LeftDelimiter);
24 | }
25 |
26 | [Fact]
27 | public void RightDelimiterReturnsCorrectValue()
28 | {
29 | Assert.Equal("]", MsSqlCharacters.Instance.RightDelimiter);
30 | }
31 |
32 | [Fact]
33 | public void SqlParameterReturnsAtSign()
34 | {
35 | Assert.Equal("@", MsSqlCharacters.Instance.SqlParameter);
36 | }
37 |
38 | [Fact]
39 | public void StoredProcedureInvocationCommandReturnsExec()
40 | {
41 | Assert.Equal("EXEC", MsSqlCharacters.Instance.StoredProcedureInvocationCommand);
42 | }
43 |
44 | [Fact]
45 | public void SupportsNamedParametersReturnsTrue()
46 | {
47 | Assert.True(MsSqlCharacters.Instance.SupportsNamedParameters);
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/Characters/MySqlCharactersTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.Characters
2 | {
3 | using MicroLite.Characters;
4 | using Xunit;
5 |
6 | ///
7 | /// Unit Tests for the class.
8 | ///
9 | public class MySqlCharactersTests
10 | {
11 | [Fact]
12 | public void InstanceReturnsTheSameInstanceEachTime()
13 | {
14 | var characters1 = MySqlCharacters.Instance;
15 | var characters2 = MySqlCharacters.Instance;
16 |
17 | Assert.Same(characters1, characters2);
18 | }
19 |
20 | [Fact]
21 | public void LeftDelimiterReturnsCorrectValue()
22 | {
23 | Assert.Equal("`", MySqlCharacters.Instance.LeftDelimiter);
24 | }
25 |
26 | [Fact]
27 | public void RightDelimiterReturnsCorrectValue()
28 | {
29 | Assert.Equal("`", MySqlCharacters.Instance.RightDelimiter);
30 | }
31 |
32 | [Fact]
33 | public void SqlParameterReturnsAtSign()
34 | {
35 | Assert.Equal("@", MySqlCharacters.Instance.SqlParameter);
36 | }
37 |
38 | [Fact]
39 | public void StoredProcedureInvocationCommandReturnsCall()
40 | {
41 | Assert.Equal("CALL", MySqlCharacters.Instance.StoredProcedureInvocationCommand);
42 | }
43 |
44 | [Fact]
45 | public void SupportsNamedParametersReturnsTrue()
46 | {
47 | Assert.True(MySqlCharacters.Instance.SupportsNamedParameters);
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/Characters/PostgreSqlCharactersTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.Characters
2 | {
3 | using MicroLite.Characters;
4 | using Xunit;
5 |
6 | ///
7 | /// Unit Tests for the class.
8 | ///
9 | public class PostgreSqlCharactersTests
10 | {
11 | [Fact]
12 | public void InstanceReturnsTheSameInstanceEachTime()
13 | {
14 | var characters1 = PostgreSqlCharacters.Instance;
15 | var characters2 = PostgreSqlCharacters.Instance;
16 |
17 | Assert.Same(characters1, characters2);
18 | }
19 |
20 | [Fact]
21 | public void LeftDelimiterReturnsCorrectValue()
22 | {
23 | Assert.Equal("\"", PostgreSqlCharacters.Instance.LeftDelimiter);
24 | }
25 |
26 | [Fact]
27 | public void RightDelimiterReturnsCorrectValue()
28 | {
29 | Assert.Equal("\"", PostgreSqlCharacters.Instance.RightDelimiter);
30 | }
31 |
32 | [Fact]
33 | public void SqlParameterReturnsAtSign()
34 | {
35 | Assert.Equal("@", PostgreSqlCharacters.Instance.SqlParameter);
36 | }
37 |
38 | [Fact]
39 | public void StoredProcedureInvocationCommandReturnsSelect()
40 | {
41 | Assert.Equal("SELECT", PostgreSqlCharacters.Instance.StoredProcedureInvocationCommand);
42 | }
43 |
44 | [Fact]
45 | public void SupportsNamedParametersReturnsTrue()
46 | {
47 | Assert.True(PostgreSqlCharacters.Instance.SupportsNamedParameters);
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/Characters/SQLiteCharactersTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.Characters
2 | {
3 | using MicroLite.Characters;
4 | using Xunit;
5 |
6 | ///
7 | /// Unit Tests for the class.
8 | ///
9 | public class SQLiteCharactersTests
10 | {
11 | [Fact]
12 | public void InstanceReturnsTheSameInstanceEachTime()
13 | {
14 | var characters1 = SQLiteCharacters.Instance;
15 | var characters2 = SQLiteCharacters.Instance;
16 |
17 | Assert.Same(characters1, characters2);
18 | }
19 |
20 | [Fact]
21 | public void LeftDelimiterReturnsCorrectValue()
22 | {
23 | Assert.Equal("\"", SQLiteCharacters.Instance.LeftDelimiter);
24 | }
25 |
26 | [Fact]
27 | public void RightDelimiterReturnsCorrectValue()
28 | {
29 | Assert.Equal("\"", SQLiteCharacters.Instance.RightDelimiter);
30 | }
31 |
32 | [Fact]
33 | public void SqlParameterReturnsAtSign()
34 | {
35 | Assert.Equal("@", SQLiteCharacters.Instance.SqlParameter);
36 | }
37 |
38 | [Fact]
39 | public void SupportsNamedParametersReturnsTrue()
40 | {
41 | Assert.True(SQLiteCharacters.Instance.SupportsNamedParameters);
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/Collections/StackCollectionTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.Collections
2 | {
3 | using MicroLite.Collections;
4 | using Xunit;
5 |
6 | public class StackCollectionTests
7 | {
8 | public class WhenAddingItems
9 | {
10 | private readonly StackCollection collection = new StackCollection();
11 |
12 | [Fact]
13 | public void ItemsAreAddedToTheTopOfTheCollection()
14 | {
15 | collection.Add("Added First");
16 | Assert.Single(collection);
17 | Assert.Equal("Added First", collection[0]);
18 |
19 | collection.Add("Added Second");
20 | Assert.Equal(2, collection.Count);
21 | Assert.Equal("Added Second", collection[0]);
22 | Assert.Equal("Added First", collection[1]);
23 | }
24 | }
25 |
26 | public class WhenConstructed
27 | {
28 | private readonly StackCollection collection = new StackCollection();
29 |
30 | [Fact]
31 | public void TheCollectionIsEmpty()
32 | {
33 | Assert.Empty(collection);
34 | }
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/Configuration/ConfigureExtensionsTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.Configuration
2 | {
3 | using System;
4 | using MicroLite.Configuration;
5 | using MicroLite.Logging;
6 | using MicroLite.Mapping;
7 | using Moq;
8 | using Xunit;
9 |
10 | ///
11 | /// Unit Tests for the class.
12 | ///
13 | public class ConfigureExtensionsTests
14 | {
15 | public class WhenCallingSetLogResolver : UnitTest
16 | {
17 | private readonly Func resolver = (s) =>
18 | {
19 | return EmptyLog.Instance;
20 | };
21 |
22 | public WhenCallingSetLogResolver()
23 | {
24 | var configureExtensions = new ConfigureExtensions();
25 | configureExtensions.SetLogResolver(this.resolver);
26 | }
27 |
28 | [Fact]
29 | public void TheLogManagerGetLoggerMethodShouldBeSet()
30 | {
31 | Assert.Same(this.resolver, LogManager.GetLogger);
32 | }
33 | }
34 |
35 | public class WhenCallingSetMappingConvention : UnitTest
36 | {
37 | private readonly IMappingConvention mappingConvention = new Mock().Object;
38 |
39 | public WhenCallingSetMappingConvention()
40 | {
41 | var configureExtensions = new ConfigureExtensions();
42 | configureExtensions.SetMappingConvention(this.mappingConvention);
43 | }
44 |
45 | [Fact]
46 | public void TheObjectInfoMappingConventionShouldBeSet()
47 | {
48 | Assert.Same(this.mappingConvention, ObjectInfo.MappingConvention);
49 | }
50 | }
51 |
52 | public class WhenCallingSetMappingConventionAndTheMappingConventionIsNull
53 | {
54 | [Fact]
55 | public void AnArgumentNullExceptionShouldBeThrown()
56 | {
57 | var configureExtensions = new ConfigureExtensions();
58 |
59 | var exception = Assert.Throws(() => configureExtensions.SetMappingConvention(null));
60 |
61 | Assert.Equal("mappingConvention", exception.ParamName);
62 | }
63 | }
64 | }
65 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/Configuration/ConfigureTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.Configuration
2 | {
3 | using MicroLite.Configuration;
4 | using Xunit;
5 |
6 | ///
7 | /// Unit Tests for the class.
8 | ///
9 | public class ConfigureTests
10 | {
11 | public class WhenCallingExtensionsMultipleTimes
12 | {
13 | private readonly IConfigureExtensions extensions1;
14 | private readonly IConfigureExtensions extensions2;
15 |
16 | public WhenCallingExtensionsMultipleTimes()
17 | {
18 | this.extensions1 = Configure.Extensions();
19 | this.extensions2 = Configure.Extensions();
20 | }
21 |
22 | [Fact]
23 | public void ANewInstanceShouldBeReturnedEachTime()
24 | {
25 | Assert.NotSame(this.extensions1, this.extensions2);
26 | }
27 | }
28 |
29 | public class WhenCallingFluentlyMultipleTimes
30 | {
31 | private readonly IConfigureConnection configure1;
32 | private readonly IConfigureConnection configure2;
33 |
34 | public WhenCallingFluentlyMultipleTimes()
35 | {
36 | this.configure1 = Configure.Fluently();
37 | this.configure2 = Configure.Fluently();
38 | }
39 |
40 | [Fact]
41 | public void ANewInstanceShouldBeReturnedEachTime()
42 | {
43 | Assert.NotSame(this.configure1, this.configure2);
44 | }
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/Driver/FirebirdDbDriverTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.Driver
2 | {
3 | using MicroLite.Driver;
4 | using Xunit;
5 |
6 | ///
7 | /// Unit Tests for the class.
8 | ///
9 | public class FirebirdDbDriverTests : UnitTest
10 | {
11 | [Fact]
12 | public void SupportsBatchedQueriesReturnsFalse()
13 | {
14 | var dbDriver = new FirebirdDbDriver();
15 |
16 | Assert.False(dbDriver.SupportsBatchedQueries);
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/Driver/SQLiteDbDriverTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.Driver
2 | {
3 | using MicroLite.Driver;
4 | using Xunit;
5 |
6 | ///
7 | /// Unit Tests for the class.
8 | ///
9 | public class SQLiteDbDriverTests : UnitTest
10 | {
11 | [Fact]
12 | public void SupportsBatchedQueriesReturnsTrue()
13 | {
14 | var dbDriver = new SQLiteDbDriver();
15 |
16 | Assert.True(dbDriver.SupportsBatchedQueries);
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/Logging/LogManagerTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.Logging
2 | {
3 | using System;
4 | using MicroLite.Logging;
5 | using Moq;
6 | using Xunit;
7 |
8 | ///
9 | /// Unit Tests for the class.
10 | ///
11 | public class LogManagerTests : UnitTest
12 | {
13 | [Fact]
14 | public void GetCurrentClassLogReturnsEmptyLogIfGetLoggerNotSet()
15 | {
16 | Assert.IsType(LogManager.GetCurrentClassLog());
17 | }
18 |
19 | [Fact]
20 | public void GetCurrentClassLogReturnsLogIfGetLoggerSet()
21 | {
22 | var log = new Mock().Object;
23 |
24 | LogManager.GetLogger = (Type type) =>
25 | {
26 | return log;
27 | };
28 |
29 | var logInstance = LogManager.GetCurrentClassLog();
30 |
31 | Assert.Same(log, logInstance);
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/Mapping/Attributes/ColumnAttributeTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.Mapping.Attributes
2 | {
3 | using MicroLite.Mapping.Attributes;
4 | using Xunit;
5 |
6 | ///
7 | /// Unit Tests for the class.
8 | ///
9 | public class ColumnAttributeTests
10 | {
11 | [Fact]
12 | public void ConstructorSetsAllowInsert()
13 | {
14 | var columnAttribute = new ColumnAttribute("Foo", allowInsert: true, allowUpdate: false);
15 |
16 | Assert.Equal("Foo", columnAttribute.Name);
17 | Assert.True(columnAttribute.AllowInsert);
18 | Assert.False(columnAttribute.AllowUpdate);
19 | }
20 |
21 | [Fact]
22 | public void ConstructorSetsAllowUpdate()
23 | {
24 | var columnAttribute = new ColumnAttribute("Foo", allowInsert: false, allowUpdate: true);
25 |
26 | Assert.Equal("Foo", columnAttribute.Name);
27 | Assert.False(columnAttribute.AllowInsert);
28 | Assert.True(columnAttribute.AllowUpdate);
29 | }
30 |
31 | [Fact]
32 | public void ConstructorSetsNameDbTypeToNullAndAllowInsertAndAllowUpdateToTrue()
33 | {
34 | var columnAttribute = new ColumnAttribute("ObjectID");
35 |
36 | Assert.Equal("ObjectID", columnAttribute.Name);
37 | Assert.True(columnAttribute.AllowInsert);
38 | Assert.True(columnAttribute.AllowUpdate);
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/Mapping/Attributes/IdentifierAttributeTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.Mapping.Attributes
2 | {
3 | using MicroLite.Mapping;
4 | using MicroLite.Mapping.Attributes;
5 | using Xunit;
6 |
7 | ///
8 | /// Unit Tests for the class.
9 | ///
10 | public class IdentifierAttributeTests
11 | {
12 | public class WhenConstructedWithIdentifierStrategy
13 | {
14 | private readonly IdentifierAttribute identifierAttribute;
15 | private readonly IdentifierStrategy identifierStrategy;
16 |
17 | public WhenConstructedWithIdentifierStrategy()
18 | {
19 | this.identifierStrategy = IdentifierStrategy.Assigned;
20 | this.identifierAttribute = new IdentifierAttribute(this.identifierStrategy);
21 | }
22 |
23 | [Fact]
24 | public void TheIdentifierStrategyIsSet()
25 | {
26 | Assert.Equal(this.identifierStrategy, this.identifierAttribute.IdentifierStrategy);
27 | }
28 |
29 | [Fact]
30 | public void TheSequenceNameIsNull()
31 | {
32 | Assert.Null(this.identifierAttribute.SequenceName);
33 | }
34 | }
35 |
36 | public class WhenConstructedWithIdentifierStrategyAndSequenceName
37 | {
38 | private readonly IdentifierAttribute identifierAttribute;
39 | private readonly IdentifierStrategy identifierStrategy;
40 | private readonly string sequenceName;
41 |
42 | public WhenConstructedWithIdentifierStrategyAndSequenceName()
43 | {
44 | this.identifierStrategy = IdentifierStrategy.Assigned;
45 | this.sequenceName = "CustomerIdSequence";
46 | this.identifierAttribute = new IdentifierAttribute(this.identifierStrategy, this.sequenceName);
47 | }
48 |
49 | [Fact]
50 | public void TheIdentifierStrategyIsSet()
51 | {
52 | Assert.Equal(this.identifierStrategy, this.identifierAttribute.IdentifierStrategy);
53 | }
54 |
55 | [Fact]
56 | public void TheSequenceNameIsSet()
57 | {
58 | Assert.Equal(this.sequenceName, this.identifierAttribute.SequenceName);
59 | }
60 | }
61 | }
62 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/Mapping/Attributes/TableAttributeTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.Mapping.Attributes
2 | {
3 | using MicroLite.Mapping.Attributes;
4 | using Xunit;
5 |
6 | ///
7 | /// Unit Tests for the class.
8 | ///
9 | public class TableAttributeTests
10 | {
11 | [Fact]
12 | public void ConstructorSetsName()
13 | {
14 | var name = "Customers";
15 |
16 | var tableAttribute = new TableAttribute(name);
17 |
18 | Assert.Equal(name, tableAttribute.Name);
19 | Assert.Null(tableAttribute.Schema);
20 | }
21 |
22 | [Fact]
23 | public void ConstructorSetsSchemaAndName()
24 | {
25 | var schema = "dbo";
26 | var name = "Customers";
27 |
28 | var tableAttribute = new TableAttribute(schema, name);
29 |
30 | Assert.Equal(name, tableAttribute.Name);
31 | Assert.Equal(schema, tableAttribute.Schema);
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/Mapping/ColumnInfoTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.Mapping
2 | {
3 | using System;
4 | using System.Data;
5 | using MicroLite.Mapping;
6 | using MicroLite.Tests.TestEntities;
7 | using Xunit;
8 |
9 | ///
10 | /// Unit Tests for the class.
11 | ///
12 | public class ColumnInfoTests
13 | {
14 | [Fact]
15 | public void ConstructorSetsPropertyValues()
16 | {
17 | var columnName = "Name";
18 | var propertyInfo = typeof(Customer).GetProperty("Name");
19 | var isIdentifier = true;
20 | var allowInsert = true;
21 | var allowUpdate = true;
22 | var sequenceName = "CustomerIdSequence";
23 | var dbType = DbType.String;
24 |
25 | var columnInfo = new ColumnInfo(columnName, dbType, propertyInfo, isIdentifier, allowInsert, allowUpdate, sequenceName);
26 |
27 | Assert.Equal(columnName, columnInfo.ColumnName);
28 | Assert.Equal(propertyInfo, columnInfo.PropertyInfo);
29 | Assert.Equal(isIdentifier, columnInfo.IsIdentifier);
30 | Assert.Equal(allowInsert, columnInfo.AllowInsert);
31 | Assert.Equal(allowUpdate, columnInfo.AllowUpdate);
32 | Assert.Equal(sequenceName, columnInfo.SequenceName);
33 | Assert.Equal(dbType, columnInfo.DbType);
34 | }
35 |
36 | [Fact]
37 | public void ConstructorThrowsArgumentNullExceptionForNullColumnName()
38 | {
39 | var exception = Assert.Throws(
40 | () => new ColumnInfo(null, DbType.String, typeof(Customer).GetProperty("Name"), false, true, true, "sequence"));
41 |
42 | Assert.Equal("columnName", exception.ParamName);
43 | }
44 |
45 | [Fact]
46 | public void ConstructorThrowsArgumentNullExceptionForNullPropertyInfo()
47 | {
48 | var exception = Assert.Throws(
49 | () => new ColumnInfo("Name", DbType.String, null, false, true, true, "sequence"));
50 |
51 | Assert.Equal("propertyInfo", exception.ParamName);
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/Mapping/Inflection/InflectionServiceTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.Mapping.Inflection
2 | {
3 | using MicroLite.Mapping.Inflection;
4 | using Xunit;
5 |
6 | ///
7 | /// Unit Tests for the class.
8 | ///
9 | public class InflectionServiceTests
10 | {
11 | [Fact]
12 | public void English_ReturnsSameInstanceEachTime()
13 | {
14 | var service1 = InflectionService.English;
15 | var service2 = InflectionService.English;
16 |
17 | Assert.Same(service1, service2);
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/ObjectDeltaTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests
2 | {
3 | using System;
4 | using System.Linq;
5 | using MicroLite.Tests.TestEntities;
6 | using Xunit;
7 |
8 | public class ObjectDeltaTests
9 | {
10 | public class WhenCallingAddChange
11 | {
12 | private readonly ObjectDelta objectDelta = new ObjectDelta(typeof(Customer), 1332);
13 |
14 | public WhenCallingAddChange()
15 | {
16 | this.objectDelta.AddChange("Name", "Fred");
17 | }
18 |
19 | [Fact]
20 | public void ChangeCountShouldReturnTheCorrectNumberOfChanges()
21 | {
22 | Assert.Equal(1, this.objectDelta.ChangeCount);
23 | }
24 |
25 | [Fact]
26 | public void ChangesShouldContainTheChange()
27 | {
28 | var change = this.objectDelta.Changes.Single();
29 | Assert.Equal("Name", change.Key);
30 | Assert.Equal("Fred", change.Value);
31 | }
32 | }
33 |
34 | public class WhenConstructed
35 | {
36 | private readonly ObjectDelta objectDelta;
37 |
38 | public WhenConstructed()
39 | {
40 | this.objectDelta = new ObjectDelta(typeof(Customer), 1332);
41 | }
42 |
43 | [Fact]
44 | public void ChangeCountShouldReturnZero()
45 | {
46 | Assert.Equal(0, this.objectDelta.ChangeCount);
47 | }
48 |
49 | [Fact]
50 | public void ChangesIsEmpty()
51 | {
52 | Assert.Empty(this.objectDelta.Changes);
53 | }
54 |
55 | [Fact]
56 | public void ForTypeIsSet()
57 | {
58 | Assert.Equal(typeof(Customer), this.objectDelta.ForType);
59 | }
60 |
61 | [Fact]
62 | public void IdentifierIsSet()
63 | {
64 | Assert.Equal(1332, this.objectDelta.Identifier);
65 | }
66 | }
67 |
68 | public class WhenConstructedWithNullIdentifier
69 | {
70 | [Fact]
71 | public void AnArgumentNullExceptionIsThrown()
72 | {
73 | var exception = Assert.Throws(() => new ObjectDelta(typeof(Customer), null));
74 |
75 | Assert.Equal("identifier", exception.ParamName);
76 | }
77 | }
78 |
79 | public class WhenConstructedWithNullType
80 | {
81 | [Fact]
82 | public void AnArgumentNullExceptionIsThrown()
83 | {
84 | var exception = Assert.Throws(() => new ObjectDelta(null, 1332));
85 |
86 | Assert.Equal("forType", exception.ParamName);
87 | }
88 | }
89 | }
90 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/ParameterNameComparerTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests
2 | {
3 | using Xunit;
4 |
5 | public class ParameterNameComparerTests
6 | {
7 | [Fact]
8 | public void Parameter101SortsAfterParameter12()
9 | {
10 | Assert.Equal(1, ParameterNameComparer.Instance.Compare("@p101", "@p12"));
11 | }
12 |
13 | [Fact]
14 | public void Parameter1SortsBeforeParameter10()
15 | {
16 | Assert.Equal(-1, ParameterNameComparer.Instance.Compare("@p1", "@p10"));
17 | }
18 |
19 | [Fact]
20 | public void Parameter1SortsEqualToParameter1()
21 | {
22 | Assert.Equal(0, ParameterNameComparer.Instance.Compare("@p1", "@p1"));
23 | }
24 |
25 | [Fact]
26 | public void Parameter9SortsBeforeParameter10()
27 | {
28 | Assert.Equal(-1, ParameterNameComparer.Instance.Compare("@p9", "@p10"));
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 | using Xunit;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("MicroLite.Tests")]
9 | [assembly: AssemblyDescription("Unit Tests for the MicroLite ORM Framework")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Project Contributors")]
12 | [assembly: AssemblyProduct("MicroLite.Tests")]
13 | [assembly: AssemblyCopyright("Copyright Project Contributors all rights reserved.")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("9d9a69e8-802e-4335-ac3a-791194fc91e9")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | [assembly: AssemblyVersion("1.0.0.0")]
35 | [assembly: AssemblyFileVersion("1.0.0.0")]
36 | [assembly: CollectionBehavior(DisableTestParallelization = true)]
--------------------------------------------------------------------------------
/MicroLite.Tests/TestEntities/CreditCard.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.TestEntities
2 | {
3 | using System;
4 |
5 | public class CreditCard
6 | {
7 | public DateTime ExpiryDate
8 | {
9 | get;
10 | set;
11 | }
12 |
13 | public string Number
14 | {
15 | get;
16 | set;
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/TestEntities/Customer.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.TestEntities
2 | {
3 | using System;
4 |
5 | ///
6 | /// An object which can be used when testing classes which need to use an ObjectInfo.
7 | ///
8 | public class Customer
9 | {
10 | public Customer()
11 | {
12 | }
13 |
14 | public DateTime Created
15 | {
16 | get;
17 | set;
18 | }
19 |
20 | public Decimal? CreditLimit
21 | {
22 | get;
23 | set;
24 | }
25 |
26 | public DateTime DateOfBirth
27 | {
28 | get;
29 | set;
30 | }
31 |
32 | public int Id
33 | {
34 | get;
35 | set;
36 | }
37 |
38 | public string Name
39 | {
40 | get;
41 | set;
42 | }
43 |
44 | public CustomerStatus Status
45 | {
46 | get;
47 | set;
48 | }
49 |
50 | public DateTime? Updated
51 | {
52 | get;
53 | set;
54 | }
55 |
56 | public Uri Website
57 | {
58 | get;
59 | set;
60 | }
61 | }
62 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/TestEntities/CustomerStatus.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.TestEntities
2 | {
3 | public enum CustomerStatus
4 | {
5 | Inactive = 0,
6 | Active = 1
7 | }
8 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/TestEntities/Invoice.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.TestEntities
2 | {
3 | ///
4 | /// An object which can be used when testing classes which need to use an ObjectInfo.
5 | ///
6 | public class Invoice
7 | {
8 | public int InvoiceId
9 | {
10 | get;
11 | set;
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/TestEntities/MockDbConnectionWrapper.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.TestEntities
2 | {
3 |
4 |
5 | using System;
6 | using System.Data;
7 | using System.Data.Common;
8 |
9 | internal sealed class MockDbConnectionWrapper : DbConnection
10 | {
11 | private readonly IDbConnection connection;
12 |
13 | internal MockDbConnectionWrapper(IDbConnection connection)
14 | {
15 | this.connection = connection;
16 | }
17 |
18 | public override string ConnectionString
19 | {
20 | get
21 | {
22 | return this.connection.ConnectionString;
23 | }
24 | set
25 | {
26 | this.connection.ConnectionString = value;
27 | }
28 | }
29 |
30 | public override string Database
31 | {
32 | get
33 | {
34 | throw new NotImplementedException();
35 | }
36 | }
37 |
38 | public override string DataSource
39 | {
40 | get
41 | {
42 | throw new NotImplementedException();
43 | }
44 | }
45 |
46 | public override string ServerVersion
47 | {
48 | get
49 | {
50 | throw new NotImplementedException();
51 | }
52 | }
53 |
54 | public override ConnectionState State
55 | {
56 | get
57 | {
58 | return this.connection.State;
59 | }
60 | }
61 |
62 | public override void ChangeDatabase(string databaseName)
63 | {
64 | throw new NotImplementedException();
65 | }
66 |
67 | public override void Close()
68 | {
69 | this.connection.Close();
70 | }
71 |
72 | public override void Open()
73 | {
74 | this.connection.Open();
75 | }
76 |
77 | protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
78 | {
79 | return new MockDbTransactionWrapper(this.connection.BeginTransaction(isolationLevel));
80 | }
81 |
82 | protected override DbCommand CreateDbCommand()
83 | {
84 | return new MockDbCommandWrapper(this.connection.CreateCommand());
85 | }
86 |
87 | protected override void Dispose(bool disposing)
88 | {
89 | this.connection.Dispose();
90 | base.Dispose(disposing);
91 | }
92 | }
93 |
94 |
95 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/TestEntities/MockDbTransactionWrapper.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.TestEntities
2 | {
3 |
4 |
5 | using System.Data;
6 | using System.Data.Common;
7 |
8 | internal sealed class MockDbTransactionWrapper : DbTransaction
9 | {
10 | private readonly IDbTransaction transaction;
11 |
12 | internal MockDbTransactionWrapper(IDbTransaction transaction)
13 | {
14 | this.transaction = transaction;
15 | }
16 |
17 | public override IsolationLevel IsolationLevel
18 | {
19 | get
20 | {
21 | return this.transaction.IsolationLevel;
22 | }
23 | }
24 |
25 | protected override DbConnection DbConnection
26 | {
27 | get
28 | {
29 | return new MockDbConnectionWrapper(this.transaction.Connection);
30 | }
31 | }
32 |
33 | public override void Commit()
34 | {
35 | this.transaction.Rollback();
36 | }
37 |
38 | public override void Rollback()
39 | {
40 | this.transaction.Rollback();
41 | }
42 |
43 | protected override void Dispose(bool disposing)
44 | {
45 | this.transaction.Dispose();
46 | base.Dispose(disposing);
47 | }
48 | }
49 |
50 |
51 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/TypeConverters/TypeConverterCollectionTests.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests.TypeConverters
2 | {
3 | using MicroLite.TypeConverters;
4 | using Xunit;
5 |
6 | ///
7 | /// Unit Tests for the class.
8 | ///
9 | public class TypeConverterCollectionTests
10 | {
11 | public class WhenCallingAdd
12 | {
13 | private readonly TypeConverterCollection collection = new TypeConverterCollection();
14 | private readonly TestTypeConverter typeConverter = new TestTypeConverter();
15 |
16 | public WhenCallingAdd()
17 | {
18 | this.collection.Add(this.typeConverter);
19 | }
20 |
21 | [Fact]
22 | public void TheTypeConverterShouldBeAddedAtTheTopOfTheList()
23 | {
24 | Assert.IsType(this.collection[0]);
25 | }
26 | }
27 |
28 | public class WhenCallingTheConstructor
29 | {
30 | private readonly TypeConverterCollection collection = new TypeConverterCollection();
31 |
32 | [Fact]
33 | public void TheEnumTypeConverterShouldBePositionZero()
34 | {
35 | Assert.IsType(this.collection[0]);
36 | }
37 |
38 | [Fact]
39 | public void ThereShouldBe4RegisteredTypeConverters()
40 | {
41 | Assert.Equal(4, this.collection.Count);
42 | }
43 |
44 | [Fact]
45 | public void TheTimeSpanTypeConverterShouldBePositionThree()
46 | {
47 | Assert.IsType(this.collection[2]);
48 | }
49 |
50 | [Fact]
51 | public void TheUriTypeConverterShouldBePositionOne()
52 | {
53 | Assert.IsType(this.collection[1]);
54 | }
55 |
56 | [Fact]
57 | public void TheXDocumentTypeConverterShouldBePositionThree()
58 | {
59 | Assert.IsType(this.collection[3]);
60 | }
61 | }
62 |
63 | private class TestTypeConverter : ITypeConverter
64 | {
65 | public bool CanConvert(System.Type propertyType)
66 | {
67 | throw new System.NotImplementedException();
68 | }
69 |
70 | public object ConvertFromDbValue(object value, System.Type propertyType)
71 | {
72 | throw new System.NotImplementedException();
73 | }
74 |
75 | public object ConvertFromDbValue(System.Data.IDataReader reader, int index, System.Type type)
76 | {
77 | throw new System.NotImplementedException();
78 | }
79 |
80 | public object ConvertToDbValue(object value, System.Type propertyType)
81 | {
82 | throw new System.NotImplementedException();
83 | }
84 | }
85 | }
86 | }
--------------------------------------------------------------------------------
/MicroLite.Tests/UnitTest.cs:
--------------------------------------------------------------------------------
1 | namespace MicroLite.Tests
2 | {
3 | using System;
4 | using System.Reflection;
5 | using MicroLite.Characters;
6 | using MicroLite.Configuration;
7 | using MicroLite.Logging;
8 | using MicroLite.Mapping;
9 |
10 | public abstract class UnitTest : IDisposable
11 | {
12 | protected UnitTest()
13 | {
14 | this.ResetMicroLiteInternalState();
15 | }
16 |
17 | public static ConventionMappingSettings GetConventionMappingSettings(IdentifierStrategy identifierStrategy)
18 | {
19 | return new ConventionMappingSettings
20 | {
21 | AllowInsert = (PropertyInfo p) =>
22 | {
23 | return p.Name != "Updated";
24 | },
25 | AllowUpdate = (PropertyInfo p) =>
26 | {
27 | return p.Name != "Created";
28 | },
29 | ResolveIdentifierStrategy = (Type type) =>
30 | {
31 | return identifierStrategy;
32 | },
33 | ResolveSequenceName = (PropertyInfo propertyInfo) =>
34 | {
35 | return identifierStrategy == IdentifierStrategy.Sequence
36 | ? propertyInfo.DeclaringType.Name + "_" + propertyInfo.Name + "_Sequence"
37 | : null;
38 | },
39 | ResolveTableSchema = (Type type) =>
40 | {
41 | return "Sales";
42 | }
43 | };
44 | }
45 |
46 | public void Dispose()
47 | {
48 | this.ResetMicroLiteInternalState();
49 |
50 | this.OnDispose();
51 | }
52 |
53 | protected virtual void OnDispose()
54 | {
55 | }
56 |
57 | private void ResetMicroLiteInternalState()
58 | {
59 | Configure.OnSessionFactoryCreated = null;
60 | SqlCharacters.Current = null;
61 | LogManager.GetLogger = null;
62 | Configure.SessionFactories.Clear();
63 |
64 | // Reset the internal state of ObjectInfo for the next set of tests so that we can easily
65 | // Test different mapping conventions etc.
66 | // Use reflection to assasinate the currently chosen mapping convention and objectinfos.
67 | var objectInfoType = typeof(ObjectInfo);
68 |
69 | var mappingConventionField = objectInfoType.GetField("s_mappingConvention", BindingFlags.Static | BindingFlags.NonPublic);
70 | mappingConventionField.SetValue(null, null);
71 |
72 | var objectInfosField = objectInfoType.GetField("s_objectInfos", BindingFlags.Static | BindingFlags.NonPublic);
73 | var getObjectInfosMethod = objectInfoType.GetMethod("GetObjectInfos", BindingFlags.Static | BindingFlags.NonPublic);
74 |
75 | var objectInfos = getObjectInfosMethod.Invoke(null, null);
76 | objectInfosField.SetValue(null, objectInfos);
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/MicroLite.Tests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/MicroLite.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29613.14
5 | MinimumVisualStudioVersion = 15.0.26124.0
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MicroLite", "MicroLite\MicroLite.csproj", "{CACB27C2-FD24-4F90-8A95-069F6EA41269}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MicroLite.Tests", "MicroLite.Tests\MicroLite.Tests.csproj", "{A693D0A7-1347-4FAA-9CB4-67E6C1C084A2}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C7DC9506-EC84-4CB1-A7CB-AD4A114FF17D}"
11 | ProjectSection(SolutionItems) = preProject
12 | .editorconfig = .editorconfig
13 | EndProjectSection
14 | EndProject
15 | Global
16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
17 | Debug|Any CPU = Debug|Any CPU
18 | Release|Any CPU = Release|Any CPU
19 | EndGlobalSection
20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
21 | {CACB27C2-FD24-4F90-8A95-069F6EA41269}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22 | {CACB27C2-FD24-4F90-8A95-069F6EA41269}.Debug|Any CPU.Build.0 = Debug|Any CPU
23 | {CACB27C2-FD24-4F90-8A95-069F6EA41269}.Release|Any CPU.ActiveCfg = Release|Any CPU
24 | {CACB27C2-FD24-4F90-8A95-069F6EA41269}.Release|Any CPU.Build.0 = Release|Any CPU
25 | {A693D0A7-1347-4FAA-9CB4-67E6C1C084A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26 | {A693D0A7-1347-4FAA-9CB4-67E6C1C084A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
27 | {A693D0A7-1347-4FAA-9CB4-67E6C1C084A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
28 | {A693D0A7-1347-4FAA-9CB4-67E6C1C084A2}.Release|Any CPU.Build.0 = Release|Any CPU
29 | EndGlobalSection
30 | GlobalSection(SolutionProperties) = preSolution
31 | HideSolutionNode = FALSE
32 | EndGlobalSection
33 | GlobalSection(ExtensibilityGlobals) = postSolution
34 | SolutionGuid = {3DB70968-A008-41EB-AE22-9EF64A48D758}
35 | EndGlobalSection
36 | EndGlobal
37 |
--------------------------------------------------------------------------------
/MicroLite.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MicroLite-ORM/MicroLite/8b898886f3c113800ffd1628c3b01b2c34874aab/MicroLite.snk
--------------------------------------------------------------------------------
/MicroLite/Builder/DeleteSqlBuilder.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using MicroLite.Builder.Syntax.Write;
15 | using MicroLite.Characters;
16 | using MicroLite.FrameworkExtensions;
17 | using MicroLite.Mapping;
18 |
19 | namespace MicroLite.Builder
20 | {
21 | [System.Diagnostics.DebuggerDisplay("{InnerSql}")]
22 | internal sealed class DeleteSqlBuilder : WriteSqlBuilderBase, IDeleteFrom
23 | {
24 | ///
25 | /// Initialises a new instance of the class with the starting command text 'DELETE FROM '.
26 | ///
27 | /// The SQL characters.
28 | internal DeleteSqlBuilder(SqlCharacters sqlCharacters)
29 | : base(sqlCharacters)
30 | => InnerSql.Append("DELETE");
31 |
32 | public IWhere From(string table)
33 | {
34 | if (string.IsNullOrEmpty(table))
35 | {
36 | throw new ArgumentException(ExceptionMessages.ArgumentNullOrEmpty.FormatWith("table"));
37 | }
38 |
39 | InnerSql.Append(" FROM ");
40 | AppendTableName(table);
41 |
42 | return this;
43 | }
44 |
45 | public IWhere From(Type forType)
46 | => From(ObjectInfo.For(forType));
47 |
48 | internal IWhere From(IObjectInfo objectInfo)
49 | {
50 | InnerSql.Append(" FROM ");
51 | AppendTableName(objectInfo);
52 |
53 | return this;
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/MicroLite/Builder/StoredProcedureSqlBuilder.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using MicroLite.Builder.Syntax;
14 | using MicroLite.Characters;
15 |
16 | namespace MicroLite.Builder
17 | {
18 | [System.Diagnostics.DebuggerDisplay("{InnerSql}")]
19 | internal sealed class StoredProcedureSqlBuilder : SqlBuilderBase, IWithParameter
20 | {
21 | internal StoredProcedureSqlBuilder(SqlCharacters sqlCharacters, string procedureName)
22 | : base(sqlCharacters)
23 | => InnerSql.Append(sqlCharacters.StoredProcedureInvocationCommand).Append(' ').Append(procedureName).Append(' ');
24 |
25 | public IWithParameter WithParameter(string parameter, object arg)
26 | {
27 | if (Arguments.Count > 0)
28 | {
29 | InnerSql.Append(',');
30 | }
31 |
32 | Arguments.Add(new SqlArgument(arg));
33 |
34 | InnerSql.Append(parameter);
35 |
36 | return this;
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/MicroLite/Builder/Syntax/IToSqlQuery.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Builder.Syntax
14 | {
15 | ///
16 | /// The interface to end the fluent build syntax.
17 | ///
18 | ///
19 | /// It's a bit of a verbose hack, need to see if I can use cast operators instead somehow...
20 | ///
21 | public interface IToSqlQuery
22 | {
23 | ///
24 | /// Creates a from the values specified.
25 | ///
26 | /// The created .
27 | SqlQuery ToSqlQuery();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/MicroLite/Builder/Syntax/IWithParameter.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Builder.Syntax
14 | {
15 | ///
16 | /// The interface which specifies a parameter and argument for a stored procedure in the fluent sql builder syntax.
17 | ///
18 | public interface IWithParameter : IToSqlQuery
19 | {
20 | ///
21 | /// Specifies that the stored procedure should be executed the specified parameter and argument.
22 | ///
23 | /// The parameter to be added.
24 | /// The argument value for the parameter.
25 | /// The next step in the fluent sql builder.
26 | ///
27 | /// Add each parameter separately, specifying the parameter name and value.
28 | ///
29 | /// var sqlQuery = SqlBuilder
30 | /// .Execute("GetCustomerInvoices")
31 | /// .WithParameter("@CustomerId", 7633245)
32 | /// .WithParameter("@StartDate", DateTime.Today.AddMonths(-3))
33 | /// .WithParameter("@EndDate", DateTime.Today)
34 | /// .ToSqlQuery();
35 | ///
36 | ///
37 | IWithParameter WithParameter(string parameter, object arg);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/MicroLite/Builder/Syntax/Read/IGroupBy.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Builder.Syntax.Read
14 | {
15 | ///
16 | /// The interface which specifies the group by method in the fluent sql builder syntax.
17 | ///
18 | public interface IGroupBy
19 | {
20 | ///
21 | /// Groups the results of the query by the specified column.
22 | ///
23 | /// The column to group by.
24 | /// The next step in the fluent sql builder.
25 | /// Thrown if column is null or empty.
26 | ///
27 | ///
28 | /// var sqlQuery = SqlBuilder
29 | /// .Select("CustomerId")
30 | /// .Max("Total")
31 | /// .From(typeof(Invoice))
32 | /// .GroupBy("CustomerId")
33 | /// .ToSqlQuery();
34 | ///
35 | /// Will generate SELECT CustomerId, MAX(Total) AS Total FROM Invoices GROUP BY CustomerId.
36 | ///
37 | IHavingOrOrderBy GroupBy(string column);
38 |
39 | ///
40 | /// Groups the results of the query by the specified columns.
41 | ///
42 | /// The columns to group by.
43 | /// The next step in the fluent sql builder.
44 | /// Thrown if columns is null.
45 | ///
46 | ///
47 | /// var sqlQuery = SqlBuilder
48 | /// .Select("CustomerId, OrderDate")
49 | /// .Max("Total")
50 | /// .From(typeof(Invoice))
51 | /// .GroupBy("CustomerId, OrderDate")
52 | /// .ToSqlQuery();
53 | ///
54 | /// Will generate SELECT CustomerId, OrderDate, MAX(Total) AS Total FROM Invoices GROUP BY CustomerId, OrderDate.
55 | ///
56 | IHavingOrOrderBy GroupBy(params string[] columns);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/MicroLite/Builder/Syntax/Read/IHavingOrOrderBy.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Builder.Syntax.Read
14 | {
15 | ///
16 | /// The interface which specifies the having method in the fluent sql builder syntax.
17 | ///
18 | public interface IHavingOrOrderBy : IOrderBy
19 | {
20 | ///
21 | /// Specifies the having clause for the query.
22 | ///
23 | /// The predicate.
24 | /// The argument value.
25 | /// Thrown if predicate is null or empty.
26 | ///
27 | /// The next step in the fluent sql builder.
28 | ///
29 | ///
30 | ///
31 | /// var sqlQuery = SqlBuilder
32 | /// .Select("CustomerId")
33 | /// .Max("Total")
34 | /// .From(typeof(Invoice))
35 | /// .GroupBy("CustomerId")
36 | /// .Having("MAX(Total) > @p0", 10000M)
37 | /// .ToSqlQuery();
38 | ///
39 | /// Will generate SELECT CustomerId, MAX(Total) AS Total FROM Invoices GROUP BY CustomerId HAVING MAX(Total) > @p0.
40 | ///
41 | IOrderBy Having(string predicate, object value);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/MicroLite/Builder/Syntax/Read/ISelectFrom.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 |
15 | namespace MicroLite.Builder.Syntax.Read
16 | {
17 | ///
18 | /// The interface which specifies the from method in the fluent sql builder syntax.
19 | ///
20 | public interface ISelectFrom
21 | {
22 | ///
23 | /// Specifies the table to perform the query against.
24 | ///
25 | /// The name of the table.
26 | /// The next step in the fluent sql builder.
27 | /// Thrown if table is null or empty.
28 | ///
29 | ///
30 | /// var query = SqlBuilder.Select("Col1", "Col2").From("Customers")... // Add remainder of query
31 | ///
32 | ///
33 | IWhereOrOrderBy From(string table);
34 |
35 | ///
36 | /// Specifies the type to perform the query against.
37 | ///
38 | /// The type of object the query relates to.
39 | /// The next step in the fluent sql builder.
40 | ///
41 | /// If the select criteria is * then all mapped columns will be used in the select list instead, otherwise the specified columns will be used.
42 | ///
43 | /// var query = SqlBuilder.Select("Col1", "Col2").From(typeof(Customer))... // Add remainder of query
44 | ///
45 | ///
46 | /// Results in all columns being named if the select list is 'SELECT *'.
47 | IWhereOrOrderBy From(Type forType);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/MicroLite/Builder/Syntax/Write/IAndOr.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Builder.Syntax.Write
14 | {
15 | ///
16 | /// The interface which specifies the and/or methods to extend the where clause in the fluent sql builder syntax.
17 | ///
18 | public interface IAndOr : IToSqlQuery
19 | {
20 | ///
21 | /// Adds a column as an AND to the where clause of the query.
22 | ///
23 | /// The column name to use in the where clause.
24 | /// The next step in the fluent sql builder.
25 | /// Thrown if column is null or empty.
26 | IWhereSingleColumn AndWhere(string column);
27 |
28 | ///
29 | /// Adds a column as an OR to the where clause of the query.
30 | ///
31 | /// The column name to use in the where clause.
32 | /// The next step in the fluent sql builder.
33 | /// Thrown if column is null or empty.
34 | IWhereSingleColumn OrWhere(string column);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/MicroLite/Builder/Syntax/Write/IDeleteFrom.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 |
15 | namespace MicroLite.Builder.Syntax.Write
16 | {
17 | ///
18 | /// The interface which specifies the from method in the fluent sql builder syntax.
19 | ///
20 | public interface IDeleteFrom
21 | {
22 | ///
23 | /// Specifies the table to delete from.
24 | ///
25 | /// The name of the table.
26 | /// The next step in the fluent sql builder.
27 | IWhere From(string table);
28 |
29 | ///
30 | /// Specifies the type to delete.
31 | ///
32 | /// The type of object the query relates to.
33 | /// The next step in the fluent sql builder.
34 | IWhere From(Type forType);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/MicroLite/Builder/Syntax/Write/IInsertColumn.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Builder.Syntax.Write
14 | {
15 | ///
16 | /// The interface which specifies the column(s) method in the fluent insert sql builder syntax.
17 | ///
18 | public interface IInsertColumn : IInsertValue
19 | {
20 | ///
21 | /// Specifies the columns in the table to have values inserted into.
22 | ///
23 | /// Name of the columns to be inserted.
24 | /// The next step in the fluent sql builder.
25 | IInsertValue Columns(params string[] columnNames);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/MicroLite/Builder/Syntax/Write/IInsertIntoTable.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 |
15 | namespace MicroLite.Builder.Syntax.Write
16 | {
17 | ///
18 | /// The interface which specifies the into method in the fluent insert sql builder syntax.
19 | ///
20 | public interface IInsertIntoTable
21 | {
22 | ///
23 | /// Specifies the table to perform the query against.
24 | ///
25 | /// The name of the table.
26 | /// The next step in the fluent sql builder.
27 | IInsertColumn Into(string table);
28 |
29 | ///
30 | /// Specifies the type to perform the query against.
31 | ///
32 | /// The type of object the query relates to.
33 | /// The next step in the fluent sql builder.
34 | IInsertColumn Into(Type forType);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/MicroLite/Builder/Syntax/Write/IInsertValue.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Builder.Syntax.Write
14 | {
15 | ///
16 | /// The interface which specifies the value method in the fluent insert sql builder syntax.
17 | ///
18 | public interface IInsertValue : IToSqlQuery
19 | {
20 | ///
21 | /// Specifies the values to be inserted into the columns.
22 | ///
23 | /// Values for the columns to be inserted.
24 | /// The next step in the fluent sql builder.
25 | IToSqlQuery Values(params object[] columnValues);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/MicroLite/Builder/Syntax/Write/ISetOrWhere.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Builder.Syntax.Write
14 | {
15 | ///
16 | /// The interface which specifies the value method in the fluent update sql builder syntax.
17 | ///
18 | public interface ISetOrWhere : IWhere
19 | {
20 | ///
21 | /// Specifies the column in the table and the new value for it.
22 | ///
23 | /// Name of the column to be updated.
24 | /// The new value for the column.
25 | /// The next step in the fluent sql builder.
26 | ISetOrWhere SetColumnValue(string columnName, object columnValue);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/MicroLite/Builder/Syntax/Write/IUpdate.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 |
15 | namespace MicroLite.Builder.Syntax.Write
16 | {
17 | ///
18 | /// The interface which specifies the table method in the fluent update sql builder syntax.
19 | ///
20 | public interface IUpdate
21 | {
22 | ///
23 | /// Specifies the table to perform the query against.
24 | ///
25 | /// The name of the table.
26 | /// The next step in the fluent sql builder.
27 | ISetOrWhere Table(string tableName);
28 |
29 | ///
30 | /// Specifies the type to perform the query against.
31 | ///
32 | /// The type of object the query relates to.
33 | /// The next step in the fluent sql builder.
34 | ISetOrWhere Table(Type forType);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/MicroLite/Builder/Syntax/Write/IWhere.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Builder.Syntax.Write
14 | {
15 | ///
16 | /// The interface which specifies the where method in the fluent sql builder syntax.
17 | ///
18 | public interface IWhere : IToSqlQuery
19 | {
20 | ///
21 | /// Specifies the where clause for the query.
22 | ///
23 | /// The column name to use in the where clause.
24 | /// The next step in the fluent sql builder.
25 | /// Thrown if column is null or empty.
26 | IWhereSingleColumn Where(string column);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/MicroLite/Builder/UpdateSqlBuilder.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using MicroLite.Builder.Syntax.Write;
15 | using MicroLite.Characters;
16 | using MicroLite.FrameworkExtensions;
17 | using MicroLite.Mapping;
18 |
19 | namespace MicroLite.Builder
20 | {
21 | [System.Diagnostics.DebuggerDisplay("{InnerSql}")]
22 | internal sealed class UpdateSqlBuilder : WriteSqlBuilderBase, IUpdate, ISetOrWhere
23 | {
24 | ///
25 | /// Initialises a new instance of the class with the starting command text 'UPDATE '.
26 | ///
27 | /// The SQL characters.
28 | internal UpdateSqlBuilder(SqlCharacters sqlCharacters)
29 | : base(sqlCharacters)
30 | => InnerSql.Append("UPDATE ");
31 |
32 | public ISetOrWhere SetColumnValue(string columnName, object columnValue)
33 | {
34 | if (Arguments.Count > 0)
35 | {
36 | InnerSql.Append(',');
37 | }
38 |
39 | InnerSql.Append(SqlCharacters.EscapeSql(columnName))
40 | .Append(" = ")
41 | .Append(SqlCharacters.GetParameterName(Arguments.Count));
42 |
43 | Arguments.Add(new SqlArgument(columnValue));
44 |
45 | return this;
46 | }
47 |
48 | public ISetOrWhere Table(string tableName)
49 | {
50 | if (string.IsNullOrEmpty(tableName))
51 | {
52 | throw new ArgumentException(ExceptionMessages.ArgumentNullOrEmpty.FormatWith("tableName"));
53 | }
54 |
55 | AppendTableName(tableName);
56 | InnerSql.Append(" SET ");
57 |
58 | return this;
59 | }
60 |
61 | public ISetOrWhere Table(Type forType)
62 | => Table(ObjectInfo.For(forType));
63 |
64 | internal ISetOrWhere Table(IObjectInfo objectInfo)
65 | {
66 | AppendTableName(objectInfo);
67 | InnerSql.Append(" SET ");
68 |
69 | return this;
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/MicroLite/Builder/_SqlBuilders.cd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | AAQAAEAAAAAAAAQAAAAAAAAAAAEAAAAAAAAAQAAAAAA=
7 | Builder\SqlBuilder.cs
8 |
9 |
10 |
11 |
12 |
13 | AzgAABCgAJAACIAAFBBABEQEAAWAAAgIAADIGBEggOQ=
14 | Builder\SelectSqlBuilder.cs
15 |
16 |
17 |
18 |
19 |
20 |
21 | AAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
22 | Builder\StoredProcedureSqlBuilder.cs
23 |
24 |
25 |
26 |
27 |
28 |
29 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAEgAAAA=
30 | Builder\InsertSqlBuilder.cs
31 |
32 |
33 |
34 |
35 |
36 |
37 | AAAAAAIAAAAAAAAAAAAAQAAAAAAIAAAAAAAAAAAAAAA=
38 | Builder\UpdateSqlBuilder.cs
39 |
40 |
41 |
42 |
43 |
44 |
45 | AgAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAA=
46 | Builder\DeleteSqlBuilder.cs
47 |
48 |
49 |
50 |
51 |
52 |
53 | AEEAAAABAAAAAACAAAAAgAAAAAAgAAAAIAAAAAAAAAA=
54 | Builder\SqlBuilderBase.cs
55 |
56 |
57 |
58 |
59 |
60 |
61 | AAAAAAAAAAAAAAAEAAAAAAAAAAAoAQAAAAAAIAAAAAA=
62 | Builder\RawWhereBuilder.cs
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/MicroLite/Characters/FirebirdSqlCharacters.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Characters
14 | {
15 | ///
16 | /// The implementation of for Firebird.
17 | ///
18 | [System.Serializable]
19 | internal sealed class FirebirdSqlCharacters : SqlCharacters
20 | {
21 | ///
22 | /// Prevents a default instance of the class from being created.
23 | ///
24 | private FirebirdSqlCharacters()
25 | {
26 | }
27 |
28 | ///
29 | /// Gets the left delimiter character.
30 | ///
31 | public override string LeftDelimiter => "\"";
32 |
33 | ///
34 | /// Gets the right delimiter character.
35 | ///
36 | public override string RightDelimiter => "\"";
37 |
38 | ///
39 | /// Gets the SQL parameter.
40 | ///
41 | public override string SqlParameter => "@";
42 |
43 | ///
44 | /// Gets a value indicating whether SQL parameters are named.
45 | ///
46 | public override bool SupportsNamedParameters => true;
47 |
48 | ///
49 | /// Gets the single instance of for Firebird.
50 | ///
51 | internal static SqlCharacters Instance { get; } = new FirebirdSqlCharacters();
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/MicroLite/Characters/MsSqlCharacters.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Characters
14 | {
15 | ///
16 | /// The implementation of for MsSql server.
17 | ///
18 | [System.Serializable]
19 | internal sealed class MsSqlCharacters : SqlCharacters
20 | {
21 | ///
22 | /// Prevents a default instance of the class from being created.
23 | ///
24 | private MsSqlCharacters()
25 | {
26 | }
27 |
28 | ///
29 | /// Gets the left delimiter character.
30 | ///
31 | public override string LeftDelimiter => "[";
32 |
33 | ///
34 | /// Gets the right delimiter character.
35 | ///
36 | public override string RightDelimiter => "]";
37 |
38 | ///
39 | /// Gets the SQL parameter.
40 | ///
41 | public override string SqlParameter => "@";
42 |
43 | ///
44 | /// Gets the stored procedure invocation command.
45 | ///
46 | public override string StoredProcedureInvocationCommand => "EXEC";
47 |
48 | ///
49 | /// Gets a value indicating whether SQL parameters are named.
50 | ///
51 | public override bool SupportsNamedParameters => true;
52 |
53 | ///
54 | /// Gets the single instance of for MsSql.
55 | ///
56 | internal static SqlCharacters Instance { get; } = new MsSqlCharacters();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/MicroLite/Characters/MySqlCharacters.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Characters
14 | {
15 | ///
16 | /// The implementation of for MySql.
17 | ///
18 | [System.Serializable]
19 | internal sealed class MySqlCharacters : SqlCharacters
20 | {
21 | ///
22 | /// Prevents a default instance of the class from being created.
23 | ///
24 | private MySqlCharacters()
25 | {
26 | }
27 |
28 | ///
29 | /// Gets the left delimiter character.
30 | ///
31 | public override string LeftDelimiter => "`";
32 |
33 | ///
34 | /// Gets the right delimiter character.
35 | ///
36 | public override string RightDelimiter => "`";
37 |
38 | ///
39 | /// Gets the SQL parameter.
40 | ///
41 | public override string SqlParameter => "@";
42 |
43 | ///
44 | /// Gets the stored procedure invocation command.
45 | ///
46 | public override string StoredProcedureInvocationCommand => "CALL";
47 |
48 | ///
49 | /// Gets a value indicating whether SQL parameters are named.
50 | ///
51 | public override bool SupportsNamedParameters => true;
52 |
53 | ///
54 | /// Gets the single instance of for MySql.
55 | ///
56 | internal static SqlCharacters Instance { get; } = new MySqlCharacters();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/MicroLite/Characters/PostgreSqlCharacters.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Characters
14 | {
15 | ///
16 | /// The implementation of for PostgreSql.
17 | ///
18 | [System.Serializable]
19 | internal sealed class PostgreSqlCharacters : SqlCharacters
20 | {
21 | ///
22 | /// Prevents a default instance of the class from being created.
23 | ///
24 | private PostgreSqlCharacters()
25 | {
26 | }
27 |
28 | ///
29 | /// Gets the left delimiter character.
30 | ///
31 | public override string LeftDelimiter => "\"";
32 |
33 | ///
34 | /// Gets the right delimiter character.
35 | ///
36 | public override string RightDelimiter => "\"";
37 |
38 | ///
39 | /// Gets the SQL parameter.
40 | ///
41 | public override string SqlParameter => "@";
42 |
43 | ///
44 | /// Gets the stored procedure invocation command.
45 | ///
46 | public override string StoredProcedureInvocationCommand => "SELECT";
47 |
48 | ///
49 | /// Gets a value indicating whether SQL parameters are named.
50 | ///
51 | public override bool SupportsNamedParameters => true;
52 |
53 | ///
54 | /// Gets the single instance of for PostgreSql.
55 | ///
56 | internal static SqlCharacters Instance { get; } = new PostgreSqlCharacters();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/MicroLite/Characters/SQLiteCharacters.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Characters
14 | {
15 | ///
16 | /// The implementation of for SQLite.
17 | ///
18 | [System.Serializable]
19 | internal sealed class SQLiteCharacters : SqlCharacters
20 | {
21 | ///
22 | /// Prevents a default instance of the class from being created.
23 | ///
24 | private SQLiteCharacters()
25 | {
26 | }
27 |
28 | ///
29 | /// Gets the left delimiter character.
30 | ///
31 | public override string LeftDelimiter => "\"";
32 |
33 | ///
34 | /// Gets the right delimiter character.
35 | ///
36 | public override string RightDelimiter => "\"";
37 |
38 | ///
39 | /// Gets the SQL parameter.
40 | ///
41 | public override string SqlParameter => "@";
42 |
43 | ///
44 | /// Gets a value indicating whether SQL parameters are named.
45 | ///
46 | public override bool SupportsNamedParameters => true;
47 |
48 | ///
49 | /// Gets the single instance of for SQLite.
50 | ///
51 | internal static SqlCharacters Instance { get; } = new SQLiteCharacters();
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/MicroLite/Characters/_SqlCharacters.cd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | AAAAAAgAAACAAAAAAAAAAAAAAAgAAAAAQAAAAAAAABA=
7 | Characters\FirebirdSqlCharacters.cs
8 |
9 |
10 |
11 |
12 |
13 | AAAAAAgAAAGAAAAAAAAAAAAAAAgAAAAAQAAAAAAAABA=
14 | Characters\MsSqlCharacters.cs
15 |
16 |
17 |
18 |
19 |
20 | AAAAAAgAAAGAAAAAAAAAAAAAAAgAAAAAQAAAAAAAABA=
21 | Characters\MySqlCharacters.cs
22 |
23 |
24 |
25 |
26 |
27 | AAAAAAgAAAGAAAAAAAAAAAAAAAgAAAAAQAAAAAAAABA=
28 | Characters\PostgreSqlCharacters.cs
29 |
30 |
31 |
32 |
33 |
34 | AAAAAAgAAAGAACABAAKAQAACCAgAAAAAIgAAAgAYABA=
35 | Characters\SqlCharacters.cs
36 |
37 |
38 |
39 |
40 |
41 | AAAAAAgAAACAAAAAAAAAAAAAAAgAAAAAQAAAAAAAABA=
42 | Characters\SQLiteCharacters.cs
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/MicroLite/Clauses.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 |
15 | namespace MicroLite
16 | {
17 | ///
18 | /// An enumeration which represents the various clauses in a SQL Command.
19 | ///
20 | [Flags]
21 | public enum Clauses
22 | {
23 | ///
24 | /// The select clause.
25 | ///
26 | Select = 1,
27 |
28 | ///
29 | /// The from clause.
30 | ///
31 | From = 2,
32 |
33 | ///
34 | /// The where clause.
35 | ///
36 | Where = 4,
37 |
38 | ///
39 | /// The order by clause.
40 | ///
41 | OrderBy = 16,
42 |
43 | ///
44 | /// The group by clause.
45 | ///
46 | GroupBy = 8,
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/MicroLite/Collections/StackCollection{T}.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System.Collections.ObjectModel;
14 |
15 | namespace MicroLite.Collections
16 | {
17 | ///
18 | /// A which imitates a stack whilst keeping the usual Add method.
19 | ///
20 | /// The type contained in the collection.
21 | internal sealed class StackCollection : Collection
22 | {
23 | ///
24 | /// Initialises a new instance of the class.
25 | ///
26 | public StackCollection()
27 | {
28 | }
29 |
30 | ///
31 | /// Inserts an element into the Collection at the specified index.
32 | ///
33 | /// The zero-based index at which should be inserted.
34 | /// The object to insert. The value can be null for reference types.
35 | /// In order to maintain the behaviour of a stack, keep inserting at position 0 which will shift the items down.
36 | protected override void InsertItem(int index, T item)
37 | => Items.Insert(0, item);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/MicroLite/Configuration/ConfigurationException.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using System.Runtime.Serialization;
15 |
16 | namespace MicroLite.Configuration
17 | {
18 | ///
19 | /// A which is thrown for configuration exceptions.
20 | ///
21 | [Serializable]
22 | public class ConfigurationException : MicroLiteException
23 | {
24 | ///
25 | /// Initialises a new instance of the class.
26 | ///
27 | public ConfigurationException()
28 | {
29 | }
30 |
31 | ///
32 | /// Initialises a new instance of the class.
33 | ///
34 | /// The message.
35 | public ConfigurationException(string message)
36 | : base(message)
37 | {
38 | }
39 |
40 | ///
41 | /// Initialises a new instance of the class.
42 | ///
43 | /// The message.
44 | /// The inner exception.
45 | public ConfigurationException(string message, Exception innerException)
46 | : base(message, innerException)
47 | {
48 | }
49 |
50 | ///
51 | /// Initialises a new instance of the class.
52 | ///
53 | /// The that holds the serialized object data about the exception being thrown.
54 | /// The that contains contextual information about the source or destination.
55 | /// The parameter is null.
56 | /// The class name is null or HResult is zero (0).
57 | protected ConfigurationException(SerializationInfo info, StreamingContext context)
58 | : base(info, context)
59 | {
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/MicroLite/Configuration/ConfigureExtensions.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using MicroLite.Logging;
15 | using MicroLite.Mapping;
16 |
17 | namespace MicroLite.Configuration
18 | {
19 | ///
20 | /// The class used to configure extensions to the MicroLite ORM framework.
21 | ///
22 | internal sealed class ConfigureExtensions : IConfigureExtensions
23 | {
24 | private ILog _log = LogManager.GetCurrentClassLog();
25 |
26 | public void SetLogResolver(Func logResolver)
27 | {
28 | LogManager.GetLogger = logResolver;
29 |
30 | _log = LogManager.GetCurrentClassLog();
31 | }
32 |
33 | public void SetMappingConvention(IMappingConvention mappingConvention)
34 | {
35 | if (mappingConvention is null)
36 | {
37 | throw new ArgumentNullException(nameof(mappingConvention));
38 | }
39 |
40 | if (_log.IsInfo)
41 | {
42 | _log.Info(LogMessages.ConfigureExtensions_UsingMappingConvention, mappingConvention.GetType().FullName);
43 | }
44 |
45 | ObjectInfo.MappingConvention = mappingConvention;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/MicroLite/Configuration/IConfigureExtensions.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using MicroLite.Logging;
15 | using MicroLite.Mapping;
16 |
17 | namespace MicroLite.Configuration
18 | {
19 | ///
20 | /// The interface which specifies the options for configuring extensions to the MicroLite ORM framework.
21 | ///
22 | public interface IConfigureExtensions
23 | {
24 | ///
25 | /// Sets the function which can be called by MicroLite to resolve the to use.
26 | ///
27 | /// The function to resolve an ILog.
28 | void SetLogResolver(Func logResolver);
29 |
30 | ///
31 | /// Specifies the mapping convention which should be used by MicroLite ORM to map classes to tables.
32 | ///
33 | /// The mapping convention to use.
34 | /// Thrown if mappingConvention is null.
35 | void SetMappingConvention(IMappingConvention mappingConvention);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/MicroLite/Configuration/ICreateSessionFactory.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Configuration
14 | {
15 | ///
16 | /// The interface which specifies the creation of the in the fluent configuration
17 | /// of the MicroLite ORM framework.
18 | ///
19 | public interface ICreateSessionFactory
20 | {
21 | ///
22 | /// Creates the session factory for the configured connection.
23 | ///
24 | /// The session factory for the specified connection.
25 | ///
26 | /// If set, Configure.OnSessionFactoryCreated will be called after the session factory is created.
27 | /// The session factory will also be added to the SessionFactories collection.
28 | ///
29 | ISessionFactory CreateSessionFactory();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/MicroLite/Configuration/_Configuration.cd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | CAAAAAAAAAAAAAABAAAAAAAAAAABAAAAAAgAAAgAAAA=
7 | Configuration\Configure.cs
8 |
9 |
10 |
11 |
12 |
13 | AAAAAAAAAABAAAAAAAAACAAAAABAAAAAAAAAAAAAAAA=
14 | Configuration\ConfigureExtensions.cs
15 |
16 |
17 |
18 |
19 |
20 |
21 | AAACAAgAAAAAIAAAAAAAiCAQAAAAAAAEAAAAAAAAAAA=
22 | Configuration\FluentConfiguration.cs
23 |
24 |
25 |
26 |
27 |
28 |
29 | AABAAAAAAAAAAAAAAAQQAAMgAACAAEAAAAAACAAAAAA=
30 | Configuration\ConfigurationExtensions.cs
31 |
32 |
33 |
34 |
35 |
36 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
37 | Configuration\ConfigurationException.cs
38 |
39 |
40 |
41 |
42 |
43 | AAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAA=
44 | Configuration\ICreateSessionFactory.cs
45 |
46 |
47 |
48 |
49 |
50 | AAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAA=
51 | Configuration\IConfigureConnection.cs
52 |
53 |
54 |
55 |
56 |
57 | AAAAAAAAAABAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAA=
58 | Configuration\IConfigureExtensions.cs
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/MicroLite/ConnectionScope.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite
14 | {
15 | ///
16 | /// An enumeration which defines when a connection used by MicroLite is opened and closed.
17 | ///
18 | public enum ConnectionScope
19 | {
20 | ///
21 | /// The connection should be opened when a transaction is started and closed when the transaction is completed (default).
22 | ///
23 | /// This is the default behaviour in 5.0 and the only available behaviour prior to 5.0.
24 | PerTransaction = 0,
25 |
26 | ///
27 | /// The connection should be opened when a session is created and and closed when the session is disposed.
28 | ///
29 | ///
30 | /// Use this option with caution, it exists mostly for use where opening a connection is expensive
31 | /// and multiple transactions are to be used within a single session,
32 | /// or for SQLite in memory databases which only persist data whilst a connection exists.
33 | ///
34 | PerSession = 1,
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/MicroLite/Core/ISessionBase.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System.Data;
14 |
15 | namespace MicroLite.Core
16 | {
17 | ///
18 | /// An abstraction for the session base which de-couples the dependency for the Transaction class.
19 | ///
20 | internal interface ISessionBase
21 | {
22 | ///
23 | /// Gets the connection.
24 | ///
25 | IDbConnection Connection { get; }
26 |
27 | ///
28 | /// Informs the session that the Transaction has been completed.
29 | ///
30 | void TransactionCompleted();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/MicroLite/Core/Include.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System.Data.Common;
14 | using System.Threading;
15 | using System.Threading.Tasks;
16 |
17 | namespace MicroLite.Core
18 | {
19 | ///
20 | /// The base class for include implementations.
21 | ///
22 | [System.Diagnostics.DebuggerDisplay("HasValue: {HasValue}, Value: {Value}")]
23 | internal abstract class Include
24 | {
25 | ///
26 | /// Gets or sets a value indicating whether this include has a value.
27 | ///
28 | public bool HasValue { get; protected set; }
29 |
30 | ///
31 | /// Builds the included value from the results in the data reader.
32 | ///
33 | /// The containing the results.
34 | /// The token to monitor for cancellation requests.
35 | /// A task representing the asynchronous operation.
36 | internal abstract Task BuildValueAsync(DbDataReader reader, CancellationToken cancellationToken);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/MicroLite/Core/IncludeMany.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using System.Collections.Generic;
15 | using System.Data.Common;
16 | using System.Threading;
17 | using System.Threading.Tasks;
18 | using MicroLite.Mapping;
19 | using MicroLite.TypeConverters;
20 |
21 | namespace MicroLite.Core
22 | {
23 | ///
24 | /// The default implementation of .
25 | ///
26 | /// The type of object to be included.
27 | [System.Diagnostics.DebuggerDisplay("HasValue: {HasValue}, Values: {Values}")]
28 | internal sealed class IncludeMany : Include, IIncludeMany
29 | {
30 | private static readonly Type s_resultType = typeof(T);
31 | private Action> _callback;
32 |
33 | public IList Values { get; } = new List();
34 |
35 | public void OnLoad(Action> action) => _callback = action;
36 |
37 | internal override async Task BuildValueAsync(DbDataReader reader, CancellationToken cancellationToken)
38 | {
39 | if (TypeConverter.IsNotEntityAndConvertible(s_resultType))
40 | {
41 | ITypeConverter typeConverter = TypeConverter.For(s_resultType) ?? TypeConverter.Default;
42 |
43 | while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
44 | {
45 | var value = (T)typeConverter.ConvertFromDbValue(reader, 0, s_resultType);
46 |
47 | Values.Add(value);
48 | }
49 | }
50 | else
51 | {
52 | IObjectInfo objectInfo = ObjectInfo.For(s_resultType);
53 |
54 | while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
55 | {
56 | var instance = (T)objectInfo.CreateInstance(reader);
57 |
58 | Values.Add(instance);
59 | }
60 | }
61 |
62 | HasValue = Values.Count > 0;
63 |
64 | _callback?.Invoke(this);
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/MicroLite/Core/IncludeScalar.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using System.Data.Common;
15 | using System.Threading;
16 | using System.Threading.Tasks;
17 | using MicroLite.TypeConverters;
18 |
19 | namespace MicroLite.Core
20 | {
21 | ///
22 | /// The default implementation of for scalar results.
23 | ///
24 | /// The type of object to be included.
25 | [System.Diagnostics.DebuggerDisplay("HasValue: {HasValue}, Value: {Value}")]
26 | internal sealed class IncludeScalar : Include, IInclude
27 | {
28 | private static readonly Type s_resultType = typeof(T);
29 | private Action> _callback;
30 |
31 | public T Value { get; private set; }
32 |
33 | public void OnLoad(Action> action) => _callback = action;
34 |
35 | internal override async Task BuildValueAsync(DbDataReader reader, CancellationToken cancellationToken)
36 | {
37 | if (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
38 | {
39 | if (reader.FieldCount != 1)
40 | {
41 | throw new MicroLiteException(ExceptionMessages.IncludeScalar_MultipleColumns);
42 | }
43 |
44 | ITypeConverter typeConverter = TypeConverter.For(s_resultType) ?? TypeConverter.Default;
45 |
46 | Value = (T)typeConverter.ConvertFromDbValue(reader, 0, s_resultType);
47 | HasValue = true;
48 |
49 | if (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
50 | {
51 | throw new MicroLiteException(ExceptionMessages.Include_SingleRecordExpected);
52 | }
53 |
54 | _callback?.Invoke(this);
55 | }
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/MicroLite/Core/IncludeSingle.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using System.Data.Common;
15 | using System.Threading;
16 | using System.Threading.Tasks;
17 | using MicroLite.Mapping;
18 | using MicroLite.TypeConverters;
19 |
20 | namespace MicroLite.Core
21 | {
22 | ///
23 | /// The default implementation of for mapped objects.
24 | ///
25 | /// The type of object to be included.
26 | [System.Diagnostics.DebuggerDisplay("HasValue: {HasValue}, Value: {Value}")]
27 | internal sealed class IncludeSingle : Include, IInclude
28 | {
29 | private static readonly Type s_resultType = typeof(T);
30 | private Action> _callback;
31 |
32 | public T Value { get; private set; }
33 |
34 | public void OnLoad(Action> action) => _callback = action;
35 |
36 | internal override async Task BuildValueAsync(DbDataReader reader, CancellationToken cancellationToken)
37 | {
38 | if (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
39 | {
40 | if (TypeConverter.IsNotEntityAndConvertible(s_resultType))
41 | {
42 | ITypeConverter typeConverter = TypeConverter.For(s_resultType) ?? TypeConverter.Default;
43 |
44 | Value = (T)typeConverter.ConvertFromDbValue(reader, 0, s_resultType);
45 | }
46 | else
47 | {
48 | IObjectInfo objectInfo = ObjectInfo.For(s_resultType);
49 |
50 | Value = (T)objectInfo.CreateInstance(reader);
51 | }
52 |
53 | HasValue = true;
54 |
55 | if (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
56 | {
57 | throw new MicroLiteException(ExceptionMessages.Include_SingleRecordExpected);
58 | }
59 |
60 | _callback?.Invoke(this);
61 | }
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/MicroLite/Core/SessionFactory.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using MicroLite.Characters;
14 | using MicroLite.Dialect;
15 | using MicroLite.Driver;
16 | using MicroLite.Listeners;
17 | using MicroLite.Logging;
18 |
19 | namespace MicroLite.Core
20 | {
21 | ///
22 | /// The default implementation of .
23 | ///
24 | [System.Diagnostics.DebuggerDisplay("SessionFactory for {ConnectionName}")]
25 | internal sealed class SessionFactory : ISessionFactory
26 | {
27 | private static readonly ILog s_log = LogManager.GetCurrentClassLog();
28 | private readonly SessionListeners _sessionListeners;
29 | private readonly ISqlDialect _sqlDialect;
30 |
31 | internal SessionFactory(string connectionName, IDbDriver dbDriver, ISqlDialect sqlDialect)
32 | {
33 | ConnectionName = connectionName;
34 | DbDriver = dbDriver;
35 | _sqlDialect = sqlDialect;
36 |
37 | _sessionListeners = new SessionListeners(Listener.DeleteListeners, Listener.InsertListener, Listener.UpdateListeners);
38 | }
39 |
40 | public string ConnectionName { get; }
41 |
42 | public IDbDriver DbDriver { get; }
43 |
44 | public IReadOnlySession OpenReadOnlySession() => OpenReadOnlySession(ConnectionScope.PerTransaction);
45 |
46 | public IReadOnlySession OpenReadOnlySession(ConnectionScope connectionScope)
47 | {
48 | if (s_log.IsDebug)
49 | {
50 | s_log.Debug(LogMessages.SessionFactory_CreatingAsyncReadOnlySession, ConnectionName);
51 | }
52 |
53 | SqlCharacters.Current = _sqlDialect.SqlCharacters;
54 |
55 | return new ReadOnlySession(connectionScope, _sqlDialect, DbDriver);
56 | }
57 |
58 | public ISession OpenSession() => OpenSession(ConnectionScope.PerTransaction);
59 |
60 | public ISession OpenSession(ConnectionScope connectionScope)
61 | {
62 | if (s_log.IsDebug)
63 | {
64 | s_log.Debug(LogMessages.SessionFactory_CreatingAsyncSession, ConnectionName);
65 | }
66 |
67 | SqlCharacters.Current = _sqlDialect.SqlCharacters;
68 |
69 | return new Session(connectionScope, _sqlDialect, DbDriver, _sessionListeners);
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/MicroLite/Core/_Includes.cd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | AAAAAAAAAAAAAAAAAAAAAgAABAAAAAAAAACAAAAAAAA=
7 | Core\Include.cs
8 |
9 |
10 |
11 |
12 |
13 | AABAAAAAAAAAAAAAAAAAAgACAAAAAAAAAACgAAAAABA=
14 | Core\IncludeSingle.cs
15 |
16 |
17 |
18 |
19 |
20 |
21 | AABAAAAAAAAAAAAAAAAAAgACAAAAACAAAACgAAAAABA=
22 | Core\IncludeMany.cs
23 |
24 |
25 |
26 |
27 |
28 |
29 | AABAAAAAAAAAAAAAAAAAAgACAAAAAAAAAACgAAAAABA=
30 | Core\IncludeScalar.cs
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/MicroLite/Core/_Session.cd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | AAQQAECAAAAAAAQAAAAAAEAAAIEAAAABAAAAAAACAAA=
7 | Core\Session.cs
8 |
9 |
10 |
11 |
12 |
13 |
14 | AAAAQAAAACBCAQAAAAkACAiABQAAAAAAAAAAAAACAEE=
15 | Core\ReadOnlySession.cs
16 |
17 |
18 |
19 |
20 |
21 |
22 | AAAAQAAAAAAAEAAAAAAAiAAAAAAAAAAAAQAQwAEAAEA=
23 | Core\SessionFactory.cs
24 |
25 |
26 |
27 |
28 |
29 |
30 | AAIAAAABACAAgQEAAAQEAAAAAAgAAAAAAAAAwACAAAA=
31 | Core\SessionBase.cs
32 |
33 |
34 |
35 |
36 |
37 |
38 | AAIAAUAAAmAIgAACEAAACAAAAAAAEACAAAIAAAAAgAA=
39 | Core\Transaction.cs
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | IAAAQAIAACBgAQAAAAAACAgQBCAAAAAAAAAAAABCAEE=
55 | Core\AsyncReadOnlySession.cs
56 |
57 |
58 |
59 |
60 |
61 |
62 | AAAAAAAACAgAIAAQAAAAAAAAAIAAAAgAAAAAAAACCMA=
63 | Core\AsyncSession.cs
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/MicroLite/Dialect/MySqlDialect.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using System.Data;
15 | using System.Text;
16 | using MicroLite.Characters;
17 | using MicroLite.Mapping;
18 |
19 | namespace MicroLite.Dialect
20 | {
21 | ///
22 | /// The implementation of for MySql server.
23 | ///
24 | internal sealed class MySqlDialect : SqlDialect
25 | {
26 | ///
27 | /// Initialises a new instance of the class.
28 | ///
29 | internal MySqlDialect()
30 | : base(MySqlCharacters.Instance)
31 | {
32 | }
33 |
34 | public override bool SupportsSelectInsertedIdentifier => true;
35 |
36 | public override SqlQuery BuildSelectInsertIdSqlQuery(IObjectInfo objectInfo) => new SqlQuery("SELECT LAST_INSERT_ID()");
37 |
38 | public override SqlQuery PageQuery(SqlQuery sqlQuery, PagingOptions pagingOptions)
39 | {
40 | if (sqlQuery is null)
41 | {
42 | throw new ArgumentNullException(nameof(sqlQuery));
43 | }
44 |
45 | var arguments = new SqlArgument[sqlQuery.Arguments.Count + 2];
46 | Array.Copy(sqlQuery.ArgumentsArray, 0, arguments, 0, sqlQuery.Arguments.Count);
47 | arguments[arguments.Length - 2] = new SqlArgument(pagingOptions.Offset, DbType.Int32);
48 | arguments[arguments.Length - 1] = new SqlArgument(pagingOptions.Count, DbType.Int32);
49 |
50 | StringBuilder stringBuilder = new StringBuilder(sqlQuery.CommandText)
51 | .Replace(Environment.NewLine, string.Empty)
52 | .Append(" LIMIT ")
53 | .Append(SqlCharacters.GetParameterName(arguments.Length - 2))
54 | .Append(',')
55 | .Append(SqlCharacters.GetParameterName(arguments.Length - 1));
56 |
57 | return new SqlQuery(stringBuilder.ToString(), arguments);
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/MicroLite/Dialect/PostgreSqlDialect.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using System.Data;
15 | using System.Text;
16 | using MicroLite.Characters;
17 | using MicroLite.Mapping;
18 |
19 | namespace MicroLite.Dialect
20 | {
21 | ///
22 | /// The implementation of for Postgre server.
23 | ///
24 | internal sealed class PostgreSqlDialect : SqlDialect
25 | {
26 | ///
27 | /// Initialises a new instance of the class.
28 | ///
29 | internal PostgreSqlDialect()
30 | : base(PostgreSqlCharacters.Instance)
31 | {
32 | }
33 |
34 | public override bool SupportsSelectInsertedIdentifier => true;
35 |
36 | public override SqlQuery BuildSelectInsertIdSqlQuery(IObjectInfo objectInfo) => new SqlQuery("SELECT lastval()");
37 |
38 | public override SqlQuery PageQuery(SqlQuery sqlQuery, PagingOptions pagingOptions)
39 | {
40 | if (sqlQuery is null)
41 | {
42 | throw new ArgumentNullException(nameof(sqlQuery));
43 | }
44 |
45 | var arguments = new SqlArgument[sqlQuery.Arguments.Count + 2];
46 | Array.Copy(sqlQuery.ArgumentsArray, 0, arguments, 0, sqlQuery.Arguments.Count);
47 | arguments[arguments.Length - 2] = new SqlArgument(pagingOptions.Count, DbType.Int32);
48 | arguments[arguments.Length - 1] = new SqlArgument(pagingOptions.Offset, DbType.Int32);
49 |
50 | StringBuilder stringBuilder = new StringBuilder(sqlQuery.CommandText)
51 | .Replace(Environment.NewLine, string.Empty)
52 | .Append(" LIMIT ")
53 | .Append(SqlCharacters.GetParameterName(arguments.Length - 2))
54 | .Append(" OFFSET ")
55 | .Append(SqlCharacters.GetParameterName(arguments.Length - 1));
56 |
57 | return new SqlQuery(stringBuilder.ToString(), arguments);
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/MicroLite/Dialect/SQLiteDialect.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using System.Data;
15 | using System.Text;
16 | using MicroLite.Characters;
17 | using MicroLite.Mapping;
18 |
19 | namespace MicroLite.Dialect
20 | {
21 | ///
22 | /// The implementation of for SQLite.
23 | ///
24 | internal sealed class SQLiteDialect : SqlDialect
25 | {
26 | ///
27 | /// Initialises a new instance of the class.
28 | ///
29 | internal SQLiteDialect()
30 | : base(SQLiteCharacters.Instance)
31 | {
32 | }
33 |
34 | public override bool SupportsSelectInsertedIdentifier => true;
35 |
36 | public override SqlQuery BuildSelectInsertIdSqlQuery(IObjectInfo objectInfo) => new SqlQuery("SELECT last_insert_rowid()");
37 |
38 | ///
39 | /// Creates an SqlQuery to page the records which would be returned by the specified SqlQuery based upon the paging options.
40 | ///
41 | /// The SQL query.
42 | /// The paging options.
43 | ///
44 | /// A to return the paged results of the specified query.
45 | ///
46 | public override SqlQuery PageQuery(SqlQuery sqlQuery, PagingOptions pagingOptions)
47 | {
48 | if (sqlQuery is null)
49 | {
50 | throw new ArgumentNullException(nameof(sqlQuery));
51 | }
52 |
53 | var arguments = new SqlArgument[sqlQuery.Arguments.Count + 2];
54 | Array.Copy(sqlQuery.ArgumentsArray, 0, arguments, 0, sqlQuery.Arguments.Count);
55 | arguments[arguments.Length - 2] = new SqlArgument(pagingOptions.Offset, DbType.Int32);
56 | arguments[arguments.Length - 1] = new SqlArgument(pagingOptions.Count, DbType.Int32);
57 |
58 | StringBuilder stringBuilder = new StringBuilder(sqlQuery.CommandText)
59 | .Replace(Environment.NewLine, string.Empty)
60 | .Append(" LIMIT ")
61 | .Append(SqlCharacters.GetParameterName(arguments.Length - 2))
62 | .Append(',')
63 | .Append(SqlCharacters.GetParameterName(arguments.Length - 1));
64 |
65 | return new SqlQuery(stringBuilder.ToString(), arguments);
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/MicroLite/Dialect/_SqlDialect.cd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | AAsAAQABAAAAAAAgIAAwSAQAAAEgABAAAQgQAAAAAAA=
7 | Dialect\SqlDialect.cs
8 |
9 |
10 |
11 |
12 |
13 |
14 | AAAAAQAAAAAAAAAgIAAAAAAAAAAAAAAAAAAAAAAAAAA=
15 | Dialect\MySqlDialect.cs
16 |
17 |
18 |
19 |
20 |
21 | AAAAAQAAAAAAAAAgIAAAAAAAAAAAAAAAAAAAAAAAAAA=
22 | Dialect\PostgreSqlDialect.cs
23 |
24 |
25 |
26 |
27 |
28 | AAAAAQAAAAAAAAAgIAAAAAAAAAAAAAAAAAAAAAAAAAA=
29 | Dialect\SQLiteDialect.cs
30 |
31 |
32 |
33 |
34 |
35 | AAAAAQAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAA=
36 | Dialect\FirebirdSqlDialect.cs
37 |
38 |
39 |
40 |
41 |
42 | AAAAAQAAAAAAAAAgIAAAAAAAAAAAAAAAAAAAAAAAAAA=
43 | Dialect\MsSql2005Dialect.cs
44 |
45 |
46 |
47 |
48 |
49 | AAAAAQAAAAAAAAAgAAAAQAAAAAAAAAABAAAAAAAAAAA=
50 | Dialect\MsSql2012Dialect.cs
51 |
52 |
53 |
54 |
55 |
56 | AAoAAQABAAAAAAAgIAAwAAQAAAAAAAAAAAAAAAAAAAA=
57 | Dialect\ISqlDialect.cs
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/MicroLite/Driver/FirebirdDbDriver.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using MicroLite.Characters;
14 |
15 | namespace MicroLite.Driver
16 | {
17 | ///
18 | /// The implementation of for Firebird.
19 | ///
20 | internal sealed class FirebirdDbDriver : DbDriver
21 | {
22 | ///
23 | /// Initialises a new instance of the class.
24 | ///
25 | internal FirebirdDbDriver()
26 | : base(FirebirdSqlCharacters.Instance)
27 | {
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/MicroLite/Driver/MsSqlDbDriver.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using System.Data;
15 | using MicroLite.Characters;
16 |
17 | namespace MicroLite.Driver
18 | {
19 | ///
20 | /// The implementation of for MsSql server.
21 | ///
22 | internal sealed class MsSqlDbDriver : DbDriver
23 | {
24 | ///
25 | /// Initialises a new instance of the class.
26 | ///
27 | internal MsSqlDbDriver()
28 | : base(MsSqlCharacters.Instance)
29 | {
30 | }
31 |
32 | public override bool SupportsBatchedQueries => true;
33 |
34 | protected override void BuildParameter(IDbDataParameter parameter, string parameterName, SqlArgument sqlArgument)
35 | {
36 | if (parameter is null)
37 | {
38 | throw new ArgumentNullException(nameof(parameter));
39 | }
40 |
41 | if (sqlArgument.DbType != DbType.Time)
42 | {
43 | // Work around for a bug in SqlClient where it thinks DbType.Time is a MetaType.MetaDateTime.
44 | // Do not set the DbType, the SqlParameter will figure it out by reflecting over the value type.
45 | parameter.DbType = sqlArgument.DbType;
46 | }
47 |
48 | parameter.Direction = ParameterDirection.Input;
49 | parameter.ParameterName = parameterName;
50 | parameter.Value = sqlArgument.Value ?? DBNull.Value;
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/MicroLite/Driver/MySqlDbDriver.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using MicroLite.Characters;
14 |
15 | namespace MicroLite.Driver
16 | {
17 | ///
18 | /// The implementation of for MySql server.
19 | ///
20 | internal sealed class MySqlDbDriver : DbDriver
21 | {
22 | ///
23 | /// Initialises a new instance of the class.
24 | ///
25 | internal MySqlDbDriver()
26 | : base(MySqlCharacters.Instance)
27 | {
28 | }
29 |
30 | public override bool SupportsBatchedQueries => true;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/MicroLite/Driver/SQLiteDbDriver.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using MicroLite.Characters;
14 |
15 | namespace MicroLite.Driver
16 | {
17 | ///
18 | /// The implementation of for SQLite.
19 | ///
20 | internal sealed class SQLiteDbDriver : DbDriver
21 | {
22 | ///
23 | /// Initialises a new instance of the class.
24 | ///
25 | internal SQLiteDbDriver()
26 | : base(SQLiteCharacters.Instance)
27 | {
28 | }
29 |
30 | public override bool SupportsBatchedQueries => true;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/MicroLite/Driver/_Driver.cd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | AAEAAAAhQAAAABEAAAEACAAAgAAQAAAAACABBAAACQA=
7 | Driver\DbDriver.cs
8 |
9 |
10 |
11 |
12 |
13 |
14 | AAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAQA=
15 | Driver\MsSqlDbDriver.cs
16 |
17 |
18 |
19 |
20 |
21 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQA=
22 | Driver\MySqlDbDriver.cs
23 |
24 |
25 |
26 |
27 |
28 | AAAAAAAAQAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAQA=
29 | Driver\PostgreSqlDbDriver.cs
30 |
31 |
32 |
33 |
34 |
35 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQA=
36 | Driver\SQLiteDbDriver.cs
37 |
38 |
39 |
40 |
41 |
42 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
43 | Driver\FirebirdDbDriver.cs
44 |
45 |
46 |
47 |
48 |
49 | AAAAAAAAAAAAAAEAAAEAAAAAAAAQAAAAACABAAAAAQA=
50 | Driver\IDbDriver.cs
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/MicroLite/FrameworkExtensions/StringExtensions.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System.Text.RegularExpressions;
14 |
15 | namespace MicroLite.FrameworkExtensions
16 | {
17 | internal static class StringExtensions
18 | {
19 | internal static string FormatWith(this string value, string arg0) => string.Format(value, arg0);
20 |
21 | internal static string FormatWith(this string value, string arg0, string arg1) => string.Format(value, arg0, arg1);
22 |
23 | internal static string ToUnderscored(this string value) => Regex.Replace(value, "(?!^)(?=[A-Z])", "_");
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/MicroLite/IAdvancedReadOnlySession.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System.Threading;
14 | using System.Threading.Tasks;
15 |
16 | namespace MicroLite
17 | {
18 | ///
19 | /// The interface which provides access to advanced read-only session operations.
20 | ///
21 | ///
22 | /// These operations allow for more advanced use and have been moved to a separate interface to avoid
23 | /// cluttering the IAsyncReadOnlySession API.
24 | ///
25 | public interface IAdvancedReadOnlySession
26 | {
27 | ///
28 | /// Asynchronously executes any pending queries which have been queued using the Include API.
29 | ///
30 | /// A task representing the asynchronous operation.
31 | /// Invokes ExecutePendingQueriesAsync(CancellationToken) with CancellationToken.None.
32 | Task ExecutePendingQueriesAsync();
33 |
34 | ///
35 | /// Asynchronously executes any pending queries which have been queued using the Include API.
36 | /// This method propagates a notification that operations should be cancelled.
37 | ///
38 | /// The token to monitor for cancellation requests.
39 | /// A task representing the asynchronous operation.
40 | Task ExecutePendingQueriesAsync(CancellationToken cancellationToken);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/MicroLite/IInclude.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 |
15 | namespace MicroLite
16 | {
17 | ///
18 | /// The interface for including a single result.
19 | ///
20 | /// The type of object to be included.
21 | public interface IInclude
22 | {
23 | ///
24 | /// Gets a value indicating whether this include has a value.
25 | ///
26 | bool HasValue { get; }
27 |
28 | ///
29 | /// Gets the included value.
30 | ///
31 | ///
32 | /// Value will be in one of the following states:
33 | /// - If the overall query has not been executed the value will be equal to its default value (null for reference types).
34 | /// - If the query yielded no results, it will be its default value; otherwise it will be the result of the query.
35 | ///
36 | T Value { get; }
37 |
38 | ///
39 | /// Called when the included value is loaded.
40 | ///
41 | /// The action to be invoked.
42 | void OnLoad(Action> action);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/MicroLite/IIncludeMany.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using System.Collections.Generic;
15 |
16 | namespace MicroLite
17 | {
18 | ///
19 | /// The interface for including a multiple results.
20 | ///
21 | /// The type of object to be included.
22 | public interface IIncludeMany
23 | {
24 | ///
25 | /// Gets a value indicating whether this include has a value.
26 | ///
27 | bool HasValue { get; }
28 |
29 | ///
30 | /// Gets the included values.
31 | ///
32 | ///
33 | /// Values will be in one of the following states:
34 | /// - If the overall query has not been executed the value will be an empty collection.
35 | /// - If the query yielded no results, it will be an empty collection; otherwise it will contain the results of the query.
36 | ///
37 | IList Values { get; }
38 |
39 | ///
40 | /// Called when the included value is loaded.
41 | ///
42 | /// The action to be invoked.
43 | void OnLoad(Action> action);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/MicroLite/ISessionFactory.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using MicroLite.Driver;
14 |
15 | namespace MicroLite
16 | {
17 | ///
18 | /// The interface which defines the factory methods for creating MicroLite sessions.
19 | ///
20 | public interface ISessionFactory
21 | {
22 | ///
23 | /// Gets the name of the connection in the connection strings configuration section used by the session factory.
24 | ///
25 | string ConnectionName { get; }
26 |
27 | ///
28 | /// Gets the DB driver used by the session factory.
29 | ///
30 | IDbDriver DbDriver { get; }
31 |
32 | ///
33 | /// Opens a new read-only session to the database using .PerTransaction.
34 | ///
35 | /// A new read-only database session.
36 | IReadOnlySession OpenReadOnlySession();
37 |
38 | ///
39 | /// Opens a new read-only session to the database using the specified .
40 | ///
41 | /// The connection scope to use for the session.
42 | /// A new read-only database session.
43 | IReadOnlySession OpenReadOnlySession(ConnectionScope connectionScope);
44 |
45 | ///
46 | /// Opens a new session to the database using .PerTransaction.
47 | ///
48 | /// A new database session.
49 | ISession OpenSession();
50 |
51 | ///
52 | /// Opens a new session to the database using the specified .
53 | ///
54 | /// The connection scope to use for the session.
55 | /// A new database session.
56 | ISession OpenSession(ConnectionScope connectionScope);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/MicroLite/ITransaction.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 |
15 | namespace MicroLite
16 | {
17 | ///
18 | /// The interface for a database transaction.
19 | ///
20 | public interface ITransaction : IDisposable
21 | {
22 | ///
23 | /// Gets a value indicating whether this transaction is active.
24 | ///
25 | bool IsActive { get; }
26 |
27 | ///
28 | /// Commits the transaction, applying all changes made within the transaction scope.
29 | ///
30 | /// Thrown if the transaction has been completed.
31 | /// Thrown if there is an error committing the transaction.
32 | void Commit();
33 |
34 | ///
35 | /// Rollbacks the transaction, undoing all changes made within the transaction scope.
36 | ///
37 | /// Thrown if the transaction has been completed.
38 | /// Thrown if there is an error rolling back the transaction.
39 | void Rollback();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/MicroLite/Infrastructure/IHaveReadOnlySession.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Infrastructure
14 | {
15 | ///
16 | /// An interface for classes which have an property.
17 | ///
18 | public interface IHaveReadOnlySession
19 | {
20 | ///
21 | /// Gets the read-only MicroLite session.
22 | ///
23 | IReadOnlySession Session { get; }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/MicroLite/Infrastructure/IHaveSession.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Infrastructure
14 | {
15 | ///
16 | /// An interface for classes which have an property.
17 | ///
18 | public interface IHaveSession
19 | {
20 | ///
21 | /// Gets the MicroLite session.
22 | ///
23 | ISession Session { get; }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/MicroLite/Listeners/IDeleteListener.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Listeners
14 | {
15 | ///
16 | /// The interface which exposes hooks into the deletion of an object by the MicroLite ORM framework.
17 | ///
18 | public interface IDeleteListener
19 | {
20 | ///
21 | /// Invoked after the SqlQuery to delete the record for the instance has been executed.
22 | ///
23 | /// The instance which has been deleted.
24 | /// The number of rows affected by the delete.
25 | void AfterDelete(object instance, int rowsAffected);
26 |
27 | ///
28 | /// Invoked before the SqlQuery to delete the record from the database is created.
29 | ///
30 | /// The instance to be deleted.
31 | void BeforeDelete(object instance);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/MicroLite/Listeners/IInsertListener.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Listeners
14 | {
15 | ///
16 | /// The interface which exposes hooks into the insertion of an object by the MicroLite ORM framework.
17 | ///
18 | public interface IInsertListener
19 | {
20 | ///
21 | /// Invoked after the SqlQuery to insert the record for the instance has been executed.
22 | ///
23 | /// The instance which has been inserted.
24 | /// The execute scalar result (the identifier value returned by the database
25 | /// or null if the identifier is .Assigned.
26 | void AfterInsert(object instance, object executeScalarResult);
27 |
28 | ///
29 | /// Invoked before the SqlQuery to insert the record into the database is created.
30 | ///
31 | /// The instance to be inserted.
32 | void BeforeInsert(object instance);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/MicroLite/Listeners/IUpdateListener.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Listeners
14 | {
15 | ///
16 | /// The interface which exposes hooks into the updating of an object by the MicroLite ORM framework.
17 | ///
18 | public interface IUpdateListener
19 | {
20 | ///
21 | /// Invoked after the SqlQuery to update the record for the instance has been executed.
22 | ///
23 | /// The instance which has been updates.
24 | /// The number of rows affected by the update.
25 | void AfterUpdate(object instance, int rowsAffected);
26 |
27 | ///
28 | /// Invoked before the SqlQuery to update the record in the database is created.
29 | ///
30 | /// The instance to be updated.
31 | void BeforeUpdate(object instance);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/MicroLite/Listeners/Listener.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System.Collections.Generic;
14 | using MicroLite.Collections;
15 |
16 | namespace MicroLite.Listeners
17 | {
18 | ///
19 | /// Static entry point for listener collections.
20 | ///
21 | public static class Listener
22 | {
23 | ///
24 | /// Gets the listener collection which contains all registered s.
25 | ///
26 | public static IList DeleteListeners { get; } = new StackCollection();
27 |
28 | ///
29 | /// Gets the listener collection which contains all registered s.
30 | ///
31 | public static IList InsertListener { get; } = new StackCollection();
32 |
33 | ///
34 | /// Gets the listener collection which contains all registered s.
35 | ///
36 | public static IList UpdateListeners { get; } = new StackCollection();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/MicroLite/Listeners/SessionListeners.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System.Collections.Generic;
14 |
15 | namespace MicroLite.Listeners
16 | {
17 | internal sealed class SessionListeners
18 | {
19 | internal SessionListeners()
20 | : this(new IDeleteListener[0], new IInsertListener[0], new IUpdateListener[0])
21 | {
22 | }
23 |
24 | internal SessionListeners(
25 | IList deleteListeners,
26 | IList insertListeners,
27 | IList updateListeners)
28 | {
29 | DeleteListeners = deleteListeners;
30 | InsertListeners = insertListeners;
31 | UpdateListeners = updateListeners;
32 | }
33 |
34 | internal IList DeleteListeners { get; }
35 |
36 | internal IList InsertListeners { get; }
37 |
38 | internal IList UpdateListeners { get; }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/MicroLite/Listeners/_Listeners.cd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | AAAAAAAIgAAAAAAAgAAAAAAIgAAAAAAAgAAAAAAAAAA=
7 | Listeners\Listener.cs
8 |
9 |
10 |
11 |
12 |
13 | AAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
14 | Listeners\DeleteListenerCollection.cs
15 |
16 |
17 |
18 |
19 |
20 | AAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
21 | Listeners\InsertListenerCollection.cs
22 |
23 |
24 |
25 |
26 |
27 | AAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
28 | Listeners\UpdateListenerCollection.cs
29 |
30 |
31 |
32 |
33 |
34 | AAAAAAAAAAAAAAAAAAAACAAAAAAACAAAAAQAAAAAAAA=
35 | Listeners\IdentifierStrategyListener.cs
36 |
37 |
38 |
39 |
40 |
41 |
42 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAABAAA=
43 | Listeners\IDeleteListener.cs
44 |
45 |
46 |
47 |
48 |
49 | AAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAQAAAAAAAA=
50 | Listeners\IInsertListener.cs
51 |
52 |
53 |
54 |
55 |
56 | AAAgAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
57 | Listeners\IUpdateListener.cs
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/MicroLite/Logging/EmptyLog.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 |
15 | namespace MicroLite.Logging
16 | {
17 | ///
18 | /// An implementation of ILog which always returns false for all log levels and all methods are no-op.
19 | ///
20 | internal sealed class EmptyLog : ILog
21 | {
22 | private EmptyLog()
23 | {
24 | }
25 |
26 | public bool IsDebug => false;
27 |
28 | public bool IsError => false;
29 |
30 | public bool IsFatal => false;
31 |
32 | public bool IsInfo => false;
33 |
34 | public bool IsWarn => false;
35 |
36 | internal static ILog Instance { get; } = new EmptyLog();
37 |
38 | public void Debug(string message)
39 | {
40 | // no-op
41 | }
42 |
43 | public void Debug(string message, params string[] formatArgs)
44 | {
45 | // no-op
46 | }
47 |
48 | public void Error(string message)
49 | {
50 | // no-op
51 | }
52 |
53 | public void Error(string message, Exception exception)
54 | {
55 | // no-op
56 | }
57 |
58 | public void Error(string message, params string[] formatArgs)
59 | {
60 | // no-op
61 | }
62 |
63 | public void Fatal(string message)
64 | {
65 | // no-op
66 | }
67 |
68 | public void Fatal(string message, Exception exception)
69 | {
70 | // no-op
71 | }
72 |
73 | public void Fatal(string message, params string[] formatArgs)
74 | {
75 | // no-op
76 | }
77 |
78 | public void Info(string message)
79 | {
80 | // no-op
81 | }
82 |
83 | public void Info(string message, params string[] formatArgs)
84 | {
85 | // no-op
86 | }
87 |
88 | public void Warn(string message)
89 | {
90 | // no-op
91 | }
92 |
93 | public void Warn(string message, params string[] formatArgs)
94 | {
95 | // no-op
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/MicroLite/Logging/LogManager.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using System.Diagnostics;
15 |
16 | namespace MicroLite.Logging
17 | {
18 | ///
19 | /// A class which the MicroLite ORM framework can call to resolve an ILog implementation.
20 | ///
21 | public static class LogManager
22 | {
23 | ///
24 | /// Gets or sets the function which can be called by MicroLite to resolve the to use.
25 | ///
26 | internal static Func GetLogger { get; set; }
27 |
28 | ///
29 | /// Gets the log for the current (calling) class.
30 | ///
31 | /// The for the class which called the method.
32 | public static ILog GetCurrentClassLog()
33 | {
34 | Func getLogger = GetLogger;
35 |
36 | if (getLogger != null)
37 | {
38 | var stackFrame = new StackFrame(skipFrames: 1);
39 |
40 | return getLogger(stackFrame.GetMethod().DeclaringType);
41 | }
42 |
43 | return EmptyLog.Instance;
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/MicroLite/Logging/_Logging.cd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | AAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAACAAAAIAAA=
7 | Logging\LogManager.cs
8 |
9 |
10 |
11 |
12 |
13 | AgAgAAAAAAAAQYAAAAAAAAAABAABAAEAAAAAAEAEAAA=
14 | Logging\EmptyLog.cs
15 |
16 |
17 |
18 |
19 |
20 |
21 | AgAgAAAAAAAAQYAAAAAAAAAABAABAAEAAAAAAEAEAAA=
22 | Logging\ILog.cs
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/MicroLite/Mapping/Attributes/TableAttribute.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 |
15 | namespace MicroLite.Mapping.Attributes
16 | {
17 | ///
18 | /// An attribute which can be applied to a class to specify the table name and database schema the table
19 | /// exists within.
20 | ///
21 | ///
22 | ///
23 | /// // Option 1 - Specify schema and table name.
24 | /// [Table("dbo", "Customers")]
25 | /// public class Customer
26 | /// {
27 | /// ...
28 | /// }
29 | ///
30 | ///
31 | /// // Option 2 - Specify table name only.
32 | /// [Table("Customers")]
33 | /// public class Customer
34 | /// {
35 | /// ...
36 | /// }
37 | ///
38 | ///
39 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
40 | public sealed class TableAttribute : Attribute
41 | {
42 | ///
43 | /// Initialises a new instance of the class.
44 | ///
45 | /// The name of the table.
46 | public TableAttribute(string name)
47 | : this(null, name)
48 | {
49 | }
50 |
51 | ///
52 | /// Initialises a new instance of the class.
53 | ///
54 | /// The database schema the table exists within (e.g. 'dbo'); otherwise null.
55 | /// The name of the table.
56 | public TableAttribute(string schema, string name)
57 | {
58 | Name = name;
59 | Schema = schema;
60 | }
61 |
62 | ///
63 | /// Gets the name of the table.
64 | ///
65 | public string Name { get; }
66 |
67 | ///
68 | /// Gets the database schema the table exists within (e.g. 'dbo'); otherwise null.
69 | ///
70 | public string Schema { get; }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/MicroLite/Mapping/Attributes/_MappingAttributes.cd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | AAAAAgAAAAAAAAAAAAAACAgAAAAAAAAAAAAAAAAAAAA=
7 | Mapping\Attributes\AttributeMappingConvention.cs
8 |
9 |
10 |
11 |
12 |
13 |
14 | ABAAAAAQAAAAAAAAAAAAAAQAYAAEAGAAAAAAAAAAAAA=
15 | Mapping\Attributes\ColumnAttribute.cs
16 |
17 |
18 |
19 |
20 |
21 | AAAAAAAAAAAAAAAAAAAAAAQAAAAEQAAAAEAAAAAAAAA=
22 | Mapping\Attributes\IdentifierAttribute.cs
23 |
24 |
25 |
26 |
27 |
28 | AAAAAAAAAAAAAAAAAAAAAAQEAAAEBAAAAAAAAAAAAAA=
29 | Mapping\Attributes\TableAttribute.cs
30 |
31 |
32 |
33 |
34 |
35 | AAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
36 | Mapping\IMappingConvention.cs
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/MicroLite/Mapping/IMappingConvention.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 |
15 | namespace MicroLite.Mapping
16 | {
17 | ///
18 | /// The interface for a class which implements a mapping convention between a class and a table.
19 | ///
20 | public interface IMappingConvention
21 | {
22 | ///
23 | /// Creates the object info for the specified type.
24 | ///
25 | /// The type to create the object info for.
26 | /// The for the specified type.
27 | IObjectInfo CreateObjectInfo(Type forType);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/MicroLite/Mapping/IdentifierStrategy.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Mapping
14 | {
15 | ///
16 | /// The supported strategies used to manage a database identifier column value.
17 | ///
18 | public enum IdentifierStrategy
19 | {
20 | ///
21 | /// The identifier value is generated by the database upon insert (for example Identity in MsSQL or AutoIncrement in SQLite, MySQL or PostgreSQL).
22 | ///
23 | DbGenerated = 0,
24 |
25 | ///
26 | /// The identifier value is assigned by user code prior to insert (either manually or via an IListener).
27 | ///
28 | Assigned = 1,
29 |
30 | ///
31 | /// The identifier value is generated by a database sequence upon insert.
32 | ///
33 | Sequence = 2,
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/MicroLite/Mapping/Inflection/IInflectionService.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Mapping.Inflection
14 | {
15 | ///
16 | /// The interface for a class which is capable of modifying the grammatical category of words.
17 | ///
18 | public interface IInflectionService
19 | {
20 | ///
21 | /// Adds a word which is considered invariant, for example 'equipment' or 'species' in English.
22 | ///
23 | /// The invariant word.
24 | void AddInvariantWord(string word);
25 |
26 | ///
27 | /// Adds (or replaces) the rule.
28 | ///
29 | /// The pattern to match upon.
30 | /// The replacement pattern.
31 | void AddRule(string searchPattern, string replacementPattern);
32 |
33 | ///
34 | /// Returns the plural version of the specified singular word or the specified word if there is no plural version.
35 | ///
36 | /// The word to be pluralized.
37 | /// The plural word, or if the word cannot be pluralized; the specified word.
38 | string ToPlural(string word);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/MicroLite/Mapping/Inflection/InflectionService.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | namespace MicroLite.Mapping.Inflection
14 | {
15 | ///
16 | /// A class which provides access to inflection services for different cultures.
17 | ///
18 | public static class InflectionService
19 | {
20 | ///
21 | /// Gets the IInflection service for English (en-GB).
22 | ///
23 | public static IInflectionService English { get; } = new EnglishInflectionService();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/MicroLite/Mapping/Inflection/_Inflection.cd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | AAAAAAAAAAAAAAAAAAAAAAAABAAAAAQAAAAAAAAAAAA=
7 | Mapping\Inflection\InflectionService.cs
8 |
9 |
10 |
11 |
12 |
13 | AAAAAAIAAAAAAAAAAAAAAAAAAAgAAAAAAAIAAAAEgAA=
14 | Mapping\Inflection\EnglishInflectionService.cs
15 |
16 |
17 |
18 |
19 |
20 |
21 | AAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAEgAA=
22 | Mapping\Inflection\IInflectionService.cs
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/MicroLite/Mapping/LowercaseWithUnderscoresConventionMappingSettings.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using System.Reflection;
15 | using MicroLite.FrameworkExtensions;
16 |
17 | namespace MicroLite.Mapping
18 | {
19 | ///
20 | /// A class containing the convention mapping settings for lowercase with underscore separators (e.g. 'CreditCard' -> 'credit_card').
21 | ///
22 | public class LowercaseWithUnderscoresConventionMappingSettings : ConventionMappingSettings
23 | {
24 | ///
25 | /// Initialises a new instance of the class.
26 | ///
27 | public LowercaseWithUnderscoresConventionMappingSettings()
28 | {
29 | #pragma warning disable CA1308 // Normalize strings to uppercase
30 | ResolveColumnName = (PropertyInfo propertyInfo) => ConventionMappingSettings.GetColumnName(propertyInfo).ToUnderscored().ToLowerInvariant();
31 | ResolveIdentifierColumnName = (PropertyInfo propertyInfo) => propertyInfo.Name.ToUnderscored().ToLowerInvariant();
32 | ResolveTableName = (Type type) =>
33 | {
34 | string tableName = UsePluralClassNameForTableName ? InflectionService.ToPlural(GetTableName(type)) : GetTableName(type);
35 |
36 | return tableName.ToUnderscored().ToLowerInvariant();
37 | #pragma warning restore CA1308 // Normalize strings to uppercase
38 | };
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/MicroLite/Mapping/MappingException.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using System.Runtime.Serialization;
15 |
16 | namespace MicroLite.Mapping
17 | {
18 | ///
19 | /// A more specific MicroLiteException which is only thrown for mapping exceptions.
20 | ///
21 | [Serializable]
22 | public class MappingException : MicroLiteException
23 | {
24 | ///
25 | /// Initialises a new instance of the class.
26 | ///
27 | public MappingException()
28 | {
29 | }
30 |
31 | ///
32 | /// Initialises a new instance of the class.
33 | ///
34 | /// The message.
35 | public MappingException(string message)
36 | : base(message)
37 | {
38 | }
39 |
40 | ///
41 | /// Initialises a new instance of the class.
42 | ///
43 | /// The message.
44 | /// The inner exception.
45 | public MappingException(string message, Exception innerException)
46 | : base(message, innerException)
47 | {
48 | }
49 |
50 | ///
51 | /// Initialises a new instance of the class.
52 | ///
53 | /// The that holds the serialized object data about the exception being thrown.
54 | /// The that contains contextual information about the source or destination.
55 | /// The parameter is null.
56 | /// The class name is null or HResult is zero (0).
57 | protected MappingException(SerializationInfo info, StreamingContext context)
58 | : base(info, context)
59 | {
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/MicroLite/Mapping/MemberInfoExtensions.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using System.Reflection;
15 |
16 | namespace MicroLite.Mapping
17 | {
18 | internal static class MemberInfoExtensions
19 | {
20 | internal static T GetAttribute(this MemberInfo memberInfo, bool inherit)
21 | where T : Attribute
22 | => memberInfo.GetCustomAttributes(typeof(T), inherit) is T[] attributes && attributes.Length == 1 ? attributes[0] : null;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/MicroLite/Mapping/UppercaseWithUnderscoresConventionMappingSettings.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using System.Reflection;
15 | using MicroLite.FrameworkExtensions;
16 |
17 | namespace MicroLite.Mapping
18 | {
19 | ///
20 | /// A class containing the convention mapping settings for uppercase with underscore separators (e.g. 'CreditCard' -> 'CREDIT_CARD').
21 | ///
22 | public class UppercaseWithUnderscoresConventionMappingSettings : ConventionMappingSettings
23 | {
24 | ///
25 | /// Initialises a new instance of the class.
26 | ///
27 | public UppercaseWithUnderscoresConventionMappingSettings()
28 | {
29 | ResolveColumnName = (PropertyInfo propertyInfo) => ConventionMappingSettings.GetColumnName(propertyInfo).ToUnderscored().ToUpperInvariant();
30 | ResolveIdentifierColumnName = (PropertyInfo propertyInfo) => propertyInfo.Name.ToUnderscored().ToUpperInvariant();
31 | ResolveTableName = (Type type) =>
32 | {
33 | string tableName = UsePluralClassNameForTableName ? InflectionService.ToPlural(GetTableName(type)) : GetTableName(type);
34 |
35 | return tableName.ToUnderscored().ToUpperInvariant();
36 | };
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/MicroLite/Mapping/_MappingConvention.cd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | AAAAAgAAAAAAAAAAAAAACAgAAACAAAAAAAAAAAAAAAA=
7 | Mapping\ConventionMappingConvention.cs
8 |
9 |
10 |
11 |
12 |
13 |
14 | AIAAAAAQCAIAAAAiAAAAIAAAIAAACEACAEABAAIAAAA=
15 | Mapping\ConventionMappingSettings.cs
16 |
17 |
18 |
19 |
20 |
21 | AAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
22 | Mapping\IMappingConvention.cs
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/MicroLite/Mapping/_ObjectInfo.cd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | AIAABCAAAIAACCAAAZAgACAIAAEASEAAAABAAAIAIAM=
7 | Mapping\PocoObjectInfo.cs
8 | Mapping\ObjectInfo.cs
9 |
10 |
11 |
12 |
13 |
14 |
15 | AAAAAACABABEAAAAAEAAAAQEAAQERAAACEAAAAwAAAA=
16 | Mapping\TableInfo.cs
17 |
18 |
19 |
20 |
21 |
22 | ABAAAAEQAAABAAAAAABAAAQAQAAEAEAAAABBAAAAAQA=
23 | Mapping\ColumnInfo.cs
24 |
25 |
26 |
27 |
28 |
29 | AIAABCAAAIAAAAAAAJAAAAAAAAEASAAAAABAAAAAIAE=
30 | Mapping\ExpandoObjectInfo.cs
31 |
32 |
33 |
34 |
35 |
36 |
37 | AIAABCAAAIAAAAAAAJAAAAAAAAEASAAAAABAIAAAIAE=
38 | Mapping\TupleObjectInfo.cs
39 |
40 |
41 |
42 |
43 |
44 |
45 | QAAAAAAAAAAABAAAAAAADAAAIAAAAAAAQAAABAAAAAQ=
46 | Mapping\ObjectInfo.cs
47 |
48 |
49 |
50 |
51 |
52 | AIAABCAAAIAAAAAAABAAAAAAAAEASAAAAABAAAAAIAE=
53 | Mapping\IObjectInfo.cs
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/MicroLite/MicroLiteException.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using System.Runtime.Serialization;
15 |
16 | namespace MicroLite
17 | {
18 | ///
19 | /// The base exception thrown by the MicroLite ORM framework.
20 | ///
21 | ///
22 | /// This exception will be thrown for exceptions encountered by the MicroLite ORM framework
23 | /// or to wrap any exceptions thrown by .net framework classes to allow for consistent error handling.
24 | ///
25 | [Serializable]
26 | public class MicroLiteException : Exception
27 | {
28 | ///
29 | /// Initialises a new instance of the class.
30 | ///
31 | public MicroLiteException()
32 | {
33 | }
34 |
35 | ///
36 | /// Initialises a new instance of the class.
37 | ///
38 | /// The message.
39 | public MicroLiteException(string message)
40 | : base(message)
41 | {
42 | }
43 |
44 | ///
45 | /// Initialises a new instance of the class.
46 | ///
47 | /// The message.
48 | /// The inner exception.
49 | public MicroLiteException(string message, Exception innerException)
50 | : base(message, innerException)
51 | {
52 | }
53 |
54 | ///
55 | /// Initialises a new instance of the class.
56 | ///
57 | /// The that holds the serialized object data about the exception being thrown.
58 | /// The that contains contextual information about the source or destination.
59 | /// The parameter is null.
60 | /// The class name is null or HResult is zero (0).
61 | protected MicroLiteException(SerializationInfo info, StreamingContext context)
62 | : base(info, context)
63 | {
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/MicroLite/ObjectDelta.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using System.Collections.Generic;
15 |
16 | namespace MicroLite
17 | {
18 | ///
19 | /// An class which contains partial (delta) changes to an object.
20 | ///
21 | [System.Diagnostics.DebuggerDisplay("{forType}")]
22 | public sealed class ObjectDelta
23 | {
24 | private readonly IDictionary _changes = new Dictionary();
25 |
26 | ///
27 | /// Initialises a new instance of the class.
28 | ///
29 | /// The type the changes relate to.
30 | /// The identifier for the instance of the type the changes relate to.
31 | public ObjectDelta(Type forType, object identifier)
32 | {
33 | ForType = forType ?? throw new ArgumentNullException(nameof(forType));
34 | Identifier = identifier ?? throw new ArgumentNullException(nameof(identifier));
35 | }
36 |
37 | ///
38 | /// Gets the number of changes in the delta.
39 | ///
40 | public int ChangeCount => _changes.Count;
41 |
42 | ///
43 | /// Gets the changes contained in the delta.
44 | ///
45 | public IEnumerable> Changes => _changes;
46 |
47 | ///
48 | /// Gets for type the changes relate to.
49 | ///
50 | public Type ForType { get; }
51 |
52 | ///
53 | /// Gets the identifier for the instance of the type the changes relate to.
54 | ///
55 | public object Identifier { get; }
56 |
57 | ///
58 | /// Adds the a property value change.
59 | ///
60 | /// The name of the property to change.
61 | /// The new value for the property (can be null).
62 | public void AddChange(string propertyName, object newValue)
63 | => _changes.Add(propertyName, newValue);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/MicroLite/PagedResult.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System.Collections.Generic;
14 |
15 | namespace MicroLite
16 | {
17 | ///
18 | /// A class which contains the result of a paged query.
19 | ///
20 | /// The type of object the contained in the results.
21 | [System.Diagnostics.DebuggerDisplay("Page {Page} of {TotalPages} showing {ResultsPerPage} results per page with a total of {TotalResults} results")]
22 | public sealed class PagedResult
23 | {
24 | ///
25 | /// Initialises a new instance of the class.
26 | ///
27 | /// The page number for the results.
28 | /// The results in the page.
29 | /// The number of results per page.
30 | /// The total number of results for the query.
31 | public PagedResult(int page, IList results, int resultsPerPage, int totalResults)
32 | {
33 | Page = page;
34 | Results = results;
35 | ResultsPerPage = resultsPerPage;
36 | TotalResults = totalResults;
37 | }
38 |
39 | ///
40 | /// Gets a value indicating whether this page contains any results.
41 | ///
42 | public bool HasResults => Results.Count > 0;
43 |
44 | ///
45 | /// Gets a value indicating whether there are more results available.
46 | ///
47 | public bool MoreResultsAvailable => Page < TotalPages;
48 |
49 | ///
50 | /// Gets the page number for the results.
51 | ///
52 | public int Page { get; }
53 |
54 | ///
55 | /// Gets the results in the page.
56 | ///
57 | public IList Results { get; }
58 |
59 | ///
60 | /// Gets the number of results per page.
61 | ///
62 | public int ResultsPerPage { get; }
63 |
64 | ///
65 | /// Gets the total number of pages for the query.
66 | ///
67 | public int TotalPages => ((TotalResults - 1) / ResultsPerPage) + 1;
68 |
69 | ///
70 | /// Gets the total number of results for the query.
71 | ///
72 | public int TotalResults { get; }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/MicroLite/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using System.Runtime.CompilerServices;
15 |
16 | [assembly: CLSCompliant(true)]
17 | [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
18 | [assembly: InternalsVisibleTo("MicroLite.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010011797cd346943588cc5fcfc675b0aeba173df75154e20fc84652791f0c028ec2d3f5c9a311ea16a2a6b021788a5e66ffa0bdb6d38e7678e605284be34be5eabe5f924eb633e9a7cf4b98ab2d12532fae0da9eda77b9aec3cbd78b1e0a2ed9e359ae4e706f441d796d92d5488b1dfb7456817454acb68265ae98d94b5fc79a8c7")]
19 |
--------------------------------------------------------------------------------
/MicroLite/TypeConverters/ITypeConverter.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System;
14 | using System.Data;
15 |
16 | namespace MicroLite.TypeConverters
17 | {
18 | ///
19 | /// The interface for a class which can convert between property type values and database values.
20 | ///
21 | public interface ITypeConverter
22 | {
23 | ///
24 | /// Determines whether this type converter can convert values for the specified type.
25 | ///
26 | /// The type to check.
27 | ///
28 | /// true if this instance can convert the specified type; otherwise, false.
29 | ///
30 | bool CanConvert(Type type);
31 |
32 | ///
33 | /// Converts the specified database value into an instance of the specified type.
34 | ///
35 | /// The database value to be converted.
36 | /// The type to convert to.
37 | /// An instance of the specified type containing the specified value.
38 | /// Thrown if type is null.
39 | object ConvertFromDbValue(object value, Type type);
40 |
41 | ///
42 | /// Converts value at the specified index in the IDataReader into an instance of the specified type.
43 | ///
44 | /// The IDataReader containing the results.
45 | /// The index of the record to read from the IDataReader.
46 | /// The type to convert result value to.
47 | /// An instance of the specified type containing the specified value.
48 | /// Thrown if reader or type is null.
49 | object ConvertFromDbValue(IDataReader reader, int index, Type type);
50 |
51 | ///
52 | /// Converts the specified value into an instance of the database value.
53 | ///
54 | /// The value to be converted.
55 | /// The type to convert from.
56 | /// An instance of the corresponding database type containing the value.
57 | /// Thrown if type is null.
58 | object ConvertToDbValue(object value, Type type);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/MicroLite/TypeConverters/TypeConverterCollection.cs:
--------------------------------------------------------------------------------
1 | // -----------------------------------------------------------------------
2 | //
3 | // Copyright Project Contributors
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | //
12 | // -----------------------------------------------------------------------
13 | using System.Collections.ObjectModel;
14 |
15 | namespace MicroLite.TypeConverters
16 | {
17 | ///
18 | /// The class which contains the ITypeConverters used by the MicroLite ORM framework.
19 | ///
20 | /// The collection acts in the same way as a stack, the last converter added is the first used if it handles the type.
21 | public sealed class TypeConverterCollection : Collection
22 | {
23 | ///
24 | /// Initialises a new instance of the class.
25 | ///
26 | public TypeConverterCollection()
27 | {
28 | // In order to maintain the behaviour of a stack, keep inserting at position 0 which will shift the items down.
29 | Items.Insert(0, new XDocumentTypeConverter());
30 | Items.Insert(0, new TimeSpanTypeConverter());
31 | Items.Insert(0, new UriTypeConverter());
32 | Items.Insert(0, new EnumTypeConverter()); // Enum is the most common of the custom types so put that at the top.
33 | }
34 |
35 | ///
36 | /// Inserts an element into the Collection at the specified index.
37 | ///
38 | /// The zero-based index at which should be inserted.
39 | /// The object to insert. The value can be null for reference types.
40 | protected override void InsertItem(int index, ITypeConverter item)
41 | => Items.Insert(0, item);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/MicroLite/TypeConverters/_TypeConverters.cd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | AAAAAAAACAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAACAA=
7 | TypeConverters\EnumTypeConverter.cs
8 |
9 |
10 |
11 |
12 |
13 |
14 | AAAAAAAACAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAACAA=
15 | TypeConverters\ObjectTypeConverter.cs
16 |
17 |
18 |
19 |
20 |
21 |
22 | QACAQAAAAAAIAAAAAAAAIAAAIAAAAAAAAQAAAAIAIEA=
23 | TypeConverters\TypeConverter.cs
24 |
25 |
26 |
27 |
28 |
29 | AAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
30 | TypeConverters\TypeConverterCollection.cs
31 |
32 |
33 |
34 |
35 |
36 | AAAAAAAACAAAAAAAAAEAAAAAAAAAAAAAgAAAAAAACAA=
37 | TypeConverters\XDocumentTypeConverter.cs
38 |
39 |
40 |
41 |
42 |
43 |
44 | AAAAAAAACAAAAAAAAAEAAAAAAACAAAAAAAAAAAAACAA=
45 | TypeConverters\UriTypeConverter.cs
46 |
47 |
48 |
49 |
50 |
51 |
52 | AAAAAAAACAAAAAAAAAEAAAAAAgAAQAAAAAAAAAAACAA=
53 | TypeConverters\TimeSpanTypeConverter.cs
54 |
55 |
56 |
57 |
58 |
59 |
60 | AAAAAAAACAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAACAA=
61 | TypeConverters\ITypeConverter.cs
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/azure-pipelines.yml:
--------------------------------------------------------------------------------
1 | trigger:
2 | branches:
3 | include:
4 | - master
5 | - develop
6 | - hotfix*
7 | paths:
8 | exclude:
9 | - .editorconfig
10 | - README.md
11 | - stylecop.json
12 |
13 | # Must be Windows due to the .NET 4.5 build target
14 | pool:
15 | vmImage: 'windows-latest'
16 |
17 | variables:
18 | buildConfiguration: 'Release'
19 | buildPlatform: 'Any CPU'
20 | buildVersion: '0.0.0'
21 | projectPath: '.\MicroLite\MicroLite.csproj'
22 | solution: '**/*.sln'
23 |
24 | steps:
25 | - task: NuGetToolInstaller@1
26 |
27 | - task: NuGetCommand@2
28 | inputs:
29 | restoreSolution: '$(solution)'
30 |
31 | - task: VSBuild@1
32 | inputs:
33 | solution: '$(solution)'
34 | platform: '$(buildPlatform)'
35 | configuration: '$(buildConfiguration)'
36 |
37 | - task: VSTest@2
38 | inputs:
39 | platform: '$(buildPlatform)'
40 | configuration: '$(buildConfiguration)'
41 | codeCoverageEnabled: true
42 |
43 | - task: PowerShell@2
44 | inputs:
45 | targetType: 'inline'
46 | script: |
47 | $projVersion = ([xml](Get-Content "$(projectPath)")) | Select-Xml -XPath "//Project/PropertyGroup[1]/Version"
48 |
49 | Write-Host "##vso[task.setvariable variable=buildVersion]$projVersion"
50 |
51 | - script: dotnet pack "$(projectPath)" -o:$(Build.ArtifactStagingDirectory) -p:PackageVersion="$(buildVersion)-preview$(Build.BuildNumber)"
52 | displayName: 'dotnet pack (pre)'
53 | condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/master'))
54 |
55 | - script: dotnet pack "$(projectPath)" -o:$(Build.ArtifactStagingDirectory) -p:PackageVersion=$(buildVersion)
56 | displayName: 'dotnet pack'
57 | condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
58 |
59 | - task: NuGetCommand@2
60 | inputs:
61 | command: 'push'
62 | packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
63 | nuGetFeedType: 'external'
64 | publishFeedCredentials: 'NuGet.org (MicroLite-ORM)'
65 | condition: and(succeeded(), in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI', 'Manual'))
66 |
--------------------------------------------------------------------------------
/nuget.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/stylecop.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
3 | "settings": {
4 | "documentationRules": {
5 | "companyName": "Project Contributors",
6 | "copyrightText": "Copyright {companyName}\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0",
7 | "documentationCulture": "en-GB",
8 | "documentExposedElements": true,
9 | "documentInterfaces": true,
10 | "documentInternalElements": false,
11 | "documentPrivateElements": false,
12 | "documentPrivateFields": false,
13 | "fileNamingConvention": "stylecop",
14 | "headerDecoration": "-----------------------------------------------------------------------",
15 | "xmlHeader": true
16 | },
17 | "indentation": {
18 | },
19 | "layoutRules": {
20 | "newlineAtEndOfFile": "require",
21 | "allowConsecutiveUsings": false
22 | },
23 | "maintainabilityRules": {
24 | "topLevelTypes": [
25 | "class",
26 | "enum",
27 | "interface",
28 | "struct"
29 | ]
30 | },
31 | "namingRules": {
32 | },
33 | "orderingRules": {
34 | "systemUsingDirectivesFirst": true,
35 | "usingDirectivesPlacement": "outsideNamespace"
36 | },
37 | "readabilityRules": {
38 | },
39 | "spacingRules": {
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------