From 4cb03742db914ddbfd49ee84f24903bcd9f09e09 Mon Sep 17 00:00:00 2001 From: Bethany Maloney <42630535+bethmaloney@users.noreply.github.com> Date: Wed, 28 Feb 2024 16:39:37 +1100 Subject: [PATCH] Normalize line endings (#642) +semver:patch --- .editorconfig | 4 - .gitattributes | 30 +- CODEOFCONDUCT.md | 46 +- CONTRIBUTING.md | 19 +- README.md | 82 +- .../CascadeConvention.cs | 52 +- .../Entities/Employee.cs | 16 +- .../Entities/Location.cs | 12 +- .../Entities/Product.cs | 32 +- .../Entities/Store.cs | 56 +- .../ExampleAutomappingConfiguration.cs | 54 +- .../Examples.FirstAutomappedProject.csproj | 48 +- .../Program.cs | 340 +-- .../Properties/AssemblyInfo.cs | 8 +- .../Entities/Employee.cs | 20 +- src/Examples.FirstProject/Entities/Product.cs | 44 +- src/Examples.FirstProject/Entities/Store.cs | 56 +- .../Examples.FirstProject.csproj | 48 +- .../Mappings/EmployeeMap.cs | 28 +- .../Mappings/LocationMap.cs | 24 +- .../Mappings/ProductMap.cs | 38 +- .../Mappings/StoreMap.cs | 36 +- src/Examples.FirstProject/Program.cs | 272 +- .../Properties/AssemblyInfo.cs | 8 +- .../Component.cs | 4 +- .../Entity.cs | 102 +- ...ntNHibernate.Specs.ExternalFixtures.csproj | 20 +- .../Overrides/EntityBatchSizeOverride.cs | 22 +- .../Properties/AssemblyInfo.cs | 8 +- .../AutoMapBackwardsCompatibilitySpecs.cs | 92 +- .../AutoPersistenceModelSpecs.Conventions.cs | 204 +- .../Automapping/AutoPersistenceModelSpecs.cs | 226 +- .../AutomappingSpecs.Components.cs | 302 +-- .../AutomappingSpecs.ElementCollections.cs | 384 +-- .../AutomappingSpecs.NestedClasses.cs | 196 +- .../AutomappingSpecs.Properties.Enum.cs | 158 +- .../AutomappingSpecs.Relationships.cs | 446 ++-- .../Automapping/AutomappingSpecs.Version.cs | 112 +- .../Fixtures/AutomappingSpecExtensions.cs | 222 +- .../Automapping/Fixtures/DictionaryEntity.cs | 22 +- .../Fixtures/EntityUsingPrivateFields.cs | 30 +- .../Fixtures/EntityWithStaticProperties.cs | 12 +- .../Automapping/Fixtures/FakeMembers.cs | 80 +- .../Fixtures/Overrides/EntityTableOverride.cs | 24 +- .../ParentChildSelfReferenceEntity.cs | 18 +- .../Fixtures/ReadOnlyEnumerableEntity.cs | 30 +- .../Fixtures/SelfReferenceEntity.cs | 12 +- .../SelfReferencingCollectionEntity.cs | 16 +- .../Automapping/Fixtures/StubTypeSource.cs | 58 +- .../Automapping/Fixtures/UserTypes.cs | 352 +-- .../Automapping/Fixtures/VersionedEntity.cs | 14 +- .../Automapping/OverrideSpecs.cs | 300 +-- .../Automapping/PrivateAutomapperSpecs.cs | 68 +- .../Automapping/PrivateFieldsSpecs.cs | 74 +- .../Conventions/ApplyFilterSpecs.cs | 182 +- .../Conventions/BiDirectionalKeysSpecs.cs | 70 +- .../Conventions/CollectionTypeChangeSpecs.cs | 74 +- .../Conventions/ComponentConventionSpecs.cs | 162 +- .../Conventions/ConventionBuilderSpecs.cs | 68 +- .../Conventions/Fixtures/Child.cs | 36 +- .../Fixtures/CollectionConvention.cs | 30 +- .../Conventions/Fixtures/CollectionTarget.cs | 66 +- .../Fixtures/FilterClassConvention.cs | 72 +- .../Conventions/Fixtures/FilterTarget.cs | 66 +- .../Conventions/Fixtures/FormulaConvention.cs | 36 +- .../Conventions/Fixtures/FormulaTarget.cs | 38 +- .../Conventions/Fixtures/Parent.cs | 36 +- .../Fixtures/SetCollectionEntity.cs | 16 +- .../Fixtures/SetCollectionEntityMap.cs | 22 +- .../SetCompositeElementCollectionEntity.cs | 16 +- .../SetCompositeElementCollectionEntityMap.cs | 24 +- .../Fixtures/SetElementCollectionEntity.cs | 16 +- .../Fixtures/SetElementCollectionEntityMap.cs | 24 +- .../Conventions/Fixtures/TwoPropertyEntity.cs | 14 +- .../Fixtures/TwoPropertyEntityMap.cs | 24 +- .../Conventions/Fixtures/Value.cs | 10 +- .../Conventions/ForeignKeyConventionSpecs.cs | 128 +- .../Conventions/FormulaConventionSpecs.cs | 106 +- .../Registration_diagnostics_specs.cs | 800 +++--- src/FluentNHibernate.Specs/Extensions.cs | 92 +- .../BiDirectionalKeyIssueSpecs.cs | 58 +- .../ClassMapSpecs/ClassMapSpecs.Cache.cs | 40 +- .../ClassMapSpecs/ClassMapSpecs.Component.cs | 232 +- .../ClassMapSpecs.Discriminator.cs | 72 +- .../ClassMapSpecs/ClassMapSpecs.HasMany.cs | 230 +- .../ClassMapSpecs/ClassMapSpecs.HasOne.cs | 48 +- .../ClassMapSpecs/ClassMapSpecs.Id.cs | 98 +- .../ClassMapSpecs/ClassMapSpecs.Property.cs | 88 +- .../ClassMapSpecs/ClassMapSpecs.Subclass.cs | 90 +- .../ClassMapSpecs/ClassMapSpecs.Version.cs | 80 +- .../FluentInterface/ClasslikeBehaviors.cs | 396 +-- .../FluentInterface/ComponentMapSpecs.cs | 676 ++--- .../ExternalComponentOutputSpecs.cs | 144 +- .../Fixtures/BiDirectionalKeyIssue.cs | 154 +- .../Fixtures/EntityWithCollections.cs | 58 +- .../Fixtures/EntityWithComponent.cs | 38 +- .../Fixtures/EntityWithFields.cs | 10 +- .../Fixtures/EntityWithProperties.cs | 22 +- .../Fixtures/EntityWithReferences.cs | 16 +- .../Fixtures/EntityWithVersion.cs | 14 +- .../FluentInterface/Fixtures/IndexTarget.cs | 6 +- .../FluentInterface/Fixtures/SuperTarget.cs | 24 +- .../FluentInterface/ProviderSpec.cs | 52 +- .../SubclassMapSpecs.Component.cs | 190 +- .../SubclassMapSpecs.HasMany.cs | 158 +- .../SubclassMapSpecs.HasOne.cs | 48 +- .../SubclassMapSpecs.Property.cs | 70 +- .../FluentNHibernate.Specs.csproj | 42 +- .../Fixtures/UnionChildEntity.cs | 6 +- .../Fixtures/UnionChildEntityMap.cs | 10 +- .../PersistenceModel/Fixtures/UnionEntity.cs | 10 +- .../Fixtures/UnionEntityMap.cs | 22 +- .../PersistenceModelSpecs.AddingProviders.cs | 122 +- .../PersistenceModelSpecs.Validation.cs | 258 +- .../PersistenceModel/SubclassSpecs.cs | 210 +- .../Properties/AssemblyInfo.cs | 10 +- .../SerializableSpecs.cs | 54 +- .../Utilities/Fixtures/Target.cs | 22 +- .../Utilities/Fixtures/TargetParent.cs | 10 +- .../Utilities/MemberReflectionSpecs.cs | 392 +-- .../Utilities/RevealSpecs.cs | 286 +-- ...irectionalManyToManyPairingVisitorSpecs.cs | 578 ++--- .../AutoMapping/Apm/AbstractBaseClassTests.cs | 140 +- .../Apm/AlterationCollectionTests.cs | 130 +- .../AutoMapping/Apm/AlterationTests.cs | 78 +- .../AutoPersistenceModelTests.Components.cs | 362 +-- .../AutoPersistenceModelTests.Conventions.cs | 352 +-- ...ersistenceModelTests.IgnoringProperties.cs | 170 +- .../AutoPersistenceModelTests.Inheritance.cs | 434 ++-- .../AutoPersistenceModelTests.Overrides.cs | 732 +++--- .../Apm/AutoPersistenceModelTests.cs | 282 +-- .../AutoMapping/Apm/CacheOverrideTests.cs | 56 +- .../AutoMapping/Apm/ConcreteBaseClassTests.cs | 98 +- .../Apm/Conventions/HasManyConventionTests.cs | 138 +- .../HasManyToManyConventionTests.cs | 74 +- .../Conventions/IdentityConventionTests.cs | 80 +- .../Conventions/ReferencesConventionTests.cs | 66 +- .../Apm/Conventions/VersionConventionTests.cs | 78 +- .../AutoMapping/Apm/GenericBaseClassTests.cs | 78 +- .../AutoMapping/Apm/IdentityTests.cs | 136 +- .../IgnoreBaseAutoPersistenceModelTests.cs | 88 +- .../AutoMapping/AutoMapTests.cs | 276 +- .../AutoMapping/AutoMappingTester.cs | 34 +- .../AutoMapping/BaseAutoMapFixture.cs | 74 +- .../AutoMapping/BaseAutoPersistenceTests.cs | 36 +- .../DefaultAutoMappingConfigurationTests.cs | 52 +- .../AutoMapping/InheritanceTests.cs | 144 +- .../JoinedSubclassConventionTests.cs | 36 +- .../AutoMapping/ManyToMany.cs | 50 +- .../AutoMappingOverrideAlterationTests.cs | 108 +- .../Overrides/ClassMappingOverrides.cs | 104 +- .../Overrides/CompositeIdOverrides.cs | 232 +- .../Overrides/HibernateMappingOverrides.cs | 48 +- .../ParentOverridesWithSubclasses.cs | 196 +- .../AutoMapping/Steps/HasManyStepTests.cs | 212 +- .../Steps/HasManyToManyStepTests.cs | 72 +- .../AutoMapping/Steps/ReferenceStepTests.cs | 132 +- .../AutoMapping/Steps/VersionStepTests.cs | 342 +-- .../AutoMapping/TestFixtures.cs | 1050 ++++---- .../UnionSubclassConventionTests.cs | 86 +- .../AutoMapping/UnionSubclassTests.cs | 36 +- .../AutoMapping/VersionTests.cs | 94 +- .../Cfg/Db/CacheSettingsBuilderTester.cs | 236 +- .../Cfg/Db/ConnectionStringBuilderTester.cs | 98 +- .../Cfg/Db/DB2400ConfigurationTester.cs | 140 +- .../Cfg/Db/DB2ConfigurationTester.cs | 154 +- .../Cfg/Db/FirebirdConfigurationTester.cs | 100 +- .../Cfg/Db/IngresConfigurationTester.cs | 146 +- .../Cfg/Db/JetDriverConfigurationTester.cs | 170 +- .../Cfg/Db/MsSqlCeConfigurationTester.cs | 60 +- .../Cfg/Db/MsSqlConfigurationTester.cs | 236 +- .../Cfg/Db/MySQLConfigurationTester.cs | 142 +- .../Cfg/Db/OracleClientConfigurationTester.cs | 278 +- .../Db/OracleDataClientConfigurationTester.cs | 282 +-- ...cleManagedDataClientConfigurationTester.cs | 282 +-- .../Cfg/Db/PersistenceConfigurationTester.cs | 310 +-- .../Cfg/Db/PostgreSQLConfigurationTester.cs | 190 +- .../Cfg/Db/SQLiteConfigurationTester.cs | 76 +- .../Cfg/Db/SqlAnywhereConfigurationTester.cs | 98 +- .../Cfg/ExceptionSerializationTests.cs | 104 +- .../Cfg/FluentConfigurationTests.cs | 890 +++---- .../Cfg/FluentlyTests.cs | 52 +- .../Cfg/MappingConfigurationTests.cs | 364 +-- .../ConventionFinderTests/AddingTypeTests.cs | 162 +- .../ConventionFinderTests/FindTests.cs | 300 +-- .../PropertyAcceptanceCriteriaAnyTests.cs | 226 +- ...opertyAcceptanceCriteriaCollectionTests.cs | 250 +- ...AcceptanceCriteriaEqualComplexTypeTests.cs | 174 +- ...eptanceCriteriaEqualSimpleTypeEvalTests.cs | 170 +- ...yAcceptanceCriteriaEqualSimpleTypeTests.cs | 170 +- ...AcceptanceCriteriaEqualSubPropertyTests.cs | 68 +- ...pertyAcceptanceCriteriaInheritanceTests.cs | 158 +- .../PropertyAcceptanceCriteriaIsAnyTests.cs | 174 +- .../PropertyAcceptanceCriteriaIsSetTests.cs | 370 +-- .../PropertyAcceptanceCriteriaTests.cs | 186 +- .../ConventionsTests/AccessConventionTests.cs | 274 +- .../ApplyingToModel/ArrayConventionTests.cs | 392 +-- .../ApplyingToModel/ClassConventionTests.cs | 320 +-- .../ComponentConventionTests.cs | 174 +- .../CompositeIdConventionTests.cs | 146 +- .../DynamicComponentConventionTests.cs | 186 +- .../HasManyCollectionConventionTests.cs | 542 ++-- .../ApplyingToModel/HasManyConventionTests.cs | 504 ++-- .../HasManyToManyCollectionConventionTests.cs | 424 ++-- .../HasManyToManyConventionTests.cs | 516 ++-- .../ApplyingToModel/HasOneConventionTests.cs | 228 +- .../HibernateMappingConventionTests.cs | 184 +- .../ApplyingToModel/IdConventionTests.cs | 404 +-- .../ApplyingToModel/JoinConventionTests.cs | 194 +- .../JoinedSubclassConventionTests.cs | 294 +-- .../KeyManyToOneConventionTests.cs | 166 +- .../KeyPropertyConventionTests.cs | 132 +- .../ManyToOneConventionTests.cs | 394 +-- .../PropertyConventionTests.cs | 466 ++-- .../SubclassConventionTests.cs | 200 +- .../ApplyingToModel/VersionConventionTests.cs | 340 +-- .../ConventionsTests/AutoImportHelperTests.cs | 70 +- .../ConventionsCollectionTests.cs | 136 +- .../DefaultAccessHelperTests.cs | 70 +- .../DefaultCascadeHelperTests.cs | 70 +- .../DefaultLazyHelperTests.cs | 94 +- .../EnumerationPropertyConventionTests.cs | 184 +- .../HasManyForeignKeyNameConventionTests.cs | 136 +- ...cessorBackingFieldNamingConventionTests.cs | 114 +- ...anyToManyChildForeignKeyConventionTests.cs | 92 +- ...sManyToManyJoinTableNameConventionTests.cs | 116 +- ...cessorBackingFieldNamingConventionTests.cs | 114 +- ...lableEnumerationPropertyConventionTests.cs | 172 +- .../Defaults/PrimaryKeyConventionTests.cs | 110 +- .../Defaults/PropertyTypeConventionTests.cs | 238 +- .../ReferenceForeignKeyConventionTests.cs | 118 +- .../Defaults/TableNameConventionTests.cs | 112 +- .../VersionColumnNameConventionTests.cs | 112 +- .../ForeignKeyConventionTests.cs | 232 +- .../ConventionsTests/ForeignKeyHelperTests.cs | 184 +- .../Inspection/AccessTests.cs | 272 +- .../Inspection/CascadeTests.cs | 112 +- .../ConventionsTests/Inspection/FetchTests.cs | 74 +- .../Inspection/GeneratedTests.cs | 74 +- .../Inspection/IncludeTests.cs | 74 +- .../Inspection/NotFoundTests.cs | 62 +- .../Inspection/OnDeleteTests.cs | 62 +- .../Inspection/OptimisticLockTests.cs | 86 +- .../Inspection/PolymorphismTests.cs | 62 +- .../Inspection/SchemaActionTests.cs | 122 +- .../MixedConventionInstanceTester.cs | 76 +- .../MultipleHelperConventions.cs | 76 +- .../ConventionsTests/OptionalAcceptTests.cs | 186 +- .../ArrayConventionTests.cs | 464 ++-- .../ClassConventionTests.cs | 378 +-- .../ComponentConventionTests.cs | 214 +- .../CompositeIdConventionTests.cs | 178 +- .../DynamicComponentConventionTests.cs | 226 +- .../HasManyCollectionConventionTests.cs | 560 ++--- .../HasManyConventionTests.cs | 582 ++--- .../HasManyToManyCollectionConventionTests.cs | 520 ++-- .../HasManyToManyConventionTests.cs | 602 ++--- .../HasOneConventionTests.cs | 280 +-- .../HibernateMappingConventionTests.cs | 232 +- .../IdConventionTests.cs | 418 +-- .../JoinConventionTests.cs | 236 +- .../JoinedSubclassConventionTests.cs | 362 +-- .../KeyManyToOneConventionTests.cs | 194 +- .../KeyPropertyConventionTests.cs | 134 +- .../ManyToOneConventionTests.cs | 466 ++-- .../PropertyConventionTests.cs | 574 ++--- .../SubclassConventionTests.cs | 264 +- .../VersionConventionTests.cs | 422 ++-- .../ConventionsTests/ProxyConventionTester.cs | 422 ++-- .../ConventionsTests/ProxyHelperTests.cs | 56 +- .../RunnableConventionsTests.cs | 1504 +++++------ src/FluentNHibernate.Testing/Debugging.cs | 26 +- .../DefaultOutputFormatterTests.cs | 184 +- .../DiagnosticConfigurationTests.cs | 136 +- .../Diagnostics/DiagnosticLoggerTests.cs | 332 +-- .../DiagnosticMessageDespatcherTests.cs | 66 +- .../StringLambdaOutputListenerTests.cs | 74 +- .../DomainModel/Access/ComponentModel.cs | 20 +- .../DomainModel/Access/CompositeIdModel.cs | 54 +- .../DomainModel/Access/ManyToManyModel.cs | 24 +- .../DomainModel/Access/ManyToOneModel.cs | 22 +- .../Mappings/CompositeIdModelMapping.cs | 32 +- .../Access/Mappings/ManyToManyModelMapping.cs | 30 +- .../Access/Mappings/ManyToOneModelMapping.cs | 30 +- .../Access/Mappings/OneToOneModelMapping.cs | 28 +- .../Access/Mappings/ParentModelMapping.cs | 92 +- .../DomainModel/Access/OneToOneModel.cs | 20 +- .../DomainModel/Access/ParentModel.cs | 60 +- .../DomainModel/ConnectedTester.cs | 356 +-- .../DomainModel/Employees.cs | 72 +- .../DomainModel/EntityEquality.cs | 186 +- .../DomainModel/InverseOneToManyTester.cs | 162 +- .../AccessStrategyComponentPartTester.cs | 330 +-- .../AccessStrategyManyToOnePartTester.cs | 466 ++-- .../DomainModel/Mapping/AnyPartTester.cs | 394 +-- .../Mapping/CascadeExpressionTester.cs | 202 +- .../DomainModel/Mapping/ClassCacheTests.cs | 146 +- .../Mapping/ClassMapConventionsTester.cs | 224 +- .../Mapping/ClassMapDynamicInsertTester.cs | 44 +- .../Mapping/ClassMapDynamicUpdateTester.cs | 44 +- .../Mapping/ClassMapOptimisticLockTester.cs | 76 +- .../Mapping/ClassMapXmlCreationTester.cs | 1220 ++++----- .../CollectionCascadeExpressionTester.cs | 60 +- .../Mapping/ComponentElementPartTester.cs | 166 +- .../Mapping/ComponentPartTester.cs | 214 +- .../Mapping/ComponentPropertyMapTester.cs | 550 ++-- .../Mapping/CompositeIdentityPartTester.cs | 436 ++-- .../DomainModel/Mapping/ConventionsTester.cs | 136 +- .../DefaultAccessStrategyClassMapTester.cs | 346 +-- .../Mapping/DynamicComponentTester.cs | 328 +-- .../Mapping/FetchTypeExpressionTester.cs | 100 +- .../DomainModel/Mapping/FilterTester.cs | 382 +-- .../DomainModel/Mapping/HbmAttributeTests.cs | 60 +- .../DomainModel/Mapping/IdentityPartTester.cs | 1078 ++++---- .../DomainModel/Mapping/ImportTester.cs | 64 +- .../DomainModel/Mapping/JoinPartTester.cs | 266 +- .../Mapping/JoinedSubClassTester.cs | 478 ++-- .../Mapping/ManyToManyIntegrationTester.cs | 98 +- .../DomainModel/Mapping/ManyToManyTester.cs | 674 ++--- .../DomainModel/Mapping/ManyToOneTester.cs | 354 +-- .../Mapping/MappingPartOutputOrderTests.cs | 176 +- .../DomainModel/Mapping/MappingTester.cs | 396 +-- .../Mapping/MultipleKeyColumnsTester.cs | 68 +- .../Mapping/OneToManyIntegrationTester.cs | 106 +- .../DomainModel/Mapping/OneToManyTester.cs | 1988 +++++++-------- .../DomainModel/Mapping/OneToOneTester.cs | 200 +- .../DomainModel/Mapping/PropertyPartTester.cs | 1340 +++++----- .../Mapping/StoredProcedureTests.cs | 124 +- .../DomainModel/Mapping/SubClassTester.cs | 1246 ++++----- .../Mapping/UnionSubclassTester.cs | 92 +- .../DomainModel/Mapping/VersionTester.cs | 192 +- .../DomainModel/Mapping/WhereTester.cs | 38 +- .../DomainModel/MemberAccessResolverTests.cs | 190 +- .../DomainModel/MemberBackingFieldTests.cs | 384 +-- .../DomainModel/Music.cs | 122 +- .../DomainModel/NamingTests.cs | 154 +- .../DomainModel/RevealTests.cs | 120 +- src/FluentNHibernate.Testing/EmptySource.cs | 46 +- .../ExpressionToSqlTests.cs | 388 +-- .../AbstractOverride.cs | 22 +- .../AbstractOverrideImplementation.cs | 14 +- .../DummyAlteration1.cs | 22 +- .../DummyAlteration2.cs | 22 +- .../AutoMappingAlterations/DummyOverride.cs | 24 +- .../AutoMappingAlterations/Model/Baz.cs | 12 +- .../AutoMappingAlterations/Model/Qux.cs | 12 +- .../Fixtures/Basic/Person.cs | 12 +- .../Fixtures/HbmOne.cs | 12 +- .../Fixtures/HbmTwo.cs | 18 +- .../MixedMappingsInSameLocation/Bar.cs | 12 +- .../MixedMappingsInSameLocation/Foo.cs | 12 +- .../Mappings/FooMap.cs | 22 +- .../Fixtures/TestPersistenceModel.cs | 20 +- .../AnyMutablePropertyModelGenerationTests.cs | 584 ++--- .../FluentInterfaceTests/BaseModelFixture.cs | 310 +-- ...acheMutablePropertyModelGenerationTests.cs | 140 +- .../ClassMapFilterPartModelGenerationTests.cs | 80 +- ...sMapMutablePropertyModelGenerationTests.cs | 348 +-- .../ClassMapSubPartModelGenerationTests.cs | 208 +- .../FluentInterfaceTests/ColumnPartTests.cs | 172 +- ...nentMutablePropertyModelGenerationTests.cs | 238 +- ...mentMutablePropertyModelGenerationTests.cs | 32 +- ...ositeElementSubPartModelGenerationTests.cs | 48 +- ...teIdMutablePropertyModelGenerationTests.cs | 124 +- .../FluentInterfaceTests/CustomPersister.cs | 1110 ++++---- .../FluentInterfaceTests/CustomProxy.cs | 12 +- ...atorMutablePropertyModelGenerationTests.cs | 338 +-- ...nentMutablePropertyModelGenerationTests.cs | 244 +- .../FluentInterfaceTests/ElementPartTests.cs | 118 +- ...pingMutablePropertyModelGenerationTests.cs | 188 +- .../FluentInterfaceTests/IdGeneratorTests.cs | 220 +- .../IdMutablePropertyModelGenerationTests.cs | 416 +-- ...JoinMutablePropertyModelGenerationTests.cs | 158 +- .../JoinSubPartModelGenerationTests.cs | 152 +- ...lassMutablePropertyModelGenerationTests.cs | 278 +- ...inedSubclassSubPartModelGenerationTests.cs | 200 +- .../KeyManyToOnePartTests.cs | 142 +- .../KeyPropertyPartTests.cs | 104 +- ...ManyMutablePropertyModelGenerationTests.cs | 594 ++--- .../ManyToManyPartAsTernaryTests.cs | 246 +- .../ManyToManySubPartModelGenerationTests.cs | 16 +- .../ManyToManyTableNameTests.cs | 420 ++-- ...oOneMutablePropertyModelGenerationTests.cs | 500 ++-- .../FluentInterfaceTests/ModelTester.cs | 56 +- .../NaturalIdPartTests.cs | 118 +- .../OneToManyMethodAccessTests.cs | 30 +- ...ManyMutablePropertyModelGenerationTests.cs | 572 ++--- .../OneToManyPartAsTernaryTests.cs | 164 +- .../OneToManySubPartModelGenerationTests.cs | 170 +- .../OneToManyTypePreditionTests.cs | 80 +- ...oOneMutablePropertyModelGenerationTests.cs | 242 +- .../PropertyEnumerablesTests.cs | 92 +- ...ertyMutablePropertyModelGenerationTests.cs | 640 ++--- .../StoredProcedurePartGenerationTests.cs | 50 +- ...lassMapForJoinedSubclassConventionTests.cs | 100 +- ...lassMutablePropertyModelGenerationTests.cs | 344 +-- ...inedSubclassSubPartModelGenerationTests.cs | 202 +- ...lassMutablePropertyModelGenerationTests.cs | 310 +-- ...pForSubclassSubPartModelGenerationTests.cs | 300 +-- .../SubclassMapWithUserTypeTests.cs | 326 +-- ...lassMutablePropertyModelGenerationTests.cs | 230 +- .../SubclassSubPartModelGenerationTests.cs | 218 +- .../TablePerHierarchyTests.cs | 210 +- ...sionMutablePropertyModelGenerationTests.cs | 304 +-- .../FluentInterfaceTests/WhereTests.cs | 382 +-- .../FluentNHibernate.Testing.csproj | 90 +- .../Infrastructure/ContainerTester.cs | 84 +- .../MappingModel/AttributeStoreTester.cs | 182 +- .../MappingModel/ClassMappingTester.cs | 300 +-- .../Defaults/PropertyColumnDefaultsTester.cs | 100 +- .../CollectionContentEqualitySpecs.cs | 296 +-- .../Equality/MappingEqualitySpecs.cs | 2230 ++++++++--------- .../MappingModel/HibernateMappingTester.cs | 88 +- .../Identity/CompositeIdMappingTester.cs | 48 +- .../MappingModel/MappingTestingExtensions.cs | 56 +- .../MappingModel/Output/XmlAnyWriterTester.cs | 288 +-- .../Output/XmlArrayWriterTester.cs | 512 ++-- .../MappingModel/Output/XmlBagWriterTester.cs | 470 ++-- .../Output/XmlCacheWriterTester.cs | 62 +- .../Output/XmlClassWriterTester.cs | 906 +++---- .../XmlCollectionRelationshipWriterTester.cs | 70 +- .../Output/XmlCollectionWriterTester.cs | 124 +- .../Output/XmlColumnWriterTester.cs | 202 +- .../Output/XmlComponentWriterTester.cs | 426 ++-- .../Output/XmlCompositeElementWriterTester.cs | 194 +- .../Output/XmlCompositeIdWriterTester.cs | 172 +- .../Output/XmlDiscriminatorWriterTester.cs | 112 +- .../Output/XmlDynamicComponentWriterTester.cs | 372 +-- .../Output/XmlElementWriterTester.cs | 96 +- .../Output/XmlFilterDefinitionWriterTester.cs | 50 +- .../Output/XmlFilterWriterTester.cs | 46 +- .../Output/XmlGeneratorWriterTester.cs | 70 +- .../Output/XmlHibernateMappingWriterTester.cs | 248 +- .../Output/XmlIIndexWriterTester.cs | 62 +- .../MappingModel/Output/XmlIdWriterTester.cs | 156 +- .../Output/XmlIdentityBasedWriterTester.cs | 62 +- .../Output/XmlIndexManyToManyWriterTester.cs | 118 +- .../Output/XmlIndexWriterTester.cs | 78 +- .../Output/XmlInheritanceWriterTester.cs | 70 +- .../Output/XmlJoinWriterTester.cs | 322 +-- .../Output/XmlJoinedSubclassWriterTester.cs | 592 ++--- .../Output/XmlKeyManyToOneWriterTester.cs | 186 +- .../Output/XmlKeyPropertyWriterTester.cs | 150 +- .../MappingModel/Output/XmlKeyWriterTester.cs | 166 +- .../Output/XmlListWriterTester.cs | 480 ++-- .../Output/XmlManyToManyWriterTester.cs | 226 +- .../Output/XmlManyToOneWriterTester.cs | 318 +-- .../MappingModel/Output/XmlMapWriterTester.cs | 522 ++-- .../Output/XmlMetaValueWriterTester.cs | 62 +- .../Output/XmlNaturalIdWriterTester.cs | 104 +- .../Output/XmlOneToManyWriterTester.cs | 90 +- .../Output/XmlOneToOneWriterTester.cs | 224 +- .../Output/XmlPropertyWriterTester.cs | 220 +- .../XmlReferenceComponentWriterTester.cs | 452 ++-- .../MappingModel/Output/XmlSetWriterTester.cs | 468 ++-- .../Output/XmlStoredProcedureWriterTester.cs | 92 +- .../Output/XmlSubclassWriterTester.cs | 522 ++-- .../Output/XmlTuplizerWriterTester.cs | 98 +- .../Output/XmlVersionWriterTester.cs | 150 +- .../Output/XmlWriterContainerTester.cs | 62 +- .../ReferenceComponentMappingSpecs.cs | 264 +- .../MappingModel/SortingTests.cs | 94 +- .../JoinPersistenceModelTests.cs | 88 +- .../SeparateSubclassVisitorFixture.cs | 426 ++-- .../SubclassPersistenceModelTests.cs | 1214 ++++----- .../Properties/AssemblyInfo.cs | 6 +- .../Serialization/SerializationFixture.cs | 48 +- src/FluentNHibernate.Testing/Specification.cs | 132 +- .../SpecificationExtensions.cs | 376 +-- .../StubTypeSource.cs | 70 +- ...PersistenceSpecificationExtensionsSpecs.cs | 1232 ++++----- .../Testing/PersistenceSpecificationTester.cs | 532 ++-- ...PersistenceSpecificationTransactionTest.cs | 218 +- .../SessionSourceConfigurationTester.cs | 140 +- .../Testing/Values/Entities.cs | 154 +- .../Testing/Values/ListSpecs.cs | 1108 ++++---- .../Testing/Values/PropertySpecs.cs | 580 ++--- .../Testing/Values/ReferenceListSpecs.cs | 96 +- .../Testing/Values/ReferencePropertySpecs.cs | 86 +- .../Testing/XmlWriterTestHelper.cs | 224 +- .../Utils/ReflectionHelperTests.cs | 162 +- .../Utils/TypeReferenceEnumTests.cs | 60 +- .../Utils/TypeReferenceEqualityTests.cs | 284 +-- .../ComponentColumnPrefixVisitorSpecs.cs | 616 ++--- ...omponentReferenceResolutionVisitorSpecs.cs | 318 +-- .../Visitors/RelationshipPairingSpec.cs | 256 +- .../Xml/MappingXmlTestHelper.cs | 234 +- src/FluentNHibernate.sln | 224 +- src/FluentNHibernate/AssemblyTypeSource.cs | 94 +- .../AutoMappingOverrideAlteration.cs | 96 +- .../Alterations/IAutoMappingAlteration.cs | 26 +- .../Alterations/IAutoMappingOverride.cs | 26 +- .../Automapping/AutoJoinPart.cs | 38 +- .../Automapping/AutoJoinedSubClassPart.cs | 194 +- src/FluentNHibernate/Automapping/AutoMap.cs | 278 +- .../Automapping/AutoMapType.cs | 26 +- .../Automapping/AutoMapper.cs | 434 ++-- .../Automapping/AutoMapping.cs | 494 ++-- .../AutoMappingAlterationCollection.cs | 182 +- .../Automapping/AutoMappingException.cs | 28 +- .../Automapping/AutoMappingExpressions.cs | 298 +-- .../Automapping/AutoPersistenceModel.cs | 1018 ++++---- .../Automapping/AutoSubClassPart.cs | 202 +- .../DefaultAutomappingConfiguration.cs | 208 +- .../Automapping/IAutoClasslike.cs | 26 +- .../Automapping/IAutomappingConfiguration.cs | 302 +-- .../Automapping/IPropertyIgnorer.cs | 18 +- .../Automapping/InlineOverride.cs | 48 +- .../PrivateAutoPersistenceModel.cs | 50 +- .../Automapping/Steps/AutoKeyMapper.cs | 44 +- .../Automapping/Steps/CollectionStep.cs | 148 +- .../Automapping/Steps/ComponentStep.cs | 54 +- .../Automapping/Steps/HasManyStep.cs | 62 +- .../Automapping/Steps/HasManyToManyStep.cs | 250 +- .../Automapping/Steps/IAutomappingStep.cs | 16 +- .../Automapping/Steps/IdentityStep.cs | 142 +- .../Automapping/Steps/PropertyStep.cs | 252 +- .../Automapping/Steps/ReferenceStep.cs | 128 +- .../Steps/SimpleTypeCollectionStep.cs | 162 +- .../Automapping/Steps/VersionStep.cs | 160 +- .../Automapping/SubclassStrategy.cs | 18 +- .../Cfg/AutoMappingsContainer.cs | 196 +- .../Cfg/Db/CacheSettingsBuilder.cs | 184 +- .../Cfg/Db/ConnectionStringBuilder.cs | 78 +- .../Cfg/Db/DB2400Configuration.cs | 32 +- .../Cfg/Db/DB2400ConnectionStringBuilder.cs | 80 +- .../Cfg/Db/DB2Configuration.cs | 48 +- .../Cfg/Db/DB2ConnectionStringBuilder.cs | 104 +- .../Cfg/Db/FirebirdConfiguration.cs | 34 +- .../Cfg/Db/IPersistenceConfigurer.cs | 14 +- .../Cfg/Db/IfxDRDAConfiguration.cs | 56 +- .../Cfg/Db/IfxDRDAConnectionStringBuilder.cs | 504 ++-- .../Cfg/Db/IfxOdbcConfiguration.cs | 56 +- .../Cfg/Db/IfxSQLIConfiguration.cs | 56 +- .../Cfg/Db/IfxSQLIConnectionStringBuilder.cs | 492 ++-- .../Cfg/Db/IngresConfiguration.cs | 32 +- .../Cfg/Db/IngresConnectionStringBuilder.cs | 120 +- .../Cfg/Db/JetDriverConfiguration.cs | 28 +- .../Db/JetDriverConnectionStringBuilder.cs | 122 +- .../Cfg/Db/MsSqlCeConfiguration.cs | 42 +- .../Cfg/Db/MsSqlConfiguration.cs | 72 +- .../Cfg/Db/MsSqlConnectionStringBuilder.cs | 166 +- .../Cfg/Db/MySQLConfiguration.cs | 32 +- .../Cfg/Db/MySQLConnectionStringBuilder.cs | 138 +- .../Cfg/Db/OdbcConnectionStringBuilder.cs | 114 +- .../Cfg/Db/OracleClientConfiguration.cs | 66 +- .../Cfg/Db/OracleConfiguration.cs | 88 +- .../Cfg/Db/OracleConnectionStringBuilder.cs | 262 +- .../Cfg/Db/OracleDataClientConfiguration.cs | 60 +- .../OracleManagedDataClientConfiguration.cs | 60 +- .../Cfg/Db/PersistenceConfiguration.cs | 678 ++--- .../Cfg/Db/PostgreSQLConfiguration.cs | 62 +- .../Db/PostgreSQLConnectionStringBuilder.cs | 122 +- .../Cfg/Db/SQLiteConfiguration.cs | 76 +- .../Cfg/FluentConfiguration.cs | 566 ++--- .../Cfg/FluentConfigurationException.cs | 124 +- .../Cfg/FluentMappingsContainer.cs | 280 +-- src/FluentNHibernate/Cfg/Fluently.cs | 92 +- .../Cfg/HbmMappingsContainer.cs | 154 +- .../Cfg/MappingConfiguration.cs | 190 +- .../Cfg/SetupConventionFinder.cs | 252 +- .../CombinedAssemblyTypeSource.cs | 82 +- .../AcceptanceCriteria/AnyExpectation.cs | 60 +- .../CollectionExpectation.cs | 66 +- .../ConcreteAcceptanceCriteria.cs | 250 +- .../AcceptanceCriteria/EmptyCriterion.cs | 56 +- .../AcceptanceCriteria/EqualCriterion.cs | 50 +- .../AcceptanceCriteria/EvalExpectation.cs | 56 +- .../AcceptanceCriteria/Expectation.cs | 60 +- .../AcceptanceCriteria/IAcceptanceCriteria.cs | 68 +- .../IAcceptanceCriterion.cs | 34 +- .../AcceptanceCriteria/IExpectation.cs | 14 +- .../AcceptanceCriteria/InverseIs.cs | 16 +- .../AcceptanceCriteria/InvertedExpectation.cs | 34 +- .../InverterAcceptanceCriteria.cs | 60 +- .../Conventions/AcceptanceCriteria/Is.cs | 40 +- .../AcceptanceCriteria/SetCriterion.cs | 48 +- .../Conventions/AccessConvention.cs | 172 +- .../AttributeCollectionConvention.cs | 68 +- .../AttributePropertyConvention.cs | 68 +- .../Conventions/ConventionsCollection.cs | 154 +- .../Conventions/DefaultConventionFinder.cs | 382 +-- .../EnumerableExtensionsForConventions.cs | 92 +- .../Conventions/ForeignKeyConvention.cs | 92 +- .../Conventions/Helpers/AutoImport.cs | 38 +- .../Builders/ArrayConventionBuilder.cs | 40 +- .../Helpers/Builders/BagConventionBuilder.cs | 40 +- .../Builders/ClassConventionBuilder.cs | 38 +- .../Builders/CollectionConventionBuilder.cs | 38 +- .../Builders/ComponentConventionBuilder.cs | 38 +- .../Builders/CompositeIdConventionBuilder.cs | 38 +- .../DynamicComponentConventionBuilder.cs | 38 +- .../Builders/HasManyConventionBuilder.cs | 38 +- .../HasManyToManyConventionBuilder.cs | 40 +- .../Builders/HasOneConventionBuilder.cs | 40 +- .../HibernateMappingConventionBuilder.cs | 38 +- .../Helpers/Builders/IdConventionBuilder.cs | 38 +- .../Helpers/Builders/JoinConventionBuilder.cs | 38 +- .../JoinedSubclassConventionBuilder.cs | 38 +- .../Builders/KeyManyToOneConventionBuilder.cs | 38 +- .../Builders/KeyPropertyConventionBuilder.cs | 38 +- .../Helpers/Builders/ListConventionBuilder.cs | 40 +- .../Helpers/Builders/MapConventionBuilder.cs | 40 +- .../OneToManyCollectionConventionBuilder.cs | 64 +- .../Builders/PropertyConventionBuilder.cs | 38 +- .../Builders/ReferenceConventionBuilder.cs | 38 +- .../Helpers/Builders/SetConventionBuilder.cs | 40 +- .../Builders/SubclassConventionBuilder.cs | 38 +- .../Builders/VersionConventionBuilder.cs | 40 +- .../Conventions/Helpers/Cache.cs | 28 +- .../Conventions/Helpers/ConventionBuilder.cs | 184 +- .../Conventions/Helpers/DefaultAccess.cs | 284 +-- .../Conventions/Helpers/DefaultCascade.cs | 82 +- .../Conventions/Helpers/DefaultLazy.cs | 38 +- .../Conventions/Helpers/DynamicInsert.cs | 42 +- .../Conventions/Helpers/DynamicUpdate.cs | 42 +- .../Conventions/Helpers/ForeignKey.cs | 36 +- .../Conventions/Helpers/IConventionBuilder.cs | 28 +- .../Conventions/Helpers/LazyLoad.cs | 38 +- .../Conventions/Helpers/OptimisticLock.cs | 28 +- .../Helpers/Prebuilt/BuiltArrayConvention.cs | 26 +- .../Helpers/Prebuilt/BuiltBagConvention.cs | 26 +- .../Helpers/Prebuilt/BuiltClassConvention.cs | 24 +- .../Prebuilt/BuiltCollectionConvention.cs | 24 +- .../Prebuilt/BuiltComponentConvention.cs | 24 +- .../Prebuilt/BuiltCompositeIdConvention.cs | 24 +- .../Helpers/Prebuilt/BuiltConventionBase.cs | 56 +- .../BuiltDynamicComponentConvention.cs | 24 +- .../Prebuilt/BuiltFuncForeignKeyConvention.cs | 38 +- .../Prebuilt/BuiltHasManyConvention.cs | 24 +- .../Prebuilt/BuiltHasManyToManyConvention.cs | 24 +- .../Helpers/Prebuilt/BuiltHasOneConvention.cs | 26 +- .../BuiltHibernateMappingConvention.cs | 24 +- .../Helpers/Prebuilt/BuiltIdConvention.cs | 24 +- .../Helpers/Prebuilt/BuiltJoinConvention.cs | 24 +- .../Prebuilt/BuiltJoinedSubclassConvention.cs | 24 +- .../Prebuilt/BuiltKeyManyToOneConvention.cs | 24 +- .../Prebuilt/BuiltKeyPropertyConvention.cs | 24 +- .../Helpers/Prebuilt/BuiltListConvention.cs | 26 +- .../BuiltManyToManyCollectionConvention.cs | 24 +- .../Helpers/Prebuilt/BuiltMapConvention.cs | 26 +- .../BuiltOneToManyCollectionConvention.cs | 24 +- .../Prebuilt/BuiltPropertyConvention.cs | 24 +- .../Helpers/Prebuilt/BuiltProxyConvention.cs | 40 +- .../Prebuilt/BuiltReferenceConvention.cs | 24 +- .../Helpers/Prebuilt/BuiltSetConvention.cs | 26 +- .../Prebuilt/BuiltSubclassConvention.cs | 22 +- .../BuiltSuffixForeignKeyConvention.cs | 38 +- .../Prebuilt/BuiltVersionConvention.cs | 24 +- .../Conventions/Helpers/PrimaryKey.cs | 58 +- .../Conventions/Helpers/Proxy.cs | 18 +- .../Conventions/Helpers/Table.cs | 36 +- .../Conventions/IAnyConvention.cs | 16 +- .../Conventions/IArrayConvention.cs | 18 +- .../Conventions/IArrayConventionAcceptance.cs | 14 +- .../Conventions/IBagConvention.cs | 18 +- .../Conventions/IBagConventionAcceptance.cs | 14 +- .../Conventions/IClassConvention.cs | 20 +- .../Conventions/IClassConventionAcceptance.cs | 10 +- .../Conventions/ICollectionConvention.cs | 12 +- .../ICollectionConventionAcceptance.cs | 10 +- .../Conventions/IColumnConvention.cs | 12 +- .../IColumnConventionAcceptance.cs | 10 +- .../Conventions/IComponentConvention.cs | 22 +- .../IComponentConventionAcceptance.cs | 10 +- .../ICompositeIdentityConvention.cs | 12 +- .../ICompositeIdentityConventionAcceptance.cs | 10 +- .../Conventions/IConvention.cs | 74 +- .../Conventions/IConventionFinder.cs | 152 +- .../IDynamicComponentConvention.cs | 20 +- .../IDynamicComponentConventionAcceptance.cs | 10 +- .../Conventions/IHasManyConvention.cs | 12 +- .../IHasManyConventionAcceptance.cs | 10 +- .../Conventions/IHasManyToManyConvention.cs | 12 +- .../IHasManyToManyConventionAcceptance.cs | 10 +- .../Conventions/IHasOneConvention.cs | 20 +- .../IHasOneConventionAcceptance.cs | 10 +- .../IHibernateMappingConvention.cs | 20 +- .../Conventions/IIdConvention.cs | 22 +- .../Conventions/IIdConventionAcceptance.cs | 10 +- .../Conventions/IIndexConvention.cs | 14 +- .../Conventions/IIndexConventionAcceptance.cs | 10 +- .../Conventions/IIndexManyToManyConvention.cs | 14 +- .../IIndexManyToManyConventionAcceptance.cs | 10 +- .../Conventions/IJoinConvention.cs | 20 +- .../Conventions/IJoinConventionAcceptance.cs | 10 +- .../Conventions/IJoinedSubclassConvention.cs | 20 +- .../IJoinedSubclassConventionAcceptance.cs | 10 +- .../Conventions/IKeyManyToOneConvention.cs | 12 +- .../IKeyManyToOneConventionAcceptance.cs | 12 +- .../Conventions/IKeyPropertyConvention.cs | 12 +- .../IKeyPropertyConventionAcceptance.cs | 12 +- .../Conventions/IListConvention.cs | 18 +- .../Conventions/IListConventionAcceptance.cs | 14 +- .../Conventions/IMapConvention.cs | 18 +- .../Conventions/IMapConventionAcceptance.cs | 14 +- .../Conventions/IPropertyConvention.cs | 20 +- .../IPropertyConventionAcceptance.cs | 10 +- .../Conventions/IReferenceConvention.cs | 22 +- .../IReferenceConventionAcceptance.cs | 10 +- .../Conventions/ISetConvention.cs | 18 +- .../Conventions/ISetConventionAcceptance.cs | 14 +- .../Conventions/ISubclassConvention.cs | 20 +- .../ISubclassConventionAcceptance.cs | 10 +- .../Conventions/IUserTypeConvention.cs | 8 +- .../Conventions/IVersionConvention.cs | 20 +- .../IVersionConventionAcceptance.cs | 10 +- .../Conventions/Inspections/AnyInspector.cs | 218 +- .../Conventions/Inspections/CacheInspector.cs | 90 +- .../Inspections/CamelCasePrefix.cs | 20 +- .../Conventions/Inspections/Cascade.cs | 112 +- .../Conventions/Inspections/ClassInspector.cs | 540 ++-- .../Inspections/CollectionInspector.cs | 456 ++-- .../Inspections/ColumnBasedInspector.cs | 160 +- .../Inspections/ColumnInspector.cs | 166 +- .../Inspections/ComponentBaseInspector.cs | 302 +-- .../Inspections/ComponentInspector.cs | 54 +- .../Inspections/CompositeElementInspector.cs | 138 +- .../Inspections/CompositeIdentityInspector.cs | 162 +- .../Inspections/DiscriminatorInspector.cs | 130 +- .../Inspections/DynamicComponentInspector.cs | 42 +- .../Inspections/ElementInspector.cs | 116 +- .../Conventions/Inspections/Fetch.cs | 104 +- .../Conventions/Inspections/Generated.cs | 138 +- .../Inspections/HibernateMappingInspector.cs | 124 +- .../Inspections/IAccessInspector.cs | 14 +- .../Conventions/Inspections/IAnyInspector.cs | 36 +- .../Inspections/IArrayInspector.cs | 12 +- .../Conventions/Inspections/IBagInspector.cs | 12 +- .../Inspections/ICacheInspector.cs | 14 +- .../Inspections/IClassInspector.cs | 76 +- .../Inspections/ICollectionInspector.cs | 74 +- .../Inspections/IColumnInspector.cs | 30 +- .../Inspections/IComponentBaseInspector.cs | 44 +- .../Inspections/IComponentInspector.cs | 10 +- .../Inspections/ICompositeElementInspector.cs | 22 +- .../ICompositeIdentityInspector.cs | 22 +- .../Inspections/IDiscriminatorInspector.cs | 44 +- .../Inspections/IDynamicComponentInspector.cs | 12 +- .../Inspections/IElementInspector.cs | 22 +- .../IExposedThroughPropertyInspector.cs | 16 +- .../Inspections/IGeneratorInspector.cs | 94 +- .../Inspections/IHibernateMappingInspector.cs | 24 +- .../Inspections/IIdentityInspector.cs | 40 +- .../Inspections/IIdentityInspectorBase.cs | 18 +- .../Inspections/IIndexInspector.cs | 14 +- .../Inspections/IIndexInspectorBase.cs | 14 +- .../Inspections/IIndexManyToManyInspector.cs | 16 +- .../Conventions/Inspections/IInspector.cs | 40 +- .../Conventions/Inspections/IJoinInspector.cs | 38 +- .../Inspections/IJoinedSubclassInspector.cs | 22 +- .../Conventions/Inspections/IKeyInspector.cs | 20 +- .../Inspections/IKeyManyToOneInspector.cs | 30 +- .../Inspections/IKeyPropertyInspector.cs | 26 +- .../Inspections/ILazyLoadInspector.cs | 14 +- .../Conventions/Inspections/IListInspector.cs | 12 +- .../IManyToManyCollectionInspector.cs | 12 +- .../Inspections/IManyToManyInspector.cs | 48 +- .../Inspections/IManyToOneInspector.cs | 44 +- .../Conventions/Inspections/IMapInspector.cs | 12 +- .../Inspections/IMetaValueInspector.cs | 16 +- .../IOneToManyCollectionInspector.cs | 14 +- .../Inspections/IOneToManyInspector.cs | 18 +- .../Inspections/IOneToOneInspector.cs | 32 +- .../Inspections/IParentInspector.cs | 16 +- .../Inspections/IPropertyInspector.cs | 52 +- .../Inspections/IReadOnlyInspector.cs | 10 +- .../Inspections/IRelationshipInspector.cs | 20 +- .../Conventions/Inspections/ISetInspector.cs | 12 +- .../Inspections/ISubclassInspector.cs | 16 +- .../Inspections/ISubclassInspectorBase.cs | 50 +- .../Inspections/IVersionInspector.cs | 48 +- .../Inspections/IdentityInspector.cs | 164 +- .../Conventions/Inspections/Include.cs | 116 +- .../Conventions/Inspections/IndexInspector.cs | 96 +- .../Inspections/IndexManyToManyInspector.cs | 106 +- .../Inspections/InspectorModelMapper.cs | 66 +- .../Conventions/Inspections/JoinInspector.cs | 238 +- .../Conventions/Inspections/JoinInstance.cs | 136 +- .../Inspections/JoinedSubclassInspector.cs | 388 +-- .../Conventions/Inspections/KeyInspector.cs | 114 +- .../Inspections/KeyManyToOneInspector.cs | 150 +- .../Inspections/KeyPropertyInspector.cs | 126 +- .../Inspections/LowerCasePrefix.cs | 20 +- .../Inspections/ManyToManyInspector.cs | 178 +- .../Inspections/ManyToOneInspector.cs | 256 +- .../Inspections/MetaValueInspector.cs | 80 +- .../Conventions/Inspections/NotFound.cs | 102 +- .../Conventions/Inspections/OnDelete.cs | 102 +- .../Inspections/OneToManyInspector.cs | 94 +- .../Inspections/OneToOneInspector.cs | 162 +- .../Conventions/Inspections/OptimisticLock.cs | 106 +- .../Inspections/ParentInspector.cs | 92 +- .../Inspections/PascalCasePrefix.cs | 22 +- .../Conventions/Inspections/Polymorphism.cs | 102 +- .../Conventions/Inspections/Prefix.cs | 30 +- .../Inspections/PropertyInspector.cs | 218 +- .../Conventions/Inspections/SchemaAction.cs | 124 +- .../Inspections/SubclassInspector.cs | 346 +-- .../Inspections/UnmappedPropertyException.cs | 28 +- .../Inspections/VersionInspector.cs | 142 +- .../Conventions/Instances/AccessInstance.cs | 218 +- .../Conventions/Instances/AnyInstance.cs | 36 +- .../Conventions/Instances/CacheInstance.cs | 120 +- .../Conventions/Instances/CascadeInstance.cs | 74 +- .../Conventions/Instances/ClassInstance.cs | 262 +- .../Instances/CollectionCascadeInstance.cs | 46 +- .../Instances/CollectionInstance.cs | 552 ++-- .../Conventions/Instances/ColumnInstance.cs | 60 +- .../Instances/ComponentInstance.cs | 148 +- .../Instances/CompositeIdentityInstance.cs | 134 +- .../Instances/DynamicComponentInstance.cs | 140 +- .../Conventions/Instances/ElementInstance.cs | 84 +- .../Conventions/Instances/FetchInstance.cs | 54 +- .../Instances/GeneratedInstance.cs | 62 +- .../Instances/GeneratorInstance.cs | 1008 ++++---- .../Instances/HibernateMappingInstance.cs | 116 +- .../Conventions/Instances/IAccessInstance.cs | 54 +- .../Conventions/Instances/IAnyInstance.cs | 14 +- .../Conventions/Instances/IArrayInstance.cs | 14 +- .../Conventions/Instances/IBagInstance.cs | 14 +- .../Conventions/Instances/ICacheInstance.cs | 30 +- .../Conventions/Instances/ICascadeInstance.cs | 22 +- .../Conventions/Instances/IClassInstance.cs | 120 +- .../Instances/ICollectionCascadeInstance.cs | 12 +- .../Instances/ICollectionInstance.cs | 94 +- .../Conventions/Instances/IColumnInstance.cs | 18 +- .../Instances/IComponentInstance.cs | 56 +- .../Instances/ICompositeIdentityInstance.cs | 36 +- .../Conventions/Instances/IElementInstance.cs | 24 +- .../Conventions/Instances/IFetchInstance.cs | 14 +- .../Instances/IGeneratedInstance.cs | 50 +- .../Instances/IGeneratorInstance.cs | 108 +- .../Instances/IHibernateMappingInstance.cs | 30 +- .../Instances/IIdentityInstance.cs | 54 +- .../Conventions/Instances/IIndexInstance.cs | 12 +- .../Instances/IIndexInstanceBase.cs | 14 +- .../Instances/IIndexManyToManyInstance.cs | 14 +- .../Conventions/Instances/IInsertInstance.cs | 16 +- .../Conventions/Instances/IJoinInstance.cs | 36 +- .../Instances/IJoinedSubclassInstance.cs | 54 +- .../Conventions/Instances/IKeyInstance.cs | 24 +- .../Instances/IKeyManyToOneInstance.cs | 32 +- .../Instances/IKeyPropertyInstance.cs | 18 +- .../Conventions/Instances/IListInstance.cs | 14 +- .../IManyToManyCollectionInstance.cs | 90 +- .../Instances/IManyToManyInstance.cs | 40 +- .../Instances/IManyToOneInstance.cs | 112 +- .../Conventions/Instances/IMapInstance.cs | 14 +- .../Instances/INotFoundInstance.cs | 12 +- .../Instances/INullableInstance.cs | 10 +- .../Instances/IOneToManyCollectionInstance.cs | 92 +- .../Instances/IOneToManyInstance.cs | 16 +- .../Instances/IOneToOneInstance.cs | 90 +- .../Instances/IOptimisticLockInstance.cs | 16 +- .../Instances/IPropertyInstance.cs | 86 +- .../Instances/IReadOnlyInstance.cs | 12 +- .../Instances/IRelationshipInstance.cs | 22 +- .../Instances/ISchemaActionInstance.cs | 22 +- .../Conventions/Instances/ISetInstance.cs | 14 +- .../Instances/ISubclassInstance.cs | 60 +- .../Conventions/Instances/IUpdateInstance.cs | 12 +- .../Conventions/Instances/IVersionInstance.cs | 64 +- .../Conventions/Instances/IdentityInstance.cs | 276 +- .../Conventions/Instances/IndexInstance.cs | 58 +- .../Instances/IndexManyToManyInstance.cs | 68 +- .../Instances/JoinedSubclassInstance.cs | 240 +- .../Conventions/Instances/KeyInstance.cs | 102 +- .../Instances/KeyManyToOneInstance.cs | 92 +- .../Instances/KeyPropertyInstance.cs | 50 +- .../Instances/ManyToManyCollectionInstance.cs | 118 +- .../Instances/ManyToManyInstance.cs | 126 +- .../Instances/ManyToOneInstance.cs | 310 +-- .../Conventions/Instances/NotFoundInstance.cs | 44 +- .../Instances/OneToManyCollectionInstance.cs | 108 +- .../Instances/OneToManyInstance.cs | 62 +- .../Conventions/Instances/OneToOneInstance.cs | 178 +- .../Instances/OptimisticLockInstance.cs | 64 +- .../Conventions/Instances/PropertyInstance.cs | 434 ++-- .../Instances/SchemaActionInstance.cs | 94 +- .../Conventions/Instances/SubclassInstance.cs | 182 +- .../Conventions/Instances/VersionInstance.cs | 268 +- .../ManyToManyTableNameConvention.cs | 102 +- .../Conventions/MultipleAttribute.cs | 12 +- .../ObjectExtensionsForConventions.cs | 30 +- .../Conventions/ProxyConvention.cs | 226 +- .../Conventions/UserTypeConvention.cs | 68 +- src/FluentNHibernate/Data/Entity.cs | 122 +- .../Diagnostics/AutomappingType.cs | 14 +- .../Diagnostics/ConsoleOutputListener.cs | 108 +- .../Diagnostics/DefaultDiagnosticLogger.cs | 182 +- .../DefaultDiagnosticMessageDispatcher.cs | 38 +- .../Diagnostics/DefaultOutputFormatter.cs | 418 +-- .../Diagnostics/DiagnosticResults.cs | 50 +- .../Diagnostics/DiagnosticsConfiguration.cs | 200 +- .../Diagnostics/IDiagnosticListener.cs | 10 +- .../Diagnostics/IDiagnosticLogger.cs | 30 +- .../IDiagnosticMessageDispatcher.cs | 12 +- .../IDiagnosticResultsFormatter.cs | 10 +- .../Diagnostics/NullDiagnosticsLogger.cs | 60 +- src/FluentNHibernate/Diagnostics/ScanPhase.cs | 12 +- .../Diagnostics/ScannedSource.cs | 12 +- .../Diagnostics/SkippedAutomappingType.cs | 62 +- .../Diagnostics/StringLambdaOutputListener.cs | 50 +- src/FluentNHibernate/DummyMethodInfo.cs | 172 +- src/FluentNHibernate/DummyPropertyInfo.cs | 218 +- src/FluentNHibernate/Extensions.cs | 54 +- src/FluentNHibernate/FluentNHibernate.csproj | 44 +- src/FluentNHibernate/ITypeSource.cs | 28 +- .../Infrastructure/Container.cs | 56 +- .../Infrastructure/ResolveException.cs | 28 +- src/FluentNHibernate/Mapping/Access.cs | 266 +- .../Mapping/AccessStrategyBuilder.cs | 434 ++-- src/FluentNHibernate/Mapping/AnyPart.cs | 466 ++-- src/FluentNHibernate/Mapping/Attributes.cs | 10 +- .../Mapping/BaseAccessStrategyBuilder.cs | 392 +-- src/FluentNHibernate/Mapping/CachePart.cs | 226 +- .../Mapping/CascadeExpression.cs | 262 +- .../Mapping/CheckTypeExpression.cs | 50 +- src/FluentNHibernate/Mapping/ClassMap.cs | 1456 +++++------ .../Mapping/ClasslikeMapBase.cs | 924 +++---- .../Mapping/CollectionCascadeExpression.cs | 66 +- .../Mapping/CollectionTypeResolver.cs | 62 +- .../Mapping/ColumnMappingCollection.cs | 142 +- src/FluentNHibernate/Mapping/ColumnPart.cs | 202 +- src/FluentNHibernate/Mapping/ComponentMap.cs | 136 +- src/FluentNHibernate/Mapping/ComponentPart.cs | 118 +- .../Mapping/ComponentPartBase.cs | 386 +-- .../Mapping/CompositeElementPart.cs | 418 +-- .../Mapping/CompositeIdentityPart.cs | 532 ++-- .../Mapping/DiscriminatorPart.cs | 484 ++-- .../Mapping/DiscriminatorValue.cs | 56 +- .../Mapping/DynamicComponentPart.cs | 130 +- src/FluentNHibernate/Mapping/ElementPart.cs | 216 +- .../Mapping/FetchTypeExpression.cs | 82 +- .../Mapping/FilterDefinition.cs | 128 +- src/FluentNHibernate/Mapping/FilterPart.cs | 148 +- .../Mapping/GeneratorBuilder.cs | 654 ++--- .../Mapping/GenericEnumMapper.cs | 26 +- .../Mapping/HibernateMappingPart.cs | 170 +- .../Mapping/IFilterDefinition.cs | 26 +- .../IdentityGenerationStrategyBuilder.cs | 1198 ++++----- src/FluentNHibernate/Mapping/IdentityPart.cs | 608 ++--- src/FluentNHibernate/Mapping/ImportPart.cs | 54 +- .../Mapping/IndexManyToManyPart.cs | 128 +- src/FluentNHibernate/Mapping/IndexPart.cs | 106 +- .../Mapping/InvalidPrefixException.cs | 32 +- src/FluentNHibernate/Mapping/JoinPart.cs | 356 +-- .../Mapping/JoinedSubClassPart.cs | 334 +-- .../Mapping/KeyManyToOnePart.cs | 172 +- .../Mapping/KeyPropertyPart.cs | 86 +- src/FluentNHibernate/Mapping/Laziness.cs | 100 +- src/FluentNHibernate/Mapping/ListIndexPart.cs | 156 +- .../Mapping/ManyToManyPart.cs | 800 +++--- src/FluentNHibernate/Mapping/ManyToOnePart.cs | 770 +++--- .../Mapping/MappingProviderStore.cs | 426 ++-- src/FluentNHibernate/Mapping/Member.cs | 1020 ++++---- .../Mapping/MemberAccessResolver.cs | 96 +- src/FluentNHibernate/Mapping/Naming.cs | 84 +- .../Mapping/NamingStrategy.cs | 102 +- src/FluentNHibernate/Mapping/NaturalIdPart.cs | 244 +- .../Mapping/NotFoundExpression.cs | 68 +- src/FluentNHibernate/Mapping/OneToManyPart.cs | 482 ++-- src/FluentNHibernate/Mapping/OneToOnePart.cs | 434 ++-- .../Mapping/OptimisticLockBuilder.cs | 182 +- src/FluentNHibernate/Mapping/ParamBuilder.cs | 38 +- .../Mapping/PolymorphismBuilder.cs | 64 +- src/FluentNHibernate/Mapping/Prefix.cs | 46 +- .../Mapping/PropertyGeneratedBuilder.cs | 82 +- src/FluentNHibernate/Mapping/PropertyPart.cs | 728 +++--- .../Mapping/Providers/IAnyMappingProvider.cs | 14 +- .../Providers/ICacheMappingProvider.cs | 14 +- .../Providers/ICollectionMappingProvider.cs | 14 +- .../Providers/IComponentMappingProvider.cs | 14 +- .../ICompositeElementMappingProvider.cs | 14 +- .../Providers/ICompositeIdMappingProvider.cs | 14 +- .../IDiscriminatorMappingProvider.cs | 14 +- .../Providers/IElementMappingProvider.cs | 14 +- .../IExternalComponentMappingProvider.cs | 18 +- .../Providers/IFilterMappingProvider.cs | 14 +- .../Providers/IHibernateMappingProvider.cs | 14 +- .../Providers/IIdentityMappingProvider.cs | 14 +- .../IIndeterminateSubclassMappingProvider.cs | 20 +- ...minateSubclassMappingProviderCollection.cs | 18 +- .../Mapping/Providers/IJoinMappingProvider.cs | 14 +- .../Providers/IManyToOneMappingProvider.cs | 14 +- .../Providers/INaturalIdMappingProvider.cs | 14 +- .../INestedCompositeElementMappingProvider.cs | 14 +- .../Providers/IOneToOneMappingProvider.cs | 14 +- .../Providers/IPropertyMappingProvider.cs | 14 +- .../IReferenceComponentMappingProvider.cs | 14 +- .../IStoredProcedureMappingProvider.cs | 14 +- .../Providers/ISubclassMappingProviders.cs | 14 +- .../Providers/IVersionMappingProvider.cs | 14 +- ...minateSubclassMappingProviderCollection.cs | 68 +- .../Mapping/ReferenceComponentPart.cs | 104 +- .../Mapping/SchemaActionBuilder.cs | 112 +- .../Mapping/StoredProcedurePart.cs | 50 +- src/FluentNHibernate/Mapping/SubClassPart.cs | 304 +-- src/FluentNHibernate/Mapping/SubclassMap.cs | 780 +++--- src/FluentNHibernate/Mapping/ToManyBase.cs | 1572 ++++++------ src/FluentNHibernate/Mapping/TuplizerPart.cs | 124 +- src/FluentNHibernate/Mapping/TypeMapping.cs | 26 +- .../Mapping/VersionGeneratedBuilder.cs | 52 +- src/FluentNHibernate/Mapping/VersionPart.cs | 490 ++-- .../MappingModel/AnyMapping.cs | 318 +-- .../MappingModel/AttributeStore.cs | 174 +- .../MappingModel/CacheMapping.cs | 160 +- .../MappingModel/ClassBased/ClassMapping.cs | 446 ++-- .../ClassBased/ClassMappingBase.cs | 414 +-- .../ClassBased/ComponentMapping.cs | 192 +- .../ClassBased/ComponentMappingBase.cs | 178 +- .../MappingModel/ClassBased/ComponentType.cs | 108 +- .../ClassBased/ExternalComponentMapping.cs | 32 +- .../ClassBased/IComponentMapping.cs | 70 +- .../ClassBased/ReferenceComponentMapping.cs | 452 ++-- .../ClassBased/SubclassMapping.cs | 360 +-- .../MappingModel/ClassBased/SubclassType.cs | 110 +- .../Collections/AttributeLayeredValues.cs | 216 +- .../MappingModel/Collections/Collection.cs | 18 +- .../Collections/CollectionMapping.cs | 600 ++--- .../Collections/CompositeElementMapping.cs | 240 +- .../Collections/ElementMapping.cs | 202 +- .../ICollectionRelationshipMapping.cs | 20 +- .../MappingModel/Collections/IIndexMapping.cs | 18 +- .../Collections/IndexManyToManyMapping.cs | 210 +- .../MappingModel/Collections/IndexMapping.cs | 200 +- .../Collections/LayeredColumns.cs | 124 +- .../MappingModel/Collections/LayeredValues.cs | 30 +- .../MappingModel/Collections/Lazy.cs | 48 +- .../Collections/ManyToManyMapping.cs | 308 +-- .../NestedCompositeElementMapping.cs | 70 +- .../Collections/OneToManyMapping.cs | 170 +- .../MappingModel/Collections/SortType.cs | 12 +- .../MappingModel/ColumnBasedMappingBase.cs | 110 +- .../MappingModel/ColumnMapping.cs | 274 +- .../Conventions/ConventionException.cs | 50 +- .../Conventions/ManyToManyTableConvention.cs | 66 +- .../MappingModel/DiscriminatorMapping.cs | 172 +- .../MappingModel/EqualityExtensions.cs | 82 +- .../MappingModel/FilterDefinitionMapping.cs | 166 +- .../MappingModel/FilterMapping.cs | 140 +- .../MappingModel/HibernateMapping.cs | 312 +-- .../MappingModel/IHasColumnMappings.cs | 18 +- .../MappingModel/IHasMappedMembers.cs | 44 +- src/FluentNHibernate/MappingModel/IMapping.cs | 18 +- .../MappingModel/IRelationship.cs | 10 +- .../Identity/CompositeIdMapping.cs | 230 +- .../MappingModel/Identity/GeneratorMapping.cs | 146 +- .../Identity/ICompositeIdKeyMapping.cs | 18 +- .../MappingModel/Identity/IIdentityMapping.cs | 8 +- .../MappingModel/Identity/IdMapping.cs | 194 +- .../Identity/KeyManyToOneMapping.cs | 228 +- .../Identity/KeyPropertyMapping.cs | 192 +- .../MappingModel/ImportMapping.cs | 126 +- .../MappingModel/JoinMapping.cs | 352 +-- .../MappingModel/KeyMapping.cs | 240 +- src/FluentNHibernate/MappingModel/Layer.cs | 20 +- .../MappingModel/ManyToOneMapping.cs | 332 +-- .../MappingModel/MappedMembers.cs | 454 ++-- .../MappingModel/MappingBase.cs | 34 +- .../MappingModel/MetaValueMapping.cs | 144 +- .../MappingModel/NaturalIdMapping.cs | 132 +- .../MappingModel/OneToOneMapping.cs | 228 +- .../Output/BaseXmlComponentWriter.cs | 114 +- .../Output/CollectionAttributeWriter.cs | 234 +- .../MappingModel/Output/IXmlWriter.cs | 14 +- .../Output/IXmlWriterServiceLocator.cs | 10 +- .../Output/MappingXmlSerializer.cs | 34 +- .../Output/Sorting/BaseXmlNodeSorter.cs | 112 +- .../MappingModel/Output/Sorting/SortValue.cs | 12 +- .../Output/Sorting/XmlClasslikeNodeSorter.cs | 148 +- .../Output/Sorting/XmlCollectionNodeSorter.cs | 58 +- .../Output/Sorting/XmlIdNodeSorter.cs | 38 +- .../Output/Sorting/XmlNodeSorter.cs | 20 +- .../MappingModel/Output/XmlAnyWriter.cs | 144 +- .../MappingModel/Output/XmlArrayWriter.cs | 78 +- .../MappingModel/Output/XmlBagWriter.cs | 60 +- .../MappingModel/Output/XmlCacheWriter.cs | 58 +- .../MappingModel/Output/XmlClassWriter.cs | 342 +-- .../MappingModel/Output/XmlClassWriterBase.cs | 144 +- .../Output/XmlCollectionRelationshipWriter.cs | 70 +- .../Output/XmlCollectionWriter.cs | 110 +- .../MappingModel/Output/XmlColumnWriter.cs | 116 +- .../MappingModel/Output/XmlComponentWriter.cs | 90 +- .../Output/XmlCompositeElementWriter.cs | 148 +- .../Output/XmlCompositeIdWriter.cs | 124 +- .../Output/XmlDiscriminatorWriter.cs | 100 +- .../MappingModel/Output/XmlElementWriter.cs | 88 +- .../Output/XmlFilterDefinitionWriter.cs | 78 +- .../MappingModel/Output/XmlFilterWriter.cs | 62 +- .../MappingModel/Output/XmlGeneratorWriter.cs | 68 +- .../Output/XmlHibernateMappingWriter.cs | 188 +- .../MappingModel/Output/XmlIIndexWriter.cs | 68 +- .../MappingModel/Output/XmlIdWriter.cs | 118 +- .../Output/XmlIdentityBasedWriter.cs | 68 +- .../MappingModel/Output/XmlImportWriter.cs | 60 +- .../Output/XmlIndexManyToManyWriter.cs | 94 +- .../MappingModel/Output/XmlIndexWriter.cs | 112 +- .../MappingModel/Output/XmlJoinWriter.cs | 214 +- .../Output/XmlKeyManyToOneWriter.cs | 118 +- .../Output/XmlKeyPropertyWriter.cs | 128 +- .../MappingModel/Output/XmlKeyWriter.cs | 112 +- .../MappingModel/Output/XmlListWriter.cs | 78 +- .../Output/XmlManyToManyWriter.cs | 148 +- .../MappingModel/Output/XmlManyToOneWriter.cs | 158 +- .../MappingModel/Output/XmlMapWriter.cs | 90 +- .../MappingModel/Output/XmlMetaValueWriter.cs | 58 +- .../MappingModel/Output/XmlNaturalIdWriter.cs | 96 +- .../MappingModel/Output/XmlOneToManyWriter.cs | 66 +- .../MappingModel/Output/XmlOneToOneWriter.cs | 106 +- .../MappingModel/Output/XmlParentWriter.cs | 58 +- .../MappingModel/Output/XmlPropertyWriter.cs | 132 +- .../MappingModel/Output/XmlSetWriter.cs | 66 +- .../Output/XmlStoredProcedureWriter.cs | 76 +- .../MappingModel/Output/XmlSubclassWriter.cs | 226 +- .../MappingModel/Output/XmlTuplizerWriter.cs | 100 +- .../MappingModel/Output/XmlVersionWriter.cs | 104 +- .../MappingModel/Output/XmlWriterContainer.cs | 292 +-- .../MappingModel/Output/XmlWriterFactory.cs | 24 +- .../Output/XmlWriterServiceLocator.cs | 34 +- .../MappingModel/ParentMapping.cs | 146 +- .../MappingModel/PropertyMapping.cs | 228 +- .../MappingModel/StoredProcedureMapping.cs | 204 +- .../MappingModel/TuplizerMapping.cs | 150 +- .../MappingModel/TuplizerMode.cs | 14 +- .../MappingModel/TypeReference.cs | 406 +-- .../MappingModel/VersionMapping.cs | 180 +- .../MissingConstructorException.cs | 28 +- src/FluentNHibernate/PersistenceModel.cs | 730 +++--- .../Properties/AssemblyInfo.cs | 8 +- src/FluentNHibernate/Reveal.cs | 120 +- src/FluentNHibernate/SessionSource.cs | 172 +- .../PersistenceSpecificationExtensions.cs | 1030 ++++---- ...onSessionSourceForSQLiteInMemoryTesting.cs | 80 +- src/FluentNHibernate/Testing/Values/List.cs | 220 +- .../Testing/Values/Property.cs | 294 +-- .../Testing/Values/ReferenceList.cs | 36 +- .../Testing/Values/ReferenceProperty.cs | 26 +- .../UnknownPropertyException.cs | 66 +- .../Utils/CollectionExtensions.cs | 44 +- src/FluentNHibernate/Utils/ExpressionToSql.cs | 286 +-- src/FluentNHibernate/Utils/Extensions.cs | 182 +- .../Utils/Reflection/Accessor.cs | 38 +- .../Utils/Reflection/ExpressionBuilder.cs | 58 +- .../Utils/Reflection/PropertyChain.cs | 210 +- .../Utils/Reflection/ReflectionHelper.cs | 270 +- .../Utils/Reflection/SingleMember.cs | 134 +- .../Utils/ReflectionExtensions.cs | 24 +- src/FluentNHibernate/Utils/StringLikeness.cs | 138 +- src/FluentNHibernate/Utils/XmlExtensions.cs | 162 +- .../AmbiguousComponentReferenceException.cs | 38 +- .../Visitors/ComponentColumnPrefixVisitor.cs | 88 +- .../ComponentReferenceResolutionVisitor.cs | 134 +- .../Visitors/ConventionVisitor.cs | 550 ++-- .../Visitors/DefaultMappingModelVisitor.cs | 374 +-- .../Visitors/IMappingModelVisitor.cs | 174 +- .../Visitors/ManyToManyTableNameVisitor.cs | 52 +- .../MissingExternalComponentException.cs | 38 +- .../Visitors/NullMappingModelVisitor.cs | 716 +++--- .../Visitors/RelationshipKeyPairingVisitor.cs | 38 +- .../Visitors/RelationshipPairingVisitor.cs | 472 ++-- .../Visitors/SeparateSubclassVisitor.cs | 316 +-- ...olvedComponentReferenceVisitedException.cs | 38 +- .../Visitors/ValidationException.cs | 32 +- .../Visitors/ValidationVisitor.cs | 92 +- 1166 files changed, 91221 insertions(+), 91208 deletions(-) diff --git a/.editorconfig b/.editorconfig index 3481533bd..8a0c02ebd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,10 +2,6 @@ root = true ; This file is for unifying the coding style for different editors and IDEs. ; More information at http://EditorConfig.org - -[*] -end_of_line = crlf - [*.ps1] indent_style = space indent_size = 2 diff --git a/.gitattributes b/.gitattributes index 48adf82e5..1612d7799 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,28 @@ -[core] -autocrlf=false +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto + +# Explicitly declare text files you want to always be normalized and converted +# to native line endings on checkout. +*.cs text diff=csharp +*.xaml text +*.txt text +*.tt text +*.ps1 text +*.cmd text +*.msbuild text +*.md text + +*.sln text eol=crlf +*.csproj text eol=crlf +*.vbproj text eol=crlf +*.fsproj text eol=crlf +*.dbproj text eol=crlf + +# Resharper DotSettings files are in Unix format +*.DotSettings text eol=lf + +# Binary files +*.png binary +*.jpg binary +*.dll binary +*.exe binary \ No newline at end of file diff --git a/CODEOFCONDUCT.md b/CODEOFCONDUCT.md index df7338359..e297904f0 100644 --- a/CODEOFCONDUCT.md +++ b/CODEOFCONDUCT.md @@ -1,24 +1,24 @@ -# Contributor Code of Conduct - -As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. - -We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. - -Examples of unacceptable behavior by participants include: - -- The use of sexualized language or imagery -- Personal attacks -- Trolling or insulting/derogatory comments -- Public or private harassment -- Publishing other's private information, such as physical or electronic addresses, without explicit permission -- Other unethical or unprofessional conduct - -Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. - -By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. - -This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. - -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting a project maintainer. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Maintainers are obligated to maintain confidentiality with regard to the reporter of an incident. - +# Contributor Code of Conduct + +As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. + +We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. + +Examples of unacceptable behavior by participants include: + +- The use of sexualized language or imagery +- Personal attacks +- Trolling or insulting/derogatory comments +- Public or private harassment +- Publishing other's private information, such as physical or electronic addresses, without explicit permission +- Other unethical or unprofessional conduct + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting a project maintainer. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Maintainers are obligated to maintain confidentiality with regard to the reporter of an incident. + This Code of Conduct is adapted from the Contributor Covenant, version 1.3.0, available from http://contributor-covenant.org/version/1/3/0/ \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b1508a0cb..2cd5d46fc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,14 +1,5 @@ -# Contribution Guidelines - -The wiki has a page on contributing to FNH: - -https://github.com/nhibernate/fluent-nhibernate/wiki/Contributing - -## Important -If you've just pulled the FNH code into a local git repository for the first time, its really important that you set the core.autocrlf setting to false to avoid running into whitespace/line ending issues. Do this using the following command: - -``` -git config core.autocrlf false -``` - - +# Contribution Guidelines + +The wiki has a page on contributing to FNH: + +https://github.com/nhibernate/fluent-nhibernate/wiki/Contributing diff --git a/README.md b/README.md index a58b0281a..3ac96baf9 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,41 @@ -![FluentNHibernate logo](https://raw.githubusercontent.com/nhibernate/fluent-nhibernate/main/docs/logo.png) - -[![Build status](https://ci.appveyor.com/api/projects/status/684r2ot07i2lrcij/branch/main?svg=true)](https://ci.appveyor.com/project/nhibernate/fluent-nhibernate/branch/main) -[![NuGet](https://img.shields.io/nuget/v/FluentNHibernate.svg)](https://www.nuget.org/packages/FluentNHibernate) - -## What is FluentNHibernate? -Fluent, XML-less, compile safe, automated, convention-based mappings for NHibernate. *Get your fluent on.* - -## Where can I get it? - -Install using the [FluentNHibernate NuGet package](https://www.nuget.org/packages/FluentNHibernate): - -``` -dotnet add package FluentNHibernate -``` - -## How do I use it? - -* Read the [introduction](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Getting-started). -* Get latest version from NuGet - - [.NETCore2.0, NETStandard2.0 or NET 4.6.1 with NHibernate 5.x](https://www.nuget.org/packages/FluentNHibernate) - - [.NET 4.0 with NHibernate 4.x](https://www.nuget.org/packages/FluentNHibernate/2.0.3) - - [.NET 3.5 with NHibernate 3 if you like it vintage](https://www.nuget.org/packages/FluentNHibernate.Net35) - -* Create your [first project](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Getting-started#wiki-yourfirstproject). - -## Further reading - -Once you've followed the above, you can compare our [auto mapping](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Auto-mapping) to our [fluent interface](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Fluent-mapping) to see which suits your application, read through our [API documentation](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Fluent-configuration), or just see what's available for reading in our [wiki](https://github.com/FluentNHibernate/fluent-nhibernate/wiki). - -Contributors ---------------------------------------------- - -Fluent NHibernate wouldn't be possible without the time and effort of its contributors. The team comprises of [James Gregory](http://jagregory.com), [Paul Batum](http://www.paulbatum.com), Andrew Stewart, [Hudson Akridge](https://github.com/HudsonAkridge), [Gleb Chermennov](https://github.com/chester89) and [Jorge Rodríguez Galán](https://github.com/jrgcubano). - -**Our valued committers are:** Aaron Jensen, Alexander Gross, Andrew Stewart, Barry Dahlberg, Bobby Johnson, Brian Donahue, Cameron Harris, Chad Myers, Chris Chilvers, Craig Neuwirt, Dan Malcolm, Daniel Mirapalheta, David Archer, David Longnecker, David R. Longnecker, Derick Bailey, Erik Ojebo, Firo, Hudson Akridge, Ivan Zlatev, James Freiwirth, James Gregory, James Kovacs, Jeremy Skinner, Lee Henson, Louis DeJardin, Patric Forsgard, Paul Batum, Roelof Blom, Stuart Childs, Tom Janssens, Tuna Toksoz, U-BSOD\pruiz, di97mni, dschilling, felixg, jeremydmiller, kevm, leebrandt, maxild, robsosno, [Jorge Rodríguez Galán](https://github.com/jrgcubano) and many more.

- -Thanks goes to [Jeremy Miller](http://codebetter.com/blogs/jeremy.miller) for the original idea and implementation. - -Fluent NHibernate is © 2008-2018 [James Gregory](http://jagregory.com) and contributors under the [BSD license](https://github.com/nhibernate/fluent-nhibernate/blob/main/LICENSE) - +![FluentNHibernate logo](https://raw.githubusercontent.com/nhibernate/fluent-nhibernate/main/docs/logo.png) + +[![Build status](https://ci.appveyor.com/api/projects/status/684r2ot07i2lrcij/branch/main?svg=true)](https://ci.appveyor.com/project/nhibernate/fluent-nhibernate/branch/main) +[![NuGet](https://img.shields.io/nuget/v/FluentNHibernate.svg)](https://www.nuget.org/packages/FluentNHibernate) + +## What is FluentNHibernate? +Fluent, XML-less, compile safe, automated, convention-based mappings for NHibernate. *Get your fluent on.* + +## Where can I get it? + +Install using the [FluentNHibernate NuGet package](https://www.nuget.org/packages/FluentNHibernate): + +``` +dotnet add package FluentNHibernate +``` + +## How do I use it? + +* Read the [introduction](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Getting-started). +* Get latest version from NuGet + - [.NETCore2.0, NETStandard2.0 or NET 4.6.1 with NHibernate 5.x](https://www.nuget.org/packages/FluentNHibernate) + - [.NET 4.0 with NHibernate 4.x](https://www.nuget.org/packages/FluentNHibernate/2.0.3) + - [.NET 3.5 with NHibernate 3 if you like it vintage](https://www.nuget.org/packages/FluentNHibernate.Net35) + +* Create your [first project](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Getting-started#wiki-yourfirstproject). + +## Further reading + +Once you've followed the above, you can compare our [auto mapping](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Auto-mapping) to our [fluent interface](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Fluent-mapping) to see which suits your application, read through our [API documentation](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Fluent-configuration), or just see what's available for reading in our [wiki](https://github.com/FluentNHibernate/fluent-nhibernate/wiki). + +Contributors +--------------------------------------------- + +Fluent NHibernate wouldn't be possible without the time and effort of its contributors. The team comprises of [James Gregory](http://jagregory.com), [Paul Batum](http://www.paulbatum.com), Andrew Stewart, [Hudson Akridge](https://github.com/HudsonAkridge), [Gleb Chermennov](https://github.com/chester89) and [Jorge Rodríguez Galán](https://github.com/jrgcubano). + +**Our valued committers are:** Aaron Jensen, Alexander Gross, Andrew Stewart, Barry Dahlberg, Bobby Johnson, Brian Donahue, Cameron Harris, Chad Myers, Chris Chilvers, Craig Neuwirt, Dan Malcolm, Daniel Mirapalheta, David Archer, David Longnecker, David R. Longnecker, Derick Bailey, Erik Ojebo, Firo, Hudson Akridge, Ivan Zlatev, James Freiwirth, James Gregory, James Kovacs, Jeremy Skinner, Lee Henson, Louis DeJardin, Patric Forsgard, Paul Batum, Roelof Blom, Stuart Childs, Tom Janssens, Tuna Toksoz, U-BSOD\pruiz, di97mni, dschilling, felixg, jeremydmiller, kevm, leebrandt, maxild, robsosno, [Jorge Rodríguez Galán](https://github.com/jrgcubano) and many more.

+ +Thanks goes to [Jeremy Miller](http://codebetter.com/blogs/jeremy.miller) for the original idea and implementation. + +Fluent NHibernate is © 2008-2018 [James Gregory](http://jagregory.com) and contributors under the [BSD license](https://github.com/nhibernate/fluent-nhibernate/blob/main/LICENSE) + diff --git a/src/Examples.FirstAutomappedProject/CascadeConvention.cs b/src/Examples.FirstAutomappedProject/CascadeConvention.cs index 9dc6bf5af..caa9cd08d 100644 --- a/src/Examples.FirstAutomappedProject/CascadeConvention.cs +++ b/src/Examples.FirstAutomappedProject/CascadeConvention.cs @@ -1,27 +1,27 @@ -using FluentNHibernate.Conventions; -using FluentNHibernate.Conventions.Instances; - -namespace Examples.FirstAutomappedProject; - -/// -/// This is a convention that will be applied to all entities in your application. What this particular -/// convention does is to specify that many-to-one, one-to-many, and many-to-many relationships will all -/// have their Cascade option set to All. -/// -class CascadeConvention : IReferenceConvention, IHasManyConvention, IHasManyToManyConvention -{ - public void Apply(IManyToOneInstance instance) - { - instance.Cascade.All(); - } - - public void Apply(IOneToManyCollectionInstance instance) - { - instance.Cascade.All(); - } - - public void Apply(IManyToManyCollectionInstance instance) - { - instance.Cascade.All(); - } +using FluentNHibernate.Conventions; +using FluentNHibernate.Conventions.Instances; + +namespace Examples.FirstAutomappedProject; + +/// +/// This is a convention that will be applied to all entities in your application. What this particular +/// convention does is to specify that many-to-one, one-to-many, and many-to-many relationships will all +/// have their Cascade option set to All. +/// +class CascadeConvention : IReferenceConvention, IHasManyConvention, IHasManyToManyConvention +{ + public void Apply(IManyToOneInstance instance) + { + instance.Cascade.All(); + } + + public void Apply(IOneToManyCollectionInstance instance) + { + instance.Cascade.All(); + } + + public void Apply(IManyToManyCollectionInstance instance) + { + instance.Cascade.All(); + } } diff --git a/src/Examples.FirstAutomappedProject/Entities/Employee.cs b/src/Examples.FirstAutomappedProject/Entities/Employee.cs index cfda3a8b3..2827dbe66 100644 --- a/src/Examples.FirstAutomappedProject/Entities/Employee.cs +++ b/src/Examples.FirstAutomappedProject/Entities/Employee.cs @@ -1,9 +1,9 @@ -namespace Examples.FirstAutomappedProject.Entities; - -public class Employee -{ - public virtual int Id { get; protected set; } - public virtual string FirstName { get; set; } - public virtual string LastName { get; set; } - public virtual Store Store { get; set; } +namespace Examples.FirstAutomappedProject.Entities; + +public class Employee +{ + public virtual int Id { get; protected set; } + public virtual string FirstName { get; set; } + public virtual string LastName { get; set; } + public virtual Store Store { get; set; } } diff --git a/src/Examples.FirstAutomappedProject/Entities/Location.cs b/src/Examples.FirstAutomappedProject/Entities/Location.cs index 3be27c222..7ac1f0338 100644 --- a/src/Examples.FirstAutomappedProject/Entities/Location.cs +++ b/src/Examples.FirstAutomappedProject/Entities/Location.cs @@ -1,7 +1,7 @@ -namespace Examples.FirstAutomappedProject.Entities; - -public class Location -{ - public virtual int Aisle { get; set; } - public virtual int Shelf { get; set; } +namespace Examples.FirstAutomappedProject.Entities; + +public class Location +{ + public virtual int Aisle { get; set; } + public virtual int Shelf { get; set; } } diff --git a/src/Examples.FirstAutomappedProject/Entities/Product.cs b/src/Examples.FirstAutomappedProject/Entities/Product.cs index 6ca0bf243..b340ad6c6 100644 --- a/src/Examples.FirstAutomappedProject/Entities/Product.cs +++ b/src/Examples.FirstAutomappedProject/Entities/Product.cs @@ -1,17 +1,17 @@ -using System.Collections.Generic; - -namespace Examples.FirstAutomappedProject.Entities; - -public class Product -{ - public virtual int Id { get; protected set; } - public virtual string Name { get; set; } - public virtual double Price { get; set; } - public virtual Location Location { get; set; } - public virtual IList StoresStockedIn { get; set; } - - public Product() - { - StoresStockedIn = new List(); - } +using System.Collections.Generic; + +namespace Examples.FirstAutomappedProject.Entities; + +public class Product +{ + public virtual int Id { get; protected set; } + public virtual string Name { get; set; } + public virtual double Price { get; set; } + public virtual Location Location { get; set; } + public virtual IList StoresStockedIn { get; set; } + + public Product() + { + StoresStockedIn = new List(); + } } diff --git a/src/Examples.FirstAutomappedProject/Entities/Store.cs b/src/Examples.FirstAutomappedProject/Entities/Store.cs index 3e6884a09..dce1720fb 100644 --- a/src/Examples.FirstAutomappedProject/Entities/Store.cs +++ b/src/Examples.FirstAutomappedProject/Entities/Store.cs @@ -1,29 +1,29 @@ -using System.Collections.Generic; - -namespace Examples.FirstAutomappedProject.Entities; - -public class Store -{ - public virtual int Id { get; protected set; } - public virtual string Name { get; set; } - public virtual IList Products { get; set; } - public virtual IList Staff { get; set; } - - public Store() - { - Products = new List(); - Staff = new List(); - } - - public virtual void AddProduct(Product product) - { - product.StoresStockedIn.Add(this); - Products.Add(product); - } - - public virtual void AddEmployee(Employee employee) - { - employee.Store = this; - Staff.Add(employee); - } +using System.Collections.Generic; + +namespace Examples.FirstAutomappedProject.Entities; + +public class Store +{ + public virtual int Id { get; protected set; } + public virtual string Name { get; set; } + public virtual IList Products { get; set; } + public virtual IList Staff { get; set; } + + public Store() + { + Products = new List(); + Staff = new List(); + } + + public virtual void AddProduct(Product product) + { + product.StoresStockedIn.Add(this); + Products.Add(product); + } + + public virtual void AddEmployee(Employee employee) + { + employee.Store = this; + Staff.Add(employee); + } } diff --git a/src/Examples.FirstAutomappedProject/ExampleAutomappingConfiguration.cs b/src/Examples.FirstAutomappedProject/ExampleAutomappingConfiguration.cs index e3bb64278..65e5f23a8 100644 --- a/src/Examples.FirstAutomappedProject/ExampleAutomappingConfiguration.cs +++ b/src/Examples.FirstAutomappedProject/ExampleAutomappingConfiguration.cs @@ -1,28 +1,28 @@ -using System; -using Examples.FirstAutomappedProject.Entities; -using FluentNHibernate.Automapping; - -namespace Examples.FirstAutomappedProject; - -/// -/// This is an example automapping configuration. You should create your own that either -/// implements IAutomappingConfiguration directly, or inherits from DefaultAutomappingConfiguration. -/// Overriding methods in this class will alter how the automapper behaves. -/// -class ExampleAutomappingConfiguration : DefaultAutomappingConfiguration -{ - public override bool ShouldMap(Type type) - { - // specify the criteria that types must meet in order to be mapped - // any type for which this method returns false will not be mapped. - return type.Namespace == "Examples.FirstAutomappedProject.Entities"; - } - - public override bool IsComponent(Type type) - { - // override this method to specify which types should be treated as components - // if you have a large list of types, you should consider maintaining a list of them - // somewhere or using some form of conventional and/or attribute design - return type == typeof(Location); - } +using System; +using Examples.FirstAutomappedProject.Entities; +using FluentNHibernate.Automapping; + +namespace Examples.FirstAutomappedProject; + +/// +/// This is an example automapping configuration. You should create your own that either +/// implements IAutomappingConfiguration directly, or inherits from DefaultAutomappingConfiguration. +/// Overriding methods in this class will alter how the automapper behaves. +/// +class ExampleAutomappingConfiguration : DefaultAutomappingConfiguration +{ + public override bool ShouldMap(Type type) + { + // specify the criteria that types must meet in order to be mapped + // any type for which this method returns false will not be mapped. + return type.Namespace == "Examples.FirstAutomappedProject.Entities"; + } + + public override bool IsComponent(Type type) + { + // override this method to specify which types should be treated as components + // if you have a large list of types, you should consider maintaining a list of them + // somewhere or using some form of conventional and/or attribute design + return type == typeof(Location); + } } diff --git a/src/Examples.FirstAutomappedProject/Examples.FirstAutomappedProject.csproj b/src/Examples.FirstAutomappedProject/Examples.FirstAutomappedProject.csproj index 6422bfdf9..c2117a46d 100644 --- a/src/Examples.FirstAutomappedProject/Examples.FirstAutomappedProject.csproj +++ b/src/Examples.FirstAutomappedProject/Examples.FirstAutomappedProject.csproj @@ -1,25 +1,25 @@ - - - - net48 - Exe - AnyCpu - false - - - - - - - - - - - - - - - - - + + + + net48 + Exe + AnyCpu + false + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Examples.FirstAutomappedProject/Program.cs b/src/Examples.FirstAutomappedProject/Program.cs index dd5d56833..91916ddba 100644 --- a/src/Examples.FirstAutomappedProject/Program.cs +++ b/src/Examples.FirstAutomappedProject/Program.cs @@ -1,171 +1,171 @@ -using System; -using System.IO; -using Examples.FirstAutomappedProject.Entities; -using FluentNHibernate.Automapping; -using FluentNHibernate.Cfg; -using FluentNHibernate.Cfg.Db; -using NHibernate; -using NHibernate.Cfg; -using NHibernate.Tool.hbm2ddl; - -namespace Examples.FirstAutomappedProject; - -/// -/// Example automapped project. -/// -/// Points of interest: -/// Program.CreateSessionFactory() -/// Program.CreateAutomappings() -/// -/// ExampleAutomappingConfiguration -/// CascadeConvention -/// -class Program -{ - private const string DbFile = "firstProgram.db"; - - static void Main() - { - // create our NHibernate session factory - var sessionFactory = CreateSessionFactory(); - - using (var session = sessionFactory.OpenSession()) - { - // populate the database - using (var transaction = session.BeginTransaction()) - { - // create a couple of Stores each with some Products and Employees - var barginBasin = new Store { Name = "Bargin Basin" }; - var superMart = new Store { Name = "SuperMart" }; - - var potatoes = new Product { Name = "Potatoes", Price = 3.60 }; - var fish = new Product { Name = "Fish", Price = 4.49 }; - var milk = new Product { Name = "Milk", Price = 0.79 }; - var bread = new Product { Name = "Bread", Price = 1.29 }; - var cheese = new Product { Name = "Cheese", Price = 2.10 }; - var waffles = new Product { Name = "Waffles", Price = 2.41 }; - - var daisy = new Employee { FirstName = "Daisy", LastName = "Harrison" }; - var jack = new Employee { FirstName = "Jack", LastName = "Torrance" }; - var sue = new Employee { FirstName = "Sue", LastName = "Walkters" }; - var bill = new Employee { FirstName = "Bill", LastName = "Taft" }; - var joan = new Employee { FirstName = "Joan", LastName = "Pope" }; - - // add products to the stores, there's some crossover in the products in each - // store, because the store-product relationship is many-to-many - AddProductsToStore(barginBasin, potatoes, fish, milk, bread, cheese); - AddProductsToStore(superMart, bread, cheese, waffles); - - // add employees to the stores, this relationship is a one-to-many, so one - // employee can only work at one store at a time - AddEmployeesToStore(barginBasin, daisy, jack, sue); - AddEmployeesToStore(superMart, bill, joan); - - // save both stores, this saves everything else via cascading - session.SaveOrUpdate(barginBasin); - session.SaveOrUpdate(superMart); - - transaction.Commit(); - } - } - - using (var session = sessionFactory.OpenSession()) - { - // retreive all stores and display them - using (session.BeginTransaction()) - { - var stores = session.CreateCriteria(typeof(Store)) - .List(); - - foreach (var store in stores) - { - WriteStorePretty(store); - } - } - } - - Console.ReadKey(); - } - - static AutoPersistenceModel CreateAutomappings() - { - // This is the actual automapping - use AutoMap to start automapping, - // then pick one of the static methods to specify what to map (in this case - // all the classes in the assembly that contains Employee), and then either - // use the Setup and Where methods to restrict that behaviour, or (preferably) - // supply a configuration instance of your definition to control the automapper. - return AutoMap.AssemblyOf(new ExampleAutomappingConfiguration()) - .Conventions.Add(); - } - - /// - /// Configure NHibernate. This method returns an ISessionFactory instance that is - /// populated with mappings created by Fluent NHibernate. - /// - /// Line 1: Begin configuration - /// 2+3: Configure the database being used (SQLite file db) - /// 4+5: Specify what mappings are going to be used (Automappings from the CreateAutomappings method) - /// 6: Expose the underlying configuration instance to the BuildSchema method, - /// this creates the database. - /// 7: Finally, build the session factory. - /// - /// - private static ISessionFactory CreateSessionFactory() - { - return Fluently.Configure() - .Database(SQLiteConfiguration.Standard - .UsingFile(DbFile)) - .Mappings(m => - m.AutoMappings.Add(CreateAutomappings)) - .ExposeConfiguration(BuildSchema) - .BuildSessionFactory(); - } - - private static void BuildSchema(Configuration config) - { - // delete the existing db on each run - if (File.Exists(DbFile)) - File.Delete(DbFile); - - // this NHibernate tool takes a configuration (with mapping info in) - // and exports a database schema from it - new SchemaExport(config) - .Create(false, true); - } - - private static void WriteStorePretty(Store store) - { - Console.WriteLine(store.Name); - Console.WriteLine(" Products:"); - - foreach (var product in store.Products) - { - Console.WriteLine(" " + product.Name); - } - - Console.WriteLine(" Staff:"); - - foreach (var employee in store.Staff) - { - Console.WriteLine(" " + employee.FirstName + " " + employee.LastName); - } - - Console.WriteLine(); - } - - public static void AddProductsToStore(Store store, params Product[] products) - { - foreach (var product in products) - { - store.AddProduct(product); - } - } - - public static void AddEmployeesToStore(Store store, params Employee[] employees) - { - foreach (var employee in employees) - { - store.AddEmployee(employee); - } - } +using System; +using System.IO; +using Examples.FirstAutomappedProject.Entities; +using FluentNHibernate.Automapping; +using FluentNHibernate.Cfg; +using FluentNHibernate.Cfg.Db; +using NHibernate; +using NHibernate.Cfg; +using NHibernate.Tool.hbm2ddl; + +namespace Examples.FirstAutomappedProject; + +/// +/// Example automapped project. +/// +/// Points of interest: +/// Program.CreateSessionFactory() +/// Program.CreateAutomappings() +/// +/// ExampleAutomappingConfiguration +/// CascadeConvention +/// +class Program +{ + private const string DbFile = "firstProgram.db"; + + static void Main() + { + // create our NHibernate session factory + var sessionFactory = CreateSessionFactory(); + + using (var session = sessionFactory.OpenSession()) + { + // populate the database + using (var transaction = session.BeginTransaction()) + { + // create a couple of Stores each with some Products and Employees + var barginBasin = new Store { Name = "Bargin Basin" }; + var superMart = new Store { Name = "SuperMart" }; + + var potatoes = new Product { Name = "Potatoes", Price = 3.60 }; + var fish = new Product { Name = "Fish", Price = 4.49 }; + var milk = new Product { Name = "Milk", Price = 0.79 }; + var bread = new Product { Name = "Bread", Price = 1.29 }; + var cheese = new Product { Name = "Cheese", Price = 2.10 }; + var waffles = new Product { Name = "Waffles", Price = 2.41 }; + + var daisy = new Employee { FirstName = "Daisy", LastName = "Harrison" }; + var jack = new Employee { FirstName = "Jack", LastName = "Torrance" }; + var sue = new Employee { FirstName = "Sue", LastName = "Walkters" }; + var bill = new Employee { FirstName = "Bill", LastName = "Taft" }; + var joan = new Employee { FirstName = "Joan", LastName = "Pope" }; + + // add products to the stores, there's some crossover in the products in each + // store, because the store-product relationship is many-to-many + AddProductsToStore(barginBasin, potatoes, fish, milk, bread, cheese); + AddProductsToStore(superMart, bread, cheese, waffles); + + // add employees to the stores, this relationship is a one-to-many, so one + // employee can only work at one store at a time + AddEmployeesToStore(barginBasin, daisy, jack, sue); + AddEmployeesToStore(superMart, bill, joan); + + // save both stores, this saves everything else via cascading + session.SaveOrUpdate(barginBasin); + session.SaveOrUpdate(superMart); + + transaction.Commit(); + } + } + + using (var session = sessionFactory.OpenSession()) + { + // retreive all stores and display them + using (session.BeginTransaction()) + { + var stores = session.CreateCriteria(typeof(Store)) + .List(); + + foreach (var store in stores) + { + WriteStorePretty(store); + } + } + } + + Console.ReadKey(); + } + + static AutoPersistenceModel CreateAutomappings() + { + // This is the actual automapping - use AutoMap to start automapping, + // then pick one of the static methods to specify what to map (in this case + // all the classes in the assembly that contains Employee), and then either + // use the Setup and Where methods to restrict that behaviour, or (preferably) + // supply a configuration instance of your definition to control the automapper. + return AutoMap.AssemblyOf(new ExampleAutomappingConfiguration()) + .Conventions.Add(); + } + + /// + /// Configure NHibernate. This method returns an ISessionFactory instance that is + /// populated with mappings created by Fluent NHibernate. + /// + /// Line 1: Begin configuration + /// 2+3: Configure the database being used (SQLite file db) + /// 4+5: Specify what mappings are going to be used (Automappings from the CreateAutomappings method) + /// 6: Expose the underlying configuration instance to the BuildSchema method, + /// this creates the database. + /// 7: Finally, build the session factory. + /// + /// + private static ISessionFactory CreateSessionFactory() + { + return Fluently.Configure() + .Database(SQLiteConfiguration.Standard + .UsingFile(DbFile)) + .Mappings(m => + m.AutoMappings.Add(CreateAutomappings)) + .ExposeConfiguration(BuildSchema) + .BuildSessionFactory(); + } + + private static void BuildSchema(Configuration config) + { + // delete the existing db on each run + if (File.Exists(DbFile)) + File.Delete(DbFile); + + // this NHibernate tool takes a configuration (with mapping info in) + // and exports a database schema from it + new SchemaExport(config) + .Create(false, true); + } + + private static void WriteStorePretty(Store store) + { + Console.WriteLine(store.Name); + Console.WriteLine(" Products:"); + + foreach (var product in store.Products) + { + Console.WriteLine(" " + product.Name); + } + + Console.WriteLine(" Staff:"); + + foreach (var employee in store.Staff) + { + Console.WriteLine(" " + employee.FirstName + " " + employee.LastName); + } + + Console.WriteLine(); + } + + public static void AddProductsToStore(Store store, params Product[] products) + { + foreach (var product in products) + { + store.AddProduct(product); + } + } + + public static void AddEmployeesToStore(Store store, params Employee[] employees) + { + foreach (var employee in employees) + { + store.AddEmployee(employee); + } + } } diff --git a/src/Examples.FirstAutomappedProject/Properties/AssemblyInfo.cs b/src/Examples.FirstAutomappedProject/Properties/AssemblyInfo.cs index 31b149844..a260a63e9 100644 --- a/src/Examples.FirstAutomappedProject/Properties/AssemblyInfo.cs +++ b/src/Examples.FirstAutomappedProject/Properties/AssemblyInfo.cs @@ -1,5 +1,5 @@ -using System; -using System.Runtime.InteropServices; - -[assembly: ComVisible(false)] +using System; +using System.Runtime.InteropServices; + +[assembly: ComVisible(false)] [assembly: CLSCompliant(true)] diff --git a/src/Examples.FirstProject/Entities/Employee.cs b/src/Examples.FirstProject/Entities/Employee.cs index 6f20f130d..c86f03e23 100644 --- a/src/Examples.FirstProject/Entities/Employee.cs +++ b/src/Examples.FirstProject/Entities/Employee.cs @@ -1,11 +1,11 @@ -using Examples.FirstProject.Entities; - -namespace Examples.FirstProject.Entities; - -public class Employee -{ - public virtual int Id { get; protected set; } - public virtual string FirstName { get; set; } - public virtual string LastName { get; set; } - public virtual Store Store { get; set; } +using Examples.FirstProject.Entities; + +namespace Examples.FirstProject.Entities; + +public class Employee +{ + public virtual int Id { get; protected set; } + public virtual string FirstName { get; set; } + public virtual string LastName { get; set; } + public virtual Store Store { get; set; } } diff --git a/src/Examples.FirstProject/Entities/Product.cs b/src/Examples.FirstProject/Entities/Product.cs index b8dc2c376..afb9d0522 100644 --- a/src/Examples.FirstProject/Entities/Product.cs +++ b/src/Examples.FirstProject/Entities/Product.cs @@ -1,23 +1,23 @@ -using System.Collections.Generic; - -namespace Examples.FirstProject.Entities; - -public class Product -{ - public virtual int Id { get; protected set; } - public virtual string Name { get; set; } - public virtual double Price { get; set; } - public virtual Location Location { get; set; } - public virtual IList StoresStockedIn { get; set; } - - public Product() - { - StoresStockedIn = new List(); - } -} - -public class Location -{ - public virtual int Aisle { get; set; } - public virtual int Shelf { get; set; } +using System.Collections.Generic; + +namespace Examples.FirstProject.Entities; + +public class Product +{ + public virtual int Id { get; protected set; } + public virtual string Name { get; set; } + public virtual double Price { get; set; } + public virtual Location Location { get; set; } + public virtual IList StoresStockedIn { get; set; } + + public Product() + { + StoresStockedIn = new List(); + } +} + +public class Location +{ + public virtual int Aisle { get; set; } + public virtual int Shelf { get; set; } } diff --git a/src/Examples.FirstProject/Entities/Store.cs b/src/Examples.FirstProject/Entities/Store.cs index 72d874ffe..8db3a5eb4 100644 --- a/src/Examples.FirstProject/Entities/Store.cs +++ b/src/Examples.FirstProject/Entities/Store.cs @@ -1,29 +1,29 @@ -using System.Collections.Generic; - -namespace Examples.FirstProject.Entities; - -public class Store -{ - public virtual int Id { get; protected set; } - public virtual string Name { get; set; } - public virtual IList Products { get; set; } - public virtual IList Staff { get; set; } - - public Store() - { - Products = new List(); - Staff = new List(); - } - - public virtual void AddProduct(Product product) - { - product.StoresStockedIn.Add(this); - Products.Add(product); - } - - public virtual void AddEmployee(Employee employee) - { - employee.Store = this; - Staff.Add(employee); - } +using System.Collections.Generic; + +namespace Examples.FirstProject.Entities; + +public class Store +{ + public virtual int Id { get; protected set; } + public virtual string Name { get; set; } + public virtual IList Products { get; set; } + public virtual IList Staff { get; set; } + + public Store() + { + Products = new List(); + Staff = new List(); + } + + public virtual void AddProduct(Product product) + { + product.StoresStockedIn.Add(this); + Products.Add(product); + } + + public virtual void AddEmployee(Employee employee) + { + employee.Store = this; + Staff.Add(employee); + } } diff --git a/src/Examples.FirstProject/Examples.FirstProject.csproj b/src/Examples.FirstProject/Examples.FirstProject.csproj index 5772e427f..a516032be 100644 --- a/src/Examples.FirstProject/Examples.FirstProject.csproj +++ b/src/Examples.FirstProject/Examples.FirstProject.csproj @@ -1,25 +1,25 @@ - - - - net48 - Exe - AnyCpu - false - - - - - - - - - - - - - - - - - + + + + net48 + Exe + AnyCpu + false + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Examples.FirstProject/Mappings/EmployeeMap.cs b/src/Examples.FirstProject/Mappings/EmployeeMap.cs index c37fc4c2b..32724bba4 100644 --- a/src/Examples.FirstProject/Mappings/EmployeeMap.cs +++ b/src/Examples.FirstProject/Mappings/EmployeeMap.cs @@ -1,15 +1,15 @@ -using Examples.FirstProject.Entities; -using FluentNHibernate.Mapping; - -namespace Examples.FirstProject.Mappings; - -public class EmployeeMap : ClassMap -{ - public EmployeeMap() - { - Id(x => x.Id); - Map(x => x.FirstName); - Map(x => x.LastName); - References(x => x.Store); - } +using Examples.FirstProject.Entities; +using FluentNHibernate.Mapping; + +namespace Examples.FirstProject.Mappings; + +public class EmployeeMap : ClassMap +{ + public EmployeeMap() + { + Id(x => x.Id); + Map(x => x.FirstName); + Map(x => x.LastName); + References(x => x.Store); + } } diff --git a/src/Examples.FirstProject/Mappings/LocationMap.cs b/src/Examples.FirstProject/Mappings/LocationMap.cs index e2b32f636..c59aa2d99 100644 --- a/src/Examples.FirstProject/Mappings/LocationMap.cs +++ b/src/Examples.FirstProject/Mappings/LocationMap.cs @@ -1,13 +1,13 @@ -using Examples.FirstProject.Entities; -using FluentNHibernate.Mapping; - -namespace Examples.FirstProject.Mappings; - -public class LocationMap : ComponentMap -{ - public LocationMap() - { - Map(x => x.Aisle); - Map(x => x.Shelf); - } +using Examples.FirstProject.Entities; +using FluentNHibernate.Mapping; + +namespace Examples.FirstProject.Mappings; + +public class LocationMap : ComponentMap +{ + public LocationMap() + { + Map(x => x.Aisle); + Map(x => x.Shelf); + } } diff --git a/src/Examples.FirstProject/Mappings/ProductMap.cs b/src/Examples.FirstProject/Mappings/ProductMap.cs index b2e8e3d97..a14987af6 100644 --- a/src/Examples.FirstProject/Mappings/ProductMap.cs +++ b/src/Examples.FirstProject/Mappings/ProductMap.cs @@ -1,20 +1,20 @@ -using Examples.FirstProject.Entities; -using FluentNHibernate.Mapping; - -namespace Examples.FirstProject.Mappings; - -public class ProductMap : ClassMap -{ - public ProductMap() - { - Id(x => x.Id); - Map(x => x.Name); - Map(x => x.Price); - HasManyToMany(x => x.StoresStockedIn) - .Cascade.All() - .Inverse() - .Table("StoreProduct"); - - Component(x => x.Location); - } +using Examples.FirstProject.Entities; +using FluentNHibernate.Mapping; + +namespace Examples.FirstProject.Mappings; + +public class ProductMap : ClassMap +{ + public ProductMap() + { + Id(x => x.Id); + Map(x => x.Name); + Map(x => x.Price); + HasManyToMany(x => x.StoresStockedIn) + .Cascade.All() + .Inverse() + .Table("StoreProduct"); + + Component(x => x.Location); + } } diff --git a/src/Examples.FirstProject/Mappings/StoreMap.cs b/src/Examples.FirstProject/Mappings/StoreMap.cs index 3f8f15b75..d9a2541a9 100644 --- a/src/Examples.FirstProject/Mappings/StoreMap.cs +++ b/src/Examples.FirstProject/Mappings/StoreMap.cs @@ -1,19 +1,19 @@ -using Examples.FirstProject.Entities; -using FluentNHibernate.Mapping; - -namespace Examples.FirstProject.Mappings; - -public class StoreMap : ClassMap -{ - public StoreMap() - { - Id(x => x.Id); - Map(x => x.Name); - HasManyToMany(x => x.Products) - .Cascade.All() - .Table("StoreProduct"); - HasMany(x => x.Staff) - .Cascade.All() - .Inverse(); - } +using Examples.FirstProject.Entities; +using FluentNHibernate.Mapping; + +namespace Examples.FirstProject.Mappings; + +public class StoreMap : ClassMap +{ + public StoreMap() + { + Id(x => x.Id); + Map(x => x.Name); + HasManyToMany(x => x.Products) + .Cascade.All() + .Table("StoreProduct"); + HasMany(x => x.Staff) + .Cascade.All() + .Inverse(); + } } diff --git a/src/Examples.FirstProject/Program.cs b/src/Examples.FirstProject/Program.cs index 1f7236879..69a647b36 100644 --- a/src/Examples.FirstProject/Program.cs +++ b/src/Examples.FirstProject/Program.cs @@ -1,137 +1,137 @@ -using System; -using System.IO; -using Examples.FirstProject.Entities; -using FluentNHibernate.Cfg; -using FluentNHibernate.Cfg.Db; -using NHibernate; -using NHibernate.Cfg; -using NHibernate.Tool.hbm2ddl; - -namespace Examples.FirstProject; - -class Program -{ - private const string DbFile = "firstProgram.db"; - - static void Main() - { - // create our NHibernate session factory - var sessionFactory = CreateSessionFactory(); - - using (var session = sessionFactory.OpenSession()) - { - // populate the database - using (var transaction = session.BeginTransaction()) - { - // create a couple of Stores each with some Products and Employees - var barginBasin = new Store { Name = "Bargin Basin" }; - var superMart = new Store { Name = "SuperMart" }; - - var potatoes = new Product { Name = "Potatoes", Price = 3.60 }; - var fish = new Product { Name = "Fish", Price = 4.49 }; - var milk = new Product { Name = "Milk", Price = 0.79 }; - var bread = new Product { Name = "Bread", Price = 1.29 }; - var cheese = new Product { Name = "Cheese", Price = 2.10 }; - var waffles = new Product { Name = "Waffles", Price = 2.41 }; - - var daisy = new Employee { FirstName = "Daisy", LastName = "Harrison" }; - var jack = new Employee { FirstName = "Jack", LastName = "Torrance" }; - var sue = new Employee { FirstName = "Sue", LastName = "Walkters" }; - var bill = new Employee { FirstName = "Bill", LastName = "Taft" }; - var joan = new Employee { FirstName = "Joan", LastName = "Pope" }; - - // add products to the stores, there's some crossover in the products in each - // store, because the store-product relationship is many-to-many - AddProductsToStore(barginBasin, potatoes, fish, milk, bread, cheese); - AddProductsToStore(superMart, bread, cheese, waffles); - - // add employees to the stores, this relationship is a one-to-many, so one - // employee can only work at one store at a time - AddEmployeesToStore(barginBasin, daisy, jack, sue); - AddEmployeesToStore(superMart, bill, joan); - - // save both stores, this saves everything else via cascading - session.SaveOrUpdate(barginBasin); - session.SaveOrUpdate(superMart); - - transaction.Commit(); - } - } - - using (var session = sessionFactory.OpenSession()) - { - // retreive all stores and display them - using (session.BeginTransaction()) - { - var stores = session.CreateCriteria(typeof(Store)) - .List(); - - foreach (var store in stores) - { - WriteStorePretty(store); - } - } - } - - Console.ReadKey(); - } - - private static ISessionFactory CreateSessionFactory() - { - return Fluently.Configure() - .Database(SQLiteConfiguration.Standard - .UsingFile(DbFile)) - .Mappings(m => - m.FluentMappings.AddFromAssemblyOf()) - .ExposeConfiguration(BuildSchema) - .BuildSessionFactory(); - } - - private static void BuildSchema(Configuration config) - { - // delete the existing db on each run - if (File.Exists(DbFile)) - File.Delete(DbFile); - - // this NHibernate tool takes a configuration (with mapping info in) - // and exports a database schema from it - new SchemaExport(config) - .Create(false, true); - } - - private static void WriteStorePretty(Store store) - { - Console.WriteLine(store.Name); - Console.WriteLine(" Products:"); - - foreach (var product in store.Products) - { - Console.WriteLine(" " + product.Name); - } - - Console.WriteLine(" Staff:"); - - foreach (var employee in store.Staff) - { - Console.WriteLine(" " + employee.FirstName + " " + employee.LastName); - } - - Console.WriteLine(); - } - - public static void AddProductsToStore(Store store, params Product[] products) - { - foreach (var product in products) - { - store.AddProduct(product); - } - } - - public static void AddEmployeesToStore(Store store, params Employee[] employees) - { - foreach (var employee in employees) - { - store.AddEmployee(employee); - } - } +using System; +using System.IO; +using Examples.FirstProject.Entities; +using FluentNHibernate.Cfg; +using FluentNHibernate.Cfg.Db; +using NHibernate; +using NHibernate.Cfg; +using NHibernate.Tool.hbm2ddl; + +namespace Examples.FirstProject; + +class Program +{ + private const string DbFile = "firstProgram.db"; + + static void Main() + { + // create our NHibernate session factory + var sessionFactory = CreateSessionFactory(); + + using (var session = sessionFactory.OpenSession()) + { + // populate the database + using (var transaction = session.BeginTransaction()) + { + // create a couple of Stores each with some Products and Employees + var barginBasin = new Store { Name = "Bargin Basin" }; + var superMart = new Store { Name = "SuperMart" }; + + var potatoes = new Product { Name = "Potatoes", Price = 3.60 }; + var fish = new Product { Name = "Fish", Price = 4.49 }; + var milk = new Product { Name = "Milk", Price = 0.79 }; + var bread = new Product { Name = "Bread", Price = 1.29 }; + var cheese = new Product { Name = "Cheese", Price = 2.10 }; + var waffles = new Product { Name = "Waffles", Price = 2.41 }; + + var daisy = new Employee { FirstName = "Daisy", LastName = "Harrison" }; + var jack = new Employee { FirstName = "Jack", LastName = "Torrance" }; + var sue = new Employee { FirstName = "Sue", LastName = "Walkters" }; + var bill = new Employee { FirstName = "Bill", LastName = "Taft" }; + var joan = new Employee { FirstName = "Joan", LastName = "Pope" }; + + // add products to the stores, there's some crossover in the products in each + // store, because the store-product relationship is many-to-many + AddProductsToStore(barginBasin, potatoes, fish, milk, bread, cheese); + AddProductsToStore(superMart, bread, cheese, waffles); + + // add employees to the stores, this relationship is a one-to-many, so one + // employee can only work at one store at a time + AddEmployeesToStore(barginBasin, daisy, jack, sue); + AddEmployeesToStore(superMart, bill, joan); + + // save both stores, this saves everything else via cascading + session.SaveOrUpdate(barginBasin); + session.SaveOrUpdate(superMart); + + transaction.Commit(); + } + } + + using (var session = sessionFactory.OpenSession()) + { + // retreive all stores and display them + using (session.BeginTransaction()) + { + var stores = session.CreateCriteria(typeof(Store)) + .List(); + + foreach (var store in stores) + { + WriteStorePretty(store); + } + } + } + + Console.ReadKey(); + } + + private static ISessionFactory CreateSessionFactory() + { + return Fluently.Configure() + .Database(SQLiteConfiguration.Standard + .UsingFile(DbFile)) + .Mappings(m => + m.FluentMappings.AddFromAssemblyOf()) + .ExposeConfiguration(BuildSchema) + .BuildSessionFactory(); + } + + private static void BuildSchema(Configuration config) + { + // delete the existing db on each run + if (File.Exists(DbFile)) + File.Delete(DbFile); + + // this NHibernate tool takes a configuration (with mapping info in) + // and exports a database schema from it + new SchemaExport(config) + .Create(false, true); + } + + private static void WriteStorePretty(Store store) + { + Console.WriteLine(store.Name); + Console.WriteLine(" Products:"); + + foreach (var product in store.Products) + { + Console.WriteLine(" " + product.Name); + } + + Console.WriteLine(" Staff:"); + + foreach (var employee in store.Staff) + { + Console.WriteLine(" " + employee.FirstName + " " + employee.LastName); + } + + Console.WriteLine(); + } + + public static void AddProductsToStore(Store store, params Product[] products) + { + foreach (var product in products) + { + store.AddProduct(product); + } + } + + public static void AddEmployeesToStore(Store store, params Employee[] employees) + { + foreach (var employee in employees) + { + store.AddEmployee(employee); + } + } } diff --git a/src/Examples.FirstProject/Properties/AssemblyInfo.cs b/src/Examples.FirstProject/Properties/AssemblyInfo.cs index 31b149844..a260a63e9 100644 --- a/src/Examples.FirstProject/Properties/AssemblyInfo.cs +++ b/src/Examples.FirstProject/Properties/AssemblyInfo.cs @@ -1,5 +1,5 @@ -using System; -using System.Runtime.InteropServices; - -[assembly: ComVisible(false)] +using System; +using System.Runtime.InteropServices; + +[assembly: ComVisible(false)] [assembly: CLSCompliant(true)] diff --git a/src/FluentNHibernate.Specs.ExternalFixtures/Component.cs b/src/FluentNHibernate.Specs.ExternalFixtures/Component.cs index 0e2e0ed5f..85de4c297 100644 --- a/src/FluentNHibernate.Specs.ExternalFixtures/Component.cs +++ b/src/FluentNHibernate.Specs.ExternalFixtures/Component.cs @@ -1,3 +1,3 @@ -namespace FluentNHibernate.Specs.ExternalFixtures; - +namespace FluentNHibernate.Specs.ExternalFixtures; + public class Component {} diff --git a/src/FluentNHibernate.Specs.ExternalFixtures/Entity.cs b/src/FluentNHibernate.Specs.ExternalFixtures/Entity.cs index cff0b74c9..c93248f11 100644 --- a/src/FluentNHibernate.Specs.ExternalFixtures/Entity.cs +++ b/src/FluentNHibernate.Specs.ExternalFixtures/Entity.cs @@ -1,52 +1,52 @@ -using System.Collections.Generic; - -namespace FluentNHibernate.Specs.ExternalFixtures; - -public class Entity -{ - EntityChild readOnlyChild; - - public int Id { get; set; } - public string One { get; set; } - public TestEnum Enum { get; set; } - public Entity Parent { get; set; } - public IList Children { get; set; } - public Component Component { get; set; } - - public enum TestEnum {} - - public EntityChild ReadOnlyChild - { - get { return readOnlyChild; } - } -} - -public class EntityChild -{} - -public abstract class A_Child : B_Parent -{ - -} - -public class B_Parent -{ - public int Id { get; set; } - public string Name { get; set; } -} - -public class Child : Parent -{ - -} - -public class Parent -{ - public int Id { get; set; } - public Component Component { get; set; } -} - -public class ChildChild : Child -{ - +using System.Collections.Generic; + +namespace FluentNHibernate.Specs.ExternalFixtures; + +public class Entity +{ + EntityChild readOnlyChild; + + public int Id { get; set; } + public string One { get; set; } + public TestEnum Enum { get; set; } + public Entity Parent { get; set; } + public IList Children { get; set; } + public Component Component { get; set; } + + public enum TestEnum {} + + public EntityChild ReadOnlyChild + { + get { return readOnlyChild; } + } +} + +public class EntityChild +{} + +public abstract class A_Child : B_Parent +{ + +} + +public class B_Parent +{ + public int Id { get; set; } + public string Name { get; set; } +} + +public class Child : Parent +{ + +} + +public class Parent +{ + public int Id { get; set; } + public Component Component { get; set; } +} + +public class ChildChild : Child +{ + } diff --git a/src/FluentNHibernate.Specs.ExternalFixtures/FluentNHibernate.Specs.ExternalFixtures.csproj b/src/FluentNHibernate.Specs.ExternalFixtures/FluentNHibernate.Specs.ExternalFixtures.csproj index 62ddda331..efe8df941 100644 --- a/src/FluentNHibernate.Specs.ExternalFixtures/FluentNHibernate.Specs.ExternalFixtures.csproj +++ b/src/FluentNHibernate.Specs.ExternalFixtures/FluentNHibernate.Specs.ExternalFixtures.csproj @@ -1,11 +1,11 @@ - - - net48;netstandard2.0 - false - - - - - - + + + net48;netstandard2.0 + false + + + + + + \ No newline at end of file diff --git a/src/FluentNHibernate.Specs.ExternalFixtures/Overrides/EntityBatchSizeOverride.cs b/src/FluentNHibernate.Specs.ExternalFixtures/Overrides/EntityBatchSizeOverride.cs index d77eae0be..4b41d7956 100644 --- a/src/FluentNHibernate.Specs.ExternalFixtures/Overrides/EntityBatchSizeOverride.cs +++ b/src/FluentNHibernate.Specs.ExternalFixtures/Overrides/EntityBatchSizeOverride.cs @@ -1,12 +1,12 @@ -using FluentNHibernate.Automapping; -using FluentNHibernate.Automapping.Alterations; - -namespace FluentNHibernate.Specs.ExternalFixtures.Overrides; - -public class EntityBatchSizeOverride : IAutoMappingOverride -{ - public void Override(AutoMapping mapping) - { - mapping.BatchSize(1234); - } +using FluentNHibernate.Automapping; +using FluentNHibernate.Automapping.Alterations; + +namespace FluentNHibernate.Specs.ExternalFixtures.Overrides; + +public class EntityBatchSizeOverride : IAutoMappingOverride +{ + public void Override(AutoMapping mapping) + { + mapping.BatchSize(1234); + } } diff --git a/src/FluentNHibernate.Specs.ExternalFixtures/Properties/AssemblyInfo.cs b/src/FluentNHibernate.Specs.ExternalFixtures/Properties/AssemblyInfo.cs index 31b149844..a260a63e9 100644 --- a/src/FluentNHibernate.Specs.ExternalFixtures/Properties/AssemblyInfo.cs +++ b/src/FluentNHibernate.Specs.ExternalFixtures/Properties/AssemblyInfo.cs @@ -1,5 +1,5 @@ -using System; -using System.Runtime.InteropServices; - -[assembly: ComVisible(false)] +using System; +using System.Runtime.InteropServices; + +[assembly: ComVisible(false)] [assembly: CLSCompliant(true)] diff --git a/src/FluentNHibernate.Specs/Automapping/AutoMapBackwardsCompatibilitySpecs.cs b/src/FluentNHibernate.Specs/Automapping/AutoMapBackwardsCompatibilitySpecs.cs index 4815d100f..f79fd9f84 100644 --- a/src/FluentNHibernate.Specs/Automapping/AutoMapBackwardsCompatibilitySpecs.cs +++ b/src/FluentNHibernate.Specs/Automapping/AutoMapBackwardsCompatibilitySpecs.cs @@ -1,47 +1,47 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using FluentNHibernate.Automapping; -using FluentNHibernate.Specs.Automapping.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.Automapping; -// just verify that the obsolete methods still work until we bin them entirely - -public class when_using_automap_obsolete_where_method_for_assembly_of : AutoMapObsoleteSpec -{ - Because of = () => - AutoMap.AssemblyOf(where_clause) - .BuildMappings(); - - It should_use_the_where_clause_provided = () => - was_called.Should().BeTrue(); -} - -public class when_using_automap_obsolete_where_method_for_an_assembly : AutoMapObsoleteSpec -{ - Because of = () => - AutoMap.Assembly(typeof(EntityUsingPrivateFields).Assembly, where_clause) - .BuildMappings(); - - It should_use_the_where_clause_provided = () => - was_called.Should().BeTrue(); -} - -public class when_using_automap_obsolete_where_method_for_a_source : AutoMapObsoleteSpec -{ - Because of = () => - AutoMap.Source(new StubTypeSource(typeof(EntityUsingPrivateFields)), where_clause) - .BuildMappings(); - - It should_use_the_where_clause_provided = () => - was_called.Should().BeTrue(); -} - -public abstract class AutoMapObsoleteSpec -{ - protected static Func where_clause = x => !(was_called = true); - protected static bool was_called; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FluentNHibernate.Automapping; +using FluentNHibernate.Specs.Automapping.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.Automapping; +// just verify that the obsolete methods still work until we bin them entirely + +public class when_using_automap_obsolete_where_method_for_assembly_of : AutoMapObsoleteSpec +{ + Because of = () => + AutoMap.AssemblyOf(where_clause) + .BuildMappings(); + + It should_use_the_where_clause_provided = () => + was_called.Should().BeTrue(); +} + +public class when_using_automap_obsolete_where_method_for_an_assembly : AutoMapObsoleteSpec +{ + Because of = () => + AutoMap.Assembly(typeof(EntityUsingPrivateFields).Assembly, where_clause) + .BuildMappings(); + + It should_use_the_where_clause_provided = () => + was_called.Should().BeTrue(); +} + +public class when_using_automap_obsolete_where_method_for_a_source : AutoMapObsoleteSpec +{ + Because of = () => + AutoMap.Source(new StubTypeSource(typeof(EntityUsingPrivateFields)), where_clause) + .BuildMappings(); + + It should_use_the_where_clause_provided = () => + was_called.Should().BeTrue(); +} + +public abstract class AutoMapObsoleteSpec +{ + protected static Func where_clause = x => !(was_called = true); + protected static bool was_called; } diff --git a/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.Conventions.cs b/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.Conventions.cs index d191520e2..6ead1f864 100644 --- a/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.Conventions.cs +++ b/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.Conventions.cs @@ -1,103 +1,103 @@ -using System; -using System.Data; -using System.Xml; -using FluentNHibernate.Automapping; -using FluentNHibernate.Conventions; -using FluentNHibernate.Conventions.Inspections; -using FluentNHibernate.Conventions.Instances; -using FluentNHibernate.Specs.Automapping.Fixtures; -using FluentNHibernate.Specs.ExternalFixtures; -using Machine.Specifications; -using NHibernate.SqlTypes; -using NHibernate.UserTypes; - -namespace FluentNHibernate.Specs.Automapping; - -public class when_the_automapper_maps_with_a_property_convention -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(Entity))) - .Conventions.Add(); - - Because of = () => - xml = mapper.BuildMappingFor().ToXml(); - - It should_apply_the_convention_to_any_properties = () => - xml.Element("class/property[@name='One']/column").HasAttribute("name", "OneXX"); - - static AutoPersistenceModel mapper; - static XmlDocument xml; - - class XXAppenderPropertyConvention : IPropertyConvention - { - public void Apply(IPropertyInstance instance) - { - instance.Column(instance.Name + "XX"); - } - } -} - -public class when_the_automapper_maps_a_readonly_reference_with_an_access_convention -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(Entity))) - .Conventions.Add(); - - Because of = () => - xml = mapper.BuildMappingFor().ToXml(); - - It should_apply_the_convention_to_any_properties = () => - xml.Element("class/many-to-one[@name='ReadOnlyChild']").HasAttribute("access", "nosetter.camelcase-underscore"); - - static AutoPersistenceModel mapper; - static XmlDocument xml; - - class Convention : IReferenceConvention - { - public void Apply(IManyToOneInstance instance) - { - instance.Access.ReadOnlyPropertyThroughCamelCaseField(CamelCasePrefix.Underscore); - } - } -} - -public class when_the_automapper_maps_with_a_usertype_convention_to_property_of_value_type -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(TypeWithNullableUT), typeof(TypeWithValueUT))) - .Conventions.Add(); - - Because of = () => - { - nullableMapping = mapper.BuildMappingFor().ToXml(); - notNullableMapping = mapper.BuildMappingFor().ToXml(); - }; - - It shold_apply_convention_to_properties_of_corresponding_nullable_type = () => - nullableMapping.Element("class/property[@name='Simple']/column").HasAttribute("name", "arbitraryName"); - - It shold_apply_convention_to_properties_of_corresponding_non_nullable_value_type = () => - notNullableMapping.Element("class/property[@name='Definite']/column").HasAttribute("name", "arbitraryName"); - - static XmlDocument nullableMapping; - static XmlDocument notNullableMapping; - static AutoPersistenceModel mapper; -} - -public class when_the_automapper_maps_with_a_usertype_convention_to_property_of_reference_type -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(NotNullableUT))) - .Conventions.Add(); - - Because of = () => - xml = mapper.BuildMappingFor().ToXml(); - - It shold_apply_convention_to_property = () => - xml.Element("class/property[@name='Complex']/column").HasAttribute("name", "someOtherName"); - - static XmlDocument xml; - static AutoPersistenceModel mapper; - - +using System; +using System.Data; +using System.Xml; +using FluentNHibernate.Automapping; +using FluentNHibernate.Conventions; +using FluentNHibernate.Conventions.Inspections; +using FluentNHibernate.Conventions.Instances; +using FluentNHibernate.Specs.Automapping.Fixtures; +using FluentNHibernate.Specs.ExternalFixtures; +using Machine.Specifications; +using NHibernate.SqlTypes; +using NHibernate.UserTypes; + +namespace FluentNHibernate.Specs.Automapping; + +public class when_the_automapper_maps_with_a_property_convention +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(Entity))) + .Conventions.Add(); + + Because of = () => + xml = mapper.BuildMappingFor().ToXml(); + + It should_apply_the_convention_to_any_properties = () => + xml.Element("class/property[@name='One']/column").HasAttribute("name", "OneXX"); + + static AutoPersistenceModel mapper; + static XmlDocument xml; + + class XXAppenderPropertyConvention : IPropertyConvention + { + public void Apply(IPropertyInstance instance) + { + instance.Column(instance.Name + "XX"); + } + } +} + +public class when_the_automapper_maps_a_readonly_reference_with_an_access_convention +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(Entity))) + .Conventions.Add(); + + Because of = () => + xml = mapper.BuildMappingFor().ToXml(); + + It should_apply_the_convention_to_any_properties = () => + xml.Element("class/many-to-one[@name='ReadOnlyChild']").HasAttribute("access", "nosetter.camelcase-underscore"); + + static AutoPersistenceModel mapper; + static XmlDocument xml; + + class Convention : IReferenceConvention + { + public void Apply(IManyToOneInstance instance) + { + instance.Access.ReadOnlyPropertyThroughCamelCaseField(CamelCasePrefix.Underscore); + } + } +} + +public class when_the_automapper_maps_with_a_usertype_convention_to_property_of_value_type +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(TypeWithNullableUT), typeof(TypeWithValueUT))) + .Conventions.Add(); + + Because of = () => + { + nullableMapping = mapper.BuildMappingFor().ToXml(); + notNullableMapping = mapper.BuildMappingFor().ToXml(); + }; + + It shold_apply_convention_to_properties_of_corresponding_nullable_type = () => + nullableMapping.Element("class/property[@name='Simple']/column").HasAttribute("name", "arbitraryName"); + + It shold_apply_convention_to_properties_of_corresponding_non_nullable_value_type = () => + notNullableMapping.Element("class/property[@name='Definite']/column").HasAttribute("name", "arbitraryName"); + + static XmlDocument nullableMapping; + static XmlDocument notNullableMapping; + static AutoPersistenceModel mapper; +} + +public class when_the_automapper_maps_with_a_usertype_convention_to_property_of_reference_type +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(NotNullableUT))) + .Conventions.Add(); + + Because of = () => + xml = mapper.BuildMappingFor().ToXml(); + + It shold_apply_convention_to_property = () => + xml.Element("class/property[@name='Complex']/column").HasAttribute("name", "someOtherName"); + + static XmlDocument xml; + static AutoPersistenceModel mapper; + + } diff --git a/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.cs b/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.cs index afd877604..d093205b1 100644 --- a/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.cs +++ b/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.cs @@ -1,114 +1,114 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Xml; -using FluentNHibernate.Automapping; -using FluentNHibernate.Cfg; -using FluentNHibernate.Cfg.Db; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.Automapping.Fixtures; -using FluentNHibernate.Specs.ExternalFixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.Automapping; - -public class when_the_automapper_is_told_to_map_a_single_type -{ - Because of = () => - xml = AutoMap.Source(new StubTypeSource(typeof(Entity))) - .BuildMappingFor() - .ToXml(); - - It should_only_return_one_class_in_the_xml = () => - { - xml.Element("class").ShouldExist(); - xml.Element("class[2]").ShouldNotExist(); - }; - - It should_map_the_id = () => - xml.Element("class/id").ShouldExist(); - - It should_map_properties = () => - xml.Element("class/property[@name='One']").ShouldExist(); - - It should_map_enum_properties = () => - xml.Element("class/property[@name='Enum']").ShouldExist(); - - It should_map_references = () => - xml.Element("class/many-to-one[@name='Parent']").ShouldExist(); - - It should_map_collections = () => - xml.Element("class/bag[@name='Children']").ShouldExist(); - - static XmlDocument xml; -} - -public class when_the_automapper_is_ran_to_completion -{ - Establish context = () => - - setup = Fluently.Configure() - .Database( - CreateStandardInMemoryConfiguration()) - .Mappings(x => x.AutoMappings.Add(AutoMap.Source(new StubTypeSource(typeof(Entity))))); - - Because of = () => - ex = Catch.Exception(() => setup.BuildConfiguration()); - - It should_generate_xml_that_is_accepted_by_the_nhibernate_schema_validation = () => - ex.Should().BeNull(); - - static FluentConfiguration setup; - static Exception ex; - - private static IPersistenceConfigurer CreateStandardInMemoryConfiguration() - { -#if NETFRAMEWORK - var configuration = SQLiteConfiguration.Standard.InMemory(); -#else - var configuration = MsSqliteConfiguration.Standard.InMemory(); -#endif - return configuration; - } -} - -public class when_the_automapper_is_told_to_map_an_inheritance_hierarchy -{ - Because of = () => - ex = Catch.Exception(() => - AutoMap.Source(new StubTypeSource(typeof(A_Child), typeof(B_Parent))) - .BuildMappings()); - - // this will fail with an exception if this is broken: - // was failing because the child class was being mapped first - // adding all properties from it and it's base class. Then the - // base class was being mapped, duplicating those properties - // that were already mapped in the child. Needed to change the - // ordering so parents are always mapped before their children - It should_map_the_top_most_class_first = () => - ex.Should().BeNull(); - - static Exception ex; -} - -public class when_the_automapper_maps_an_inheritance_hierarchy_with_three_levels_and_the_middle_ignored -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(ChildChild), typeof(Parent), typeof(Child))) - .IgnoreBase(); - - Because of = () => - mappings = mapper.BuildMappings() - .SelectMany(x => x.Classes); - - It should_map_the_parent = () => - mappings.Count().Should().Be(1); - - It should_map_the_child_child_as_a_subclass_of_parent = () => - mappings.Single() - .Subclasses.Single().Type.Should().Be(typeof(ChildChild)); - - static AutoPersistenceModel mapper; - static IEnumerable mappings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Xml; +using FluentNHibernate.Automapping; +using FluentNHibernate.Cfg; +using FluentNHibernate.Cfg.Db; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.Automapping.Fixtures; +using FluentNHibernate.Specs.ExternalFixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.Automapping; + +public class when_the_automapper_is_told_to_map_a_single_type +{ + Because of = () => + xml = AutoMap.Source(new StubTypeSource(typeof(Entity))) + .BuildMappingFor() + .ToXml(); + + It should_only_return_one_class_in_the_xml = () => + { + xml.Element("class").ShouldExist(); + xml.Element("class[2]").ShouldNotExist(); + }; + + It should_map_the_id = () => + xml.Element("class/id").ShouldExist(); + + It should_map_properties = () => + xml.Element("class/property[@name='One']").ShouldExist(); + + It should_map_enum_properties = () => + xml.Element("class/property[@name='Enum']").ShouldExist(); + + It should_map_references = () => + xml.Element("class/many-to-one[@name='Parent']").ShouldExist(); + + It should_map_collections = () => + xml.Element("class/bag[@name='Children']").ShouldExist(); + + static XmlDocument xml; +} + +public class when_the_automapper_is_ran_to_completion +{ + Establish context = () => + + setup = Fluently.Configure() + .Database( + CreateStandardInMemoryConfiguration()) + .Mappings(x => x.AutoMappings.Add(AutoMap.Source(new StubTypeSource(typeof(Entity))))); + + Because of = () => + ex = Catch.Exception(() => setup.BuildConfiguration()); + + It should_generate_xml_that_is_accepted_by_the_nhibernate_schema_validation = () => + ex.Should().BeNull(); + + static FluentConfiguration setup; + static Exception ex; + + private static IPersistenceConfigurer CreateStandardInMemoryConfiguration() + { +#if NETFRAMEWORK + var configuration = SQLiteConfiguration.Standard.InMemory(); +#else + var configuration = MsSqliteConfiguration.Standard.InMemory(); +#endif + return configuration; + } +} + +public class when_the_automapper_is_told_to_map_an_inheritance_hierarchy +{ + Because of = () => + ex = Catch.Exception(() => + AutoMap.Source(new StubTypeSource(typeof(A_Child), typeof(B_Parent))) + .BuildMappings()); + + // this will fail with an exception if this is broken: + // was failing because the child class was being mapped first + // adding all properties from it and it's base class. Then the + // base class was being mapped, duplicating those properties + // that were already mapped in the child. Needed to change the + // ordering so parents are always mapped before their children + It should_map_the_top_most_class_first = () => + ex.Should().BeNull(); + + static Exception ex; +} + +public class when_the_automapper_maps_an_inheritance_hierarchy_with_three_levels_and_the_middle_ignored +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(ChildChild), typeof(Parent), typeof(Child))) + .IgnoreBase(); + + Because of = () => + mappings = mapper.BuildMappings() + .SelectMany(x => x.Classes); + + It should_map_the_parent = () => + mappings.Count().Should().Be(1); + + It should_map_the_child_child_as_a_subclass_of_parent = () => + mappings.Single() + .Subclasses.Single().Type.Should().Be(typeof(ChildChild)); + + static AutoPersistenceModel mapper; + static IEnumerable mappings; } diff --git a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Components.cs b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Components.cs index bb47e5c12..982fffb76 100644 --- a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Components.cs +++ b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Components.cs @@ -1,152 +1,152 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using FluentNHibernate.Automapping; -using FluentNHibernate.Mapping; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.Automapping.Fixtures; -using FluentNHibernate.Specs.ExternalFixtures; -using FluentNHibernate.Utils; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.Automapping; - -public class when_the_automapper_is_told_to_map_an_entity_and_a_component -{ - Establish context = () => - mapper = AutoMap.Source( - new StubTypeSource(typeof(Entity), typeof(Component)), - new TestConfiguration()); - - Because of = () => - mappings = mapper.BuildMappings() - .SelectMany(x => x.Classes); - - It should_map_the_entity = () => - mappings.ShouldContain(x => x.Type == typeof(Entity)); - - It should_not_map_the_component_as_an_entity = () => - mappings.ShouldNotContain(x => x.Type == typeof(Component)); - - It should_map_the_component_as_a_component_of_the_entity = () => - mappings.Single(x => x.Type == typeof(Entity)) - .Components.ShouldContain(x => x.Type == typeof(Component)); - - static AutoPersistenceModel mapper; - static IEnumerable mappings; - - class TestConfiguration : DefaultAutomappingConfiguration - { - public override bool IsComponent(Type type) - { - return type == typeof(Component); - } - } -} - -public class when_the_automapper_is_told_to_map_an_entity_and_a_component_that_has_an_associated_ComponentMap -{ - Establish context = () => - mapper = AutoMap.Source( - new StubTypeSource(typeof(Entity), typeof(Component)), - new TestConfiguration()) - .AddMappingsFromSource(new StubTypeSource(typeof(CompMap))); - - Because of = () => - mappings = mapper.BuildMappings() - .SelectMany(x => x.Classes); - - It should_map_the_entity = () => - mappings.ShouldContain(x => x.Type == typeof(Entity)); - - It should_not_map_the_component_as_an_entity = () => - mappings.ShouldNotContain(x => x.Type == typeof(Component)); - - It should_map_the_component_as_a_component_of_the_entity = () => - mappings.Single(x => x.Type == typeof(Entity)) - .Components.ShouldContain(x => x.Type == typeof(Component)); - - It should_use_the_component_map_for_mapping = () => - mappings.Single().Components.Single().Access.Should().Be("none"); - - static AutoPersistenceModel mapper; - static IEnumerable mappings; - - class TestConfiguration : DefaultAutomappingConfiguration - { - public override bool IsComponent(Type type) - { - return type == typeof(Component); - } - } - - class CompMap : ComponentMap - { - public CompMap() - { - Access.None(); - } - } -} - -public class when_the_automapper_maps_nested_comonents -{ - Establish context = () => - mapper = AutoMap.Source( - new StubTypeSource(typeof(Entity1), typeof(Location), typeof(FormatA), typeof(FormatB)), - new TestConfiguration()); - - Because of = () => - mapping = mapper.BuildMappingFor(); - - It should_prefix_the_components_in_the_entity = () => - mapping.Components - .SelectMany(x => x.Properties) - .SelectMany(x => x.Columns) - .Select(x => x.Name) - .Should().Contain(new string[] { "LeftLocationProperty", "RightLocationProperty" }); - - It should_prefix_the_components_in_the_components = () => - mapping.Components - .SelectMany(x => x.Components) - .SelectMany(x => x.Properties) - .SelectMany(x => x.Columns) - .Select(x => x.Name) - .Should().Contain(new string[] { "LeftAPropertyA", "LeftBPropertyB", "RightAPropertyA", "RightBPropertyB" }); - - static AutoPersistenceModel mapper; - static ClassMapping mapping; - - class TestConfiguration : DefaultAutomappingConfiguration - { - public override bool IsComponent(Type type) - { - return type.In(typeof(Location), typeof(FormatA), typeof(FormatB)); - } - } -} - -public class Entity1 -{ - public int Id { get; set; } - public Location Left { get; set; } - public Location Right { get; set; } -} - -public class Location -{ - public string LocationProperty { get; set; } - public FormatA A { get; set; } - public FormatB B { get; set; } -} - -public class FormatA -{ - public string PropertyA { get; set; } -} - -public class FormatB -{ - public string PropertyB { get; set; } +using System; +using System.Collections.Generic; +using System.Linq; +using FluentNHibernate.Automapping; +using FluentNHibernate.Mapping; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.Automapping.Fixtures; +using FluentNHibernate.Specs.ExternalFixtures; +using FluentNHibernate.Utils; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.Automapping; + +public class when_the_automapper_is_told_to_map_an_entity_and_a_component +{ + Establish context = () => + mapper = AutoMap.Source( + new StubTypeSource(typeof(Entity), typeof(Component)), + new TestConfiguration()); + + Because of = () => + mappings = mapper.BuildMappings() + .SelectMany(x => x.Classes); + + It should_map_the_entity = () => + mappings.ShouldContain(x => x.Type == typeof(Entity)); + + It should_not_map_the_component_as_an_entity = () => + mappings.ShouldNotContain(x => x.Type == typeof(Component)); + + It should_map_the_component_as_a_component_of_the_entity = () => + mappings.Single(x => x.Type == typeof(Entity)) + .Components.ShouldContain(x => x.Type == typeof(Component)); + + static AutoPersistenceModel mapper; + static IEnumerable mappings; + + class TestConfiguration : DefaultAutomappingConfiguration + { + public override bool IsComponent(Type type) + { + return type == typeof(Component); + } + } +} + +public class when_the_automapper_is_told_to_map_an_entity_and_a_component_that_has_an_associated_ComponentMap +{ + Establish context = () => + mapper = AutoMap.Source( + new StubTypeSource(typeof(Entity), typeof(Component)), + new TestConfiguration()) + .AddMappingsFromSource(new StubTypeSource(typeof(CompMap))); + + Because of = () => + mappings = mapper.BuildMappings() + .SelectMany(x => x.Classes); + + It should_map_the_entity = () => + mappings.ShouldContain(x => x.Type == typeof(Entity)); + + It should_not_map_the_component_as_an_entity = () => + mappings.ShouldNotContain(x => x.Type == typeof(Component)); + + It should_map_the_component_as_a_component_of_the_entity = () => + mappings.Single(x => x.Type == typeof(Entity)) + .Components.ShouldContain(x => x.Type == typeof(Component)); + + It should_use_the_component_map_for_mapping = () => + mappings.Single().Components.Single().Access.Should().Be("none"); + + static AutoPersistenceModel mapper; + static IEnumerable mappings; + + class TestConfiguration : DefaultAutomappingConfiguration + { + public override bool IsComponent(Type type) + { + return type == typeof(Component); + } + } + + class CompMap : ComponentMap + { + public CompMap() + { + Access.None(); + } + } +} + +public class when_the_automapper_maps_nested_comonents +{ + Establish context = () => + mapper = AutoMap.Source( + new StubTypeSource(typeof(Entity1), typeof(Location), typeof(FormatA), typeof(FormatB)), + new TestConfiguration()); + + Because of = () => + mapping = mapper.BuildMappingFor(); + + It should_prefix_the_components_in_the_entity = () => + mapping.Components + .SelectMany(x => x.Properties) + .SelectMany(x => x.Columns) + .Select(x => x.Name) + .Should().Contain(new string[] { "LeftLocationProperty", "RightLocationProperty" }); + + It should_prefix_the_components_in_the_components = () => + mapping.Components + .SelectMany(x => x.Components) + .SelectMany(x => x.Properties) + .SelectMany(x => x.Columns) + .Select(x => x.Name) + .Should().Contain(new string[] { "LeftAPropertyA", "LeftBPropertyB", "RightAPropertyA", "RightBPropertyB" }); + + static AutoPersistenceModel mapper; + static ClassMapping mapping; + + class TestConfiguration : DefaultAutomappingConfiguration + { + public override bool IsComponent(Type type) + { + return type.In(typeof(Location), typeof(FormatA), typeof(FormatB)); + } + } +} + +public class Entity1 +{ + public int Id { get; set; } + public Location Left { get; set; } + public Location Right { get; set; } +} + +public class Location +{ + public string LocationProperty { get; set; } + public FormatA A { get; set; } + public FormatB B { get; set; } +} + +public class FormatA +{ + public string PropertyA { get; set; } +} + +public class FormatB +{ + public string PropertyB { get; set; } } diff --git a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.ElementCollections.cs b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.ElementCollections.cs index 0adb7aebe..44f6ddb89 100644 --- a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.ElementCollections.cs +++ b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.ElementCollections.cs @@ -1,193 +1,193 @@ -using System.Linq; -using FluentNHibernate.Automapping; -using FluentNHibernate.Automapping.Steps; -using FluentNHibernate.MappingModel; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.MappingModel.Collections; -using FluentNHibernate.Specs.Automapping.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.Automapping; - -public class when_the_automapper_is_asked_if_it_can_map_a_list_of_strings : AutoMapOneToManyVisitSpec -{ - Because of = () => - maps_property = step.ShouldMap(FakeMembers.IListOfStrings); - - It should_accept_the_property = () => - maps_property.Should().BeTrue(); - - static bool maps_property; -} - -public class when_the_automapper_is_asked_if_it_can_map_a_list_of_ints : AutoMapOneToManyVisitSpec -{ - Because of = () => - maps_property = step.ShouldMap(FakeMembers.IListOfInts); - - It should_accept_the_property = () => - maps_property.Should().BeTrue(); - - static bool maps_property; -} - -public class when_the_automapper_is_asked_if_it_can_map_a_list_of_doubles : AutoMapOneToManyVisitSpec -{ - Because of = () => - maps_property = step.ShouldMap(FakeMembers.IListOfDoubles); - - It should_accept_the_property = () => - maps_property.Should().BeTrue(); - - static bool maps_property; -} - -public class when_the_automapper_is_asked_if_it_can_map_a_list_of_shorts : AutoMapOneToManyVisitSpec -{ - Because of = () => - maps_property = step.ShouldMap(FakeMembers.IListOfShorts); - - It should_accept_the_property = () => - maps_property.Should().BeTrue(); - - static bool maps_property; -} - -public class when_the_automapper_is_asked_if_it_can_map_a_list_of_longs : AutoMapOneToManyVisitSpec -{ - Because of = () => - maps_property = step.ShouldMap(FakeMembers.IListOfLongs); - - It should_accept_the_property = () => - maps_property.Should().BeTrue(); - - static bool maps_property; -} - -public class when_the_automapper_is_asked_if_it_can_map_a_list_of_floats : AutoMapOneToManyVisitSpec -{ - Because of = () => - maps_property = step.ShouldMap(FakeMembers.IListOfFloats); - - It should_accept_the_property = () => - maps_property.Should().BeTrue(); - - static bool maps_property; -} - -public class when_the_automapper_is_asked_if_it_can_map_a_list_of_bools : AutoMapOneToManyVisitSpec -{ - Because of = () => - maps_property = step.ShouldMap(FakeMembers.IListOfBools); - - It should_accept_the_property = () => - maps_property.Should().BeTrue(); - - static bool maps_property; -} - -public class when_the_automapper_is_asked_if_it_can_map_a_list_of_DateTimes : AutoMapOneToManyVisitSpec -{ - Because of = () => - maps_property = step.ShouldMap(FakeMembers.IListOfDateTimes); - - It should_accept_the_property = () => - maps_property.Should().BeTrue(); - - static bool maps_property; -} - -public class when_the_automapper_is_told_to_map_a_list_of_simple_types_with_a_custom_column_defined : AutoMapOneToManySpec -{ - Establish context = () => - cfg.FixedSimpleTypeCollectionValueColumn = "custom_column"; - - Because of = () => - step.Map(container, FakeMembers.IListOfStrings); - - It should_create_use_the_element_column_name_defined_in_the_expressions = () => - container.Collections.Single().Element.Columns.Single().Name.Should().Be("custom_column"); -} - -public class when_the_automapper_is_told_to_map_a_list_of_simple_types : AutoMapOneToManySpec -{ - Because of = () => - step.Map(container, FakeMembers.IListOfStrings); - - It should_create_a_collection = () => - container.Collections.Count().Should().Be(1); - - It should_create_a_collection_that_s_a_bag = () => - container.Collections.Single().Collection.Should().Be(Collection.Bag); - - It should_create_an_element_for_the_collection = () => - container.Collections.Single().Element.Should().NotBeNull(); - - It should_use_the_default_element_column = () => - container.Collections.Single().Element.Columns.Single().Name.Should().Be("Value"); - - It should_set_the_element_type_to_the_first_generic_argument_of_the_collection_type = () => - container.Collections.Single().Element.Type.Should().Be(new TypeReference(typeof(string))); - - It should_create_a_key = () => - container.Collections.Single().Key.Should().NotBeNull(); - - It should_set_the_key_s_containing_entity_to_the_type_owning_the_property = () => - container.Collections.Single().Key.ContainingEntityType.Should().Be(FakeMembers.Type); - - It should_create_a_column_for_the_key_with_the_default_id_naming = () => - container.Collections.Single().Key.Columns.Single().Name.Should().Be("Target_id"); - - It should_set_the_collection_s_containing_entity_type_to_the_type_owning_the_property = () => - container.Collections.Single().ContainingEntityType.Should().Be(FakeMembers.Type); - - It should_set_the_collection_s_member_to_the_property = () => - container.Collections.Single().Member.Should().Be(FakeMembers.IListOfStrings); - - It should_set_the_collection_s_name_to_the_property_name = () => - container.Collections.Single().Name.Should().Be(FakeMembers.IListOfStrings.Name); - - It should_not_create_a_relationship_for_the_collection = () => - container.Collections.Single().Relationship.Should().BeNull(); - - It should_not_create_a_component_for_the_collection = () => - container.Collections.Single().CompositeElement.Should().BeNull(); -} - -public abstract class AutoMapOneToManySpec -{ - Establish context = () => - { - cfg = new TestConfiguration(); - step = new HasManyStep(cfg); - container = new ClassMapping(); - container.Set(x => x.Type, Layer.Defaults, FakeMembers.Type); - }; - - protected static HasManyStep step; - protected static ClassMapping container; - protected static TestConfiguration cfg; - - protected class TestConfiguration : DefaultAutomappingConfiguration - { - public override string SimpleTypeCollectionValueColumn(Member member) - { - return FixedSimpleTypeCollectionValueColumn ?? base.SimpleTypeCollectionValueColumn(member); - } - - public string FixedSimpleTypeCollectionValueColumn { get; set; } - } -} - -public abstract class AutoMapOneToManyVisitSpec -{ - Establish context = () => - { - cfg = new DefaultAutomappingConfiguration(); - step = new SimpleTypeCollectionStep(cfg); - }; - - protected static SimpleTypeCollectionStep step; - protected static IAutomappingConfiguration cfg; +using System.Linq; +using FluentNHibernate.Automapping; +using FluentNHibernate.Automapping.Steps; +using FluentNHibernate.MappingModel; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.MappingModel.Collections; +using FluentNHibernate.Specs.Automapping.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.Automapping; + +public class when_the_automapper_is_asked_if_it_can_map_a_list_of_strings : AutoMapOneToManyVisitSpec +{ + Because of = () => + maps_property = step.ShouldMap(FakeMembers.IListOfStrings); + + It should_accept_the_property = () => + maps_property.Should().BeTrue(); + + static bool maps_property; +} + +public class when_the_automapper_is_asked_if_it_can_map_a_list_of_ints : AutoMapOneToManyVisitSpec +{ + Because of = () => + maps_property = step.ShouldMap(FakeMembers.IListOfInts); + + It should_accept_the_property = () => + maps_property.Should().BeTrue(); + + static bool maps_property; +} + +public class when_the_automapper_is_asked_if_it_can_map_a_list_of_doubles : AutoMapOneToManyVisitSpec +{ + Because of = () => + maps_property = step.ShouldMap(FakeMembers.IListOfDoubles); + + It should_accept_the_property = () => + maps_property.Should().BeTrue(); + + static bool maps_property; +} + +public class when_the_automapper_is_asked_if_it_can_map_a_list_of_shorts : AutoMapOneToManyVisitSpec +{ + Because of = () => + maps_property = step.ShouldMap(FakeMembers.IListOfShorts); + + It should_accept_the_property = () => + maps_property.Should().BeTrue(); + + static bool maps_property; +} + +public class when_the_automapper_is_asked_if_it_can_map_a_list_of_longs : AutoMapOneToManyVisitSpec +{ + Because of = () => + maps_property = step.ShouldMap(FakeMembers.IListOfLongs); + + It should_accept_the_property = () => + maps_property.Should().BeTrue(); + + static bool maps_property; +} + +public class when_the_automapper_is_asked_if_it_can_map_a_list_of_floats : AutoMapOneToManyVisitSpec +{ + Because of = () => + maps_property = step.ShouldMap(FakeMembers.IListOfFloats); + + It should_accept_the_property = () => + maps_property.Should().BeTrue(); + + static bool maps_property; +} + +public class when_the_automapper_is_asked_if_it_can_map_a_list_of_bools : AutoMapOneToManyVisitSpec +{ + Because of = () => + maps_property = step.ShouldMap(FakeMembers.IListOfBools); + + It should_accept_the_property = () => + maps_property.Should().BeTrue(); + + static bool maps_property; +} + +public class when_the_automapper_is_asked_if_it_can_map_a_list_of_DateTimes : AutoMapOneToManyVisitSpec +{ + Because of = () => + maps_property = step.ShouldMap(FakeMembers.IListOfDateTimes); + + It should_accept_the_property = () => + maps_property.Should().BeTrue(); + + static bool maps_property; +} + +public class when_the_automapper_is_told_to_map_a_list_of_simple_types_with_a_custom_column_defined : AutoMapOneToManySpec +{ + Establish context = () => + cfg.FixedSimpleTypeCollectionValueColumn = "custom_column"; + + Because of = () => + step.Map(container, FakeMembers.IListOfStrings); + + It should_create_use_the_element_column_name_defined_in_the_expressions = () => + container.Collections.Single().Element.Columns.Single().Name.Should().Be("custom_column"); +} + +public class when_the_automapper_is_told_to_map_a_list_of_simple_types : AutoMapOneToManySpec +{ + Because of = () => + step.Map(container, FakeMembers.IListOfStrings); + + It should_create_a_collection = () => + container.Collections.Count().Should().Be(1); + + It should_create_a_collection_that_s_a_bag = () => + container.Collections.Single().Collection.Should().Be(Collection.Bag); + + It should_create_an_element_for_the_collection = () => + container.Collections.Single().Element.Should().NotBeNull(); + + It should_use_the_default_element_column = () => + container.Collections.Single().Element.Columns.Single().Name.Should().Be("Value"); + + It should_set_the_element_type_to_the_first_generic_argument_of_the_collection_type = () => + container.Collections.Single().Element.Type.Should().Be(new TypeReference(typeof(string))); + + It should_create_a_key = () => + container.Collections.Single().Key.Should().NotBeNull(); + + It should_set_the_key_s_containing_entity_to_the_type_owning_the_property = () => + container.Collections.Single().Key.ContainingEntityType.Should().Be(FakeMembers.Type); + + It should_create_a_column_for_the_key_with_the_default_id_naming = () => + container.Collections.Single().Key.Columns.Single().Name.Should().Be("Target_id"); + + It should_set_the_collection_s_containing_entity_type_to_the_type_owning_the_property = () => + container.Collections.Single().ContainingEntityType.Should().Be(FakeMembers.Type); + + It should_set_the_collection_s_member_to_the_property = () => + container.Collections.Single().Member.Should().Be(FakeMembers.IListOfStrings); + + It should_set_the_collection_s_name_to_the_property_name = () => + container.Collections.Single().Name.Should().Be(FakeMembers.IListOfStrings.Name); + + It should_not_create_a_relationship_for_the_collection = () => + container.Collections.Single().Relationship.Should().BeNull(); + + It should_not_create_a_component_for_the_collection = () => + container.Collections.Single().CompositeElement.Should().BeNull(); +} + +public abstract class AutoMapOneToManySpec +{ + Establish context = () => + { + cfg = new TestConfiguration(); + step = new HasManyStep(cfg); + container = new ClassMapping(); + container.Set(x => x.Type, Layer.Defaults, FakeMembers.Type); + }; + + protected static HasManyStep step; + protected static ClassMapping container; + protected static TestConfiguration cfg; + + protected class TestConfiguration : DefaultAutomappingConfiguration + { + public override string SimpleTypeCollectionValueColumn(Member member) + { + return FixedSimpleTypeCollectionValueColumn ?? base.SimpleTypeCollectionValueColumn(member); + } + + public string FixedSimpleTypeCollectionValueColumn { get; set; } + } +} + +public abstract class AutoMapOneToManyVisitSpec +{ + Establish context = () => + { + cfg = new DefaultAutomappingConfiguration(); + step = new SimpleTypeCollectionStep(cfg); + }; + + protected static SimpleTypeCollectionStep step; + protected static IAutomappingConfiguration cfg; } diff --git a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.NestedClasses.cs b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.NestedClasses.cs index 59b4ff9ec..271706399 100644 --- a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.NestedClasses.cs +++ b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.NestedClasses.cs @@ -1,99 +1,99 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using FluentNHibernate.Automapping; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.Automapping.Fixtures; -using Machine.Specifications; - -namespace FluentNHibernate.Specs.Automapping; - -public class when_the_automapper_is_told_to_map_an_entity_with_a_nested_entity -{ - Establish context = () => - mapper = AutoMap.Source( - new StubTypeSource(typeof(Order), typeof(Order.OrderLine))); - - Because of = () => - mappings = mapper.BuildMappings() - .SelectMany(x => x.Classes); - - It should_map_the_entity = () => - mappings.ShouldContain(x => x.Type == typeof(Order)); - - It should_automap_the_nested_entity_per_default = () => - mappings.ShouldContain(x => x.Type == typeof(Order.OrderLine)); - - static AutoPersistenceModel mapper; - static IEnumerable mappings; -} - -public class when_changing_the_behaviour_of_automapping_configuration_to_also_map_nested_entities -{ - Establish context = () => - mapper = AutoMap.Source( - new StubTypeSource(typeof(Order), typeof(Order.OrderLine)), new TestConfiguration()); - - Because of = () => - mappings = mapper.BuildMappings() - .SelectMany(x => x.Classes); - - It should_map_the_entity = () => - mappings.ShouldContain(x => x.Type == typeof(Order)); - - It should_automap_the_nested_entity = () => - mappings.ShouldContain(x => x.Type == typeof(Order.OrderLine)); - - static AutoPersistenceModel mapper; - static IEnumerable mappings; - - class TestConfiguration : DefaultAutomappingConfiguration - { - public override bool ShouldMap(Type type) - { - return base.ShouldMap(type) || type.IsNested; - } - } -} - -public class when_automapper_is_told_to_map_a_class_with_a_nested_classes -{ - Establish context = () => - { - nonPublicNestedType = typeof(PersonCard).GetNestedTypes(BindingFlags.NonPublic).Single(); - model = AutoMap.Source(new StubTypeSource(typeof(PersonCard), typeof(PersonCard.PublicAddress), nonPublicNestedType)); - }; - - Because of = () => mappings = model.BuildMappings().SelectMany(m => m.Classes); - It should_map_the_main_class = () => mappings.ShouldContain(m => m.Type == typeof(PersonCard)); - It should_map_public_nested_class = () => mappings.ShouldContain(m => m.Type == typeof(PersonCard.PublicAddress)); - It should_not_map_non_public_nested_class = () => mappings.ShouldNotContain(m => m.Type == nonPublicNestedType); - - static AutoPersistenceModel model; - static DefaultAutomappingConfiguration configuration; - static Type nonPublicNestedType; - static IEnumerable mappings; -} - -public class PersonCard -{ - public int Id { get; set; } - public class PublicAddress - { - public int Id { get; set; } - } - private class PrivateAddress - { - public int Id { get; set; } - } -} - -public class Order -{ - public int Id { get; set; } - public class OrderLine - { - public int Id { get; set; } - } +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using FluentNHibernate.Automapping; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.Automapping.Fixtures; +using Machine.Specifications; + +namespace FluentNHibernate.Specs.Automapping; + +public class when_the_automapper_is_told_to_map_an_entity_with_a_nested_entity +{ + Establish context = () => + mapper = AutoMap.Source( + new StubTypeSource(typeof(Order), typeof(Order.OrderLine))); + + Because of = () => + mappings = mapper.BuildMappings() + .SelectMany(x => x.Classes); + + It should_map_the_entity = () => + mappings.ShouldContain(x => x.Type == typeof(Order)); + + It should_automap_the_nested_entity_per_default = () => + mappings.ShouldContain(x => x.Type == typeof(Order.OrderLine)); + + static AutoPersistenceModel mapper; + static IEnumerable mappings; +} + +public class when_changing_the_behaviour_of_automapping_configuration_to_also_map_nested_entities +{ + Establish context = () => + mapper = AutoMap.Source( + new StubTypeSource(typeof(Order), typeof(Order.OrderLine)), new TestConfiguration()); + + Because of = () => + mappings = mapper.BuildMappings() + .SelectMany(x => x.Classes); + + It should_map_the_entity = () => + mappings.ShouldContain(x => x.Type == typeof(Order)); + + It should_automap_the_nested_entity = () => + mappings.ShouldContain(x => x.Type == typeof(Order.OrderLine)); + + static AutoPersistenceModel mapper; + static IEnumerable mappings; + + class TestConfiguration : DefaultAutomappingConfiguration + { + public override bool ShouldMap(Type type) + { + return base.ShouldMap(type) || type.IsNested; + } + } +} + +public class when_automapper_is_told_to_map_a_class_with_a_nested_classes +{ + Establish context = () => + { + nonPublicNestedType = typeof(PersonCard).GetNestedTypes(BindingFlags.NonPublic).Single(); + model = AutoMap.Source(new StubTypeSource(typeof(PersonCard), typeof(PersonCard.PublicAddress), nonPublicNestedType)); + }; + + Because of = () => mappings = model.BuildMappings().SelectMany(m => m.Classes); + It should_map_the_main_class = () => mappings.ShouldContain(m => m.Type == typeof(PersonCard)); + It should_map_public_nested_class = () => mappings.ShouldContain(m => m.Type == typeof(PersonCard.PublicAddress)); + It should_not_map_non_public_nested_class = () => mappings.ShouldNotContain(m => m.Type == nonPublicNestedType); + + static AutoPersistenceModel model; + static DefaultAutomappingConfiguration configuration; + static Type nonPublicNestedType; + static IEnumerable mappings; +} + +public class PersonCard +{ + public int Id { get; set; } + public class PublicAddress + { + public int Id { get; set; } + } + private class PrivateAddress + { + public int Id { get; set; } + } +} + +public class Order +{ + public int Id { get; set; } + public class OrderLine + { + public int Id { get; set; } + } } diff --git a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Properties.Enum.cs b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Properties.Enum.cs index 84465c8b5..8fcda2beb 100644 --- a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Properties.Enum.cs +++ b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Properties.Enum.cs @@ -1,80 +1,80 @@ -using System.Linq; -using FluentNHibernate.Automapping; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.Automapping.Fixtures; -using Machine.Specifications; -using FluentAssertions; -using NHibernate.Type; - -namespace FluentNHibernate.Specs.Automapping; - -public class when_the_automapper_is_told_to_map_an_entity_with_static_properties -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(EntityWithStaticProperties))); - - Because of = () => - mapping = mapper.BuildMappings().SelectMany(x => x.Classes).First(); - - It should_not_create_property_mappings_for_the_static_properties = () => - mapping.Properties.Any(x => x.Name == "StaticProperty").Should().BeFalse(); - - static AutoPersistenceModel mapper; - static ClassMapping mapping; -} - -public class when_the_automapper_is_told_to_map_an_entity_with_a_enum_property : AutomapperEnumPropertySpec -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(Target))); - - Because of = () => - mapping = mapper.BuildMappings().SelectMany(x => x.Classes).First(); - - It should_create_a_property_mapping_for_the_property = () => - mapping.Properties.ShouldContain(x => x.Name == "EnumProperty"); - - It should_use_the_enum_string_type_for_the_property = () => - mapping.Properties.First().Type.GetUnderlyingSystemType().Should().Be(typeof(EnumStringType)); - - It should_create_a_column_for_the_property_mapping_with_the_property_name = () => - mapping.Properties.First().Columns.ShouldContain(x => x.Name == "EnumProperty"); -} - -public class when_the_automapper_is_told_to_map_an_entity_with_a_nullable_enum_property : AutomapperEnumPropertySpec -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(NullableTarget))); - - Because of = () => - mapping = mapper.BuildMappings().SelectMany(x => x.Classes).First(); - - It should_create_a_property_mapping_for_the_property = () => - mapping.Properties.ShouldContain(x => x.Name == "EnumProperty"); - - It should_use_the_enum_string_mapper_for_the_property = () => - mapping.Properties.First().Type.GetUnderlyingSystemType().Should().Be(typeof(EnumStringType)); - - It should_create_a_column_for_the_property_mapping_with_the_property_name = () => - mapping.Properties.First().Columns.ShouldContain(x => x.Name == "EnumProperty"); -} - -class Target -{ - public int Id { get; set; } - public Enum EnumProperty { get; set; } -} - -class NullableTarget -{ - public int Id { get; set; } - public Enum? EnumProperty { get; set; } -} - -enum Enum { } - -public abstract class AutomapperEnumPropertySpec -{ - protected static AutoPersistenceModel mapper; - protected static ClassMapping mapping; +using System.Linq; +using FluentNHibernate.Automapping; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.Automapping.Fixtures; +using Machine.Specifications; +using FluentAssertions; +using NHibernate.Type; + +namespace FluentNHibernate.Specs.Automapping; + +public class when_the_automapper_is_told_to_map_an_entity_with_static_properties +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(EntityWithStaticProperties))); + + Because of = () => + mapping = mapper.BuildMappings().SelectMany(x => x.Classes).First(); + + It should_not_create_property_mappings_for_the_static_properties = () => + mapping.Properties.Any(x => x.Name == "StaticProperty").Should().BeFalse(); + + static AutoPersistenceModel mapper; + static ClassMapping mapping; +} + +public class when_the_automapper_is_told_to_map_an_entity_with_a_enum_property : AutomapperEnumPropertySpec +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(Target))); + + Because of = () => + mapping = mapper.BuildMappings().SelectMany(x => x.Classes).First(); + + It should_create_a_property_mapping_for_the_property = () => + mapping.Properties.ShouldContain(x => x.Name == "EnumProperty"); + + It should_use_the_enum_string_type_for_the_property = () => + mapping.Properties.First().Type.GetUnderlyingSystemType().Should().Be(typeof(EnumStringType)); + + It should_create_a_column_for_the_property_mapping_with_the_property_name = () => + mapping.Properties.First().Columns.ShouldContain(x => x.Name == "EnumProperty"); +} + +public class when_the_automapper_is_told_to_map_an_entity_with_a_nullable_enum_property : AutomapperEnumPropertySpec +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(NullableTarget))); + + Because of = () => + mapping = mapper.BuildMappings().SelectMany(x => x.Classes).First(); + + It should_create_a_property_mapping_for_the_property = () => + mapping.Properties.ShouldContain(x => x.Name == "EnumProperty"); + + It should_use_the_enum_string_mapper_for_the_property = () => + mapping.Properties.First().Type.GetUnderlyingSystemType().Should().Be(typeof(EnumStringType)); + + It should_create_a_column_for_the_property_mapping_with_the_property_name = () => + mapping.Properties.First().Columns.ShouldContain(x => x.Name == "EnumProperty"); +} + +class Target +{ + public int Id { get; set; } + public Enum EnumProperty { get; set; } +} + +class NullableTarget +{ + public int Id { get; set; } + public Enum? EnumProperty { get; set; } +} + +enum Enum { } + +public abstract class AutomapperEnumPropertySpec +{ + protected static AutoPersistenceModel mapper; + protected static ClassMapping mapping; } diff --git a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Relationships.cs b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Relationships.cs index fdee055db..723acd31d 100644 --- a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Relationships.cs +++ b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Relationships.cs @@ -1,224 +1,224 @@ -using System; -using System.Linq; -using FluentNHibernate.Automapping; -using FluentNHibernate.Conventions; -using FluentNHibernate.Conventions.Instances; -using FluentNHibernate.Mapping; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.MappingModel.Collections; -using FluentNHibernate.Specs.Automapping.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.Automapping; - -public class when_the_automapper_is_told_to_map_a_class_with_a_self_referencing_collection -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(SelfReferencingCollectionEntity))); - - Because of = () => - mapping = mapper.BuildMappingFor(); - - It should_have_one_collection = () => - mapping.Collections.Should().NotBeEmpty(); - - It should_have_it_s_own_type_for_the_collection_child_type = () => - mapping.Collections.Single().ChildType.Should().Be(typeof(SelfReferencingCollectionEntity)); - - It should_have_the_property_name_for_the_collection_name = () => - mapping.Collections.Single().Name.Should().Be("Children"); - - It should_have_a_one_to_many_collection = () => - mapping.Collections.Single().Relationship.Should().BeOfType(); - - static AutoPersistenceModel mapper; - static ClassMapping mapping; -} - -public class when_the_automapper_is_told_to_map_a_class_with_a_self_reference -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(SelfReferenceEntity))); - - Because of = () => - mapping = mapper.BuildMappingFor(); - - It should_have_one_reference = () => - mapping.References.Should().NotBeEmpty(); - - It should_have_it_s_own_type_for_the_reference_type = () => - mapping.References.Single().Class.GetUnderlyingSystemType().Should().Be(typeof(SelfReferenceEntity)); - - It should_have_the_property_name_for_the_reference_name = () => - mapping.References.Single().Name.Should().Be("Parent"); - - static AutoPersistenceModel mapper; - static ClassMapping mapping; -} - -public class when_the_automapper_is_told_to_map_a_class_with_a_self_reference_and_a_self_referencing_collection -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(ParentChildSelfReferenceEntity))); - - Because of = () => - mapping = mapper.BuildMappingFor(); - - It should_have_one_collection = () => - mapping.Collections.Should().NotBeEmpty(); - - It should_have_it_s_own_type_for_the_collection_child_type = () => - mapping.Collections.Single().ChildType.Should().Be(typeof(ParentChildSelfReferenceEntity)); - - It should_have_the_property_name_for_the_collection_name = () => - mapping.Collections.Single().Name.Should().Be("Children"); - - It should_have_a_one_to_many_collection = () => - mapping.Collections.Single().Relationship.Should().BeOfType(); - - It should_have_the_correct_collection_key_column = () => - mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("Parent_id"); - - It should_have_one_reference = () => - mapping.References.Should().NotBeEmpty(); - - It should_have_it_s_own_type_for_the_reference_type = () => - mapping.References.Single().Class.GetUnderlyingSystemType().Should().Be(typeof(ParentChildSelfReferenceEntity)); - - It should_have_the_property_name_for_the_reference_name = () => - mapping.References.Single().Name.Should().Be("Parent"); - - It should_have_the_correct_reference_key_column = () => - mapping.References.Single().Columns.Single().Name.Should().Be("Parent_id"); - - static AutoPersistenceModel mapper; - static ClassMapping mapping; -} - -public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_with_a_backing_field -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity))); - - Because of = () => - mapping = mapper.BuildMappingFor(); - - It should_map_the_read_only_property_collection = () => - mapping.Collections.Select(x => x.Name).Should().Contain("BackingFieldCollection"); - - It should_map_the_property_using_property_through_field_access_strategy = () => - mapping.Collections.First(x => x.Name == "BackingFieldCollection").Access.Should().Be("nosetter.camelcase"); - - static AutoPersistenceModel mapper; - static ClassMapping mapping; -} - -public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_with_a_backing_field_with_a_convention_which_changes_the_access_strategy -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity))) - .Conventions.Add(); - - Because of = () => - mapping = mapper.BuildMappingFor(); - - It should_map_the_read_only_property_collection = () => - mapping.Collections.Select(x => x.Name).Should().Contain("BackingFieldCollection"); - - It should_map_the_property_using_property_through_field_access_strategy = () => - mapping.Collections.First(x => x.Name == "BackingFieldCollection").Access.Should().Be("property"); - - static AutoPersistenceModel mapper; - static ClassMapping mapping; - - class Convention : IHasManyConvention - { - public void Apply(IOneToManyCollectionInstance instance) - { - instance.Access.Property(); - } - } -} - -public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_with_a_backing_field_with_an_overridden_configuration -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity)), new TestConfiguration()); - - Because of = () => - mapping = mapper.BuildMappingFor(); - - It should_map_the_property_using_the_access_strategy_from_the_configuration = () => - mapping.Collections.First(x => x.Name == "BackingFieldCollection").Access.Should().Be("noop"); - - static AutoPersistenceModel mapper; - static ClassMapping mapping; - - class TestConfiguration : DefaultAutomappingConfiguration - { - public override Access GetAccessStrategyForReadOnlyProperty(Member member) - { - return Access.NoOp; - } - } -} - -public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_autoproperty -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity))); - - Because of = () => - mapping = mapper.BuildMappingFor(); - - It should_map_the_read_only_property_collection = () => - mapping.Collections.Select(x => x.Name).Should().Contain("AutoPropertyCollection"); - - It should_map_the_property_using_backfield_access_strategy = () => - mapping.Collections.First(x => x.Name == "AutoPropertyCollection").Access.Should().Be("backfield"); - - static AutoPersistenceModel mapper; - static ClassMapping mapping; -} - -public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_autoproperty_with_an_overridden_configuration -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity)), new TestConfiguration()); - - Because of = () => - mapping = mapper.BuildMappingFor(); - - It should_map_the_property_using_the_access_strategy_from_the_configuration = () => - mapping.Collections.First(x => x.Name == "AutoPropertyCollection").Access.Should().Be("noop"); - - static AutoPersistenceModel mapper; - static ClassMapping mapping; - - class TestConfiguration : DefaultAutomappingConfiguration - { - public override Access GetAccessStrategyForReadOnlyProperty(Member member) - { - return Access.NoOp; - } - } -} - -public class when_automapping_an_entity_with_dictionary_properties -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(DictionaryEntity))); - - Because of = () => - mapping = mapper.BuildMappingFor(); - - It should_not_map_the_non_generic_dictionary = () => - mapping.Collections.Select(x => x.Name).Should().NotContain("Dictionary"); - - It should_not_map_the_generic_dictionary = () => - mapping.Collections.Select(x => x.Name).Should().NotContain("GenericDictionary"); - - static AutoPersistenceModel mapper; - static ClassMapping mapping; +using System; +using System.Linq; +using FluentNHibernate.Automapping; +using FluentNHibernate.Conventions; +using FluentNHibernate.Conventions.Instances; +using FluentNHibernate.Mapping; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.MappingModel.Collections; +using FluentNHibernate.Specs.Automapping.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.Automapping; + +public class when_the_automapper_is_told_to_map_a_class_with_a_self_referencing_collection +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(SelfReferencingCollectionEntity))); + + Because of = () => + mapping = mapper.BuildMappingFor(); + + It should_have_one_collection = () => + mapping.Collections.Should().NotBeEmpty(); + + It should_have_it_s_own_type_for_the_collection_child_type = () => + mapping.Collections.Single().ChildType.Should().Be(typeof(SelfReferencingCollectionEntity)); + + It should_have_the_property_name_for_the_collection_name = () => + mapping.Collections.Single().Name.Should().Be("Children"); + + It should_have_a_one_to_many_collection = () => + mapping.Collections.Single().Relationship.Should().BeOfType(); + + static AutoPersistenceModel mapper; + static ClassMapping mapping; +} + +public class when_the_automapper_is_told_to_map_a_class_with_a_self_reference +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(SelfReferenceEntity))); + + Because of = () => + mapping = mapper.BuildMappingFor(); + + It should_have_one_reference = () => + mapping.References.Should().NotBeEmpty(); + + It should_have_it_s_own_type_for_the_reference_type = () => + mapping.References.Single().Class.GetUnderlyingSystemType().Should().Be(typeof(SelfReferenceEntity)); + + It should_have_the_property_name_for_the_reference_name = () => + mapping.References.Single().Name.Should().Be("Parent"); + + static AutoPersistenceModel mapper; + static ClassMapping mapping; +} + +public class when_the_automapper_is_told_to_map_a_class_with_a_self_reference_and_a_self_referencing_collection +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(ParentChildSelfReferenceEntity))); + + Because of = () => + mapping = mapper.BuildMappingFor(); + + It should_have_one_collection = () => + mapping.Collections.Should().NotBeEmpty(); + + It should_have_it_s_own_type_for_the_collection_child_type = () => + mapping.Collections.Single().ChildType.Should().Be(typeof(ParentChildSelfReferenceEntity)); + + It should_have_the_property_name_for_the_collection_name = () => + mapping.Collections.Single().Name.Should().Be("Children"); + + It should_have_a_one_to_many_collection = () => + mapping.Collections.Single().Relationship.Should().BeOfType(); + + It should_have_the_correct_collection_key_column = () => + mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("Parent_id"); + + It should_have_one_reference = () => + mapping.References.Should().NotBeEmpty(); + + It should_have_it_s_own_type_for_the_reference_type = () => + mapping.References.Single().Class.GetUnderlyingSystemType().Should().Be(typeof(ParentChildSelfReferenceEntity)); + + It should_have_the_property_name_for_the_reference_name = () => + mapping.References.Single().Name.Should().Be("Parent"); + + It should_have_the_correct_reference_key_column = () => + mapping.References.Single().Columns.Single().Name.Should().Be("Parent_id"); + + static AutoPersistenceModel mapper; + static ClassMapping mapping; +} + +public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_with_a_backing_field +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity))); + + Because of = () => + mapping = mapper.BuildMappingFor(); + + It should_map_the_read_only_property_collection = () => + mapping.Collections.Select(x => x.Name).Should().Contain("BackingFieldCollection"); + + It should_map_the_property_using_property_through_field_access_strategy = () => + mapping.Collections.First(x => x.Name == "BackingFieldCollection").Access.Should().Be("nosetter.camelcase"); + + static AutoPersistenceModel mapper; + static ClassMapping mapping; +} + +public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_with_a_backing_field_with_a_convention_which_changes_the_access_strategy +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity))) + .Conventions.Add(); + + Because of = () => + mapping = mapper.BuildMappingFor(); + + It should_map_the_read_only_property_collection = () => + mapping.Collections.Select(x => x.Name).Should().Contain("BackingFieldCollection"); + + It should_map_the_property_using_property_through_field_access_strategy = () => + mapping.Collections.First(x => x.Name == "BackingFieldCollection").Access.Should().Be("property"); + + static AutoPersistenceModel mapper; + static ClassMapping mapping; + + class Convention : IHasManyConvention + { + public void Apply(IOneToManyCollectionInstance instance) + { + instance.Access.Property(); + } + } +} + +public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_with_a_backing_field_with_an_overridden_configuration +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity)), new TestConfiguration()); + + Because of = () => + mapping = mapper.BuildMappingFor(); + + It should_map_the_property_using_the_access_strategy_from_the_configuration = () => + mapping.Collections.First(x => x.Name == "BackingFieldCollection").Access.Should().Be("noop"); + + static AutoPersistenceModel mapper; + static ClassMapping mapping; + + class TestConfiguration : DefaultAutomappingConfiguration + { + public override Access GetAccessStrategyForReadOnlyProperty(Member member) + { + return Access.NoOp; + } + } +} + +public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_autoproperty +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity))); + + Because of = () => + mapping = mapper.BuildMappingFor(); + + It should_map_the_read_only_property_collection = () => + mapping.Collections.Select(x => x.Name).Should().Contain("AutoPropertyCollection"); + + It should_map_the_property_using_backfield_access_strategy = () => + mapping.Collections.First(x => x.Name == "AutoPropertyCollection").Access.Should().Be("backfield"); + + static AutoPersistenceModel mapper; + static ClassMapping mapping; +} + +public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_autoproperty_with_an_overridden_configuration +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity)), new TestConfiguration()); + + Because of = () => + mapping = mapper.BuildMappingFor(); + + It should_map_the_property_using_the_access_strategy_from_the_configuration = () => + mapping.Collections.First(x => x.Name == "AutoPropertyCollection").Access.Should().Be("noop"); + + static AutoPersistenceModel mapper; + static ClassMapping mapping; + + class TestConfiguration : DefaultAutomappingConfiguration + { + public override Access GetAccessStrategyForReadOnlyProperty(Member member) + { + return Access.NoOp; + } + } +} + +public class when_automapping_an_entity_with_dictionary_properties +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(DictionaryEntity))); + + Because of = () => + mapping = mapper.BuildMappingFor(); + + It should_not_map_the_non_generic_dictionary = () => + mapping.Collections.Select(x => x.Name).Should().NotContain("Dictionary"); + + It should_not_map_the_generic_dictionary = () => + mapping.Collections.Select(x => x.Name).Should().NotContain("GenericDictionary"); + + static AutoPersistenceModel mapper; + static ClassMapping mapping; } diff --git a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Version.cs b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Version.cs index 327794674..d03c51b4e 100644 --- a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Version.cs +++ b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Version.cs @@ -1,57 +1,57 @@ -using System; -using System.Linq; -using FluentNHibernate.Automapping; -using FluentNHibernate.Conventions; -using FluentNHibernate.Conventions.Instances; -using FluentNHibernate.Mapping; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.MappingModel.Collections; -using FluentNHibernate.Specs.Automapping.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.Automapping; - -public class when_the_automapper_is_told_to_map_a_class_with_a_version -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(VersionedEntity))); - - Because of = () => - mapping = mapper.BuildMappingFor(); - - It should_have_a_version = () => - mapping.Version.Should().NotBeNull(); - - It should_have_picked_the_right_property_to_be_the_version = () => - mapping.Version.Name.Should().Be("Timestamp"); - - static AutoPersistenceModel mapper; - static ClassMapping mapping; -} - -public class when_the_automapper_is_told_to_map_a_class_with_a_custom_version_defined_in_config -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(VersionedEntity)), new TestConfig()); - - Because of = () => - mapping = mapper.BuildMappingFor(); - - It should_have_a_version = () => - mapping.Version.Should().NotBeNull(); - - It should_have_picked_the_right_property_to_be_the_version = () => - mapping.Version.Name.Should().Be("AnUnobviousVersion"); - - static AutoPersistenceModel mapper; - static ClassMapping mapping; - - class TestConfig : DefaultAutomappingConfiguration - { - public override bool IsVersion(Member member) - { - return member.Name == "AnUnobviousVersion"; - } - } +using System; +using System.Linq; +using FluentNHibernate.Automapping; +using FluentNHibernate.Conventions; +using FluentNHibernate.Conventions.Instances; +using FluentNHibernate.Mapping; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.MappingModel.Collections; +using FluentNHibernate.Specs.Automapping.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.Automapping; + +public class when_the_automapper_is_told_to_map_a_class_with_a_version +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(VersionedEntity))); + + Because of = () => + mapping = mapper.BuildMappingFor(); + + It should_have_a_version = () => + mapping.Version.Should().NotBeNull(); + + It should_have_picked_the_right_property_to_be_the_version = () => + mapping.Version.Name.Should().Be("Timestamp"); + + static AutoPersistenceModel mapper; + static ClassMapping mapping; +} + +public class when_the_automapper_is_told_to_map_a_class_with_a_custom_version_defined_in_config +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(VersionedEntity)), new TestConfig()); + + Because of = () => + mapping = mapper.BuildMappingFor(); + + It should_have_a_version = () => + mapping.Version.Should().NotBeNull(); + + It should_have_picked_the_right_property_to_be_the_version = () => + mapping.Version.Name.Should().Be("AnUnobviousVersion"); + + static AutoPersistenceModel mapper; + static ClassMapping mapping; + + class TestConfig : DefaultAutomappingConfiguration + { + public override bool IsVersion(Member member) + { + return member.Name == "AnUnobviousVersion"; + } + } } diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/AutomappingSpecExtensions.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/AutomappingSpecExtensions.cs index 6a2e1b275..3325408fc 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/AutomappingSpecExtensions.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/AutomappingSpecExtensions.cs @@ -1,112 +1,112 @@ -using System; -using System.Linq; -using System.Xml; -using FluentNHibernate.Automapping; -using FluentNHibernate.MappingModel; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.MappingModel.Output; -using Machine.Specifications; - -namespace FluentNHibernate.Specs.Automapping.Fixtures; - -public static class AutomappingSpecExtensions -{ - public static ClassMapping BuildMappingFor(this AutoPersistenceModel model) - { - return model.BuildMappings() - .SelectMany(x => x.Classes) - .FirstOrDefault(x => x.Type == typeof(T)); - } - - public static XmlDocument ToXml(this ClassMapping mapping) - { - var hbm = new HibernateMapping(); - - hbm.AddClass(mapping); - - return new MappingXmlSerializer() - .Serialize(hbm); - } -} - -public static class XmlTestExtensions -{ - public static XmlElementTester Element(this XmlDocument doc, string path) - { - return new XmlElementTester(doc, path); - } - - public class XmlElementTester - { - readonly XmlDocument doc; - string currentPath; - XmlElement currentElement; - - public XmlElementTester(XmlDocument doc, string path) - { - currentElement = (XmlElement)doc.DocumentElement.SelectSingleNode(path); - this.doc = doc; - currentPath = path; - } - - public XmlElementTester ShouldExist() - { - if (currentElement == null) - throw new SpecificationException(string.Format("Should exist at {0} but does not.", currentPath)); - - return this; - } - - public XmlElementTester ShouldNotExist() - { - if (currentElement != null) - throw new SpecificationException(string.Format("Should not exist at {0} but does.", currentPath)); - - return this; - } - - public XmlElementTester HasAttribute(string name) - { - if (!currentElement.HasAttribute(name)) - throw new SpecificationException(string.Format("Should have attribute named {0} at {1} but does not.", name, currentPath)); - - return this; - } - - public XmlElementTester HasAttribute(string name, string value) - { - ShouldExist(); - HasAttribute(name); - - var actual = currentElement.GetAttribute(name); - - if (!actual.Equals(value)) - throw new SpecificationException(string.Format("Should have attribute named {0} at {1} with value of {2} but was {3}", name, currentPath, value, actual)); - - return this; - } - - public XmlElementTester HasAttribute(string name, Func predicate) - { - ShouldExist(); - HasAttribute(name); - - var actual = currentElement.GetAttribute(name); - - if (!predicate(actual)) - throw new SpecificationException(string.Format("Should have attribute named {0} at {1} with value matching predicate but does not.", name, currentPath)); - - return this; - } - - public XmlElementTester DoesntHaveAttribute(string name) - { - ShouldExist(); - - if (currentElement.HasAttribute(name)) - throw new SpecificationException(string.Format("Should not have attribute named {0} at {1} but does.", name, currentPath)); - - return this; - } - } +using System; +using System.Linq; +using System.Xml; +using FluentNHibernate.Automapping; +using FluentNHibernate.MappingModel; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.MappingModel.Output; +using Machine.Specifications; + +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +public static class AutomappingSpecExtensions +{ + public static ClassMapping BuildMappingFor(this AutoPersistenceModel model) + { + return model.BuildMappings() + .SelectMany(x => x.Classes) + .FirstOrDefault(x => x.Type == typeof(T)); + } + + public static XmlDocument ToXml(this ClassMapping mapping) + { + var hbm = new HibernateMapping(); + + hbm.AddClass(mapping); + + return new MappingXmlSerializer() + .Serialize(hbm); + } +} + +public static class XmlTestExtensions +{ + public static XmlElementTester Element(this XmlDocument doc, string path) + { + return new XmlElementTester(doc, path); + } + + public class XmlElementTester + { + readonly XmlDocument doc; + string currentPath; + XmlElement currentElement; + + public XmlElementTester(XmlDocument doc, string path) + { + currentElement = (XmlElement)doc.DocumentElement.SelectSingleNode(path); + this.doc = doc; + currentPath = path; + } + + public XmlElementTester ShouldExist() + { + if (currentElement == null) + throw new SpecificationException(string.Format("Should exist at {0} but does not.", currentPath)); + + return this; + } + + public XmlElementTester ShouldNotExist() + { + if (currentElement != null) + throw new SpecificationException(string.Format("Should not exist at {0} but does.", currentPath)); + + return this; + } + + public XmlElementTester HasAttribute(string name) + { + if (!currentElement.HasAttribute(name)) + throw new SpecificationException(string.Format("Should have attribute named {0} at {1} but does not.", name, currentPath)); + + return this; + } + + public XmlElementTester HasAttribute(string name, string value) + { + ShouldExist(); + HasAttribute(name); + + var actual = currentElement.GetAttribute(name); + + if (!actual.Equals(value)) + throw new SpecificationException(string.Format("Should have attribute named {0} at {1} with value of {2} but was {3}", name, currentPath, value, actual)); + + return this; + } + + public XmlElementTester HasAttribute(string name, Func predicate) + { + ShouldExist(); + HasAttribute(name); + + var actual = currentElement.GetAttribute(name); + + if (!predicate(actual)) + throw new SpecificationException(string.Format("Should have attribute named {0} at {1} with value matching predicate but does not.", name, currentPath)); + + return this; + } + + public XmlElementTester DoesntHaveAttribute(string name) + { + ShouldExist(); + + if (currentElement.HasAttribute(name)) + throw new SpecificationException(string.Format("Should not have attribute named {0} at {1} but does.", name, currentPath)); + + return this; + } + } } diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/DictionaryEntity.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/DictionaryEntity.cs index 915002cd2..22a0673e3 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/DictionaryEntity.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/DictionaryEntity.cs @@ -1,12 +1,12 @@ -using System.Collections; -using System.Collections.Generic; -using FluentNHibernate.Specs.ExternalFixtures; - -namespace FluentNHibernate.Specs.Automapping.Fixtures; - -class DictionaryEntity -{ - public int Id { get; set; } - public IDictionary GenericDictionary { get; set; } - public IDictionary Dictionary { get; set; } +using System.Collections; +using System.Collections.Generic; +using FluentNHibernate.Specs.ExternalFixtures; + +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +class DictionaryEntity +{ + public int Id { get; set; } + public IDictionary GenericDictionary { get; set; } + public IDictionary Dictionary { get; set; } } diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityUsingPrivateFields.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityUsingPrivateFields.cs index 09dd42cfc..fd028a8cf 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityUsingPrivateFields.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityUsingPrivateFields.cs @@ -1,16 +1,16 @@ -using System; -using System.Collections.Generic; - -namespace FluentNHibernate.Specs.Automapping.Fixtures; - -class EntityUsingPrivateFields -{ - int id; - string one; - DateTime two; - DateTime? three; - int _one; - IList _children; - - public string PublicPropertyThatShouldBeIgnored { get; set; } +using System; +using System.Collections.Generic; + +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +class EntityUsingPrivateFields +{ + int id; + string one; + DateTime two; + DateTime? three; + int _one; + IList _children; + + public string PublicPropertyThatShouldBeIgnored { get; set; } } diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityWithStaticProperties.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityWithStaticProperties.cs index ceb780520..5b540627f 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityWithStaticProperties.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityWithStaticProperties.cs @@ -1,7 +1,7 @@ -namespace FluentNHibernate.Specs.Automapping.Fixtures; - -public class EntityWithStaticProperties -{ - public int Id { get; set; } - public static int StaticProperty { get; set; } +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +public class EntityWithStaticProperties +{ + public int Id { get; set; } + public static int StaticProperty { get; set; } } diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/FakeMembers.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/FakeMembers.cs index 2077598cb..28f50da85 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/FakeMembers.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/FakeMembers.cs @@ -1,41 +1,41 @@ -using System; -using System.Collections.Generic; - -namespace FluentNHibernate.Specs.Automapping.Fixtures; - -public static class FakeMembers -{ - public static readonly Type Type = typeof(Target); - public static readonly Member IListOfStrings; - public static readonly Member IListOfInts; - public static readonly Member IListOfDoubles; - public static readonly Member IListOfShorts; - public static readonly Member IListOfLongs; - public static readonly Member IListOfFloats; - public static readonly Member IListOfBools; - public static readonly Member IListOfDateTimes; - - static FakeMembers() - { - IListOfStrings = typeof(Target).GetProperty("IListOfStrings").ToMember(); - IListOfInts = typeof(Target).GetProperty("IListOfInts").ToMember(); - IListOfDoubles = typeof(Target).GetProperty("IListOfDoubles").ToMember(); - IListOfShorts = typeof(Target).GetProperty("IListOfShorts").ToMember(); - IListOfLongs = typeof(Target).GetProperty("IListOfLongs").ToMember(); - IListOfFloats = typeof(Target).GetProperty("IListOfFloats").ToMember(); - IListOfBools = typeof(Target).GetProperty("IListOfBools").ToMember(); - IListOfDateTimes = typeof(Target).GetProperty("IListOfDateTimes").ToMember(); - } - - class Target - { - public IList IListOfStrings { get; set; } - public IList IListOfInts { get; set; } - public IList IListOfDoubles { get; set; } - public IList IListOfShorts { get; set; } - public IList IListOfLongs { get; set; } - public IList IListOfFloats { get; set; } - public IList IListOfBools { get; set; } - public IList IListOfDateTimes { get; set; } - } +using System; +using System.Collections.Generic; + +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +public static class FakeMembers +{ + public static readonly Type Type = typeof(Target); + public static readonly Member IListOfStrings; + public static readonly Member IListOfInts; + public static readonly Member IListOfDoubles; + public static readonly Member IListOfShorts; + public static readonly Member IListOfLongs; + public static readonly Member IListOfFloats; + public static readonly Member IListOfBools; + public static readonly Member IListOfDateTimes; + + static FakeMembers() + { + IListOfStrings = typeof(Target).GetProperty("IListOfStrings").ToMember(); + IListOfInts = typeof(Target).GetProperty("IListOfInts").ToMember(); + IListOfDoubles = typeof(Target).GetProperty("IListOfDoubles").ToMember(); + IListOfShorts = typeof(Target).GetProperty("IListOfShorts").ToMember(); + IListOfLongs = typeof(Target).GetProperty("IListOfLongs").ToMember(); + IListOfFloats = typeof(Target).GetProperty("IListOfFloats").ToMember(); + IListOfBools = typeof(Target).GetProperty("IListOfBools").ToMember(); + IListOfDateTimes = typeof(Target).GetProperty("IListOfDateTimes").ToMember(); + } + + class Target + { + public IList IListOfStrings { get; set; } + public IList IListOfInts { get; set; } + public IList IListOfDoubles { get; set; } + public IList IListOfShorts { get; set; } + public IList IListOfLongs { get; set; } + public IList IListOfFloats { get; set; } + public IList IListOfBools { get; set; } + public IList IListOfDateTimes { get; set; } + } } diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/Overrides/EntityTableOverride.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/Overrides/EntityTableOverride.cs index 13e22a4f0..3340e9a98 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/Overrides/EntityTableOverride.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/Overrides/EntityTableOverride.cs @@ -1,13 +1,13 @@ -using FluentNHibernate.Automapping; -using FluentNHibernate.Automapping.Alterations; -using FluentNHibernate.Specs.ExternalFixtures; - -namespace FluentNHibernate.Specs.Automapping.Fixtures.Overrides; - -public class EntityTableOverride : IAutoMappingOverride -{ - public void Override(AutoMapping mapping) - { - mapping.Table("OverriddenTableName"); - } +using FluentNHibernate.Automapping; +using FluentNHibernate.Automapping.Alterations; +using FluentNHibernate.Specs.ExternalFixtures; + +namespace FluentNHibernate.Specs.Automapping.Fixtures.Overrides; + +public class EntityTableOverride : IAutoMappingOverride +{ + public void Override(AutoMapping mapping) + { + mapping.Table("OverriddenTableName"); + } } diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/ParentChildSelfReferenceEntity.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/ParentChildSelfReferenceEntity.cs index b5b74e9a5..b93ee1efc 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/ParentChildSelfReferenceEntity.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/ParentChildSelfReferenceEntity.cs @@ -1,10 +1,10 @@ -using System.Collections.Generic; - -namespace FluentNHibernate.Specs.Automapping.Fixtures; - -public class ParentChildSelfReferenceEntity -{ - public int Id { get; set; } - public ParentChildSelfReferenceEntity Parent { get; set; } - public IList Children { get; set; } +using System.Collections.Generic; + +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +public class ParentChildSelfReferenceEntity +{ + public int Id { get; set; } + public ParentChildSelfReferenceEntity Parent { get; set; } + public IList Children { get; set; } } diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/ReadOnlyEnumerableEntity.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/ReadOnlyEnumerableEntity.cs index b4095d637..07a761575 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/ReadOnlyEnumerableEntity.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/ReadOnlyEnumerableEntity.cs @@ -1,16 +1,16 @@ -using System.Collections.Generic; -using FluentNHibernate.Specs.ExternalFixtures; - -namespace FluentNHibernate.Specs.Automapping.Fixtures; - -class ReadOnlyEnumerableEntity -{ - IList backingFieldCollection; - - public int Id { get; set; } - public IEnumerable AutoPropertyCollection { get; private set; } - public IEnumerable BackingFieldCollection - { - get { return backingFieldCollection; } - } +using System.Collections.Generic; +using FluentNHibernate.Specs.ExternalFixtures; + +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +class ReadOnlyEnumerableEntity +{ + IList backingFieldCollection; + + public int Id { get; set; } + public IEnumerable AutoPropertyCollection { get; private set; } + public IEnumerable BackingFieldCollection + { + get { return backingFieldCollection; } + } } diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferenceEntity.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferenceEntity.cs index f7b4b6258..3d17bd03c 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferenceEntity.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferenceEntity.cs @@ -1,7 +1,7 @@ -namespace FluentNHibernate.Specs.Automapping.Fixtures; - -public class SelfReferenceEntity -{ - public int Id { get; set; } - public SelfReferenceEntity Parent { get; set; } +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +public class SelfReferenceEntity +{ + public int Id { get; set; } + public SelfReferenceEntity Parent { get; set; } } diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferencingCollectionEntity.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferencingCollectionEntity.cs index abaa20853..f95755129 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferencingCollectionEntity.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferencingCollectionEntity.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; - -namespace FluentNHibernate.Specs.Automapping.Fixtures; - -public class SelfReferencingCollectionEntity -{ - public int Id { get; set; } - public IList Children { get; set; } +using System.Collections.Generic; + +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +public class SelfReferencingCollectionEntity +{ + public int Id { get; set; } + public IList Children { get; set; } } diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/StubTypeSource.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/StubTypeSource.cs index 4a84eaf5e..a87a7c404 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/StubTypeSource.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/StubTypeSource.cs @@ -1,30 +1,30 @@ -using System; -using System.Collections.Generic; -using FluentNHibernate.Diagnostics; - -namespace FluentNHibernate.Specs.Automapping.Fixtures; - -internal class StubTypeSource : ITypeSource -{ - private readonly IEnumerable types; - - public StubTypeSource(params Type[] types) - { - this.types = types; - } - - public IEnumerable GetTypes() - { - return types; - } - - public void LogSource(IDiagnosticLogger logger) - { - logger.LoadedFluentMappingsFromSource(this); - } - - public string GetIdentifier() - { - return "StubTypeSource"; - } +using System; +using System.Collections.Generic; +using FluentNHibernate.Diagnostics; + +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +internal class StubTypeSource : ITypeSource +{ + private readonly IEnumerable types; + + public StubTypeSource(params Type[] types) + { + this.types = types; + } + + public IEnumerable GetTypes() + { + return types; + } + + public void LogSource(IDiagnosticLogger logger) + { + logger.LoadedFluentMappingsFromSource(this); + } + + public string GetIdentifier() + { + return "StubTypeSource"; + } } diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/UserTypes.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/UserTypes.cs index 33c160748..57cf92ee6 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/UserTypes.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/UserTypes.cs @@ -1,177 +1,177 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using System.Linq; -using System.Text; -using FluentNHibernate.Conventions; -using FluentNHibernate.Conventions.Instances; -using NHibernate.Engine; -using NHibernate.SqlTypes; -using NHibernate.UserTypes; - -namespace FluentNHibernate.Specs.Automapping.Fixtures; - -public class TypeWithNullableUT -{ - public int ID { get; set; } - public UserValueType? Simple { get; set; } -} - -public class TypeWithValueUT -{ - public int Id { get; set; } - public UserValueType Definite { get; set; } -} - -public class NotNullableUT -{ - public int ID { get; set; } - public CustomUserType Complex { get; set; } -} - -public class ValueTypeConvention : UserTypeConvention -{ - public override void Apply(IPropertyInstance instance) - { - base.Apply(instance); - instance.Column("arbitraryName"); - } -} - -public class CustomTypeConvention : UserTypeConvention -{ - public override void Apply(IPropertyInstance instance) - { - base.Apply(instance); - instance.Column("someOtherName"); - } -} - -public class CustomUserType : IUserType -{ - public new bool Equals(object x, object y) - { - return x == y; - } - - public int GetHashCode(object x) - { - return x.GetHashCode(); - } - - public object NullSafeGet(IDataReader rs, string[] names, object owner) - { - return null; - } - - public void NullSafeSet(IDbCommand cmd, object value, int index) - { - - } - - public object DeepCopy(object value) - { - return value; - } - - public object Replace(object original, object target, object owner) - { - return original; - } - - public object Assemble(object cached, object owner) - { - return cached; - } - - public object Disassemble(object value) - { - return value; - } - - public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner) - { - throw new NotImplementedException(); - } - - public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public SqlType[] SqlTypes - { - get { return new[] { new SqlType(DbType.String) }; } - } - - public Type ReturnedType - { - get { return typeof(CustomUserType); } - } - - public bool IsMutable - { - get { return true; } - } -} - -public struct UserValueType : IUserType -{ - public string AddressLine1 { get; set; } - public string AddressLine2 { get; set; } - - public new bool Equals(object x, object y) - { - throw new NotImplementedException(); - } - - public int GetHashCode(object x) - { - throw new NotImplementedException(); - } - - public object NullSafeGet(IDataReader rs, string[] names, object owner) - { - throw new NotImplementedException(); - } - - public void NullSafeSet(IDbCommand cmd, object value, int index) - { - throw new NotImplementedException(); - } - - public object DeepCopy(object value) - { - throw new NotImplementedException(); - } - - public object Replace(object original, object target, object owner) - { - throw new NotImplementedException(); - } - - public object Assemble(object cached, object owner) - { - throw new NotImplementedException(); - } - - public object Disassemble(object value) - { - throw new NotImplementedException(); - } - - public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner) - { - throw new NotImplementedException(); - } - - public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session) - { - throw new NotImplementedException(); - } - - public SqlType[] SqlTypes { get; private set; } - public Type ReturnedType { get { return typeof(UserValueType); } } - public bool IsMutable { get; private set; } +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Common; +using System.Linq; +using System.Text; +using FluentNHibernate.Conventions; +using FluentNHibernate.Conventions.Instances; +using NHibernate.Engine; +using NHibernate.SqlTypes; +using NHibernate.UserTypes; + +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +public class TypeWithNullableUT +{ + public int ID { get; set; } + public UserValueType? Simple { get; set; } +} + +public class TypeWithValueUT +{ + public int Id { get; set; } + public UserValueType Definite { get; set; } +} + +public class NotNullableUT +{ + public int ID { get; set; } + public CustomUserType Complex { get; set; } +} + +public class ValueTypeConvention : UserTypeConvention +{ + public override void Apply(IPropertyInstance instance) + { + base.Apply(instance); + instance.Column("arbitraryName"); + } +} + +public class CustomTypeConvention : UserTypeConvention +{ + public override void Apply(IPropertyInstance instance) + { + base.Apply(instance); + instance.Column("someOtherName"); + } +} + +public class CustomUserType : IUserType +{ + public new bool Equals(object x, object y) + { + return x == y; + } + + public int GetHashCode(object x) + { + return x.GetHashCode(); + } + + public object NullSafeGet(IDataReader rs, string[] names, object owner) + { + return null; + } + + public void NullSafeSet(IDbCommand cmd, object value, int index) + { + + } + + public object DeepCopy(object value) + { + return value; + } + + public object Replace(object original, object target, object owner) + { + return original; + } + + public object Assemble(object cached, object owner) + { + return cached; + } + + public object Disassemble(object value) + { + return value; + } + + public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner) + { + throw new NotImplementedException(); + } + + public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session) + { + throw new NotImplementedException(); + } + + public SqlType[] SqlTypes + { + get { return new[] { new SqlType(DbType.String) }; } + } + + public Type ReturnedType + { + get { return typeof(CustomUserType); } + } + + public bool IsMutable + { + get { return true; } + } +} + +public struct UserValueType : IUserType +{ + public string AddressLine1 { get; set; } + public string AddressLine2 { get; set; } + + public new bool Equals(object x, object y) + { + throw new NotImplementedException(); + } + + public int GetHashCode(object x) + { + throw new NotImplementedException(); + } + + public object NullSafeGet(IDataReader rs, string[] names, object owner) + { + throw new NotImplementedException(); + } + + public void NullSafeSet(IDbCommand cmd, object value, int index) + { + throw new NotImplementedException(); + } + + public object DeepCopy(object value) + { + throw new NotImplementedException(); + } + + public object Replace(object original, object target, object owner) + { + throw new NotImplementedException(); + } + + public object Assemble(object cached, object owner) + { + throw new NotImplementedException(); + } + + public object Disassemble(object value) + { + throw new NotImplementedException(); + } + + public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner) + { + throw new NotImplementedException(); + } + + public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session) + { + throw new NotImplementedException(); + } + + public SqlType[] SqlTypes { get; private set; } + public Type ReturnedType { get { return typeof(UserValueType); } } + public bool IsMutable { get; private set; } } diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/VersionedEntity.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/VersionedEntity.cs index cc8a6ea1a..389e7ce8c 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/VersionedEntity.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/VersionedEntity.cs @@ -1,8 +1,8 @@ -namespace FluentNHibernate.Specs.Automapping.Fixtures; - -public class VersionedEntity -{ - public int Id { get; set; } - public int Timestamp { get; set; } - public string AnUnobviousVersion { get; set; } +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +public class VersionedEntity +{ + public int Id { get; set; } + public int Timestamp { get; set; } + public string AnUnobviousVersion { get; set; } } diff --git a/src/FluentNHibernate.Specs/Automapping/OverrideSpecs.cs b/src/FluentNHibernate.Specs/Automapping/OverrideSpecs.cs index 25cce5214..7779f6014 100644 --- a/src/FluentNHibernate.Specs/Automapping/OverrideSpecs.cs +++ b/src/FluentNHibernate.Specs/Automapping/OverrideSpecs.cs @@ -1,151 +1,151 @@ -using System.Linq; -using FluentNHibernate.Automapping; -using FluentNHibernate.Automapping.Alterations; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.Automapping.Fixtures; -using FluentNHibernate.Specs.Automapping.Fixtures.Overrides; -using FluentNHibernate.Specs.ExternalFixtures; -using FluentNHibernate.Specs.ExternalFixtures.Overrides; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.Automapping; - -public class when_using_an_automapping_override_to_create_a_join -{ - Establish context = () => - model = AutoMap.Source(new StubTypeSource(typeof(Entity))) - .Override(map => - map.Join("join_table", m => m.Map(x => x.One))); - - Because of = () => - mapping = model.BuildMappingFor(); - - It should_create_the_join_mapping = () => - mapping.Joins.Should().NotBeEmpty(); - - It should_have_a_property_in_the_join = () => - mapping.Joins.Single().Properties.Select(x => x.Name).Should().Contain("One"); - - It should_exclude_the_join_mapped_property_from_the_main_automapping = () => - mapping.Properties.Select(x => x.Name).Should().NotContain("One"); - - static AutoPersistenceModel model; - static ClassMapping mapping; -} - -public class when_using_an_automapping_override_to_specify_a_discriminators_and_join_on_subclass -{ - private Establish context = () => - model = AutoMap.Source(new StubTypeSource(typeof (Parent), typeof (Child))) - .Override(map => - map.DiscriminateSubClassesOnColumn("type")) - .Override(map => map.Join("table", part => { })); - - private Because of = () => - mapping = model.BuildMappingFor(); - - It should_not_create_the_join_mapping = () => - mapping.Joins.Should().BeEmpty(); - - It should_map_the_discriminator = () => - mapping.Discriminator.Should().NotBeNull(); - - It should_map_subclasses_as_joined_subclasses = () => - mapping.Subclasses.Should().OnlyContain(x => x.Joins.Any()); - - static AutoPersistenceModel model; - static ClassMapping mapping; -} - -public class when_using_an_automapping_override_to_specify_a_discriminator -{ - Establish context = () => - model = AutoMap.Source(new StubTypeSource(typeof(Parent), typeof(Child))) - .Override(map => - map.DiscriminateSubClassesOnColumn("discriminator")); - - Because of = () => - mapping = model.BuildMappingFor(); - - It should_map_the_discriminator = () => - mapping.Discriminator.Should().NotBeNull(); - - It should_map_subclasses_as_subclass_instead_of_joined_subclass = () => - { - mapping.Subclasses.Count().Should().Be(1); - mapping.Subclasses.Should().OnlyContain(subclass => subclass.SubclassType == SubclassType.Subclass); - }; - - static AutoPersistenceModel model; - static ClassMapping mapping; -} - -[Subject(typeof(IAutoMappingOverride<>))] -public class when_using_multiple_overrides_from_different_assemblies -{ - Establish context = () => - model = AutoMap.Source(new StubTypeSource(typeof(Entity))) - .UseOverridesFromAssemblyOf() - .UseOverridesFromAssemblyOf(); - - Because of = () => - mapping = model.BuildMappingFor(); - - It should_apply_override_from_the_first_assembly = () => - mapping.BatchSize.Should().Be(1234); - - It should_apply_override_from_the_second_assembly = () => - mapping.TableName.Should().Be("OverriddenTableName"); - - static AutoPersistenceModel model; - static ClassMapping mapping; -} - -[Subject(typeof(IAutoMappingOverride<>))] -public class when_multiple_overrides_present_in_one_class -{ - Establish context = () => - { - model = AutoMap.Source(new StubTypeSource(typeof(Entity), typeof(Parent), typeof(B_Parent))); - model.Override(typeof(MultipleOverrides)); - }; - - Because of = () => - { - entityMapping = model.BuildMappingFor(); - parentMapping = model.BuildMappingFor(); - bParentMapping = model.BuildMappingFor(); - }; - - It should_apply_overrides_to_every_class_for_which_such_were_provided = () => - { - entityMapping.EntityName.Should().Be("customEntityName"); - parentMapping.TableName.Should().Be("fancyTableName_Parent"); - bParentMapping.BatchSize.Should().Be(50); - }; - - - static AutoPersistenceModel model; - static ClassMapping entityMapping; - static ClassMapping parentMapping; - static ClassMapping bParentMapping; -} - -public class MultipleOverrides: IAutoMappingOverride, IAutoMappingOverride, IAutoMappingOverride -{ - public void Override(AutoMapping mapping) - { - mapping.EntityName("customEntityName"); - } - - public void Override(AutoMapping mapping) - { - mapping.Table("fancyTableName_Parent"); - } - - public void Override(AutoMapping mapping) - { - mapping.BatchSize(50); - } +using System.Linq; +using FluentNHibernate.Automapping; +using FluentNHibernate.Automapping.Alterations; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.Automapping.Fixtures; +using FluentNHibernate.Specs.Automapping.Fixtures.Overrides; +using FluentNHibernate.Specs.ExternalFixtures; +using FluentNHibernate.Specs.ExternalFixtures.Overrides; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.Automapping; + +public class when_using_an_automapping_override_to_create_a_join +{ + Establish context = () => + model = AutoMap.Source(new StubTypeSource(typeof(Entity))) + .Override(map => + map.Join("join_table", m => m.Map(x => x.One))); + + Because of = () => + mapping = model.BuildMappingFor(); + + It should_create_the_join_mapping = () => + mapping.Joins.Should().NotBeEmpty(); + + It should_have_a_property_in_the_join = () => + mapping.Joins.Single().Properties.Select(x => x.Name).Should().Contain("One"); + + It should_exclude_the_join_mapped_property_from_the_main_automapping = () => + mapping.Properties.Select(x => x.Name).Should().NotContain("One"); + + static AutoPersistenceModel model; + static ClassMapping mapping; +} + +public class when_using_an_automapping_override_to_specify_a_discriminators_and_join_on_subclass +{ + private Establish context = () => + model = AutoMap.Source(new StubTypeSource(typeof (Parent), typeof (Child))) + .Override(map => + map.DiscriminateSubClassesOnColumn("type")) + .Override(map => map.Join("table", part => { })); + + private Because of = () => + mapping = model.BuildMappingFor(); + + It should_not_create_the_join_mapping = () => + mapping.Joins.Should().BeEmpty(); + + It should_map_the_discriminator = () => + mapping.Discriminator.Should().NotBeNull(); + + It should_map_subclasses_as_joined_subclasses = () => + mapping.Subclasses.Should().OnlyContain(x => x.Joins.Any()); + + static AutoPersistenceModel model; + static ClassMapping mapping; +} + +public class when_using_an_automapping_override_to_specify_a_discriminator +{ + Establish context = () => + model = AutoMap.Source(new StubTypeSource(typeof(Parent), typeof(Child))) + .Override(map => + map.DiscriminateSubClassesOnColumn("discriminator")); + + Because of = () => + mapping = model.BuildMappingFor(); + + It should_map_the_discriminator = () => + mapping.Discriminator.Should().NotBeNull(); + + It should_map_subclasses_as_subclass_instead_of_joined_subclass = () => + { + mapping.Subclasses.Count().Should().Be(1); + mapping.Subclasses.Should().OnlyContain(subclass => subclass.SubclassType == SubclassType.Subclass); + }; + + static AutoPersistenceModel model; + static ClassMapping mapping; +} + +[Subject(typeof(IAutoMappingOverride<>))] +public class when_using_multiple_overrides_from_different_assemblies +{ + Establish context = () => + model = AutoMap.Source(new StubTypeSource(typeof(Entity))) + .UseOverridesFromAssemblyOf() + .UseOverridesFromAssemblyOf(); + + Because of = () => + mapping = model.BuildMappingFor(); + + It should_apply_override_from_the_first_assembly = () => + mapping.BatchSize.Should().Be(1234); + + It should_apply_override_from_the_second_assembly = () => + mapping.TableName.Should().Be("OverriddenTableName"); + + static AutoPersistenceModel model; + static ClassMapping mapping; +} + +[Subject(typeof(IAutoMappingOverride<>))] +public class when_multiple_overrides_present_in_one_class +{ + Establish context = () => + { + model = AutoMap.Source(new StubTypeSource(typeof(Entity), typeof(Parent), typeof(B_Parent))); + model.Override(typeof(MultipleOverrides)); + }; + + Because of = () => + { + entityMapping = model.BuildMappingFor(); + parentMapping = model.BuildMappingFor(); + bParentMapping = model.BuildMappingFor(); + }; + + It should_apply_overrides_to_every_class_for_which_such_were_provided = () => + { + entityMapping.EntityName.Should().Be("customEntityName"); + parentMapping.TableName.Should().Be("fancyTableName_Parent"); + bParentMapping.BatchSize.Should().Be(50); + }; + + + static AutoPersistenceModel model; + static ClassMapping entityMapping; + static ClassMapping parentMapping; + static ClassMapping bParentMapping; +} + +public class MultipleOverrides: IAutoMappingOverride, IAutoMappingOverride, IAutoMappingOverride +{ + public void Override(AutoMapping mapping) + { + mapping.EntityName("customEntityName"); + } + + public void Override(AutoMapping mapping) + { + mapping.Table("fancyTableName_Parent"); + } + + public void Override(AutoMapping mapping) + { + mapping.BatchSize(50); + } } diff --git a/src/FluentNHibernate.Specs/Automapping/PrivateAutomapperSpecs.cs b/src/FluentNHibernate.Specs/Automapping/PrivateAutomapperSpecs.cs index 70da9ca1e..9200911b1 100644 --- a/src/FluentNHibernate.Specs/Automapping/PrivateAutomapperSpecs.cs +++ b/src/FluentNHibernate.Specs/Automapping/PrivateAutomapperSpecs.cs @@ -1,35 +1,35 @@ -using System.Linq; -using FluentNHibernate.Automapping; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.Automapping.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.Automapping; - -public class when_using_the_private_automapper_to_map_a_entity_with_private_fields_starting_with_an_underscore -{ - Establish context = () => - { - model = new PrivateAutoPersistenceModel() - .Setup(conventions => conventions.FindMembers = m => m.IsField && m.Name.StartsWith("_")); - - model.ValidationEnabled = false; - model.AddTypeSource(new StubTypeSource(typeof(EntityUsingPrivateFields))); - }; - - Because of = () => - mapping = model.BuildMappingFor(); - - It should_map_fields_matching_the_convention = () => - mapping.Properties.Select(x => x.Name).Should().Contain("_one"); - - It should_map_private_collections = () => - mapping.Collections.Select(x => x.Name).Should().Contain("_children"); - - It should_not_map_fields_that_dont_match_the_convention = () => - mapping.Properties.Select(x => x.Name).Should().NotContain("one"); - - static ClassMapping mapping; - static AutoPersistenceModel model; +using System.Linq; +using FluentNHibernate.Automapping; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.Automapping.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.Automapping; + +public class when_using_the_private_automapper_to_map_a_entity_with_private_fields_starting_with_an_underscore +{ + Establish context = () => + { + model = new PrivateAutoPersistenceModel() + .Setup(conventions => conventions.FindMembers = m => m.IsField && m.Name.StartsWith("_")); + + model.ValidationEnabled = false; + model.AddTypeSource(new StubTypeSource(typeof(EntityUsingPrivateFields))); + }; + + Because of = () => + mapping = model.BuildMappingFor(); + + It should_map_fields_matching_the_convention = () => + mapping.Properties.Select(x => x.Name).Should().Contain("_one"); + + It should_map_private_collections = () => + mapping.Collections.Select(x => x.Name).Should().Contain("_children"); + + It should_not_map_fields_that_dont_match_the_convention = () => + mapping.Properties.Select(x => x.Name).Should().NotContain("one"); + + static ClassMapping mapping; + static AutoPersistenceModel model; } diff --git a/src/FluentNHibernate.Specs/Automapping/PrivateFieldsSpecs.cs b/src/FluentNHibernate.Specs/Automapping/PrivateFieldsSpecs.cs index 39b22ed78..b1061fdb7 100644 --- a/src/FluentNHibernate.Specs/Automapping/PrivateFieldsSpecs.cs +++ b/src/FluentNHibernate.Specs/Automapping/PrivateFieldsSpecs.cs @@ -1,38 +1,38 @@ -using System.Linq; -using System.Reflection; -using FluentNHibernate.Automapping; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.MappingModel.Identity; -using FluentNHibernate.Specs.Automapping.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.Automapping; - -public class when_using_the_automapper_to_map_an_entity_that_uses_private_fields_for_storage -{ - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(EntityUsingPrivateFields))) - .Setup(s => s.FindMembers = m => m.IsField && m.IsPrivate); - - Because of = () => - mapping = mapper.BuildMappingFor(); - - It should_find_an_id = () => - mapping.Id.Should().NotBeNull(); - - It should_use_the_correct_field_for_the_id = () => - { - mapping.Id.As().Name.Should().Be("id"); - mapping.Id.As().Member.Should().Be(typeof(EntityUsingPrivateFields).GetField("id", BindingFlags.Instance | BindingFlags.NonPublic).ToMember()); - }; - - It should_ignore_properties = () => - mapping.Properties.Where(x => x.Member.IsProperty).Should().BeEmpty(); - - It should_map_fields = () => - mapping.Properties.Select(x => x.Name).Should().Contain(new string[] { "one", "two", "three" }); - - static AutoPersistenceModel mapper; - static ClassMapping mapping; +using System.Linq; +using System.Reflection; +using FluentNHibernate.Automapping; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.MappingModel.Identity; +using FluentNHibernate.Specs.Automapping.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.Automapping; + +public class when_using_the_automapper_to_map_an_entity_that_uses_private_fields_for_storage +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(EntityUsingPrivateFields))) + .Setup(s => s.FindMembers = m => m.IsField && m.IsPrivate); + + Because of = () => + mapping = mapper.BuildMappingFor(); + + It should_find_an_id = () => + mapping.Id.Should().NotBeNull(); + + It should_use_the_correct_field_for_the_id = () => + { + mapping.Id.As().Name.Should().Be("id"); + mapping.Id.As().Member.Should().Be(typeof(EntityUsingPrivateFields).GetField("id", BindingFlags.Instance | BindingFlags.NonPublic).ToMember()); + }; + + It should_ignore_properties = () => + mapping.Properties.Where(x => x.Member.IsProperty).Should().BeEmpty(); + + It should_map_fields = () => + mapping.Properties.Select(x => x.Name).Should().Contain(new string[] { "one", "two", "three" }); + + static AutoPersistenceModel mapper; + static ClassMapping mapping; } diff --git a/src/FluentNHibernate.Specs/Conventions/ApplyFilterSpecs.cs b/src/FluentNHibernate.Specs/Conventions/ApplyFilterSpecs.cs index f04742593..79742baca 100644 --- a/src/FluentNHibernate.Specs/Conventions/ApplyFilterSpecs.cs +++ b/src/FluentNHibernate.Specs/Conventions/ApplyFilterSpecs.cs @@ -1,92 +1,92 @@ -using System; -using System.Linq; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.MappingModel.Collections; -using FluentNHibernate.Specs.Conventions.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.Conventions; - -public class when_applying_a_filter_to_an_entity_using_conventions -{ - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Conventions.Add(); - model.Add(new FilterTargetMap()); - }; - - Because of = () => - mapping = model.BuildMappingFor(); - - It should_add_a_filter_to_the_entity_s_mapping = () => - mapping.Filters.Should().NotBeEmpty(); - - It should_set_the_name_of_the_added_filter_correctly = () => - mapping.Filters.Single().Name.Should().Be(FilterClassConvention.FilterName); - - It should_set_the_condition_of_the_added_filter_correctly = () => - mapping.Filters.Single().Condition.Should().Be(FilterClassConvention.FilterCondition); - - static FluentNHibernate.PersistenceModel model; - static ClassMapping mapping; -} - -public class when_applying_a_filter_to_a_one_to_many_using_conventions -{ - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Conventions.Add(); - model.Add(new FilterTargetMap()); - model.Add(new FilterChildTargetMap()); - }; - - Because of = () => - { - var classMapping = model.BuildMappingFor(); - mapping = classMapping.Collections.Single(x => x.Relationship is OneToManyMapping); - }; - - It should_add_a_filter_to_the_one_to_many_relationship_s_mapping = () => - mapping.Filters.Should().NotBeEmpty(); - - It should_set_the_name_of_the_added_filter_correctly = () => - mapping.Filters.Single().Name.Should().Be(FilterHasManyConvention.FilterName); - - It should_set_the_condition_of_the_added_filter_correctly = () => - mapping.Filters.Single().Name.Should().Be(FilterHasManyConvention.FilterName); - - static FluentNHibernate.PersistenceModel model; - static CollectionMapping mapping; -} - -public class when_applying_a_filter_to_a_many_to_many_using_conventions -{ - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Conventions.Add(); - model.Add(new FilterTargetMap()); - model.Add(new FilterChildTargetMap()); - }; - - Because of = () => - { - var classMapping = model.BuildMappingFor(); - mapping = classMapping.Collections.Single(x => x.Relationship is ManyToManyMapping); - }; - - It should_add_a_filter_to_the_one_to_many_relationship_s_mapping = () => - mapping.Filters.Should().NotBeEmpty(); - - It should_set_the_name_of_the_added_filter_correctly = () => - mapping.Filters.Single().Name.Should().Be(FilterHasManyConvention.FilterName); - - It should_set_the_condition_of_the_added_filter_correctly = () => - mapping.Filters.Single().Name.Should().Be(FilterHasManyConvention.FilterName); - - static FluentNHibernate.PersistenceModel model; - static CollectionMapping mapping; +using System; +using System.Linq; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.MappingModel.Collections; +using FluentNHibernate.Specs.Conventions.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.Conventions; + +public class when_applying_a_filter_to_an_entity_using_conventions +{ + Establish context = () => + { + model = new FluentNHibernate.PersistenceModel(); + model.Conventions.Add(); + model.Add(new FilterTargetMap()); + }; + + Because of = () => + mapping = model.BuildMappingFor(); + + It should_add_a_filter_to_the_entity_s_mapping = () => + mapping.Filters.Should().NotBeEmpty(); + + It should_set_the_name_of_the_added_filter_correctly = () => + mapping.Filters.Single().Name.Should().Be(FilterClassConvention.FilterName); + + It should_set_the_condition_of_the_added_filter_correctly = () => + mapping.Filters.Single().Condition.Should().Be(FilterClassConvention.FilterCondition); + + static FluentNHibernate.PersistenceModel model; + static ClassMapping mapping; +} + +public class when_applying_a_filter_to_a_one_to_many_using_conventions +{ + Establish context = () => + { + model = new FluentNHibernate.PersistenceModel(); + model.Conventions.Add(); + model.Add(new FilterTargetMap()); + model.Add(new FilterChildTargetMap()); + }; + + Because of = () => + { + var classMapping = model.BuildMappingFor(); + mapping = classMapping.Collections.Single(x => x.Relationship is OneToManyMapping); + }; + + It should_add_a_filter_to_the_one_to_many_relationship_s_mapping = () => + mapping.Filters.Should().NotBeEmpty(); + + It should_set_the_name_of_the_added_filter_correctly = () => + mapping.Filters.Single().Name.Should().Be(FilterHasManyConvention.FilterName); + + It should_set_the_condition_of_the_added_filter_correctly = () => + mapping.Filters.Single().Name.Should().Be(FilterHasManyConvention.FilterName); + + static FluentNHibernate.PersistenceModel model; + static CollectionMapping mapping; +} + +public class when_applying_a_filter_to_a_many_to_many_using_conventions +{ + Establish context = () => + { + model = new FluentNHibernate.PersistenceModel(); + model.Conventions.Add(); + model.Add(new FilterTargetMap()); + model.Add(new FilterChildTargetMap()); + }; + + Because of = () => + { + var classMapping = model.BuildMappingFor(); + mapping = classMapping.Collections.Single(x => x.Relationship is ManyToManyMapping); + }; + + It should_add_a_filter_to_the_one_to_many_relationship_s_mapping = () => + mapping.Filters.Should().NotBeEmpty(); + + It should_set_the_name_of_the_added_filter_correctly = () => + mapping.Filters.Single().Name.Should().Be(FilterHasManyConvention.FilterName); + + It should_set_the_condition_of_the_added_filter_correctly = () => + mapping.Filters.Single().Name.Should().Be(FilterHasManyConvention.FilterName); + + static FluentNHibernate.PersistenceModel model; + static CollectionMapping mapping; } diff --git a/src/FluentNHibernate.Specs/Conventions/BiDirectionalKeysSpecs.cs b/src/FluentNHibernate.Specs/Conventions/BiDirectionalKeysSpecs.cs index 2345627b6..f91a73244 100644 --- a/src/FluentNHibernate.Specs/Conventions/BiDirectionalKeysSpecs.cs +++ b/src/FluentNHibernate.Specs/Conventions/BiDirectionalKeysSpecs.cs @@ -1,36 +1,36 @@ -using System.Linq; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.Conventions.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.Conventions; - -public class when_mapping_a_many_to_one_one_to_many_bi_directional_relationship -{ - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Add(new ParentMap()); - model.Add(new ChildMap()); - }; - - Because of = () => - { - var mappings = model.BuildMappings(); - parent = mappings.SelectMany(x => x.Classes).FirstOrDefault(x => x.Type == typeof(Parent)); - child = mappings.SelectMany(x => x.Classes).FirstOrDefault(x => x.Type == typeof(Child)); - }; - - [Ignore("Ignored due to a regression this code caused - as this feature was added only as an experiment, I doubt anyone will miss it for the time being.")] - It should_use_the_many_to_one_columns_for_the_one_to_many_key = () => - parent.Collections.Single().Key.Columns.Select(x => x.Name).Should().ContainSingle(name => name == "one" || name == "two"); - - [Ignore("Ignored due to a regression this code caused - as this feature was added only as an experiment, I doubt anyone will miss it for the time being.")] - It shouldnt_alter_the_many_to_one_columns = () => - child.References.Single().Columns.Select(x => x.Name).Should().ContainSingle(name => name == "one" || name == "two"); - - static FluentNHibernate.PersistenceModel model; - static ClassMapping parent; - static ClassMapping child; +using System.Linq; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.Conventions.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.Conventions; + +public class when_mapping_a_many_to_one_one_to_many_bi_directional_relationship +{ + Establish context = () => + { + model = new FluentNHibernate.PersistenceModel(); + model.Add(new ParentMap()); + model.Add(new ChildMap()); + }; + + Because of = () => + { + var mappings = model.BuildMappings(); + parent = mappings.SelectMany(x => x.Classes).FirstOrDefault(x => x.Type == typeof(Parent)); + child = mappings.SelectMany(x => x.Classes).FirstOrDefault(x => x.Type == typeof(Child)); + }; + + [Ignore("Ignored due to a regression this code caused - as this feature was added only as an experiment, I doubt anyone will miss it for the time being.")] + It should_use_the_many_to_one_columns_for_the_one_to_many_key = () => + parent.Collections.Single().Key.Columns.Select(x => x.Name).Should().ContainSingle(name => name == "one" || name == "two"); + + [Ignore("Ignored due to a regression this code caused - as this feature was added only as an experiment, I doubt anyone will miss it for the time being.")] + It shouldnt_alter_the_many_to_one_columns = () => + child.References.Single().Columns.Select(x => x.Name).Should().ContainSingle(name => name == "one" || name == "two"); + + static FluentNHibernate.PersistenceModel model; + static ClassMapping parent; + static ClassMapping child; } diff --git a/src/FluentNHibernate.Specs/Conventions/CollectionTypeChangeSpecs.cs b/src/FluentNHibernate.Specs/Conventions/CollectionTypeChangeSpecs.cs index e768390f3..06462b900 100644 --- a/src/FluentNHibernate.Specs/Conventions/CollectionTypeChangeSpecs.cs +++ b/src/FluentNHibernate.Specs/Conventions/CollectionTypeChangeSpecs.cs @@ -1,38 +1,38 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.MappingModel.Collections; -using FluentNHibernate.Specs.Conventions.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.Conventions; - -public class when_changing_the_collection_type_with_conventions -{ - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Conventions.Add(); - model.Add(new CollectionTargetMap()); - model.Add(new CollectionChildTargetMap()); - }; - - Because of = () => - mapping = model.BuildMappingFor(); - - It should_be_able_to_change_a_bag_to_a_list = () => - mapping.Collections - .Single(x => x.Name == "Bag") - .Collection.Should().Be(Collection.List); - - It should_be_able_to_change_a_set_to_a_list = () => - mapping.Collections - .Single(x => x.Name == "Set") - .Collection.Should().Be(Collection.List); - - static FluentNHibernate.PersistenceModel model; - static ClassMapping mapping; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.MappingModel.Collections; +using FluentNHibernate.Specs.Conventions.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.Conventions; + +public class when_changing_the_collection_type_with_conventions +{ + Establish context = () => + { + model = new FluentNHibernate.PersistenceModel(); + model.Conventions.Add(); + model.Add(new CollectionTargetMap()); + model.Add(new CollectionChildTargetMap()); + }; + + Because of = () => + mapping = model.BuildMappingFor(); + + It should_be_able_to_change_a_bag_to_a_list = () => + mapping.Collections + .Single(x => x.Name == "Bag") + .Collection.Should().Be(Collection.List); + + It should_be_able_to_change_a_set_to_a_list = () => + mapping.Collections + .Single(x => x.Name == "Set") + .Collection.Should().Be(Collection.List); + + static FluentNHibernate.PersistenceModel model; + static ClassMapping mapping; } diff --git a/src/FluentNHibernate.Specs/Conventions/ComponentConventionSpecs.cs b/src/FluentNHibernate.Specs/Conventions/ComponentConventionSpecs.cs index fa1d5a29e..6a45da631 100644 --- a/src/FluentNHibernate.Specs/Conventions/ComponentConventionSpecs.cs +++ b/src/FluentNHibernate.Specs/Conventions/ComponentConventionSpecs.cs @@ -1,82 +1,82 @@ -using FluentAssertions; -using FluentNHibernate.Conventions; -using FluentNHibernate.Conventions.Instances; -using FluentNHibernate.Mapping; -using FluentNHibernate.MappingModel.ClassBased; -using Machine.Specifications; -using System.Linq; - -namespace FluentNHibernate.Specs.Conventions; - -public class when_specifying_component_convention -{ - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Conventions.Add(); - model.Add(new AddressMap()); - model.Add(new EntityWithComponentMap()); - }; - - Because of = () => - { - mapping = model.BuildMappingFor(); - }; - - It should_be_able_to_specify_column_name = () => - { - var property = mapping.Components.First() - .Properties.Single(x => x.Name == "Count"); - - property.Columns.FirstOrDefault().Name.Should().Be("different"); - }; - - private static FluentNHibernate.PersistenceModel model; - private static ClassMapping mapping; -} - -public class EntityWithComponent -{ - public int Id { get; set; } - public string Description { get; set; } - public Address Address { get; set; } -} - -public class Address -{ - public int Count { get; set; } - public string Line1 { get; set; } - public string Line2 { get; set; } -} - -internal class AddressMap : ComponentMap
-{ - public AddressMap() - { - Map(x => x.Line1); - Map(x => x.Line2); - Map(x => x.Count); - } -} - -public class ComponentConvention : IComponentConvention -{ - public void Apply(IComponentInstance instance) - { - if (instance.Type == typeof(Address)) - { - var type = instance.Properties.First(p => p.Type == typeof(int)); - type.Column("different"); - } - } -} - -public class EntityWithComponentMap : ClassMap -{ - public EntityWithComponentMap() - { - Id(x => x.Id); - Map(x => x.Description); - Component(x => x.Address); - } +using FluentAssertions; +using FluentNHibernate.Conventions; +using FluentNHibernate.Conventions.Instances; +using FluentNHibernate.Mapping; +using FluentNHibernate.MappingModel.ClassBased; +using Machine.Specifications; +using System.Linq; + +namespace FluentNHibernate.Specs.Conventions; + +public class when_specifying_component_convention +{ + Establish context = () => + { + model = new FluentNHibernate.PersistenceModel(); + model.Conventions.Add(); + model.Add(new AddressMap()); + model.Add(new EntityWithComponentMap()); + }; + + Because of = () => + { + mapping = model.BuildMappingFor(); + }; + + It should_be_able_to_specify_column_name = () => + { + var property = mapping.Components.First() + .Properties.Single(x => x.Name == "Count"); + + property.Columns.FirstOrDefault().Name.Should().Be("different"); + }; + + private static FluentNHibernate.PersistenceModel model; + private static ClassMapping mapping; +} + +public class EntityWithComponent +{ + public int Id { get; set; } + public string Description { get; set; } + public Address Address { get; set; } +} + +public class Address +{ + public int Count { get; set; } + public string Line1 { get; set; } + public string Line2 { get; set; } +} + +internal class AddressMap : ComponentMap
+{ + public AddressMap() + { + Map(x => x.Line1); + Map(x => x.Line2); + Map(x => x.Count); + } +} + +public class ComponentConvention : IComponentConvention +{ + public void Apply(IComponentInstance instance) + { + if (instance.Type == typeof(Address)) + { + var type = instance.Properties.First(p => p.Type == typeof(int)); + type.Column("different"); + } + } +} + +public class EntityWithComponentMap : ClassMap +{ + public EntityWithComponentMap() + { + Id(x => x.Id); + Map(x => x.Description); + Component(x => x.Address); + } } diff --git a/src/FluentNHibernate.Specs/Conventions/ConventionBuilderSpecs.cs b/src/FluentNHibernate.Specs/Conventions/ConventionBuilderSpecs.cs index 4c3b50886..7ad2893c0 100644 --- a/src/FluentNHibernate.Specs/Conventions/ConventionBuilderSpecs.cs +++ b/src/FluentNHibernate.Specs/Conventions/ConventionBuilderSpecs.cs @@ -1,35 +1,35 @@ -using System.Linq; -using FluentNHibernate.Conventions; -using FluentNHibernate.Conventions.Helpers; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.Conventions.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.Conventions; - -public class when_a_convention_builder_is_used_for_properties -{ - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Add(new TwoPropertyEntityMap()); - model.Conventions.Add( - ConventionBuilder.Property.When( - z => z.Expect(c => c.Name == "TargetProperty"), - z => z.CustomSqlType("EXAMPLE"))); - }; - - Because of = () => - mapping = model.BuildMappingFor(); - - It shouldnt_apply_the_convention_to_any_properties_that_dont_match_the_acceptance_criteria = () => - mapping.Properties.Single(x => x.Name == "OtherProperty").Columns.Single().SqlType.Should().NotBe("EXAMPLE"); - - It should_apply_the_convention_to_any_properties_that_match_the_acceptance_criteria = () => - mapping.Properties.Single(x => x.Name == "TargetProperty").Columns.Single().SqlType.Should().Be("EXAMPLE"); - - static IPropertyConvention conventions; - static FluentNHibernate.PersistenceModel model; - static ClassMapping mapping; +using System.Linq; +using FluentNHibernate.Conventions; +using FluentNHibernate.Conventions.Helpers; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.Conventions.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.Conventions; + +public class when_a_convention_builder_is_used_for_properties +{ + Establish context = () => + { + model = new FluentNHibernate.PersistenceModel(); + model.Add(new TwoPropertyEntityMap()); + model.Conventions.Add( + ConventionBuilder.Property.When( + z => z.Expect(c => c.Name == "TargetProperty"), + z => z.CustomSqlType("EXAMPLE"))); + }; + + Because of = () => + mapping = model.BuildMappingFor(); + + It shouldnt_apply_the_convention_to_any_properties_that_dont_match_the_acceptance_criteria = () => + mapping.Properties.Single(x => x.Name == "OtherProperty").Columns.Single().SqlType.Should().NotBe("EXAMPLE"); + + It should_apply_the_convention_to_any_properties_that_match_the_acceptance_criteria = () => + mapping.Properties.Single(x => x.Name == "TargetProperty").Columns.Single().SqlType.Should().Be("EXAMPLE"); + + static IPropertyConvention conventions; + static FluentNHibernate.PersistenceModel model; + static ClassMapping mapping; } diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/Child.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/Child.cs index 74ab45e0f..94415f6f6 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/Child.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/Child.cs @@ -1,19 +1,19 @@ -using FluentNHibernate.Mapping; - -namespace FluentNHibernate.Specs.Conventions.Fixtures; - -public class Child -{ - public int Id { get; set; } - public Parent Parent { get; set; } -} - -public class ChildMap : ClassMap -{ - public ChildMap() - { - Id(x => x.Id); - References(x => x.Parent) - .Columns("one", "two"); - } +using FluentNHibernate.Mapping; + +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class Child +{ + public int Id { get; set; } + public Parent Parent { get; set; } +} + +public class ChildMap : ClassMap +{ + public ChildMap() + { + Id(x => x.Id); + References(x => x.Parent) + .Columns("one", "two"); + } } diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionConvention.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionConvention.cs index 00d932baa..e14bbcf23 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionConvention.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionConvention.cs @@ -1,16 +1,16 @@ -using System; -using FluentNHibernate.Conventions; -using FluentNHibernate.Conventions.Instances; - -namespace FluentNHibernate.Specs.Conventions.Fixtures; - -public class CollectionConvention : ICollectionConvention -{ - public const string FilterName = "TestFilterName"; - public const string FilterCondition = "TestFilterCondition"; - - public void Apply(ICollectionInstance instance) - { - instance.AsList(); - } +using System; +using FluentNHibernate.Conventions; +using FluentNHibernate.Conventions.Instances; + +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class CollectionConvention : ICollectionConvention +{ + public const string FilterName = "TestFilterName"; + public const string FilterCondition = "TestFilterCondition"; + + public void Apply(ICollectionInstance instance) + { + instance.AsList(); + } } diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionTarget.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionTarget.cs index 737fdf777..f20879ad5 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionTarget.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionTarget.cs @@ -1,34 +1,34 @@ -using System.Collections.Generic; -using FluentNHibernate.Mapping; - -namespace FluentNHibernate.Specs.Conventions.Fixtures; - -public class CollectionTarget -{ - public int Id { get; set; } - public IList Bag { get; set; } - public ISet Set { get; set; } -} - -public class CollectionChildTarget -{ - public int Id { get; set; } -} - -public class CollectionTargetMap : ClassMap -{ - public CollectionTargetMap() - { - Id(x => x.Id); - HasMany(x => x.Bag); - HasMany(x => x.Set); - } -} - -public class CollectionChildTargetMap : ClassMap -{ - public CollectionChildTargetMap() - { - Id(x => x.Id); - } +using System.Collections.Generic; +using FluentNHibernate.Mapping; + +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class CollectionTarget +{ + public int Id { get; set; } + public IList Bag { get; set; } + public ISet Set { get; set; } +} + +public class CollectionChildTarget +{ + public int Id { get; set; } +} + +public class CollectionTargetMap : ClassMap +{ + public CollectionTargetMap() + { + Id(x => x.Id); + HasMany(x => x.Bag); + HasMany(x => x.Set); + } +} + +public class CollectionChildTargetMap : ClassMap +{ + public CollectionChildTargetMap() + { + Id(x => x.Id); + } } diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterClassConvention.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterClassConvention.cs index 772f8a847..1970d9ca2 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterClassConvention.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterClassConvention.cs @@ -1,37 +1,37 @@ -using FluentNHibernate.Conventions; -using FluentNHibernate.Conventions.Instances; - -namespace FluentNHibernate.Specs.Conventions.Fixtures; - -public class FilterClassConvention : IClassConvention -{ - public const string FilterName = "TestFilterName"; - public const string FilterCondition = "TestFilterCondition"; - - public void Apply(IClassInstance instance) - { - instance.ApplyFilter(FilterName, FilterCondition); - } -} - -public class FilterHasManyConvention : IHasManyConvention -{ - public const string FilterName = "TestFilterName"; - public const string FilterCondition = "TestFilterCondition"; - - public void Apply(IOneToManyCollectionInstance instance) - { - instance.ApplyFilter(FilterName, FilterCondition); - } -} - -public class FilterHasManyToManyConvention : IHasManyToManyConvention -{ - public const string FilterName = "TestFilterName"; - public const string FilterCondition = "TestFilterCondition"; - - public void Apply(IManyToManyCollectionInstance instance) - { - instance.ApplyFilter(FilterName, FilterCondition); - } +using FluentNHibernate.Conventions; +using FluentNHibernate.Conventions.Instances; + +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class FilterClassConvention : IClassConvention +{ + public const string FilterName = "TestFilterName"; + public const string FilterCondition = "TestFilterCondition"; + + public void Apply(IClassInstance instance) + { + instance.ApplyFilter(FilterName, FilterCondition); + } +} + +public class FilterHasManyConvention : IHasManyConvention +{ + public const string FilterName = "TestFilterName"; + public const string FilterCondition = "TestFilterCondition"; + + public void Apply(IOneToManyCollectionInstance instance) + { + instance.ApplyFilter(FilterName, FilterCondition); + } +} + +public class FilterHasManyToManyConvention : IHasManyToManyConvention +{ + public const string FilterName = "TestFilterName"; + public const string FilterCondition = "TestFilterCondition"; + + public void Apply(IManyToManyCollectionInstance instance) + { + instance.ApplyFilter(FilterName, FilterCondition); + } } diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterTarget.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterTarget.cs index cd3bbdf30..40497db9a 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterTarget.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterTarget.cs @@ -1,34 +1,34 @@ -using System.Collections.Generic; -using FluentNHibernate.Mapping; - -namespace FluentNHibernate.Specs.Conventions.Fixtures; - -public class FilterTarget -{ - public int Id { get; set; } - public IList ChildOneToMany { get; set; } - public IList ChildManyToMany { get; set; } -} - -public class FilterChildTarget -{ - public int Id { get; set; } -} - -public class FilterTargetMap : ClassMap -{ - public FilterTargetMap() - { - Id(x => x.Id); - HasMany(x => x.ChildOneToMany); - HasManyToMany(x => x.ChildManyToMany); - } -} - -public class FilterChildTargetMap : ClassMap -{ - public FilterChildTargetMap() - { - Id(x => x.Id); - } +using System.Collections.Generic; +using FluentNHibernate.Mapping; + +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class FilterTarget +{ + public int Id { get; set; } + public IList ChildOneToMany { get; set; } + public IList ChildManyToMany { get; set; } +} + +public class FilterChildTarget +{ + public int Id { get; set; } +} + +public class FilterTargetMap : ClassMap +{ + public FilterTargetMap() + { + Id(x => x.Id); + HasMany(x => x.ChildOneToMany); + HasManyToMany(x => x.ChildManyToMany); + } +} + +public class FilterChildTargetMap : ClassMap +{ + public FilterChildTargetMap() + { + Id(x => x.Id); + } } diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/FormulaConvention.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/FormulaConvention.cs index d018bff02..0b5f15ad7 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/FormulaConvention.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/FormulaConvention.cs @@ -1,19 +1,19 @@ -using FluentNHibernate.Conventions; -using FluentNHibernate.Conventions.Instances; - -namespace FluentNHibernate.Specs.Conventions.Fixtures; - -public class FormulaConvention : IPropertyConvention, IReferenceConvention -{ - public const string FormulaValue = "select x from y"; - - public void Apply(IPropertyInstance instance) - { - instance.Formula(FormulaValue); - } - - public void Apply(IManyToOneInstance instance) - { - instance.Formula(FormulaValue); - } +using FluentNHibernate.Conventions; +using FluentNHibernate.Conventions.Instances; + +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class FormulaConvention : IPropertyConvention, IReferenceConvention +{ + public const string FormulaValue = "select x from y"; + + public void Apply(IPropertyInstance instance) + { + instance.Formula(FormulaValue); + } + + public void Apply(IManyToOneInstance instance) + { + instance.Formula(FormulaValue); + } } diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/FormulaTarget.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/FormulaTarget.cs index b3fc39222..314c7eac3 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/FormulaTarget.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/FormulaTarget.cs @@ -1,20 +1,20 @@ -using FluentNHibernate.Mapping; - -namespace FluentNHibernate.Specs.Conventions.Fixtures; - -public class FormulaTarget -{ - public int Id { get; private set; } - public string Prop { get; private set; } - public FormulaTarget Target { get; private set; } -} - -public class FormulaTargetMap : ClassMap -{ - public FormulaTargetMap() - { - Id(x => x.Id); - Map(x => x.Prop, "a-column"); - References(x => x.Target); - } +using FluentNHibernate.Mapping; + +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class FormulaTarget +{ + public int Id { get; private set; } + public string Prop { get; private set; } + public FormulaTarget Target { get; private set; } +} + +public class FormulaTargetMap : ClassMap +{ + public FormulaTargetMap() + { + Id(x => x.Id); + Map(x => x.Prop, "a-column"); + References(x => x.Target); + } } diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/Parent.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/Parent.cs index 3b57f079e..d7a4c7c30 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/Parent.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/Parent.cs @@ -1,19 +1,19 @@ -using System.Collections.Generic; -using FluentNHibernate.Mapping; - -namespace FluentNHibernate.Specs.Conventions.Fixtures; - -public class Parent -{ - public int Id { get; set; } - public IList Children { get; set; } -} - -public class ParentMap : ClassMap -{ - public ParentMap() - { - Id(x => x.Id); - HasMany(x => x.Children); - } +using System.Collections.Generic; +using FluentNHibernate.Mapping; + +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class Parent +{ + public int Id { get; set; } + public IList Children { get; set; } +} + +public class ParentMap : ClassMap +{ + public ParentMap() + { + Id(x => x.Id); + HasMany(x => x.Children); + } } diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCollectionEntity.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCollectionEntity.cs index f46f37ebe..7d0d1624c 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCollectionEntity.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCollectionEntity.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; - -namespace FluentNHibernate.Specs.Conventions.Fixtures; - -public class SetCollectionEntity -{ - public int Id { get; set; } - public ISet Children { get; set; } +using System.Collections.Generic; + +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class SetCollectionEntity +{ + public int Id { get; set; } + public ISet Children { get; set; } } diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCollectionEntityMap.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCollectionEntityMap.cs index b8778533e..a20dfbdd5 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCollectionEntityMap.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCollectionEntityMap.cs @@ -1,12 +1,12 @@ -using FluentNHibernate.Mapping; - -namespace FluentNHibernate.Specs.Conventions.Fixtures; - -public class SetCollectionEntityMap : ClassMap -{ - public SetCollectionEntityMap() - { - Id(x => x.Id); - HasMany(x => x.Children); - } +using FluentNHibernate.Mapping; + +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class SetCollectionEntityMap : ClassMap +{ + public SetCollectionEntityMap() + { + Id(x => x.Id); + HasMany(x => x.Children); + } } diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCompositeElementCollectionEntity.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCompositeElementCollectionEntity.cs index c4c546d7b..a4b0eaf29 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCompositeElementCollectionEntity.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCompositeElementCollectionEntity.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; - -namespace FluentNHibernate.Specs.Conventions.Fixtures; - -public class SetCompositeElementCollectionEntity -{ - public int Id { get; set; } - public ISet Values { get; set; } +using System.Collections.Generic; + +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class SetCompositeElementCollectionEntity +{ + public int Id { get; set; } + public ISet Values { get; set; } } diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCompositeElementCollectionEntityMap.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCompositeElementCollectionEntityMap.cs index a5631add8..f5f9e2cf1 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCompositeElementCollectionEntityMap.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCompositeElementCollectionEntityMap.cs @@ -1,13 +1,13 @@ -using FluentNHibernate.Mapping; - -namespace FluentNHibernate.Specs.Conventions.Fixtures; - -public class SetCompositeElementCollectionEntityMap : ClassMap -{ - public SetCompositeElementCollectionEntityMap() - { - Id(x => x.Id); - HasMany(x => x.Values) - .Component(c => c.Map(x => x.Property)); - } +using FluentNHibernate.Mapping; + +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class SetCompositeElementCollectionEntityMap : ClassMap +{ + public SetCompositeElementCollectionEntityMap() + { + Id(x => x.Id); + HasMany(x => x.Values) + .Component(c => c.Map(x => x.Property)); + } } diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetElementCollectionEntity.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetElementCollectionEntity.cs index 8ae8cda4a..46f0f0bb8 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetElementCollectionEntity.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetElementCollectionEntity.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; - -namespace FluentNHibernate.Specs.Conventions.Fixtures; - -public class SetElementCollectionEntity -{ - public int Id { get; set; } - public ISet Strings { get; set; } +using System.Collections.Generic; + +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class SetElementCollectionEntity +{ + public int Id { get; set; } + public ISet Strings { get; set; } } diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetElementCollectionEntityMap.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetElementCollectionEntityMap.cs index fbae68ef9..f304b777f 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetElementCollectionEntityMap.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetElementCollectionEntityMap.cs @@ -1,13 +1,13 @@ -using FluentNHibernate.Mapping; - -namespace FluentNHibernate.Specs.Conventions.Fixtures; - -public class SetElementCollectionEntityMap : ClassMap -{ - public SetElementCollectionEntityMap() - { - Id(x => x.Id); - HasMany(x => x.Strings) - .Element("Value"); - } +using FluentNHibernate.Mapping; + +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class SetElementCollectionEntityMap : ClassMap +{ + public SetElementCollectionEntityMap() + { + Id(x => x.Id); + HasMany(x => x.Strings) + .Element("Value"); + } } diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/TwoPropertyEntity.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/TwoPropertyEntity.cs index 927788c5a..f19bf6546 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/TwoPropertyEntity.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/TwoPropertyEntity.cs @@ -1,8 +1,8 @@ -namespace FluentNHibernate.Specs.Conventions.Fixtures; - -class TwoPropertyEntity -{ - public int Id { get; set; } - public string TargetProperty { get; set; } - public string OtherProperty { get; set; } +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +class TwoPropertyEntity +{ + public int Id { get; set; } + public string TargetProperty { get; set; } + public string OtherProperty { get; set; } } diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/TwoPropertyEntityMap.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/TwoPropertyEntityMap.cs index 92c117ec8..c643ef3f9 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/TwoPropertyEntityMap.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/TwoPropertyEntityMap.cs @@ -1,13 +1,13 @@ -using FluentNHibernate.Mapping; - -namespace FluentNHibernate.Specs.Conventions.Fixtures; - -class TwoPropertyEntityMap : ClassMap -{ - public TwoPropertyEntityMap() - { - Id(x => x.Id); - Map(x => x.TargetProperty); - Map(x => x.OtherProperty); - } +using FluentNHibernate.Mapping; + +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +class TwoPropertyEntityMap : ClassMap +{ + public TwoPropertyEntityMap() + { + Id(x => x.Id); + Map(x => x.TargetProperty); + Map(x => x.OtherProperty); + } } diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/Value.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/Value.cs index 64dd1e713..ffdc78c3f 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/Value.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/Value.cs @@ -1,6 +1,6 @@ -namespace FluentNHibernate.Specs.Conventions.Fixtures; - -public class Value -{ - public string Property { get; set; } +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class Value +{ + public string Property { get; set; } } diff --git a/src/FluentNHibernate.Specs/Conventions/ForeignKeyConventionSpecs.cs b/src/FluentNHibernate.Specs/Conventions/ForeignKeyConventionSpecs.cs index 5e55a2a6e..ded805c74 100644 --- a/src/FluentNHibernate.Specs/Conventions/ForeignKeyConventionSpecs.cs +++ b/src/FluentNHibernate.Specs/Conventions/ForeignKeyConventionSpecs.cs @@ -1,65 +1,65 @@ -using System; -using System.Linq; -using FluentNHibernate.Conventions; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.Conventions.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.Conventions; - -public abstract class ForeignKeyConventionSpec -{ - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Conventions.Add(new TestForeignKeyConvention()); - }; - - protected static FluentNHibernate.PersistenceModel model; - protected static ClassMapping mapping; - - class TestForeignKeyConvention : ForeignKeyConvention - { - protected override string GetKeyName(Member property, Type type) - { - return "KEY_NAME"; - } - } -} - -public class when_a_foreign_key_convention_is_being_applied_to_a_set_mapping : ForeignKeyConventionSpec -{ - Establish context = () => - model.Add(new SetCollectionEntityMap()); - - Because of = () => - mapping = model.BuildMappingFor(); - - It should_override_the_key_column_name = () => - mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("KEY_NAME"); -} - -public class when_a_foreign_key_convention_is_being_applied_to_a_set_mapping_with_an_element : ForeignKeyConventionSpec -{ - Establish context = () => - model.Add(new SetElementCollectionEntityMap()); - - Because of = () => - mapping = model.BuildMappingFor(); - - It should_override_the_key_column_name = () => - mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("KEY_NAME"); -} - -public class when_a_foreign_key_convention_is_being_applied_to_a_set_mapping_with_a_composite_element : ForeignKeyConventionSpec -{ - Establish context = () => - model.Add(new SetCompositeElementCollectionEntityMap()); - - Because of = () => - mapping = model.BuildMappingFor(); - - It should_override_the_key_column_name = () => - mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("KEY_NAME"); +using System; +using System.Linq; +using FluentNHibernate.Conventions; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.Conventions.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.Conventions; + +public abstract class ForeignKeyConventionSpec +{ + Establish context = () => + { + model = new FluentNHibernate.PersistenceModel(); + model.Conventions.Add(new TestForeignKeyConvention()); + }; + + protected static FluentNHibernate.PersistenceModel model; + protected static ClassMapping mapping; + + class TestForeignKeyConvention : ForeignKeyConvention + { + protected override string GetKeyName(Member property, Type type) + { + return "KEY_NAME"; + } + } +} + +public class when_a_foreign_key_convention_is_being_applied_to_a_set_mapping : ForeignKeyConventionSpec +{ + Establish context = () => + model.Add(new SetCollectionEntityMap()); + + Because of = () => + mapping = model.BuildMappingFor(); + + It should_override_the_key_column_name = () => + mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("KEY_NAME"); +} + +public class when_a_foreign_key_convention_is_being_applied_to_a_set_mapping_with_an_element : ForeignKeyConventionSpec +{ + Establish context = () => + model.Add(new SetElementCollectionEntityMap()); + + Because of = () => + mapping = model.BuildMappingFor(); + + It should_override_the_key_column_name = () => + mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("KEY_NAME"); +} + +public class when_a_foreign_key_convention_is_being_applied_to_a_set_mapping_with_a_composite_element : ForeignKeyConventionSpec +{ + Establish context = () => + model.Add(new SetCompositeElementCollectionEntityMap()); + + Because of = () => + mapping = model.BuildMappingFor(); + + It should_override_the_key_column_name = () => + mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("KEY_NAME"); } diff --git a/src/FluentNHibernate.Specs/Conventions/FormulaConventionSpecs.cs b/src/FluentNHibernate.Specs/Conventions/FormulaConventionSpecs.cs index 2bdc469fd..94d7efad7 100644 --- a/src/FluentNHibernate.Specs/Conventions/FormulaConventionSpecs.cs +++ b/src/FluentNHibernate.Specs/Conventions/FormulaConventionSpecs.cs @@ -1,54 +1,54 @@ -using System.Linq; -using FluentNHibernate.Conventions; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.Conventions.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.Conventions; - -[Subject(typeof(IPropertyConvention))] -public class when_a_formula_is_added_to_a_property -{ - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Conventions.Add(); - model.Add(new FormulaTargetMap()); - }; - - Because of = () => - mapping = model.BuildMappingFor(); - - It should_remove_all_columns_from_the_property = () => - mapping.Properties.Single().Columns.Should().BeEmpty(); - - It should_add_the_formula_to_the_property = () => - mapping.Properties.Single().Formula.Should().Be(FormulaConvention.FormulaValue); - - static FluentNHibernate.PersistenceModel model; - static ClassMapping mapping; -} - -[Subject(typeof(IReferenceConvention))] -public class when_a_formula_is_added_to_a_reference -{ - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Conventions.Add(); - model.Add(new FormulaTargetMap()); - }; - - Because of = () => - mapping = model.BuildMappingFor(); - - It should_remove_all_columns_from_the_property = () => - mapping.References.Single().Columns.Should().BeEmpty(); - - It should_add_the_formula_to_the_property = () => - mapping.References.Single().Formula.Should().Be(FormulaConvention.FormulaValue); - - static FluentNHibernate.PersistenceModel model; - static ClassMapping mapping; +using System.Linq; +using FluentNHibernate.Conventions; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.Conventions.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.Conventions; + +[Subject(typeof(IPropertyConvention))] +public class when_a_formula_is_added_to_a_property +{ + Establish context = () => + { + model = new FluentNHibernate.PersistenceModel(); + model.Conventions.Add(); + model.Add(new FormulaTargetMap()); + }; + + Because of = () => + mapping = model.BuildMappingFor(); + + It should_remove_all_columns_from_the_property = () => + mapping.Properties.Single().Columns.Should().BeEmpty(); + + It should_add_the_formula_to_the_property = () => + mapping.Properties.Single().Formula.Should().Be(FormulaConvention.FormulaValue); + + static FluentNHibernate.PersistenceModel model; + static ClassMapping mapping; +} + +[Subject(typeof(IReferenceConvention))] +public class when_a_formula_is_added_to_a_reference +{ + Establish context = () => + { + model = new FluentNHibernate.PersistenceModel(); + model.Conventions.Add(); + model.Add(new FormulaTargetMap()); + }; + + Because of = () => + mapping = model.BuildMappingFor(); + + It should_remove_all_columns_from_the_property = () => + mapping.References.Single().Columns.Should().BeEmpty(); + + It should_add_the_formula_to_the_property = () => + mapping.References.Single().Formula.Should().Be(FormulaConvention.FormulaValue); + + static FluentNHibernate.PersistenceModel model; + static ClassMapping mapping; } diff --git a/src/FluentNHibernate.Specs/Diagnostics/Registration_diagnostics_specs.cs b/src/FluentNHibernate.Specs/Diagnostics/Registration_diagnostics_specs.cs index f27cb8d8b..ebdffc475 100644 --- a/src/FluentNHibernate.Specs/Diagnostics/Registration_diagnostics_specs.cs +++ b/src/FluentNHibernate.Specs/Diagnostics/Registration_diagnostics_specs.cs @@ -1,401 +1,401 @@ -using System; -using System.Linq; -using FluentNHibernate.Automapping; -using FluentNHibernate.Conventions; -using FluentNHibernate.Diagnostics; -using FluentNHibernate.Mapping; -using FluentNHibernate.Specs.Automapping.Fixtures; -using FluentNHibernate.Specs.ExternalFixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.Diagnostics; - -public class when_registering_types_with_diagnostics_enabled -{ - Establish context = () => - { - var dispatcher = new DefaultDiagnosticMessageDispatcher(); - dispatcher.RegisterListener(new StubListener(x => results = x)); - - model = new FluentNHibernate.PersistenceModel(); - model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); - }; - - Because of = () => - { - model.AddMappingsFromSource(new StubTypeSource(typeof(First), typeof(FirstMap), typeof(SecondMap), typeof(ChildMap), typeof(CompMap))); - model.BuildMappings(); - }; - - It should_produce_results_when_enabled = () => - results.Should().NotBeNull(); - - It should_register_each_ClassMap_type_and_return_them_in_the_results = () => - results.FluentMappings.Should().Contain(new Type[] { typeof(FirstMap), typeof(SecondMap) }); - - It should_register_each_SubclassMap_type_and_return_them_in_the_results = () => - results.FluentMappings.Should().Contain(typeof(ChildMap)); - - It should_register_each_ComponentMap_type_and_return_them_in_the_results = () => - results.FluentMappings.Should().Contain(typeof(CompMap)); - - It should_return_the_source_in_the_results = () => - results.ScannedSources - .Where(x => x.Phase == ScanPhase.FluentMappings) - .Select(x => x.Identifier) - .Should().ContainSingle(identifier => identifier == "StubTypeSource"); - - It should_not_register_non_fluent_mapping_types = () => - results.FluentMappings.Should().NotContain(typeof(First)); - - static FluentNHibernate.PersistenceModel model; - static DiagnosticResults results; -} - -public class when_registering_conventions_with_diagnostics_enabled -{ - Establish context = () => - { - var dispatcher = new DefaultDiagnosticMessageDispatcher(); - dispatcher.RegisterListener(new StubListener(x => results = x)); - - model = new FluentNHibernate.PersistenceModel(); - model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); - }; - - Because of = () => - { - model.Conventions.AddSource(new StubTypeSource(typeof(ConventionA), typeof(ConventionB), typeof(NotAConvention))); - model.BuildMappings(); - }; - - It should_produce_results_when_enabled = () => - results.Should().NotBeNull(); - - It should_register_each_convention_type_and_return_them_in_the_results = () => - results.Conventions.Should().Contain(new Type[] { typeof(ConventionA), typeof(ConventionB) }); - - It should_return_the_source_in_the_results = () => - results.ScannedSources - .Where(x => x.Phase == ScanPhase.Conventions) - .Select(x => x.Identifier) - .Should().ContainSingle(identifier => identifier == "StubTypeSource"); - - It should_not_register_non_convention_types = () => - results.Conventions.Should().NotContain(typeof(NotAConvention)); - - static FluentNHibernate.PersistenceModel model; - static DiagnosticResults results; -} - -public class when_automapping_with_diagnostics_enabled -{ - Establish context = () => - { - var dispatcher = new DefaultDiagnosticMessageDispatcher(); - dispatcher.RegisterListener(new StubListener(x => results = x)); - - model = AutoMap.Source(new StubTypeSource(typeof(First), typeof(Second), typeof(Third)), new TestAutomappingConfiguration()); - - model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); - }; - - Because of = () => - model.BuildMappings(); - - It should_produce_results_when_enabled = () => - results.Should().NotBeNull(); - - It should_include_a_skipped_entry_for_each_skipped_type = () => - results.AutomappingSkippedTypes.Select(x => x.Type).Should().Contain(typeof(First)); - - It should_have_a_reason_of_skipped_by_configuration_for_each_skipped_type = () => - results.AutomappingSkippedTypes.Select(x => x.Reason).Should().Contain("Skipped by result of IAutomappingConfiguration.ShouldMap(Type)"); - - It should_not_include_a_skipped_entry_for_used_types = () => - results.AutomappingSkippedTypes.Select(x => x.Type).Should().NotContain(new Type[] { typeof(Second), typeof(Third) }); - - It should_include_all_unskipped_types_in_the_candidate_list = () => - results.AutomappingCandidateTypes.Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); - - It should_include_all_unskipped_types_in_the_automapped_list = () => - results.AutomappedTypes.Select(x => x.Type).Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); - - static AutoPersistenceModel model; - static DiagnosticResults results; - - class TestAutomappingConfiguration : DefaultAutomappingConfiguration - { - public override bool ShouldMap(Type type) - { - return type != typeof(First); - } - } -} - -public class when_automapping_with_diagnostics_enabled_and_excluding_by_where -{ - Establish context = () => - { - var dispatcher = new DefaultDiagnosticMessageDispatcher(); - dispatcher.RegisterListener(new StubListener(x => results = x)); - - model = AutoMap.Source(new StubTypeSource(typeof(First), typeof(Second), typeof(Third))) - .Where(x => x != typeof(First)); - - model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); - }; - - Because of = () => - model.BuildMappings(); - - It should_produce_results_when_enabled = () => - results.Should().NotBeNull(); - - It should_include_a_skipped_entry_for_each_skipped_type = () => - results.AutomappingSkippedTypes.Select(x => x.Type).Should().Contain(typeof(First)); - - It should_have_a_reason_of_skipped_by_explicit_where_for_each_skipped_type = () => - results.AutomappingSkippedTypes.Select(x => x.Reason).Should().Contain("Skipped by Where clause"); - - It should_not_include_a_skipped_entry_for_used_types = () => - results.AutomappingSkippedTypes.Select(x => x.Type).Should().NotContain(new Type[] { typeof(Second), typeof(Third) }); - - It should_include_all_unskipped_types_in_the_candidate_list = () => - results.AutomappingCandidateTypes.Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); - - It should_include_all_unskipped_types_in_the_automapped_list = () => - results.AutomappedTypes.Select(x => x.Type).Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); - - static AutoPersistenceModel model; - static DiagnosticResults results; -} - -public class when_automapping_with_diagnostics_enabled_and_excluding_by_IgnoreBase -{ - Establish context = () => - { - var dispatcher = new DefaultDiagnosticMessageDispatcher(); - dispatcher.RegisterListener(new StubListener(x => results = x)); - - model = AutoMap.Source(new StubTypeSource(typeof(First), typeof(Second), typeof(Third))) - .IgnoreBase(); - - model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); - }; - - Because of = () => - model.BuildMappings(); - - It should_produce_results_when_enabled = () => - results.Should().NotBeNull(); - - It should_include_a_skipped_entry_for_each_skipped_type = () => - results.AutomappingSkippedTypes.Select(x => x.Type).Should().Contain(typeof(First)); - - It should_have_a_reason_of_skipped_by_IgnoreBase_for_each_skipped_type = () => - results.AutomappingSkippedTypes.Select(x => x.Reason).Should().Contain("Skipped by IgnoreBase"); - - It should_not_include_a_skipped_entry_for_used_types = () => - results.AutomappingSkippedTypes.Select(x => x.Type).Should().NotContain(new Type[] { typeof(Second), typeof(Third) }); - - It should_include_all_unskipped_types_in_the_candidate_list = () => - results.AutomappingCandidateTypes.Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); - - It should_include_all_unskipped_types_in_the_automapped_list = () => - results.AutomappedTypes.Select(x => x.Type).Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); - - static AutoPersistenceModel model; - static DiagnosticResults results; -} - -public class when_automapping_with_diagnostics_enabled_and_excluding_by_generic_IgnoreBase -{ - Establish context = () => - { - var dispatcher = new DefaultDiagnosticMessageDispatcher(); - dispatcher.RegisterListener(new StubListener(x => results = x)); - - model = AutoMap.Source(new StubTypeSource(typeof(Something), typeof(Second), typeof(Third))) - .IgnoreBase(typeof(Something<>)); - - model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); - }; - - Because of = () => - model.BuildMappings(); - - It should_produce_results_when_enabled = () => - results.Should().NotBeNull(); - - It should_include_a_skipped_entry_for_each_skipped_type = () => - results.AutomappingSkippedTypes.Select(x => x.Type).Should().Contain(typeof(Something)); - - It should_have_a_reason_of_skipped_by_IgnoreBase_for_each_skipped_type = () => - results.AutomappingSkippedTypes.Select(x => x.Reason).Should().Contain("Skipped by IgnoreBase"); - - It should_not_include_a_skipped_entry_for_used_types = () => - results.AutomappingSkippedTypes.Select(x => x.Type).Should().NotContain(new Type[] { typeof(Second), typeof(Third) }); - - It should_include_all_unskipped_types_in_the_candidate_list = () => - results.AutomappingCandidateTypes.Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); - - It should_include_all_unskipped_types_in_the_automapped_list = () => - results.AutomappedTypes.Select(x => x.Type).Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); - - static AutoPersistenceModel model; - static DiagnosticResults results; -} - -public class when_automapping_with_diagnostics_enabled_and_excluding_by_layer_supertype -{ - Establish context = () => - { - var dispatcher = new DefaultDiagnosticMessageDispatcher(); - dispatcher.RegisterListener(new StubListener(x => results = x)); - - model = AutoMap.Source(new StubTypeSource(typeof(Abstract), typeof(Second), typeof(Third)), new TestAutomappingConfiguration()); - - model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); - }; - - Because of = () => - model.BuildMappings(); - - It should_produce_results_when_enabled = () => - results.Should().NotBeNull(); - - It should_include_a_skipped_entry_for_each_skipped_type = () => - results.AutomappingSkippedTypes.Select(x => x.Type).Should().Contain(typeof(Abstract)); - - It should_have_a_reason_of_skipped_by_IgnoreBase_for_each_skipped_type = () => - results.AutomappingSkippedTypes.Select(x => x.Reason).Should().Contain("Skipped by IAutomappingConfiguration.AbstractClassIsLayerSupertype(Type)"); - - It should_not_include_a_skipped_entry_for_used_types = () => - results.AutomappingSkippedTypes.Select(x => x.Type).Should().NotContain(new Type[] { typeof(Second), typeof(Third) }); - - It should_include_all_unskipped_types_in_the_candidate_list = () => - results.AutomappingCandidateTypes.Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); - - It should_include_all_unskipped_types_in_the_automapped_list = () => - results.AutomappedTypes.Select(x => x.Type).Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); - - static AutoPersistenceModel model; - static DiagnosticResults results; - - class TestAutomappingConfiguration : DefaultAutomappingConfiguration - { - public override bool AbstractClassIsLayerSupertype(Type type) - { - return type == typeof(Abstract); - } - } -} - -public class when_automapping_with_diagnostics_enabled_and_excluding_by_explicit_component -{ - Establish context = () => - { - var dispatcher = new DefaultDiagnosticMessageDispatcher(); - dispatcher.RegisterListener(new StubListener(x => results = x)); - - model = AutoMap.Source(new StubTypeSource(typeof(Component), typeof(Second), typeof(Third)), new TestAutomappingConfiguration()); - - model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); - }; - - Because of = () => - model.BuildMappings(); - - It should_produce_results_when_enabled = () => - results.Should().NotBeNull(); - - It should_include_a_skipped_entry_for_each_skipped_type = () => - results.AutomappingSkippedTypes.Select(x => x.Type).Should().Contain(typeof(Component)); - - It should_have_a_reason_of_skipped_by_IgnoreBase_for_each_skipped_type = () => - results.AutomappingSkippedTypes.Select(x => x.Reason).Should().Contain("Skipped by IAutomappingConfiguration.IsComponent(Type)"); - - It should_not_include_a_skipped_entry_for_used_types = () => - results.AutomappingSkippedTypes.Select(x => x.Type).Should().NotContain(new Type[] { typeof(Second), typeof(Third) } ); - - It should_include_all_unskipped_types_in_the_candidate_list = () => - results.AutomappingCandidateTypes.Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); - - It should_include_all_unskipped_types_in_the_automapped_list = () => - results.AutomappedTypes.Select(x => x.Type).Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); - - static AutoPersistenceModel model; - static DiagnosticResults results; - - class TestAutomappingConfiguration : DefaultAutomappingConfiguration - { - public override bool IsComponent(Type type) - { - return type == typeof(Component); - } - } -} - -abstract class Abstract -{} - -class FirstMap : ClassMap -{ - public FirstMap() - { - Id(x => x.Id); - } -} - -class First -{ - public int Id { get; set; } -} - -class Something -{} - -class SecondMap : ClassMap -{ - public SecondMap() - { - Id(x => x.Id); - } -} - -class Second -{ - public int Id { get; set; } -} - -class Third -{ - public int Id { get; set; } -} - -class ChildMap : SubclassMap {} - -class Child : Second {} - -class CompMap : ComponentMap {} -class Comp {} -class ConventionA : IConvention {} -class ConventionB : IConvention {} -class NotAConvention {} - -class StubListener : IDiagnosticListener -{ - readonly Action receiver; - - public StubListener(Action receiver) - { - this.receiver = receiver; - } - - public void Receive(DiagnosticResults results) - { - receiver(results); - } +using System; +using System.Linq; +using FluentNHibernate.Automapping; +using FluentNHibernate.Conventions; +using FluentNHibernate.Diagnostics; +using FluentNHibernate.Mapping; +using FluentNHibernate.Specs.Automapping.Fixtures; +using FluentNHibernate.Specs.ExternalFixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.Diagnostics; + +public class when_registering_types_with_diagnostics_enabled +{ + Establish context = () => + { + var dispatcher = new DefaultDiagnosticMessageDispatcher(); + dispatcher.RegisterListener(new StubListener(x => results = x)); + + model = new FluentNHibernate.PersistenceModel(); + model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); + }; + + Because of = () => + { + model.AddMappingsFromSource(new StubTypeSource(typeof(First), typeof(FirstMap), typeof(SecondMap), typeof(ChildMap), typeof(CompMap))); + model.BuildMappings(); + }; + + It should_produce_results_when_enabled = () => + results.Should().NotBeNull(); + + It should_register_each_ClassMap_type_and_return_them_in_the_results = () => + results.FluentMappings.Should().Contain(new Type[] { typeof(FirstMap), typeof(SecondMap) }); + + It should_register_each_SubclassMap_type_and_return_them_in_the_results = () => + results.FluentMappings.Should().Contain(typeof(ChildMap)); + + It should_register_each_ComponentMap_type_and_return_them_in_the_results = () => + results.FluentMappings.Should().Contain(typeof(CompMap)); + + It should_return_the_source_in_the_results = () => + results.ScannedSources + .Where(x => x.Phase == ScanPhase.FluentMappings) + .Select(x => x.Identifier) + .Should().ContainSingle(identifier => identifier == "StubTypeSource"); + + It should_not_register_non_fluent_mapping_types = () => + results.FluentMappings.Should().NotContain(typeof(First)); + + static FluentNHibernate.PersistenceModel model; + static DiagnosticResults results; +} + +public class when_registering_conventions_with_diagnostics_enabled +{ + Establish context = () => + { + var dispatcher = new DefaultDiagnosticMessageDispatcher(); + dispatcher.RegisterListener(new StubListener(x => results = x)); + + model = new FluentNHibernate.PersistenceModel(); + model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); + }; + + Because of = () => + { + model.Conventions.AddSource(new StubTypeSource(typeof(ConventionA), typeof(ConventionB), typeof(NotAConvention))); + model.BuildMappings(); + }; + + It should_produce_results_when_enabled = () => + results.Should().NotBeNull(); + + It should_register_each_convention_type_and_return_them_in_the_results = () => + results.Conventions.Should().Contain(new Type[] { typeof(ConventionA), typeof(ConventionB) }); + + It should_return_the_source_in_the_results = () => + results.ScannedSources + .Where(x => x.Phase == ScanPhase.Conventions) + .Select(x => x.Identifier) + .Should().ContainSingle(identifier => identifier == "StubTypeSource"); + + It should_not_register_non_convention_types = () => + results.Conventions.Should().NotContain(typeof(NotAConvention)); + + static FluentNHibernate.PersistenceModel model; + static DiagnosticResults results; +} + +public class when_automapping_with_diagnostics_enabled +{ + Establish context = () => + { + var dispatcher = new DefaultDiagnosticMessageDispatcher(); + dispatcher.RegisterListener(new StubListener(x => results = x)); + + model = AutoMap.Source(new StubTypeSource(typeof(First), typeof(Second), typeof(Third)), new TestAutomappingConfiguration()); + + model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); + }; + + Because of = () => + model.BuildMappings(); + + It should_produce_results_when_enabled = () => + results.Should().NotBeNull(); + + It should_include_a_skipped_entry_for_each_skipped_type = () => + results.AutomappingSkippedTypes.Select(x => x.Type).Should().Contain(typeof(First)); + + It should_have_a_reason_of_skipped_by_configuration_for_each_skipped_type = () => + results.AutomappingSkippedTypes.Select(x => x.Reason).Should().Contain("Skipped by result of IAutomappingConfiguration.ShouldMap(Type)"); + + It should_not_include_a_skipped_entry_for_used_types = () => + results.AutomappingSkippedTypes.Select(x => x.Type).Should().NotContain(new Type[] { typeof(Second), typeof(Third) }); + + It should_include_all_unskipped_types_in_the_candidate_list = () => + results.AutomappingCandidateTypes.Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); + + It should_include_all_unskipped_types_in_the_automapped_list = () => + results.AutomappedTypes.Select(x => x.Type).Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); + + static AutoPersistenceModel model; + static DiagnosticResults results; + + class TestAutomappingConfiguration : DefaultAutomappingConfiguration + { + public override bool ShouldMap(Type type) + { + return type != typeof(First); + } + } +} + +public class when_automapping_with_diagnostics_enabled_and_excluding_by_where +{ + Establish context = () => + { + var dispatcher = new DefaultDiagnosticMessageDispatcher(); + dispatcher.RegisterListener(new StubListener(x => results = x)); + + model = AutoMap.Source(new StubTypeSource(typeof(First), typeof(Second), typeof(Third))) + .Where(x => x != typeof(First)); + + model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); + }; + + Because of = () => + model.BuildMappings(); + + It should_produce_results_when_enabled = () => + results.Should().NotBeNull(); + + It should_include_a_skipped_entry_for_each_skipped_type = () => + results.AutomappingSkippedTypes.Select(x => x.Type).Should().Contain(typeof(First)); + + It should_have_a_reason_of_skipped_by_explicit_where_for_each_skipped_type = () => + results.AutomappingSkippedTypes.Select(x => x.Reason).Should().Contain("Skipped by Where clause"); + + It should_not_include_a_skipped_entry_for_used_types = () => + results.AutomappingSkippedTypes.Select(x => x.Type).Should().NotContain(new Type[] { typeof(Second), typeof(Third) }); + + It should_include_all_unskipped_types_in_the_candidate_list = () => + results.AutomappingCandidateTypes.Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); + + It should_include_all_unskipped_types_in_the_automapped_list = () => + results.AutomappedTypes.Select(x => x.Type).Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); + + static AutoPersistenceModel model; + static DiagnosticResults results; +} + +public class when_automapping_with_diagnostics_enabled_and_excluding_by_IgnoreBase +{ + Establish context = () => + { + var dispatcher = new DefaultDiagnosticMessageDispatcher(); + dispatcher.RegisterListener(new StubListener(x => results = x)); + + model = AutoMap.Source(new StubTypeSource(typeof(First), typeof(Second), typeof(Third))) + .IgnoreBase(); + + model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); + }; + + Because of = () => + model.BuildMappings(); + + It should_produce_results_when_enabled = () => + results.Should().NotBeNull(); + + It should_include_a_skipped_entry_for_each_skipped_type = () => + results.AutomappingSkippedTypes.Select(x => x.Type).Should().Contain(typeof(First)); + + It should_have_a_reason_of_skipped_by_IgnoreBase_for_each_skipped_type = () => + results.AutomappingSkippedTypes.Select(x => x.Reason).Should().Contain("Skipped by IgnoreBase"); + + It should_not_include_a_skipped_entry_for_used_types = () => + results.AutomappingSkippedTypes.Select(x => x.Type).Should().NotContain(new Type[] { typeof(Second), typeof(Third) }); + + It should_include_all_unskipped_types_in_the_candidate_list = () => + results.AutomappingCandidateTypes.Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); + + It should_include_all_unskipped_types_in_the_automapped_list = () => + results.AutomappedTypes.Select(x => x.Type).Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); + + static AutoPersistenceModel model; + static DiagnosticResults results; +} + +public class when_automapping_with_diagnostics_enabled_and_excluding_by_generic_IgnoreBase +{ + Establish context = () => + { + var dispatcher = new DefaultDiagnosticMessageDispatcher(); + dispatcher.RegisterListener(new StubListener(x => results = x)); + + model = AutoMap.Source(new StubTypeSource(typeof(Something), typeof(Second), typeof(Third))) + .IgnoreBase(typeof(Something<>)); + + model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); + }; + + Because of = () => + model.BuildMappings(); + + It should_produce_results_when_enabled = () => + results.Should().NotBeNull(); + + It should_include_a_skipped_entry_for_each_skipped_type = () => + results.AutomappingSkippedTypes.Select(x => x.Type).Should().Contain(typeof(Something)); + + It should_have_a_reason_of_skipped_by_IgnoreBase_for_each_skipped_type = () => + results.AutomappingSkippedTypes.Select(x => x.Reason).Should().Contain("Skipped by IgnoreBase"); + + It should_not_include_a_skipped_entry_for_used_types = () => + results.AutomappingSkippedTypes.Select(x => x.Type).Should().NotContain(new Type[] { typeof(Second), typeof(Third) }); + + It should_include_all_unskipped_types_in_the_candidate_list = () => + results.AutomappingCandidateTypes.Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); + + It should_include_all_unskipped_types_in_the_automapped_list = () => + results.AutomappedTypes.Select(x => x.Type).Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); + + static AutoPersistenceModel model; + static DiagnosticResults results; +} + +public class when_automapping_with_diagnostics_enabled_and_excluding_by_layer_supertype +{ + Establish context = () => + { + var dispatcher = new DefaultDiagnosticMessageDispatcher(); + dispatcher.RegisterListener(new StubListener(x => results = x)); + + model = AutoMap.Source(new StubTypeSource(typeof(Abstract), typeof(Second), typeof(Third)), new TestAutomappingConfiguration()); + + model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); + }; + + Because of = () => + model.BuildMappings(); + + It should_produce_results_when_enabled = () => + results.Should().NotBeNull(); + + It should_include_a_skipped_entry_for_each_skipped_type = () => + results.AutomappingSkippedTypes.Select(x => x.Type).Should().Contain(typeof(Abstract)); + + It should_have_a_reason_of_skipped_by_IgnoreBase_for_each_skipped_type = () => + results.AutomappingSkippedTypes.Select(x => x.Reason).Should().Contain("Skipped by IAutomappingConfiguration.AbstractClassIsLayerSupertype(Type)"); + + It should_not_include_a_skipped_entry_for_used_types = () => + results.AutomappingSkippedTypes.Select(x => x.Type).Should().NotContain(new Type[] { typeof(Second), typeof(Third) }); + + It should_include_all_unskipped_types_in_the_candidate_list = () => + results.AutomappingCandidateTypes.Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); + + It should_include_all_unskipped_types_in_the_automapped_list = () => + results.AutomappedTypes.Select(x => x.Type).Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); + + static AutoPersistenceModel model; + static DiagnosticResults results; + + class TestAutomappingConfiguration : DefaultAutomappingConfiguration + { + public override bool AbstractClassIsLayerSupertype(Type type) + { + return type == typeof(Abstract); + } + } +} + +public class when_automapping_with_diagnostics_enabled_and_excluding_by_explicit_component +{ + Establish context = () => + { + var dispatcher = new DefaultDiagnosticMessageDispatcher(); + dispatcher.RegisterListener(new StubListener(x => results = x)); + + model = AutoMap.Source(new StubTypeSource(typeof(Component), typeof(Second), typeof(Third)), new TestAutomappingConfiguration()); + + model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); + }; + + Because of = () => + model.BuildMappings(); + + It should_produce_results_when_enabled = () => + results.Should().NotBeNull(); + + It should_include_a_skipped_entry_for_each_skipped_type = () => + results.AutomappingSkippedTypes.Select(x => x.Type).Should().Contain(typeof(Component)); + + It should_have_a_reason_of_skipped_by_IgnoreBase_for_each_skipped_type = () => + results.AutomappingSkippedTypes.Select(x => x.Reason).Should().Contain("Skipped by IAutomappingConfiguration.IsComponent(Type)"); + + It should_not_include_a_skipped_entry_for_used_types = () => + results.AutomappingSkippedTypes.Select(x => x.Type).Should().NotContain(new Type[] { typeof(Second), typeof(Third) } ); + + It should_include_all_unskipped_types_in_the_candidate_list = () => + results.AutomappingCandidateTypes.Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); + + It should_include_all_unskipped_types_in_the_automapped_list = () => + results.AutomappedTypes.Select(x => x.Type).Should().OnlyContain(type => type.Equals(typeof(Second)) || type.Equals(typeof(Third))); + + static AutoPersistenceModel model; + static DiagnosticResults results; + + class TestAutomappingConfiguration : DefaultAutomappingConfiguration + { + public override bool IsComponent(Type type) + { + return type == typeof(Component); + } + } +} + +abstract class Abstract +{} + +class FirstMap : ClassMap +{ + public FirstMap() + { + Id(x => x.Id); + } +} + +class First +{ + public int Id { get; set; } +} + +class Something +{} + +class SecondMap : ClassMap +{ + public SecondMap() + { + Id(x => x.Id); + } +} + +class Second +{ + public int Id { get; set; } +} + +class Third +{ + public int Id { get; set; } +} + +class ChildMap : SubclassMap {} + +class Child : Second {} + +class CompMap : ComponentMap {} +class Comp {} +class ConventionA : IConvention {} +class ConventionB : IConvention {} +class NotAConvention {} + +class StubListener : IDiagnosticListener +{ + readonly Action receiver; + + public StubListener(Action receiver) + { + this.receiver = receiver; + } + + public void Receive(DiagnosticResults results) + { + receiver(results); + } } diff --git a/src/FluentNHibernate.Specs/Extensions.cs b/src/FluentNHibernate.Specs/Extensions.cs index e3165c56e..5539da642 100644 --- a/src/FluentNHibernate.Specs/Extensions.cs +++ b/src/FluentNHibernate.Specs/Extensions.cs @@ -1,47 +1,47 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Xml; -using FluentNHibernate.MappingModel.ClassBased; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs; - -public static class Extensions -{ - public static T As(this object instance) - { - return (T)instance; - } - - public static void ShouldContain(this IEnumerable collection, Func predicate) - { - collection.Any(predicate).Should().BeTrue(); - } - - public static void ShouldNotContain(this IEnumerable collection, Func predicate) - { - collection.Any(predicate).Should().BeFalse(); - } - - public static ClassMapping BuildMappingFor(this FluentNHibernate.PersistenceModel model) - { - return model.BuildMappings() - .SelectMany(x => x.Classes) - .FirstOrDefault(x => x.Type == typeof(T)); - } - - public static void OutputXmlToConsole(this XmlDocument document) - { - var stringWriter = new System.IO.StringWriter(); - var xmlWriter = new XmlTextWriter(stringWriter); - xmlWriter.Formatting = Formatting.Indented; - document.WriteContentTo(xmlWriter); - - Console.WriteLine(string.Empty); - Console.WriteLine(stringWriter.ToString()); - Console.WriteLine(string.Empty); - } +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Xml; +using FluentNHibernate.MappingModel.ClassBased; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs; + +public static class Extensions +{ + public static T As(this object instance) + { + return (T)instance; + } + + public static void ShouldContain(this IEnumerable collection, Func predicate) + { + collection.Any(predicate).Should().BeTrue(); + } + + public static void ShouldNotContain(this IEnumerable collection, Func predicate) + { + collection.Any(predicate).Should().BeFalse(); + } + + public static ClassMapping BuildMappingFor(this FluentNHibernate.PersistenceModel model) + { + return model.BuildMappings() + .SelectMany(x => x.Classes) + .FirstOrDefault(x => x.Type == typeof(T)); + } + + public static void OutputXmlToConsole(this XmlDocument document) + { + var stringWriter = new System.IO.StringWriter(); + var xmlWriter = new XmlTextWriter(stringWriter); + xmlWriter.Formatting = Formatting.Indented; + document.WriteContentTo(xmlWriter); + + Console.WriteLine(string.Empty); + Console.WriteLine(stringWriter.ToString()); + Console.WriteLine(string.Empty); + } } diff --git a/src/FluentNHibernate.Specs/FluentInterface/BiDirectionalKeyIssueSpecs.cs b/src/FluentNHibernate.Specs/FluentInterface/BiDirectionalKeyIssueSpecs.cs index c8383a90a..a6def29f9 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/BiDirectionalKeyIssueSpecs.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/BiDirectionalKeyIssueSpecs.cs @@ -1,30 +1,30 @@ -using System.Linq; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.FluentInterface.Fixtures.BiDirectionalKeyIssue; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.FluentInterface; - -public class when_there_are_two_references_to_the_same_entity -{ - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Add(new ContactMap()); - model.Add(new ContactEmailMap()); - model.Add(new ContactPhoneMap()); - model.Add(new CaseMap()); - }; - - Because of = () => - contact_mapping = model.BuildMappingFor(); - - It should_work_like_1_0_did_aka_not_create_multiple_columns_to_the_same_entity = () => - contact_mapping.Collections - .Single(x => x.Name == "EmailAddresses") - .Key.Columns.Select(x => x.Name).Should().ContainSingle((name) => name == "Contact_id"); - - static FluentNHibernate.PersistenceModel model; - static ClassMapping contact_mapping; +using System.Linq; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.FluentInterface.Fixtures.BiDirectionalKeyIssue; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.FluentInterface; + +public class when_there_are_two_references_to_the_same_entity +{ + Establish context = () => + { + model = new FluentNHibernate.PersistenceModel(); + model.Add(new ContactMap()); + model.Add(new ContactEmailMap()); + model.Add(new ContactPhoneMap()); + model.Add(new CaseMap()); + }; + + Because of = () => + contact_mapping = model.BuildMappingFor(); + + It should_work_like_1_0_did_aka_not_create_multiple_columns_to_the_same_entity = () => + contact_mapping.Collections + .Single(x => x.Name == "EmailAddresses") + .Key.Columns.Select(x => x.Name).Should().ContainSingle((name) => name == "Contact_id"); + + static FluentNHibernate.PersistenceModel model; + static ClassMapping contact_mapping; } diff --git a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Cache.cs b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Cache.cs index 2a5436aa3..b65bd1806 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Cache.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Cache.cs @@ -1,21 +1,21 @@ -using FluentAssertions; -using FluentNHibernate.MappingModel; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.FluentInterface.Fixtures; -using Machine.Specifications; - -namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; - -public class when_class_map_is_told_to_configure_the_cache : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.Cache.ReadOnly()); - - It should_set_the_cache_property_on_the_mapping = () => - mapping.Cache.Should().NotBeNull(); - - It should_set_the_cache_usage_to_the_value_used = () => - mapping.Cache.Usage.Should().Be("read-only"); - - static ClassMapping mapping; +using FluentAssertions; +using FluentNHibernate.MappingModel; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.FluentInterface.Fixtures; +using Machine.Specifications; + +namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; + +public class when_class_map_is_told_to_configure_the_cache : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.Cache.ReadOnly()); + + It should_set_the_cache_property_on_the_mapping = () => + mapping.Cache.Should().NotBeNull(); + + It should_set_the_cache_usage_to_the_value_used = () => + mapping.Cache.Usage.Should().Be("read-only"); + + static ClassMapping mapping; } diff --git a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Component.cs b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Component.cs index f091e07e2..232a07817 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Component.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Component.cs @@ -1,117 +1,117 @@ -using System; -using System.Collections; -using FluentNHibernate.Mapping; -using FluentNHibernate.Mapping.Providers; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.FluentInterface.Fixtures; -using Machine.Specifications; - -namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; - -public class when_class_map_is_told_to_map_a_component : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.Component(x => x.Component, c => {})); - - Behaves_like a_component_in_a_classlike; - - protected static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_a_component_from_a_field : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.Component(x => x.Component, c => { })); - - Behaves_like a_component_in_a_classlike; - - protected static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_a_component_using_a_provider : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.Component(new ComponentMappingProviderStub())); - - Behaves_like a_component_in_a_classlike; - - protected static ClassMapping mapping; - - private class ComponentMappingProviderStub : IComponentMappingProvider - { - public IComponentMapping GetComponentMapping() - { - return null; - } - } -} - -public class when_class_map_is_told_to_map_a_component_using_reveal : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.Component(Reveal.Member("Component"), c => { })); - - Behaves_like a_component_in_a_classlike; - - protected static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_a_dynamic_component : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.DynamicComponent(x => x.DynamicComponent, c => { })); - - Behaves_like a_component_in_a_classlike; - - protected static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_a_dynamic_component_from_a_field : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.DynamicComponent(x => x.DynamicComponent, c => { })); - - Behaves_like a_component_in_a_classlike; - - protected static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_a_dynamic_component_using_reveal : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.DynamicComponent(Reveal.Member("DynamicComponent"), c => { })); - - Behaves_like a_component_in_a_classlike; - - protected static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_a_reference_component : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.Component(x => x.Component)); - - Behaves_like a_component_in_a_classlike; - - protected static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_a_reference_component_from_a_field : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.Component(x => x.Component)); - - Behaves_like a_component_in_a_classlike; - - protected static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_a_reference_component_using_reveal : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.Component(Reveal.Member("Component"))); - - Behaves_like a_component_in_a_classlike; - - protected static ClassMapping mapping; +using System; +using System.Collections; +using FluentNHibernate.Mapping; +using FluentNHibernate.Mapping.Providers; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.FluentInterface.Fixtures; +using Machine.Specifications; + +namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; + +public class when_class_map_is_told_to_map_a_component : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.Component(x => x.Component, c => {})); + + Behaves_like a_component_in_a_classlike; + + protected static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_a_component_from_a_field : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.Component(x => x.Component, c => { })); + + Behaves_like a_component_in_a_classlike; + + protected static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_a_component_using_a_provider : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.Component(new ComponentMappingProviderStub())); + + Behaves_like a_component_in_a_classlike; + + protected static ClassMapping mapping; + + private class ComponentMappingProviderStub : IComponentMappingProvider + { + public IComponentMapping GetComponentMapping() + { + return null; + } + } +} + +public class when_class_map_is_told_to_map_a_component_using_reveal : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.Component(Reveal.Member("Component"), c => { })); + + Behaves_like a_component_in_a_classlike; + + protected static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_a_dynamic_component : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.DynamicComponent(x => x.DynamicComponent, c => { })); + + Behaves_like a_component_in_a_classlike; + + protected static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_a_dynamic_component_from_a_field : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.DynamicComponent(x => x.DynamicComponent, c => { })); + + Behaves_like a_component_in_a_classlike; + + protected static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_a_dynamic_component_using_reveal : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.DynamicComponent(Reveal.Member("DynamicComponent"), c => { })); + + Behaves_like a_component_in_a_classlike; + + protected static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_a_reference_component : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.Component(x => x.Component)); + + Behaves_like a_component_in_a_classlike; + + protected static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_a_reference_component_from_a_field : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.Component(x => x.Component)); + + Behaves_like a_component_in_a_classlike; + + protected static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_a_reference_component_using_reveal : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.Component(Reveal.Member("Component"))); + + Behaves_like a_component_in_a_classlike; + + protected static ClassMapping mapping; } diff --git a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Discriminator.cs b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Discriminator.cs index fdaeceec9..c037d0cf5 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Discriminator.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Discriminator.cs @@ -1,37 +1,37 @@ -using System.Linq; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.FluentInterface.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; - -public class when_class_map_is_told_to_create_a_discriminator : ProviderSpec -{ - Because of = () => - class_mapping = map_as_class(m => m.DiscriminateSubClassesOnColumn(column_name)); - - It should_set_the_discriminator_property_on_the_class_mapping = () => - class_mapping.Discriminator.Should().NotBeNull(); - - It should_create_one_column_for_the_discriminator = () => - class_mapping.Discriminator.Columns.Count().Should().Be(1); - - It should_create_a_column_for_the_discriminator_with_the_name_as_supplied = () => - class_mapping.Discriminator.Columns.First().Name.Should().Be(column_name); - - static ClassMapping class_mapping; - const string column_name = "col"; -} - -public class when_class_map_is_told_to_create_a_discriminator_with_a_default_value : ProviderSpec -{ - Because of = () => - class_mapping = map_as_class(m => m.DiscriminateSubClassesOnColumn("col", base_value)); - - It should_set_the_default_discriminator_value_on_the_class_mapping = () => - class_mapping.DiscriminatorValue.Should().Be(base_value); - - static ClassMapping class_mapping; - const string base_value = "base-value"; +using System.Linq; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.FluentInterface.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; + +public class when_class_map_is_told_to_create_a_discriminator : ProviderSpec +{ + Because of = () => + class_mapping = map_as_class(m => m.DiscriminateSubClassesOnColumn(column_name)); + + It should_set_the_discriminator_property_on_the_class_mapping = () => + class_mapping.Discriminator.Should().NotBeNull(); + + It should_create_one_column_for_the_discriminator = () => + class_mapping.Discriminator.Columns.Count().Should().Be(1); + + It should_create_a_column_for_the_discriminator_with_the_name_as_supplied = () => + class_mapping.Discriminator.Columns.First().Name.Should().Be(column_name); + + static ClassMapping class_mapping; + const string column_name = "col"; +} + +public class when_class_map_is_told_to_create_a_discriminator_with_a_default_value : ProviderSpec +{ + Because of = () => + class_mapping = map_as_class(m => m.DiscriminateSubClassesOnColumn("col", base_value)); + + It should_set_the_default_discriminator_value_on_the_class_mapping = () => + class_mapping.DiscriminatorValue.Should().Be(base_value); + + static ClassMapping class_mapping; + const string base_value = "base-value"; } diff --git a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.HasMany.cs b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.HasMany.cs index 04972ddd8..9b28a0681 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.HasMany.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.HasMany.cs @@ -1,116 +1,116 @@ -using System.Linq; -using FluentNHibernate.MappingModel; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.FluentInterface.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; - -public class when_class_map_is_told_to_map_a_has_many_bag : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.HasMany(x => x.BagOfChildren)); - - Behaves_like a_bag_in_a_classlike_mapping; - - It should_use_the_containing_type_name_suffixed_with_id_as_the_key_column_name = () => - mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("EntityWithCollections_id"); - - protected static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_a_has_many_set : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.HasMany(x => x.SetOfChildren)); - - Behaves_like a_set_in_a_classlike_mapping; - - protected static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_a_has_many_list_with_default_index : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.HasMany(x => x.BagOfChildren).AsList()); - - Behaves_like a_list_with_the_default_index_in_a_classlike_mapping; - - protected static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_a_has_many_list_with_custom_index : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.HasMany(x => x.BagOfChildren).AsList(x => - { - x.Column("custom-column"); - x.Type(); - })); - - Behaves_like a_list_with_a_custom_index_in_a_classlike_mapping; - - protected static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_a_has_many_array : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.HasMany(x => x.ArrayOfChildren).AsArray(x => x.Position)); - - Behaves_like an_array_in_a_classlike_mapping; - - protected static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_an_has_many_from_a_field : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.HasMany(x => x.BagOfChildren)); - - Behaves_like a_bag_in_a_classlike_mapping; - - It should_use_the_containing_type_name_suffixed_with_id_as_the_key_column_name = () => - mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("EntityWithFieldCollections_id"); - - protected static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_an_has_many_using_reveal : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.HasMany(Reveal.Member("BagOfChildren"))); - - Behaves_like a_bag_in_a_classlike_mapping; - - It should_use_the_containing_type_name_suffixed_with_id_as_the_key_column_name = () => - mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("EntityWithCollections_id"); - - protected static ClassMapping mapping; -} - -public class when_class_map_has_a_collection_with_a_component_with_a_nested_component : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => - m.HasMany(x => x.BagOfChildren) - .Component(c => - { - c.Component(x => x.Area, n => n.Map(x => x.Lat)); - })); - - It should_create_a_nested_component_inside_the_first_component = () => - mapping.Collections.Single().CompositeElement.CompositeElements.Should().NotBeEmpty(); - - It should_create_the_nested_component_with_the_correct_name = () => - mapping.Collections.Single().CompositeElement.CompositeElements.Single().Name.Should().Be("Area"); - - It should_create_the_nested_component_with_the_correct_type = () => - mapping.Collections.Single().CompositeElement.CompositeElements.Single().Class.Should().Be(new TypeReference(typeof(AreaComponent))); - - It should_create_a_property_inside_the_nested_component = () => - mapping.Collections.Single().CompositeElement.CompositeElements.Single().Properties.Should().NotBeEmpty(); - - static ClassMapping mapping; +using System.Linq; +using FluentNHibernate.MappingModel; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.FluentInterface.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; + +public class when_class_map_is_told_to_map_a_has_many_bag : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.HasMany(x => x.BagOfChildren)); + + Behaves_like a_bag_in_a_classlike_mapping; + + It should_use_the_containing_type_name_suffixed_with_id_as_the_key_column_name = () => + mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("EntityWithCollections_id"); + + protected static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_a_has_many_set : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.HasMany(x => x.SetOfChildren)); + + Behaves_like a_set_in_a_classlike_mapping; + + protected static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_a_has_many_list_with_default_index : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.HasMany(x => x.BagOfChildren).AsList()); + + Behaves_like a_list_with_the_default_index_in_a_classlike_mapping; + + protected static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_a_has_many_list_with_custom_index : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.HasMany(x => x.BagOfChildren).AsList(x => + { + x.Column("custom-column"); + x.Type(); + })); + + Behaves_like a_list_with_a_custom_index_in_a_classlike_mapping; + + protected static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_a_has_many_array : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.HasMany(x => x.ArrayOfChildren).AsArray(x => x.Position)); + + Behaves_like an_array_in_a_classlike_mapping; + + protected static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_an_has_many_from_a_field : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.HasMany(x => x.BagOfChildren)); + + Behaves_like a_bag_in_a_classlike_mapping; + + It should_use_the_containing_type_name_suffixed_with_id_as_the_key_column_name = () => + mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("EntityWithFieldCollections_id"); + + protected static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_an_has_many_using_reveal : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.HasMany(Reveal.Member("BagOfChildren"))); + + Behaves_like a_bag_in_a_classlike_mapping; + + It should_use_the_containing_type_name_suffixed_with_id_as_the_key_column_name = () => + mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("EntityWithCollections_id"); + + protected static ClassMapping mapping; +} + +public class when_class_map_has_a_collection_with_a_component_with_a_nested_component : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => + m.HasMany(x => x.BagOfChildren) + .Component(c => + { + c.Component(x => x.Area, n => n.Map(x => x.Lat)); + })); + + It should_create_a_nested_component_inside_the_first_component = () => + mapping.Collections.Single().CompositeElement.CompositeElements.Should().NotBeEmpty(); + + It should_create_the_nested_component_with_the_correct_name = () => + mapping.Collections.Single().CompositeElement.CompositeElements.Single().Name.Should().Be("Area"); + + It should_create_the_nested_component_with_the_correct_type = () => + mapping.Collections.Single().CompositeElement.CompositeElements.Single().Class.Should().Be(new TypeReference(typeof(AreaComponent))); + + It should_create_a_property_inside_the_nested_component = () => + mapping.Collections.Single().CompositeElement.CompositeElements.Single().Properties.Should().NotBeEmpty(); + + static ClassMapping mapping; } diff --git a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.HasOne.cs b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.HasOne.cs index 77b86cf78..82a0f42cf 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.HasOne.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.HasOne.cs @@ -1,25 +1,25 @@ -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.FluentInterface.Fixtures; -using Machine.Specifications; - -namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; - -public class when_class_map_is_told_to_map_a_has_one : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.HasOne(x => x.Reference)); - - Behaves_like a_has_one_in_a_classlike_mapping; - - protected static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_a_has_one_using_reveal : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.HasOne(Reveal.Member("Reference"))); - - Behaves_like a_has_one_in_a_classlike_mapping; - - protected static ClassMapping mapping; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.FluentInterface.Fixtures; +using Machine.Specifications; + +namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; + +public class when_class_map_is_told_to_map_a_has_one : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.HasOne(x => x.Reference)); + + Behaves_like a_has_one_in_a_classlike_mapping; + + protected static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_a_has_one_using_reveal : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.HasOne(Reveal.Member("Reference"))); + + Behaves_like a_has_one_in_a_classlike_mapping; + + protected static ClassMapping mapping; } diff --git a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Id.cs b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Id.cs index bc4b32e6b..73b5e1a7d 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Id.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Id.cs @@ -1,50 +1,50 @@ -using System.Linq; -using FluentNHibernate.MappingModel; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.MappingModel.Identity; -using FluentNHibernate.Specs.FluentInterface.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; - -public class when_class_map_is_told_to_map_an_id_without_a_property_or_column : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.Id()); - - It should_set_the_id_on_the_mapping = () => - Id.Should().NotBeNull(); - - It should_not_set_the_member_on_the_id = () => - Id.Member.Should().BeNull(); - - It should_not_specify_any_columns_for_the_id = () => - Id.Columns.Should().BeEmpty(); - - It should_specify_the_default_generator_for_the_id = () => - Id.Generator.Class.Should().Be("increment"); - - It should_set_the_id_type_to_int_by_default = () => - Id.Type.Should().Be(new TypeReference(typeof(int))); - - static ClassMapping mapping; - - static IdMapping Id { get { return mapping.Id as IdMapping; }} -} - -public class when_class_map_has_a_composite_id_with_a_key_reference_with_multiple_columns : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => - m.CompositeId() - .KeyReference(x => x.Reference, "col1", "col2")); - - It should_add_all_the_columns_to_the_composite_id_mapping = () => - mapping.Id.As() - .Keys.Single() - .Columns.Select(x => x.Name) - .Should().Contain(new string[] { "col1", "col2" }); - - static ClassMapping mapping; +using System.Linq; +using FluentNHibernate.MappingModel; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.MappingModel.Identity; +using FluentNHibernate.Specs.FluentInterface.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; + +public class when_class_map_is_told_to_map_an_id_without_a_property_or_column : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.Id()); + + It should_set_the_id_on_the_mapping = () => + Id.Should().NotBeNull(); + + It should_not_set_the_member_on_the_id = () => + Id.Member.Should().BeNull(); + + It should_not_specify_any_columns_for_the_id = () => + Id.Columns.Should().BeEmpty(); + + It should_specify_the_default_generator_for_the_id = () => + Id.Generator.Class.Should().Be("increment"); + + It should_set_the_id_type_to_int_by_default = () => + Id.Type.Should().Be(new TypeReference(typeof(int))); + + static ClassMapping mapping; + + static IdMapping Id { get { return mapping.Id as IdMapping; }} +} + +public class when_class_map_has_a_composite_id_with_a_key_reference_with_multiple_columns : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => + m.CompositeId() + .KeyReference(x => x.Reference, "col1", "col2")); + + It should_add_all_the_columns_to_the_composite_id_mapping = () => + mapping.Id.As() + .Keys.Single() + .Columns.Select(x => x.Name) + .Should().Contain(new string[] { "col1", "col2" }); + + static ClassMapping mapping; } diff --git a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Property.cs b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Property.cs index 04ab373eb..52e35a78a 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Property.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Property.cs @@ -1,45 +1,45 @@ -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.FluentInterface.Fixtures; -using Machine.Specifications; - -namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; - -public class when_class_map_is_told_to_map_a_property : ProviderSpec -{ - Because of = () => - mapping = map_as_class(o => o.Map(x => x.Name)); - - Behaves_like a_property_in_a_classlike_mapping; - - protected static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_a_field : ProviderSpec -{ - Because of = () => - mapping = map_as_class(o => o.Map(x => x.Name)); - - Behaves_like a_property_in_a_classlike_mapping; - - protected static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_a_private_property_using_reveal : ProviderSpec -{ - Because of = () => - mapping = map_as_class(o => o.Map(Reveal.Member("Name"))); - - Behaves_like a_property_in_a_classlike_mapping; - - protected static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_a_private_field_using_reveal : ProviderSpec -{ - Because of = () => - mapping = map_as_class(o => o.Map(Reveal.Member("name"))); - - Behaves_like a_property_in_a_classlike_mapping; - - protected static ClassMapping mapping; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.FluentInterface.Fixtures; +using Machine.Specifications; + +namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; + +public class when_class_map_is_told_to_map_a_property : ProviderSpec +{ + Because of = () => + mapping = map_as_class(o => o.Map(x => x.Name)); + + Behaves_like a_property_in_a_classlike_mapping; + + protected static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_a_field : ProviderSpec +{ + Because of = () => + mapping = map_as_class(o => o.Map(x => x.Name)); + + Behaves_like a_property_in_a_classlike_mapping; + + protected static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_a_private_property_using_reveal : ProviderSpec +{ + Because of = () => + mapping = map_as_class(o => o.Map(Reveal.Member("Name"))); + + Behaves_like a_property_in_a_classlike_mapping; + + protected static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_a_private_field_using_reveal : ProviderSpec +{ + Because of = () => + mapping = map_as_class(o => o.Map(Reveal.Member("name"))); + + Behaves_like a_property_in_a_classlike_mapping; + + protected static ClassMapping mapping; } diff --git a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Subclass.cs b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Subclass.cs index a9f1373cb..7511787ed 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Subclass.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Subclass.cs @@ -1,46 +1,46 @@ -using System.Linq; -using FluentNHibernate.Mapping; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.FluentInterface.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; - -public class when_class_map_is_told_to_create_an_inline_subclass : ProviderSpec -{ - // ignored warning for obsolete SubClass -#pragma warning disable 612,618 - - Because of = () => - class_mapping = map_as_class(m => m.DiscriminateSubClassesOnColumn("col").SubClass(sc => { })); - -#pragma warning restore 612,618 - - It should_add_subclass_to_class_mapping_subclasses_collection = () => - class_mapping.Subclasses.Count().Should().Be(1); - - static ClassMapping class_mapping; -} - -public class when_class_map_is_told_to_create_an_inline_joined_subclass : ProviderSpec -{ - // ignored warning for obsolete JoinedSubClass -#pragma warning disable 612,618 - - Because of = () => - class_mapping = map_as_class(m => m.JoinedSubClass("key", c => { })); - -#pragma warning restore 612,618 - - It should_add_joined_subclass_to_class_mapping_subclasses_collection = () => - class_mapping.Subclasses.Count().Should().Be(1); - - It should_create_a_key_for_the_subclass = () => - class_mapping.Subclasses.First().Key.Should().NotBeNull(); - - It should_create_a_column_for_the_key_with_the_name_specified = () => - class_mapping.Subclasses.First().Key.Columns.Single().Name.Should().Be("key"); - - static ClassMapping class_mapping; +using System.Linq; +using FluentNHibernate.Mapping; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.FluentInterface.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; + +public class when_class_map_is_told_to_create_an_inline_subclass : ProviderSpec +{ + // ignored warning for obsolete SubClass +#pragma warning disable 612,618 + + Because of = () => + class_mapping = map_as_class(m => m.DiscriminateSubClassesOnColumn("col").SubClass(sc => { })); + +#pragma warning restore 612,618 + + It should_add_subclass_to_class_mapping_subclasses_collection = () => + class_mapping.Subclasses.Count().Should().Be(1); + + static ClassMapping class_mapping; +} + +public class when_class_map_is_told_to_create_an_inline_joined_subclass : ProviderSpec +{ + // ignored warning for obsolete JoinedSubClass +#pragma warning disable 612,618 + + Because of = () => + class_mapping = map_as_class(m => m.JoinedSubClass("key", c => { })); + +#pragma warning restore 612,618 + + It should_add_joined_subclass_to_class_mapping_subclasses_collection = () => + class_mapping.Subclasses.Count().Should().Be(1); + + It should_create_a_key_for_the_subclass = () => + class_mapping.Subclasses.First().Key.Should().NotBeNull(); + + It should_create_a_column_for_the_key_with_the_name_specified = () => + class_mapping.Subclasses.First().Key.Columns.Single().Name.Should().Be("key"); + + static ClassMapping class_mapping; } diff --git a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Version.cs b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Version.cs index e99d4ebe2..985c9d50a 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Version.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Version.cs @@ -1,41 +1,41 @@ -using System.Linq; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.FluentInterface.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; - -public class when_class_map_is_told_to_map_a_version : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.Version(x => x.VersionNumber)); - - It should_set_the_version_property_on_the_mapping = () => - mapping.Version.Should().NotBeNull(); - - It should_create_a_single_column_for_the_version = () => - mapping.Version.Columns.Count().Should().Be(1); - - It should_use_the_property_name_for_the_column_name = () => - mapping.Version.Columns.Single().Name.Should().Be("VersionNumber"); - - static ClassMapping mapping; -} - -public class when_class_map_is_told_to_map_a_version_using_reveal : ProviderSpec -{ - Because of = () => - mapping = map_as_class(m => m.Version(Reveal.Member("VersionNumber"))); - - It should_set_the_version_property_on_the_mapping = () => - mapping.Version.Should().NotBeNull(); - - It should_create_a_single_column_for_the_version = () => - mapping.Version.Columns.Count().Should().Be(1); - - It should_use_the_property_name_for_the_column_name = () => - mapping.Version.Columns.Single().Name.Should().Be("VersionNumber"); - - static ClassMapping mapping; +using System.Linq; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.FluentInterface.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; + +public class when_class_map_is_told_to_map_a_version : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.Version(x => x.VersionNumber)); + + It should_set_the_version_property_on_the_mapping = () => + mapping.Version.Should().NotBeNull(); + + It should_create_a_single_column_for_the_version = () => + mapping.Version.Columns.Count().Should().Be(1); + + It should_use_the_property_name_for_the_column_name = () => + mapping.Version.Columns.Single().Name.Should().Be("VersionNumber"); + + static ClassMapping mapping; +} + +public class when_class_map_is_told_to_map_a_version_using_reveal : ProviderSpec +{ + Because of = () => + mapping = map_as_class(m => m.Version(Reveal.Member("VersionNumber"))); + + It should_set_the_version_property_on_the_mapping = () => + mapping.Version.Should().NotBeNull(); + + It should_create_a_single_column_for_the_version = () => + mapping.Version.Columns.Count().Should().Be(1); + + It should_use_the_property_name_for_the_column_name = () => + mapping.Version.Columns.Single().Name.Should().Be("VersionNumber"); + + static ClassMapping mapping; } diff --git a/src/FluentNHibernate.Specs/FluentInterface/ClasslikeBehaviors.cs b/src/FluentNHibernate.Specs/FluentInterface/ClasslikeBehaviors.cs index 70a0f3720..4238f1fe0 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClasslikeBehaviors.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClasslikeBehaviors.cs @@ -1,199 +1,199 @@ -using System.Linq; -using FluentNHibernate.MappingModel; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.MappingModel.Collections; -using FluentNHibernate.Specs.FluentInterface.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.FluentInterface; - -[Behaviors] -public class ClasslikePropertyBehaviour -{ - protected static ClassMappingBase mapping; - - It should_add_a_property_mapping_to_the_properties_collection_on_the_class_mapping = () => - mapping.Properties.Count().Should().Be(1); - - It should_create_property_mapping_with_correct_name = () => - mapping.Properties.First().Name.Should().Be("Name"); - - It should_have_a_single_column = () => - mapping.Properties.First().Columns.Count().Should().Be(1); - - It should_have_a_column_with_the_same_name_as_the_property = () => - mapping.Properties.First().Columns.First().Name.Should().Be("Name"); -} - -[Behaviors] -public class ClasslikeComponentBehaviour -{ - protected static ClassMappingBase mapping; - - It should_add_a_component_to_the_components_collection = () => - mapping.Components.Count().Should().Be(1); -} - -[Behaviors] -public class ClasslikeHasOneBehaviour -{ - protected static ClassMappingBase mapping; - - It should_add_the_has_one_to_the_has_one_collection_on_the_mapping = () => - mapping.OneToOnes.Count().Should().Be(1); - - It should_create_the_has_one_with_the_name_from_the_property_used = () => - mapping.OneToOnes.Single().Name.Should().Be("Reference"); -} - -[Behaviors] -public class ClasslikeBagBehaviour -{ - It should_add_only_one_collection_to_the_mapping = () => - mapping.Collections.Count().Should().Be(1); - - It should_add_a_bag_to_the_collections_of_the_mapping = () => - mapping.Collections.Single().Collection.Should().Be(Collection.Bag); - - It should_use_the_property_name_as_the_collection_name = () => - mapping.Collections.Single().Name.Should().Be("BagOfChildren"); - - It should_create_a_key_for_the_collection = () => - mapping.Collections.Single().Key.Should().NotBeNull(); - - It should_create_a_single_column_for_the_key = () => - mapping.Collections.Single().Key.Columns.Count().Should().Be(1); - - protected static ClassMappingBase mapping; -} - -[Behaviors] -public class ClasslikeSetBehaviour -{ - It should_add_only_one_collection_to_the_mapping = () => - mapping.Collections.Count().Should().Be(1); - - It should_add_a_set_to_the_collections_of_the_mapping = () => - mapping.Collections.Single().Collection.Should().Be(Collection.Set); - - It should_use_the_property_name_as_the_collection_name = () => - mapping.Collections.Single().Name.Should().Be("SetOfChildren"); - - It should_create_a_key_for_the_collection = () => - mapping.Collections.Single().Key.Should().NotBeNull(); - - It should_create_a_single_column_for_the_key = () => - mapping.Collections.Single().Key.Columns.Count().Should().Be(1); - - It should_use_the_containing_type_name_suffixed_with_id_as_the_key_column_name = () => - mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("EntityWithCollections_id"); - - protected static ClassMappingBase mapping; -} - -[Behaviors] -public class ClasslikeListWithDefaultIndexBehaviour : ClasslikeListBehaviour -{ - It should_create_an_index_for_the_collection_mapping = () => - mapping.Collections.Single().Index.Should().NotBeNull(); - - It should_create_a_single_column_for_the_index = () => - mapping.Collections.Single().Index.Columns.Count().Should().Be(1); - - It should_use_index_as_the_index_column_name = () => - mapping.Collections.Single().Index.Columns.Single().Name.Should().Be("Index"); -} - -[Behaviors] -public class ClasslikeListWithCustomIndexBehaviour : ClasslikeListBehaviour -{ - It should_create_an_index_for_the_collection_mapping = () => - mapping.Collections.Single().Index.Should().NotBeNull(); - - It should_create_a_single_column_for_the_index = () => - mapping.Collections.Single().Index.Columns.Count().Should().Be(1); - - It should_use_specified_column_name_as_the_index_column_name = () => - mapping.Collections.Single().Index.Columns.Single().Name.Should().Be("custom-column"); - - It should_use_specified_type_as_the_index_type = () => - mapping.Collections.Single().Index.As().Type.Should().Be(new TypeReference(typeof(IndexTarget))); -} - -public abstract class ClasslikeListBehaviour -{ - It should_add_only_one_collection_to_the_mapping = () => - mapping.Collections.Count().Should().Be(1); - - It should_add_a_list_to_the_collections_of_the_mapping = () => - mapping.Collections.Single().Collection.Should().Be(Collection.List); - - It should_use_the_property_name_as_the_collection_name = () => - mapping.Collections.Single().Name.Should().Be("ListOfChildren"); - - It should_create_a_key_for_the_collection = () => - mapping.Collections.Single().Key.Should().NotBeNull(); - - It should_create_a_single_column_for_the_key = () => - mapping.Collections.Single().Key.Columns.Count().Should().Be(1); - - It should_use_the_containing_type_name_suffixed_with_id_as_the_key_column_name = () => - mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("OneToManyTarget_id"); - - protected static ClassMappingBase mapping; -} - -[Behaviors] -public class ClasslikeArrayBehaviour -{ - It should_add_only_one_collection_to_the_mapping = () => - mapping.Collections.Count().Should().Be(1); - - It should_add_an_array_to_the_collections_of_the_mapping = () => - mapping.Collections.Single().Collection.Should().Be(Collection.Array); - - It should_use_the_property_name_as_the_collection_name = () => - mapping.Collections.Single().Name.Should().Be("ArrayOfChildren"); - - It should_create_a_key_for_the_collection = () => - mapping.Collections.Single().Key.Should().NotBeNull(); - - It should_create_a_single_column_for_the_key = () => - mapping.Collections.Single().Key.Columns.Count().Should().Be(1); - - It should_use_the_containing_type_name_suffixed_with_id_as_the_key_column_name = () => - mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("EntityWithCollections_id"); - - It should_create_an_index_for_the_collection_mapping = () => - mapping.Collections.Single().Index.Should().NotBeNull(); - - It should_create_a_single_column_for_the_index = () => - mapping.Collections.Single().Index.Columns.Count().Should().Be(1); - - It should_use_specified_property_as_the_index_column_name = () => - mapping.Collections.Single().Index.Columns.Single().Name.Should().Be("Position"); - - protected static ClassMappingBase mapping; -} - -[Behaviors] -public class HasManyElementBehaviour -{ - It should_create_a_collection = () => - collection.Should().NotBeNull(); - - It should_create_a_element_mapping_in_the_collection = () => - collection.Element.Should().NotBeNull(); - - It should_not_create_an_inner_relationship = () => - collection.Relationship.Should().BeNull(); - - It should_not_create_a_component = () => - collection.CompositeElement.Should().BeNull(); - - It should_use_the_default_column_name_for_the_element = () => - collection.Element.Columns.Single().Name.Should().Be("value"); - - protected static CollectionMapping collection; +using System.Linq; +using FluentNHibernate.MappingModel; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.MappingModel.Collections; +using FluentNHibernate.Specs.FluentInterface.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.FluentInterface; + +[Behaviors] +public class ClasslikePropertyBehaviour +{ + protected static ClassMappingBase mapping; + + It should_add_a_property_mapping_to_the_properties_collection_on_the_class_mapping = () => + mapping.Properties.Count().Should().Be(1); + + It should_create_property_mapping_with_correct_name = () => + mapping.Properties.First().Name.Should().Be("Name"); + + It should_have_a_single_column = () => + mapping.Properties.First().Columns.Count().Should().Be(1); + + It should_have_a_column_with_the_same_name_as_the_property = () => + mapping.Properties.First().Columns.First().Name.Should().Be("Name"); +} + +[Behaviors] +public class ClasslikeComponentBehaviour +{ + protected static ClassMappingBase mapping; + + It should_add_a_component_to_the_components_collection = () => + mapping.Components.Count().Should().Be(1); +} + +[Behaviors] +public class ClasslikeHasOneBehaviour +{ + protected static ClassMappingBase mapping; + + It should_add_the_has_one_to_the_has_one_collection_on_the_mapping = () => + mapping.OneToOnes.Count().Should().Be(1); + + It should_create_the_has_one_with_the_name_from_the_property_used = () => + mapping.OneToOnes.Single().Name.Should().Be("Reference"); +} + +[Behaviors] +public class ClasslikeBagBehaviour +{ + It should_add_only_one_collection_to_the_mapping = () => + mapping.Collections.Count().Should().Be(1); + + It should_add_a_bag_to_the_collections_of_the_mapping = () => + mapping.Collections.Single().Collection.Should().Be(Collection.Bag); + + It should_use_the_property_name_as_the_collection_name = () => + mapping.Collections.Single().Name.Should().Be("BagOfChildren"); + + It should_create_a_key_for_the_collection = () => + mapping.Collections.Single().Key.Should().NotBeNull(); + + It should_create_a_single_column_for_the_key = () => + mapping.Collections.Single().Key.Columns.Count().Should().Be(1); + + protected static ClassMappingBase mapping; +} + +[Behaviors] +public class ClasslikeSetBehaviour +{ + It should_add_only_one_collection_to_the_mapping = () => + mapping.Collections.Count().Should().Be(1); + + It should_add_a_set_to_the_collections_of_the_mapping = () => + mapping.Collections.Single().Collection.Should().Be(Collection.Set); + + It should_use_the_property_name_as_the_collection_name = () => + mapping.Collections.Single().Name.Should().Be("SetOfChildren"); + + It should_create_a_key_for_the_collection = () => + mapping.Collections.Single().Key.Should().NotBeNull(); + + It should_create_a_single_column_for_the_key = () => + mapping.Collections.Single().Key.Columns.Count().Should().Be(1); + + It should_use_the_containing_type_name_suffixed_with_id_as_the_key_column_name = () => + mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("EntityWithCollections_id"); + + protected static ClassMappingBase mapping; +} + +[Behaviors] +public class ClasslikeListWithDefaultIndexBehaviour : ClasslikeListBehaviour +{ + It should_create_an_index_for_the_collection_mapping = () => + mapping.Collections.Single().Index.Should().NotBeNull(); + + It should_create_a_single_column_for_the_index = () => + mapping.Collections.Single().Index.Columns.Count().Should().Be(1); + + It should_use_index_as_the_index_column_name = () => + mapping.Collections.Single().Index.Columns.Single().Name.Should().Be("Index"); +} + +[Behaviors] +public class ClasslikeListWithCustomIndexBehaviour : ClasslikeListBehaviour +{ + It should_create_an_index_for_the_collection_mapping = () => + mapping.Collections.Single().Index.Should().NotBeNull(); + + It should_create_a_single_column_for_the_index = () => + mapping.Collections.Single().Index.Columns.Count().Should().Be(1); + + It should_use_specified_column_name_as_the_index_column_name = () => + mapping.Collections.Single().Index.Columns.Single().Name.Should().Be("custom-column"); + + It should_use_specified_type_as_the_index_type = () => + mapping.Collections.Single().Index.As().Type.Should().Be(new TypeReference(typeof(IndexTarget))); +} + +public abstract class ClasslikeListBehaviour +{ + It should_add_only_one_collection_to_the_mapping = () => + mapping.Collections.Count().Should().Be(1); + + It should_add_a_list_to_the_collections_of_the_mapping = () => + mapping.Collections.Single().Collection.Should().Be(Collection.List); + + It should_use_the_property_name_as_the_collection_name = () => + mapping.Collections.Single().Name.Should().Be("ListOfChildren"); + + It should_create_a_key_for_the_collection = () => + mapping.Collections.Single().Key.Should().NotBeNull(); + + It should_create_a_single_column_for_the_key = () => + mapping.Collections.Single().Key.Columns.Count().Should().Be(1); + + It should_use_the_containing_type_name_suffixed_with_id_as_the_key_column_name = () => + mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("OneToManyTarget_id"); + + protected static ClassMappingBase mapping; +} + +[Behaviors] +public class ClasslikeArrayBehaviour +{ + It should_add_only_one_collection_to_the_mapping = () => + mapping.Collections.Count().Should().Be(1); + + It should_add_an_array_to_the_collections_of_the_mapping = () => + mapping.Collections.Single().Collection.Should().Be(Collection.Array); + + It should_use_the_property_name_as_the_collection_name = () => + mapping.Collections.Single().Name.Should().Be("ArrayOfChildren"); + + It should_create_a_key_for_the_collection = () => + mapping.Collections.Single().Key.Should().NotBeNull(); + + It should_create_a_single_column_for_the_key = () => + mapping.Collections.Single().Key.Columns.Count().Should().Be(1); + + It should_use_the_containing_type_name_suffixed_with_id_as_the_key_column_name = () => + mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("EntityWithCollections_id"); + + It should_create_an_index_for_the_collection_mapping = () => + mapping.Collections.Single().Index.Should().NotBeNull(); + + It should_create_a_single_column_for_the_index = () => + mapping.Collections.Single().Index.Columns.Count().Should().Be(1); + + It should_use_specified_property_as_the_index_column_name = () => + mapping.Collections.Single().Index.Columns.Single().Name.Should().Be("Position"); + + protected static ClassMappingBase mapping; +} + +[Behaviors] +public class HasManyElementBehaviour +{ + It should_create_a_collection = () => + collection.Should().NotBeNull(); + + It should_create_a_element_mapping_in_the_collection = () => + collection.Element.Should().NotBeNull(); + + It should_not_create_an_inner_relationship = () => + collection.Relationship.Should().BeNull(); + + It should_not_create_a_component = () => + collection.CompositeElement.Should().BeNull(); + + It should_use_the_default_column_name_for_the_element = () => + collection.Element.Columns.Single().Name.Should().Be("value"); + + protected static CollectionMapping collection; } diff --git a/src/FluentNHibernate.Specs/FluentInterface/ComponentMapSpecs.cs b/src/FluentNHibernate.Specs/FluentInterface/ComponentMapSpecs.cs index 48c58a40b..567df39ec 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ComponentMapSpecs.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ComponentMapSpecs.cs @@ -1,339 +1,339 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using FluentNHibernate.Mapping; -using FluentNHibernate.Mapping.Providers; -using FluentNHibernate.MappingModel; -using FluentNHibernate.MappingModel.ClassBased; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.FluentInterface; - -public class when_creating_the_mapping_for_a_component_using_component_map -{ - Establish context = () => - { - component = new ComponentMap(); - component.Map(x => x.a_property); - component.ReferencesAny(x => x.an_any).EntityIdentifierColumn("x").EntityTypeColumn("y").IdentityType(typeof(Target)); - component.HasMany(x => x.a_collection); - component.Component(x => x.a_component); - component.HasOne(x => x.a_one_to_one); - component.References(x => x.a_reference); - }; - - Because of = () => - mapping = (component as IExternalComponentMappingProvider).GetComponentMapping(); - - It should_create_an_external_component_mapping = () => - mapping.Should().BeOfType(); - - It should_add_properties_to_the_properties_collection = () => - mapping.Properties.ShouldContain(x => x.Name == "a_property"); - - It should_add_anys_to_the_anys_collection = () => - mapping.Anys.ShouldContain(x => x.Name == "an_any"); - - It should_add_collections_to_the_collections_collection = () => - mapping.Collections.ShouldContain(x => x.Name == "a_collection"); - - It should_add_components_to_the_components_collection = () => - mapping.Components.ShouldContain(x => x.Name == "a_component"); - - It should_add_one_to_ones_to_the_one_to_ones_collection = () => - mapping.OneToOnes.ShouldContain(x => x.Name == "a_one_to_one"); - - It should_add_references_to_the_references_collection = () => - mapping.References.ShouldContain(x => x.Name == "a_reference"); - - private static ComponentMap component; - private static ComponentMapping mapping; - - private class Target - { - public string a_property { get; set; } - public Target an_any { get; set; } - public ComponentTarget a_component { get; set; } - public Target a_one_to_one { get; set; } - public Target a_reference { get; set; } - public IEnumerable a_collection { get; set; } - } - - class ComponentTarget - {} -} - -public class when_mapping_a_component_in_an_entity_without_defining_any_mappings_for_the_component -{ - Establish context = () => - { - classmap = new ClassMap(); - classmap.Id(x => x.Id); - classmap.Component(x => x.Component); - }; - - Because of = () => - mapping = (classmap as IMappingProvider).GetClassMapping() - .Components.First(); - - It should_create_a_reference_component_mapping = () => - mapping.Should().BeOfType(); - - It should_store_the_property_in_the_reference_component_mapping = () => - (mapping as ReferenceComponentMapping).Member.Name.Should().Be("Component"); - - private static ClassMap classmap; - private static IComponentMapping mapping; - - private class Target - { - public int Id { get; set; } - public Component Component { get; set;} - } - - private class Component {} -} - -public class when_compiling_the_mappings_with_a_reference_component_in_a_subclass -{ - Establish context = () => - { - var component_map = new ComponentMap(); - component_map.Map(x => x.Property); - - var class_map = new ClassMap(); - class_map.Id(x => x.Id); - - var subclass_map = new SubclassMap(); - subclass_map.Component(x => x.Component); - - persistence_model = new FluentNHibernate.PersistenceModel(); - persistence_model.Add(class_map); - persistence_model.Add(subclass_map); - persistence_model.Add(component_map); - }; - - Because of = () => - { - mappings = persistence_model.BuildMappings(); - class_mapping = mappings.SelectMany(x => x.Classes).First(); - }; - - It should_add_the_subclass_to_the_class = () => - class_mapping.Subclasses.Count().Should().Be(1); - - It should_merge_the_delegated_component_mapping_with_the_unassociated_component_mapping_from_the_component_map = () => - { - var component_mapping = class_mapping.Subclasses.Single().Components.First(); - - component_mapping.Member.Name.Should().Be("Component"); - component_mapping.Properties.ShouldContain(x => x.Name == "Property"); - }; - - private static FluentNHibernate.PersistenceModel persistence_model; - private static IEnumerable mappings; - private static ClassMapping class_mapping; - - private class Target - { - public int Id { get; set; } - } - - private class TargetChild : Target - { - public Component Component { get; set; } - } - - private class Component - { - public string Property { get; set; } - } -} - -public class when_compiling_the_mappings_with_a_nested_reference_component_in_a_component_map -{ - Establish context = () => - { - component_map = new ComponentMap(); - }; - - Because of = () => - ex = Catch.Exception(() => component_map.Component(x => x.Compo)); - - It should_throw_a_not_supported_exception = () => - ex.Should().BeOfType(); - - static ComponentMap component_map; - static Exception ex; - - private class Component - { - public Component Compo { get; set; } - } -} - -public class when_compiling_the_mappings_with_a_reference_component_and_a_related_external_component -{ - Establish context = () => - { - var component_map = new ComponentMap(); - component_map.Map(x => x.Property); - - var class_map = new ClassMap(); - class_map.Id(x => x.Id); - class_map.Component(x => x.Component); - - persistence_model = new FluentNHibernate.PersistenceModel(); - persistence_model.Add(class_map); - persistence_model.Add(component_map); - }; - - Because of = () => - { - mappings = persistence_model.BuildMappings(); - class_mapping = mappings.SelectMany(x => x.Classes).First(); - }; - - It should_merge_the_delegated_component_mapping_with_the_unassociated_component_mapping_from_the_component_map = () => - { - var component_mapping = class_mapping.Components.First(); - - component_mapping.Member.Name.Should().Be("Component"); - component_mapping.Properties.ShouldContain(x => x.Name == "Property"); - }; - - private static FluentNHibernate.PersistenceModel persistence_model; - private static IEnumerable mappings; - private static ClassMapping class_mapping; - - private class Target - { - public int Id { get; set; } - public Component Component { get; set; } - } - - private class Component - { - public string Property { get; set; } - } -} - -public class when_compiling_the_mappings_with_two_of_the_same_reference_component_and_a_related_external_component -{ - Establish context = () => - { - var component_map = new ComponentMap(); - component_map.Map(x => x.Property, "PROP"); - - var class_map = new ClassMap(); - class_map.Id(x => x.Id); - class_map.Component(x => x.ComponentA) - .ColumnPrefix("A_"); - class_map.Component(x => x.ComponentB) - .ColumnPrefix("B_"); - - persistence_model = new FluentNHibernate.PersistenceModel(); - persistence_model.Add(class_map); - persistence_model.Add(component_map); - }; - - Because of = () => - { - mappings = persistence_model.BuildMappings(); - class_mapping = mappings.SelectMany(x => x.Classes).First(); - }; - - It should_merge_the_component_mappings_with_the_mapping_from_the_component_map = () => - class_mapping.Components.Select(x => x.Name).Should().Contain("ComponentA", "ComponentB"); - - It should_use_the_column_prefixes_for_the_columns = () => - { - class_mapping.Components.First(x => x.Name == "ComponentA") - .Properties.SelectMany(x => x.Columns) - .Select(x => x.Name) - .Should().Contain("A_PROP"); - class_mapping.Components.First(x => x.Name == "ComponentB") - .Properties.SelectMany(x => x.Columns) - .Select(x => x.Name) - .Should().Contain("B_PROP"); - }; - - private static FluentNHibernate.PersistenceModel persistence_model; - private static IEnumerable mappings; - private static ClassMapping class_mapping; - - private class Target - { - public int Id { get; set; } - public Component ComponentA { get; set; } - public Component ComponentB { get; set; } - } - - private class Component - { - public string Property { get; set; } - } -} - -public class when_compiling_the_mappings_with_multiple_nested_component_mappings -{ - Establish context = () => { - var component_map = new ComponentMap(); - component_map.Component(x => x.NestedComponent1, - c => c.Map(y => y.Property, "PROP1")); - component_map.Component(x => x.NestedComponent2, - c => c.Map(y => y.Property, "PROP2")); - - var class_map = new ClassMap(); - class_map.Id(x => x.Id); - class_map.Component(x => x.Component) - .ColumnPrefix("A_"); - - persistence_model = new FluentNHibernate.PersistenceModel(); - persistence_model.Add(class_map); - persistence_model.Add(component_map); - }; - - Because of = () => { - mappings = persistence_model.BuildMappings(); - class_mapping = mappings.SelectMany(x => x.Classes).First(); - }; - - It should_use_the_column_prefix_for_all_nested_component_columns = () => { - var root_component = class_mapping.Components.First(x => x.Name == "Component"); - - root_component - .Components.First(x => x.Name == "NestedComponent1") - .Properties.SelectMany(x => x.Columns) - .Select(x => x.Name) - .Should().Contain("A_PROP1"); - - root_component - .Components.First(x => x.Name == "NestedComponent2") - .Properties.SelectMany(x => x.Columns) - .Select(x => x.Name) - .Should().Contain("A_PROP2"); - }; - - private static FluentNHibernate.PersistenceModel persistence_model; - private static IEnumerable mappings; - private static ClassMapping class_mapping; - - private class Target - { - public int Id { get; set; } - public Component Component { get; set; } - } - - private class Component - { - public NestedComponent NestedComponent1 { get; set; } - public NestedComponent NestedComponent2 { get; set; } - } - - private class NestedComponent - { - public string Property { get; set; } - } +using System; +using System.Collections.Generic; +using System.Linq; +using FluentNHibernate.Mapping; +using FluentNHibernate.Mapping.Providers; +using FluentNHibernate.MappingModel; +using FluentNHibernate.MappingModel.ClassBased; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.FluentInterface; + +public class when_creating_the_mapping_for_a_component_using_component_map +{ + Establish context = () => + { + component = new ComponentMap(); + component.Map(x => x.a_property); + component.ReferencesAny(x => x.an_any).EntityIdentifierColumn("x").EntityTypeColumn("y").IdentityType(typeof(Target)); + component.HasMany(x => x.a_collection); + component.Component(x => x.a_component); + component.HasOne(x => x.a_one_to_one); + component.References(x => x.a_reference); + }; + + Because of = () => + mapping = (component as IExternalComponentMappingProvider).GetComponentMapping(); + + It should_create_an_external_component_mapping = () => + mapping.Should().BeOfType(); + + It should_add_properties_to_the_properties_collection = () => + mapping.Properties.ShouldContain(x => x.Name == "a_property"); + + It should_add_anys_to_the_anys_collection = () => + mapping.Anys.ShouldContain(x => x.Name == "an_any"); + + It should_add_collections_to_the_collections_collection = () => + mapping.Collections.ShouldContain(x => x.Name == "a_collection"); + + It should_add_components_to_the_components_collection = () => + mapping.Components.ShouldContain(x => x.Name == "a_component"); + + It should_add_one_to_ones_to_the_one_to_ones_collection = () => + mapping.OneToOnes.ShouldContain(x => x.Name == "a_one_to_one"); + + It should_add_references_to_the_references_collection = () => + mapping.References.ShouldContain(x => x.Name == "a_reference"); + + private static ComponentMap component; + private static ComponentMapping mapping; + + private class Target + { + public string a_property { get; set; } + public Target an_any { get; set; } + public ComponentTarget a_component { get; set; } + public Target a_one_to_one { get; set; } + public Target a_reference { get; set; } + public IEnumerable a_collection { get; set; } + } + + class ComponentTarget + {} +} + +public class when_mapping_a_component_in_an_entity_without_defining_any_mappings_for_the_component +{ + Establish context = () => + { + classmap = new ClassMap(); + classmap.Id(x => x.Id); + classmap.Component(x => x.Component); + }; + + Because of = () => + mapping = (classmap as IMappingProvider).GetClassMapping() + .Components.First(); + + It should_create_a_reference_component_mapping = () => + mapping.Should().BeOfType(); + + It should_store_the_property_in_the_reference_component_mapping = () => + (mapping as ReferenceComponentMapping).Member.Name.Should().Be("Component"); + + private static ClassMap classmap; + private static IComponentMapping mapping; + + private class Target + { + public int Id { get; set; } + public Component Component { get; set;} + } + + private class Component {} +} + +public class when_compiling_the_mappings_with_a_reference_component_in_a_subclass +{ + Establish context = () => + { + var component_map = new ComponentMap(); + component_map.Map(x => x.Property); + + var class_map = new ClassMap(); + class_map.Id(x => x.Id); + + var subclass_map = new SubclassMap(); + subclass_map.Component(x => x.Component); + + persistence_model = new FluentNHibernate.PersistenceModel(); + persistence_model.Add(class_map); + persistence_model.Add(subclass_map); + persistence_model.Add(component_map); + }; + + Because of = () => + { + mappings = persistence_model.BuildMappings(); + class_mapping = mappings.SelectMany(x => x.Classes).First(); + }; + + It should_add_the_subclass_to_the_class = () => + class_mapping.Subclasses.Count().Should().Be(1); + + It should_merge_the_delegated_component_mapping_with_the_unassociated_component_mapping_from_the_component_map = () => + { + var component_mapping = class_mapping.Subclasses.Single().Components.First(); + + component_mapping.Member.Name.Should().Be("Component"); + component_mapping.Properties.ShouldContain(x => x.Name == "Property"); + }; + + private static FluentNHibernate.PersistenceModel persistence_model; + private static IEnumerable mappings; + private static ClassMapping class_mapping; + + private class Target + { + public int Id { get; set; } + } + + private class TargetChild : Target + { + public Component Component { get; set; } + } + + private class Component + { + public string Property { get; set; } + } +} + +public class when_compiling_the_mappings_with_a_nested_reference_component_in_a_component_map +{ + Establish context = () => + { + component_map = new ComponentMap(); + }; + + Because of = () => + ex = Catch.Exception(() => component_map.Component(x => x.Compo)); + + It should_throw_a_not_supported_exception = () => + ex.Should().BeOfType(); + + static ComponentMap component_map; + static Exception ex; + + private class Component + { + public Component Compo { get; set; } + } +} + +public class when_compiling_the_mappings_with_a_reference_component_and_a_related_external_component +{ + Establish context = () => + { + var component_map = new ComponentMap(); + component_map.Map(x => x.Property); + + var class_map = new ClassMap(); + class_map.Id(x => x.Id); + class_map.Component(x => x.Component); + + persistence_model = new FluentNHibernate.PersistenceModel(); + persistence_model.Add(class_map); + persistence_model.Add(component_map); + }; + + Because of = () => + { + mappings = persistence_model.BuildMappings(); + class_mapping = mappings.SelectMany(x => x.Classes).First(); + }; + + It should_merge_the_delegated_component_mapping_with_the_unassociated_component_mapping_from_the_component_map = () => + { + var component_mapping = class_mapping.Components.First(); + + component_mapping.Member.Name.Should().Be("Component"); + component_mapping.Properties.ShouldContain(x => x.Name == "Property"); + }; + + private static FluentNHibernate.PersistenceModel persistence_model; + private static IEnumerable mappings; + private static ClassMapping class_mapping; + + private class Target + { + public int Id { get; set; } + public Component Component { get; set; } + } + + private class Component + { + public string Property { get; set; } + } +} + +public class when_compiling_the_mappings_with_two_of_the_same_reference_component_and_a_related_external_component +{ + Establish context = () => + { + var component_map = new ComponentMap(); + component_map.Map(x => x.Property, "PROP"); + + var class_map = new ClassMap(); + class_map.Id(x => x.Id); + class_map.Component(x => x.ComponentA) + .ColumnPrefix("A_"); + class_map.Component(x => x.ComponentB) + .ColumnPrefix("B_"); + + persistence_model = new FluentNHibernate.PersistenceModel(); + persistence_model.Add(class_map); + persistence_model.Add(component_map); + }; + + Because of = () => + { + mappings = persistence_model.BuildMappings(); + class_mapping = mappings.SelectMany(x => x.Classes).First(); + }; + + It should_merge_the_component_mappings_with_the_mapping_from_the_component_map = () => + class_mapping.Components.Select(x => x.Name).Should().Contain("ComponentA", "ComponentB"); + + It should_use_the_column_prefixes_for_the_columns = () => + { + class_mapping.Components.First(x => x.Name == "ComponentA") + .Properties.SelectMany(x => x.Columns) + .Select(x => x.Name) + .Should().Contain("A_PROP"); + class_mapping.Components.First(x => x.Name == "ComponentB") + .Properties.SelectMany(x => x.Columns) + .Select(x => x.Name) + .Should().Contain("B_PROP"); + }; + + private static FluentNHibernate.PersistenceModel persistence_model; + private static IEnumerable mappings; + private static ClassMapping class_mapping; + + private class Target + { + public int Id { get; set; } + public Component ComponentA { get; set; } + public Component ComponentB { get; set; } + } + + private class Component + { + public string Property { get; set; } + } +} + +public class when_compiling_the_mappings_with_multiple_nested_component_mappings +{ + Establish context = () => { + var component_map = new ComponentMap(); + component_map.Component(x => x.NestedComponent1, + c => c.Map(y => y.Property, "PROP1")); + component_map.Component(x => x.NestedComponent2, + c => c.Map(y => y.Property, "PROP2")); + + var class_map = new ClassMap(); + class_map.Id(x => x.Id); + class_map.Component(x => x.Component) + .ColumnPrefix("A_"); + + persistence_model = new FluentNHibernate.PersistenceModel(); + persistence_model.Add(class_map); + persistence_model.Add(component_map); + }; + + Because of = () => { + mappings = persistence_model.BuildMappings(); + class_mapping = mappings.SelectMany(x => x.Classes).First(); + }; + + It should_use_the_column_prefix_for_all_nested_component_columns = () => { + var root_component = class_mapping.Components.First(x => x.Name == "Component"); + + root_component + .Components.First(x => x.Name == "NestedComponent1") + .Properties.SelectMany(x => x.Columns) + .Select(x => x.Name) + .Should().Contain("A_PROP1"); + + root_component + .Components.First(x => x.Name == "NestedComponent2") + .Properties.SelectMany(x => x.Columns) + .Select(x => x.Name) + .Should().Contain("A_PROP2"); + }; + + private static FluentNHibernate.PersistenceModel persistence_model; + private static IEnumerable mappings; + private static ClassMapping class_mapping; + + private class Target + { + public int Id { get; set; } + public Component Component { get; set; } + } + + private class Component + { + public NestedComponent NestedComponent1 { get; set; } + public NestedComponent NestedComponent2 { get; set; } + } + + private class NestedComponent + { + public string Property { get; set; } + } } diff --git a/src/FluentNHibernate.Specs/FluentInterface/ExternalComponentOutputSpecs.cs b/src/FluentNHibernate.Specs/FluentInterface/ExternalComponentOutputSpecs.cs index 9a9b092a1..99630d9c3 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ExternalComponentOutputSpecs.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ExternalComponentOutputSpecs.cs @@ -1,73 +1,73 @@ -using System; -using System.Diagnostics; -using System.Linq; -using FluentNHibernate.Mapping; -using FluentNHibernate.MappingModel.Output; -using Machine.Specifications; -using Machine.Specifications.Model; -using FluentAssertions; - -namespace FluentNHibernate.Specs.FluentInterface; - -public class when_generating_the_output_for_a_resolved_component_reference -{ - Establish context = () => - { - inline_component = new ClassMap(); - inline_component.Id(x => x.Id); - inline_component.Component(x => x.ComponentProperty1, c => c.Map(x => x.Property)); - inline_component.Component(x => x.ComponentProperty2, c => c.Map(x => x.Property)); - - external_component = new ComponentMap(); - external_component.Map(x => x.Property); - - reference_component = new ClassMap(); - reference_component.Id(x => x.Id); - reference_component.Component(x => x.ComponentProperty1); - reference_component.Component(x => x.ComponentProperty2); - }; - - Because of = () => - { - inline_xml = render_xml(x => x.Add(inline_component)); - referenced_xml = render_xml(x => - { - x.Add(reference_component); - x.Add(external_component); - }); - }; - - It should_be_rendered_the_same_as_an_inline_component = () => - referenced_xml.Should().Be(inline_xml); - - - private static string render_xml(Action addMappings) - { - var model = new FluentNHibernate.PersistenceModel(); - - addMappings(model); - - var mappings = model.BuildMappings(); - var doc = new MappingXmlSerializer().Serialize(mappings.First()); - - return doc.OuterXml; - } - - private static ClassMap inline_component; - private static ClassMap reference_component; - private static ComponentMap external_component; - private static string inline_xml; - private static string referenced_xml; - - private class Target - { - public int Id { get; set;} - public Component ComponentProperty1 { get; set; } - public Component ComponentProperty2 { get; set; } - } - - private class Component - { - public string Property { get; set; } - } +using System; +using System.Diagnostics; +using System.Linq; +using FluentNHibernate.Mapping; +using FluentNHibernate.MappingModel.Output; +using Machine.Specifications; +using Machine.Specifications.Model; +using FluentAssertions; + +namespace FluentNHibernate.Specs.FluentInterface; + +public class when_generating_the_output_for_a_resolved_component_reference +{ + Establish context = () => + { + inline_component = new ClassMap(); + inline_component.Id(x => x.Id); + inline_component.Component(x => x.ComponentProperty1, c => c.Map(x => x.Property)); + inline_component.Component(x => x.ComponentProperty2, c => c.Map(x => x.Property)); + + external_component = new ComponentMap(); + external_component.Map(x => x.Property); + + reference_component = new ClassMap(); + reference_component.Id(x => x.Id); + reference_component.Component(x => x.ComponentProperty1); + reference_component.Component(x => x.ComponentProperty2); + }; + + Because of = () => + { + inline_xml = render_xml(x => x.Add(inline_component)); + referenced_xml = render_xml(x => + { + x.Add(reference_component); + x.Add(external_component); + }); + }; + + It should_be_rendered_the_same_as_an_inline_component = () => + referenced_xml.Should().Be(inline_xml); + + + private static string render_xml(Action addMappings) + { + var model = new FluentNHibernate.PersistenceModel(); + + addMappings(model); + + var mappings = model.BuildMappings(); + var doc = new MappingXmlSerializer().Serialize(mappings.First()); + + return doc.OuterXml; + } + + private static ClassMap inline_component; + private static ClassMap reference_component; + private static ComponentMap external_component; + private static string inline_xml; + private static string referenced_xml; + + private class Target + { + public int Id { get; set;} + public Component ComponentProperty1 { get; set; } + public Component ComponentProperty2 { get; set; } + } + + private class Component + { + public string Property { get; set; } + } } diff --git a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/BiDirectionalKeyIssue.cs b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/BiDirectionalKeyIssue.cs index d6c93c279..a3382393c 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/BiDirectionalKeyIssue.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/BiDirectionalKeyIssue.cs @@ -1,78 +1,78 @@ -using System; -using System.Collections.Generic; -using FluentNHibernate.Mapping; - -namespace FluentNHibernate.Specs.FluentInterface.Fixtures.BiDirectionalKeyIssue; - -public abstract class Entity -{ - public Guid Id { get; set; } -} - -public class ContactMap : DomainMap -{ - public ContactMap() - { - HasMany(x => x.EmailAddresses); - HasMany(x => x.PhoneNumbers); - } -} - -public class Contact : Entity -{ - public virtual IEnumerable EmailAddresses { get; set; } - public virtual IEnumerable PhoneNumbers { get; set; } -} - -public class ContactEmail : Entity -{ - public virtual string EmailAddress { get; set; } - public virtual Contact Contact { get; set; } -} - -public class ContactPhone : Entity -{ - public virtual string PhoneNumber { get; set; } -} - -public class ContactEmailMap : DomainMap -{ - public ContactEmailMap() - { - Map(c => c.EmailAddress); - References(x => x.Contact); - } -} - -public class ContactPhoneMap : DomainMap -{ - public ContactPhoneMap() - { - Map(c => c.PhoneNumber); - } -} - -public class DomainMap : ClassMap where T : Entity -{ - public DomainMap() - { - Id(x => x.Id).Column("id").GeneratedBy.GuidComb(); - Table(typeof(T).Name); - } -} - -public class CaseMap : DomainMap -{ - public CaseMap() - { - References(c => c.AlternateContact); - References(c => c.Contact); - Table("Cases"); - } -} - -public class Case : Entity -{ - public virtual Contact Contact { get; set; } - public virtual Contact AlternateContact { get; set; } +using System; +using System.Collections.Generic; +using FluentNHibernate.Mapping; + +namespace FluentNHibernate.Specs.FluentInterface.Fixtures.BiDirectionalKeyIssue; + +public abstract class Entity +{ + public Guid Id { get; set; } +} + +public class ContactMap : DomainMap +{ + public ContactMap() + { + HasMany(x => x.EmailAddresses); + HasMany(x => x.PhoneNumbers); + } +} + +public class Contact : Entity +{ + public virtual IEnumerable EmailAddresses { get; set; } + public virtual IEnumerable PhoneNumbers { get; set; } +} + +public class ContactEmail : Entity +{ + public virtual string EmailAddress { get; set; } + public virtual Contact Contact { get; set; } +} + +public class ContactPhone : Entity +{ + public virtual string PhoneNumber { get; set; } +} + +public class ContactEmailMap : DomainMap +{ + public ContactEmailMap() + { + Map(c => c.EmailAddress); + References(x => x.Contact); + } +} + +public class ContactPhoneMap : DomainMap +{ + public ContactPhoneMap() + { + Map(c => c.PhoneNumber); + } +} + +public class DomainMap : ClassMap where T : Entity +{ + public DomainMap() + { + Id(x => x.Id).Column("id").GeneratedBy.GuidComb(); + Table(typeof(T).Name); + } +} + +public class CaseMap : DomainMap +{ + public CaseMap() + { + References(c => c.AlternateContact); + References(c => c.Contact); + Table("Cases"); + } +} + +public class Case : Entity +{ + public virtual Contact Contact { get; set; } + public virtual Contact AlternateContact { get; set; } } diff --git a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithCollections.cs b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithCollections.cs index 567144113..5dc3bf882 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithCollections.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithCollections.cs @@ -1,30 +1,30 @@ -using System; -using System.Collections.Generic; - -namespace FluentNHibernate.Specs.FluentInterface.Fixtures; - -class EntityWithCollections -{ - public EntityCollectionChild[] ArrayOfChildren { get; set; } - public IList BagOfChildren { get; set; } - public ISet SetOfChildren { get; set; } - - public IList BagOfStrings { get; set; } -} - -class EntityWithFieldCollections -{ - public IList BagOfChildren; -} - -class EntityCollectionChild -{ - public int Position { get; set; } - public AreaComponent Area { get; set; } -} - -class AreaComponent -{ - public int Lat { get; set; } - public int Long { get; set; } +using System; +using System.Collections.Generic; + +namespace FluentNHibernate.Specs.FluentInterface.Fixtures; + +class EntityWithCollections +{ + public EntityCollectionChild[] ArrayOfChildren { get; set; } + public IList BagOfChildren { get; set; } + public ISet SetOfChildren { get; set; } + + public IList BagOfStrings { get; set; } +} + +class EntityWithFieldCollections +{ + public IList BagOfChildren; +} + +class EntityCollectionChild +{ + public int Position { get; set; } + public AreaComponent Area { get; set; } +} + +class AreaComponent +{ + public int Lat { get; set; } + public int Long { get; set; } } diff --git a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithComponent.cs b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithComponent.cs index 8611337a2..4af108574 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithComponent.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithComponent.cs @@ -1,20 +1,20 @@ -using System; -using System.Collections; - -namespace FluentNHibernate.Specs.FluentInterface.Fixtures; - -class EntityWithComponent -{ - public ComponentTarget Component { get; set; } - public IDictionary DynamicComponent { get; set; } -} - -class EntityWithFieldComponent -{ - public ComponentTarget Component; - public IDictionary DynamicComponent; -} - -class ComponentTarget -{ +using System; +using System.Collections; + +namespace FluentNHibernate.Specs.FluentInterface.Fixtures; + +class EntityWithComponent +{ + public ComponentTarget Component { get; set; } + public IDictionary DynamicComponent { get; set; } +} + +class EntityWithFieldComponent +{ + public ComponentTarget Component; + public IDictionary DynamicComponent; +} + +class ComponentTarget +{ } diff --git a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithFields.cs b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithFields.cs index 4791d2c01..bae24fa1f 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithFields.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithFields.cs @@ -1,6 +1,6 @@ -namespace FluentNHibernate.Specs.FluentInterface.Fixtures; - -class EntityWithFields -{ - public string Name; +namespace FluentNHibernate.Specs.FluentInterface.Fixtures; + +class EntityWithFields +{ + public string Name; } diff --git a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithProperties.cs b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithProperties.cs index dda66c51a..6f0c326ea 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithProperties.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithProperties.cs @@ -1,12 +1,12 @@ -namespace FluentNHibernate.Specs.FluentInterface.Fixtures; - -class EntityWithProperties -{ - public string Name { get; set; } -} - -class EntityWithPrivateProperties -{ - private string Name { get; set; } - string name; +namespace FluentNHibernate.Specs.FluentInterface.Fixtures; + +class EntityWithProperties +{ + public string Name { get; set; } +} + +class EntityWithPrivateProperties +{ + private string Name { get; set; } + string name; } diff --git a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithReferences.cs b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithReferences.cs index 59f9e0992..8d21b7e0e 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithReferences.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithReferences.cs @@ -1,9 +1,9 @@ -namespace FluentNHibernate.Specs.FluentInterface.Fixtures; - -class EntityWithReferences -{ - public ReferenceTarget Reference { get; set; } -} - -class ReferenceTarget +namespace FluentNHibernate.Specs.FluentInterface.Fixtures; + +class EntityWithReferences +{ + public ReferenceTarget Reference { get; set; } +} + +class ReferenceTarget {} diff --git a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithVersion.cs b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithVersion.cs index 013d4b90d..41e10c95a 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithVersion.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithVersion.cs @@ -1,8 +1,8 @@ -using System; - -namespace FluentNHibernate.Specs.FluentInterface.Fixtures; - -class EntityWithVersion -{ - public TimeSpan VersionNumber { get; set; } +using System; + +namespace FluentNHibernate.Specs.FluentInterface.Fixtures; + +class EntityWithVersion +{ + public TimeSpan VersionNumber { get; set; } } diff --git a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/IndexTarget.cs b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/IndexTarget.cs index 8ec856e61..46db1d76d 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/IndexTarget.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/IndexTarget.cs @@ -1,4 +1,4 @@ -namespace FluentNHibernate.Specs.FluentInterface.Fixtures; - -class IndexTarget +namespace FluentNHibernate.Specs.FluentInterface.Fixtures; + +class IndexTarget {} diff --git a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/SuperTarget.cs b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/SuperTarget.cs index c3052ab6f..e9a7512b3 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/SuperTarget.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/SuperTarget.cs @@ -1,13 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace FluentNHibernate.Specs.FluentInterface.Fixtures; - -class SuperTarget -{ -} - -class ChildTarget : SuperTarget +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace FluentNHibernate.Specs.FluentInterface.Fixtures; + +class SuperTarget +{ +} + +class ChildTarget : SuperTarget {} diff --git a/src/FluentNHibernate.Specs/FluentInterface/ProviderSpec.cs b/src/FluentNHibernate.Specs/FluentInterface/ProviderSpec.cs index eaf983ba8..fba65674f 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ProviderSpec.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ProviderSpec.cs @@ -1,27 +1,27 @@ -using System; -using FluentNHibernate.Mapping; -using FluentNHibernate.Mapping.Providers; -using FluentNHibernate.MappingModel.ClassBased; - -namespace FluentNHibernate.Specs.FluentInterface; - -public abstract class ProviderSpec -{ - public static ClassMapping map_as_class(Action> setup) - { - var provider = new ClassMap(); - - setup(provider); - - return ((IMappingProvider)provider).GetClassMapping(); - } - - public static SubclassMapping map_as_subclass(Action> setup) - { - var provider = new SubclassMap(); - - setup(provider); - - return ((IIndeterminateSubclassMappingProvider)provider).GetSubclassMapping(SubclassType.Subclass); - } +using System; +using FluentNHibernate.Mapping; +using FluentNHibernate.Mapping.Providers; +using FluentNHibernate.MappingModel.ClassBased; + +namespace FluentNHibernate.Specs.FluentInterface; + +public abstract class ProviderSpec +{ + public static ClassMapping map_as_class(Action> setup) + { + var provider = new ClassMap(); + + setup(provider); + + return ((IMappingProvider)provider).GetClassMapping(); + } + + public static SubclassMapping map_as_subclass(Action> setup) + { + var provider = new SubclassMap(); + + setup(provider); + + return ((IIndeterminateSubclassMappingProvider)provider).GetSubclassMapping(SubclassType.Subclass); + } } diff --git a/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.Component.cs b/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.Component.cs index a5f85310e..4638cf0d5 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.Component.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.Component.cs @@ -1,96 +1,96 @@ -using System.Collections; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.FluentInterface.Fixtures; -using Machine.Specifications; - -namespace FluentNHibernate.Specs.FluentInterface.SubclassMapSpecs; - -public class when_subclass_map_is_told_to_map_a_component : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(m => m.Component(x => x.Component, c => {})); - - Behaves_like a_component_in_a_classlike; - - protected static SubclassMapping mapping; -} - -public class when_subclass_map_is_told_to_map_a_component_from_a_field : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(m => m.Component(x => x.Component, c => { })); - - Behaves_like a_component_in_a_classlike; - - protected static SubclassMapping mapping; -} - -public class when_subclass_map_is_told_to_map_a_component_using_reveal : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(m => m.Component(Reveal.Member("Component"), c => { })); - - Behaves_like a_component_in_a_classlike; - - protected static SubclassMapping mapping; -} - -public class when_subclass_map_is_told_to_map_a_dynamic_component : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(m => m.DynamicComponent(x => x.DynamicComponent, c => { })); - - Behaves_like a_component_in_a_classlike; - - protected static SubclassMapping mapping; -} - -public class when_subclass_map_is_told_to_map_a_dynamic_component_from_a_field : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(m => m.DynamicComponent(x => x.DynamicComponent, c => { })); - - Behaves_like a_component_in_a_classlike; - - protected static SubclassMapping mapping; -} - -public class when_subclass_map_is_told_to_map_a_dynamic_component_using_reveal : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(m => m.DynamicComponent(Reveal.Member("DynamicComponent"), c => { })); - - Behaves_like a_component_in_a_classlike; - - protected static SubclassMapping mapping; -} - -public class when_subclass_map_is_told_to_map_a_reference_component : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(m => m.Component(x => x.Component)); - - Behaves_like a_component_in_a_classlike; - - protected static SubclassMapping mapping; -} - -public class when_subclass_map_is_told_to_map_a_reference_component_from_a_field : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(m => m.Component(x => x.Component)); - - Behaves_like a_component_in_a_classlike; - - protected static SubclassMapping mapping; -} - -public class when_subclass_map_is_told_to_map_a_reference_component_using_reveal : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(m => m.Component(Reveal.Member("Component"))); - - Behaves_like a_component_in_a_classlike; - - protected static SubclassMapping mapping; +using System.Collections; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.FluentInterface.Fixtures; +using Machine.Specifications; + +namespace FluentNHibernate.Specs.FluentInterface.SubclassMapSpecs; + +public class when_subclass_map_is_told_to_map_a_component : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(m => m.Component(x => x.Component, c => {})); + + Behaves_like a_component_in_a_classlike; + + protected static SubclassMapping mapping; +} + +public class when_subclass_map_is_told_to_map_a_component_from_a_field : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(m => m.Component(x => x.Component, c => { })); + + Behaves_like a_component_in_a_classlike; + + protected static SubclassMapping mapping; +} + +public class when_subclass_map_is_told_to_map_a_component_using_reveal : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(m => m.Component(Reveal.Member("Component"), c => { })); + + Behaves_like a_component_in_a_classlike; + + protected static SubclassMapping mapping; +} + +public class when_subclass_map_is_told_to_map_a_dynamic_component : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(m => m.DynamicComponent(x => x.DynamicComponent, c => { })); + + Behaves_like a_component_in_a_classlike; + + protected static SubclassMapping mapping; +} + +public class when_subclass_map_is_told_to_map_a_dynamic_component_from_a_field : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(m => m.DynamicComponent(x => x.DynamicComponent, c => { })); + + Behaves_like a_component_in_a_classlike; + + protected static SubclassMapping mapping; +} + +public class when_subclass_map_is_told_to_map_a_dynamic_component_using_reveal : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(m => m.DynamicComponent(Reveal.Member("DynamicComponent"), c => { })); + + Behaves_like a_component_in_a_classlike; + + protected static SubclassMapping mapping; +} + +public class when_subclass_map_is_told_to_map_a_reference_component : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(m => m.Component(x => x.Component)); + + Behaves_like a_component_in_a_classlike; + + protected static SubclassMapping mapping; +} + +public class when_subclass_map_is_told_to_map_a_reference_component_from_a_field : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(m => m.Component(x => x.Component)); + + Behaves_like a_component_in_a_classlike; + + protected static SubclassMapping mapping; +} + +public class when_subclass_map_is_told_to_map_a_reference_component_using_reveal : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(m => m.Component(Reveal.Member("Component"))); + + Behaves_like a_component_in_a_classlike; + + protected static SubclassMapping mapping; } diff --git a/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.HasMany.cs b/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.HasMany.cs index 25f2d19da..15bac1a9b 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.HasMany.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.HasMany.cs @@ -1,80 +1,80 @@ -using System.Linq; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.FluentInterface.Fixtures; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.FluentInterface.SubclassMapSpecs; - -public class when_subclass_map_is_told_to_map_a_has_many_bag : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(m => m.HasMany(x => x.BagOfChildren)); - - Behaves_like a_bag_in_a_classlike_mapping; - - It should_use_the_containing_type_name_suffixed_with_id_as_the_key_column_name = () => - mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("EntityWithCollections_id"); - - protected static SubclassMapping mapping; -} - -public class when_subclass_map_is_told_to_map_a_has_many_set : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(m => m.HasMany(x => x.SetOfChildren)); - - Behaves_like a_set_in_a_classlike_mapping; - - protected static SubclassMapping mapping; -} - -public class when_subclass_map_is_told_to_map_a_has_many_list_with_default_index : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(m => m.HasMany(x => x.BagOfChildren).AsList()); - - Behaves_like a_list_with_the_default_index_in_a_classlike_mapping; - - protected static SubclassMapping mapping; -} - -public class when_subclass_map_is_told_to_map_a_has_many_list_with_custom_index : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(m => m.HasMany(x => x.BagOfChildren).AsList(x => - { - x.Column("custom-column"); - x.Type(); - })); - - Behaves_like a_list_with_a_custom_index_in_a_classlike_mapping; - - protected static SubclassMapping mapping; -} - -public class when_subclass_map_is_told_to_map_an_has_many_from_a_field : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(m => m.HasMany(x => x.BagOfChildren)); - - Behaves_like a_bag_in_a_classlike_mapping; - - It should_use_the_containing_type_name_suffixed_with_id_as_the_key_column_name = () => - mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("EntityWithFieldCollections_id"); - - protected static SubclassMapping mapping; -} - -public class when_subclass_map_is_told_to_map_an_has_many_using_reveal : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(m => m.HasMany(Reveal.Member("BagOfChildren"))); - - Behaves_like a_bag_in_a_classlike_mapping; - - It should_use_the_containing_type_name_suffixed_with_id_as_the_key_column_name = () => - mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("EntityWithCollections_id"); - - protected static SubclassMapping mapping; +using System.Linq; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.FluentInterface.Fixtures; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.FluentInterface.SubclassMapSpecs; + +public class when_subclass_map_is_told_to_map_a_has_many_bag : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(m => m.HasMany(x => x.BagOfChildren)); + + Behaves_like a_bag_in_a_classlike_mapping; + + It should_use_the_containing_type_name_suffixed_with_id_as_the_key_column_name = () => + mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("EntityWithCollections_id"); + + protected static SubclassMapping mapping; +} + +public class when_subclass_map_is_told_to_map_a_has_many_set : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(m => m.HasMany(x => x.SetOfChildren)); + + Behaves_like a_set_in_a_classlike_mapping; + + protected static SubclassMapping mapping; +} + +public class when_subclass_map_is_told_to_map_a_has_many_list_with_default_index : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(m => m.HasMany(x => x.BagOfChildren).AsList()); + + Behaves_like a_list_with_the_default_index_in_a_classlike_mapping; + + protected static SubclassMapping mapping; +} + +public class when_subclass_map_is_told_to_map_a_has_many_list_with_custom_index : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(m => m.HasMany(x => x.BagOfChildren).AsList(x => + { + x.Column("custom-column"); + x.Type(); + })); + + Behaves_like a_list_with_a_custom_index_in_a_classlike_mapping; + + protected static SubclassMapping mapping; +} + +public class when_subclass_map_is_told_to_map_an_has_many_from_a_field : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(m => m.HasMany(x => x.BagOfChildren)); + + Behaves_like a_bag_in_a_classlike_mapping; + + It should_use_the_containing_type_name_suffixed_with_id_as_the_key_column_name = () => + mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("EntityWithFieldCollections_id"); + + protected static SubclassMapping mapping; +} + +public class when_subclass_map_is_told_to_map_an_has_many_using_reveal : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(m => m.HasMany(Reveal.Member("BagOfChildren"))); + + Behaves_like a_bag_in_a_classlike_mapping; + + It should_use_the_containing_type_name_suffixed_with_id_as_the_key_column_name = () => + mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("EntityWithCollections_id"); + + protected static SubclassMapping mapping; } diff --git a/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.HasOne.cs b/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.HasOne.cs index 9b6b23c8d..d3feaa728 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.HasOne.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.HasOne.cs @@ -1,25 +1,25 @@ -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.FluentInterface.Fixtures; -using Machine.Specifications; - -namespace FluentNHibernate.Specs.FluentInterface.SubclassMapSpecs; - -public class when_subclass_map_is_told_to_map_a_has_one : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(m => m.HasOne(x => x.Reference)); - - Behaves_like a_has_one_in_a_classlike_mapping; - - protected static SubclassMapping mapping; -} - -public class when_subclass_map_is_told_to_map_a_has_one_using_reveal : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(m => m.HasOne(Reveal.Member("Reference"))); - - Behaves_like a_has_one_in_a_classlike_mapping; - - protected static SubclassMapping mapping; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.FluentInterface.Fixtures; +using Machine.Specifications; + +namespace FluentNHibernate.Specs.FluentInterface.SubclassMapSpecs; + +public class when_subclass_map_is_told_to_map_a_has_one : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(m => m.HasOne(x => x.Reference)); + + Behaves_like a_has_one_in_a_classlike_mapping; + + protected static SubclassMapping mapping; +} + +public class when_subclass_map_is_told_to_map_a_has_one_using_reveal : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(m => m.HasOne(Reveal.Member("Reference"))); + + Behaves_like a_has_one_in_a_classlike_mapping; + + protected static SubclassMapping mapping; } diff --git a/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.Property.cs b/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.Property.cs index 6879047b1..a79fbd35a 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.Property.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.Property.cs @@ -1,36 +1,36 @@ -using System.Linq; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.FluentInterface.Fixtures; -using Machine.Specifications; - -namespace FluentNHibernate.Specs.FluentInterface.SubclassMapSpecs; - -public class when_subclass_map_is_told_to_map_a_property : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(o => o.Map(x => x.Name)); - - Behaves_like a_property_in_a_classlike_mapping; - - protected static SubclassMapping mapping; -} - -public class when_subclass_map_is_told_to_map_a_field : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(o => o.Map(x => x.Name)); - - Behaves_like a_property_in_a_classlike_mapping; - - protected static SubclassMapping mapping; -} - -public class when_subclass_map_is_told_to_map_a_private_property_using_reveal : ProviderSpec -{ - Because of = () => - mapping = map_as_subclass(o => o.Map(Reveal.Member("Name"))); - - Behaves_like a_property_in_a_classlike_mapping; - - protected static SubclassMapping mapping; +using System.Linq; +using FluentNHibernate.MappingModel.ClassBased; +using FluentNHibernate.Specs.FluentInterface.Fixtures; +using Machine.Specifications; + +namespace FluentNHibernate.Specs.FluentInterface.SubclassMapSpecs; + +public class when_subclass_map_is_told_to_map_a_property : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(o => o.Map(x => x.Name)); + + Behaves_like a_property_in_a_classlike_mapping; + + protected static SubclassMapping mapping; +} + +public class when_subclass_map_is_told_to_map_a_field : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(o => o.Map(x => x.Name)); + + Behaves_like a_property_in_a_classlike_mapping; + + protected static SubclassMapping mapping; +} + +public class when_subclass_map_is_told_to_map_a_private_property_using_reveal : ProviderSpec +{ + Because of = () => + mapping = map_as_subclass(o => o.Map(Reveal.Member("Name"))); + + Behaves_like a_property_in_a_classlike_mapping; + + protected static SubclassMapping mapping; } diff --git a/src/FluentNHibernate.Specs/FluentNHibernate.Specs.csproj b/src/FluentNHibernate.Specs/FluentNHibernate.Specs.csproj index b0fd5e0f7..3bffa2aa6 100644 --- a/src/FluentNHibernate.Specs/FluentNHibernate.Specs.csproj +++ b/src/FluentNHibernate.Specs/FluentNHibernate.Specs.csproj @@ -1,22 +1,22 @@ - - - - net48;net6.0 - - - - - - - - - - - - - - - - - + + + + net48;net6.0 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionChildEntity.cs b/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionChildEntity.cs index f4862608e..76feb2812 100644 --- a/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionChildEntity.cs +++ b/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionChildEntity.cs @@ -1,4 +1,4 @@ -namespace FluentNHibernate.Specs.PersistenceModel.Fixtures; - -class UnionChildEntity : UnionEntity +namespace FluentNHibernate.Specs.PersistenceModel.Fixtures; + +class UnionChildEntity : UnionEntity {} diff --git a/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionChildEntityMap.cs b/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionChildEntityMap.cs index 7536c4dfd..8d3494cf3 100644 --- a/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionChildEntityMap.cs +++ b/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionChildEntityMap.cs @@ -1,6 +1,6 @@ -using FluentNHibernate.Mapping; - -namespace FluentNHibernate.Specs.PersistenceModel.Fixtures; - -class UnionChildEntityMap : SubclassMap +using FluentNHibernate.Mapping; + +namespace FluentNHibernate.Specs.PersistenceModel.Fixtures; + +class UnionChildEntityMap : SubclassMap {} diff --git a/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionEntity.cs b/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionEntity.cs index 73e5ce81c..79b9aec22 100644 --- a/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionEntity.cs +++ b/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionEntity.cs @@ -1,6 +1,6 @@ -namespace FluentNHibernate.Specs.PersistenceModel.Fixtures; - -class UnionEntity -{ - public int Id { get; set; } +namespace FluentNHibernate.Specs.PersistenceModel.Fixtures; + +class UnionEntity +{ + public int Id { get; set; } } diff --git a/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionEntityMap.cs b/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionEntityMap.cs index 3c32a8ada..c5620b5e6 100644 --- a/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionEntityMap.cs +++ b/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionEntityMap.cs @@ -1,12 +1,12 @@ -using FluentNHibernate.Mapping; - -namespace FluentNHibernate.Specs.PersistenceModel.Fixtures; - -class UnionEntityMap : ClassMap -{ - public UnionEntityMap() - { - Id(x => x.Id); - UseUnionSubclassForInheritanceMapping(); - } +using FluentNHibernate.Mapping; + +namespace FluentNHibernate.Specs.PersistenceModel.Fixtures; + +class UnionEntityMap : ClassMap +{ + public UnionEntityMap() + { + Id(x => x.Id); + UseUnionSubclassForInheritanceMapping(); + } } diff --git a/src/FluentNHibernate.Specs/PersistenceModel/PersistenceModelSpecs.AddingProviders.cs b/src/FluentNHibernate.Specs/PersistenceModel/PersistenceModelSpecs.AddingProviders.cs index 763fcf9f6..6f8817b76 100644 --- a/src/FluentNHibernate.Specs/PersistenceModel/PersistenceModelSpecs.AddingProviders.cs +++ b/src/FluentNHibernate.Specs/PersistenceModel/PersistenceModelSpecs.AddingProviders.cs @@ -1,62 +1,62 @@ -using FluentAssertions; -using FluentNHibernate.Mapping; -using FluentNHibernate.Specs.Automapping.Fixtures; -using Machine.Specifications; - -namespace FluentNHibernate.Specs.PersistenceModel; - -public class when_the_persistence_model_has_a_component_added_by_type : PersistenceModelSpec -{ - Because of = () => - persistence_model.Add(typeof(MyComponentMap)); - - It should_contain_the_mapping = () => - persistence_model.ContainsMapping(typeof(MyComponentMap)).Should().BeTrue(); -} - -public class when_the_persistence_model_has_a_component_instance_added : PersistenceModelSpec -{ - Because of = () => - persistence_model.Add(new MyComponentMap()); - - It should_contain_the_mapping = () => - persistence_model.ContainsMapping(typeof(MyComponentMap)).Should().BeTrue(); -} - -public class when_the_persistence_model_scans_a_source_for_types : PersistenceModelSpec -{ - Because of = () => - persistence_model.AddMappingsFromSource(new StubTypeSource(new[] - { - typeof(MyComponentMap), - typeof(MyClassMap), - typeof(MySubclassMap), - typeof(MyFilterMap), - })); - - It should_contain_the_class_mapping = () => - persistence_model.ContainsMapping(typeof(MyClassMap)).Should().BeTrue(); - - It should_contain_the_component_mapping = () => - persistence_model.ContainsMapping(typeof(MyComponentMap)).Should().BeTrue(); - - It should_contain_the_subclass_mapping = () => - persistence_model.ContainsMapping(typeof(MySubclassMap)).Should().BeTrue(); - - It should_contain_the_filter_mapping = () => - persistence_model.ContainsMapping(typeof(MyFilterMap)).Should().BeTrue(); -} - -public abstract class PersistenceModelSpec -{ - Establish context = () => - persistence_model = new FluentNHibernate.PersistenceModel(); - - protected static FluentNHibernate.PersistenceModel persistence_model; - - protected class MyComponentMap : ComponentMap { } - protected class MyClassMap : ClassMap {} - protected class MySubclassMap : SubclassMap {} - protected class MyFilterMap : FilterDefinition {} - protected class Target { } +using FluentAssertions; +using FluentNHibernate.Mapping; +using FluentNHibernate.Specs.Automapping.Fixtures; +using Machine.Specifications; + +namespace FluentNHibernate.Specs.PersistenceModel; + +public class when_the_persistence_model_has_a_component_added_by_type : PersistenceModelSpec +{ + Because of = () => + persistence_model.Add(typeof(MyComponentMap)); + + It should_contain_the_mapping = () => + persistence_model.ContainsMapping(typeof(MyComponentMap)).Should().BeTrue(); +} + +public class when_the_persistence_model_has_a_component_instance_added : PersistenceModelSpec +{ + Because of = () => + persistence_model.Add(new MyComponentMap()); + + It should_contain_the_mapping = () => + persistence_model.ContainsMapping(typeof(MyComponentMap)).Should().BeTrue(); +} + +public class when_the_persistence_model_scans_a_source_for_types : PersistenceModelSpec +{ + Because of = () => + persistence_model.AddMappingsFromSource(new StubTypeSource(new[] + { + typeof(MyComponentMap), + typeof(MyClassMap), + typeof(MySubclassMap), + typeof(MyFilterMap), + })); + + It should_contain_the_class_mapping = () => + persistence_model.ContainsMapping(typeof(MyClassMap)).Should().BeTrue(); + + It should_contain_the_component_mapping = () => + persistence_model.ContainsMapping(typeof(MyComponentMap)).Should().BeTrue(); + + It should_contain_the_subclass_mapping = () => + persistence_model.ContainsMapping(typeof(MySubclassMap)).Should().BeTrue(); + + It should_contain_the_filter_mapping = () => + persistence_model.ContainsMapping(typeof(MyFilterMap)).Should().BeTrue(); +} + +public abstract class PersistenceModelSpec +{ + Establish context = () => + persistence_model = new FluentNHibernate.PersistenceModel(); + + protected static FluentNHibernate.PersistenceModel persistence_model; + + protected class MyComponentMap : ComponentMap { } + protected class MyClassMap : ClassMap {} + protected class MySubclassMap : SubclassMap {} + protected class MyFilterMap : FilterDefinition {} + protected class Target { } } diff --git a/src/FluentNHibernate.Specs/PersistenceModel/PersistenceModelSpecs.Validation.cs b/src/FluentNHibernate.Specs/PersistenceModel/PersistenceModelSpecs.Validation.cs index 7623725aa..7d08442f1 100644 --- a/src/FluentNHibernate.Specs/PersistenceModel/PersistenceModelSpecs.Validation.cs +++ b/src/FluentNHibernate.Specs/PersistenceModel/PersistenceModelSpecs.Validation.cs @@ -1,130 +1,130 @@ -using System; -using System.Collections.Generic; -using FluentNHibernate.Mapping; -using FluentNHibernate.Visitors; -using Machine.Specifications; -using FluentAssertions; - -namespace FluentNHibernate.Specs.PersistenceModel; - -public class when_the_persistence_model_is_told_to_build_the_mappings_with_a_valid_class_mapping : PersistenceModelValidationSpec -{ - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - - var class_map = new ClassMap(); - class_map.Id(x => x.Id); - - model.Add(class_map); - }; - - Because of = () => - exception = Catch.Exception(() => model.BuildMappings()); - - It shouldnt_throw_any_validation_exceptions = () => - exception.Should().BeNull(); -} - -public class when_the_persistence_model_is_told_to_build_the_mappings_with_a_class_mapping_that_doesnt_have_an_id : PersistenceModelValidationSpec -{ - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Add(new ClassMap()); - }; - - Because of = () => - exception = Catch.Exception(() => model.BuildMappings()); - - It should_throw_a_validation_exception = () => - { - exception.Should().NotBeNull(); - exception.Should().BeOfType(); - }; - - It should_indicate_which_entity_is_missing_the_id = () => - exception.As().RelatedEntity.Should().Be(typeof(Target)); - - It should_explain_how_to_correct_the_error = () => - exception.As().Resolution.Should().Be("Use the Id method to map your identity property. For example: Id(x => x.Id)"); - - It should_provide_a_sufficently_detailed_message_in_the_exception = () => - exception.Message.Should().Be("The entity 'Target' doesn't have an Id mapped. Use the Id method to map your identity property. For example: Id(x => x.Id)."); -} - -public class when_the_persistence_model_is_told_to_build_the_mappings_with_a_many_to_many_relationship_with_inverse_specified_on_both_sides : PersistenceModelValidationSpec -{ - Establish context = () => - { - var left = new ClassMap(); - left.Id(x => x.Id); - left.HasManyToMany(x => x.Rights) - .Inverse(); - var right = new ClassMap(); - right.Id(x => x.Id); - right.HasManyToMany(x => x.Lefts) - .Inverse(); - - model = new FluentNHibernate.PersistenceModel(); - model.Add(left); - model.Add(right); - }; - - Because of = () => - exception = Catch.Exception(() => model.BuildMappings()); - - It should_throw_a_validation_exception = () => - { - exception.Should().NotBeNull(); - exception.Should().BeOfType(); - }; - - It should_indicate_which_entity_has_the_invalid_many_to_many = () => - exception.As().RelatedEntity.Should().Be(typeof(Left)); - - It should_explain_how_to_correct_the_error = () => - exception.As().Resolution.Should().Be("Remove Inverse from one side of the relationship"); - - It should_provide_a_sufficently_detailed_message_in_the_exception = () => - exception.Message.Should().Be("The relationship Left.Rights to Right.Lefts has Inverse specified on both sides. Remove Inverse from one side of the relationship."); -} - -public class when_the_persistence_model_with_validation_disabled_is_told_to_build_the_mappings_with_a_class_mapping_that_doesnt_have_an_id : PersistenceModelValidationSpec -{ - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Add(new ClassMap()); - model.ValidationEnabled = false; - }; - - Because of = () => - exception = Catch.Exception(() => model.BuildMappings()); - - It shouldnt_throw_any_validation_exceptions = () => - exception.Should().BeNull(); -} - -public abstract class PersistenceModelValidationSpec -{ - protected static FluentNHibernate.PersistenceModel model; - protected static Exception exception; - - protected class Target - { - public int Id { get; set; } - } - - protected class Left - { - public int Id { get; set; } - public IList Rights { get; set; } - } - - protected class Right - { - public int Id { get; set; } - public IList Lefts { get; set; } - } +using System; +using System.Collections.Generic; +using FluentNHibernate.Mapping; +using FluentNHibernate.Visitors; +using Machine.Specifications; +using FluentAssertions; + +namespace FluentNHibernate.Specs.PersistenceModel; + +public class when_the_persistence_model_is_told_to_build_the_mappings_with_a_valid_class_mapping : PersistenceModelValidationSpec +{ + Establish context = () => + { + model = new FluentNHibernate.PersistenceModel(); + + var class_map = new ClassMap(); + class_map.Id(x => x.Id); + + model.Add(class_map); + }; + + Because of = () => + exception = Catch.Exception(() => model.BuildMappings()); + + It shouldnt_throw_any_validation_exceptions = () => + exception.Should().BeNull(); +} + +public class when_the_persistence_model_is_told_to_build_the_mappings_with_a_class_mapping_that_doesnt_have_an_id : PersistenceModelValidationSpec +{ + Establish context = () => + { + model = new FluentNHibernate.PersistenceModel(); + model.Add(new ClassMap()); + }; + + Because of = () => + exception = Catch.Exception(() => model.BuildMappings()); + + It should_throw_a_validation_exception = () => + { + exception.Should().NotBeNull(); + exception.Should().BeOfType(); + }; + + It should_indicate_which_entity_is_missing_the_id = () => + exception.As().RelatedEntity.Should().Be(typeof(Target)); + + It should_explain_how_to_correct_the_error = () => + exception.As().Resolution.Should().Be("Use the Id method to map your identity property. For example: Id(x => x.Id)"); + + It should_provide_a_sufficently_detailed_message_in_the_exception = () => + exception.Message.Should().Be("The entity 'Target' doesn't have an Id mapped. Use the Id method to map your identity property. For example: Id(x => x.Id)."); +} + +public class when_the_persistence_model_is_told_to_build_the_mappings_with_a_many_to_many_relationship_with_inverse_specified_on_both_sides : PersistenceModelValidationSpec +{ + Establish context = () => + { + var left = new ClassMap(); + left.Id(x => x.Id); + left.HasManyToMany(x => x.Rights) + .Inverse(); + var right = new ClassMap(); + right.Id(x => x.Id); + right.HasManyToMany(x => x.Lefts) + .Inverse(); + + model = new FluentNHibernate.PersistenceModel(); + model.Add(left); + model.Add(right); + }; + + Because of = () => + exception = Catch.Exception(() => model.BuildMappings()); + + It should_throw_a_validation_exception = () => + { + exception.Should().NotBeNull(); + exception.Should().BeOfType(); + }; + + It should_indicate_which_entity_has_the_invalid_many_to_many = () => + exception.As().RelatedEntity.Should().Be(typeof(Left)); + + It should_explain_how_to_correct_the_error = () => + exception.As().Resolution.Should().Be("Remove Inverse from one side of the relationship"); + + It should_provide_a_sufficently_detailed_message_in_the_exception = () => + exception.Message.Should().Be("The relationship Left.Rights to Right.Lefts has Inverse specified on both sides. Remove Inverse from one side of the relationship."); +} + +public class when_the_persistence_model_with_validation_disabled_is_told_to_build_the_mappings_with_a_class_mapping_that_doesnt_have_an_id : PersistenceModelValidationSpec +{ + Establish context = () => + { + model = new FluentNHibernate.PersistenceModel(); + model.Add(new ClassMap()); + model.ValidationEnabled = false; + }; + + Because of = () => + exception = Catch.Exception(() => model.BuildMappings()); + + It shouldnt_throw_any_validation_exceptions = () => + exception.Should().BeNull(); +} + +public abstract class PersistenceModelValidationSpec +{ + protected static FluentNHibernate.PersistenceModel model; + protected static Exception exception; + + protected class Target + { + public int Id { get; set; } + } + + protected class Left + { + public int Id { get; set; } + public IList Rights { get; set; } + } + + protected class Right + { + public int Id { get; set; } + public IList Lefts { get; set; } + } } diff --git a/src/FluentNHibernate.Specs/PersistenceModel/SubclassSpecs.cs b/src/FluentNHibernate.Specs/PersistenceModel/SubclassSpecs.cs index 432e2644b..4a4a22df8 100644 --- a/src/FluentNHibernate.Specs/PersistenceModel/SubclassSpecs.cs +++ b/src/FluentNHibernate.Specs/PersistenceModel/SubclassSpecs.cs @@ -1,106 +1,106 @@ -using System.Collections.Generic; -using System.Linq; -using FluentNHibernate.Cfg.Db; -using FluentNHibernate.Mapping; -using FluentNHibernate.MappingModel; -using FluentNHibernate.MappingModel.ClassBased; -using FluentNHibernate.Specs.PersistenceModel.Fixtures; -using Machine.Specifications; -using NHibernate.Cfg; -using NHibernate.Tool.hbm2ddl; -using FluentAssertions; - -namespace FluentNHibernate.Specs.PersistenceModel; - -public class when_subclass_map_is_combined_with_a_class_map_flagged_as_union -{ - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Add(new UnionEntityMap()); - model.Add(new UnionChildEntityMap()); - }; - - Because of = () => - mapping = model.BuildMappingFor(); - - It should_map_the_subclass_as_a_union_subclass = () => - mapping.Subclasses.Single().SubclassType.Should().Be(SubclassType.UnionSubclass); - - static FluentNHibernate.PersistenceModel model; - static ClassMapping mapping; -} - -public class when_subclass_map_has_a_has_many_to_another_entity -{ - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Add(new ProductMap()); - model.Add(new SpecialProductMap()); - model.Add(new OptionMap()); - - //cfg = new Configuration(); - //SQLiteConfiguration.Standard.InMemory() - // .ConfigureProperties(cfg); - //model.Configure(cfg); - - //new SchemaExport(cfg).Create(true, false); - }; - - Because of = () => - mappings = model.BuildMappings() - .SelectMany(x => x.Classes); - - It should_only_use_one_column_in_the_target_entity_s_key = () => - mappings.Single(x => x.Type == typeof(Product)) - .Subclasses.Single() - .Collections.Single() - .Key.Columns.Select(x => x.Name) - .Should().ContainSingle(name => name == "SpecialProduct_id"); - - static FluentNHibernate.PersistenceModel model; - static IEnumerable mappings; - static Configuration cfg; - - class Product - { - public int ProductId { get; set; } - } - - class SpecialProduct : Product - { - public ICollection