├── .editorconfig ├── .gitattributes ├── .github ├── FUNDING.yml └── workflows │ ├── ci.yml │ ├── lock.yml │ └── release.yml ├── .gitignore ├── .readthedocs.yml ├── AutoMapper.sln ├── AutoMapper.snk ├── Build.ps1 ├── CONTRIBUTING.md ├── Directory.Build.props ├── ISSUE_TEMPLATE.md ├── LICENSE.txt ├── Push.ps1 ├── README.md ├── Setup.ps1 ├── docs ├── Makefile ├── make.bat ├── requirements.txt └── source │ ├── 10.0-Upgrade-Guide.md │ ├── 11.0-Upgrade-Guide.md │ ├── 12.0-Upgrade-Guide.md │ ├── 13.0-Upgrade-Guide.md │ ├── 5.0-Upgrade-Guide.md │ ├── 8.0-Upgrade-Guide.md │ ├── 8.1.1-Upgrade-Guide.md │ ├── 9.0-Upgrade-Guide.md │ ├── API-Changes.md │ ├── Attribute-mapping.md │ ├── Before-and-after-map-actions.md │ ├── Conditional-mapping.md │ ├── Configuration-validation.md │ ├── Configuration.md │ ├── Construction.md │ ├── Custom-type-converters.md │ ├── Custom-value-resolvers.md │ ├── Dependency-injection.md │ ├── Dynamic-and-ExpandoObject-Mapping.md │ ├── Enum-Mapping.md │ ├── Expression-Translation-(UseAsDataSource).md │ ├── Flattening.md │ ├── Getting-started.md │ ├── Lists-and-arrays.md │ ├── Mapping-inheritance.md │ ├── Nested-mappings.md │ ├── Null-substitution.md │ ├── Open-Generics.md │ ├── Projection.md │ ├── Queryable-Extensions.md │ ├── Reverse-Mapping-and-Unflattening.md │ ├── Setup.md │ ├── The-MyGet-build.md │ ├── Understanding-your-mapping.md │ ├── Value-converters.md │ ├── Value-transformers.md │ ├── conf.py │ ├── img │ └── logo.png │ └── index.rst ├── icon.png ├── nuget.config ├── nuget.exe └── src ├── AutoMapper.DI.Tests ├── AppDomainResolutionTests.cs ├── AssemblyResolutionTests.cs ├── AttributeTests.cs ├── AutoMapper.DI.Tests.csproj ├── DependencyTests.cs ├── Integrations │ └── ServiceLifetimeTests.cs ├── MultipleRegistrationTests.cs ├── Profiles.cs ├── Properties │ └── AssemblyInfo.cs ├── ScopeTests.cs ├── ServiceLifetimeTests.cs └── TypeResolutionTests.cs ├── AutoMapper ├── ApiCompat │ ├── PreBuild.ps1 │ └── PreBuild.sh ├── ApiCompatBaseline.txt ├── AssemblyInfo.cs ├── AutoMapper.csproj ├── AutoMapperMappingException.cs ├── Configuration │ ├── Annotations │ │ ├── AutoMapAttribute.cs │ │ ├── IMemberConfigurationProvider.cs │ │ ├── IgnoreAttribute.cs │ │ ├── MapAtRuntimeAttribute.cs │ │ ├── MappingOrderAttribute.cs │ │ ├── NullSubstituteAttribute.cs │ │ ├── SourceMemberAttribute.cs │ │ ├── UseExistingValueAttribute.cs │ │ ├── ValueConverterAttribute.cs │ │ └── ValueResolverAttribute.cs │ ├── ConfigurationValidator.cs │ ├── Conventions.cs │ ├── CtorParamConfigurationExpression.cs │ ├── IMappingExpression.cs │ ├── IMappingExpressionBase.cs │ ├── IMappingOperationOptions.cs │ ├── IMemberConfigurationExpression.cs │ ├── INamingConvention.cs │ ├── IProfileExpression.cs │ ├── MapperConfiguration.cs │ ├── MapperConfigurationExpression.cs │ ├── MappingExpression.cs │ ├── MemberConfigurationExpression.cs │ ├── PathConfigurationExpression.cs │ ├── Profile.cs │ ├── SourceMappingExpression.cs │ └── TypeMapConfiguration.cs ├── ConstructorMap.cs ├── Execution │ ├── ExpressionBuilder.cs │ ├── ObjectFactory.cs │ ├── ProxyGenerator.cs │ └── TypeMapPlanBuilder.cs ├── Features.cs ├── Internal │ ├── InternalApi.cs │ ├── LockingConcurrentDictionary.cs │ ├── MemberPath.cs │ ├── PrimitiveHelper.cs │ ├── ReflectionHelper.cs │ ├── TypeDetails.cs │ ├── TypeExtensions.cs │ └── TypePair.cs ├── Mapper.cs ├── Mappers │ ├── AssignableMapper.cs │ ├── CollectionMapper.cs │ ├── ConstructorMapper.cs │ ├── ConversionOperatorMapper.cs │ ├── ConvertMapper.cs │ ├── EnumToEnumMapper.cs │ ├── FromDynamicMapper.cs │ ├── FromStringDictionaryMapper.cs │ ├── IObjectMapper.cs │ ├── KeyValueMapper.cs │ ├── MapperRegistry.cs │ ├── NullableDestinationMapper.cs │ ├── NullableSourceMapper.cs │ ├── ParseStringMapper.cs │ ├── StringToEnumMapper.cs │ ├── ToDynamicMapper.cs │ ├── ToStringDictionaryMapper.cs │ ├── ToStringMapper.cs │ └── UnderlyingEnumTypeMapper.cs ├── MemberMap.cs ├── PathMap.cs ├── ProfileMap.cs ├── PropertyMap.cs ├── QueryableExtensions │ ├── Extensions.cs │ ├── NullsafeQueryRewriter.cs │ ├── ProjectionBuilder.cs │ └── ProjectionMappers │ │ ├── AssignableProjectionMapper.cs │ │ ├── EnumProjectionMapper.cs │ │ ├── EnumerableProjectionMapper.cs │ │ ├── NullableSourceProjectionMapper.cs │ │ └── StringProjectionMapper.cs ├── ResolutionContext.cs ├── ServiceCollectionExtensions.cs └── TypeMap.cs ├── Benchmark ├── BenchEngine.cs ├── Benchmark.csproj ├── FlatteningMapper.cs ├── HiPerfTimer.cs ├── IObjectToObjectMapper.cs └── Program.cs ├── IntegrationTests ├── AutoMapper.IntegrationTests.csproj ├── BuiltInTypes │ ├── ByteArray.cs │ ├── ConvertUsing.cs │ ├── DateTimeToNullableDateTime.cs │ ├── Enums.cs │ ├── NullableToNonNullable.cs │ ├── ProjectEnumerableOfIntToHashSet.cs │ └── ProjectEnumerableOfIntToList.cs ├── ChildClassTests.cs ├── ConstructorDefaultValue.cs ├── CustomMapFrom │ ├── CustomMapFromTest.cs │ └── MapObjectPropertyFromSubQuery.cs ├── CustomProjection.cs ├── ExplicitExpansion │ ├── ConstructorExplicitExpansionOverride.cs │ ├── ExpandCollections.cs │ ├── ExpandCollectionsOverride.cs │ ├── ExpandCollectionsWithStrings.cs │ ├── ExpandMembersPath.cs │ ├── ExplicitlyExpandCollectionsAndChildReferences.cs │ ├── MembersToExpandExpressions.cs │ ├── NestedExplicitExpand.cs │ ├── NestedExplicitExpandWithFields.cs │ ├── ProjectAndAllowNullCollections.cs │ └── ProjectionWithExplicitExpansion.cs ├── ICollectionAggregateProjections.cs ├── IEnumerableAggregateProjections.cs ├── IEnumerableMemberProjections.cs ├── IncludeMembers.cs ├── Inheritance │ ├── DerivedComplexTypes.cs │ ├── OverrideDestinationMappingsTest.cs │ ├── PolymorphismTests.cs │ ├── ProjectToAbstractType.cs │ ├── ProjectToAbstractTypeWithInheritance.cs │ ├── ProxyTests.cs │ └── QueryableInterfaceInheritanceIssue.cs ├── IntegrationTest.cs ├── MaxDepth │ ├── MaxDepthWithCollections.cs │ ├── NavigationPropertySO.cs │ └── NestedDtos.cs ├── NullCheckCollections.cs ├── NullSubstitute.cs ├── ParameterizedQueries.cs ├── ProjectionAdvanced.cs ├── ProjectionOrderTest.cs └── ValueTransformerTests.cs ├── TestApp ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── TestApp.csproj └── UnitTests ├── AddProfiles.cs ├── App.config ├── ArraysAndLists.cs ├── AssemblyScanning.cs ├── AssertionExtensions.cs ├── AttributeBasedMaps.cs ├── AutoMapper.UnitTests.csproj ├── AutoMapperSpecBase.cs ├── AutoMapperTester.cs ├── BasicFlattening.cs ├── BeforeAfterMapping.cs ├── BidirectionalRelationships.cs ├── BidirectionalRelationshipsWithoutPR.cs ├── Bug ├── AddingConfigurationForNonMatchingDestinationMemberBug.cs ├── AfterMapNestedObjects.cs ├── AllowNullCollectionsAssignableArray.cs ├── AllowNullDestinationValuesBugs.cs ├── AssertConfigurationIsValidNullables.cs ├── AssignableCollectionBug.cs ├── AutoMapperInheritanceProblemDemo.cs ├── BaseMapWithIncludesAndUnincludedMappings.cs ├── CannotConvertEnumToNullable.cs ├── CannotMapICollectionToAggregateSumDestination.cs ├── CannotProjectIEnumerableToAggregateDestinations.cs ├── CannotProjectStringToNullableEnum.cs ├── CaseSensitivityBug.cs ├── CollectionBaseClassGetConvention.cs ├── CollectionMapperMapsISetIncorrectly.cs ├── CollectionWhere.cs ├── CollectionsNullability.cs ├── ConditionBug.cs ├── ConstructUsingReturnsNull.cs ├── ConstructorParameterNamedType.cs ├── ContextValuesIncorrect.cs ├── ConvertMapperThreading.cs ├── CreateMapExpressionWithIgnoredPropertyBug.cs ├── CustomConverters.cs ├── CustomIEnumerableBug.cs ├── DeepCloningBug.cs ├── DeepInheritanceIssue.cs ├── DestinationCtorCalledTwice.cs ├── DestinationValueInitializedByCtorBug.cs ├── DuplicateExtensionMethods.cs ├── DuplicateValuesBug.cs ├── DuplicateValuesBugWithoutPR.cs ├── EFCollections.cs ├── EmptyNullSubstituteBug.cs ├── EnumCaseSensitivityBug.cs ├── EnumConditionsBug.cs ├── EnumMatchingOnValue.cs ├── ExistingArrays.cs ├── ForAllMembersAndDoNotUseDestinationValue.cs ├── GenericCreateMapWithCircularReferences.cs ├── GenericTypeConverter.cs ├── GuidTryExpression.cs ├── IgnoreAll.cs ├── IncludeBaseInheritance.cs ├── IncludeInheritance.cs ├── InitializeNRE.cs ├── IntToNullableDecimal.cs ├── InterfaceMultipleInheritance.cs ├── InterfaceSelfMappingBug.cs ├── InternalProperties.cs ├── JsonNet.cs ├── LazyCollectionMapping.cs ├── ListSourceMapperBug.cs ├── MapAtRuntime │ ├── BaseEntity.cs │ ├── BaseEntityDTO.cs │ ├── Entity1.cs │ ├── Entity10.cs │ ├── Entity11.cs │ ├── Entity12.cs │ ├── Entity13.cs │ ├── Entity14.cs │ ├── Entity15.cs │ ├── Entity16.cs │ ├── Entity17.cs │ ├── Entity18.cs │ ├── Entity19.cs │ ├── Entity2.cs │ ├── Entity20.cs │ ├── Entity21.cs │ ├── Entity22.cs │ ├── Entity23.cs │ ├── Entity24.cs │ ├── Entity25.cs │ ├── Entity26.cs │ ├── Entity3.cs │ ├── Entity4.cs │ ├── Entity5.cs │ ├── Entity6.cs │ ├── Entity7.cs │ ├── Entity8.cs │ ├── Entity9.cs │ ├── EntityDTO1.cs │ ├── EntityDTO10.cs │ ├── EntityDTO11.cs │ ├── EntityDTO12.cs │ ├── EntityDTO13.cs │ ├── EntityDTO14.cs │ ├── EntityDTO15.cs │ ├── EntityDTO16.cs │ ├── EntityDTO17.cs │ ├── EntityDTO18.cs │ ├── EntityDTO19.cs │ ├── EntityDTO2.cs │ ├── EntityDTO20.cs │ ├── EntityDTO21.cs │ ├── EntityDTO22.cs │ ├── EntityDTO23.cs │ ├── EntityDTO24.cs │ ├── EntityDTO25.cs │ ├── EntityDTO26.cs │ ├── EntityDTO3.cs │ ├── EntityDTO4.cs │ ├── EntityDTO5.cs │ ├── EntityDTO6.cs │ ├── EntityDTO7.cs │ ├── EntityDTO8.cs │ ├── EntityDTO9.cs │ └── MapAtRuntime.cs ├── MapAtRuntimeWithCollections │ ├── BaseEntity.cs │ ├── BaseEntityDTO.cs │ ├── Entity1.cs │ ├── Entity10.cs │ ├── Entity11.cs │ ├── Entity12.cs │ ├── Entity13.cs │ ├── Entity14.cs │ ├── Entity15.cs │ ├── Entity16.cs │ ├── Entity17.cs │ ├── Entity18.cs │ ├── Entity19.cs │ ├── Entity2.cs │ ├── Entity20.cs │ ├── Entity21.cs │ ├── Entity22.cs │ ├── Entity23.cs │ ├── Entity24.cs │ ├── Entity25.cs │ ├── Entity26.cs │ ├── Entity3.cs │ ├── Entity4.cs │ ├── Entity5.cs │ ├── Entity6.cs │ ├── Entity7.cs │ ├── Entity8.cs │ ├── Entity9.cs │ ├── EntityDTO1.cs │ ├── EntityDTO10.cs │ ├── EntityDTO11.cs │ ├── EntityDTO12.cs │ ├── EntityDTO13.cs │ ├── EntityDTO14.cs │ ├── EntityDTO15.cs │ ├── EntityDTO16.cs │ ├── EntityDTO17.cs │ ├── EntityDTO18.cs │ ├── EntityDTO19.cs │ ├── EntityDTO2.cs │ ├── EntityDTO20.cs │ ├── EntityDTO21.cs │ ├── EntityDTO22.cs │ ├── EntityDTO23.cs │ ├── EntityDTO24.cs │ ├── EntityDTO25.cs │ ├── EntityDTO26.cs │ ├── EntityDTO3.cs │ ├── EntityDTO4.cs │ ├── EntityDTO5.cs │ ├── EntityDTO6.cs │ ├── EntityDTO7.cs │ ├── EntityDTO8.cs │ ├── EntityDTO9.cs │ └── MapAtRuntimeWithCollections.cs ├── MapExpandoObjectProperty.cs ├── MapFromClosureBug.cs ├── MapOverloadsWithDynamic.cs ├── MappingInheritance.cs ├── MappingToAReadOnlyCollection.cs ├── MemberListSourceAndForPath.cs ├── MemberNamedTypeBug.cs ├── MissingMapping.cs ├── MultiThreadingIssues.cs ├── MultidimensionalArrays.cs ├── MultipleInterfaceInheritance.cs ├── MultipleTypeConverterInterfaces.cs ├── NamingConventions.cs ├── NestedMappingProjectionsExplicitExpanding.cs ├── NonExistingProperty.cs ├── NullArrayBug.cs ├── NullConstructorParameterName.cs ├── NullSubstituteInnerClass.cs ├── NullSubstituteType.cs ├── NullToString.cs ├── NullableBytesAndEnums.cs ├── NullableConverterBug.cs ├── NullableDateTime.cs ├── NullableEnumToNullableValueType.cs ├── NullableEnums.cs ├── NullableIntToNullableDecimal.cs ├── NullableIntToNullableEnum.cs ├── NullablePropertiesBug.cs ├── NullableResolveUsing.cs ├── NullableToInvalid.cs ├── NullableUntypedMapFrom.cs ├── ObjectEnumToObjectEnum.cs ├── ObjectTypeMapFailure.cs ├── OneSourceWithMultipleDestinationsAndPreserveReferences.cs ├── OneSourceWithMultipleDestinationsWithoutPR.cs ├── ParentChildResolversBug.cs ├── PreserveReferencesSameDestination.cs ├── ProjectCollectionsBug.cs ├── ProjectConstructorParameters.cs ├── ProjectUsingTheQueriedEntity.cs ├── PropertyNamedType.cs ├── ReadOnlyCollectionMappingBug.cs ├── ReadOnlyFieldMappingBug.cs ├── RecognizeDestinationPostfixes.cs ├── RecognizeIxesBug.cs ├── RemovePrefixes.cs ├── RepeatedMappingConfigurationTest.cs ├── ReportMissingInclude.cs ├── ReverseMapReplaceMemberName.cs ├── SelectiveConfigurationValidation.cs ├── SequenceContainsNoElementsTest.cs ├── SetterOnlyBug.cs ├── StructMapping.cs ├── SubclassMappings.cs ├── TargetISet.cs ├── TypeMapIncludeBaseTypes.cs ├── UseDestinationValue.cs └── WithoutPreserveReferencesSameDestination.cs ├── BuildExecutionPlan.cs ├── ClassDiagram1.cd ├── CollectionMapping.cs ├── ConditionalMapping.cs ├── ConfigCompilation.cs ├── ConfigurationFeatureTest.cs ├── ConfigurationRules.cs ├── ConfigurationValidation.cs ├── Constructors.cs ├── ContextItems.cs ├── CustomCollectionTester.cs ├── CustomMapping.cs ├── CustomValidations.cs ├── Dictionaries.cs ├── EnumToNullableEnum.cs ├── Enumerations.cs ├── ExplicitMapperCreation.cs ├── ExpressionBridge.cs ├── ExtensionMethods.cs ├── FillingExistingDestination.cs ├── ForAllMaps.cs ├── ForAllMembers.cs ├── ForPath.cs ├── General.cs ├── IMappingExpression ├── ForCtorParam.cs ├── IncludeMembers.cs ├── NonGenericConstructorTests.cs ├── NonGenericProjectEnumTest.cs ├── NonGenericResolveUsing.cs └── NonGenericReverseMapping.cs ├── IgnoreAllPropertiesWithAnInaccessibleSetterTests.cs ├── IgnoreAllTests.cs ├── Indexers.cs ├── InterfaceMapping.cs ├── Internal ├── CreateProxyThreading.cs ├── GenerateSimilarType.cs ├── MapperTests.cs ├── ObjectFactoryTests.cs ├── PrimitiveExtensionsTester.cs └── TypeMapFactorySpecs.cs ├── Internationalization.cs ├── MapToAttributeTest.cs ├── Mappers ├── ConstructorMapperTests.cs ├── ConversionOperators.cs ├── ConvertMapperTests.cs ├── CustomMapperTests.cs ├── DynamicMapperTests.cs ├── NameValueCollectionMapperTests.cs ├── ReadOnlyCollectionMapperTests.cs ├── ReadOnlyDictionaryMapperTests.cs ├── StringDictionaryMapperTests.cs └── TypeHelperTests.cs ├── MappingExceptions.cs ├── MappingExpressionFeatureWithReverseTest.cs ├── MappingExpressionFeatureWithoutReverseTest.cs ├── MappingInheritance ├── ApplyIncludeBaseRecursively.cs ├── ConventionMappedCollectionShouldMapBaseTypes.cs ├── IgnoreShouldBeInherited.cs ├── IgnoreShouldBeInheritedIfConventionCannotMap.cs ├── IncludeAllDerived.cs ├── IncludeBaseBug.cs ├── IncludeBaseShouldNotCreateMaps.cs ├── IncludeBaseShouldValidateTypes.cs ├── IncludeBaseWithNonGenericUsage.cs ├── IncludedBaseMappingShouldInheritBaseMappings.cs ├── IncludedMappingShouldInheritBaseMappings.cs ├── InheritanceWithoutIncludeShouldWork.cs ├── MapToBaseClass.cs ├── MultipleInheritedBaseMappingsOfSameTypeFails.cs ├── OpenGenericsWithInheritance.cs ├── OverrideIgnore.cs ├── PreserveReferencesWithInheritance.cs ├── PropertyOnMappingShouldResolveMostSpecificType.cs ├── ReverseMapWithInclude.cs ├── ShouldInheritBeforeAndAfterMap.cs ├── ShouldSupportOnlyDestinationTypeBeingDerived.cs └── SourceValidationWithInheritance.cs ├── MappingOrder.cs ├── MaxDepthTests.cs ├── MaxExecutionPlanDepth.cs ├── MemberNameReplacers.cs ├── MemberResolution.cs ├── NestedContainers.cs ├── NullBehavior.cs ├── OpenGenerics.cs ├── Profiles.cs ├── Projection ├── ConstructorTests.cs ├── ExplicitExpansion.cs ├── ExplicitExpansionWithInheritance.cs ├── ExplicitValues.cs ├── GenericsTests.cs ├── InheritedMaps.cs ├── MapFromTest.cs ├── MoreExplanatoryExceptionTests.cs ├── NestedAndArraysTests.cs ├── NestedExpressionsMapFromTests.cs ├── NonGenericQueryableTests.cs ├── NullSubstitutes.cs ├── ParameterizedQueriesTests.cs ├── PrimitiveArraysTest.cs ├── ProjectCollectionEnumerableTest.cs ├── ProjectCollectionListTest.cs ├── ProjectEnumTest.cs ├── ProjectEnumerableToArrayTest.cs ├── ProjectIReadOnlyCollection.cs ├── ProjectTest.cs ├── ProjectionMappers.cs ├── ProjectionTests.cs ├── RecursiveQuery.cs └── ToStringTests.cs ├── Regression.cs ├── ReverseMapWithPreserveReferences.cs ├── ReverseMapWithoutPreserveReferences.cs ├── ReverseMapping.cs ├── SeparateConfiguration.cs ├── ShouldMapMethod.cs ├── ShouldUseConstructor.cs ├── TesterExtensions.cs ├── TypeConverters.cs ├── TypeExtensionsTests.cs ├── UsingEngineInsideMap.cs ├── ValueConverters.cs ├── ValueTransformers.cs └── ValueTypes.cs /.gitattributes: -------------------------------------------------------------------------------- 1 | *.doc diff=astextplain 2 | *.DOC diff=astextplain 3 | *.docx diff=astextplain 4 | *.DOCX diff=astextplain 5 | *.dot diff=astextplain 6 | *.DOT diff=astextplain 7 | *.pdf diff=astextplain 8 | *.PDF diff=astextplain 9 | *.rtf diff=astextplain 10 | *.RTF diff=astextplain 11 | 12 | *.jpg binary 13 | *.png binary 14 | *.gif binary 15 | 16 | core.eol crlf 17 | 18 | *.cs diff=csharp 19 | 20 | *.csproj merge=union 21 | *.vbproj merge=union 22 | *.fsproj merge=union 23 | *.dbproj merge=union 24 | *.sln merge=union -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [jbogard, lbargaoanu] 4 | 5 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | permissions: 11 | contents: read 12 | concurrency: 13 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} 14 | cancel-in-progress: true 15 | jobs: 16 | build: 17 | strategy: 18 | fail-fast: false 19 | runs-on: windows-latest 20 | steps: 21 | - name: Checkout 22 | uses: actions/checkout@v2 23 | with: 24 | fetch-depth: 0 25 | - name: Install SQL Local DB 26 | run: ./Setup.ps1 27 | shell: pwsh 28 | - name: Build and Test 29 | run: ./Build.ps1 30 | shell: pwsh 31 | - name: Push to MyGet 32 | env: 33 | NUGET_URL: https://www.myget.org/F/automapperdev/api/v3/index.json 34 | NUGET_API_KEY: ${{ secrets.MYGET_CI_API_KEY }} 35 | run: ./Push.ps1 36 | shell: pwsh 37 | - name: Artifacts 38 | uses: actions/upload-artifact@v2 39 | with: 40 | name: artifacts 41 | path: artifacts/**/* -------------------------------------------------------------------------------- /.github/workflows/lock.yml: -------------------------------------------------------------------------------- 1 | name: 'Lock threads' 2 | 3 | on: 4 | schedule: 5 | - cron: '0 0 * * 0' 6 | 7 | permissions: 8 | contents: read 9 | 10 | jobs: 11 | lock: 12 | permissions: 13 | issues: write # for dessant/lock-threads to lock issues 14 | pull-requests: write # for dessant/lock-threads to lock PRs 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: dessant/lock-threads@v2 18 | with: 19 | github-token: ${{ github.token }} 20 | issue-lock-inactive-days: 31 21 | pr-lock-inactive-days: 31 22 | issue-lock-comment: > 23 | This issue has been automatically locked since there 24 | has not been any recent activity after it was closed. 25 | Please open a new issue for related bugs. 26 | pr-lock-comment: > 27 | This pull request has been automatically locked since there 28 | has not been any recent activity after it was closed. 29 | Please open a new issue for related bugs. 30 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*.*.*' 7 | permissions: 8 | contents: read 9 | 10 | jobs: 11 | build: 12 | strategy: 13 | fail-fast: false 14 | runs-on: windows-latest 15 | steps: 16 | - name: Checkout 17 | uses: actions/checkout@v2 18 | with: 19 | fetch-depth: 0 20 | - name: Install SQL Local DB 21 | run: ./Setup.ps1 22 | shell: pwsh 23 | - name: Build and Test 24 | run: ./Build.ps1 25 | shell: pwsh 26 | - name: Push to MyGet 27 | env: 28 | NUGET_URL: https://www.myget.org/F/automapperdev/api/v3/index.json 29 | NUGET_API_KEY: ${{ secrets.MYGET_CI_API_KEY }} 30 | run: ./Push.ps1 31 | shell: pwsh 32 | - name: Push to NuGet 33 | env: 34 | NUGET_URL: https://api.nuget.org/v3/index.json 35 | NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} 36 | run: ./Push.ps1 37 | shell: pwsh 38 | - name: Artifacts 39 | uses: actions/upload-artifact@v2 40 | with: 41 | name: artifacts 42 | path: artifacts/**/* -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | release/ 3 | scripts/ 4 | artifacts/ 5 | .dotnet 6 | TestResults/ 7 | *.suo 8 | *.user 9 | bin 10 | Bin 11 | obj 12 | _ReSharper* 13 | *.csproj.user 14 | *.resharper.user 15 | *.suo 16 | *.cache 17 | TestResult.xml 18 | AppPackages/ 19 | *.bak 20 | packages 21 | *.orig 22 | *.DotSettings 23 | *.ide/ 24 | .nuget 25 | project.lock.json 26 | .vs 27 | 28 | # JetBrains Rider 29 | .idea/ 30 | *.sln.iml 31 | 32 | # Read the Docs 33 | docs/_build 34 | /src/LastMajorVersionBinary 35 | *.diagsession 36 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | 3 | build: 4 | os: "ubuntu-22.04" 5 | tools: 6 | python: "3.10" 7 | 8 | python: 9 | install: 10 | - requirements: docs/requirements.txt 11 | 12 | sphinx: 13 | configuration: docs/source/conf.py -------------------------------------------------------------------------------- /AutoMapper.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sulhan12/AutoMapper/2314ed6c64b1538f542859dfc1a50a91e3504452/AutoMapper.snk -------------------------------------------------------------------------------- /Build.ps1: -------------------------------------------------------------------------------- 1 | # Taken from psake https://github.com/psake/psake 2 | 3 | <# 4 | .SYNOPSIS 5 | This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode 6 | to see if an error occcured. If an error is detected then an exception is thrown. 7 | This function allows you to run command-line programs without having to 8 | explicitly check the $lastexitcode variable. 9 | .EXAMPLE 10 | exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed" 11 | #> 12 | function Exec 13 | { 14 | [CmdletBinding()] 15 | param( 16 | [Parameter(Position=0,Mandatory=1)][scriptblock]$cmd, 17 | [Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd) 18 | ) 19 | & $cmd 20 | if ($lastexitcode -ne 0) { 21 | throw ("Exec: " + $errorMessage) 22 | } 23 | } 24 | 25 | $artifacts = ".\artifacts" 26 | 27 | if(Test-Path $artifacts) { Remove-Item $artifacts -Force -Recurse } 28 | 29 | exec { & dotnet test -c Release --results-directory $artifacts -l trx } 30 | 31 | exec { & dotnet pack .\src\AutoMapper\AutoMapper.csproj -c Release -o $artifacts --no-build } 32 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Jimmy Bogard 5 | latest 6 | $(NoWarn);CS1701;CS1702;CS1591 7 | true 8 | strict 9 | enable 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2010 Jimmy Bogard 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /Push.ps1: -------------------------------------------------------------------------------- 1 | $scriptName = $MyInvocation.MyCommand.Name 2 | $artifacts = "./artifacts" 3 | 4 | if ([string]::IsNullOrEmpty($Env:NUGET_API_KEY)) { 5 | Write-Host "${scriptName}: NUGET_API_KEY is empty or not set. Skipped pushing package(s)." 6 | } else { 7 | Get-ChildItem $artifacts -Filter "*.nupkg" | ForEach-Object { 8 | Write-Host "$($scriptName): Pushing $($_.Name)" 9 | dotnet nuget push $_ --source $Env:NUGET_URL --api-key $Env:NUGET_API_KEY 10 | if ($lastexitcode -ne 0) { 11 | throw ("Exec: " + $errorMessage) 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Setup.ps1: -------------------------------------------------------------------------------- 1 | # Taken from psake https://github.com/psake/psake 2 | 3 | <# 4 | .SYNOPSIS 5 | This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode 6 | to see if an error occcured. If an error is detected then an exception is thrown. 7 | This function allows you to run command-line programs without having to 8 | explicitly check the $lastexitcode variable. 9 | .EXAMPLE 10 | exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed" 11 | #> 12 | function Exec 13 | { 14 | [CmdletBinding()] 15 | param( 16 | [Parameter(Position=0,Mandatory=1)][scriptblock]$cmd, 17 | [Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd) 18 | ) 19 | & $cmd 20 | if ($lastexitcode -ne 0) { 21 | throw ("Exec: " + $errorMessage) 22 | } 23 | } 24 | 25 | Write-Host "Downloading" 26 | Import-Module BitsTransfer 27 | Start-BitsTransfer -Source https://download.microsoft.com/download/7/c/1/7c14e92e-bdcb-4f89-b7cf-93543e7112d1/SqlLocalDB.msi -Destination SqlLocalDB.msi 28 | Write-Host "Installing" 29 | Start-Process -FilePath "SqlLocalDB.msi" -Wait -ArgumentList "/qn", "/norestart", "/l*v SqlLocalDBInstall.log", "IACCEPTSQLLOCALDBLICENSETERMS=YES"; 30 | <# 31 | Write-Host "Checking" 32 | sqlcmd -l 60 -S "(localdb)\MSSQLLocalDB" -Q "SELECT @@VERSION;" 33 | #> 34 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx==7.1.2 2 | sphinx-rtd-theme==1.3.0rc1 3 | myst_parser==2.0.0 -------------------------------------------------------------------------------- /docs/source/13.0-Upgrade-Guide.md: -------------------------------------------------------------------------------- 1 | # 13.0 Upgrade Guide 2 | 3 | [Release notes](https://github.com/AutoMapper/AutoMapper/releases/tag/v13.0.0). 4 | 5 | ## AutoMapper now targets .Net 6 6 | 7 | ## `AddAutoMapper` is part of the core package and the DI package is discontinued 8 | 9 | ## `AllowAdditiveTypeMapCreation` was removed 10 | 11 | Be sure to call `CreateMap` once for a source type, destination type pair. If you want to reuse configuration, use mapping inheritance. 12 | 13 | ## ProjectTo runtime polymorphic mapping with Include/IncludeBase 14 | 15 | We consider this an off the beaten path feature and we don't expose it through `CreateProjection`. You can use [an extension method](https://github.com/AutoMapper/AutoMapper/search?l=C%23&q=Advanced) or `CreateMap`. 16 | 17 | ## `Context.State` similar to `Context.Items` 18 | 19 | The same pattern the framework uses to pass state to delegates. Note that `State` and `Items` are mutually exclusive per `Map` call. 20 | 21 | ## Custom Equals/GetHashCode for source objects 22 | 23 | To avoid broken implementations, we no longer call those when checking for identical source objects, we hard code to checking object references. 24 | -------------------------------------------------------------------------------- /docs/source/8.1.1-Upgrade-Guide.md: -------------------------------------------------------------------------------- 1 | # 8.1.1 Upgrade Guide 2 | 3 | The purpose of this release is to allow you to upgrade to 9.0 gradually. 4 | 5 | ## AutoMapper no longer creates maps automatically by default 6 | 7 | `CreateMissingTypeMaps` was deprecated and its default value changed to `false`. If you were relying on this, your app will no longer work by default. 8 | 9 | If you're not interested in upgrading to 9.0, where dynamic mapping was removed, you should stick with 8.1. 10 | 11 | Otherwise you can port your app gradually to 9.0 by creating the needed maps. Setting `CreateMissingTypeMaps` to `false` will get you the 9.0 behavior and setting it to `true` will revert to the 8.1 behavior. 12 | -------------------------------------------------------------------------------- /docs/source/9.0-Upgrade-Guide.md: -------------------------------------------------------------------------------- 1 | # 9.0 Upgrade Guide 2 | 3 | ## The static API was removed 4 | 5 | Switch to the instance based API, preferably using dependency injection. 6 | See [here](Setup.html) and [here](Dependency-injection.html). 7 | 8 | ## AutoMapper no longer creates maps automatically (CreateMissingTypeMaps and conventions) 9 | 10 | You will need to explicitly configure maps, manually or using reflection. Also consider [attribute mapping](Attribute-mapping.html). -------------------------------------------------------------------------------- /docs/source/API-Changes.md: -------------------------------------------------------------------------------- 1 | # API Changes 2 | 3 | Starting with version 9.0, you can find out [what changed](https://raw.githubusercontent.com/AutoMapper/AutoMapper/master/src/AutoMapper/ApiCompatBaseline.txt) in the public API from the last major version release. 4 | From the [releases page](https://github.com/AutoMapper/AutoMapper/releases) you can reach the source code for that release and the version of ApiCompatBaseline.txt in that tree will tell you what changed. 5 | A major version release is compared with the previous major version release (so 9.0.0 with 8.0.0) and a minor version release with the current major version release (so 9.1.1 with 9.0.0). -------------------------------------------------------------------------------- /docs/source/Dynamic-and-ExpandoObject-Mapping.md: -------------------------------------------------------------------------------- 1 | # Dynamic and ExpandoObject Mapping 2 | 3 | AutoMapper can map to/from dynamic objects without any explicit configuration: 4 | 5 | ```c# 6 | public class Foo { 7 | public int Bar { get; set; } 8 | public int Baz { get; set; } 9 | public Foo InnerFoo { get; set; } 10 | } 11 | dynamic foo = new MyDynamicObject(); 12 | foo.Bar = 5; 13 | foo.Baz = 6; 14 | 15 | var configuration = new MapperConfiguration(cfg => {}); 16 | 17 | var result = mapper.Map(foo); 18 | result.Bar.ShouldEqual(5); 19 | result.Baz.ShouldEqual(6); 20 | 21 | dynamic foo2 = mapper.Map(result); 22 | foo2.Bar.ShouldEqual(5); 23 | foo2.Baz.ShouldEqual(6); 24 | ``` 25 | 26 | Similarly you can map straight from `Dictionary` to objects, AutoMapper will line up the keys with property names. 27 | For mapping to destination child objects, you can use the dot notation. 28 | ```c# 29 | var result = mapper.Map(new Dictionary { ["InnerFoo.Bar"] = 42 }); 30 | result.InnerFoo.Bar.ShouldEqual(42); 31 | ``` -------------------------------------------------------------------------------- /docs/source/Null-substitution.md: -------------------------------------------------------------------------------- 1 | # Null Substitution 2 | 3 | Null substitution allows you to supply an alternate value for a destination member if the source value is null anywhere along the member chain. This means that instead of mapping from null, it will map from the value you supply. 4 | 5 | ```c# 6 | var config = new MapperConfiguration(cfg => cfg.CreateMap() 7 | .ForMember(destination => destination.Value, opt => opt.NullSubstitute("Other Value"))); 8 | 9 | var source = new Source { Value = null }; 10 | var mapper = config.CreateMapper(); 11 | var dest = mapper.Map(source); 12 | 13 | dest.Value.ShouldEqual("Other Value"); 14 | 15 | source.Value = "Not null"; 16 | 17 | dest = mapper.Map(source); 18 | 19 | dest.Value.ShouldEqual("Not null"); 20 | ``` 21 | 22 | The substitute is assumed to be of the source member type, and will go through any mapping/conversion after to the destination type. 23 | -------------------------------------------------------------------------------- /docs/source/The-MyGet-build.md: -------------------------------------------------------------------------------- 1 | # The MyGet Build 2 | 3 | AutoMapper uses MyGet to publish development builds based on the master branch. This means that the MyGet build sometimes contains fixes that are not available in the current NuGet package. Please try the latest MyGet build before reporting issues, in case your issue has already been fixed but not released. 4 | 5 | The AutoMapper MyGet gallery is available [here](https://myget.org/feed/automapperdev/package/nuget/AutoMapper). Be sure to include prereleases. 6 | 7 | ## Installing the Package 8 | 9 | If you want to install the latest MyGet package into a project, you can use the following command: 10 | 11 | ``` 12 | Install-Package AutoMapper -Source https://www.myget.org/F/automapperdev/api/v3/index.json -IncludePrerelease 13 | ``` 14 | -------------------------------------------------------------------------------- /docs/source/Understanding-your-mapping.md: -------------------------------------------------------------------------------- 1 | # Understanding Your Mappings 2 | 3 | AutoMapper creates an execution plan for your mapping. That execution plan can be viewed as [an expression tree](https://msdn.microsoft.com/en-us/library/mt654263.aspx?f=255&MSPPError=-2147217396) during debugging. You can get a better view of the resulting code by installing [the ReadableExpressions VS extension](https://marketplace.visualstudio.com/items?itemName=vs-publisher-1232914.ReadableExpressionsVisualizers). If you need to see the code outside VS, you can use [the ReadableExpressions package directly](https://www.nuget.org/packages/AgileObjects.ReadableExpressions). [This DotNetFiddle](https://dotnetfiddle.net/aJYTGZ) has a live demo using the NuGet package, and [this article](https://agileobjects.co.uk/view-automapper-execution-plan-readableexpressions) describes using the VS extension. 4 | 5 | ```c# 6 | var configuration = new MapperConfiguration(cfg => cfg.CreateMap()); 7 | var executionPlan = configuration.BuildExecutionPlan(typeof(Foo), typeof(Bar)); 8 | ``` 9 | 10 | Be sure to remove all such code before release. 11 | 12 | For ProjectTo, you need to inspect `IQueryable.Expression`. 13 | 14 | ```c# 15 | var expression = context.Entities.ProjectTo().Expression; 16 | ``` 17 | -------------------------------------------------------------------------------- /docs/source/Value-transformers.md: -------------------------------------------------------------------------------- 1 | # Value Transformers 2 | 3 | Value transformers apply an additional transformation to a single type. Before assigning the value, AutoMapper will check to see if the value to be set has any value transformations associated, and will apply them before setting. 4 | 5 | You can create value transformers at several different levels: 6 | 7 | - Globally 8 | - Profile 9 | - Map 10 | - Member 11 | 12 | ```c# 13 | var configuration = new MapperConfiguration(cfg => { 14 | cfg.ValueTransformers.Add(val => val + "!!!"); 15 | }); 16 | 17 | var source = new Source { Value = "Hello" }; 18 | var dest = mapper.Map(source); 19 | 20 | dest.Value.ShouldBe("Hello!!!"); 21 | ``` 22 | -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | 3 | # -- Project information 4 | 5 | project = 'AutoMapper' 6 | copyright = '2024, Jimmy Bogard' 7 | author = 'Jimmy Bogard' 8 | 9 | # -- General configuration 10 | 11 | extensions = [ 12 | 'sphinx.ext.duration', 13 | 'sphinx.ext.doctest', 14 | 'sphinx.ext.autodoc', 15 | 'sphinx.ext.autosummary', 16 | 'sphinx.ext.intersphinx', 17 | 'myst_parser' 18 | ] 19 | 20 | intersphinx_mapping = { 21 | 'python': ('https://docs.python.org/3/', None), 22 | 'sphinx': ('https://www.sphinx-doc.org/en/master/', None), 23 | } 24 | intersphinx_disabled_domains = ['std'] 25 | 26 | templates_path = ['_templates'] 27 | 28 | # -- Options for HTML output 29 | 30 | html_theme = 'sphinx_rtd_theme' 31 | html_theme_options = { 32 | 'logo_only': True, 33 | 'display_version': False 34 | } 35 | html_logo = 'img/logo.png' 36 | 37 | 38 | # -- Options for EPUB output 39 | epub_show_urls = 'footnote' -------------------------------------------------------------------------------- /docs/source/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sulhan12/AutoMapper/2314ed6c64b1538f542859dfc1a50a91e3504452/docs/source/img/logo.png -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sulhan12/AutoMapper/2314ed6c64b1538f542859dfc1a50a91e3504452/icon.png -------------------------------------------------------------------------------- /nuget.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /nuget.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sulhan12/AutoMapper/2314ed6c64b1538f542859dfc1a50a91e3504452/nuget.exe -------------------------------------------------------------------------------- /src/AutoMapper.DI.Tests/AppDomainResolutionTests.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | 3 | namespace AutoMapper.Extensions.Microsoft.DependencyInjection.Tests 4 | { 5 | using System; 6 | using AutoMapper.Internal; 7 | using Shouldly; 8 | using Xunit; 9 | 10 | public class AppDomainResolutionTests 11 | { 12 | private readonly IServiceProvider _provider; 13 | 14 | public AppDomainResolutionTests() 15 | { 16 | IServiceCollection services = new ServiceCollection(); 17 | services.AddAutoMapper(typeof(AppDomainResolutionTests)); 18 | _provider = services.BuildServiceProvider(); 19 | } 20 | 21 | [Fact] 22 | public void ShouldResolveConfiguration() 23 | { 24 | _provider.GetService().ShouldNotBeNull(); 25 | } 26 | 27 | [Fact] 28 | public void ShouldConfigureProfiles() 29 | { 30 | _provider.GetService().Internal().GetAllTypeMaps().Count.ShouldBe(4); 31 | } 32 | 33 | [Fact] 34 | public void ShouldResolveMapper() 35 | { 36 | _provider.GetService().ShouldNotBeNull(); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /src/AutoMapper.DI.Tests/AttributeTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using Shouldly; 4 | using Xunit; 5 | 6 | namespace AutoMapper.Extensions.Microsoft.DependencyInjection.Tests 7 | { 8 | public class AttributeTests 9 | { 10 | [Fact] 11 | public void Should_not_register_static_instance_when_configured() 12 | { 13 | IServiceCollection services = new ServiceCollection(); 14 | services.AddAutoMapper(typeof(Source3)); 15 | 16 | var serviceProvider = services.BuildServiceProvider(); 17 | 18 | var mapper = serviceProvider.GetService(); 19 | 20 | var source = new Source3 {Value = 3}; 21 | 22 | var dest = mapper.Map(source); 23 | 24 | dest.Value.ShouldBe(source.Value); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /src/AutoMapper.DI.Tests/AutoMapper.DI.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | true 6 | AutoMapper.Extensions.Microsoft.DependencyInjection.Tests 7 | AutoMapper.Extensions.Microsoft.DependencyInjection.Tests 8 | true 9 | false 10 | false 11 | false 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/AutoMapper.DI.Tests/DependencyTests.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Extensions.Microsoft.DependencyInjection.Tests 2 | { 3 | using System; 4 | using global::Microsoft.Extensions.DependencyInjection; 5 | using Shouldly; 6 | using Xunit; 7 | 8 | public class DependencyTests 9 | { 10 | private readonly IServiceProvider _provider; 11 | 12 | public DependencyTests() 13 | { 14 | IServiceCollection services = new ServiceCollection(); 15 | services.AddTransient(sp => new FooService(5)); 16 | services.AddAutoMapper(typeof(Source), typeof(Profile)); 17 | _provider = services.BuildServiceProvider(); 18 | 19 | _provider.GetService().AssertConfigurationIsValid(); 20 | } 21 | 22 | [Fact] 23 | public void ShouldResolveWithDependency() 24 | { 25 | var mapper = _provider.GetService(); 26 | var dest = mapper.Map(new Source2()); 27 | 28 | dest.ResolvedValue.ShouldBe(5); 29 | } 30 | 31 | [Fact] 32 | public void ShouldConvertWithDependency() 33 | { 34 | var mapper = _provider.GetService(); 35 | var dest = mapper.Map(new Source2 { ConvertedValue = 5}); 36 | 37 | dest.ConvertedValue.ShouldBe(10); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/AutoMapper.DI.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 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: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AutoMapper.Extensions.Microsoft.DependencyInjection.Tests")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("a93a7f85-292a-4130-891d-4307d3f60c30")] 20 | 21 | [assembly: Xunit.CollectionBehavior(DisableTestParallelization = true)] 22 | -------------------------------------------------------------------------------- /src/AutoMapper/ApiCompat/PreBuild.ps1: -------------------------------------------------------------------------------- 1 | param([string]$version) 2 | echo $version 3 | $versionNumbers = $version.Split(".") 4 | if($versionNumbers[1] -eq "0" -AND $versionNumbers[2] -eq "0") 5 | { 6 | $oldVersion = $versionNumbers[0] - 1 7 | }else{ 8 | $oldVersion = $versionNumbers[0] 9 | } 10 | $oldVersion = $oldVersion.ToString() +".0.0" 11 | echo $oldVersion 12 | & ..\..\nuget install AutoMapper -Version $oldVersion -OutputDirectory ..\LastMajorVersionBinary 13 | & copy ..\LastMajorVersionBinary\AutoMapper.$oldVersion\lib\net6.0\AutoMapper.dll ..\LastMajorVersionBinary 14 | -------------------------------------------------------------------------------- /src/AutoMapper/ApiCompat/PreBuild.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | version=$1 3 | echo $version 4 | readarray -d . -t versionNumbers <<< $version 5 | if [[ ${versionNumbers[1]} -eq "0" && ${versionNumbers[2]} -eq "0" ]] 6 | then 7 | oldVersion=$(({versionNumbers[0]} - 1)) 8 | else 9 | oldVersion=${versionNumbers[0]} 10 | fi 11 | oldVersion="$oldVersion.0.0" 12 | echo $oldVersion 13 | rm -rf ../LastMajorVersionBinary 14 | curl https://globalcdn.nuget.org/packages/automapper.$oldVersion.nupkg --create-dirs -o ../LastMajorVersionBinary/automapper.$oldVersion.nupkg 15 | unzip -j ../LastMajorVersionBinary/automapper.$oldVersion.nupkg lib/netstandard2.1/AutoMapper.dll -d ../LastMajorVersionBinary 16 | -------------------------------------------------------------------------------- /src/AutoMapper/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Resources; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: CLSCompliant(true)] 5 | [assembly: ComVisible(false)] 6 | [assembly: NeutralResourcesLanguage("en")] 7 | 8 | namespace System.Runtime.CompilerServices; 9 | 10 | static class IsExternalInit { } -------------------------------------------------------------------------------- /src/AutoMapper/Configuration/Annotations/IMemberConfigurationProvider.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Configuration; 2 | 3 | public interface IMemberConfigurationProvider 4 | { 5 | void ApplyConfiguration(IMemberConfigurationExpression memberConfigurationExpression); 6 | } -------------------------------------------------------------------------------- /src/AutoMapper/Configuration/Annotations/IgnoreAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Configuration.Annotations; 2 | 3 | /// 4 | /// Ignore this member for configuration validation and skip during mapping. 5 | /// 6 | /// 7 | /// Must be used in combination with 8 | /// 9 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] 10 | public sealed class IgnoreAttribute : Attribute, IMemberConfigurationProvider 11 | { 12 | public void ApplyConfiguration(IMemberConfigurationExpression memberConfigurationExpression) 13 | { 14 | memberConfigurationExpression.Ignore(); 15 | } 16 | } -------------------------------------------------------------------------------- /src/AutoMapper/Configuration/Annotations/MapAtRuntimeAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Configuration.Annotations; 2 | 3 | /// 4 | /// Do not precompute the execution plan for this member, just map it at runtime. 5 | /// Simplifies the execution plan by not inlining. 6 | /// 7 | /// 8 | /// Must be used in combination with 9 | /// 10 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] 11 | public sealed class MapAtRuntimeAttribute : Attribute, IMemberConfigurationProvider 12 | { 13 | public void ApplyConfiguration(IMemberConfigurationExpression memberConfigurationExpression) 14 | { 15 | memberConfigurationExpression.MapAtRuntime(); 16 | } 17 | } -------------------------------------------------------------------------------- /src/AutoMapper/Configuration/Annotations/MappingOrderAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Configuration.Annotations; 2 | 3 | /// 4 | /// Supply a custom mapping order instead of what the .NET runtime returns 5 | /// 6 | /// 7 | /// Must be used in combination with 8 | /// 9 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] 10 | public sealed class MappingOrderAttribute(int value) : Attribute, IMemberConfigurationProvider 11 | { 12 | public int Value { get; } = value; 13 | 14 | public void ApplyConfiguration(IMemberConfigurationExpression memberConfigurationExpression) 15 | { 16 | memberConfigurationExpression.SetMappingOrder(Value); 17 | } 18 | } -------------------------------------------------------------------------------- /src/AutoMapper/Configuration/Annotations/NullSubstituteAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Configuration.Annotations; 2 | 3 | /// 4 | /// Substitute a custom value when the source member resolves as null 5 | /// 6 | /// 7 | /// Must be used in combination with 8 | /// 9 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] 10 | public sealed class NullSubstituteAttribute(object value) : Attribute, IMemberConfigurationProvider 11 | { 12 | /// 13 | /// Value to use if source value is null 14 | /// 15 | public object Value { get; } = value; 16 | 17 | public void ApplyConfiguration(IMemberConfigurationExpression memberConfigurationExpression) 18 | { 19 | memberConfigurationExpression.NullSubstitute(Value); 20 | } 21 | } -------------------------------------------------------------------------------- /src/AutoMapper/Configuration/Annotations/SourceMemberAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Configuration.Annotations; 2 | 3 | /// 4 | /// Specify the source member to map from. Can only reference a member on the type 5 | /// 6 | /// 7 | /// Must be used in combination with 8 | /// 9 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] 10 | public sealed class SourceMemberAttribute(string name) : Attribute, IMemberConfigurationProvider 11 | { 12 | public string Name { get; } = name; 13 | 14 | public void ApplyConfiguration(IMemberConfigurationExpression memberConfigurationExpression) 15 | { 16 | var destinationMember = memberConfigurationExpression.DestinationMember; 17 | if (destinationMember.Has() || destinationMember.Has()) 18 | { 19 | return; 20 | } 21 | memberConfigurationExpression.MapFrom(Name); 22 | } 23 | } -------------------------------------------------------------------------------- /src/AutoMapper/Configuration/Annotations/UseExistingValueAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Configuration.Annotations; 2 | 3 | /// 4 | /// Use the destination value instead of mapping from the source value or creating a new instance 5 | /// 6 | /// 7 | /// Must be used in combination with 8 | /// 9 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] 10 | public sealed class UseExistingValueAttribute : Attribute, IMemberConfigurationProvider 11 | { 12 | public void ApplyConfiguration(IMemberConfigurationExpression memberConfigurationExpression) 13 | { 14 | memberConfigurationExpression.UseDestinationValue(); 15 | } 16 | } -------------------------------------------------------------------------------- /src/AutoMapper/Configuration/Annotations/ValueConverterAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Configuration.Annotations; 2 | 3 | /// 4 | /// Specify a value converter type to convert from the matching source member to the destination member 5 | /// Use with to specify a separate source member to supply to the value converter 6 | /// 7 | /// 8 | /// Must be used in combination with 9 | /// 10 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] 11 | public sealed class ValueConverterAttribute(Type type) : Attribute, IMemberConfigurationProvider 12 | { 13 | /// 14 | /// type 15 | /// 16 | public Type Type { get; } = type; 17 | 18 | public void ApplyConfiguration(IMemberConfigurationExpression memberConfigurationExpression) 19 | { 20 | var sourceMemberAttribute = memberConfigurationExpression.DestinationMember.GetCustomAttribute(); 21 | 22 | if (sourceMemberAttribute != null) 23 | { 24 | memberConfigurationExpression.ConvertUsing(Type, sourceMemberAttribute.Name); 25 | } 26 | else 27 | { 28 | memberConfigurationExpression.ConvertUsing(Type); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/AutoMapper/Internal/LockingConcurrentDictionary.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | namespace AutoMapper.Internal; 3 | public readonly struct LockingConcurrentDictionary(Func valueFactory, int capacity = 31) 4 | { 5 | private readonly Func> _valueFactory = key => new(() => valueFactory(key)); 6 | private readonly ConcurrentDictionary> _dictionary = new(Environment.ProcessorCount, capacity); 7 | public TValue GetOrAdd(in TKey key) => _dictionary.GetOrAdd(key, _valueFactory).Value; 8 | public bool IsDefault => _dictionary == null; 9 | } -------------------------------------------------------------------------------- /src/AutoMapper/Internal/MemberPath.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Internal; 2 | [EditorBrowsable(EditorBrowsableState.Never)] 3 | public readonly record struct MemberPath(MemberInfo[] Members) 4 | { 5 | public static readonly MemberPath Empty = new(Members: []); 6 | public MemberPath(Stack members) : this(members.ToMemberInfos()){} 7 | public MemberInfo Last => Members[^1]; 8 | public MemberInfo First => Members[0]; 9 | public int Length => Members.Length; 10 | public bool Equals(MemberPath other) => Members.SequenceEqual(other.Members); 11 | public override int GetHashCode() 12 | { 13 | HashCode hashCode = new(); 14 | foreach(var member in Members) 15 | { 16 | hashCode.Add(member); 17 | } 18 | return hashCode.ToHashCode(); 19 | } 20 | public override string ToString() => string.Join(".", Members.Select(mi => mi.Name)); 21 | public bool StartsWith(MemberPath path) 22 | { 23 | if (path.Length > Length) 24 | { 25 | return false; 26 | } 27 | for (int index = 0; index < path.Length; index++) 28 | { 29 | if (Members[index] != path.Members[index]) 30 | { 31 | return false; 32 | } 33 | } 34 | return true; 35 | } 36 | public MemberPath Concat(IEnumerable memberInfos) => new([..Members.Concat(memberInfos)]); 37 | } -------------------------------------------------------------------------------- /src/AutoMapper/Mappers/AssignableMapper.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Internal.Mappers; 2 | 3 | public class AssignableMapper : IObjectMapper 4 | { 5 | public bool IsMatch(TypePair context) => context.DestinationType.IsAssignableFrom(context.SourceType); 6 | public Expression MapExpression(IGlobalConfiguration configuration, ProfileMap profileMap, 7 | MemberMap memberMap, Expression sourceExpression, Expression destExpression) => sourceExpression; 8 | } -------------------------------------------------------------------------------- /src/AutoMapper/Mappers/ConstructorMapper.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Internal.Mappers; 2 | public class ConstructorMapper : IObjectMapper 3 | { 4 | public bool IsMatch(TypePair context) => GetConstructor(context.SourceType, context.DestinationType) != null; 5 | private static ConstructorInfo GetConstructor(Type sourceType, Type destinationType) => 6 | destinationType.GetConstructor(TypeExtensions.InstanceFlags, null, [sourceType], null); 7 | public Expression MapExpression(IGlobalConfiguration configuration, ProfileMap profileMap, MemberMap memberMap, Expression sourceExpression, Expression destExpression) 8 | { 9 | var constructor = GetConstructor(sourceExpression.Type, destExpression.Type); 10 | return New(constructor, ToType(sourceExpression, constructor.FirstParameterType())); 11 | } 12 | } -------------------------------------------------------------------------------- /src/AutoMapper/Mappers/ConversionOperatorMapper.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Internal.Mappers; 2 | public class ConversionOperatorMapper : IObjectMapper 3 | { 4 | private readonly string _operatorName; 5 | public ConversionOperatorMapper(string operatorName) => _operatorName = operatorName; 6 | public bool IsMatch(TypePair context) => GetConversionOperator(context.SourceType, context.DestinationType) != null; 7 | private MethodInfo GetConversionOperator(Type sourceType, Type destinationType) 8 | { 9 | foreach (MethodInfo sourceMethod in sourceType.GetMember(_operatorName, MemberTypes.Method, BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy)) 10 | { 11 | if (destinationType.IsAssignableFrom(sourceMethod.ReturnType)) 12 | { 13 | return sourceMethod; 14 | } 15 | } 16 | return destinationType.GetMethod(_operatorName, TypeExtensions.StaticFlags, null, [sourceType], null); 17 | } 18 | public Expression MapExpression(IGlobalConfiguration configuration, ProfileMap profileMap, MemberMap memberMap, Expression sourceExpression, Expression destExpression) 19 | { 20 | var conversionOperator = GetConversionOperator(sourceExpression.Type, destExpression.Type); 21 | return Call(conversionOperator, ToType(sourceExpression, conversionOperator.FirstParameterType())); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/AutoMapper/Mappers/ConvertMapper.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Internal.Mappers; 2 | public class ConvertMapper : IObjectMapper 3 | { 4 | public static bool IsPrimitive(Type type) => type.IsPrimitive || type == typeof(string) || type == typeof(decimal); 5 | public bool IsMatch(TypePair types) => (types.SourceType == typeof(string) && types.DestinationType == typeof(DateTime)) || 6 | (IsPrimitive(types.SourceType) && IsPrimitive(types.DestinationType)); 7 | public Expression MapExpression(IGlobalConfiguration configuration, ProfileMap profileMap, 8 | MemberMap memberMap, Expression sourceExpression, Expression destExpression) 9 | { 10 | var convertMethod = typeof(Convert).GetMethod("To" + destExpression.Type.Name, [sourceExpression.Type]); 11 | return Call(convertMethod, sourceExpression); 12 | } 13 | } -------------------------------------------------------------------------------- /src/AutoMapper/Mappers/EnumToEnumMapper.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Internal.Mappers; 2 | public class EnumToEnumMapper : IObjectMapper 3 | { 4 | private static readonly MethodInfo TryParseMethod = typeof(Enum).StaticGenericMethod("TryParse", parametersCount: 3); 5 | public bool IsMatch(TypePair context) => context.IsEnumToEnum(); 6 | public Expression MapExpression(IGlobalConfiguration configuration, ProfileMap profileMap, 7 | MemberMap memberMap, Expression sourceExpression, Expression destExpression) 8 | { 9 | var destinationType = destExpression.Type; 10 | var sourceToString = Call(sourceExpression, ObjectToString); 11 | var result = Variable(destinationType, "destinationEnumValue"); 12 | var ignoreCase = True; 13 | var tryParse = Call(TryParseMethod.MakeGenericMethod(destinationType), sourceToString, ignoreCase, result); 14 | var (variables, statements) = configuration.Scratchpad(); 15 | variables.Add(result); 16 | statements.Add(Condition(tryParse, result, Convert(sourceExpression, destinationType))); 17 | return Block(variables, statements); 18 | } 19 | } -------------------------------------------------------------------------------- /src/AutoMapper/Mappers/KeyValueMapper.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Internal.Mappers; 2 | public class KeyValueMapper : IObjectMapper 3 | { 4 | public bool IsMatch(TypePair context) => IsKeyValue(context.SourceType) && IsKeyValue(context.DestinationType); 5 | public static bool IsKeyValue(Type type) => type.IsGenericType(typeof(KeyValuePair<,>)); 6 | public Expression MapExpression(IGlobalConfiguration configuration, ProfileMap profileMap, MemberMap memberMap, Expression sourceExpression, Expression destExpression) 7 | { 8 | var sourceArguments = sourceExpression.Type.GenericTypeArguments; 9 | var destinationType = destExpression.Type; 10 | var destinationArguments = destinationType.GenericTypeArguments; 11 | TypePair keys = new(sourceArguments[0], destinationArguments[0]); 12 | TypePair values = new(sourceArguments[1], destinationArguments[1]); 13 | var mapKeys = configuration.MapExpression(profileMap, keys, ExpressionBuilder.Property(sourceExpression, "Key")); 14 | var mapValues = configuration.MapExpression(profileMap, values, ExpressionBuilder.Property(sourceExpression, "Value")); 15 | return New(destinationType.GetConstructor(destinationArguments), mapKeys, mapValues); 16 | } 17 | } -------------------------------------------------------------------------------- /src/AutoMapper/Mappers/NullableDestinationMapper.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Internal.Mappers; 2 | 3 | public class NullableDestinationMapper : IObjectMapper 4 | { 5 | public bool IsMatch(TypePair context) => context.DestinationType.IsNullableType(); 6 | public Expression MapExpression(IGlobalConfiguration configuration, ProfileMap profileMap, MemberMap memberMap, Expression sourceExpression, Expression destExpression) => 7 | configuration.MapExpression(profileMap, GetAssociatedTypes(sourceExpression.Type, destExpression.Type), sourceExpression, memberMap); 8 | public TypePair? GetAssociatedTypes(TypePair initialTypes) => GetAssociatedTypes(initialTypes.SourceType, initialTypes.DestinationType); 9 | TypePair GetAssociatedTypes(Type sourceType, Type destinationType) => new(sourceType, Nullable.GetUnderlyingType(destinationType)); 10 | } -------------------------------------------------------------------------------- /src/AutoMapper/Mappers/NullableSourceMapper.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Internal.Mappers; 2 | 3 | public class NullableSourceMapper : IObjectMapper 4 | { 5 | public bool IsMatch(TypePair context) => context.SourceType.IsNullableType(); 6 | public Expression MapExpression(IGlobalConfiguration configuration, ProfileMap profileMap, MemberMap memberMap, Expression sourceExpression, Expression destExpression) => 7 | configuration.MapExpression(profileMap, GetAssociatedTypes(sourceExpression.Type, destExpression.Type), 8 | ExpressionBuilder.Property(sourceExpression, "Value"), memberMap, destExpression); 9 | public TypePair? GetAssociatedTypes(TypePair initialTypes) => GetAssociatedTypes(initialTypes.SourceType, initialTypes.DestinationType); 10 | TypePair GetAssociatedTypes(Type sourceType, Type destinationType) => new(Nullable.GetUnderlyingType(sourceType), destinationType); 11 | } -------------------------------------------------------------------------------- /src/AutoMapper/Mappers/ParseStringMapper.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Internal.Mappers; 2 | 3 | public class ParseStringMapper : IObjectMapper 4 | { 5 | public bool IsMatch(TypePair context) => context.SourceType == typeof(string) && HasParse(context.DestinationType); 6 | static bool HasParse(Type type) => type == typeof(Guid) || type == typeof(TimeSpan) || type == typeof(DateTimeOffset); 7 | public Expression MapExpression(IGlobalConfiguration configuration, ProfileMap profileMap, MemberMap memberMap, Expression sourceExpression, Expression destExpression) => 8 | Call(destExpression.Type.GetMethod("Parse", [typeof(string)]), sourceExpression); 9 | } -------------------------------------------------------------------------------- /src/AutoMapper/Mappers/ToStringDictionaryMapper.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Internal.Mappers; 2 | public class ToStringDictionaryMapper : IObjectMapper 3 | { 4 | private static readonly MethodInfo MembersDictionaryMethodInfo = typeof(ToStringDictionaryMapper).GetStaticMethod(nameof(MembersDictionary)); 5 | public bool IsMatch(TypePair context) => typeof(IDictionary).IsAssignableFrom(context.DestinationType); 6 | public Expression MapExpression(IGlobalConfiguration configuration, ProfileMap profileMap, MemberMap memberMap, Expression sourceExpression, Expression destExpression) => 7 | Call(MembersDictionaryMethodInfo, sourceExpression.ToObject(), Constant(profileMap)); 8 | private static Dictionary MembersDictionary(object source, ProfileMap profileMap) => 9 | profileMap.CreateTypeDetails(source.GetType()).ReadAccessors.ToDictionary(p => p.Name, p => p.GetMemberValue(source)); 10 | } -------------------------------------------------------------------------------- /src/AutoMapper/Mappers/ToStringMapper.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Internal.Mappers; 2 | public class ToStringMapper : IObjectMapper 3 | { 4 | public bool IsMatch(TypePair context) => context.DestinationType == typeof(string); 5 | public Expression MapExpression(IGlobalConfiguration configuration, ProfileMap profileMap, MemberMap memberMap, Expression sourceExpression, Expression destExpression) 6 | { 7 | var sourceType = sourceExpression.Type; 8 | var toStringCall = Call(sourceExpression, ObjectToString); 9 | return sourceType.IsEnum ? StringToEnumMapper.CheckEnumMember(sourceExpression, sourceType, toStringCall) : toStringCall; 10 | } 11 | } -------------------------------------------------------------------------------- /src/AutoMapper/Mappers/UnderlyingEnumTypeMapper.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.Internal.Mappers; 2 | 3 | public class UnderlyingTypeEnumMapper : IObjectMapper 4 | { 5 | public bool IsMatch(TypePair context) => context.IsEnumToUnderlyingType() || context.IsUnderlyingTypeToEnum(); 6 | public Expression MapExpression(IGlobalConfiguration configuration, ProfileMap profileMap, 7 | MemberMap memberMap, Expression sourceExpression, Expression destExpression) => sourceExpression; 8 | } -------------------------------------------------------------------------------- /src/AutoMapper/PathMap.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper; 2 | [DebuggerDisplay("{DestinationExpression}")] 3 | [EditorBrowsable(EditorBrowsableState.Never)] 4 | public sealed class PathMap(LambdaExpression destinationExpression, MemberPath memberPath, TypeMap typeMap) : MemberMap(typeMap) 5 | { 6 | public PathMap(PathMap pathMap, TypeMap typeMap, IncludedMember includedMember) : this(pathMap.DestinationExpression, pathMap.MemberPath, typeMap) 7 | { 8 | IncludedMember = includedMember.Chain(pathMap.IncludedMember); 9 | Resolver = pathMap.Resolver; 10 | Condition = pathMap.Condition; 11 | Ignored = pathMap.Ignored; 12 | } 13 | public override Type SourceType => Resolver.ResolvedType; 14 | public LambdaExpression DestinationExpression { get; } = destinationExpression; 15 | public MemberPath MemberPath { get; } = memberPath; 16 | public override Type DestinationType => MemberPath.Last.GetMemberType(); 17 | public override string DestinationName => MemberPath.ToString(); 18 | public override bool CanBeSet => ReflectionHelper.CanBeSet(MemberPath.Last); 19 | public override bool Ignored { get; set; } 20 | public override IncludedMember IncludedMember { get; protected set; } 21 | public override LambdaExpression Condition { get; set; } 22 | } -------------------------------------------------------------------------------- /src/AutoMapper/QueryableExtensions/ProjectionMappers/AssignableProjectionMapper.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.QueryableExtensions.Impl; 2 | [EditorBrowsable(EditorBrowsableState.Never)] 3 | public class AssignableProjectionMapper : IProjectionMapper 4 | { 5 | public bool IsMatch(TypePair context) => context.DestinationType.IsAssignableFrom(context.SourceType); 6 | public Expression Project(IGlobalConfiguration configuration, in ProjectionRequest request, Expression resolvedSource, LetPropertyMaps letPropertyMaps) 7 | => ToType(resolvedSource, request.DestinationType); 8 | } -------------------------------------------------------------------------------- /src/AutoMapper/QueryableExtensions/ProjectionMappers/EnumProjectionMapper.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.QueryableExtensions.Impl; 2 | [EditorBrowsable(EditorBrowsableState.Never)] 3 | public class EnumProjectionMapper : IProjectionMapper 4 | { 5 | public Expression Project(IGlobalConfiguration configuration, in ProjectionRequest request, Expression resolvedSource, LetPropertyMaps letPropertyMaps) 6 | => Convert(resolvedSource, request.DestinationType); 7 | public bool IsMatch(TypePair context) => context.IsEnumToEnum() || context.IsUnderlyingTypeToEnum() || context.IsEnumToUnderlyingType(); 8 | } -------------------------------------------------------------------------------- /src/AutoMapper/QueryableExtensions/ProjectionMappers/NullableSourceProjectionMapper.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.QueryableExtensions.Impl; 2 | internal class NullableSourceProjectionMapper : IProjectionMapper 3 | { 4 | public Expression Project(IGlobalConfiguration configuration, in ProjectionRequest request, Expression resolvedSource, LetPropertyMaps letPropertyMaps) => 5 | Coalesce(resolvedSource, New(request.DestinationType)); 6 | public bool IsMatch(TypePair context) => 7 | context.DestinationType.IsValueType && !context.DestinationType.IsNullableType() && context.SourceType.IsNullableType(); 8 | } -------------------------------------------------------------------------------- /src/AutoMapper/QueryableExtensions/ProjectionMappers/StringProjectionMapper.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.QueryableExtensions.Impl; 2 | 3 | [EditorBrowsable(EditorBrowsableState.Never)] 4 | public class StringProjectionMapper : IProjectionMapper 5 | { 6 | public bool IsMatch(TypePair context) => context.DestinationType == typeof(string); 7 | public Expression Project(IGlobalConfiguration configuration, in ProjectionRequest request, Expression resolvedSource, LetPropertyMaps letPropertyMaps) 8 | => Call(resolvedSource, ObjectToString); 9 | } -------------------------------------------------------------------------------- /src/Benchmark/BenchEngine.cs: -------------------------------------------------------------------------------- 1 | namespace Benchmark; 2 | 3 | public class BenchEngine 4 | { 5 | private readonly IObjectToObjectMapper _mapper; 6 | private readonly string _mode; 7 | 8 | public BenchEngine(IObjectToObjectMapper mapper, string mode) 9 | { 10 | _mapper = mapper; 11 | _mode = mode; 12 | } 13 | 14 | public void Start() 15 | { 16 | _mapper.Initialize(); 17 | _mapper.Map(); 18 | 19 | var timer = Stopwatch.StartNew(); 20 | 21 | for(int i = 0; i < 1_000_000; i++) 22 | { 23 | _mapper.Map(); 24 | } 25 | 26 | timer.Stop(); 27 | 28 | Console.WriteLine("{2:D3} ms {0}: - {1}", _mapper.Name, _mode, (int)timer.Elapsed.TotalMilliseconds); 29 | } 30 | } -------------------------------------------------------------------------------- /src/Benchmark/Benchmark.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | Exe 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/Benchmark/HiPerfTimer.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace Benchmark; 4 | 5 | public class HiPerfTimer 6 | { 7 | [DllImport("Kernel32.dll")] 8 | private static extern bool QueryPerformanceCounter( 9 | out long lpPerformanceCount); 10 | 11 | [DllImport("Kernel32.dll")] 12 | private static extern bool QueryPerformanceFrequency( 13 | out long lpFrequency); 14 | 15 | private long _startTime, _stopTime; 16 | private long _freq; 17 | 18 | // Constructor 19 | public HiPerfTimer() 20 | { 21 | _startTime = 0; 22 | _stopTime = 0; 23 | 24 | if (QueryPerformanceFrequency(out _freq) == false) 25 | { 26 | // high-performance counter not supported 27 | throw new Win32Exception(); 28 | } 29 | } 30 | 31 | // Start the timer 32 | public void Start() 33 | { 34 | // lets do the waiting threads there work 35 | Thread.Sleep(0); 36 | 37 | QueryPerformanceCounter(out _startTime); 38 | } 39 | 40 | // Stop the timer 41 | public void Stop() 42 | { 43 | QueryPerformanceCounter(out _stopTime); 44 | } 45 | 46 | // Returns the duration of the timer (in seconds) 47 | public double Duration 48 | { 49 | get 50 | { 51 | double d = (_stopTime - _startTime); 52 | return d / _freq; 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /src/Benchmark/IObjectToObjectMapper.cs: -------------------------------------------------------------------------------- 1 | namespace Benchmark; 2 | 3 | public interface IObjectToObjectMapper 4 | { 5 | string Name { get; } 6 | void Initialize(); 7 | object Map(); 8 | } -------------------------------------------------------------------------------- /src/Benchmark/Program.cs: -------------------------------------------------------------------------------- 1 | using Benchmark.Flattening; 2 | 3 | namespace Benchmark; 4 | 5 | public class Program 6 | { 7 | public static void Main(string[] args) 8 | { 9 | var mappers = new Dictionary 10 | { 11 | { "Flattening", new IObjectToObjectMapper[] { new FlatteningMapper() , new ManualMapper(), } }, 12 | { "Ctors", new IObjectToObjectMapper[] { new CtorMapper(), new ManualCtorMapper(), } }, 13 | { "Complex", new IObjectToObjectMapper[] { new ComplexTypeMapper(), new ManualComplexTypeMapper() } }, 14 | { "Deep", new IObjectToObjectMapper[] { new DeepTypeMapper(), new ManualDeepTypeMapper() } } 15 | }; 16 | while (true) 17 | { 18 | foreach (var pair in mappers) 19 | { 20 | foreach (var mapper in pair.Value) 21 | { 22 | new BenchEngine(mapper, pair.Key).Start(); 23 | } 24 | } 25 | Console.ReadLine(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/IntegrationTests/AutoMapper.IntegrationTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | $(NoWarn);618 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/IntegrationTests/ProjectionAdvanced.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.IntegrationTests; 2 | public class ProjectionAdvanced : IntegrationTest 3 | { 4 | protected override MapperConfiguration CreateConfiguration() => new(c => c.CreateProjection().Advanced().ForAllMembers(o=>o.Ignore())); 5 | [Fact] 6 | public void Should_work() 7 | { 8 | using var context = new Context(); 9 | var dto = ProjectTo(context.Entities).Single(); 10 | dto.Id.ShouldBe(0); 11 | dto.Name.ShouldBeNull(); 12 | dto.Value.ShouldBeNull(); 13 | } 14 | public class Initializer : DropCreateDatabaseAlways 15 | { 16 | protected override void Seed(Context context) => context.Add(new Entity { Name = "name", Value = "value" }); 17 | } 18 | public class Context : LocalDbContext 19 | { 20 | public DbSet Entities { get; set; } 21 | } 22 | public class Entity 23 | { 24 | public int Id { get; set; } 25 | public string Name { get; set; } 26 | public string Value { get; set; } 27 | } 28 | public class Dto 29 | { 30 | public int Id { get; set; } 31 | public string Name { get; set; } 32 | public string Value { get; set; } 33 | } 34 | } -------------------------------------------------------------------------------- /src/TestApp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 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: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("TestApp")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("de95f633-80b5-4248-a594-7fb357c8dac9")] 20 | -------------------------------------------------------------------------------- /src/TestApp/TestApp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | TestApp 6 | Exe 7 | enable 8 | enable 9 | TestApp 10 | false 11 | false 12 | false 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/UnitTests/AddProfiles.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests; 2 | 3 | public class AddProfiles : AutoMapperSpecBase 4 | { 5 | public class Source { } 6 | public class Dest { } 7 | public class ForwardProfile : Profile 8 | { 9 | public ForwardProfile() => CreateMap(); 10 | } 11 | public class ReverseProfile : Profile 12 | { 13 | public ReverseProfile() => CreateMap(); 14 | } 15 | protected override MapperConfiguration CreateConfiguration() => new(c => c.AddProfiles(new Profile[] { new ForwardProfile(), new ReverseProfile() })); 16 | [Fact] 17 | public void Should_not_throw_when_loading_multiple_profiles() => GetProfiles().Count().ShouldBe(3); // default plus two specifically added 18 | } -------------------------------------------------------------------------------- /src/UnitTests/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/UnitTests/AssertionExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests; 2 | 3 | public static class AssertionExtensions 4 | { 5 | public static void ShouldContain(this IEnumerable items, object item) 6 | => ShouldBeEnumerableTestExtensions.ShouldContain(items.Cast(), item); 7 | 8 | public static void ShouldBeEmpty(this IEnumerable items) 9 | => ShouldBeEnumerableTestExtensions.ShouldBeEmpty(items.Cast()); 10 | 11 | public static void ShouldBeThrownBy(this Type exceptionType, Action action) 12 | => action.ShouldThrow(exceptionType); 13 | 14 | public static void ShouldThrowException(this Action action, Action customAssertion) where T : Exception 15 | { 16 | bool throws = false; 17 | try 18 | { 19 | action(); 20 | } 21 | catch (T e) 22 | { 23 | throws = true; 24 | customAssertion(e); 25 | } 26 | throws.ShouldBeTrue(); 27 | } 28 | 29 | public static void ShouldNotBeThrownBy(this Type exceptionType, Action action) 30 | => action.ShouldNotThrow(); 31 | } -------------------------------------------------------------------------------- /src/UnitTests/AutoMapper.UnitTests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | $(NoWarn);649;618 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/UnitTests/AutoMapperTester.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests; 2 | 3 | public class AutoMapperTester : IDisposable 4 | { 5 | [Fact] 6 | public void Should_be_able_to_handle_derived_proxy_types() 7 | { 8 | var config = new MapperConfiguration(cfg => cfg.CreateMap()); 9 | var source = new[] { new DerivedModelType { TheProperty = "Foo" }, new DerivedModelType { TheProperty = "Bar" } }; 10 | 11 | var mapper = config.CreateMapper(); 12 | var destination = (DtoType[])mapper.Map(source, typeof(ModelType[]), typeof(DtoType[])); 13 | 14 | destination[0].TheProperty.ShouldBe("Foo"); 15 | destination[1].TheProperty.ShouldBe("Bar"); 16 | } 17 | 18 | public void Dispose() 19 | { 20 | 21 | } 22 | 23 | public class ModelType 24 | { 25 | public string TheProperty { get; set; } 26 | } 27 | 28 | public class DerivedModelType : ModelType 29 | { 30 | } 31 | 32 | public class DtoType 33 | { 34 | public string TheProperty { get; set; } 35 | } 36 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/AddingConfigurationForNonMatchingDestinationMemberBug.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug 2 | { 3 | namespace AddingConfigurationForNonMatchingDestinationMember 4 | { 5 | public class AddingConfigurationForNonMatchingDestinationMemberBug : NonValidatingSpecBase 6 | { 7 | public class Source 8 | { 9 | 10 | } 11 | 12 | public class Destination 13 | { 14 | public string Value { get; set; } 15 | } 16 | 17 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 18 | { 19 | cfg.CreateMap() 20 | .ForMember(dest => dest.Value, opt => opt.NullSubstitute("Foo")); 21 | }); 22 | 23 | [Fact] 24 | public void Should_show_configuration_error() 25 | { 26 | typeof (AutoMapperConfigurationException).ShouldBeThrownBy(AssertConfigurationIsValid); 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/AfterMapNestedObjects.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class AfterMapNestedObjects : AutoMapperSpecBase 4 | { 5 | bool _afterMapCalled; 6 | 7 | public class Inner 8 | { 9 | public string Prop1 { get; set; } 10 | } 11 | 12 | public class Outer 13 | { 14 | public Inner Inner { get; set; } 15 | } 16 | 17 | public class InnerDTO 18 | { 19 | public string Prop1 { get; set; } 20 | } 21 | 22 | public class OuterDTO 23 | { 24 | public InnerDTO Inner { get; set; } 25 | } 26 | 27 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 28 | { 29 | cfg.CreateMap(); 30 | cfg.CreateMap(); 31 | }); 32 | 33 | protected override void Because_of() 34 | { 35 | var outer = new Outer { Inner = new Inner() { Prop1 = "Prop1" } }; 36 | Mapper.Map(outer, o => o.AfterMap((s, d) => _afterMapCalled = true)); 37 | } 38 | 39 | [Fact] 40 | public void Should_call_aftermap_for_outer_objects() 41 | { 42 | _afterMapCalled.ShouldBeTrue(); 43 | } 44 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/AllowNullCollectionsAssignableArray.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class AllowNullCollectionsAssignableArray : AutoMapperSpecBase 4 | { 5 | private Destination _destination; 6 | 7 | class Source 8 | { 9 | public string[] ArrayOfItems { get; set; } 10 | } 11 | class Destination 12 | { 13 | public string[] ArrayOfItems { get; set; } 14 | } 15 | 16 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 17 | { 18 | cfg.AllowNullCollections = false; 19 | cfg.CreateMap(); 20 | }); 21 | 22 | protected override void Because_of() 23 | { 24 | _destination = new Destination 25 | { 26 | ArrayOfItems = new string[] { "Red Fish", "Blue Fish" }, 27 | }; 28 | Mapper.Map(new Source(), _destination); 29 | } 30 | 31 | [Fact] 32 | public void Should_overwrite_destination_array() 33 | { 34 | _destination.ArrayOfItems.ShouldBeEmpty(); 35 | } 36 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/AssertConfigurationIsValidNullables.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class AssertConfigurationIsValidNullables : AutoMapperSpecBase 4 | { 5 | class Source 6 | { 7 | public int? Number { get; set; } 8 | } 9 | class Destination 10 | { 11 | public decimal? Number { get; set; } 12 | } 13 | 14 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 15 | { 16 | cfg.CreateMap(); 17 | }); 18 | [Fact] 19 | public void Validate() => AssertConfigurationIsValid(); 20 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/CannotConvertEnumToNullable.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class CannotConvertEnumToNullable 4 | { 5 | public enum DummyTypes : int 6 | { 7 | Foo = 1, 8 | Bar = 2 9 | } 10 | 11 | public class DummySource 12 | { 13 | public DummyTypes Dummy { get; set; } 14 | } 15 | 16 | public class DummyDestination 17 | { 18 | public int? Dummy { get; set; } 19 | } 20 | 21 | [Fact] 22 | public void Should_map_enum_to_nullable() 23 | { 24 | var config = new MapperConfiguration(cfg => cfg.CreateMap()); 25 | config.AssertConfigurationIsValid(); 26 | DummySource src = new DummySource() { Dummy = DummyTypes.Bar }; 27 | 28 | var destination = config.CreateMapper().Map(src); 29 | 30 | destination.Dummy.ShouldBe((int)DummyTypes.Bar); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/CannotMapICollectionToAggregateSumDestination.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class CannotMapICollectionToAggregateSumDestination 4 | { 5 | class DummySource 6 | { 7 | public ICollection DummyCollection { get; set; } 8 | } 9 | 10 | class DummyDestination 11 | { 12 | public int DummyCollectionSum { get; set; } 13 | } 14 | 15 | [Fact] 16 | public void Should_map_icollection_to_aggregate_sum_destination() 17 | { 18 | // arrange 19 | var config = new MapperConfiguration(cfg => 20 | { 21 | cfg.CreateProjection(); 22 | }); 23 | 24 | // act 25 | // do nothing 26 | 27 | // assert 28 | config.AssertConfigurationIsValid(); 29 | } 30 | 31 | [Fact] 32 | public void Should_project_icollection_to_aggregate_sum_destination() 33 | { 34 | // arrange 35 | var config = new MapperConfiguration(cfg => cfg.CreateProjection()); 36 | var source = new DummySource() { DummyCollection = new[] { 1, 4, 5 } }; 37 | 38 | // act 39 | var destination = new[] { source }.AsQueryable() 40 | .ProjectTo(config) 41 | .Single(); 42 | 43 | // assert 44 | destination.DummyCollectionSum.ShouldBe(10); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/CannotProjectIEnumerableToAggregateDestinations.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class CannotProjectIEnumerableToAggregateDestinations 4 | { 5 | class DummySource 6 | { 7 | public IEnumerable DummyEnumerable { get; set; } 8 | } 9 | 10 | class DummyDestination 11 | { 12 | public int DummyEnumerableCount { get; set; } 13 | public int DummyEnumerableSum { get; set; } 14 | public int DummyEnumerableMin { get; set; } 15 | public int DummyEnumerableMax { get; set; } 16 | } 17 | 18 | [Fact] 19 | public void Should_project_ienumerable_to_aggregate_destinations() 20 | { 21 | // arrange 22 | var config = new MapperConfiguration(cfg => cfg.CreateProjection()); 23 | var source = new DummySource() { DummyEnumerable = new[] { 1, 4, 5 } }; 24 | 25 | // act 26 | var destination = new[] { source }.AsQueryable() 27 | .ProjectTo(config) 28 | .Single(); 29 | 30 | // assert 31 | destination.DummyEnumerableCount.ShouldBe(3); 32 | destination.DummyEnumerableSum.ShouldBe(10); 33 | destination.DummyEnumerableMin.ShouldBe(1); 34 | destination.DummyEnumerableMax.ShouldBe(5); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/CannotProjectStringToNullableEnum.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class CannotProjectStringToNullableEnum 4 | { 5 | public enum DummyTypes : int 6 | { 7 | Foo = 1, 8 | Bar = 2 9 | } 10 | 11 | public class DummySource 12 | { 13 | public string Dummy { get; set; } 14 | } 15 | 16 | public class DummyDestination 17 | { 18 | public DummyTypes? Dummy { get; set; } 19 | } 20 | 21 | [Fact] 22 | public void Should_project_string_to_nullable_enum() 23 | { 24 | var config = new MapperConfiguration(cfg => 25 | { 26 | cfg.CreateProjection().ConvertUsing(s => (DummyTypes)System.Enum.Parse(typeof(DummyTypes),s)); 27 | cfg.CreateProjection(); 28 | }); 29 | 30 | config.AssertConfigurationIsValid(); 31 | 32 | var src = new DummySource[] { new DummySource { Dummy = "Foo" } }; 33 | 34 | var destination = src.AsQueryable().ProjectTo(config).First(); 35 | 36 | destination.Dummy.ShouldBe(DummyTypes.Foo); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/CaseSensitivityBug.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | public class CaseSensitivityBug : AutoMapperSpecBase 3 | { 4 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 5 | { 6 | cfg.CreateMap(); 7 | }); 8 | public class Foo 9 | { 10 | public int ID { get; set; } 11 | } 12 | 13 | public class Bar 14 | { 15 | public int id { get; set; } 16 | } 17 | [Fact] 18 | public void Validate() => AssertConfigurationIsValid(); 19 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/CollectionBaseClassGetConvention.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class CollectionBaseClassGetConvention : AutoMapperSpecBase 4 | { 5 | Destination _destination; 6 | static int[] SomeCollection = new[] { 1, 2, 3 }; 7 | 8 | public abstract class SourceBase 9 | { 10 | public IEnumerable GetItems() 11 | { 12 | return SomeCollection; 13 | } 14 | } 15 | 16 | public class Source : SourceBase 17 | { 18 | } 19 | 20 | public class Destination 21 | { 22 | public IEnumerable Items { get; set; } 23 | } 24 | 25 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 26 | { 27 | cfg.CreateMap(); 28 | }); 29 | 30 | protected override void Because_of() 31 | { 32 | _destination = Mapper.Map(new Source()); 33 | } 34 | 35 | [Fact] 36 | public void Should_map_collection_with_get_convention() 37 | { 38 | _destination.Items.SequenceEqual(SomeCollection).ShouldBeTrue(); 39 | } 40 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/CollectionWhere.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class CollectionWhere : AutoMapperSpecBase 4 | { 5 | private Destination _destination; 6 | private List _sourceList = new List() { 1, 2, 3 }; 7 | 8 | class Source 9 | { 10 | public int Id { get; set; } 11 | 12 | public IEnumerable ListProperty { get; set; } 13 | } 14 | 15 | class Destination 16 | { 17 | public int Id { get; set; } 18 | 19 | public IEnumerable ListProperty { get; set; } 20 | } 21 | 22 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 23 | { 24 | cfg.CreateMap(); 25 | }); 26 | 27 | protected override void Because_of() 28 | { 29 | var source = new Source() 30 | { 31 | Id = 1, 32 | ListProperty = _sourceList, 33 | }; 34 | _destination = new Destination() 35 | { 36 | Id = 2, 37 | ListProperty = new List() { 4, 5, 6 }.Where(a=>true).ToArray() 38 | }; 39 | _destination = Mapper.Map(source, _destination); 40 | } 41 | 42 | [Fact] 43 | public void Should_map_collections_with_where() 44 | { 45 | Enumerable.SequenceEqual(_destination.ListProperty, _sourceList).ShouldBeTrue(); 46 | } 47 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/CollectionsNullability.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class CollectionsNullability : AutoMapperSpecBase 4 | { 5 | Holder _destination; 6 | 7 | public class Container 8 | { 9 | public List Items { get; set; } 10 | } 11 | 12 | class Holder 13 | { 14 | public Container[] Containers { get; set; } 15 | } 16 | 17 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 18 | { 19 | cfg.CreateMap(); 20 | cfg.CreateMap(); 21 | }); 22 | 23 | protected override void Because_of() 24 | { 25 | var from = new Holder { Containers = new[] { new Container() } }; 26 | _destination = Mapper.Map(from); 27 | } 28 | 29 | [Fact] 30 | public void Should_map_null_collection_to_not_null() 31 | { 32 | _destination.Containers[0].Items.ShouldNotBeNull(); 33 | } 34 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/ConstructUsingReturnsNull.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class ConstructUsingReturnsNull : AutoMapperSpecBase 4 | { 5 | class Source 6 | { 7 | public int Number { get; set; } 8 | } 9 | class Destination 10 | { 11 | public int Number { get; set; } 12 | } 13 | 14 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 15 | { 16 | cfg.CreateMap().ConstructUsing((Source source) => null); 17 | }); 18 | 19 | [Fact] 20 | public void Should_throw_when_construct_using_returns_null() 21 | { 22 | new Action(() => Mapper.Map(new Source())) 23 | .ShouldThrowException(ex=>ex.InnerException.ShouldBeOfType()); 24 | } 25 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/ConstructorParameterNamedType.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class ConstructorParameterNamedType 4 | { 5 | public class SourceClass { } 6 | 7 | public class DestinationClass 8 | { 9 | public DestinationClass() { } 10 | 11 | public DestinationClass(int type) 12 | { 13 | Type = type; 14 | } 15 | 16 | public int Type { get; private set; } 17 | } 18 | 19 | [Fact] 20 | public void Should_handle_constructor_parameter_named_type() 21 | { 22 | var config = new MapperConfiguration(c => c.CreateMap()); 23 | new Action(config.AssertConfigurationIsValid).ShouldThrowException(ex=>ex.Errors[0].UnmappedPropertyNames[0].ShouldBe("Type")); 24 | } 25 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/ConvertMapperThreading.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests; 2 | 3 | public class ConvertMapperThreading 4 | { 5 | class Source 6 | { 7 | public string Number { get; set; } 8 | } 9 | 10 | class Destination 11 | { 12 | public int Number { get; set; } 13 | } 14 | 15 | [Fact] 16 | public async Task Should_work() 17 | { 18 | var tasks = Enumerable.Range(0, 5).Select(i => Task.Factory.StartNew(() => 19 | { 20 | new MapperConfiguration(c => c.CreateMap()); 21 | })).ToArray(); 22 | try 23 | { 24 | await Task.WhenAll(tasks); 25 | } 26 | catch(AggregateException ex) 27 | { 28 | ex.Handle(e => 29 | { 30 | if(e is InvalidOperationException) 31 | { 32 | throw e; 33 | } 34 | return false; 35 | }); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/CreateMapExpressionWithIgnoredPropertyBug.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | public class CreateMapExpressionWithIgnoredPropertyBug 3 | { 4 | [Fact] 5 | public void ShouldNotMapPropertyWhenItIsIgnored() 6 | { 7 | var config = new MapperConfiguration(cfg => 8 | { 9 | cfg.CreateProjection() 10 | .ForMember(x => x.Name, x => x.Ignore()); 11 | }); 12 | 13 | IQueryable collection = (new List { new Person { Name = "Person1" } }).AsQueryable(); 14 | 15 | List result = collection.ProjectTo(config).ToList(); 16 | 17 | result.ForEach(x => x.Name.ShouldBeNull()); 18 | } 19 | 20 | public class Person 21 | { 22 | public string Name { get; set; } 23 | } 24 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/DeepCloningBug.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class DeepCloningBug : AutoMapperSpecBase 4 | { 5 | private Outer _source; 6 | private Outer _dest; 7 | 8 | public class Outer 9 | { 10 | public Inner Foo { get; set; } 11 | } 12 | 13 | public class Inner 14 | { 15 | 16 | } 17 | 18 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 19 | { 20 | cfg.CreateMap(); 21 | cfg.CreateMap(); 22 | }); 23 | 24 | protected override void Because_of() 25 | { 26 | _source = new Outer { Foo = new Inner() }; 27 | _dest = Mapper.Map(_source); 28 | } 29 | 30 | [Fact] 31 | public void Should_map_new_top_object() 32 | { 33 | _dest.ShouldNotBeSameAs(_source); 34 | } 35 | 36 | [Fact] 37 | public void Should_map_new_second_level_object() 38 | { 39 | _dest.Foo.ShouldNotBeSameAs(_source.Foo); 40 | } 41 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/DuplicateExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class DuplicateExtensionMethods : AutoMapperSpecBase 4 | { 5 | public class Outlay 6 | { 7 | public int Amount { get; set; } 8 | } 9 | 10 | public enum AccountKind { None } 11 | 12 | class Source 13 | { 14 | public int UserId { get; set; } 15 | public string UserName { get; set; } 16 | public string UserPhone { get; set; } 17 | public string IDCard { get; set; } 18 | public AccountKind Kind { get; set; } 19 | public decimal UnUsedAmount { get; set; } 20 | public List Outlay { get; set; } 21 | } 22 | class Destination 23 | { 24 | public int UserId { get; set; } 25 | public string UserName { get; set; } 26 | public string UserPhone { get; set; } 27 | public string IDCard { get; set; } 28 | public AccountKind Kind { get; set; } 29 | public decimal UnUsedAmount { get; set; } 30 | } 31 | 32 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 33 | { 34 | cfg.CreateMap(); 35 | }); 36 | [Fact] 37 | public void Validate() => AssertConfigurationIsValid(); 38 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/EFCollections.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class EFCollections : AutoMapperSpecBase 4 | { 5 | private Dest _dest; 6 | 7 | public class Source 8 | { 9 | public ICollection Children { get; set; } 10 | 11 | } 12 | 13 | public class OtherSource : Source 14 | { 15 | } 16 | 17 | public class OtherChild : Child 18 | { 19 | 20 | } 21 | 22 | public class Dest 23 | { 24 | public ICollection Children { get; set; } 25 | } 26 | 27 | public class DestChild {} 28 | 29 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 30 | { 31 | cfg.CreateMap(); 32 | cfg.CreateMap(); 33 | }); 34 | 35 | protected override void Because_of() 36 | { 37 | var source = new OtherSource 38 | { 39 | Children = new Collection 40 | { 41 | new OtherChild(), 42 | new OtherChild() 43 | } 44 | }; 45 | _dest = Mapper.Map(source); 46 | } 47 | 48 | [Fact] 49 | public void Should_map_collection_items() 50 | { 51 | _dest.Children.Count.ShouldBe(2); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/EnumCaseSensitivityBug.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | public class EnumCaseSensitivityBug : AutoMapperSpecBase 3 | { 4 | private SecondEnum _resultSecondEnum; 5 | private FirstEnum _resultFirstEnum; 6 | 7 | public enum FirstEnum 8 | { 9 | Dog, 10 | Cat 11 | } 12 | 13 | public enum SecondEnum 14 | { 15 | cat, 16 | dog 17 | } 18 | 19 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 20 | { 21 | // not creating a map on purpose to trigger use of EnumToEnumMapper 22 | }); 23 | 24 | protected override void Because_of() 25 | { 26 | _resultSecondEnum = Mapper.Map(FirstEnum.Cat); 27 | _resultFirstEnum = Mapper.Map(SecondEnum.dog); 28 | } 29 | 30 | [Fact] 31 | public void Should_match_on_the_name_even_if_values_match() 32 | { 33 | _resultSecondEnum.ShouldBe(SecondEnum.cat); 34 | _resultFirstEnum.ShouldBe(FirstEnum.Dog); 35 | } 36 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/EnumMatchingOnValue.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class EnumMatchingOnValue : AutoMapperSpecBase 4 | { 5 | private SecondClass _result; 6 | 7 | public class FirstClass 8 | { 9 | public FirstEnum EnumValue { get; set; } 10 | } 11 | 12 | public enum FirstEnum 13 | { 14 | NamedEnum = 1, 15 | SecondNameEnum = 2 16 | } 17 | 18 | public class SecondClass 19 | { 20 | public SecondEnum EnumValue { get; set; } 21 | } 22 | 23 | public enum SecondEnum 24 | { 25 | DifferentNamedEnum = 1, 26 | SecondNameEnum = 2 27 | } 28 | 29 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 30 | { 31 | cfg.CreateMap(); 32 | }); 33 | 34 | protected override void Because_of() 35 | { 36 | var source = new FirstClass 37 | { 38 | EnumValue = FirstEnum.NamedEnum 39 | }; 40 | _result = Mapper.Map(source); 41 | } 42 | 43 | [Fact] 44 | public void Should_match_on_the_name_even_if_values_match() 45 | { 46 | _result.EnumValue.ShouldBe(SecondEnum.DifferentNamedEnum); 47 | } 48 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/ForAllMembersAndDoNotUseDestinationValue.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class ForAllMembersAndResolveUsing : AutoMapperSpecBase 4 | { 5 | private Destination _destination; 6 | 7 | class Source 8 | { 9 | public int Number { get; set; } 10 | } 11 | class Destination 12 | { 13 | public int Number { get; set; } 14 | } 15 | 16 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 17 | { 18 | cfg.CreateMap().ForAllMembers(opt => opt.MapFrom(s=>12)); 19 | }); 20 | 21 | protected override void Because_of() 22 | { 23 | var source = new Source 24 | { 25 | Number = 23 26 | }; 27 | _destination = Mapper.Map(source); 28 | } 29 | 30 | [Fact] 31 | public void Should_work_together() 32 | { 33 | _destination.Number.ShouldBe(12); 34 | } 35 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/GuidTryExpression.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class GuidTryExpression : AutoMapperSpecBase 4 | { 5 | private Destination _destination; 6 | private Guid _value = Guid.NewGuid(); 7 | 8 | class Source 9 | { 10 | public Guid Value { get; set; } 11 | } 12 | class Destination 13 | { 14 | public string Value { get; set; } 15 | } 16 | 17 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 18 | { 19 | cfg.CreateMap().ForMember(d => d.Value, o => o.MapFrom(s => s.Value)); 20 | }); 21 | 22 | protected override void Because_of() 23 | { 24 | var source = new Source 25 | { 26 | Value = _value 27 | }; 28 | _destination = Mapper.Map(source); 29 | } 30 | 31 | [Fact] 32 | public void Should_map_int_to_nullable_decimal() 33 | { 34 | _destination.Value.ShouldBe(_value.ToString()); 35 | } 36 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/IntToNullableDecimal.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class IntToNullableDecimal : AutoMapperSpecBase 4 | { 5 | private Destination _destination; 6 | 7 | class Source 8 | { 9 | public int Number { get; set; } 10 | } 11 | class Destination 12 | { 13 | public decimal? Number { get; set; } 14 | } 15 | 16 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 17 | { 18 | cfg.CreateMap(); 19 | }); 20 | 21 | protected override void Because_of() 22 | { 23 | var source = new Source 24 | { 25 | Number = 23 26 | }; 27 | _destination = Mapper.Map(source); 28 | } 29 | 30 | [Fact] 31 | public void Should_map_int_to_nullable_decimal() 32 | { 33 | _destination.Number.ShouldBe(23); 34 | } 35 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/InterfaceSelfMappingBug.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class InterfaceSelfMappingBug 4 | { 5 | public interface IFoo 6 | { 7 | int Value { get; set; } 8 | } 9 | 10 | public class Bar : IFoo 11 | { 12 | public int Value { get; set; } 13 | } 14 | 15 | public class Baz : IFoo 16 | { 17 | public int Value { get; set; } 18 | } 19 | 20 | [Fact] 21 | public void Example() 22 | { 23 | var config = new MapperConfiguration(cfg => 24 | { 25 | cfg.AllowNullCollections = true; 26 | cfg.CreateMap(); 27 | }); 28 | config.AssertConfigurationIsValid(); 29 | 30 | IFoo bar = new Bar 31 | { 32 | Value = 5 33 | }; 34 | IFoo baz = new Baz 35 | { 36 | Value = 10 37 | }; 38 | 39 | config.CreateMapper().Map(bar, baz); 40 | 41 | baz.Value.ShouldBe(5); 42 | } 43 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/InternalProperties.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class InternalProperties : AutoMapperSpecBase 4 | { 5 | public int SomeValue = 2354; 6 | private Destination _destination; 7 | 8 | class Source 9 | { 10 | internal int Number { get; set; } 11 | } 12 | class Destination 13 | { 14 | internal int Number { get; set; } 15 | } 16 | 17 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 18 | { 19 | cfg.ShouldMapProperty = p => true; 20 | cfg.CreateMap(); 21 | }); 22 | 23 | protected override void Because_of() 24 | { 25 | _destination = Mapper.Map(new Source { Number = SomeValue }); 26 | } 27 | 28 | [Fact] 29 | public void Should_map_internal_property() 30 | { 31 | _destination.Number.ShouldBe(SomeValue); 32 | } 33 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/ListSourceMapperBug.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | public class ListSourceMapperBug 3 | { 4 | public class CustomCollection : Collection, IListSource 5 | { 6 | public IList GetList() 7 | { 8 | return new ReadOnlyCollection(this.ToList()); 9 | } 10 | 11 | public bool ContainsListCollection 12 | { 13 | get { return true; } 14 | } 15 | } 16 | 17 | public class Source 18 | { 19 | } 20 | 21 | public class Dest 22 | { 23 | } 24 | 25 | [Fact] 26 | public void CustomListSourceShouldNotBlowUp() 27 | { 28 | var config = new MapperConfiguration(cfg => cfg.CreateMap()); 29 | 30 | var source = new CustomCollection {new Source()}; 31 | 32 | var dests = config.CreateMapper().Map, CustomCollection>(source); 33 | 34 | dests.Count.ShouldBe(1); 35 | } 36 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/BaseEntity.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class BaseEntity 4 | { 5 | public Guid Id { get; set; } 6 | } 7 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/BaseEntityDTO.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class BaseEntity 4 | { 5 | public Guid Id { get; set; } 6 | } 7 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity1.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity1 : BaseEntity 4 | { 5 | public Entity1() 6 | { 7 | this.Entities2 = new Entity2(); 8 | } 9 | public Guid Entity17Id { get; set; } 10 | public Entity17 Entity17 { get; set; } 11 | public Guid? Entity22Id { get; set; } 12 | public Entity22 Entity22 { get; set; } 13 | public Guid? Entity20Id { get; set; } 14 | public Entity20 Entity20 { get; set; } 15 | public Guid? Entity12Id { get; set; } 16 | public Entity12 Entity12 { get; set; } 17 | public Guid Entity14Id { get; set; } 18 | public Entity14 Entity14 { get; set; } 19 | public Guid Entity8Id { get; set; } 20 | public Entity8 Entity8 { get; set; } 21 | public Entity2 Entities2 { get; set; } 22 | } 23 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity10.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity10 : BaseEntity 4 | { 5 | public Entity10() 6 | { 7 | this.Entities11 = new Entity11(); 8 | } 9 | public Entity11 Entities11 { get; set; } 10 | } 11 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity11.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity11 : BaseEntity 4 | { 5 | public Entity11() 6 | { 7 | this.Entities10 = new Entity10(); 8 | this.Entities8 = new Entity8(); 9 | } 10 | public Entity10 Entities10 { get; set; } 11 | public Entity8 Entities8 { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity12.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity12 : BaseEntity 4 | { 5 | public Entity12() 6 | { 7 | //this.Entities20 = new Entity20(); 8 | //this.Entities14 = new Entity14(); 9 | //this.Entities16 = new Entity16(); 10 | } 11 | public Entity20 Entities20 { get; set; } 12 | public Entity16 Entities16 { get; set; } 13 | public Entity14 Entities14 { get; set; } 14 | } 15 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity13.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity13 : BaseEntity 4 | { 5 | public Guid Entity17Id { get; set; } 6 | public Entity17 Entity17 { get; set; } 7 | public Guid Entity8Id { get; set; } 8 | public Entity8 Entity8 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity14.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity14 : BaseEntity 4 | { 5 | public Entity14() 6 | { 7 | this.Entities12 = new Entity12(); 8 | this.Entities1 = new Entity1(); 9 | } 10 | 11 | public Entity12 Entities12 { get; set; } 12 | public Entity1 Entities1 { get; set; } 13 | } 14 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity15.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity15 : BaseEntity 4 | { 5 | public Guid Entity17Id { get; set; } 6 | public Entity17 Entity17 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity16.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity16 : BaseEntity 4 | { 5 | public Guid Entity20Id { get; set; } 6 | public Entity20 Entity20 { get; set; } 7 | public Guid Entity12Id { get; set; } 8 | public Entity12 Entity12 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity17.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity17 :BaseEntity 4 | { 5 | public Entity17() 6 | { 7 | //this.Entities20 = new Entity20(); 8 | this.Entities8 = new Entity8(); 9 | this.Entities5 = new Entity5(); 10 | this.Entities18 = new Entity18(); 11 | } 12 | 13 | public Entity20 Entities20 { get; set; } 14 | public Entity8 Entities8 { get; set; } 15 | public Entity5 Entities5 { get; set; } 16 | public Entity18 Entities18 { get; set; } 17 | } 18 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity18.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity18 : BaseEntity 4 | { 5 | public Guid Entity17Id { get; set; } 6 | public Entity17 Entity17 { get; set; } 7 | public Guid Entity20Id { get; set; } 8 | public Entity20 Entity20 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity19.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity19 : BaseEntity 4 | { 5 | public Guid Entity25Id { get; set; } 6 | public Entity25 Entity25 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity2.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity2 : BaseEntity 4 | { 5 | public Guid Entity1Id { get; set; } 6 | public Entity1 Entity1 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity20.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity20 : BaseEntity 4 | { 5 | public Entity20() 6 | { 7 | //this.Entities8 = new Entity8(); 8 | //this.Entities26 = new Entity26(); 9 | //this.Entities12 = new Entity12(); 10 | //this.Entities17 = new Entity17(); 11 | //this.Entities21 = new Entity21(); 12 | //this.Entities16 = new Entity16(); 13 | } 14 | 15 | public Guid Entity3Id { get; set; } 16 | public Entity3 Entity3 { get; set; } 17 | public Guid Entity22Id { get; set; } 18 | public Entity22 Entity22 { get; set; } 19 | public Entity8 Entities8 { get; set; } 20 | public Entity26 Entities26 { get; set; } 21 | public Entity12 Entities12 { get; set; } 22 | public Entity17 Entities17 { get; set; } 23 | public Entity21 Entities21 { get; set; } 24 | public Entity16 Entities16 { get; set; } 25 | } 26 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity21.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity21 : BaseEntity 4 | { 5 | public Guid Entity20Id { get; set; } 6 | public Entity20 Entity20 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity22.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity22 : BaseEntity 4 | { 5 | public Entity22() 6 | { 7 | this.Entities20 = new Entity20(); 8 | this.Entities24 = new Entity24(); 9 | } 10 | public Entity20 Entities20 { get; set; } 11 | public Entity24 Entities24 { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity23.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity23 : BaseEntity 4 | { 5 | public Guid Entity5Id { get; set; } 6 | public Entity5 Entity5 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity24.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity24 : BaseEntity 4 | { 5 | public Guid Entity3Id { get; set; } 6 | public Entity3 Entity3 { get; set; } 7 | public Guid Entity22Id { get; set; } 8 | public Entity22 Entity22 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity25.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity25 : BaseEntity 4 | { 5 | public Entity25() 6 | { 7 | this.Entities19 = new Entity19(); 8 | } 9 | 10 | public Entity19 Entities19 { get; set; } 11 | public Guid? Entity8Id { get; set; } 12 | public Entity8 Entity8 { get; set; } 13 | public Guid? Entity17Id { get; set; } 14 | public Entity17 Entity17 { get; set; } 15 | } 16 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity26.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity26 : BaseEntity 4 | { 5 | public Entity26() 6 | { 7 | //this.Entities20 = new Entity20(); 8 | } 9 | 10 | public Entity20 Entities20 { get; set; } 11 | } 12 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity3.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity3 : BaseEntity 4 | { 5 | public Entity3() 6 | { 7 | this.Entities4 = new Entity4(); 8 | this.Entities8 = new Entity8(); 9 | } 10 | public Entity4 Entities4 { get; set; } 11 | public Entity8 Entities8 { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity4.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity4 : BaseEntity 4 | { 5 | public Guid Entity3Id { get; set; } 6 | public Entity3 Entity3 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity5.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity5 : BaseEntity 4 | { 5 | public Entity5() 6 | { 7 | //this.Entities6 = new Entity6(); 8 | //this.TimeSlots = new Entity23(); 9 | //this.Entities5 = new Entity5(); 10 | } 11 | 12 | public Guid? Entity8Id { get; set; } 13 | public Entity8 Entity8 { get; set; } 14 | public Guid? Entity17Id { get; set; } 15 | public Entity17 Entity17 { get; set; } 16 | public Guid? Entity5Id { get; set; } 17 | public Entity5 Entity5Exception { get; set; } 18 | public Entity5 Entities5 { get; set; } 19 | public Entity6 Entities6 { get; set; } 20 | public Entity23 TimeSlots { get; set; } 21 | } 22 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity6.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity6 : BaseEntity 4 | { 5 | public Entity6() 6 | { 7 | this.Entities12 = new Entity12(); 8 | } 9 | 10 | public Guid Entity5Id { get; set; } 11 | public Entity5 Entity5 { get; set; } 12 | public Guid Entity20Id { get; set; } 13 | public Entity20 Entity20 { get; set; } 14 | public Entity12 Entities12 { get; set; } 15 | } 16 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity7.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity7 : BaseEntity 4 | { 5 | public Guid Entity25Id { get; set; } 6 | public Entity25 Entity25 { get; set; } 7 | public Guid? Entity14Id { get; set; } 8 | public Entity14 Entity14 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity8.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity8 : BaseEntity 4 | { 5 | public Entity8() 6 | { 7 | //this.Entities20 = new Entity20(); 8 | //this.Entities22 = new Entity22(); 9 | //this.Entities3 = new Entity3(); 10 | //this.Entities11 = new Entity11(); 11 | //this.Entities17 = new Entity17(); 12 | } 13 | 14 | public Entity20 Entities20 { get; set; } 15 | public Entity17 Entities17 { get; set; } 16 | public Entity22 Entities22 { get; set; } 17 | public Entity3 Entities3 { get; set; } 18 | public Entity11 Entities11 { get; set; } 19 | } 20 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/Entity9.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3; 2 | 3 | public class Entity9 : BaseEntity 4 | { 5 | public Guid Entity3Id { get; set; } 6 | public Entity3 Entity3 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO1.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO1 : BaseEntity 4 | { 5 | public EntityDTO1() 6 | { 7 | this.Entities2 = new EntityDTO2(); 8 | } 9 | public Guid Entity17Id { get; set; } 10 | public EntityDTO17 Entity17 { get; set; } 11 | public Guid? Entity22Id { get; set; } 12 | public EntityDTO22 Entity22 { get; set; } 13 | public Guid? Entity20Id { get; set; } 14 | public EntityDTO20 Entity20 { get; set; } 15 | public Guid? Entity12Id { get; set; } 16 | public EntityDTO12 Entity12 { get; set; } 17 | public Guid Entity14Id { get; set; } 18 | public EntityDTO14 Entity14 { get; set; } 19 | public Guid Entity8Id { get; set; } 20 | public EntityDTO8 Entity8 { get; set; } 21 | public EntityDTO2 Entities2 { get; set; } 22 | } 23 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO10.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO10 : BaseEntity 4 | { 5 | public EntityDTO10() 6 | { 7 | this.Entities11 = new EntityDTO11(); 8 | } 9 | public EntityDTO11 Entities11 { get; set; } 10 | } 11 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO11.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO11 : BaseEntity 4 | { 5 | public EntityDTO11() 6 | { 7 | //this.Entities10 = new EntityDTO10(); 8 | //this.Entities8 = new EntityDTO8(); 9 | } 10 | public EntityDTO10 Entities10 { get; set; } 11 | public EntityDTO8 Entities8 { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO12.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO12 : BaseEntity 4 | { 5 | public EntityDTO12() 6 | { 7 | //this.Entities20 = new EntityDTO20(); 8 | //this.Entities14 = new EntityDTO14(); 9 | //Entities16 = new EntityDTO16(); 10 | } 11 | public EntityDTO20 Entities20 { get; set; } 12 | public EntityDTO16 Entities16 { get; set; } 13 | public EntityDTO14 Entities14 { get; set; } 14 | } 15 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO13.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO13 : BaseEntity 4 | { 5 | public Guid Entity17Id { get; set; } 6 | public EntityDTO17 Entity17 { get; set; } 7 | public Guid Entity8Id { get; set; } 8 | public EntityDTO8 Entity8 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO14.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO14 : BaseEntity 4 | { 5 | public EntityDTO14() 6 | { 7 | this.Entities12 = new EntityDTO12(); 8 | this.Entities1 = new EntityDTO1(); 9 | } 10 | 11 | //public Address Address { get; set; } 12 | public EntityDTO12 Entities12 { get; set; } 13 | public EntityDTO1 Entities1 { get; set; } 14 | } 15 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO15.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO15 : BaseEntity 4 | { 5 | public EntityDTO15() 6 | { 7 | } 8 | public Guid Entity17Id { get; set; } 9 | public EntityDTO17 Entity17 { get; set; } 10 | } 11 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO16.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO16 : BaseEntity 4 | { 5 | public Guid Entity20Id { get; set; } 6 | public EntityDTO20 Entity20 { get; set; } 7 | public Guid Entity12Id { get; set; } 8 | public EntityDTO12 Entity12 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO17.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO17 :BaseEntity 4 | { 5 | public EntityDTO17() 6 | { 7 | //this.Entities20 = new EntityDTO20(); 8 | //this.Entities8 = new EntityDTO8(); 9 | //this.Entities5 = new EntityDTO5(); 10 | //this.Entities18 = new EntityDTO18(); 11 | } 12 | 13 | public EntityDTO20 Entities20 { get; set; } 14 | public EntityDTO8 Entities8 { get; set; } 15 | public EntityDTO5 Entities5 { get; set; } 16 | public EntityDTO18 Entities18 { get; set; } 17 | } 18 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO18.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO18 : BaseEntity 4 | { 5 | public Guid Entity17Id { get; set; } 6 | public EntityDTO17 Entity17 { get; set; } 7 | public Guid Entity20Id { get; set; } 8 | public EntityDTO20 Entity20 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO19.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO19 : BaseEntity 4 | { 5 | public Guid Entity25Id { get; set; } 6 | public EntityDTO25 Entity25 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO2.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO2 : BaseEntity 4 | { 5 | public Guid Entity1Id { get; set; } 6 | public EntityDTO1 Entity1 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO20.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO20 : BaseEntity 4 | { 5 | //TODO Remove comments 6 | public EntityDTO20() 7 | { 8 | //this.Entities8 = new EntityDTO8(); 9 | //this.Entities26 = new EntityDTO26(); 10 | //this.Entities12 = new EntityDTO12(); 11 | //this.Entities17 = new EntityDTO17(); 12 | //this.Entities21 = new EntityDTO21(); 13 | //this.Entities16 = new EntityDTO16(); 14 | } 15 | 16 | public Guid Entity3Id { get; set; } 17 | public EntityDTO3 Entity3 { get; set; } 18 | public Guid Entity22Id { get; set; } 19 | public EntityDTO22 Entity22 { get; set; } 20 | public EntityDTO8 Entities8 { get; set; } 21 | public EntityDTO26 Entities26 { get; set; } 22 | public EntityDTO12 Entities12 { get; set; } 23 | public EntityDTO17 Entities17 { get; set; } 24 | public EntityDTO21 Entities21 { get; set; } 25 | public EntityDTO16 Entities16 { get; set; } 26 | } 27 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO21.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO21 : BaseEntity 4 | { 5 | public Guid Entity20Id { get; set; } 6 | public EntityDTO20 Entity20 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO22.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO22 : BaseEntity 4 | { 5 | public EntityDTO22() 6 | { 7 | //this.Entities20 = new EntityDTO20(); 8 | //this.Entities24 = new EntityDTO24(); 9 | } 10 | public EntityDTO20 Entities20 { get; set; } 11 | public EntityDTO24 Entities24 { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO23.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO23 : BaseEntity 4 | { 5 | public Guid Entity5Id { get; set; } 6 | public EntityDTO5 Entity5 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO24.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO24 : BaseEntity 4 | { 5 | public Guid Entity3Id { get; set; } 6 | public EntityDTO3 Entity3 { get; set; } 7 | public Guid Entity22Id { get; set; } 8 | public EntityDTO22 Entity22 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO25.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO25 : BaseEntity 4 | { 5 | public EntityDTO25() 6 | { 7 | this.Entities19 = new EntityDTO19(); 8 | } 9 | 10 | public EntityDTO19 Entities19 { get; set; } 11 | public Guid? Entity8Id { get; set; } 12 | public EntityDTO8 Entity8 { get; set; } 13 | public Guid? Entity17Id { get; set; } 14 | public EntityDTO17 Entity17 { get; set; } 15 | } 16 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO26.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO26 : BaseEntity 4 | { 5 | public EntityDTO26() 6 | { 7 | this.Entities20 = new EntityDTO20(); 8 | } 9 | 10 | public EntityDTO20 Entities20 { get; set; } 11 | } 12 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO3.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO3 : BaseEntity 4 | { 5 | public EntityDTO3() 6 | { 7 | //this.Entities4 = new EntityDTO4(); 8 | //this.Entities8 = new EntityDTO8(); 9 | } 10 | public EntityDTO4 Entities4 { get; set; } 11 | public EntityDTO8 Entities8 { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO4.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO4 : BaseEntity 4 | { 5 | public Guid Entity3Id { get; set; } 6 | public EntityDTO3 Entity3 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO5.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO5 : BaseEntity 4 | { 5 | public EntityDTO5() 6 | { 7 | //this.Entities6 = new EntityDTO6(); 8 | //this.TimeSlots = new EntityDTO23(); 9 | //this.Entities5 = new EntityDTO5(); 10 | } 11 | 12 | public Guid? Entity8Id { get; set; } 13 | public EntityDTO8 Entity8 { get; set; } 14 | public Guid? Entity17Id { get; set; } 15 | public EntityDTO17 Entity17 { get; set; } 16 | public Guid? Entity5Id { get; set; } 17 | public EntityDTO5 Entity5Exception { get; set; } 18 | public EntityDTO5 Entities5 { get; set; } 19 | public EntityDTO6 Entities6 { get; set; } 20 | public EntityDTO23 TimeSlots { get; set; } 21 | } 22 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO6.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO6 : BaseEntity 4 | { 5 | public EntityDTO6() 6 | { 7 | //this.Entities12 = new EntityDTO12(); 8 | } 9 | 10 | public Guid Entity5Id { get; set; } 11 | public EntityDTO5 Entity5 { get; set; } 12 | public Guid Entity20Id { get; set; } 13 | public EntityDTO20 Entity20 { get; set; } 14 | public EntityDTO12 Entities12 { get; set; } 15 | } 16 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO7.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO7 : BaseEntity 4 | { 5 | public Guid Entity25Id { get; set; } 6 | public EntityDTO25 Entity25 { get; set; } 7 | public Guid? Entity14Id { get; set; } 8 | public EntityDTO14 Entity14 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO8.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO8 : BaseEntity 4 | { 5 | public EntityDTO8() 6 | { 7 | this.Entities20 = new EntityDTO20(); 8 | this.Entities22 = new EntityDTO22(); 9 | this.Entities3 = new EntityDTO3(); 10 | this.Entities11 = new EntityDTO11(); 11 | this.Entities17 = new EntityDTO17(); 12 | } 13 | 14 | public EntityDTO20 Entities20 { get; set; } 15 | public EntityDTO17 Entities17 { get; set; } 16 | public EntityDTO22 Entities22 { get; set; } 17 | public EntityDTO3 Entities3 { get; set; } 18 | public EntityDTO11 Entities11 { get; set; } 19 | } 20 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntime/EntityDTO9.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3; 2 | 3 | public class EntityDTO9 : BaseEntity 4 | { 5 | public Guid Entity3Id { get; set; } 6 | public EntityDTO3 Entity3 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/BaseEntity.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class BaseEntity 4 | { 5 | public Guid Id { get; set; } 6 | } 7 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/BaseEntityDTO.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class BaseEntity 4 | { 5 | public Guid Id { get; set; } 6 | } 7 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity1.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity1 : BaseEntity 4 | { 5 | public Entity1() 6 | { 7 | this.Entities2 = new List(); 8 | } 9 | public Guid Entity17Id { get; set; } 10 | public Entity17 Entity17 { get; set; } 11 | public Guid? Entity22Id { get; set; } 12 | public Entity22 Entity22 { get; set; } 13 | public Guid? Entity20Id { get; set; } 14 | public Entity20 Entity20 { get; set; } 15 | public Guid? Entity12Id { get; set; } 16 | public Entity12 Entity12 { get; set; } 17 | public Guid Entity14Id { get; set; } 18 | public Entity14 Entity14 { get; set; } 19 | public Guid Entity8Id { get; set; } 20 | public Entity8 Entity8 { get; set; } 21 | public ICollection Entities2 { get; set; } 22 | public Entity2 Entity2 { get; set; } 23 | } 24 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity10.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity10 : BaseEntity 4 | { 5 | public Entity10() 6 | { 7 | this.Entities11 = new List(); 8 | } 9 | public ICollection Entities11 { get; set; } 10 | } 11 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity11.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity11 : BaseEntity 4 | { 5 | public Entity11() 6 | { 7 | this.Entities10 = new List(); 8 | this.Entities8 = new List(); 9 | } 10 | public ICollection Entities10 { get; set; } 11 | public ICollection Entities8 { get; set; } 12 | public Entity8 Entity8 { get; set; } 13 | } 14 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity12.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity12 : BaseEntity 4 | { 5 | public Entity12() 6 | { 7 | this.Entities20 = new List(); 8 | this.Entities14 = new List(); 9 | this.Entities16 = new List(); 10 | } 11 | public ICollection Entities20 { get; set; } 12 | public ICollection Entities16 { get; set; } 13 | public ICollection Entities14 { get; set; } 14 | } 15 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity13.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity13 : BaseEntity 4 | { 5 | public Guid Entity17Id { get; set; } 6 | public Entity17 Entity17 { get; set; } 7 | public Guid Entity8Id { get; set; } 8 | public Entity8 Entity8 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity14.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity14 : BaseEntity 4 | { 5 | public Entity14() 6 | { 7 | this.Entities12 = new List(); 8 | this.Entities1 = new List(); 9 | } 10 | 11 | public ICollection Entities12 { get; set; } 12 | public ICollection Entities1 { get; set; } 13 | } 14 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity15.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity15 : BaseEntity 4 | { 5 | public Guid Entity17Id { get; set; } 6 | public Entity17 Entity17 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity16.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity16 : BaseEntity 4 | { 5 | public Guid Entity20Id { get; set; } 6 | public Entity20 Entity20 { get; set; } 7 | public Guid Entity12Id { get; set; } 8 | public Entity12 Entity12 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity17.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity17 :BaseEntity 4 | { 5 | public Entity17() 6 | { 7 | this.Entities20 = new List(); 8 | this.Entities8 = new List(); 9 | this.Entities5 = new List(); 10 | this.Entities18 = new List(); 11 | } 12 | 13 | public ICollection Entities20 { get; set; } 14 | public ICollection Entities8 { get; set; } 15 | public ICollection Entities5 { get; set; } 16 | public ICollection Entities18 { get; set; } 17 | } 18 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity18.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity18 : BaseEntity 4 | { 5 | public Guid Entity17Id { get; set; } 6 | public Entity17 Entity17 { get; set; } 7 | public Guid Entity20Id { get; set; } 8 | public Entity20 Entity20 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity19.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity19 : BaseEntity 4 | { 5 | public Guid Entity25Id { get; set; } 6 | public Entity25 Entity25 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity2.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity2 : BaseEntity 4 | { 5 | public Guid Entity1Id { get; set; } 6 | public Entity1 Entity1 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity20.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity20 : BaseEntity 4 | { 5 | public Entity20() 6 | { 7 | this.Entities8 = new List(); 8 | this.Entities26 = new List(); 9 | this.Entities12 = new List(); 10 | this.Entities17 = new List(); 11 | this.Entities21 = new List(); 12 | this.Entities16 = new List(); 13 | } 14 | 15 | public Guid Entity3Id { get; set; } 16 | public Entity3 Entity3 { get; set; } 17 | public Guid Entity22Id { get; set; } 18 | public Entity22 Entity22 { get; set; } 19 | public ICollection Entities8 { get; set; } 20 | public Entity8 Entity8 { get; set; } 21 | public ICollection Entities26 { get; set; } 22 | public ICollection Entities12 { get; set; } 23 | public ICollection Entities17 { get; set; } 24 | public Entity17 Entitys17 { get; set; } 25 | public ICollection Entities21 { get; set; } 26 | public ICollection Entities16 { get; set; } 27 | } 28 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity21.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity21 : BaseEntity 4 | { 5 | public Guid Entity20Id { get; set; } 6 | public Entity20 Entity20 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity22.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity22 : BaseEntity 4 | { 5 | public Entity22() 6 | { 7 | this.Entities20 = new List(); 8 | this.Entities24 = new List(); 9 | } 10 | public ICollection Entities20 { get; set; } 11 | public ICollection Entities24 { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity23.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity23 : BaseEntity 4 | { 5 | public Guid Entity5Id { get; set; } 6 | public Entity5 Entity5 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity24.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity24 : BaseEntity 4 | { 5 | public Guid Entity3Id { get; set; } 6 | public Entity3 Entity3 { get; set; } 7 | public Guid Entity22Id { get; set; } 8 | public Entity22 Entity22 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity25.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity25 : BaseEntity 4 | { 5 | public Entity25() 6 | { 7 | this.Entities19 = new List(); 8 | } 9 | 10 | public ICollection Entities19 { get; set; } 11 | public Guid? Entity8Id { get; set; } 12 | public Entity8 Entity8 { get; set; } 13 | public Guid? Entity17Id { get; set; } 14 | public Entity17 Entity17 { get; set; } 15 | } 16 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity26.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity26 : BaseEntity 4 | { 5 | public Entity26() 6 | { 7 | this.Entities20 = new List(); 8 | } 9 | 10 | public ICollection Entities20 { get; set; } 11 | } 12 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity3.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity3 : BaseEntity 4 | { 5 | public Entity3() 6 | { 7 | this.Entities4 = new List(); 8 | this.Entities8 = new List(); 9 | } 10 | public ICollection Entities4 { get; set; } 11 | public ICollection Entities8 { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity4.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity4 : BaseEntity 4 | { 5 | public Guid Entity3Id { get; set; } 6 | public Entity3 Entity3 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity5.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity5 : BaseEntity 4 | { 5 | public Entity5() 6 | { 7 | this.Entities6 = new List(); 8 | this.TimeSlots = new List(); 9 | this.Entities5 = new List(); 10 | } 11 | 12 | public Guid? Entity8Id { get; set; } 13 | public Entity8 Entity8 { get; set; } 14 | public Guid? Entity17Id { get; set; } 15 | public Entity17 Entity17 { get; set; } 16 | public Guid? Entity5Id { get; set; } 17 | public Entity5 Entity5Exception { get; set; } 18 | public ICollection Entities5 { get; set; } 19 | public List Entities6 { get; set; } 20 | public ICollection TimeSlots { get; set; } 21 | } 22 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity6.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity6 : BaseEntity 4 | { 5 | public Entity6() 6 | { 7 | this.Entities12 = new List(); 8 | } 9 | 10 | public Guid Entity5Id { get; set; } 11 | public Entity5 Entity5 { get; set; } 12 | public Guid Entity20Id { get; set; } 13 | public Entity20 Entity20 { get; set; } 14 | public ICollection Entities12 { get; set; } 15 | } 16 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity7.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity7 : BaseEntity 4 | { 5 | public Guid Entity25Id { get; set; } 6 | public Entity25 Entity25 { get; set; } 7 | public Guid? Entity14Id { get; set; } 8 | public Entity14 Entity14 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity8.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity8 : BaseEntity 4 | { 5 | public Entity8() 6 | { 7 | this.Entities20 = new List(); 8 | this.Entities22 = new List(); 9 | this.Entities3 = new List(); 10 | this.Entities11 = new List(); 11 | this.Entities17 = new List(); 12 | } 13 | 14 | public ICollection Entities20 { get; set; } 15 | public ICollection Entities17 { get; set; } 16 | public Entity17 Entity17 { get; set; } 17 | public ICollection Entities22 { get; set; } 18 | public Entity22 Entity22 { get; set; } 19 | public ICollection Entities3 { get; set; } 20 | public ICollection Entities11 { get; set; } 21 | public Entity11 Entity11 { get; set; } 22 | } 23 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/Entity9.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDatabaseModel3WithCollections; 2 | 3 | public class Entity9 : BaseEntity 4 | { 5 | public Guid Entity3Id { get; set; } 6 | public Entity3 Entity3 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO1.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO1 : BaseEntity 4 | { 5 | public EntityDTO1() 6 | { 7 | this.Entities2 = new List(); 8 | } 9 | public Guid Entity17Id { get; set; } 10 | public EntityDTO17 Entity17 { get; set; } 11 | public Guid? Entity22Id { get; set; } 12 | public EntityDTO22 Entity22 { get; set; } 13 | public Guid? Entity20Id { get; set; } 14 | public EntityDTO20 Entity20 { get; set; } 15 | public Guid? Entity12Id { get; set; } 16 | public EntityDTO12 Entity12 { get; set; } 17 | public Guid Entity14Id { get; set; } 18 | public EntityDTO14 Entity14 { get; set; } 19 | public Guid Entity8Id { get; set; } 20 | public EntityDTO8 Entity8 { get; set; } 21 | public ICollection Entities2 { get; set; } 22 | } 23 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO10.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO10 : BaseEntity 4 | { 5 | public EntityDTO10() 6 | { 7 | this.Entities11 = new List(); 8 | } 9 | public ICollection Entities11 { get; set; } 10 | } 11 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO11.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO11 : BaseEntity 4 | { 5 | public EntityDTO11() 6 | { 7 | this.Entities10 = new List(); 8 | this.Entities8 = new List(); 9 | } 10 | public ICollection Entities10 { get; set; } 11 | public ICollection Entities8 { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO12.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO12 : BaseEntity 4 | { 5 | public EntityDTO12() 6 | { 7 | this.Entities20 = new List(); 8 | this.Entities14 = new List(); 9 | Entities16 = new List(); 10 | } 11 | public ICollection Entities20 { get; set; } 12 | public ICollection Entities16 { get; set; } 13 | public ICollection Entities14 { get; set; } 14 | } 15 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO13.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO13 : BaseEntity 4 | { 5 | public Guid Entity17Id { get; set; } 6 | public EntityDTO17 Entity17 { get; set; } 7 | public Guid Entity8Id { get; set; } 8 | public EntityDTO8 Entity8 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO14.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO14 : BaseEntity 4 | { 5 | public EntityDTO14() 6 | { 7 | this.Entities12 = new List(); 8 | this.Entities1 = new List(); 9 | } 10 | 11 | //public Address Address { get; set; } 12 | public ICollection Entities12 { get; set; } 13 | public ICollection Entities1 { get; set; } 14 | } 15 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO15.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO15 : BaseEntity 4 | { 5 | public EntityDTO15() 6 | { 7 | } 8 | public Guid Entity17Id { get; set; } 9 | public EntityDTO17 Entity17 { get; set; } 10 | } 11 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO16.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO16 : BaseEntity 4 | { 5 | public Guid Entity20Id { get; set; } 6 | public EntityDTO20 Entity20 { get; set; } 7 | public Guid Entity12Id { get; set; } 8 | public EntityDTO12 Entity12 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO17.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO17 :BaseEntity 4 | { 5 | public EntityDTO17() 6 | { 7 | this.Entities20 = new List(); 8 | this.Entities8 = new List(); 9 | this.Entities5 = new List(); 10 | this.Entities18 = new List(); 11 | } 12 | 13 | public ICollection Entities20 { get; set; } 14 | public ICollection Entities8 { get; set; } 15 | public ICollection Entities5 { get; set; } 16 | public ICollection Entities18 { get; set; } 17 | } 18 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO18.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO18 : BaseEntity 4 | { 5 | public Guid Entity17Id { get; set; } 6 | public EntityDTO17 Entity17 { get; set; } 7 | public Guid Entity20Id { get; set; } 8 | public EntityDTO20 Entity20 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO19.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO19 : BaseEntity 4 | { 5 | public Guid Entity25Id { get; set; } 6 | public EntityDTO25 Entity25 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO2.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO2 : BaseEntity 4 | { 5 | public Guid Entity1Id { get; set; } 6 | public EntityDTO1 Entity1 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO20.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO20 : BaseEntity 4 | { 5 | public EntityDTO20() 6 | { 7 | this.Entities8 = new List(); 8 | this.Entities26 = new List(); 9 | this.Entities12 = new List(); 10 | this.Entities17 = new List(); 11 | this.Entities21 = new List(); 12 | this.Entities16 = new List(); 13 | } 14 | 15 | public Guid Entity3Id { get; set; } 16 | public EntityDTO3 Entity3 { get; set; } 17 | public Guid Entity22Id { get; set; } 18 | public EntityDTO22 Entity22 { get; set; } 19 | public ICollection Entities8 { get; set; } 20 | public ICollection Entities26 { get; set; } 21 | public ICollection Entities12 { get; set; } 22 | public ICollection Entities17 { get; set; } 23 | public ICollection Entities21 { get; set; } 24 | public ICollection Entities16 { get; set; } 25 | } 26 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO21.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO21 : BaseEntity 4 | { 5 | public Guid Entity20Id { get; set; } 6 | public EntityDTO20 Entity20 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO22.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO22 : BaseEntity 4 | { 5 | public EntityDTO22() 6 | { 7 | this.Entities20 = new List(); 8 | this.Entities24 = new List(); 9 | } 10 | public ICollection Entities20 { get; set; } 11 | public ICollection Entities24 { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO23.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO23 : BaseEntity 4 | { 5 | public Guid Entity5Id { get; set; } 6 | public EntityDTO5 Entity5 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO24.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO24 : BaseEntity 4 | { 5 | public Guid Entity3Id { get; set; } 6 | public EntityDTO3 Entity3 { get; set; } 7 | public Guid Entity22Id { get; set; } 8 | public EntityDTO22 Entity22 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO25.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO25 : BaseEntity 4 | { 5 | public EntityDTO25() 6 | { 7 | this.Entities19 = new List(); 8 | } 9 | 10 | public ICollection Entities19 { get; set; } 11 | public Guid? Entity8Id { get; set; } 12 | public EntityDTO8 Entity8 { get; set; } 13 | public Guid? Entity17Id { get; set; } 14 | public EntityDTO17 Entity17 { get; set; } 15 | } 16 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO26.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO26 : BaseEntity 4 | { 5 | public EntityDTO26() 6 | { 7 | this.Entities20 = new List(); 8 | } 9 | 10 | public ICollection Entities20 { get; set; } 11 | } 12 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO3.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO3 : BaseEntity 4 | { 5 | public EntityDTO3() 6 | { 7 | this.Entities4 = new List(); 8 | this.Entities8 = new List(); 9 | } 10 | public ICollection Entities4 { get; set; } 11 | public ICollection Entities8 { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO4.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO4 : BaseEntity 4 | { 5 | public Guid Entity3Id { get; set; } 6 | public EntityDTO3 Entity3 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO5.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO5 : BaseEntity 4 | { 5 | public EntityDTO5() 6 | { 7 | this.Entities6 = new List(); 8 | this.TimeSlots = new List(); 9 | this.Entities5 = new List(); 10 | } 11 | 12 | public Guid? Entity8Id { get; set; } 13 | public EntityDTO8 Entity8 { get; set; } 14 | public Guid? Entity17Id { get; set; } 15 | public EntityDTO17 Entity17 { get; set; } 16 | public Guid? Entity5Id { get; set; } 17 | public EntityDTO5 Entity5Exception { get; set; } 18 | public ICollection Entities5 { get; set; } 19 | public List Entities6 { get; set; } 20 | public ICollection TimeSlots { get; set; } 21 | } 22 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO6.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO6 : BaseEntity 4 | { 5 | public EntityDTO6() 6 | { 7 | this.Entities12 = new List(); 8 | } 9 | 10 | public Guid Entity5Id { get; set; } 11 | public EntityDTO5 Entity5 { get; set; } 12 | public Guid Entity20Id { get; set; } 13 | public EntityDTO20 Entity20 { get; set; } 14 | public ICollection Entities12 { get; set; } 15 | } 16 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO7.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO7 : BaseEntity 4 | { 5 | public Guid Entity25Id { get; set; } 6 | public EntityDTO25 Entity25 { get; set; } 7 | public Guid? Entity14Id { get; set; } 8 | public EntityDTO14 Entity14 { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO8.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO8 : BaseEntity 4 | { 5 | public EntityDTO8() 6 | { 7 | this.Entities20 = new List(); 8 | this.Entities22 = new List(); 9 | this.Entities3 = new List(); 10 | this.Entities11 = new List(); 11 | this.Entities17 = new List(); 12 | } 13 | 14 | public ICollection Entities20 { get; set; } 15 | public ICollection Entities17 { get; set; } 16 | public ICollection Entities22 { get; set; } 17 | public ICollection Entities3 { get; set; } 18 | public ICollection Entities11 { get; set; } 19 | public EntityDTO11 Entity11 { get; set; } 20 | } 21 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapAtRuntimeWithCollections/EntityDTO9.cs: -------------------------------------------------------------------------------- 1 | namespace OmmitedDTOModel3WithCollections; 2 | 3 | public class EntityDTO9 : BaseEntity 4 | { 5 | public Guid Entity3Id { get; set; } 6 | public EntityDTO3 Entity3 { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/MapExpandoObjectProperty.cs: -------------------------------------------------------------------------------- 1 | using System.Dynamic; 2 | 3 | namespace AutoMapper.UnitTests.Bug; 4 | 5 | public class MapExpandoObjectProperty : AutoMapperSpecBase 6 | { 7 | 8 | class From 9 | { 10 | public ExpandoObject ExpandoObject { get; set; } 11 | } 12 | 13 | class To 14 | { 15 | public ExpandoObject ExpandoObject { get; set; } 16 | } 17 | 18 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 19 | { 20 | cfg.CreateMap(); 21 | }); 22 | [Fact] 23 | public void Should_work() 24 | { 25 | dynamic baseSettings = new ExpandoObject(); 26 | var settings = Mapper.Map(new From { ExpandoObject = baseSettings}); 27 | } 28 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/MemberListSourceAndForPath.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class MemberListSourceAndForPath : AutoMapperSpecBase 4 | { 5 | bool _equal; 6 | 7 | public class TargetOuter 8 | { 9 | public TargetInner Inner { get; set; } 10 | 11 | // The properties below should be ignored, they are not relevant 12 | public int Unrelated { get; set; } 13 | public string AlsoUnrelated { get; set; } 14 | } 15 | 16 | public class TargetInner 17 | { 18 | public string MyProp { get; set; } 19 | } 20 | 21 | public class Input 22 | { 23 | public string Source { get; set; } 24 | } 25 | 26 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 27 | { 28 | cfg.CreateMap(MemberList.Source) 29 | .ForPath(x => x.Inner.MyProp, opt => opt.MapFrom(x => x.Source)); 30 | }); 31 | 32 | protected override void Because_of() 33 | { 34 | var input = new Input() {Source = "Hello World!"}; 35 | var output = Mapper.Map(input); 36 | 37 | _equal = output.Inner.MyProp == input.Source; 38 | } 39 | 40 | [Fact] 41 | public void Should_ignore_destination_members() 42 | { 43 | _equal.ShouldBeTrue(); 44 | } 45 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/MissingMapping.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests; 2 | public class MissingMapping : AutoMapperSpecBase 3 | { 4 | public class Source 5 | { 6 | public int Value { get; set; } 7 | } 8 | 9 | public class Dest 10 | { 11 | public int Value { get; set; } 12 | } 13 | 14 | protected override MapperConfiguration CreateConfiguration() => new(c => { }); 15 | 16 | [Fact] 17 | public void Can_not_map_unmapped_type() 18 | { 19 | new Action(() => Mapper.Map(new Source())).ShouldThrow(); 20 | } 21 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/MultipleInterfaceInheritance.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class MultipleInterfaceInheritance : AutoMapperSpecBase 4 | { 5 | private ThingDto _thingDto; 6 | 7 | public class Thing 8 | { 9 | public IItem[] Items { get; set; } 10 | } 11 | 12 | public class ThingDto 13 | { 14 | public ItemDto[] Items { get; set; } 15 | } 16 | 17 | public class Item : IItem 18 | { 19 | } 20 | 21 | public class ItemDto 22 | { 23 | } 24 | 25 | public interface IItem : ISome // everything works well if IItem doesn't inherit ISome. 26 | { 27 | } 28 | 29 | public interface ISome 30 | { 31 | } 32 | 33 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 34 | { 35 | cfg.CreateMap(); 36 | cfg.CreateMap(); 37 | }); 38 | 39 | protected override void Because_of() 40 | { 41 | var thing = new Thing { Items = new[] { new Item() } }; 42 | _thingDto = Mapper.Map(thing); 43 | } 44 | 45 | [Fact] 46 | public void Should_map_successfully() 47 | { 48 | _thingDto.Items.Length.ShouldBe(1); 49 | } 50 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/NonExistingProperty.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class NonExistingProperty : NonValidatingSpecBase 4 | { 5 | public class Source 6 | { 7 | } 8 | 9 | public class Destination 10 | { 11 | } 12 | 13 | [Fact] 14 | public void Should_report_missing_property() 15 | { 16 | new Action(() => new MapperConfiguration(cfg => cfg.CreateMap().ForMember("X", s => { }))).ShouldThrow(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/NullArrayBug.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | public class NullArrayBug : AutoMapperSpecBase 3 | { 4 | private static Source _source; 5 | private Destination _destination; 6 | 7 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 8 | { 9 | cfg.AllowNullCollections = false; 10 | cfg.CreateMap(); 11 | 12 | _source = new Source {Name = null, Data = null}; 13 | }); 14 | 15 | protected override void Because_of() 16 | { 17 | _destination = Mapper.Map(_source); 18 | } 19 | 20 | [Fact] 21 | public void Should_map_name_to_null() 22 | { 23 | _destination.Name.ShouldBeNull(); 24 | } 25 | 26 | [Fact] 27 | public void Should_map_null_array_to_empty() 28 | { 29 | _destination.Data.ShouldNotBeNull(); 30 | _destination.Data.ShouldBeEmpty(); 31 | } 32 | 33 | public class Source 34 | { 35 | public string Name { get; set; } 36 | public string[] Data { get; set; } 37 | } 38 | 39 | public class Destination 40 | { 41 | public string Name { get; set; } 42 | public string[] Data { get; set; } 43 | } 44 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/NullSubstituteInnerClass.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class NullSubstituteInnerClass : AutoMapperSpecBase 4 | { 5 | private FooDto _destination; 6 | 7 | public class Foo 8 | { 9 | public int Id { get; set; } 10 | public Bar Bar { get; set; } 11 | } 12 | 13 | public class Bar 14 | { 15 | public string Name { get; set; } 16 | } 17 | 18 | 19 | public class FooDto 20 | { 21 | public int Id { get; set; } 22 | public BarDto Bar { get; set; } 23 | } 24 | 25 | public class BarDto 26 | { 27 | public string Name { get; set; } 28 | } 29 | 30 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 31 | { 32 | cfg.CreateMap(); 33 | cfg.CreateMap() 34 | .ForMember(dest => dest.Bar, opts => opts.NullSubstitute(new Bar())); 35 | }); 36 | 37 | protected override void Because_of() 38 | { 39 | _destination = Mapper.Map(new Foo() 40 | { 41 | Id = 5, 42 | Bar = null 43 | }); 44 | } 45 | 46 | [Fact] 47 | public void Should_map_int_to_nullable_decimal() 48 | { 49 | _destination.Bar.ShouldNotBeNull(); 50 | } 51 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/NullSubstituteType.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class NullSubstituteType : AutoMapperSpecBase 4 | { 5 | private Destination _destination; 6 | 7 | class Source 8 | { 9 | public long? Number { get; set; } 10 | } 11 | class Destination 12 | { 13 | public long? Number { get; set; } 14 | } 15 | 16 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 17 | { 18 | cfg.CreateMap().ForMember(d => d.Number, o => o.NullSubstitute(0)); 19 | }); 20 | 21 | protected override void Because_of() 22 | { 23 | _destination = Mapper.Map(new Source()); 24 | } 25 | 26 | [Fact] 27 | public void Should_substitute_zero_for_null() 28 | { 29 | _destination.Number.ShouldBe(0); 30 | } 31 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/NullToString.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class NullToString : AutoMapperSpecBase 4 | { 5 | private Destination _destination; 6 | 7 | class Source 8 | { 9 | public InnerSource Inner { get; set; } 10 | } 11 | class InnerSource 12 | { 13 | } 14 | class Destination 15 | { 16 | public string Inner { get; set; } 17 | } 18 | 19 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 20 | { 21 | cfg.CreateMap(); 22 | }); 23 | 24 | protected override void Because_of() 25 | { 26 | _destination = Mapper.Map(new Source()); 27 | } 28 | 29 | [Fact] 30 | public void Should_map_int_to_nullable_decimal() 31 | { 32 | _destination.Inner.ShouldBeNull(); 33 | } 34 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/NullableEnumToNullableValueType.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class NullableEnumToNullableValueType 4 | { 5 | public class CannotConvertEnumToNullableWhenPassedNull : AutoMapperSpecBase 6 | { 7 | public enum DummyTypes : int 8 | { 9 | Foo = 1, 10 | Bar = 2 11 | } 12 | 13 | public class DummySource 14 | { 15 | public DummyTypes? Dummy { get; set; } 16 | } 17 | 18 | public class DummyDestination 19 | { 20 | public int? Dummy { get; set; } 21 | } 22 | 23 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 24 | { 25 | cfg.CreateMap(); 26 | }); 27 | 28 | [Fact] 29 | public void Should_map_null_enum_to_nullable_base_type() 30 | { 31 | DummySource src = new DummySource() { Dummy = null }; 32 | 33 | var destination = Mapper.Map(src); 34 | 35 | destination.Dummy.ShouldBeNull(); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/NullableEnums.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class NullableEnums : AutoMapperSpecBase 4 | { 5 | public class Src { public EnumType? A { get; set; } } 6 | public class Dst { public EnumType? A { get; set; } } 7 | 8 | public enum EnumType { One, Two } 9 | 10 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 11 | { 12 | cfg.CreateMap(); 13 | }); 14 | 15 | [Fact] 16 | public void TestNullableEnum() 17 | { 18 | var d = Mapper.Map(new Src { A = null }, new Dst { A = EnumType.One }); 19 | 20 | d.A.ShouldBeNull(); 21 | } 22 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/NullableIntToNullableEnum.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class NullableIntToNullableEnum : AutoMapperSpecBase 4 | { 5 | Destination _destination; 6 | 7 | public enum Values 8 | { 9 | One = 1, 10 | Two = 2, 11 | Three = 3 12 | } 13 | 14 | public class Source 15 | { 16 | public int? Value { get; set; } 17 | } 18 | 19 | public class Destination 20 | { 21 | public Values? Value { get; set; } 22 | } 23 | 24 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 25 | { 26 | cfg.CreateMap(); 27 | }); 28 | 29 | protected override void Because_of() 30 | { 31 | _destination = Mapper.Map(new Source()); 32 | } 33 | 34 | [Fact] 35 | public void Should_map_null_to_null() 36 | { 37 | _destination.Value.ShouldBeNull(); 38 | } 39 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/NullablePropertiesBug.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class NullablePropertiesBug 4 | { 5 | public class Source { public int? A { get; set; } } 6 | public class Target { public int? A { get; set; } } 7 | 8 | [Fact] 9 | public void Example() 10 | { 11 | 12 | var config = new MapperConfiguration(cfg => cfg.CreateMap()); 13 | 14 | var d = config.CreateMapper().Map(new Source { A = null }, new Target { A = 10 }); 15 | 16 | d.A.ShouldBeNull(); 17 | } 18 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/NullableResolveUsing.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class NullableResolveUsing : AutoMapperSpecBase 4 | { 5 | private Destination _destination; 6 | 7 | class Source 8 | { 9 | public decimal? Number { get; set; } 10 | } 11 | class Destination 12 | { 13 | public decimal? OddNumber { get; set; } 14 | } 15 | 16 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 17 | { 18 | cfg.CreateMap().ForMember(d => d.OddNumber, o => o.MapFrom(s => s.Number)); 19 | }); 20 | 21 | protected override void Because_of() 22 | { 23 | _destination = Mapper.Map(new Source()); 24 | } 25 | 26 | [Fact] 27 | public void Should_map_nullable_decimal_with_ResolveUsing() 28 | { 29 | _destination.OddNumber.ShouldBeNull(); 30 | } 31 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/NullableToInvalid.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class NullableToInvalid : NonValidatingSpecBase 4 | { 5 | public class Source 6 | { 7 | public int? Value { get; set; } 8 | } 9 | 10 | public class Destination 11 | { 12 | public SomeObject Value { get; set; } 13 | } 14 | 15 | public class SomeObject 16 | { 17 | } 18 | 19 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 20 | { 21 | cfg.CreateMap(); 22 | }); 23 | 24 | [Fact] 25 | public void Should_not_validate() 26 | { 27 | new Action(AssertConfigurationIsValid).ShouldThrow(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/NullableUntypedMapFrom.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class NullableUntypedMapFrom : AutoMapperSpecBase 4 | { 5 | private Destination _destination; 6 | 7 | class Source 8 | { 9 | public decimal? Number { get; set; } 10 | } 11 | class Destination 12 | { 13 | public decimal? OddNumber { get; set; } 14 | } 15 | 16 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 17 | { 18 | cfg.CreateMap().ForMember(d => d.OddNumber, o => o.MapFrom(s => (object)s.Number)); 19 | }); 20 | 21 | protected override void Because_of() 22 | { 23 | _destination = Mapper.Map(new Source { Number = 12 }); 24 | } 25 | 26 | [Fact] 27 | public void Should_map_nullable_decimal() 28 | { 29 | _destination.OddNumber.ShouldBe(12); 30 | } 31 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/ObjectEnumToObjectEnum.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class ObjectEnumToObjectEnum : AutoMapperSpecBase 4 | { 5 | Target _target; 6 | 7 | public enum SourceEnumValue 8 | { 9 | Donkey, 10 | Mule 11 | } 12 | 13 | public enum TargetEnumValue 14 | { 15 | Donkey, 16 | Mule 17 | } 18 | 19 | public class Source 20 | { 21 | public object Value { get; set; } 22 | } 23 | 24 | public class Target 25 | { 26 | public object Value { get; set; } 27 | } 28 | 29 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 30 | { 31 | var parentMapping = cfg.CreateMap(); 32 | parentMapping.ForMember(dest => dest.Value, opt => opt.MapFrom(s => (TargetEnumValue) s.Value)); 33 | }); 34 | 35 | protected override void Because_of() 36 | { 37 | _target = Mapper.Map(new Source { Value = SourceEnumValue.Mule }); 38 | } 39 | 40 | [Fact] 41 | public void Should_be_enum() 42 | { 43 | _target.Value.ShouldBeOfType(); 44 | } 45 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/ObjectTypeMapFailure.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class ObjectTypeMapFailure : NonValidatingSpecBase 4 | { 5 | [Fact] 6 | public void Should_map_the_object_type() 7 | { 8 | var displayModel = new DisplayModel 9 | { 10 | Radius = 300 11 | }; 12 | object vm = new SomeViewModel(); 13 | var config = new MapperConfiguration(cfg => cfg.CreateMap()); 14 | 15 | var mapper = config.CreateMapper(); 16 | mapper.Map(displayModel, vm); 17 | ((SomeViewModel)vm).Radius.ShouldBe(300); // fails 18 | 19 | var vm2 = new SomeViewModel(); 20 | mapper.Map(displayModel, vm2); 21 | vm2.Radius.ShouldBe(300); // succeeds 22 | } 23 | 24 | public class SomeViewModel 25 | { 26 | public int Radius { get; set; } 27 | } 28 | 29 | public class DisplayModel 30 | { 31 | public int Radius { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/OneSourceWithMultipleDestinationsAndPreserveReferences.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class OneSourceWithMultipleDestinationsAndPreserveReferences : AutoMapperSpecBase 4 | { 5 | ClientModel _destination; 6 | 7 | public partial class Client 8 | { 9 | public string Address1 { get; set; } 10 | } 11 | public class AddressModel 12 | { 13 | public string Address1 { get; set; } 14 | } 15 | public class ClientModel 16 | { 17 | public AddressModel Address { get; set; } 18 | } 19 | 20 | protected override MapperConfiguration CreateConfiguration() => new(mapConfig => 21 | { 22 | mapConfig.CreateMap() 23 | .ForMember(m => m.Address, opt => opt.MapFrom(x => x)) 24 | .PreserveReferences(); 25 | mapConfig.CreateMap() 26 | .PreserveReferences(); 27 | }); 28 | 29 | protected override void Because_of() 30 | { 31 | _destination = Mapper.Map(new Client { Address1 = "abc" }); 32 | } 33 | 34 | [Fact] 35 | public void Should_map_ok() 36 | { 37 | _destination.Address.Address1.ShouldBe("abc"); 38 | } 39 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/OneSourceWithMultipleDestinationsWithoutPR.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class OneSourceWithMultipleDestinationsWithoutPR : AutoMapperSpecBase 4 | { 5 | ClientModel _destination; 6 | 7 | public partial class Client 8 | { 9 | public string Address1 { get; set; } 10 | } 11 | public class AddressModel 12 | { 13 | public string Address1 { get; set; } 14 | } 15 | public class ClientModel 16 | { 17 | public AddressModel Address { get; set; } 18 | } 19 | 20 | protected override MapperConfiguration CreateConfiguration() => new(mapConfig => 21 | { 22 | mapConfig.CreateMap() 23 | .ForMember(m => m.Address, opt => opt.MapFrom(x => x)); 24 | mapConfig.CreateMap(); 25 | }); 26 | 27 | protected override void Because_of() 28 | { 29 | _destination = Mapper.Map(new Client { Address1 = "abc" }); 30 | } 31 | 32 | [Fact] 33 | public void Should_map_ok() 34 | { 35 | _destination.Address.Address1.ShouldBe("abc"); 36 | } 37 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/ProjectConstructorParameters.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class ProjectConstructorParameters : AutoMapperSpecBase 4 | { 5 | SourceDto _dest; 6 | const int SomeValue = 15; 7 | 8 | public class Inner 9 | { 10 | public int Member { get; set; } 11 | } 12 | 13 | public class Source 14 | { 15 | public int Value { get; set; } 16 | public Inner Inner { get; set; } 17 | } 18 | 19 | public class SourceDto 20 | { 21 | private int _value; 22 | 23 | public SourceDto(int innerMember) 24 | { 25 | _value = innerMember; 26 | } 27 | 28 | public int Value 29 | { 30 | get { return _value; } 31 | } 32 | } 33 | 34 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 35 | { 36 | cfg.CreateProjection(); 37 | }); 38 | 39 | protected override void Because_of() 40 | { 41 | var source = new Source { Inner = new Inner { Member = SomeValue } }; 42 | //_dest = Mapper.Map(source); 43 | _dest = new[] { source }.AsQueryable().ProjectTo(Configuration).First(); 44 | } 45 | 46 | [Fact] 47 | public void Should_project_constructor_parameter_mappings() 48 | { 49 | _dest.Value.ShouldBe(SomeValue); 50 | } 51 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/ProjectUsingTheQueriedEntity.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class ProjectUsingTheQueriedEntity : AutoMapperSpecBase 4 | { 5 | private Destination _destination; 6 | 7 | class Source 8 | { 9 | public int Number { get; set; } 10 | } 11 | class Destination 12 | { 13 | public int Number { get; set; } 14 | } 15 | 16 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 17 | { 18 | cfg.CreateProjection().ConvertUsing(s => new Destination {Number = 23 + s.Number}); 19 | }); 20 | 21 | protected override void Because_of() 22 | { 23 | _destination = new[] { new Source() }.AsQueryable().ProjectTo(Configuration).First(); 24 | } 25 | 26 | [Fact] 27 | public void Should_handle_projectusing_with_the_queried_entity() 28 | { 29 | _destination.Number.ShouldBe(23); 30 | } 31 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/PropertyNamedType.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class PropertyNamedType 4 | { 5 | class Source 6 | { 7 | public int Number { get; set; } 8 | } 9 | class Destination 10 | { 11 | public int Type { get; set; } 12 | } 13 | 14 | [Fact] 15 | public void Should_detect_unmapped_destination_property_named_type() 16 | { 17 | var config = new MapperConfiguration(c=>c.CreateMap()); 18 | new Action(config.AssertConfigurationIsValid).ShouldThrowException( 19 | ex=>ex.Errors[0].UnmappedPropertyNames[0].ShouldBe("Type")); 20 | } 21 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/ReadOnlyCollectionMappingBug.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | // Bug #511 4 | // https://github.com/AutoMapper/AutoMapper/issues/511 5 | public class ReadOnlyCollectionMappingBug 6 | { 7 | class Source { public int X { get; set; } } 8 | class Target { public int X { get; set; } } 9 | 10 | [Fact] 11 | public void Example() 12 | { 13 | var config = new MapperConfiguration(cfg => cfg.CreateMap()); 14 | 15 | var source = new List { new Source { X = 42 } }; 16 | var target = config.CreateMapper().Map>(source); 17 | 18 | target.Count.ShouldBe(source.Count); 19 | target[0].X.ShouldBe(source[0].X); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/ReadOnlyFieldMappingBug.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class ReadOnlyFieldMappingBug : AutoMapperSpecBase 4 | { 5 | public class Source 6 | { 7 | public string Value { get; set; } 8 | } 9 | 10 | public class Destination 11 | { 12 | public readonly string Value; 13 | 14 | public Destination(string value) 15 | { 16 | Value = value; 17 | } 18 | } 19 | 20 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 21 | { 22 | // BUG. ArgumentException : Expression must be writeable 23 | cfg.CreateMap(); 24 | }); 25 | 26 | [Fact] 27 | public void Should_map_over_constructor() 28 | { 29 | var source = new Source { Value = "value" }; 30 | 31 | var dest = Mapper.Map(source); 32 | 33 | dest.Value.ShouldBe(source.Value); 34 | } 35 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/RecognizeDestinationPostfixes.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class RecognizeDestinationPostfixes : AutoMapperSpecBase 4 | { 5 | class Person 6 | { 7 | public int Age { get; set; } 8 | public int Age2 => 2017 - Birthday.Year; 9 | public DateTime Birthday { get; set; } 10 | public string Name { get; set; } 11 | } 12 | 13 | class PersonDto 14 | { 15 | public int AgeV { get; set; } 16 | public string NameV { get; set; } 17 | } 18 | 19 | protected override MapperConfiguration CreateConfiguration() => new(cfg=> 20 | { 21 | cfg.RecognizeDestinationPostfixes("V"); 22 | cfg.CreateMap().ForMember("AgeV", m => m.MapFrom("Age2")); 23 | }); 24 | 25 | [Fact] 26 | public void Should_be_overriden_by_MapFrom() 27 | { 28 | var person = new Person { Birthday = new DateTime(2000, 1, 1), Name = "Shy" }; 29 | Mapper.Map(person).AgeV.ShouldBe(17); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/RemovePrefixes.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class RemovePrefixes : NonValidatingSpecBase 4 | { 5 | class Source 6 | { 7 | public int GetNumber { get; set; } 8 | } 9 | class Destination 10 | { 11 | public int Number { get; set; } 12 | } 13 | 14 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 15 | { 16 | cfg.ClearPrefixes(); 17 | cfg.CreateMap(); 18 | }); 19 | 20 | [Fact] 21 | public void Should_not_map_with_default_postfix() 22 | { 23 | new Action(AssertConfigurationIsValid).ShouldThrow(); 24 | } 25 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/RepeatedMappingConfigurationTest.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class When_mapping_for_derived_class_is_duplicated : NonValidatingSpecBase 4 | { 5 | public class ModelObject 6 | { 7 | public string BaseString { get; set; } 8 | } 9 | 10 | public class ModelSubObject : ModelObject 11 | { 12 | public string SubString { get; set; } 13 | } 14 | 15 | public class DtoObject 16 | { 17 | public string BaseString { get; set; } 18 | } 19 | 20 | public class DtoSubObject : DtoObject 21 | { 22 | public string SubString { get; set; } 23 | } 24 | 25 | [Fact] 26 | public void should_not_throw_duplicated_key_exception() 27 | { 28 | new MapperConfiguration(cfg => 29 | { 30 | cfg.CreateMap() 31 | .Include(); 32 | 33 | cfg.CreateMap(); 34 | 35 | cfg.CreateMap() 36 | .Include(); 37 | 38 | cfg.CreateMap(); 39 | }); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/SelectiveConfigurationValidation.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | public class SelectiveConfigurationValidation : NonValidatingSpecBase 3 | { 4 | public class GoodSrc { } 5 | public class GoodDest { } 6 | 7 | public class BadSrc 8 | { 9 | public Type BlowUp { get; set; } 10 | } 11 | 12 | public class BadDest 13 | { 14 | public int Value { get; set; } 15 | public int BlowUp { get; set; } 16 | } 17 | public class GoodProfile : Profile 18 | { 19 | public GoodProfile() 20 | { 21 | CreateMap(); 22 | } 23 | } 24 | 25 | public class BadProfile : Profile 26 | { 27 | public BadProfile() 28 | { 29 | CreateMap(); 30 | } 31 | } 32 | 33 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 34 | { 35 | cfg.AddProfile(); 36 | cfg.AddProfile(); 37 | }); 38 | 39 | [Fact] 40 | public void Should_pass_specific_profile_assertion() 41 | { 42 | typeof(AutoMapperConfigurationException) 43 | .ShouldNotBeThrownBy(AssertConfigurationIsValid); 44 | } 45 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/SequenceContainsNoElementsTest.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class SequenceContainsNoElementsTest : AutoMapperSpecBase 4 | { 5 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 6 | { 7 | cfg.CreateMap(); 8 | }); 9 | 10 | [Fact] 11 | public void should_not_throw_InvalidOperationException() 12 | { 13 | Person[] personArr = new Person[] { }; 14 | People people = new People(personArr); 15 | var pmc = Mapper.Map>(people); 16 | pmc.ShouldNotBeNull(); 17 | pmc.Count.ShouldBe(0); 18 | } 19 | } 20 | 21 | public class People : IEnumerable 22 | { 23 | private readonly Person[] people; 24 | public People(Person[] people) 25 | { 26 | this.people = people; 27 | } 28 | public IEnumerator GetEnumerator() => people.GetEnumerator(); 29 | } 30 | 31 | public class Person 32 | { 33 | public string Name { get; set; } 34 | } 35 | 36 | public class PersonModel 37 | { 38 | public string Name { get; set; } 39 | } 40 | -------------------------------------------------------------------------------- /src/UnitTests/Bug/SetterOnlyBug.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug 2 | { 3 | namespace SetterOnlyBug 4 | { 5 | public class MappingTests : AutoMapperSpecBase 6 | { 7 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 8 | { 9 | cfg 10 | .CreateMap() 11 | .ForMember("Property", o => o.Ignore()); 12 | }); 13 | 14 | [Fact] 15 | public void TestMapping() 16 | { 17 | var source = new Source 18 | { 19 | Property = "Something" 20 | }; 21 | var destination = Mapper.Map(source); 22 | 23 | destination.GetProperty().ShouldBeNull(); 24 | } 25 | } 26 | 27 | public class Source 28 | { 29 | public string Property { get; set; } 30 | } 31 | 32 | public class Desitination 33 | { 34 | string _property; 35 | 36 | public string Property 37 | { 38 | set { _property = value; } 39 | } 40 | 41 | public string GetProperty() 42 | { 43 | return _property; 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/SubclassMappings.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class SubclassMappings : AutoMapperSpecBase 4 | { 5 | public class Source 6 | { 7 | public string Name { get; set; } 8 | } 9 | 10 | public class Destination 11 | { 12 | public string Name { get; set; } 13 | } 14 | 15 | public class SubDestination : Destination 16 | { 17 | public string SubName { get; set; } 18 | } 19 | 20 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 21 | { 22 | cfg.CreateMap(); 23 | }); 24 | 25 | [Fact] 26 | public void TestCase() 27 | { 28 | 29 | var source = new Source() { Name = "Test" }; 30 | var destination = new Destination(); 31 | 32 | Mapper.Map(source, destination); // Works 33 | 34 | var subDestination = new SubDestination(); 35 | 36 | Mapper.Map(source, subDestination); // Fails 37 | } 38 | } -------------------------------------------------------------------------------- /src/UnitTests/Bug/TargetISet.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class TargetISet : AutoMapperSpecBase 4 | { 5 | Destination _destination; 6 | string[] _items = new[] { "one", "two", "three" }; 7 | 8 | public class Source 9 | { 10 | public IEnumerable Items { get; set; } 11 | } 12 | 13 | class Destination 14 | { 15 | public ISet Items { get; set; } 16 | } 17 | 18 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 19 | { 20 | cfg.CreateMap(); 21 | }); 22 | 23 | protected override void Because_of() 24 | { 25 | _destination = Mapper.Map(new Source { Items = _items }); 26 | } 27 | 28 | [Fact] 29 | public void Should_map_IEnumerable_to_ISet() 30 | { 31 | _destination.Items.SetEquals(_items).ShouldBeTrue(); 32 | } 33 | 34 | [Fact] 35 | public void Should_map_null_to_empty() 36 | { 37 | Mapper.Map(new Source()).ShouldNotBeNull(); 38 | } 39 | } -------------------------------------------------------------------------------- /src/UnitTests/ConfigCompilation.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests; 2 | public class ConfigCompilation : NonValidatingSpecBase 3 | { 4 | public class Source { } 5 | public class Dest { } 6 | public class Source2 { } 7 | public class Dest2 { } 8 | 9 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 10 | { 11 | cfg.CreateMap(); 12 | cfg.CreateMap(); 13 | cfg.CreateMap(typeof(IEnumerable<>), typeof(IEnumerable<>)).ConvertUsing(s => s); 14 | }); 15 | 16 | [Fact] 17 | public void Should_compile_mappings() 18 | { 19 | Configuration.CompileMappings(); 20 | 21 | Mapper.Map(new Source()).ShouldNotBeNull(); 22 | } 23 | } -------------------------------------------------------------------------------- /src/UnitTests/CustomCollectionTester.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests; 2 | public class CustomCollectionTester { 3 | [Fact] 4 | public void Should_be_able_to_handle_custom_dictionary_with_custom_methods() { 5 | var config = new MapperConfiguration(cfg => cfg.CreateMap()); 6 | var mapper = config.CreateMapper(); 7 | } 8 | 9 | public class BaseClassWithDictionary { 10 | public DataDictionary Data { get; set; } 11 | } 12 | 13 | public class DerivedClassWithDictionary : BaseClassWithDictionary { } 14 | 15 | public class DataDictionary : Dictionary { 16 | public string GetString(string name, string @default) { 17 | return null; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/UnitTests/EnumToNullableEnum.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests; 2 | 3 | public class EnumToNullableEnum : AutoMapperSpecBase 4 | { 5 | Destination _destination; 6 | public enum SomeEnum { Foo, Bar } 7 | 8 | public class Source 9 | { 10 | public SomeEnum EnumValue { get; set; } 11 | } 12 | 13 | public class Destination 14 | { 15 | public SomeEnum? EnumValue { get; set; } 16 | } 17 | 18 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 19 | { 20 | cfg.CreateMap(); 21 | }); 22 | 23 | protected override void Because_of() 24 | { 25 | _destination = Mapper.Map(new Source{ EnumValue = SomeEnum.Bar }); 26 | } 27 | 28 | [Fact] 29 | public void Should_map_enum_to_nullable_enum() 30 | { 31 | _destination.EnumValue.ShouldBe(SomeEnum.Bar); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/UnitTests/ExplicitMapperCreation.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests; 2 | public class ExplicitMapperCreation : AutoMapperSpecBase 3 | { 4 | protected override MapperConfiguration CreateConfiguration() =>new(cfg => cfg.CreateMap()); 5 | public class Source 6 | { 7 | public int Value { get; set; } 8 | } 9 | public class Dest 10 | { 11 | public int Value { get; set; } 12 | } 13 | [Fact] 14 | public void Should_map() 15 | { 16 | var source = new Source {Value = 10}; 17 | var dest = Mapper.Map(source); 18 | dest.Value.ShouldBe(source.Value); 19 | } 20 | } -------------------------------------------------------------------------------- /src/UnitTests/IMappingExpression/NonGenericConstructorTests.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Projection; 2 | public class NonGenericConstructorTests : AutoMapperSpecBase 3 | { 4 | private Dest[] _dest; 5 | 6 | public class Source 7 | { 8 | public int Value { get; set; } 9 | } 10 | 11 | public class Dest 12 | { 13 | public Dest() 14 | { 15 | 16 | } 17 | public Dest(int other) 18 | { 19 | Other = other; 20 | } 21 | 22 | public int Value { get; set; } 23 | [IgnoreMap] 24 | public int Other { get; set; } 25 | } 26 | 27 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 28 | { 29 | cfg.AddIgnoreMapAttribute(); 30 | cfg.CreateMap(typeof (Source), typeof (Dest)).ConstructUsing(src => new Dest(((Source)src).Value + 10)); 31 | }); 32 | 33 | protected override void Because_of() 34 | { 35 | var values = new[] 36 | { 37 | new Source() 38 | { 39 | Value = 5 40 | } 41 | }.AsQueryable(); 42 | 43 | _dest = values.ProjectTo(Configuration).ToArray(); 44 | } 45 | 46 | [Fact] 47 | public void Should_construct_correctly() => _dest[0].Other.ShouldBe(15); 48 | } -------------------------------------------------------------------------------- /src/UnitTests/IMappingExpression/NonGenericResolveUsing.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests; 2 | 3 | public class When_using_non_generic_ResolveUsing : AutoMapperSpecBase 4 | { 5 | private Destination _destination; 6 | 7 | public class Source 8 | { 9 | } 10 | public class Destination 11 | { 12 | public int Value { get; set; } 13 | } 14 | 15 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 16 | { 17 | cfg.CreateMap(typeof(Source), typeof(Destination)).ForMember("Value", o => o.MapFrom((src, dest, member, ctx) => 10)); 18 | }); 19 | 20 | protected override void Because_of() 21 | { 22 | _destination = Mapper.Map(new Source()); 23 | } 24 | 25 | [Fact] 26 | public void Should_map_ok() 27 | { 28 | _destination.Value.ShouldBe(10); 29 | } 30 | } -------------------------------------------------------------------------------- /src/UnitTests/IgnoreAllPropertiesWithAnInaccessibleSetterTests.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests; 2 | 3 | public class SomeSource 4 | { 5 | public int IgnoreMe { get; set; } 6 | } 7 | 8 | public class Destination : DestinationBase 9 | { 10 | } 11 | 12 | public class DestinationBase 13 | { 14 | public int IgnoreMe { get; private set; } 15 | } 16 | 17 | public class IgnoreAllPropertiesWithAnInaccessibleSetterTests 18 | { 19 | [Fact] 20 | public void AutoMapper_SimpleObject_IgnoresPrivateSettersInBaseClasses() 21 | { 22 | // Arrange 23 | var config = new MapperConfiguration(cfg => 24 | { 25 | cfg.CreateMap() 26 | .IgnoreAllPropertiesWithAnInaccessibleSetter(); 27 | }); 28 | var mapper = config.CreateMapper(); 29 | 30 | var source = new SomeSource { IgnoreMe = 666 }; 31 | var destination = new Destination(); 32 | 33 | // Act 34 | mapper.Map(source, destination); 35 | 36 | // Assert 37 | config.AssertConfigurationIsValid(); 38 | Assert.Equal(0, destination.IgnoreMe); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/UnitTests/Indexers.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests 2 | { 3 | namespace Indexers 4 | { 5 | public class When_mapping_to_a_destination_with_an_indexer_property : AutoMapperSpecBase 6 | { 7 | private Destination _result; 8 | 9 | public class Source 10 | { 11 | public string Value { get; set; } 12 | } 13 | 14 | public class Destination 15 | { 16 | public string Value { get; set; } 17 | public string this[string key] { get { return null; }} 18 | } 19 | 20 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 21 | { 22 | cfg.CreateMap(); 23 | }); 24 | 25 | protected override void Because_of() 26 | { 27 | _result = Mapper.Map(new Source {Value = "Bob"}); 28 | } 29 | 30 | [Fact] 31 | public void Should_ignore_indexers_and_map_successfully() 32 | { 33 | _result.Value.ShouldBe("Bob"); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/UnitTests/Internal/CreateProxyThreading.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper.Execution; 2 | 3 | namespace AutoMapper.UnitTests; 4 | 5 | public class CreateProxyThreading 6 | { 7 | [Fact] 8 | public async Task Should_create_the_proxy_once() 9 | { 10 | var tasks = Enumerable.Range(0, 5).Select(i => Task.Factory.StartNew(() => 11 | { 12 | ProxyGenerator.GetProxyType(typeof(ISomeDto)); 13 | })).ToArray(); 14 | await Task.WhenAll(tasks); 15 | } 16 | 17 | public interface ISomeDto 18 | { 19 | string Property1 { get; set; } 20 | string Property21 { get; set; } 21 | string Property3 { get; set; } 22 | string Property4 { get; set; } 23 | string Property5 { get; set; } 24 | string Property6 { get; set; } 25 | string Property7 { get; set; } 26 | string Property8 { get; set; } 27 | string Property9 { get; set; } 28 | string Property10 { get; set; } 29 | string Property11 { get; set; } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/UnitTests/Internal/MapperTests.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Tests; 2 | 3 | public class MapperTests : NonValidatingSpecBase 4 | { 5 | public class Source 6 | { 7 | 8 | } 9 | 10 | public class Destination 11 | { 12 | 13 | } 14 | 15 | [Fact] 16 | public void Should_find_configured_type_map_when_two_types_are_configured() 17 | { 18 | var config = new MapperConfiguration(cfg => cfg.CreateMap()); 19 | 20 | config.FindTypeMapFor().ShouldNotBeNull(); 21 | } 22 | } -------------------------------------------------------------------------------- /src/UnitTests/Internal/ObjectFactoryTests.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests; 2 | 3 | using Execution; 4 | public class ObjectFactoryTests 5 | { 6 | [Fact] 7 | public void Test_with_create_ctor() => ObjectFactory.CreateInstance(typeof(ObjectFactoryTests)).ShouldBeOfType(); 8 | [Fact] 9 | public void Test_with_value_object_create_ctor() => ObjectFactory.CreateInstance(typeof(DateTimeOffset)).ShouldBeOfType(); 10 | [Fact] 11 | public void Create_ctor_should_throw_when_default_constructor_is_missing() => 12 | new Action(() => ObjectFactory.CreateInstance(typeof(AssemblyLoadEventArgs))) 13 | .ShouldThrow().Message.ShouldStartWith(typeof(AssemblyLoadEventArgs).FullName); 14 | } -------------------------------------------------------------------------------- /src/UnitTests/Internationalization.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests 2 | { 3 | namespace Internationalization 4 | { 5 | public class When_mapping_a_source_with_non_english_property_names : AutoMapperSpecBase 6 | { 7 | private OrderDto _result; 8 | 9 | public class Order 10 | { 11 | public Customer Customer { get; set; } 12 | } 13 | 14 | public class Customer 15 | { 16 | public string Æøå { get; set; } 17 | } 18 | 19 | public class OrderDto 20 | { 21 | public string CustomerÆøå { get; set; } 22 | } 23 | 24 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 25 | { 26 | cfg.CreateMap(); 27 | }); 28 | 29 | protected override void Because_of() 30 | { 31 | _result = Mapper.Map(new Order {Customer = new Customer {Æøå = "Bob"}}); 32 | } 33 | 34 | [Fact] 35 | public void Should_match_to_identical_property_name_on_destination() 36 | { 37 | _result.CustomerÆøå.ShouldBe("Bob"); 38 | } 39 | } 40 | 41 | } 42 | } -------------------------------------------------------------------------------- /src/UnitTests/Mappers/ConstructorMapperTests.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Mappers; 2 | 3 | public class ConstructorMapperTests : AutoMapperSpecBase 4 | { 5 | class Destination 6 | { 7 | public Destination(string value) 8 | { 9 | Value = value; 10 | } 11 | public string Value { get; } 12 | } 13 | protected override MapperConfiguration CreateConfiguration() => new(_=> { }); 14 | [Fact] 15 | public void Should_use_constructor() => Mapper.Map("value").Value.ShouldBe("value"); 16 | } -------------------------------------------------------------------------------- /src/UnitTests/Mappers/TypeHelperTests.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Mappers; 2 | 3 | public class TypeHelperTests 4 | { 5 | [Fact] 6 | public void CanReturnElementTypeOnCollectionThatImplementsTheSameGenericInterfaceMultipleTimes() 7 | { 8 | Type myType = typeof(ChargeCollection); 9 | 10 | Type elementType = ReflectionHelper.GetElementType(myType); 11 | 12 | elementType.ShouldNotBeNull(); 13 | } 14 | 15 | public class Charge { } 16 | 17 | public interface IChargeCollection : IEnumerable { } 18 | 19 | public class ChargeCollection : Collection, IChargeCollection 20 | { 21 | public new IEnumerator GetEnumerator() 22 | { 23 | return null; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/UnitTests/MappingInheritance/IgnoreShouldBeInheritedIfConventionCannotMap.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class IgnoreShouldBeInheritedIfConventionCannotMap 4 | { 5 | public class BaseDomain 6 | { 7 | 8 | } 9 | 10 | public class StandardDomain : BaseDomain 11 | { 12 | 13 | } 14 | 15 | public class SpecificDomain : StandardDomain 16 | { 17 | } 18 | 19 | public class MoreSpecificDomain : SpecificDomain 20 | { 21 | 22 | } 23 | 24 | public class Dto 25 | { 26 | public string SpecificProperty { get; set; } 27 | } 28 | 29 | [Fact] 30 | public void inhertited_ignore_should_be_overridden_passes_validation() 31 | { 32 | var config = new MapperConfiguration(cfg => 33 | { 34 | cfg.CreateMap() 35 | .ForMember(d => d.SpecificProperty, m => m.Ignore()) 36 | .Include(); 37 | 38 | cfg.CreateMap() 39 | .Include(); 40 | 41 | cfg.CreateMap() 42 | .Include(); 43 | 44 | cfg.CreateMap(); 45 | }); 46 | 47 | config.AssertConfigurationIsValid(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/UnitTests/MappingInheritance/IncludeAllDerived.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.MappingInheritance; 2 | 3 | public class IncludeAllDerived : AutoMapperSpecBase 4 | { 5 | public class A 6 | { 7 | public int Value { get; set; } 8 | } 9 | public class B : A { } 10 | public class C : B { } 11 | public class D : A { } 12 | 13 | public class ADto 14 | { 15 | public int Value { get; set; } 16 | } 17 | 18 | public class BDto : ADto { } 19 | public class CDto : BDto { } 20 | public class DDto : ADto { } 21 | 22 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 23 | { 24 | cfg.CreateMap() 25 | .ForMember(d => d.Value, opt => opt.MapFrom(src => 5)) 26 | .IncludeAllDerived(); 27 | 28 | cfg.CreateMap(); 29 | cfg.CreateMap(); 30 | cfg.CreateMap(); 31 | }); 32 | 33 | [Fact] 34 | public void Should_apply_configuration_to_all_derived() 35 | { 36 | Mapper.Map(new A {Value = 10}).Value.ShouldBe(5); 37 | Mapper.Map(new B {Value = 10}).Value.ShouldBe(5); 38 | Mapper.Map(new C {Value = 10}).Value.ShouldBe(5); 39 | Mapper.Map(new D {Value = 10}).Value.ShouldBe(5); 40 | } 41 | } -------------------------------------------------------------------------------- /src/UnitTests/MappingInheritance/IncludeBaseShouldNotCreateMaps.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.MappingInheritance; 2 | 3 | public class IncludeBaseShouldNotCreateMaps : AutoMapperSpecBase 4 | { 5 | public abstract class BaseBaseSource { } 6 | public class BaseSource : BaseBaseSource 7 | { 8 | public string Foo { get; set; } 9 | } 10 | public class Source : BaseSource { } 11 | 12 | public abstract class BaseBaseDest 13 | { 14 | public string Foo { get; set; } 15 | } 16 | public class BaseDest : BaseBaseDest { } 17 | public class Dest : BaseDest { } 18 | 19 | public class TestProfile : Profile 20 | { 21 | public TestProfile() 22 | { 23 | CreateMap(); 24 | CreateMap() 25 | .IncludeBase(); 26 | } 27 | } 28 | 29 | protected override MapperConfiguration CreateConfiguration() => new(cfg => cfg.AddProfile()); 30 | [Fact] 31 | public void Validate() => AssertConfigurationIsValid(); 32 | } -------------------------------------------------------------------------------- /src/UnitTests/MappingInheritance/IncludeBaseShouldValidateTypes.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests; 2 | 3 | public class IncludeBaseShouldValidateTypes 4 | { 5 | [Fact] 6 | public void Should_throw() 7 | { 8 | new Action(() => 9 | { 10 | var c = new MapperConfiguration(cfg => cfg.CreateMap().IncludeBase()); 11 | }).ShouldThrowException(ex => 12 | { 13 | ex.Message.ShouldStartWith($"{typeof(string)} is not derived from {typeof(int)}."); 14 | }); 15 | } 16 | } -------------------------------------------------------------------------------- /src/UnitTests/MappingInheritance/InheritanceWithoutIncludeShouldWork.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.MappingInheritance; 2 | public class InheritanceWithoutIncludeShouldWork : AutoMapperSpecBase 3 | { 4 | public class FooBase { } 5 | public class Foo : FooBase { } 6 | public class FooDto { public int Value { get; set; } } 7 | 8 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 9 | { 10 | cfg.CreateMap().ForMember(d => d.Value, opt => opt.MapFrom(src => 10)); 11 | cfg.CreateMap().ForMember(d => d.Value, opt => opt.MapFrom(src => 5)); 12 | }); 13 | 14 | [Fact] 15 | public void Should_map_derived() 16 | { 17 | Map(new Foo()).Value.ShouldBe(5); 18 | } 19 | 20 | [Fact] 21 | public void Should_map_base() 22 | { 23 | Map(new FooBase()).Value.ShouldBe(10); 24 | } 25 | 26 | private FooDto Map(FooBase foo) 27 | { 28 | return Mapper.Map(foo); 29 | } 30 | } -------------------------------------------------------------------------------- /src/UnitTests/MappingInheritance/MultipleInheritedBaseMappingsOfSameTypeFails.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Bug; 2 | 3 | public class MultipleMappingsOfSameTypeFails 4 | { 5 | public class MyClass 6 | { 7 | public ActivityBase Information { get; set; } 8 | public InformationClass CurrentInformation { get; set; } 9 | } 10 | 11 | public class MySpecificClass :MyClass{} 12 | 13 | public class MyDto 14 | { 15 | public InformationDto Information { get; set; } 16 | } 17 | 18 | public class MySpecificDto : MyDto{} 19 | public class InformationDto{} 20 | public class ActivityBase{} 21 | public class InformationBase{} 22 | public class InformationClass{} 23 | 24 | [Fact] 25 | public void multiple_inherited_base_mappings_of_same_type_fails() 26 | { 27 | var config = new MapperConfiguration(cfg => 28 | { 29 | cfg.CreateMap() 30 | .ForMember(d => d.Information, m => m.MapFrom(s => s.CurrentInformation)) 31 | .Include(); 32 | cfg.CreateMap(); 33 | 34 | cfg.CreateMap(); 35 | }); 36 | 37 | 38 | config.AssertConfigurationIsValid(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/UnitTests/Projection/ExplicitValues.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Projection; 2 | public class ExplicitValues : AutoMapperSpecBase 3 | { 4 | private List _dests; 5 | 6 | public class Source 7 | { 8 | public int Value { get; set; } 9 | } 10 | 11 | public class Dest 12 | { 13 | public int Value { get; set; } 14 | } 15 | 16 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 17 | { 18 | cfg.CreateProjection() 19 | .ForMember(dest => dest.Value, opt => opt.MapFrom(src => 5)); 20 | }); 21 | 22 | protected override void Because_of() 23 | { 24 | var source = new[] { new Source { Value = 10 } }.AsQueryable(); 25 | 26 | _dests = source.ProjectTo(Configuration).ToList(); 27 | } 28 | 29 | [Fact] 30 | public void Should_substitute_value() 31 | { 32 | _dests[0].Value.ShouldBe(5); 33 | } 34 | } -------------------------------------------------------------------------------- /src/UnitTests/Projection/GenericsTests.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Projection; 2 | public class GenericsTests : AutoMapperSpecBase 3 | { 4 | private Dest[] _dests; 5 | 6 | public class Source 7 | { 8 | public T Value { get; set; } 9 | } 10 | 11 | public class Dest 12 | { 13 | public T Value { get; set; } 14 | } 15 | 16 | protected override MapperConfiguration CreateConfiguration() => new(cfg => 17 | { 18 | cfg.CreateMap(typeof (Source<>), typeof (Dest<>)); 19 | }); 20 | 21 | protected override void Because_of() 22 | { 23 | var sources = new[] 24 | { 25 | new Source 26 | { 27 | Value = "5" 28 | } 29 | }.AsQueryable(); 30 | 31 | _dests = sources.ProjectTo>(Configuration).ToArray(); 32 | } 33 | 34 | [Fact] 35 | public void Should_convert_even_though_mapper_not_explicitly_called_before_hand() 36 | { 37 | _dests[0].Value.ShouldBe("5"); 38 | } 39 | } -------------------------------------------------------------------------------- /src/UnitTests/Projection/MoreExplanatoryExceptionTests.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Projection; 2 | 3 | public class MoreExplanatoryExceptionTests 4 | { 5 | [Fact] 6 | public void ConstructorWithUnknownParameterTypeThrowsExplicitException() 7 | { 8 | // Arrange 9 | var config = new MapperConfiguration(cfg => 10 | cfg.CreateProjection()); 11 | 12 | // Act 13 | var exception = Assert.Throws(() => 14 | new EntitySource[0].AsQueryable().ProjectTo(config)); 15 | 16 | // Assert 17 | Assert.Contains("parameter notSupported", exception.Message, StringComparison.OrdinalIgnoreCase); 18 | } 19 | 20 | class EntitySource 21 | { 22 | public DateTime NotSupported; 23 | } 24 | class EntityDestination 25 | { 26 | public EntityDestination(int notSupported = 0) { } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/UnitTests/Projection/RecursiveQuery.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests.Projection; 2 | 3 | public class RecursiveQuery : AutoMapperSpecBase 4 | { 5 | class Source 6 | { 7 | public int Id { get; set; } 8 | public Source Parent { get; set; } 9 | } 10 | class Destination 11 | { 12 | public int Id { get; set; } 13 | public Destination Parent { get; set; } 14 | } 15 | protected override MapperConfiguration CreateConfiguration() => new(c=> 16 | { 17 | c.CreateProjection(); 18 | c.Internal().RecursiveQueriesMaxDepth = 1; 19 | }); 20 | [Fact] 21 | public void Should_work() 22 | { 23 | var source = new[] { new Source { Id = 1, Parent = new Source { Id = 2, Parent = new Source { } } }, new Source { Id = 3, Parent = new Source { Id = 4, Parent = new Source { } } } }; 24 | var result = ProjectTo(source.AsQueryable()).ToArray(); 25 | result[0].Id.ShouldBe(1); 26 | result[0].Parent.Id.ShouldBe(2); 27 | result[0].Parent.Parent.ShouldBeNull(); 28 | result[1].Id.ShouldBe(3); 29 | result[1].Parent.Id.ShouldBe(4); 30 | result[1].Parent.Parent.ShouldBeNull(); 31 | } 32 | } -------------------------------------------------------------------------------- /src/UnitTests/SeparateConfiguration.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests; 2 | public class SeparateConfiguration : NonValidatingSpecBase 3 | { 4 | public class Source 5 | { 6 | public int Value { get; set; } 7 | } 8 | public class Dest 9 | { 10 | public int Value { get; set; } 11 | } 12 | protected override MapperConfiguration CreateConfiguration() 13 | { 14 | var expr = new MapperConfigurationExpression(); 15 | 16 | expr.CreateMap(); 17 | 18 | return new MapperConfiguration(expr); 19 | } 20 | 21 | [Fact] 22 | public void Should_use_passed_in_configuration() 23 | { 24 | var source = new Source {Value = 5}; 25 | var dest = Mapper.Map(source); 26 | 27 | dest.Value.ShouldBe(source.Value); 28 | } 29 | } -------------------------------------------------------------------------------- /src/UnitTests/TesterExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests; 2 | 3 | public static class StopgapNBehaveExtensions 4 | { 5 | public static void ShouldBeOfLength(this IEnumerable collection, int length) 6 | { 7 | collection.ShouldNotBeNull(); 8 | collection.Count().ShouldBe(length); 9 | } 10 | } -------------------------------------------------------------------------------- /src/UnitTests/TypeExtensionsTests.cs: -------------------------------------------------------------------------------- 1 | namespace AutoMapper.UnitTests; 2 | public class TypeExtensionsTests 3 | { 4 | public class Foo 5 | { 6 | public Foo() 7 | { 8 | Value2 = "adsf"; 9 | Value4 = "Fasdfadsf"; 10 | } 11 | 12 | public string Value1 { get; set; } 13 | public string Value2 { get; private set; } 14 | protected string Value3 { get; set; } 15 | private string Value4 { get; set; } 16 | public string Value5 => "ASDf"; 17 | public string Value6 { set { Value4 = value; } } 18 | 19 | [Fact] 20 | public void Should_recognize_public_members() 21 | { 22 | // typeof(Foo).GetProperties().Length.ShouldBe(4); 23 | } 24 | } 25 | } --------------------------------------------------------------------------------