From 48b250a311d04772f496abc08e33056d77534bbf Mon Sep 17 00:00:00 2001 From: Alex Zaytsev Date: Tue, 1 Nov 2022 13:55:49 +1300 Subject: [PATCH] Convert to file-scoped namespaces --- .editorconfig | 5 + .../CascadeConvention.cs | 39 +- .../Entities/Employee.cs | 17 +- .../Entities/Location.cs | 13 +- .../Entities/Product.cs | 25 +- .../Entities/Store.cs | 45 +- .../ExampleAutomappingConfiguration.cs | 41 +- .../Program.cs | 269 ++- .../Properties/AssemblyInfo.cs | 2 +- .../Entities/Employee.cs | 17 +- src/Examples.FirstProject/Entities/Product.cs | 35 +- src/Examples.FirstProject/Entities/Store.cs | 45 +- .../Mappings/EmployeeMap.cs | 19 +- .../Mappings/LocationMap.cs | 15 +- .../Mappings/ProductMap.cs | 27 +- .../Mappings/StoreMap.cs | 27 +- src/Examples.FirstProject/Program.cs | 205 +- .../Properties/AssemblyInfo.cs | 2 +- .../Component.cs | 7 +- .../Entity.cs | 73 +- .../Overrides/EntityBatchSizeOverride.cs | 13 +- .../Properties/AssemblyInfo.cs | 2 +- .../AutoMapBackwardsCompatibilitySpecs.cs | 74 +- .../AutoPersistenceModelSpecs.Conventions.cs | 125 +- .../Automapping/AutoPersistenceModelSpecs.cs | 153 +- .../AutomappingSpecs.Components.cs | 215 +- .../AutomappingSpecs.ElementCollections.cs | 265 ++- .../AutomappingSpecs.NestedClasses.cs | 134 +- .../AutomappingSpecs.Properties.Enum.cs | 109 +- .../AutomappingSpecs.Relationships.cs | 295 ++- .../Automapping/AutomappingSpecs.Version.cs | 63 +- .../Fixtures/AutomappingSpecExtensions.cs | 147 +- .../Automapping/Fixtures/DictionaryEntity.cs | 15 +- .../Fixtures/EntityUsingPrivateFields.cs | 23 +- .../Fixtures/EntityWithStaticProperties.cs | 13 +- .../Automapping/Fixtures/FakeMembers.cs | 69 +- .../Fixtures/Overrides/EntityTableOverride.cs | 13 +- .../ParentChildSelfReferenceEntity.cs | 15 +- .../Fixtures/ReadOnlyEnumerableEntity.cs | 21 +- .../Fixtures/SelfReferenceEntity.cs | 13 +- .../SelfReferencingCollectionEntity.cs | 13 +- .../Automapping/Fixtures/StubTypeSource.cs | 41 +- .../Automapping/Fixtures/UserTypes.cs | 259 ++- .../Automapping/Fixtures/VersionedEntity.cs | 15 +- .../Automapping/OverrideSpecs.cs | 219 +- .../Automapping/PrivateAutomapperSpecs.cs | 41 +- .../Automapping/PrivateFieldsSpecs.cs | 45 +- .../Conventions/ApplyFilterSpecs.cs | 147 +- .../Conventions/BiDirectionalKeysSpecs.cs | 49 +- .../Conventions/CollectionTypeChangeSpecs.cs | 45 +- .../Conventions/ComponentConventionSpecs.cs | 111 +- .../Conventions/ConventionBuilderSpecs.cs | 43 +- .../Conventions/Fixtures/Child.cs | 27 +- .../Fixtures/CollectionConvention.cs | 19 +- .../Conventions/Fixtures/CollectionTarget.cs | 47 +- .../Fixtures/FilterClassConvention.cs | 51 +- .../Conventions/Fixtures/FilterTarget.cs | 47 +- .../Conventions/Fixtures/FormulaConvention.cs | 25 +- .../Conventions/Fixtures/FormulaTarget.cs | 29 +- .../Conventions/Fixtures/Parent.cs | 25 +- .../Fixtures/SetCollectionEntity.cs | 13 +- .../Fixtures/SetCollectionEntityMap.cs | 15 +- .../SetCompositeElementCollectionEntity.cs | 13 +- .../SetCompositeElementCollectionEntityMap.cs | 17 +- .../Fixtures/SetElementCollectionEntity.cs | 13 +- .../Fixtures/SetElementCollectionEntityMap.cs | 17 +- .../Conventions/Fixtures/TwoPropertyEntity.cs | 15 +- .../Fixtures/TwoPropertyEntityMap.cs | 17 +- .../Conventions/Fixtures/Value.cs | 11 +- .../Conventions/ForeignKeyConventionSpecs.cs | 83 +- .../Conventions/FormulaConventionSpecs.cs | 71 +- .../Registration_diagnostics_specs.cs | 537 +++-- src/FluentNHibernate.Specs/Extensions.cs | 61 +- .../BiDirectionalKeyIssueSpecs.cs | 39 +- .../ClassMapSpecs/ClassMapSpecs.Cache.cs | 23 +- .../ClassMapSpecs/ClassMapSpecs.Component.cs | 151 +- .../ClassMapSpecs.Discriminator.cs | 47 +- .../ClassMapSpecs/ClassMapSpecs.HasMany.cs | 159 +- .../ClassMapSpecs/ClassMapSpecs.HasOne.cs | 31 +- .../ClassMapSpecs/ClassMapSpecs.Id.cs | 67 +- .../ClassMapSpecs/ClassMapSpecs.Property.cs | 59 +- .../ClassMapSpecs/ClassMapSpecs.Subclass.cs | 47 +- .../ClassMapSpecs/ClassMapSpecs.Version.cs | 51 +- .../FluentInterface/ClasslikeBehaviors.cs | 277 ++- .../FluentInterface/ComponentMapSpecs.cs | 597 +++--- .../ExternalComponentOutputSpecs.cs | 97 +- .../Fixtures/BiDirectionalKeyIssue.cs | 109 +- .../Fixtures/EntityWithCollections.cs | 45 +- .../Fixtures/EntityWithComponent.cs | 29 +- .../Fixtures/EntityWithFields.cs | 11 +- .../Fixtures/EntityWithProperties.cs | 21 +- .../Fixtures/EntityWithReferences.cs | 15 +- .../Fixtures/EntityWithVersion.cs | 11 +- .../FluentInterface/Fixtures/IndexTarget.cs | 9 +- .../FluentInterface/Fixtures/SuperTarget.cs | 13 +- .../FluentInterface/ProviderSpec.cs | 29 +- .../SubclassMapSpecs.Component.cs | 129 +- .../SubclassMapSpecs.HasMany.cs | 107 +- .../SubclassMapSpecs.HasOne.cs | 31 +- .../SubclassMapSpecs.Property.cs | 45 +- .../Fixtures/UnionChildEntity.cs | 9 +- .../Fixtures/UnionChildEntityMap.cs | 9 +- .../PersistenceModel/Fixtures/UnionEntity.cs | 11 +- .../Fixtures/UnionEntityMap.cs | 15 +- .../PersistenceModelSpecs.AddingProviders.cs | 113 +- .../PersistenceModelSpecs.Validation.cs | 203 +- .../PersistenceModel/SubclassSpecs.cs | 151 +- .../SerializableSpecs.cs | 31 +- .../Utilities/Fixtures/Target.cs | 23 +- .../Utilities/Fixtures/TargetParent.cs | 11 +- .../Utilities/MemberReflectionSpecs.cs | 312 ++- .../Utilities/RevealSpecs.cs | 197 +- ...irectionalManyToManyPairingVisitorSpecs.cs | 441 ++-- .../AutoMapping/Apm/AbstractBaseClassTests.cs | 101 +- .../Apm/AlterationCollectionTests.cs | 91 +- .../AutoMapping/Apm/AlterationTests.cs | 55 +- .../AutoPersistenceModelTests.Components.cs | 267 ++- .../AutoPersistenceModelTests.Conventions.cs | 267 ++- ...ersistenceModelTests.IgnoringProperties.cs | 157 +- .../AutoPersistenceModelTests.Inheritance.cs | 409 ++-- .../AutoPersistenceModelTests.Overrides.cs | 713 ++++--- .../Apm/AutoPersistenceModelTests.cs | 191 +- .../AutoMapping/Apm/CacheOverrideTests.cs | 39 +- .../AutoMapping/Apm/ConcreteBaseClassTests.cs | 69 +- .../Apm/Conventions/HasManyConventionTests.cs | 95 +- .../HasManyToManyConventionTests.cs | 55 +- .../Conventions/IdentityConventionTests.cs | 47 +- .../Conventions/ReferencesConventionTests.cs | 41 +- .../Apm/Conventions/VersionConventionTests.cs | 49 +- .../AutoMapping/Apm/GenericBaseClassTests.cs | 47 +- .../AutoMapping/Apm/IdentityTests.cs | 93 +- .../IgnoreBaseAutoPersistenceModelTests.cs | 69 +- .../AutoMapping/AutoMapTests.cs | 210 +- .../AutoMapping/AutoMappingTester.cs | 15 +- .../AutoMapping/BaseAutoMapFixture.cs | 51 +- .../AutoMapping/BaseAutoPersistenceTests.cs | 25 +- .../DefaultAutoMappingConfigurationTests.cs | 33 +- .../AutoMapping/InheritanceTests.cs | 101 +- .../JoinedSubclassConventionTests.cs | 21 +- .../AutoMappingOverrideAlterationTests.cs | 91 +- .../Overrides/ClassMappingOverrides.cs | 67 +- .../Overrides/CompositeIdOverrides.cs | 197 +- .../Overrides/HibernateMappingOverrides.cs | 25 +- .../ParentOverridesWithSubclasses.cs | 159 +- .../Overrides/ReferenceComponentOverrides.cs | 55 +- .../AutoMapping/Steps/HasManyStepTests.cs | 187 +- .../Steps/HasManyToManyStepTests.cs | 45 +- .../AutoMapping/Steps/ReferenceStepTests.cs | 97 +- .../AutoMapping/Steps/VersionStepTests.cs | 246 ++- .../AutoMapping/SubclassConventionTests.cs | 69 +- .../AutoMapping/TestFixtures.cs | 2 +- .../UnionSubclassConventionTests.cs | 65 +- .../AutoMapping/UnionSubclassTests.cs | 19 +- .../AutoMapping/VersionTests.cs | 73 +- .../Cfg/Db/CacheSettingsBuilderTester.cs | 177 +- .../Cfg/Db/ConnectionStringBuilderTester.cs | 67 +- .../Cfg/Db/DB2400ConfigurationTester.cs | 77 +- .../Cfg/Db/DB2ConfigurationTester.cs | 121 +- .../Cfg/Db/FirebirdConfigurationTester.cs | 89 +- .../Cfg/Db/IngresConfigurationTester.cs | 113 +- .../Cfg/Db/JetDriverConfigurationTester.cs | 107 +- .../Cfg/Db/MsSqlCeConfigurationTester.cs | 45 +- .../Cfg/Db/MsSqlConfigurationTester.cs | 195 +- .../Cfg/Db/MsSqliteConfigurationTester.cs | 41 +- .../Cfg/Db/MySQLConfigurationTester.cs | 111 +- .../Cfg/Db/OracleClientConfigurationTester.cs | 201 +- .../Db/OracleDataClientConfigurationTester.cs | 235 +-- ...cleManagedDataClientConfigurationTester.cs | 167 +- .../Cfg/Db/PersistenceConfigurationTester.cs | 249 ++- .../Cfg/Db/PostgreSQLConfigurationTester.cs | 153 +- .../Cfg/Db/SQLiteConfigurationTester.cs | 58 +- .../Cfg/Db/SqlAnywhereConfigurationTester.cs | 71 +- .../Cfg/ExceptionSerializationTests.cs | 69 +- .../Cfg/FluentConfigurationTests.cs | 801 ++++--- .../Cfg/FluentlyTests.cs | 37 +- .../Cfg/MappingConfigurationTests.cs | 341 ++- .../SQLiteFrameworkConfigurationFactory.cs | 33 +- .../ConventionFinderTests/AddingTypeTests.cs | 117 +- .../ConventionFinderTests/FindTests.cs | 225 +- .../PropertyAcceptanceCriteriaAnyTests.cs | 211 +- ...opertyAcceptanceCriteriaCollectionTests.cs | 233 +- ...AcceptanceCriteriaEqualComplexTypeTests.cs | 133 +- ...eptanceCriteriaEqualSimpleTypeEvalTests.cs | 133 +- ...yAcceptanceCriteriaEqualSimpleTypeTests.cs | 133 +- ...AcceptanceCriteriaEqualSubPropertyTests.cs | 45 +- ...pertyAcceptanceCriteriaInheritanceTests.cs | 117 +- .../PropertyAcceptanceCriteriaIsAnyTests.cs | 149 +- .../PropertyAcceptanceCriteriaIsSetTests.cs | 353 ++-- .../PropertyAcceptanceCriteriaTests.cs | 169 +- .../ConventionsTests/AccessConventionTests.cs | 215 +- .../ApplyingToModel/ArrayConventionTests.cs | 279 ++- .../ApplyingToModel/ClassConventionTests.cs | 229 +- .../ComponentConventionTests.cs | 121 +- .../CompositeIdConventionTests.cs | 95 +- .../DynamicComponentConventionTests.cs | 133 +- .../HasManyCollectionConventionTests.cs | 391 ++-- .../ApplyingToModel/HasManyConventionTests.cs | 361 ++-- .../HasManyToManyCollectionConventionTests.cs | 301 ++- .../HasManyToManyConventionTests.cs | 371 ++-- .../ApplyingToModel/HasOneConventionTests.cs | 157 +- .../HibernateMappingConventionTests.cs | 127 +- .../ApplyingToModel/IdConventionTests.cs | 279 ++- .../ApplyingToModel/JoinConventionTests.cs | 133 +- .../JoinedSubclassConventionTests.cs | 207 +- .../KeyManyToOneConventionTests.cs | 111 +- .../KeyPropertyConventionTests.cs | 87 +- .../ManyToOneConventionTests.cs | 283 ++- .../PropertyConventionTests.cs | 337 ++- .../SubclassConventionTests.cs | 137 +- .../ApplyingToModel/VersionConventionTests.cs | 241 ++- .../ConventionsTests/AutoImportHelperTests.cs | 51 +- .../ConventionsCollectionTests.cs | 99 +- .../DefaultAccessHelperTests.cs | 51 +- .../DefaultCascadeHelperTests.cs | 51 +- .../DefaultLazyHelperTests.cs | 73 +- .../HasManyForeignKeyNameConventionTests.cs | 2 +- ...cessorBackingFieldNamingConventionTests.cs | 2 +- ...anyToManyChildForeignKeyConventionTests.cs | 2 +- ...sManyToManyJoinTableNameConventionTests.cs | 2 +- ...cessorBackingFieldNamingConventionTests.cs | 2 +- ...lableEnumerationPropertyConventionTests.cs | 2 +- .../Defaults/PrimaryKeyConventionTests.cs | 2 +- .../Defaults/PropertyTypeConventionTests.cs | 2 +- .../ReferenceForeignKeyConventionTests.cs | 2 +- .../Defaults/TableNameConventionTests.cs | 2 +- .../VersionColumnNameConventionTests.cs | 2 +- .../ForeignKeyConventionTests.cs | 165 +- .../ConventionsTests/ForeignKeyHelperTests.cs | 155 +- .../Inspection/AccessTests.cs | 265 ++- .../Inspection/CascadeTests.cs | 107 +- .../ConventionsTests/Inspection/FetchTests.cs | 57 +- .../Inspection/GeneratedTests.cs | 57 +- .../Inspection/IncludeTests.cs | 57 +- .../Inspection/NotFoundTests.cs | 47 +- .../Inspection/OnDeleteTests.cs | 47 +- .../Inspection/OptimisticLockTests.cs | 67 +- .../Inspection/PolymorphismTests.cs | 47 +- .../Inspection/SchemaActionTests.cs | 117 +- .../MixedConventionInstanceTester.cs | 49 +- .../MultipleHelperConventions.cs | 53 +- .../ConventionsTests/OptionalAcceptTests.cs | 121 +- .../ArrayConventionTests.cs | 317 ++- .../ClassConventionTests.cs | 259 ++- .../ComponentConventionTests.cs | 147 +- .../CompositeIdConventionTests.cs | 117 +- .../DynamicComponentConventionTests.cs | 157 +- .../HasManyCollectionConventionTests.cs | 385 ++-- .../HasManyConventionTests.cs | 399 ++-- .../HasManyToManyCollectionConventionTests.cs | 357 ++-- .../HasManyToManyConventionTests.cs | 413 ++-- .../HasOneConventionTests.cs | 189 +- .../HibernateMappingConventionTests.cs | 155 +- .../IdConventionTests.cs | 285 ++- .../JoinConventionTests.cs | 159 +- .../JoinedSubclassConventionTests.cs | 247 ++- .../KeyManyToOneConventionTests.cs | 129 +- .../KeyPropertyConventionTests.cs | 87 +- .../ManyToOneConventionTests.cs | 323 ++- .../PropertyConventionTests.cs | 397 ++-- .../SubclassConventionTests.cs | 179 +- .../VersionConventionTests.cs | 287 ++- .../ConventionsTests/ProxyConventionTester.cs | 285 ++- .../ConventionsTests/ProxyHelperTests.cs | 39 +- .../RunnableConventionsTests.cs | 785 ++++--- src/FluentNHibernate.Testing/Debugging.cs | 17 +- .../DefaultOutputFormatterTests.cs | 161 +- .../DiagnosticConfigurationTests.cs | 95 +- .../Diagnostics/DiagnosticLoggerTests.cs | 313 ++- .../DiagnosticMessageDespatcherTests.cs | 45 +- .../StringLambdaOutputListenerTests.cs | 53 +- .../DomainModel/Access/ComponentModel.cs | 11 +- .../DomainModel/Access/CompositeIdModel.cs | 35 +- .../DomainModel/Access/ManyToManyModel.cs | 13 +- .../DomainModel/Access/ManyToOneModel.cs | 13 +- .../Mappings/CompositeIdModelMapping.cs | 17 +- .../Access/Mappings/ManyToManyModelMapping.cs | 15 +- .../Access/Mappings/ManyToOneModelMapping.cs | 15 +- .../Access/Mappings/OneToOneModelMapping.cs | 13 +- .../Access/Mappings/ParentModelMapping.cs | 75 +- .../DomainModel/Access/OneToOneModel.cs | 11 +- .../DomainModel/Access/ParentModel.cs | 41 +- .../DomainModel/ConnectedTester.cs | 253 ++- .../DomainModel/Employees.cs | 53 +- .../DomainModel/EntityEquality.cs | 135 +- .../DomainModel/InverseOneToManyTester.cs | 111 +- .../AccessStrategyComponentPartTester.cs | 325 ++- .../AccessStrategyManyToOnePartTester.cs | 461 ++-- .../DomainModel/Mapping/AnyPartTester.cs | 375 ++-- .../Mapping/CascadeExpressionTester.cs | 193 +- .../DomainModel/Mapping/ClassCacheTests.cs | 125 +- .../Mapping/ClassMapConventionsTester.cs | 191 +- .../Mapping/ClassMapDynamicInsertTester.cs | 35 +- .../Mapping/ClassMapDynamicUpdateTester.cs | 35 +- .../Mapping/ClassMapOptimisticLockTester.cs | 63 +- .../Mapping/ClassMapXmlCreationTester.cs | 1125 +++++----- .../CollectionCascadeExpressionTester.cs | 45 +- .../Mapping/ComponentElementPartTester.cs | 147 +- .../Mapping/ComponentPartTester.cs | 193 +- .../Mapping/ComponentPropertyMapTester.cs | 433 ++-- .../Mapping/CompositeIdentityPartTester.cs | 421 ++-- .../DomainModel/Mapping/ConventionsTester.cs | 93 +- .../DefaultAccessStrategyClassMapTester.cs | 341 ++- .../Mapping/DynamicComponentTester.cs | 315 ++- .../Mapping/FetchTypeExpressionTester.cs | 91 +- .../DomainModel/Mapping/FilterTester.cs | 373 ++-- .../DomainModel/Mapping/HbmAttributeTests.cs | 49 +- .../DomainModel/Mapping/IdentityPartTester.cs | 965 +++++---- .../DomainModel/Mapping/ImportTester.cs | 53 +- .../DomainModel/Mapping/JoinPartTester.cs | 221 +- .../Mapping/JoinedSubClassTester.cs | 470 ++--- .../Mapping/ManyToManyIntegrationTester.cs | 61 +- ...ySelfReferencedInverseIntegrationTester.cs | 89 +- .../DomainModel/Mapping/ManyToManyTester.cs | 640 +++--- .../DomainModel/Mapping/ManyToOneTester.cs | 351 ++- .../Mapping/MappingPartOutputOrderTests.cs | 144 +- .../DomainModel/Mapping/MappingTester.cs | 283 ++- .../Mapping/MultipleKeyColumnsTester.cs | 39 +- .../Mapping/OneToManyIntegrationTester.cs | 69 +- .../DomainModel/Mapping/OneToManyTester.cs | 1873 ++++++++--------- .../DomainModel/Mapping/OneToOneTester.cs | 171 +- .../DomainModel/Mapping/PropertyPartTester.cs | 1073 +++++----- .../Mapping/StoredProcedureTests.cs | 103 +- .../DomainModel/Mapping/SubClassTester.cs | 1116 +++++----- .../Mapping/UnionSubclassTester.cs | 85 +- .../DomainModel/Mapping/VersionTester.cs | 165 +- .../DomainModel/Mapping/WhereTester.cs | 35 +- .../DomainModel/MemberAccessResolverTests.cs | 147 +- .../DomainModel/MemberBackingFieldTests.cs | 295 ++- .../DomainModel/Music.cs | 93 +- .../DomainModel/NamingTests.cs | 127 +- .../DomainModel/RevealTests.cs | 95 +- src/FluentNHibernate.Testing/EmptySource.cs | 29 +- .../ExpressionToSqlTests.cs | 283 ++- .../AbstractOverride.cs | 17 +- .../AbstractOverrideImplementation.cs | 9 +- .../DummyAlteration1.cs | 11 +- .../DummyAlteration2.cs | 11 +- .../AutoMappingAlterations/DummyOverride.cs | 13 +- .../AutoMappingAlterations/Model/Baz.cs | 13 +- .../AutoMappingAlterations/Model/Qux.cs | 13 +- .../Fixtures/Basic/Person.cs | 13 +- .../Fixtures/HbmOne.cs | 13 +- .../Fixtures/HbmTwo.cs | 15 +- .../MixedMappingsInSameLocation/Bar.cs | 13 +- .../MixedMappingsInSameLocation/Foo.cs | 13 +- .../Mappings/FooMap.cs | 15 +- .../Fixtures/TestPersistenceModel.cs | 13 +- .../AnyMutablePropertyModelGenerationTests.cs | 523 +++-- .../FluentInterfaceTests/BaseModelFixture.cs | 223 +- ...acheMutablePropertyModelGenerationTests.cs | 119 +- .../ClassMapFilterPartModelGenerationTests.cs | 55 +- ...sMapMutablePropertyModelGenerationTests.cs | 335 ++- .../ClassMapSubPartModelGenerationTests.cs | 167 +- .../FluentInterfaceTests/ColumnPartTests.cs | 135 +- ...nentMutablePropertyModelGenerationTests.cs | 203 +- ...mentMutablePropertyModelGenerationTests.cs | 21 +- ...ositeElementSubPartModelGenerationTests.cs | 35 +- ...teIdMutablePropertyModelGenerationTests.cs | 101 +- .../FluentInterfaceTests/CustomPersister.cs | 1071 +++++----- .../FluentInterfaceTests/CustomProxy.cs | 13 +- ...atorMutablePropertyModelGenerationTests.cs | 329 ++- ...nentMutablePropertyModelGenerationTests.cs | 207 +- .../FluentInterfaceTests/ElementPartTests.cs | 95 +- ...pingMutablePropertyModelGenerationTests.cs | 161 +- .../FluentInterfaceTests/IdGeneratorTests.cs | 155 +- .../IdMutablePropertyModelGenerationTests.cs | 407 ++-- ...JoinMutablePropertyModelGenerationTests.cs | 133 +- .../JoinSubPartModelGenerationTests.cs | 125 +- ...lassMutablePropertyModelGenerationTests.cs | 271 ++- ...inedSubclassSubPartModelGenerationTests.cs | 167 +- .../KeyManyToOnePartTests.cs | 111 +- .../KeyPropertyPartTests.cs | 83 +- ...ManyMutablePropertyModelGenerationTests.cs | 583 +++-- .../ManyToManyPartAsTernaryTests.cs | 207 +- .../ManyToManySubPartModelGenerationTests.cs | 11 +- .../ManyToManyTableNameTests.cs | 281 ++- ...oOneMutablePropertyModelGenerationTests.cs | 487 +++-- .../FluentInterfaceTests/ModelTester.cs | 45 +- .../NaturalIdPartTests.cs | 101 +- .../OneToManyMethodAccessTests.cs | 21 +- ...ManyMutablePropertyModelGenerationTests.cs | 559 +++-- .../OneToManyPartAsTernaryTests.cs | 137 +- .../OneToManySubPartModelGenerationTests.cs | 143 +- .../OneToManyTypePreditionTests.cs | 63 +- ...oOneMutablePropertyModelGenerationTests.cs | 203 +- .../PropertyEnumerablesTests.cs | 71 +- ...ertyMutablePropertyModelGenerationTests.cs | 629 +++--- .../StoredProcedurePartGenerationTests.cs | 37 +- ...lassMapForJoinedSubclassConventionTests.cs | 65 +- ...lassMutablePropertyModelGenerationTests.cs | 335 ++- ...inedSubclassSubPartModelGenerationTests.cs | 167 +- ...lassMutablePropertyModelGenerationTests.cs | 303 ++- ...pForSubclassSubPartModelGenerationTests.cs | 283 ++- .../SubclassMapWithUserTypeTests.cs | 223 +- ...lassMutablePropertyModelGenerationTests.cs | 195 +- .../SubclassSubPartModelGenerationTests.cs | 181 +- .../TablePerHierarchyTests.cs | 145 +- ...sionMutablePropertyModelGenerationTests.cs | 297 ++- .../FluentInterfaceTests/WhereTests.cs | 369 ++-- .../Infrastructure/ContainerTester.cs | 71 +- .../MappingModel/AttributeStoreTester.cs | 137 +- .../MappingModel/ClassMappingTester.cs | 271 ++- .../Defaults/PropertyColumnDefaultsTester.cs | 67 +- .../CollectionContentEqualitySpecs.cs | 227 +- .../Equality/MappingEqualitySpecs.cs | 2 +- .../MappingModel/HibernateMappingTester.cs | 71 +- .../Identity/CompositeIdMappingTester.cs | 35 +- .../MappingModel/MappingTestingExtensions.cs | 35 +- .../MappingModel/Output/XmlAnyWriterTester.cs | 273 ++- .../Output/XmlArrayWriterTester.cs | 457 ++-- .../MappingModel/Output/XmlBagWriterTester.cs | 429 ++-- .../Output/XmlCacheWriterTester.cs | 43 +- .../Output/XmlClassWriterTester.cs | 649 +++--- .../XmlCollectionRelationshipWriterTester.cs | 51 +- .../Output/XmlCollectionWriterTester.cs | 93 +- .../Output/XmlColumnWriterTester.cs | 189 +- .../Output/XmlComponentWriterTester.cs | 347 ++- .../Output/XmlCompositeElementWriterTester.cs | 173 +- .../Output/XmlCompositeIdWriterTester.cs | 157 +- .../Output/XmlDiscriminatorWriterTester.cs | 99 +- .../Output/XmlDynamicComponentWriterTester.cs | 279 ++- .../Output/XmlElementWriterTester.cs | 81 +- .../Output/XmlFilterDefinitionWriterTester.cs | 35 +- .../Output/XmlFilterWriterTester.cs | 31 +- .../Output/XmlGeneratorWriterTester.cs | 49 +- .../Output/XmlHibernateMappingWriterTester.cs | 233 +- .../Output/XmlIIndexWriterTester.cs | 47 +- .../MappingModel/Output/XmlIdWriterTester.cs | 115 +- .../Output/XmlIdentityBasedWriterTester.cs | 47 +- .../Output/XmlIndexManyToManyWriterTester.cs | 103 +- .../Output/XmlIndexWriterTester.cs | 63 +- .../Output/XmlInheritanceWriterTester.cs | 51 +- .../Output/XmlJoinWriterTester.cs | 269 ++- .../Output/XmlJoinedSubclassWriterTester.cs | 427 ++-- .../Output/XmlKeyManyToOneWriterTester.cs | 171 +- .../Output/XmlKeyPropertyWriterTester.cs | 111 +- .../MappingModel/Output/XmlKeyWriterTester.cs | 153 +- .../Output/XmlListWriterTester.cs | 341 ++- .../Output/XmlManyToManyWriterTester.cs | 211 +- .../Output/XmlManyToOneWriterTester.cs | 295 ++- .../MappingModel/Output/XmlMapWriterTester.cs | 369 ++-- .../Output/XmlMetaValueWriterTester.cs | 43 +- .../Output/XmlNaturalIdWriterTester.cs | 81 +- .../Output/XmlOneToManyWriterTester.cs | 75 +- .../Output/XmlOneToOneWriterTester.cs | 209 +- .../Output/XmlPropertyWriterTester.cs | 207 +- .../XmlReferenceComponentWriterTester.cs | 345 ++- .../MappingModel/Output/XmlSetWriterTester.cs | 437 ++-- .../Output/XmlStoredProcedureWriterTester.cs | 71 +- .../Output/XmlSubclassWriterTester.cs | 371 ++-- .../Output/XmlTuplizerWriterTester.cs | 81 +- .../Output/XmlVersionWriterTester.cs | 135 +- .../Output/XmlWriterContainerTester.cs | 39 +- .../ReferenceComponentMappingSpecs.cs | 243 ++- .../MappingModel/SortingTests.cs | 55 +- .../JoinPersistenceModelTests.cs | 71 +- .../SeparateSubclassVisitorFixture.cs | 327 ++- .../Properties/AssemblyInfo.cs | 2 +- .../Serialization/SerializationFixture.cs | 27 +- src/FluentNHibernate.Testing/Specification.cs | 92 +- .../SpecificationExtensions.cs | 453 ++-- .../StubTypeSource.cs | 49 +- ...PersistenceSpecificationExtensionsSpecs.cs | 1149 +++++----- .../Testing/PersistenceSpecificationTester.cs | 413 ++-- ...PersistenceSpecificationTransactionTest.cs | 137 +- .../SessionSourceConfigurationTester.cs | 101 +- .../Testing/Values/Entities.cs | 111 +- .../Testing/Values/ListSpecs.cs | 803 ++++--- .../Testing/Values/PropertySpecs.cs | 429 ++-- .../Testing/Values/ReferenceBagSpec.cs | 207 +- .../Testing/Values/ReferenceListSpecs.cs | 59 +- .../Testing/Values/ReferencePropertySpecs.cs | 65 +- .../Testing/XmlWriterTestHelper.cs | 159 +- .../Utils/ReflectionHelperTests.cs | 147 +- .../Utils/TypeReferenceEnumTests.cs | 41 +- .../Utils/TypeReferenceEqualityTests.cs | 275 ++- .../ComponentColumnPrefixVisitorSpecs.cs | 549 +++-- ...omponentReferenceResolutionVisitorSpecs.cs | 235 +-- .../Visitors/RelationshipPairingSpec.cs | 179 +- .../RelationshipPairingVisitorSpec.cs | 91 +- ...ionshipPairingVisitorSpecSupportClasses.cs | 27 +- .../Xml/MappingXmlTestHelper.cs | 161 +- src/FluentNHibernate/AssemblyTypeSource.cs | 83 +- .../AutoMappingOverrideAlteration.cs | 69 +- .../Alterations/IAutoMappingAlteration.cs | 23 +- .../Alterations/IAutoMappingOverride.cs | 23 +- .../Automapping/AutoJoinPart.cs | 27 +- .../Automapping/AutoJoinedSubClassPart.cs | 140 +- src/FluentNHibernate/Automapping/AutoMap.cs | 237 ++- .../Automapping/AutoMapType.cs | 19 +- .../Automapping/AutoMapper.cs | 333 ++- .../Automapping/AutoMapping.cs | 357 ++-- .../AutoMappingAlterationCollection.cs | 143 +- .../Automapping/AutoMappingException.cs | 21 +- .../Automapping/AutoMappingExpressions.cs | 225 +- .../Automapping/AutoPersistenceModel.cs | 815 ++++--- .../Automapping/AutoSubClassPart.cs | 148 +- .../DefaultAutomappingConfiguration.cs | 157 +- .../Automapping/IAutoClasslike.cs | 21 +- .../Automapping/IAutomappingConfiguration.cs | 287 ++- .../Automapping/IPropertyIgnorer.cs | 15 +- .../Automapping/InlineOverride.cs | 37 +- .../PrivateAutoPersistenceModel.cs | 37 +- .../Automapping/Steps/AutoKeyMapper.cs | 27 +- .../Automapping/Steps/CollectionStep.cs | 103 +- .../Automapping/Steps/ComponentStep.cs | 41 +- .../Automapping/Steps/HasManyStep.cs | 49 +- .../Automapping/Steps/HasManyToManyStep.cs | 187 +- .../Automapping/Steps/IAutomappingStep.cs | 13 +- .../Automapping/Steps/IdentityStep.cs | 101 +- .../Automapping/Steps/PropertyStep.cs | 181 +- .../Automapping/Steps/ReferenceStep.cs | 91 +- .../Steps/SimpleTypeCollectionStep.cs | 115 +- .../Automapping/Steps/VersionStep.cs | 111 +- .../Automapping/SubclassStrategy.cs | 15 +- .../Cfg/AutoMappingsContainer.cs | 153 +- .../Cfg/Db/CacheSettingsBuilder.cs | 145 +- .../Cfg/Db/ConnectionStringBuilder.cs | 31 +- .../Cfg/Db/DB2400Configuration.cs | 21 +- .../Cfg/Db/DB2400ConnectionStringBuilder.cs | 73 +- .../Cfg/Db/DB2Configuration.cs | 35 +- .../Cfg/Db/DB2ConnectionStringBuilder.cs | 97 +- .../Cfg/Db/FirebirdConfiguration.cs | 23 +- .../Cfg/Db/IPersistenceConfigurer.cs | 11 +- .../Cfg/Db/IfxDRDAConfiguration.cs | 37 +- .../Cfg/Db/IfxDRDAConnectionStringBuilder.cs | 453 ++-- .../Cfg/Db/IfxOdbcConfiguration.cs | 37 +- .../Cfg/Db/IfxSQLIConfiguration.cs | 37 +- .../Cfg/Db/IfxSQLIConnectionStringBuilder.cs | 435 ++-- .../Cfg/Db/IngresConfiguration.cs | 21 +- .../Cfg/Db/IngresConnectionStringBuilder.cs | 113 +- .../Cfg/Db/JetDriverConfiguration.cs | 23 +- .../Db/JetDriverConnectionStringBuilder.cs | 111 +- .../Cfg/Db/MsSqlCeConfiguration.cs | 29 +- .../Cfg/Db/MsSqlConfiguration.cs | 53 +- .../Cfg/Db/MsSqlConnectionStringBuilder.cs | 133 +- .../Cfg/Db/MsSqliteConfiguration.cs | 48 +- .../Cfg/Db/MySQLConfiguration.cs | 21 +- .../Cfg/Db/MySQLConnectionStringBuilder.cs | 111 +- .../Cfg/Db/OdbcConnectionStringBuilder.cs | 95 +- .../Cfg/Db/OracleClientConfiguration.cs | 49 +- .../Cfg/Db/OracleConfiguration.cs | 71 +- .../Cfg/Db/OracleConnectionStringBuilder.cs | 233 +- .../Cfg/Db/OracleDataClientConfiguration.cs | 49 +- .../OracleManagedDataClientConfiguration.cs | 53 +- .../Cfg/Db/PersistenceConfiguration.cs | 581 +++-- .../Cfg/Db/PostgreSQLConfiguration.cs | 45 +- .../Db/PostgreSQLConnectionStringBuilder.cs | 115 +- .../Cfg/Db/SQLAnywhereConfiguration.cs | 69 +- .../Cfg/Db/SQLiteConfiguration.cs | 57 +- ...ybaseSQLAnywhereConnectionStringBuilder.cs | 89 +- .../Cfg/FluentConfiguration.cs | 469 ++--- .../Cfg/FluentConfigurationException.cs | 75 +- .../Cfg/FluentMappingsContainer.cs | 227 +- src/FluentNHibernate/Cfg/Fluently.cs | 75 +- .../Cfg/HbmMappingsContainer.cs | 117 +- .../Cfg/MappingConfiguration.cs | 149 +- .../Cfg/SetupConventionFinder.cs | 191 +- .../CombinedAssemblyTypeSource.cs | 59 +- .../AcceptanceCriteria/AnyExpectation.cs | 39 +- .../CollectionExpectation.cs | 43 +- .../ConcreteAcceptanceCriteria.cs | 183 +- .../AcceptanceCriteria/EmptyCriterion.cs | 35 +- .../AcceptanceCriteria/EqualCriterion.cs | 35 +- .../AcceptanceCriteria/EvalExpectation.cs | 39 +- .../AcceptanceCriteria/Expectation.cs | 43 +- .../AcceptanceCriteria/IAcceptanceCriteria.cs | 47 +- .../IAcceptanceCriterion.cs | 23 +- .../AcceptanceCriteria/IExpectation.cs | 11 +- .../AcceptanceCriteria/InverseIs.cs | 13 +- .../AcceptanceCriteria/InvertedExpectation.cs | 25 +- .../InverterAcceptanceCriteria.cs | 37 +- .../Conventions/AcceptanceCriteria/Is.cs | 25 +- .../AcceptanceCriteria/SetCriterion.cs | 29 +- .../Conventions/AccessConvention.cs | 131 +- .../AttributeCollectionConvention.cs | 49 +- .../AttributePropertyConvention.cs | 49 +- .../Conventions/ConventionsCollection.cs | 107 +- .../Conventions/DefaultConventionFinder.cs | 293 ++- .../EnumerableExtensionsForConventions.cs | 71 +- .../Conventions/ForeignKeyConvention.cs | 65 +- .../Conventions/Helpers/AutoImport.cs | 29 +- .../Builders/ArrayConventionBuilder.cs | 23 +- .../Helpers/Builders/BagConventionBuilder.cs | 23 +- .../Builders/ClassConventionBuilder.cs | 21 +- .../Builders/CollectionConventionBuilder.cs | 21 +- .../Builders/ComponentConventionBuilder.cs | 21 +- .../Builders/CompositeIdConventionBuilder.cs | 21 +- .../DynamicComponentConventionBuilder.cs | 21 +- .../Builders/HasManyConventionBuilder.cs | 21 +- .../HasManyToManyConventionBuilder.cs | 21 +- .../Builders/HasOneConventionBuilder.cs | 21 +- .../HibernateMappingConventionBuilder.cs | 21 +- .../Helpers/Builders/IdConventionBuilder.cs | 21 +- .../Helpers/Builders/JoinConventionBuilder.cs | 21 +- .../JoinedSubclassConventionBuilder.cs | 21 +- .../Builders/KeyManyToOneConventionBuilder.cs | 21 +- .../Builders/KeyPropertyConventionBuilder.cs | 21 +- .../Helpers/Builders/ListConventionBuilder.cs | 23 +- .../Helpers/Builders/MapConventionBuilder.cs | 23 +- .../OneToManyCollectionConventionBuilder.cs | 39 +- .../Builders/PropertyConventionBuilder.cs | 21 +- .../Builders/ReferenceConventionBuilder.cs | 21 +- .../Helpers/Builders/SetConventionBuilder.cs | 23 +- .../Builders/SubclassConventionBuilder.cs | 21 +- .../Builders/VersionConventionBuilder.cs | 21 +- .../Conventions/Helpers/Cache.cs | 17 +- .../Conventions/Helpers/ConventionBuilder.cs | 173 +- .../Conventions/Helpers/DefaultAccess.cs | 273 ++- .../Conventions/Helpers/DefaultCascade.cs | 65 +- .../Conventions/Helpers/DefaultLazy.cs | 29 +- .../Conventions/Helpers/DynamicInsert.cs | 29 +- .../Conventions/Helpers/DynamicUpdate.cs | 29 +- .../Conventions/Helpers/ForeignKey.cs | 21 +- .../Conventions/Helpers/IConventionBuilder.cs | 19 +- .../Conventions/Helpers/LazyLoad.cs | 29 +- .../Conventions/Helpers/OptimisticLock.cs | 17 +- .../Helpers/Prebuilt/BuiltArrayConvention.cs | 17 +- .../Helpers/Prebuilt/BuiltBagConvention.cs | 17 +- .../Helpers/Prebuilt/BuiltClassConvention.cs | 15 +- .../Prebuilt/BuiltCollectionConvention.cs | 15 +- .../Prebuilt/BuiltComponentConvention.cs | 15 +- .../Prebuilt/BuiltCompositeIdConvention.cs | 15 +- .../Helpers/Prebuilt/BuiltConventionBase.cs | 41 +- .../BuiltDynamicComponentConvention.cs | 15 +- .../Prebuilt/BuiltFuncForeignKeyConvention.cs | 25 +- .../Prebuilt/BuiltHasManyConvention.cs | 15 +- .../Prebuilt/BuiltHasManyToManyConvention.cs | 15 +- .../Helpers/Prebuilt/BuiltHasOneConvention.cs | 15 +- .../BuiltHibernateMappingConvention.cs | 15 +- .../Helpers/Prebuilt/BuiltIdConvention.cs | 15 +- .../Helpers/Prebuilt/BuiltJoinConvention.cs | 15 +- .../Prebuilt/BuiltJoinedSubclassConvention.cs | 15 +- .../Prebuilt/BuiltKeyManyToOneConvention.cs | 15 +- .../Prebuilt/BuiltKeyPropertyConvention.cs | 15 +- .../Helpers/Prebuilt/BuiltListConvention.cs | 17 +- .../BuiltManyToManyCollectionConvention.cs | 15 +- .../Helpers/Prebuilt/BuiltMapConvention.cs | 17 +- .../BuiltOneToManyCollectionConvention.cs | 15 +- .../Prebuilt/BuiltPropertyConvention.cs | 15 +- .../Helpers/Prebuilt/BuiltProxyConvention.cs | 25 +- .../Prebuilt/BuiltReferenceConvention.cs | 15 +- .../Helpers/Prebuilt/BuiltSetConvention.cs | 17 +- .../Prebuilt/BuiltSubclassConvention.cs | 13 +- .../BuiltSuffixForeignKeyConvention.cs | 25 +- .../Prebuilt/BuiltVersionConvention.cs | 15 +- .../Conventions/Helpers/PrimaryKey.cs | 35 +- .../Conventions/Helpers/Proxy.cs | 13 +- .../Conventions/Helpers/Table.cs | 25 +- .../Conventions/IAnyConvention.cs | 9 +- .../Conventions/IArrayConvention.cs | 11 +- .../Conventions/IArrayConventionAcceptance.cs | 11 +- .../Conventions/IBagConvention.cs | 11 +- .../Conventions/IBagConventionAcceptance.cs | 11 +- .../Conventions/IClassConvention.cs | 17 +- .../Conventions/IClassConventionAcceptance.cs | 9 +- .../Conventions/ICollectionConvention.cs | 9 +- .../ICollectionConventionAcceptance.cs | 9 +- .../Conventions/IColumnConvention.cs | 9 +- .../IColumnConventionAcceptance.cs | 9 +- .../Conventions/IComponentConvention.cs | 17 +- .../IComponentConventionAcceptance.cs | 9 +- .../ICompositeIdentityConvention.cs | 9 +- .../ICompositeIdentityConventionAcceptance.cs | 9 +- .../Conventions/IConvention.cs | 57 +- .../Conventions/IConventionFinder.cs | 123 +- .../IDynamicComponentConvention.cs | 17 +- .../IDynamicComponentConventionAcceptance.cs | 9 +- .../Conventions/IHasManyConvention.cs | 9 +- .../IHasManyConventionAcceptance.cs | 9 +- .../Conventions/IHasManyToManyConvention.cs | 9 +- .../IHasManyToManyConventionAcceptance.cs | 9 +- .../Conventions/IHasOneConvention.cs | 15 +- .../IHasOneConventionAcceptance.cs | 9 +- .../IHibernateMappingConvention.cs | 17 +- .../Conventions/IIdConvention.cs | 17 +- .../Conventions/IIdConventionAcceptance.cs | 9 +- .../Conventions/IIndexConvention.cs | 9 +- .../Conventions/IIndexConventionAcceptance.cs | 9 +- .../Conventions/IIndexManyToManyConvention.cs | 9 +- .../IIndexManyToManyConventionAcceptance.cs | 9 +- .../Conventions/IJoinConvention.cs | 15 +- .../Conventions/IJoinConventionAcceptance.cs | 9 +- .../Conventions/IJoinedSubclassConvention.cs | 15 +- .../IJoinedSubclassConventionAcceptance.cs | 9 +- .../Conventions/IKeyManyToOneConvention.cs | 9 +- .../IKeyManyToOneConventionAcceptance.cs | 9 +- .../Conventions/IKeyPropertyConvention.cs | 9 +- .../IKeyPropertyConventionAcceptance.cs | 9 +- .../Conventions/IListConvention.cs | 11 +- .../Conventions/IListConventionAcceptance.cs | 11 +- .../Conventions/IMapConvention.cs | 11 +- .../Conventions/IMapConventionAcceptance.cs | 11 +- .../Conventions/IPropertyConvention.cs | 17 +- .../IPropertyConventionAcceptance.cs | 9 +- .../Conventions/IReferenceConvention.cs | 17 +- .../IReferenceConventionAcceptance.cs | 9 +- .../Conventions/ISetConvention.cs | 11 +- .../Conventions/ISetConventionAcceptance.cs | 11 +- .../Conventions/ISubclassConvention.cs | 15 +- .../ISubclassConventionAcceptance.cs | 9 +- .../Conventions/IUserTypeConvention.cs | 9 +- .../Conventions/IVersionConvention.cs | 15 +- .../IVersionConventionAcceptance.cs | 9 +- .../Conventions/Inspections/AnyInspector.cs | 159 +- .../Conventions/Inspections/CacheInspector.cs | 79 +- .../Inspections/CamelCasePrefix.cs | 19 +- .../Conventions/Inspections/Cascade.cs | 111 +- .../Conventions/Inspections/ClassInspector.cs | 399 ++-- .../Inspections/CollectionInspector.cs | 338 ++- .../Inspections/ColumnBasedInspector.cs | 147 +- .../Inspections/ColumnInspector.cs | 155 +- .../Inspections/ComponentBaseInspector.cs | 215 +- .../Inspections/ComponentInspector.cs | 39 +- .../Inspections/CompositeElementInspector.cs | 93 +- .../Inspections/CompositeIdentityInspector.cs | 115 +- .../Inspections/DiscriminatorInspector.cs | 95 +- .../Inspections/DynamicComponentInspector.cs | 29 +- .../Inspections/ElementInspector.cs | 81 +- .../Conventions/Inspections/Fetch.cs | 103 +- .../Conventions/Inspections/Generated.cs | 111 +- .../Inspections/HibernateMappingInspector.cs | 91 +- .../Inspections/IAccessInspector.cs | 11 +- .../Conventions/Inspections/IAnyInspector.cs | 33 +- .../Inspections/IArrayInspector.cs | 11 +- .../Conventions/Inspections/IBagInspector.cs | 11 +- .../Inspections/ICacheInspector.cs | 15 +- .../Inspections/IClassInspector.cs | 67 +- .../Inspections/ICollectionInspector.cs | 63 +- .../Inspections/IColumnInspector.cs | 31 +- .../Inspections/IComponentBaseInspector.cs | 37 +- .../Inspections/IComponentInspector.cs | 11 +- .../Inspections/ICompositeElementInspector.cs | 17 +- .../ICompositeIdentityInspector.cs | 17 +- .../Inspections/IDiscriminatorInspector.cs | 39 +- .../Inspections/IDynamicComponentInspector.cs | 9 +- .../Inspections/IElementInspector.cs | 17 +- .../IExposedThroughPropertyInspector.cs | 11 +- .../Inspections/IGeneratorInspector.cs | 75 +- .../Inspections/IHibernateMappingInspector.cs | 21 +- .../Inspections/IIdentityInspector.cs | 35 +- .../Inspections/IIdentityInspectorBase.cs | 15 +- .../Inspections/IIndexInspector.cs | 11 +- .../Inspections/IIndexInspectorBase.cs | 11 +- .../Inspections/IIndexManyToManyInspector.cs | 13 +- .../Conventions/Inspections/IInspector.cs | 29 +- .../Conventions/Inspections/IJoinInspector.cs | 33 +- .../Inspections/IJoinedSubclassInspector.cs | 19 +- .../Conventions/Inspections/IKeyInspector.cs | 17 +- .../Inspections/IKeyManyToOneInspector.cs | 23 +- .../Inspections/IKeyPropertyInspector.cs | 19 +- .../Inspections/ILazyLoadInspector.cs | 11 +- .../Conventions/Inspections/IListInspector.cs | 11 +- .../IManyToManyCollectionInspector.cs | 13 +- .../Inspections/IManyToManyInspector.cs | 39 +- .../Inspections/IManyToOneInspector.cs | 37 +- .../Conventions/Inspections/IMapInspector.cs | 11 +- .../Inspections/IMetaValueInspector.cs | 13 +- .../IOneToManyCollectionInspector.cs | 13 +- .../Inspections/IOneToManyInspector.cs | 13 +- .../Inspections/IOneToOneInspector.cs | 27 +- .../Inspections/IParentInspector.cs | 13 +- .../Inspections/IPropertyInspector.cs | 47 +- .../Inspections/IReadOnlyInspector.cs | 11 +- .../Inspections/IRelationshipInspector.cs | 11 +- .../Conventions/Inspections/ISetInspector.cs | 11 +- .../Inspections/ISubclassInspector.cs | 13 +- .../Inspections/ISubclassInspectorBase.cs | 43 +- .../Inspections/IVersionInspector.cs | 41 +- .../Inspections/IdentityInspector.cs | 115 +- .../Conventions/Inspections/Include.cs | 113 +- .../Conventions/Inspections/IndexInspector.cs | 65 +- .../Inspections/IndexManyToManyInspector.cs | 73 +- .../Inspections/InspectorModelMapper.cs | 45 +- .../Conventions/Inspections/JoinInspector.cs | 169 +- .../Conventions/Inspections/JoinInstance.cs | 103 +- .../Inspections/JoinedSubclassInspector.cs | 285 ++- .../Conventions/Inspections/KeyInspector.cs | 81 +- .../Inspections/KeyManyToOneInspector.cs | 107 +- .../Inspections/KeyPropertyInspector.cs | 89 +- .../Inspections/LowerCasePrefix.cs | 19 +- .../Inspections/ManyToManyInspector.cs | 131 +- .../Inspections/ManyToOneInspector.cs | 191 +- .../Inspections/MetaValueInspector.cs | 69 +- .../Conventions/Inspections/NotFound.cs | 81 +- .../Conventions/Inspections/OnDelete.cs | 81 +- .../Inspections/OneToManyInspector.cs | 83 +- .../Inspections/OneToOneInspector.cs | 119 +- .../Conventions/Inspections/OptimisticLock.cs | 107 +- .../Inspections/ParentInspector.cs | 65 +- .../Inspections/PascalCasePrefix.cs | 21 +- .../Conventions/Inspections/Polymorphism.cs | 81 +- .../Conventions/Inspections/Prefix.cs | 27 +- .../Inspections/PropertyInspector.cs | 159 +- .../Conventions/Inspections/SchemaAction.cs | 97 +- .../Inspections/SubclassInspector.cs | 253 ++- .../Inspections/UnmappedPropertyException.cs | 21 +- .../Inspections/VersionInspector.cs | 103 +- .../Conventions/Instances/AccessInstance.cs | 211 +- .../Conventions/Instances/AnyInstance.cs | 25 +- .../Conventions/Instances/CacheInstance.cs | 115 +- .../Conventions/Instances/CascadeInstance.cs | 67 +- .../Conventions/Instances/ClassInstance.cs | 201 +- .../Instances/CollectionCascadeInstance.cs | 35 +- .../Instances/CollectionInstance.cs | 424 ++-- .../Conventions/Instances/ColumnInstance.cs | 43 +- .../Instances/ComponentInstance.cs | 111 +- .../Instances/CompositeIdentityInstance.cs | 91 +- .../Instances/DynamicComponentInstance.cs | 103 +- .../Conventions/Instances/ElementInstance.cs | 69 +- .../Conventions/Instances/FetchInstance.cs | 41 +- .../Instances/GeneratedInstance.cs | 49 +- .../Instances/GeneratorInstance.cs | 995 +++++---- .../Instances/HibernateMappingInstance.cs | 87 +- .../Conventions/Instances/IAccessInstance.cs | 47 +- .../Conventions/Instances/IAnyInstance.cs | 11 +- .../Conventions/Instances/IArrayInstance.cs | 11 +- .../Conventions/Instances/IBagInstance.cs | 11 +- .../Conventions/Instances/ICacheInstance.cs | 27 +- .../Conventions/Instances/ICascadeInstance.cs | 19 +- .../Conventions/Instances/IClassInstance.cs | 101 +- .../Instances/ICollectionCascadeInstance.cs | 13 +- .../Instances/ICollectionInstance.cs | 81 +- .../Conventions/Instances/IColumnInstance.cs | 15 +- .../Instances/IComponentInstance.cs | 45 +- .../Instances/ICompositeIdentityInstance.cs | 23 +- .../Conventions/Instances/IElementInstance.cs | 17 +- .../Conventions/Instances/IFetchInstance.cs | 15 +- .../Instances/IGeneratedInstance.cs | 43 +- .../Instances/IGeneratorInstance.cs | 99 +- .../Instances/IHibernateMappingInstance.cs | 25 +- .../Instances/IIdentityInstance.cs | 47 +- .../Conventions/Instances/IIndexInstance.cs | 9 +- .../Instances/IIndexInstanceBase.cs | 11 +- .../Instances/IIndexManyToManyInstance.cs | 11 +- .../Conventions/Instances/IInsertInstance.cs | 17 +- .../Conventions/Instances/IJoinInstance.cs | 29 +- .../Instances/IJoinedSubclassInstance.cs | 45 +- .../Conventions/Instances/IKeyInstance.cs | 19 +- .../Instances/IKeyManyToOneInstance.cs | 21 +- .../Instances/IKeyPropertyInstance.cs | 13 +- .../Conventions/Instances/IListInstance.cs | 11 +- .../IManyToManyCollectionInstance.cs | 73 +- .../Instances/IManyToManyInstance.cs | 31 +- .../Instances/IManyToOneInstance.cs | 95 +- .../Conventions/Instances/IMapInstance.cs | 11 +- .../Instances/INotFoundInstance.cs | 13 +- .../Instances/INullableInstance.cs | 11 +- .../Instances/IOneToManyCollectionInstance.cs | 85 +- .../Instances/IOneToManyInstance.cs | 11 +- .../Instances/IOneToOneInstance.cs | 75 +- .../Instances/IOptimisticLockInstance.cs | 17 +- .../Instances/IPropertyInstance.cs | 75 +- .../Instances/IReadOnlyInstance.cs | 13 +- .../Instances/IRelationshipInstance.cs | 15 +- .../Instances/ISchemaActionInstance.cs | 23 +- .../Conventions/Instances/ISetInstance.cs | 11 +- .../Instances/ISubclassInstance.cs | 49 +- .../Conventions/Instances/IUpdateInstance.cs | 13 +- .../Conventions/Instances/IVersionInstance.cs | 57 +- .../Conventions/Instances/IdentityInstance.cs | 205 +- .../Conventions/Instances/IndexInstance.cs | 41 +- .../Instances/IndexManyToManyInstance.cs | 49 +- .../Instances/JoinedSubclassInstance.cs | 179 +- .../Conventions/Instances/KeyInstance.cs | 71 +- .../Instances/KeyManyToOneInstance.cs | 67 +- .../Instances/KeyPropertyInstance.cs | 35 +- .../Instances/ManyToManyCollectionInstance.cs | 85 +- .../Instances/ManyToManyInstance.cs | 87 +- .../Instances/ManyToOneInstance.cs | 237 ++- .../Conventions/Instances/NotFoundInstance.cs | 33 +- .../Instances/OneToManyCollectionInstance.cs | 75 +- .../Instances/OneToManyInstance.cs | 43 +- .../Conventions/Instances/OneToOneInstance.cs | 135 +- .../Instances/OptimisticLockInstance.cs | 49 +- .../Conventions/Instances/PropertyInstance.cs | 335 ++- .../Instances/SchemaActionInstance.cs | 91 +- .../Conventions/Instances/SubclassInstance.cs | 141 +- .../Conventions/Instances/VersionInstance.cs | 205 +- .../ManyToManyTableNameConvention.cs | 83 +- .../Conventions/MultipleAttribute.cs | 11 +- .../ObjectExtensionsForConventions.cs | 21 +- .../Conventions/ProxyConvention.cs | 165 +- .../Conventions/UserTypeConvention.cs | 47 +- src/FluentNHibernate/Data/Entity.cs | 107 +- .../Diagnostics/AutomappingType.cs | 11 +- .../Diagnostics/ConsoleOutputListener.cs | 77 +- .../Diagnostics/DefaultDiagnosticLogger.cs | 143 +- .../DefaultDiagnosticMessageDispatcher.cs | 27 +- .../Diagnostics/DefaultOutputFormatter.cs | 291 ++- .../Diagnostics/DiagnosticResults.cs | 39 +- .../Diagnostics/DiagnosticsConfiguration.cs | 173 +- .../Diagnostics/IDiagnosticListener.cs | 11 +- .../Diagnostics/IDiagnosticLogger.cs | 25 +- .../IDiagnosticMessageDispatcher.cs | 13 +- .../IDiagnosticResultsFormatter.cs | 11 +- .../Diagnostics/NullDiagnosticsLogger.cs | 41 +- src/FluentNHibernate/Diagnostics/ScanPhase.cs | 13 +- .../Diagnostics/ScannedSource.cs | 13 +- .../Diagnostics/SkippedAutomappingType.cs | 47 +- .../Diagnostics/StringLambdaOutputListener.cs | 37 +- src/FluentNHibernate/Driver/MsSQLiteDriver.cs | 115 +- src/FluentNHibernate/DummyMethodInfo.cs | 161 +- src/FluentNHibernate/DummyPropertyInfo.cs | 205 +- src/FluentNHibernate/Extensions.cs | 29 +- src/FluentNHibernate/ITypeSource.cs | 21 +- .../Infrastructure/Container.cs | 39 +- .../NetStandardSerialization.cs | 307 ++- .../Infrastructure/ResolveException.cs | 21 +- .../Infrastructure/Serialization.cs | 27 +- src/FluentNHibernate/Mapping/Access.cs | 261 ++- .../Mapping/AccessStrategyBuilder.cs | 421 ++-- src/FluentNHibernate/Mapping/AnyPart.cs | 377 ++-- src/FluentNHibernate/Mapping/Attributes.cs | 9 +- .../Mapping/BaseAccessStrategyBuilder.cs | 379 ++-- src/FluentNHibernate/Mapping/CachePart.cs | 191 +- .../Mapping/CascadeExpression.cs | 255 ++- .../Mapping/CheckTypeExpression.cs | 37 +- src/FluentNHibernate/Mapping/ClassMap.cs | 1229 ++++++----- .../Mapping/ClasslikeMapBase.cs | 909 ++++---- .../Mapping/CollectionCascadeExpression.cs | 57 +- .../Mapping/CollectionTypeResolver.cs | 39 +- .../Mapping/ColumnMappingCollection.cs | 107 +- src/FluentNHibernate/Mapping/ColumnPart.cs | 165 +- src/FluentNHibernate/Mapping/ComponentMap.cs | 107 +- src/FluentNHibernate/Mapping/ComponentPart.cs | 95 +- .../Mapping/ComponentPartBase.cs | 305 ++- .../Mapping/CompositeElementPart.cs | 353 ++-- .../Mapping/CompositeIdentityPart.cs | 461 ++-- .../Mapping/DiscriminatorPart.cs | 413 ++-- .../Mapping/DiscriminatorValue.cs | 43 +- .../Mapping/DynamicComponentPart.cs | 101 +- src/FluentNHibernate/Mapping/ElementPart.cs | 171 +- .../Mapping/FetchTypeExpression.cs | 71 +- .../Mapping/FilterDefinition.cs | 97 +- src/FluentNHibernate/Mapping/FilterPart.cs | 113 +- .../Mapping/GeneratorBuilder.cs | 645 +++--- .../Mapping/GenericEnumMapper.cs | 17 +- .../Mapping/HibernateMappingPart.cs | 133 +- .../Mapping/IFilterDefinition.cs | 15 +- .../IdentityGenerationStrategyBuilder.cs | 1189 ++++++----- src/FluentNHibernate/Mapping/IdentityPart.cs | 509 +++-- src/FluentNHibernate/Mapping/ImportPart.cs | 41 +- .../Mapping/IndexManyToManyPart.cs | 95 +- src/FluentNHibernate/Mapping/IndexPart.cs | 77 +- .../Mapping/InvalidPrefixException.cs | 25 +- src/FluentNHibernate/Mapping/JoinPart.cs | 283 ++- .../Mapping/JoinedSubClassPart.cs | 257 ++- .../Mapping/KeyManyToOnePart.cs | 137 +- .../Mapping/KeyPropertyPart.cs | 77 +- src/FluentNHibernate/Mapping/Laziness.cs | 79 +- src/FluentNHibernate/Mapping/ListIndexPart.cs | 127 +- .../Mapping/ManyToManyPart.cs | 633 +++--- src/FluentNHibernate/Mapping/ManyToOnePart.cs | 663 +++--- .../Mapping/MappingProviderStore.cs | 369 ++-- src/FluentNHibernate/Mapping/Member.cs | 819 ++++--- .../Mapping/MemberAccessResolver.cs | 65 +- src/FluentNHibernate/Mapping/Naming.cs | 73 +- .../Mapping/NamingStrategy.cs | 97 +- src/FluentNHibernate/Mapping/NaturalIdPart.cs | 204 +- .../Mapping/NestedCompositeElementPart.cs | 33 +- .../Mapping/NotFoundExpression.cs | 57 +- src/FluentNHibernate/Mapping/OneToManyPart.cs | 395 ++-- src/FluentNHibernate/Mapping/OneToOnePart.cs | 365 ++-- .../Mapping/OptimisticLockBuilder.cs | 153 +- src/FluentNHibernate/Mapping/ParamBuilder.cs | 27 +- .../Mapping/ParentPropertyPart.cs | 19 +- .../Mapping/PolymorphismBuilder.cs | 53 +- src/FluentNHibernate/Mapping/Prefix.cs | 39 +- .../Mapping/PropertyGeneratedBuilder.cs | 69 +- src/FluentNHibernate/Mapping/PropertyPart.cs | 597 +++--- .../Mapping/Providers/IAnyMappingProvider.cs | 11 +- .../Providers/ICacheMappingProvider.cs | 11 +- .../Providers/ICollectionMappingProvider.cs | 11 +- .../Providers/IComponentMappingProvider.cs | 11 +- .../ICompositeElementMappingProvider.cs | 11 +- .../Providers/ICompositeIdMappingProvider.cs | 11 +- .../IDiscriminatorMappingProvider.cs | 11 +- .../Providers/IElementMappingProvider.cs | 11 +- .../IExternalComponentMappingProvider.cs | 13 +- .../Providers/IFilterMappingProvider.cs | 11 +- .../Providers/IHibernateMappingProvider.cs | 11 +- .../Providers/IIdentityMappingProvider.cs | 11 +- .../IIndeterminateSubclassMappingProvider.cs | 15 +- ...minateSubclassMappingProviderCollection.cs | 15 +- .../Mapping/Providers/IJoinMappingProvider.cs | 11 +- .../Providers/IManyToOneMappingProvider.cs | 11 +- .../Providers/INaturalIdMappingProvider.cs | 11 +- .../INestedCompositeElementMappingProvider.cs | 11 +- .../Providers/IOneToOneMappingProvider.cs | 11 +- .../Providers/IPropertyMappingProvider.cs | 11 +- .../IReferenceComponentMappingProvider.cs | 11 +- .../IStoredProcedureMappingProvider.cs | 11 +- .../Providers/ISubclassMappingProviders.cs | 11 +- .../Providers/IVersionMappingProvider.cs | 11 +- ...minateSubclassMappingProviderCollection.cs | 51 +- .../Mapping/ReferenceComponentPart.cs | 85 +- .../Mapping/SchemaActionBuilder.cs | 109 +- .../Mapping/StoredProcedurePart.cs | 37 +- src/FluentNHibernate/Mapping/SubClassPart.cs | 231 +- src/FluentNHibernate/Mapping/SubclassMap.cs | 653 +++--- src/FluentNHibernate/Mapping/ToManyBase.cs | 1339 ++++++------ src/FluentNHibernate/Mapping/TuplizerPart.cs | 105 +- src/FluentNHibernate/Mapping/TypeMapping.cs | 17 +- .../Mapping/VersionGeneratedBuilder.cs | 41 +- src/FluentNHibernate/Mapping/VersionPart.cs | 421 ++-- .../MappingModel/AnyMapping.cs | 243 ++- .../MappingModel/AttributeStore.cs | 119 +- .../MappingModel/CacheMapping.cs | 119 +- .../MappingModel/ClassBased/ClassMapping.cs | 435 ++-- .../ClassBased/ClassMappingBase.cs | 325 ++- .../ClassBased/ComponentMapping.cs | 141 +- .../ClassBased/ComponentMappingBase.cs | 139 +- .../MappingModel/ClassBased/ComponentType.cs | 105 +- .../ClassBased/ExternalComponentMapping.cs | 27 +- .../ClassBased/IComponentMapping.cs | 63 +- .../ClassBased/ReferenceComponentMapping.cs | 363 ++-- .../ClassBased/SubclassMapping.cs | 279 ++- .../MappingModel/ClassBased/SubclassType.cs | 107 +- .../Collections/AttributeLayeredValues.cs | 157 +- .../MappingModel/Collections/Collection.cs | 19 +- .../Collections/CollectionMapping.cs | 465 ++-- .../Collections/CompositeElementMapping.cs | 181 +- .../Collections/ElementMapping.cs | 151 +- .../ICollectionRelationshipMapping.cs | 17 +- .../MappingModel/Collections/IIndexMapping.cs | 13 +- .../Collections/IndexManyToManyMapping.cs | 159 +- .../MappingModel/Collections/IndexMapping.cs | 149 +- .../Collections/LayeredColumns.cs | 83 +- .../MappingModel/Collections/LayeredValues.cs | 21 +- .../MappingModel/Collections/Lazy.cs | 45 +- .../Collections/ManyToManyMapping.cs | 237 ++- .../NestedCompositeElementMapping.cs | 51 +- .../Collections/OneToManyMapping.cs | 127 +- .../MappingModel/Collections/SortType.cs | 13 +- .../MappingModel/ColumnBasedMappingBase.cs | 83 +- .../MappingModel/ColumnMapping.cs | 209 +- .../Conventions/ConventionException.cs | 37 +- .../MappingModel/DiscriminatorMapping.cs | 129 +- .../MappingModel/EqualityExtensions.cs | 59 +- .../MappingModel/FilterDefinitionMapping.cs | 123 +- .../MappingModel/FilterMapping.cs | 107 +- .../MappingModel/HibernateMapping.cs | 241 ++- .../MappingModel/IHasColumnMappings.cs | 15 +- .../MappingModel/IHasMappedMembers.cs | 37 +- src/FluentNHibernate/MappingModel/IMapping.cs | 15 +- .../MappingModel/IRelationship.cs | 11 +- .../Identity/CompositeIdMapping.cs | 175 +- .../MappingModel/Identity/GeneratorMapping.cs | 109 +- .../Identity/ICompositeIdKeyMapping.cs | 15 +- .../MappingModel/Identity/IIdentityMapping.cs | 9 +- .../MappingModel/Identity/IdMapping.cs | 145 +- .../Identity/KeyManyToOneMapping.cs | 171 +- .../Identity/KeyPropertyMapping.cs | 145 +- .../MappingModel/ImportMapping.cs | 99 +- .../MappingModel/JoinMapping.cs | 267 ++- .../MappingModel/KeyMapping.cs | 183 +- src/FluentNHibernate/MappingModel/Layer.cs | 17 +- .../MappingModel/ManyToOneMapping.cs | 255 ++- .../MappingModel/MappedMembers.cs | 438 ++-- .../MappingModel/MappingBase.cs | 23 +- .../MappingModel/MetaValueMapping.cs | 105 +- .../MappingModel/NaturalIdMapping.cs | 99 +- .../MappingModel/OneToOneMapping.cs | 175 +- .../Output/BaseXmlComponentWriter.cs | 75 +- .../Output/CollectionAttributeWriter.cs | 165 +- .../MappingModel/Output/IXmlWriter.cs | 11 +- .../Output/IXmlWriterServiceLocator.cs | 11 +- .../Output/MappingXmlSerializer.cs | 23 +- .../Output/Sorting/BaseXmlNodeSorter.cs | 77 +- .../MappingModel/Output/Sorting/SortValue.cs | 13 +- .../Output/Sorting/XmlClasslikeNodeSorter.cs | 129 +- .../Output/Sorting/XmlCollectionNodeSorter.cs | 47 +- .../Output/Sorting/XmlIdNodeSorter.cs | 27 +- .../Output/Sorting/XmlNodeSorter.cs | 13 +- .../MappingModel/Output/XmlAnyWriter.cs | 101 +- .../MappingModel/Output/XmlArrayWriter.cs | 55 +- .../MappingModel/Output/XmlBagWriter.cs | 41 +- .../MappingModel/Output/XmlCacheWriter.cs | 39 +- .../MappingModel/Output/XmlClassWriter.cs | 243 ++- .../MappingModel/Output/XmlClassWriterBase.cs | 103 +- .../Output/XmlCollectionRelationshipWriter.cs | 51 +- .../Output/XmlCollectionWriter.cs | 83 +- .../MappingModel/Output/XmlColumnWriter.cs | 77 +- .../MappingModel/Output/XmlComponentWriter.cs | 71 +- .../Output/XmlCompositeElementWriter.cs | 105 +- .../Output/XmlCompositeIdWriter.cs | 85 +- .../Output/XmlDiscriminatorWriter.cs | 69 +- .../MappingModel/Output/XmlElementWriter.cs | 61 +- .../Output/XmlFilterDefinitionWriter.cs | 53 +- .../MappingModel/Output/XmlFilterWriter.cs | 39 +- .../MappingModel/Output/XmlGeneratorWriter.cs | 45 +- .../Output/XmlHibernateMappingWriter.cs | 127 +- .../MappingModel/Output/XmlIIndexWriter.cs | 51 +- .../MappingModel/Output/XmlIdWriter.cs | 81 +- .../Output/XmlIdentityBasedWriter.cs | 51 +- .../MappingModel/Output/XmlImportWriter.cs | 39 +- .../Output/XmlIndexManyToManyWriter.cs | 65 +- .../MappingModel/Output/XmlIndexWriter.cs | 99 +- .../MappingModel/Output/XmlJoinWriter.cs | 153 +- .../Output/XmlKeyManyToOneWriter.cs | 81 +- .../Output/XmlKeyPropertyWriter.cs | 85 +- .../MappingModel/Output/XmlKeyWriter.cs | 77 +- .../MappingModel/Output/XmlListWriter.cs | 55 +- .../Output/XmlManyToManyWriter.cs | 101 +- .../MappingModel/Output/XmlManyToOneWriter.cs | 109 +- .../MappingModel/Output/XmlMapWriter.cs | 63 +- .../MappingModel/Output/XmlMetaValueWriter.cs | 39 +- .../MappingModel/Output/XmlNaturalIdWriter.cs | 85 +- .../MappingModel/Output/XmlOneToManyWriter.cs | 43 +- .../MappingModel/Output/XmlOneToOneWriter.cs | 71 +- .../MappingModel/Output/XmlParentWriter.cs | 39 +- .../MappingModel/Output/XmlPropertyWriter.cs | 91 +- .../MappingModel/Output/XmlSetWriter.cs | 45 +- .../Output/XmlStoredProcedureWriter.cs | 55 +- .../MappingModel/Output/XmlSubclassWriter.cs | 159 +- .../MappingModel/Output/XmlTuplizerWriter.cs | 69 +- .../MappingModel/Output/XmlVersionWriter.cs | 73 +- .../MappingModel/Output/XmlWriterContainer.cs | 197 +- .../MappingModel/Output/XmlWriterFactory.cs | 17 +- .../Output/XmlWriterServiceLocator.cs | 25 +- .../MappingModel/ParentMapping.cs | 105 +- .../MappingModel/PropertyMapping.cs | 173 +- .../MappingModel/StoredProcedureMapping.cs | 151 +- .../MappingModel/TuplizerMapping.cs | 115 +- .../MappingModel/TuplizerMode.cs | 15 +- .../MappingModel/TypeReference.cs | 297 ++- .../MappingModel/VersionMapping.cs | 131 +- .../MissingConstructorException.cs | 21 +- src/FluentNHibernate/PersistenceModel.cs | 535 +++-- .../Properties/AssemblyInfo.cs | 2 +- src/FluentNHibernate/Reveal.cs | 109 +- src/FluentNHibernate/SessionSource.cs | 117 +- .../Testing/PersistenceSpecification.cs | 149 +- .../PersistenceSpecificationExtensions.cs | 823 ++++---- ...onSessionSourceForSQLiteInMemoryTesting.cs | 69 +- src/FluentNHibernate/Testing/Values/List.cs | 159 +- .../Testing/Values/Property.cs | 239 ++- .../Testing/Values/ReferenceBag.cs | 77 +- .../Testing/Values/ReferenceList.cs | 23 +- .../Testing/Values/ReferenceProperty.cs | 19 +- .../UnknownPropertyException.cs | 47 +- .../Utils/CollectionExtensions.cs | 27 +- src/FluentNHibernate/Utils/ExpressionToSql.cs | 229 +- src/FluentNHibernate/Utils/Extensions.cs | 117 +- .../Utils/ObservableDictionary.cs | 285 ++- .../Utils/Reflection/Accessor.cs | 23 +- .../Utils/Reflection/ExpressionBuilder.cs | 39 +- .../Utils/Reflection/PropertyChain.cs | 141 +- .../Utils/Reflection/ReflectionHelper.cs | 195 +- .../Utils/Reflection/SingleMember.cs | 99 +- .../Utils/ReflectionExtensions.cs | 13 +- src/FluentNHibernate/Utils/StringLikeness.cs | 107 +- src/FluentNHibernate/Utils/XmlExtensions.cs | 115 +- .../AmbiguousComponentReferenceException.cs | 31 +- .../Visitors/ComponentColumnPrefixVisitor.cs | 73 +- .../ComponentReferenceResolutionVisitor.cs | 93 +- .../Visitors/ConventionVisitor.cs | 393 ++-- .../Visitors/DefaultMappingModelVisitor.cs | 317 ++- .../Visitors/IMappingModelVisitor.cs | 157 +- .../Visitors/ManyToManyTableNameVisitor.cs | 37 +- .../MissingExternalComponentException.cs | 31 +- .../Visitors/NullMappingModelVisitor.cs | 425 ++-- .../Visitors/RelationshipKeyPairingVisitor.cs | 23 +- .../Visitors/RelationshipPairingVisitor.cs | 357 ++-- .../Visitors/SeparateSubclassVisitor.cs | 237 ++- ...olvedComponentReferenceVisitedException.cs | 31 +- .../Visitors/ValidationException.cs | 25 +- .../Visitors/ValidationVisitor.cs | 73 +- 1169 files changed, 70003 insertions(+), 71172 deletions(-) diff --git a/.editorconfig b/.editorconfig index 873452dcb..49eb1ac3b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,6 +13,11 @@ indent_size = 2 [*.cs] indent_style = space indent_size = 4 +insert_final_newline = true + +csharp_style_namespace_declarations = file_scoped + +dotnet_diagnostic.IDE0161.severity = warning [*.cake] indent_style = space diff --git a/src/Examples.FirstAutomappedProject/CascadeConvention.cs b/src/Examples.FirstAutomappedProject/CascadeConvention.cs index 63a09ca00..9dc6bf5af 100644 --- a/src/Examples.FirstAutomappedProject/CascadeConvention.cs +++ b/src/Examples.FirstAutomappedProject/CascadeConvention.cs @@ -1,28 +1,27 @@ using FluentNHibernate.Conventions; using FluentNHibernate.Conventions.Instances; -namespace Examples.FirstAutomappedProject +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 { - /// - /// 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) { - public void Apply(IManyToOneInstance instance) - { - instance.Cascade.All(); - } + instance.Cascade.All(); + } - public void Apply(IOneToManyCollectionInstance instance) - { - instance.Cascade.All(); - } + public void Apply(IOneToManyCollectionInstance instance) + { + instance.Cascade.All(); + } - public void Apply(IManyToManyCollectionInstance instance) - { - instance.Cascade.All(); - } + public void Apply(IManyToManyCollectionInstance instance) + { + instance.Cascade.All(); } -} \ No newline at end of file +} diff --git a/src/Examples.FirstAutomappedProject/Entities/Employee.cs b/src/Examples.FirstAutomappedProject/Entities/Employee.cs index 49f0922db..cfda3a8b3 100644 --- a/src/Examples.FirstAutomappedProject/Entities/Employee.cs +++ b/src/Examples.FirstAutomappedProject/Entities/Employee.cs @@ -1,10 +1,9 @@ -namespace Examples.FirstAutomappedProject.Entities +namespace Examples.FirstAutomappedProject.Entities; + +public class Employee { - 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; } - } -} \ No newline at end of file + 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 850beb602..3be27c222 100644 --- a/src/Examples.FirstAutomappedProject/Entities/Location.cs +++ b/src/Examples.FirstAutomappedProject/Entities/Location.cs @@ -1,8 +1,7 @@ -namespace Examples.FirstAutomappedProject.Entities +namespace Examples.FirstAutomappedProject.Entities; + +public class Location { - public class Location - { - public virtual int Aisle { get; set; } - public virtual int Shelf { get; set; } - } -} \ No newline at end of file + 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 92ec4cbec..6ca0bf243 100644 --- a/src/Examples.FirstAutomappedProject/Entities/Product.cs +++ b/src/Examples.FirstAutomappedProject/Entities/Product.cs @@ -1,18 +1,17 @@ using System.Collections.Generic; -namespace Examples.FirstAutomappedProject.Entities +namespace Examples.FirstAutomappedProject.Entities; + +public class Product { - 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 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 Product() + { + StoresStockedIn = new List(); } -} \ No newline at end of file +} diff --git a/src/Examples.FirstAutomappedProject/Entities/Store.cs b/src/Examples.FirstAutomappedProject/Entities/Store.cs index 62b59cad9..3e6884a09 100644 --- a/src/Examples.FirstAutomappedProject/Entities/Store.cs +++ b/src/Examples.FirstAutomappedProject/Entities/Store.cs @@ -1,30 +1,29 @@ using System.Collections.Generic; -namespace Examples.FirstAutomappedProject.Entities +namespace Examples.FirstAutomappedProject.Entities; + +public class Store { - 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 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 Store() + { + Products = new List(); + Staff = new List(); + } - public virtual void AddProduct(Product product) - { - product.StoresStockedIn.Add(this); - Products.Add(product); - } + 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); - } + public virtual void AddEmployee(Employee employee) + { + employee.Store = this; + Staff.Add(employee); } -} \ No newline at end of file +} diff --git a/src/Examples.FirstAutomappedProject/ExampleAutomappingConfiguration.cs b/src/Examples.FirstAutomappedProject/ExampleAutomappingConfiguration.cs index 9a75497f0..e3bb64278 100644 --- a/src/Examples.FirstAutomappedProject/ExampleAutomappingConfiguration.cs +++ b/src/Examples.FirstAutomappedProject/ExampleAutomappingConfiguration.cs @@ -2,28 +2,27 @@ using Examples.FirstAutomappedProject.Entities; using FluentNHibernate.Automapping; -namespace Examples.FirstAutomappedProject +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 { - /// - /// 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) { - 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"; - } + // 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); - } + 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); } -} \ No newline at end of file +} diff --git a/src/Examples.FirstAutomappedProject/Program.cs b/src/Examples.FirstAutomappedProject/Program.cs index 262741401..dd5d56833 100644 --- a/src/Examples.FirstAutomappedProject/Program.cs +++ b/src/Examples.FirstAutomappedProject/Program.cs @@ -8,165 +8,164 @@ using NHibernate.Cfg; using NHibernate.Tool.hbm2ddl; -namespace Examples.FirstAutomappedProject +namespace Examples.FirstAutomappedProject; + +/// +/// Example automapped project. +/// +/// Points of interest: +/// Program.CreateSessionFactory() +/// Program.CreateAutomappings() +/// +/// ExampleAutomappingConfiguration +/// CascadeConvention +/// +class Program { - /// - /// Example automapped project. - /// - /// Points of interest: - /// Program.CreateSessionFactory() - /// Program.CreateAutomappings() - /// - /// ExampleAutomappingConfiguration - /// CascadeConvention - /// - class Program + private const string DbFile = "firstProgram.db"; + + static void Main() { - private const string DbFile = "firstProgram.db"; + // create our NHibernate session factory + var sessionFactory = CreateSessionFactory(); - static void Main() + using (var session = sessionFactory.OpenSession()) { - // create our NHibernate session factory - var sessionFactory = CreateSessionFactory(); - - using (var session = sessionFactory.OpenSession()) + // populate the database + using (var transaction = session.BeginTransaction()) { - // 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(); - } + // 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()) + using (var session = sessionFactory.OpenSession()) + { + // retreive all stores and display them + using (session.BeginTransaction()) { - // retreive all stores and display them - using (session.BeginTransaction()) - { - var stores = session.CreateCriteria(typeof(Store)) - .List(); + var stores = session.CreateCriteria(typeof(Store)) + .List(); - foreach (var store in stores) - { - WriteStorePretty(store); - } + 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(); - } + Console.ReadKey(); + } - /// - /// 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(); - } + 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(); + } - 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); - } + /// + /// 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 WriteStorePretty(Store store) - { - Console.WriteLine(store.Name); - Console.WriteLine(" Products:"); - - foreach (var product in store.Products) - { - Console.WriteLine(" " + product.Name); - } + 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); + } - Console.WriteLine(" Staff:"); + private static void WriteStorePretty(Store store) + { + Console.WriteLine(store.Name); + Console.WriteLine(" Products:"); + + foreach (var product in store.Products) + { + Console.WriteLine(" " + product.Name); + } - foreach (var employee in store.Staff) - { - Console.WriteLine(" " + employee.FirstName + " " + employee.LastName); - } + Console.WriteLine(" Staff:"); - Console.WriteLine(); + foreach (var employee in store.Staff) + { + Console.WriteLine(" " + employee.FirstName + " " + employee.LastName); } - public static void AddProductsToStore(Store store, params Product[] products) + Console.WriteLine(); + } + + public static void AddProductsToStore(Store store, params Product[] products) + { + foreach (var product in products) { - foreach (var product in products) - { - store.AddProduct(product); - } + store.AddProduct(product); } + } - public static void AddEmployeesToStore(Store store, params Employee[] employees) + public static void AddEmployeesToStore(Store store, params Employee[] employees) + { + foreach (var employee in employees) { - foreach (var employee in employees) - { - store.AddEmployee(employee); - } + store.AddEmployee(employee); } } -} \ No newline at end of file +} diff --git a/src/Examples.FirstAutomappedProject/Properties/AssemblyInfo.cs b/src/Examples.FirstAutomappedProject/Properties/AssemblyInfo.cs index a0f494ee0..31b149844 100644 --- a/src/Examples.FirstAutomappedProject/Properties/AssemblyInfo.cs +++ b/src/Examples.FirstAutomappedProject/Properties/AssemblyInfo.cs @@ -2,4 +2,4 @@ using System.Runtime.InteropServices; [assembly: ComVisible(false)] -[assembly: CLSCompliant(true)] \ No newline at end of file +[assembly: CLSCompliant(true)] diff --git a/src/Examples.FirstProject/Entities/Employee.cs b/src/Examples.FirstProject/Entities/Employee.cs index 2a6c6a71d..6f20f130d 100644 --- a/src/Examples.FirstProject/Entities/Employee.cs +++ b/src/Examples.FirstProject/Entities/Employee.cs @@ -1,12 +1,11 @@ using Examples.FirstProject.Entities; -namespace Examples.FirstProject.Entities +namespace Examples.FirstProject.Entities; + +public class Employee { - 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; } - } -} \ No newline at end of file + 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 8a15c329f..b8dc2c376 100644 --- a/src/Examples.FirstProject/Entities/Product.cs +++ b/src/Examples.FirstProject/Entities/Product.cs @@ -1,24 +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; } +namespace Examples.FirstProject.Entities; - public Product() - { - StoresStockedIn = new List(); - } - } +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 class Location + public Product() { - public virtual int Aisle { get; set; } - public virtual int Shelf { get; set; } + StoresStockedIn = new List(); } -} \ No newline at end of file +} + +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 5b53b4af4..72d874ffe 100644 --- a/src/Examples.FirstProject/Entities/Store.cs +++ b/src/Examples.FirstProject/Entities/Store.cs @@ -1,30 +1,29 @@ using System.Collections.Generic; -namespace Examples.FirstProject.Entities +namespace Examples.FirstProject.Entities; + +public class Store { - 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 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 Store() + { + Products = new List(); + Staff = new List(); + } - public virtual void AddProduct(Product product) - { - product.StoresStockedIn.Add(this); - Products.Add(product); - } + 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); - } + public virtual void AddEmployee(Employee employee) + { + employee.Store = this; + Staff.Add(employee); } -} \ No newline at end of file +} diff --git a/src/Examples.FirstProject/Mappings/EmployeeMap.cs b/src/Examples.FirstProject/Mappings/EmployeeMap.cs index 6606836a6..c37fc4c2b 100644 --- a/src/Examples.FirstProject/Mappings/EmployeeMap.cs +++ b/src/Examples.FirstProject/Mappings/EmployeeMap.cs @@ -1,16 +1,15 @@ using Examples.FirstProject.Entities; using FluentNHibernate.Mapping; -namespace Examples.FirstProject.Mappings +namespace Examples.FirstProject.Mappings; + +public class EmployeeMap : ClassMap { - public class EmployeeMap : ClassMap + public EmployeeMap() { - public EmployeeMap() - { - Id(x => x.Id); - Map(x => x.FirstName); - Map(x => x.LastName); - References(x => x.Store); - } + Id(x => x.Id); + Map(x => x.FirstName); + Map(x => x.LastName); + References(x => x.Store); } -} \ No newline at end of file +} diff --git a/src/Examples.FirstProject/Mappings/LocationMap.cs b/src/Examples.FirstProject/Mappings/LocationMap.cs index 8d4661ee4..e2b32f636 100644 --- a/src/Examples.FirstProject/Mappings/LocationMap.cs +++ b/src/Examples.FirstProject/Mappings/LocationMap.cs @@ -1,14 +1,13 @@ using Examples.FirstProject.Entities; using FluentNHibernate.Mapping; -namespace Examples.FirstProject.Mappings +namespace Examples.FirstProject.Mappings; + +public class LocationMap : ComponentMap { - public class LocationMap : ComponentMap + public LocationMap() { - public LocationMap() - { - Map(x => x.Aisle); - Map(x => x.Shelf); - } + Map(x => x.Aisle); + Map(x => x.Shelf); } -} \ No newline at end of file +} diff --git a/src/Examples.FirstProject/Mappings/ProductMap.cs b/src/Examples.FirstProject/Mappings/ProductMap.cs index 657ffe2a2..b2e8e3d97 100644 --- a/src/Examples.FirstProject/Mappings/ProductMap.cs +++ b/src/Examples.FirstProject/Mappings/ProductMap.cs @@ -1,21 +1,20 @@ using Examples.FirstProject.Entities; using FluentNHibernate.Mapping; -namespace Examples.FirstProject.Mappings +namespace Examples.FirstProject.Mappings; + +public class ProductMap : ClassMap { - public class ProductMap : ClassMap + public ProductMap() { - public ProductMap() - { - Id(x => x.Id); - Map(x => x.Name); - Map(x => x.Price); - HasManyToMany(x => x.StoresStockedIn) - .Cascade.All() - .Inverse() - .Table("StoreProduct"); + 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); - } + Component(x => x.Location); } -} \ No newline at end of file +} diff --git a/src/Examples.FirstProject/Mappings/StoreMap.cs b/src/Examples.FirstProject/Mappings/StoreMap.cs index 2784504f8..3f8f15b75 100644 --- a/src/Examples.FirstProject/Mappings/StoreMap.cs +++ b/src/Examples.FirstProject/Mappings/StoreMap.cs @@ -1,20 +1,19 @@ using Examples.FirstProject.Entities; using FluentNHibernate.Mapping; -namespace Examples.FirstProject.Mappings +namespace Examples.FirstProject.Mappings; + +public class StoreMap : ClassMap { - public class StoreMap : ClassMap + public StoreMap() { - 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(); - } + Id(x => x.Id); + Map(x => x.Name); + HasManyToMany(x => x.Products) + .Cascade.All() + .Table("StoreProduct"); + HasMany(x => x.Staff) + .Cascade.All() + .Inverse(); } -} \ No newline at end of file +} diff --git a/src/Examples.FirstProject/Program.cs b/src/Examples.FirstProject/Program.cs index ea53c1724..1f7236879 100644 --- a/src/Examples.FirstProject/Program.cs +++ b/src/Examples.FirstProject/Program.cs @@ -7,132 +7,131 @@ using NHibernate.Cfg; using NHibernate.Tool.hbm2ddl; -namespace Examples.FirstProject +namespace Examples.FirstProject; + +class Program { - class Program + private const string DbFile = "firstProgram.db"; + + static void Main() { - private const string DbFile = "firstProgram.db"; + // create our NHibernate session factory + var sessionFactory = CreateSessionFactory(); - static void Main() + using (var session = sessionFactory.OpenSession()) { - // create our NHibernate session factory - var sessionFactory = CreateSessionFactory(); - - using (var session = sessionFactory.OpenSession()) + // populate the database + using (var transaction = session.BeginTransaction()) { - // 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(); - } + // 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()) + using (var session = sessionFactory.OpenSession()) + { + // retreive all stores and display them + using (session.BeginTransaction()) { - // retreive all stores and display them - using (session.BeginTransaction()) - { - var stores = session.CreateCriteria(typeof(Store)) - .List(); + var stores = session.CreateCriteria(typeof(Store)) + .List(); - foreach (var store in stores) - { - WriteStorePretty(store); - } + 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(); - } + Console.ReadKey(); + } - 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 ISessionFactory CreateSessionFactory() + { + return Fluently.Configure() + .Database(SQLiteConfiguration.Standard + .UsingFile(DbFile)) + .Mappings(m => + m.FluentMappings.AddFromAssemblyOf()) + .ExposeConfiguration(BuildSchema) + .BuildSessionFactory(); + } - private static void WriteStorePretty(Store store) - { - Console.WriteLine(store.Name); - Console.WriteLine(" Products:"); - - foreach (var product in store.Products) - { - Console.WriteLine(" " + product.Name); - } + 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); + } - Console.WriteLine(" Staff:"); + private static void WriteStorePretty(Store store) + { + Console.WriteLine(store.Name); + Console.WriteLine(" Products:"); + + foreach (var product in store.Products) + { + Console.WriteLine(" " + product.Name); + } - foreach (var employee in store.Staff) - { - Console.WriteLine(" " + employee.FirstName + " " + employee.LastName); - } + Console.WriteLine(" Staff:"); - Console.WriteLine(); + foreach (var employee in store.Staff) + { + Console.WriteLine(" " + employee.FirstName + " " + employee.LastName); } - public static void AddProductsToStore(Store store, params Product[] products) + Console.WriteLine(); + } + + public static void AddProductsToStore(Store store, params Product[] products) + { + foreach (var product in products) { - foreach (var product in products) - { - store.AddProduct(product); - } + store.AddProduct(product); } + } - public static void AddEmployeesToStore(Store store, params Employee[] employees) + public static void AddEmployeesToStore(Store store, params Employee[] employees) + { + foreach (var employee in employees) { - foreach (var employee in employees) - { - store.AddEmployee(employee); - } + store.AddEmployee(employee); } } -} +} diff --git a/src/Examples.FirstProject/Properties/AssemblyInfo.cs b/src/Examples.FirstProject/Properties/AssemblyInfo.cs index a0f494ee0..31b149844 100644 --- a/src/Examples.FirstProject/Properties/AssemblyInfo.cs +++ b/src/Examples.FirstProject/Properties/AssemblyInfo.cs @@ -2,4 +2,4 @@ using System.Runtime.InteropServices; [assembly: ComVisible(false)] -[assembly: CLSCompliant(true)] \ No newline at end of file +[assembly: CLSCompliant(true)] diff --git a/src/FluentNHibernate.Specs.ExternalFixtures/Component.cs b/src/FluentNHibernate.Specs.ExternalFixtures/Component.cs index 70df2eb8c..0e2e0ed5f 100644 --- a/src/FluentNHibernate.Specs.ExternalFixtures/Component.cs +++ b/src/FluentNHibernate.Specs.ExternalFixtures/Component.cs @@ -1,4 +1,3 @@ -namespace FluentNHibernate.Specs.ExternalFixtures -{ - public class Component {} -} \ No newline at end of file +namespace FluentNHibernate.Specs.ExternalFixtures; + +public class Component {} diff --git a/src/FluentNHibernate.Specs.ExternalFixtures/Entity.cs b/src/FluentNHibernate.Specs.ExternalFixtures/Entity.cs index 1702c6432..cff0b74c9 100644 --- a/src/FluentNHibernate.Specs.ExternalFixtures/Entity.cs +++ b/src/FluentNHibernate.Specs.ExternalFixtures/Entity.cs @@ -1,53 +1,52 @@ using System.Collections.Generic; -namespace FluentNHibernate.Specs.ExternalFixtures +namespace FluentNHibernate.Specs.ExternalFixtures; + +public class Entity { - public class Entity - { - EntityChild readOnlyChild; + 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 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 enum TestEnum {} - public EntityChild ReadOnlyChild - { - get { return readOnlyChild; } - } + public EntityChild ReadOnlyChild + { + get { return readOnlyChild; } } +} - public class EntityChild - {} +public class EntityChild +{} - public abstract class A_Child : B_Parent - { +public abstract class A_Child : B_Parent +{ - } +} - public class B_Parent - { - public int Id { get; set; } - public string Name { get; set; } - } +public class B_Parent +{ + public int Id { get; set; } + public string Name { get; set; } +} - public class Child : Parent - { +public class Child : Parent +{ - } +} - public class Parent - { - public int Id { get; set; } - public Component Component { get; set; } - } +public class Parent +{ + public int Id { get; set; } + public Component Component { get; set; } +} - public class ChildChild : Child - { +public class ChildChild : Child +{ - } -} \ 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 ad146c990..d77eae0be 100644 --- a/src/FluentNHibernate.Specs.ExternalFixtures/Overrides/EntityBatchSizeOverride.cs +++ b/src/FluentNHibernate.Specs.ExternalFixtures/Overrides/EntityBatchSizeOverride.cs @@ -1,13 +1,12 @@ using FluentNHibernate.Automapping; using FluentNHibernate.Automapping.Alterations; -namespace FluentNHibernate.Specs.ExternalFixtures.Overrides +namespace FluentNHibernate.Specs.ExternalFixtures.Overrides; + +public class EntityBatchSizeOverride : IAutoMappingOverride { - public class EntityBatchSizeOverride : IAutoMappingOverride + public void Override(AutoMapping mapping) { - public void Override(AutoMapping mapping) - { - mapping.BatchSize(1234); - } + mapping.BatchSize(1234); } -} +} diff --git a/src/FluentNHibernate.Specs.ExternalFixtures/Properties/AssemblyInfo.cs b/src/FluentNHibernate.Specs.ExternalFixtures/Properties/AssemblyInfo.cs index a0f494ee0..31b149844 100644 --- a/src/FluentNHibernate.Specs.ExternalFixtures/Properties/AssemblyInfo.cs +++ b/src/FluentNHibernate.Specs.ExternalFixtures/Properties/AssemblyInfo.cs @@ -2,4 +2,4 @@ using System.Runtime.InteropServices; [assembly: ComVisible(false)] -[assembly: CLSCompliant(true)] \ No newline at end of file +[assembly: CLSCompliant(true)] diff --git a/src/FluentNHibernate.Specs/Automapping/AutoMapBackwardsCompatibilitySpecs.cs b/src/FluentNHibernate.Specs/Automapping/AutoMapBackwardsCompatibilitySpecs.cs index 8b2518bb7..4815d100f 100644 --- a/src/FluentNHibernate.Specs/Automapping/AutoMapBackwardsCompatibilitySpecs.cs +++ b/src/FluentNHibernate.Specs/Automapping/AutoMapBackwardsCompatibilitySpecs.cs @@ -7,43 +7,41 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.Automapping +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 { - // 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; - } + 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 e4171c291..d191520e2 100644 --- a/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.Conventions.cs +++ b/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.Conventions.cs @@ -11,94 +11,93 @@ using NHibernate.SqlTypes; using NHibernate.UserTypes; -namespace FluentNHibernate.Specs.Automapping +namespace FluentNHibernate.Specs.Automapping; + +public class when_the_automapper_maps_with_a_property_convention { - public class when_the_automapper_maps_with_a_property_convention - { - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(Entity))) - .Conventions.Add(); + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(Entity))) + .Conventions.Add(); - Because of = () => - xml = mapper.BuildMappingFor().ToXml(); + Because of = () => + xml = mapper.BuildMappingFor().ToXml(); - It should_apply_the_convention_to_any_properties = () => - xml.Element("class/property[@name='One']/column").HasAttribute("name", "OneXX"); + It should_apply_the_convention_to_any_properties = () => + xml.Element("class/property[@name='One']/column").HasAttribute("name", "OneXX"); - static AutoPersistenceModel mapper; - static XmlDocument xml; + static AutoPersistenceModel mapper; + static XmlDocument xml; - class XXAppenderPropertyConvention : IPropertyConvention + class XXAppenderPropertyConvention : IPropertyConvention + { + public void Apply(IPropertyInstance instance) { - public void Apply(IPropertyInstance instance) - { - instance.Column(instance.Name + "XX"); - } + 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(); +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(); + 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"); + 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; + static AutoPersistenceModel mapper; + static XmlDocument xml; - class Convention : IReferenceConvention + class Convention : IReferenceConvention + { + public void Apply(IManyToOneInstance instance) { - public void Apply(IManyToOneInstance instance) - { - instance.Access.ReadOnlyPropertyThroughCamelCaseField(CamelCasePrefix.Underscore); - } + 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))) +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(); - }; + 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_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"); + 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; - } + 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(); +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(); + Because of = () => + xml = mapper.BuildMappingFor().ToXml(); - It shold_apply_convention_to_property = () => - xml.Element("class/property[@name='Complex']/column").HasAttribute("name", "someOtherName"); + It shold_apply_convention_to_property = () => + xml.Element("class/property[@name='Complex']/column").HasAttribute("name", "someOtherName"); - static XmlDocument xml; - static AutoPersistenceModel mapper; + static XmlDocument xml; + static AutoPersistenceModel mapper; - } -} +} diff --git a/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.cs b/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.cs index 67eb39910..afd877604 100644 --- a/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.cs +++ b/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.cs @@ -11,105 +11,104 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.Automapping +namespace FluentNHibernate.Specs.Automapping; + +public class when_the_automapper_is_told_to_map_a_single_type { - public class when_the_automapper_is_told_to_map_a_single_type - { - Because of = () => - xml = AutoMap.Source(new StubTypeSource(typeof(Entity))) - .BuildMappingFor() - .ToXml(); + 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_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_the_id = () => + xml.Element("class/id").ShouldExist(); - It should_map_properties = () => - xml.Element("class/property[@name='One']").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_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_references = () => + xml.Element("class/many-to-one[@name='Parent']").ShouldExist(); - It should_map_collections = () => - xml.Element("class/bag[@name='Children']").ShouldExist(); + It should_map_collections = () => + xml.Element("class/bag[@name='Children']").ShouldExist(); - static XmlDocument xml; - } + static XmlDocument xml; +} - public class when_the_automapper_is_ran_to_completion - { - Establish context = () => +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))))); + setup = Fluently.Configure() + .Database( + CreateStandardInMemoryConfiguration()) + .Mappings(x => x.AutoMappings.Add(AutoMap.Source(new StubTypeSource(typeof(Entity))))); - Because of = () => - ex = Catch.Exception(() => setup.BuildConfiguration()); + Because of = () => + ex = Catch.Exception(() => setup.BuildConfiguration()); - It should_generate_xml_that_is_accepted_by_the_nhibernate_schema_validation = () => - ex.Should().BeNull(); + It should_generate_xml_that_is_accepted_by_the_nhibernate_schema_validation = () => + ex.Should().BeNull(); - static FluentConfiguration setup; - static Exception ex; + static FluentConfiguration setup; + static Exception ex; - private static IPersistenceConfigurer CreateStandardInMemoryConfiguration() - { + private static IPersistenceConfigurer CreateStandardInMemoryConfiguration() + { #if NETFRAMEWORK - var configuration = SQLiteConfiguration.Standard.InMemory(); + var configuration = SQLiteConfiguration.Standard.InMemory(); #else var configuration = MsSqliteConfiguration.Standard.InMemory(); #endif - return configuration; - } + 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_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(); +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); + Because of = () => + mappings = mapper.BuildMappings() + .SelectMany(x => x.Classes); - It should_map_the_parent = () => - mappings.Count().Should().Be(1); + 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)); + 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; - } -} + 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 62e874326..bb47e5c12 100644 --- a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Components.cs +++ b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Components.cs @@ -10,144 +10,143 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.Automapping +namespace FluentNHibernate.Specs.Automapping; + +public class when_the_automapper_is_told_to_map_an_entity_and_a_component { - 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()); + Establish context = () => + mapper = AutoMap.Source( + new StubTypeSource(typeof(Entity), typeof(Component)), + new TestConfiguration()); - Because of = () => - mappings = mapper.BuildMappings() - .SelectMany(x => x.Classes); + Because of = () => + mappings = mapper.BuildMappings() + .SelectMany(x => x.Classes); - It should_map_the_entity = () => - mappings.ShouldContain(x => x.Type == typeof(Entity)); + 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_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_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; + static AutoPersistenceModel mapper; + static IEnumerable mappings; - class TestConfiguration : DefaultAutomappingConfiguration + class TestConfiguration : DefaultAutomappingConfiguration + { + public override bool IsComponent(Type type) { - public override bool IsComponent(Type type) - { - return type == typeof(Component); - } + 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); +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))); - It should_map_the_entity = () => - mappings.ShouldContain(x => x.Type == typeof(Entity)); + Because of = () => + mappings = mapper.BuildMappings() + .SelectMany(x => x.Classes); - It should_not_map_the_component_as_an_entity = () => - mappings.ShouldNotContain(x => x.Type == typeof(Component)); + It should_map_the_entity = () => + mappings.ShouldContain(x => x.Type == typeof(Entity)); - 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_not_map_the_component_as_an_entity = () => + mappings.ShouldNotContain(x => x.Type == typeof(Component)); - It should_use_the_component_map_for_mapping = () => - mappings.Single().Components.Single().Access.Should().Be("none"); + 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; + It should_use_the_component_map_for_mapping = () => + mappings.Single().Components.Single().Access.Should().Be("none"); - class TestConfiguration : DefaultAutomappingConfiguration - { - public override bool IsComponent(Type type) - { - return type == typeof(Component); - } - } + static AutoPersistenceModel mapper; + static IEnumerable mappings; - class CompMap : ComponentMap + class TestConfiguration : DefaultAutomappingConfiguration + { + public override bool IsComponent(Type type) { - public CompMap() - { - Access.None(); - } + return type == typeof(Component); } } - public class when_the_automapper_maps_nested_comonents + class CompMap : ComponentMap { - 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 CompMap() { - public override bool IsComponent(Type type) - { - return type.In(typeof(Location), typeof(FormatA), typeof(FormatB)); - } + Access.None(); } } +} - public class Entity1 +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 int Id { get; set; } - public Location Left { get; set; } - public Location Right { get; set; } + public override bool IsComponent(Type type) + { + return type.In(typeof(Location), typeof(FormatA), typeof(FormatB)); + } } +} - public class Location - { - public string LocationProperty { get; set; } - public FormatA A { get; set; } - public FormatB B { get; set; } - } +public class Entity1 +{ + public int Id { get; set; } + public Location Left { get; set; } + public Location Right { get; set; } +} - public class FormatA - { - public string PropertyA { get; set; } - } +public class Location +{ + public string LocationProperty { get; set; } + public FormatA A { get; set; } + public FormatB B { get; set; } +} - public class FormatB - { - public string PropertyB { 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 8324456a7..0adb7aebe 100644 --- a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.ElementCollections.cs +++ b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.ElementCollections.cs @@ -8,187 +8,186 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.Automapping +namespace FluentNHibernate.Specs.Automapping; + +public class when_the_automapper_is_asked_if_it_can_map_a_list_of_strings : AutoMapOneToManyVisitSpec { - public class when_the_automapper_is_asked_if_it_can_map_a_list_of_strings : AutoMapOneToManyVisitSpec - { - Because of = () => - maps_property = step.ShouldMap(FakeMembers.IListOfStrings); + Because of = () => + maps_property = step.ShouldMap(FakeMembers.IListOfStrings); - It should_accept_the_property = () => - maps_property.Should().BeTrue(); + It should_accept_the_property = () => + maps_property.Should().BeTrue(); - static bool maps_property; - } + 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); +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(); + It should_accept_the_property = () => + maps_property.Should().BeTrue(); - static bool maps_property; - } + 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); +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(); + It should_accept_the_property = () => + maps_property.Should().BeTrue(); - static bool maps_property; - } + 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); +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(); + It should_accept_the_property = () => + maps_property.Should().BeTrue(); - static bool maps_property; - } + 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); +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(); + It should_accept_the_property = () => + maps_property.Should().BeTrue(); - static bool maps_property; - } + 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); +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(); + It should_accept_the_property = () => + maps_property.Should().BeTrue(); - static bool maps_property; - } + 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); +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(); + It should_accept_the_property = () => + maps_property.Should().BeTrue(); - static bool maps_property; - } + 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); +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(); + It should_accept_the_property = () => + maps_property.Should().BeTrue(); - static bool maps_property; - } + 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"; +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); + 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"); - } + 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); +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 = () => + 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_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_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_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_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_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_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_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_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_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_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_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(); - } + It should_not_create_a_component_for_the_collection = () => + container.Collections.Single().CompositeElement.Should().BeNull(); +} - public abstract class AutoMapOneToManySpec +public abstract class AutoMapOneToManySpec +{ + Establish context = () => { - Establish context = () => - { - cfg = new TestConfiguration(); - step = new HasManyStep(cfg); - container = new ClassMapping(); - container.Set(x => x.Type, Layer.Defaults, FakeMembers.Type); - }; + 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 static HasManyStep step; + protected static ClassMapping container; + protected static TestConfiguration cfg; - protected class TestConfiguration : DefaultAutomappingConfiguration + protected class TestConfiguration : DefaultAutomappingConfiguration + { + public override string SimpleTypeCollectionValueColumn(Member member) { - public override string SimpleTypeCollectionValueColumn(Member member) - { - return FixedSimpleTypeCollectionValueColumn ?? base.SimpleTypeCollectionValueColumn(member); - } - - public string FixedSimpleTypeCollectionValueColumn { get; set; } + return FixedSimpleTypeCollectionValueColumn ?? base.SimpleTypeCollectionValueColumn(member); } + + public string FixedSimpleTypeCollectionValueColumn { get; set; } } +} - public abstract class AutoMapOneToManyVisitSpec +public abstract class AutoMapOneToManyVisitSpec +{ + Establish context = () => { - Establish context = () => - { - cfg = new DefaultAutomappingConfiguration(); - step = new SimpleTypeCollectionStep(cfg); - }; + cfg = new DefaultAutomappingConfiguration(); + step = new SimpleTypeCollectionStep(cfg); + }; - protected static SimpleTypeCollectionStep step; - protected static IAutomappingConfiguration cfg; - } -} \ No newline at end of file + 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 b34546a93..59b4ff9ec 100644 --- a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.NestedClasses.cs +++ b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.NestedClasses.cs @@ -7,95 +7,93 @@ using FluentNHibernate.Specs.Automapping.Fixtures; using Machine.Specifications; -namespace FluentNHibernate.Specs.Automapping +namespace FluentNHibernate.Specs.Automapping; + +public class when_the_automapper_is_told_to_map_an_entity_with_a_nested_entity { - 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))); + Establish context = () => + mapper = AutoMap.Source( + new StubTypeSource(typeof(Order), typeof(Order.OrderLine))); - Because of = () => - mappings = mapper.BuildMappings() - .SelectMany(x => x.Classes); + Because of = () => + mappings = mapper.BuildMappings() + .SelectMany(x => x.Classes); - It should_map_the_entity = () => - mappings.ShouldContain(x => x.Type == typeof(Order)); + 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)); + It should_automap_the_nested_entity_per_default = () => + mappings.ShouldContain(x => x.Type == typeof(Order.OrderLine)); - static AutoPersistenceModel mapper; - static IEnumerable mappings; - } + 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()); +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); + Because of = () => + mappings = mapper.BuildMappings() + .SelectMany(x => x.Classes); - It should_map_the_entity = () => - mappings.ShouldContain(x => x.Type == typeof(Order)); + 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)); + It should_automap_the_nested_entity = () => + mappings.ShouldContain(x => x.Type == typeof(Order.OrderLine)); - static AutoPersistenceModel mapper; - static IEnumerable mappings; + static AutoPersistenceModel mapper; + static IEnumerable mappings; - class TestConfiguration : DefaultAutomappingConfiguration + class TestConfiguration : DefaultAutomappingConfiguration + { + public override bool ShouldMap(Type type) { - public override bool ShouldMap(Type type) - { - return base.ShouldMap(type) || type.IsNested; - } + return base.ShouldMap(type) || type.IsNested; } } +} - public class when_automapper_is_told_to_map_a_class_with_a_nested_classes +public class when_automapper_is_told_to_map_a_class_with_a_nested_classes +{ + Establish context = () => { - 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; + 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; } } - - public class PersonCard + private class PrivateAddress { 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 class Order +{ + public int Id { get; set; } + public class OrderLine { public int Id { get; set; } - public class OrderLine - { - public int Id { get; set; } - } } - -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Properties.Enum.cs b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Properties.Enum.cs index 431d5d610..84465c8b5 100644 --- a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Properties.Enum.cs +++ b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Properties.Enum.cs @@ -6,76 +6,75 @@ using FluentAssertions; using NHibernate.Type; -namespace FluentNHibernate.Specs.Automapping +namespace FluentNHibernate.Specs.Automapping; + +public class when_the_automapper_is_told_to_map_an_entity_with_static_properties { - public class when_the_automapper_is_told_to_map_an_entity_with_static_properties - { - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(EntityWithStaticProperties))); + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(EntityWithStaticProperties))); - Because of = () => - mapping = mapper.BuildMappings().SelectMany(x => x.Classes).First(); + 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(); + 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; - } + 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))); +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(); + 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_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_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"); - } + 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))); +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(); + 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_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_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"); - } + 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 Target +{ + public int Id { get; set; } + public Enum EnumProperty { get; set; } +} - class NullableTarget - { - public int Id { get; set; } - public Enum? EnumProperty { get; set; } - } +class NullableTarget +{ + public int Id { get; set; } + public Enum? EnumProperty { get; set; } +} - enum Enum { } +enum Enum { } - public abstract class AutomapperEnumPropertySpec - { - protected static AutoPersistenceModel mapper; - protected static ClassMapping mapping; - } -} \ No newline at end of file +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 41f96770a..fdee055db 100644 --- a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Relationships.cs +++ b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Relationships.cs @@ -10,216 +10,215 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.Automapping +namespace FluentNHibernate.Specs.Automapping; + +public class when_the_automapper_is_told_to_map_a_class_with_a_self_referencing_collection { - 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))); + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(SelfReferencingCollectionEntity))); - Because of = () => - mapping = mapper.BuildMappingFor(); + Because of = () => + mapping = mapper.BuildMappingFor(); - It should_have_one_collection = () => - mapping.Collections.Should().NotBeEmpty(); + 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_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_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_a_one_to_many_collection = () => + mapping.Collections.Single().Relationship.Should().BeOfType(); - static AutoPersistenceModel mapper; - static ClassMapping mapping; - } + 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))); +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(); + Because of = () => + mapping = mapper.BuildMappingFor(); - It should_have_one_reference = () => - mapping.References.Should().NotBeEmpty(); + 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_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"); + It should_have_the_property_name_for_the_reference_name = () => + mapping.References.Single().Name.Should().Be("Parent"); - static AutoPersistenceModel mapper; - static ClassMapping mapping; - } + 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))); +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(); + Because of = () => + mapping = mapper.BuildMappingFor(); - It should_have_one_collection = () => - mapping.Collections.Should().NotBeEmpty(); + 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_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_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_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_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_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_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_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"); + It should_have_the_correct_reference_key_column = () => + mapping.References.Single().Columns.Single().Name.Should().Be("Parent_id"); - static AutoPersistenceModel mapper; - static ClassMapping mapping; - } + 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))); +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(); + 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_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"); + 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; - } + 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(); +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(); + 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_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"); + 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; + static AutoPersistenceModel mapper; + static ClassMapping mapping; - class Convention : IHasManyConvention + class Convention : IHasManyConvention + { + public void Apply(IOneToManyCollectionInstance instance) { - public void Apply(IOneToManyCollectionInstance instance) - { - instance.Access.Property(); - } + 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()); +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(); + 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"); + 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; + static AutoPersistenceModel mapper; + static ClassMapping mapping; - class TestConfiguration : DefaultAutomappingConfiguration + class TestConfiguration : DefaultAutomappingConfiguration + { + public override Access GetAccessStrategyForReadOnlyProperty(Member member) { - public override Access GetAccessStrategyForReadOnlyProperty(Member member) - { - return Access.NoOp; - } + 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))); +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(); + 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_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"); + 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; - } + 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()); +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(); + 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"); + 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; + static AutoPersistenceModel mapper; + static ClassMapping mapping; - class TestConfiguration : DefaultAutomappingConfiguration + class TestConfiguration : DefaultAutomappingConfiguration + { + public override Access GetAccessStrategyForReadOnlyProperty(Member member) { - public override Access GetAccessStrategyForReadOnlyProperty(Member member) - { - return Access.NoOp; - } + return Access.NoOp; } } +} - public class when_automapping_an_entity_with_dictionary_properties - { - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(DictionaryEntity))); +public class when_automapping_an_entity_with_dictionary_properties +{ + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(DictionaryEntity))); - Because of = () => - mapping = mapper.BuildMappingFor(); + 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_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"); + It should_not_map_the_generic_dictionary = () => + mapping.Collections.Select(x => x.Name).Should().NotContain("GenericDictionary"); - static AutoPersistenceModel mapper; - static ClassMapping mapping; - } -} + 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 6069efb22..327794674 100644 --- a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Version.cs +++ b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Version.cs @@ -10,49 +10,48 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.Automapping +namespace FluentNHibernate.Specs.Automapping; + +public class when_the_automapper_is_told_to_map_a_class_with_a_version { - public class when_the_automapper_is_told_to_map_a_class_with_a_version - { - Establish context = () => - mapper = AutoMap.Source(new StubTypeSource(typeof(VersionedEntity))); + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(VersionedEntity))); - Because of = () => - mapping = mapper.BuildMappingFor(); + Because of = () => + mapping = mapper.BuildMappingFor(); - It should_have_a_version = () => - mapping.Version.Should().NotBeNull(); + 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"); + It should_have_picked_the_right_property_to_be_the_version = () => + mapping.Version.Name.Should().Be("Timestamp"); - static AutoPersistenceModel mapper; - static ClassMapping mapping; - } + 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()); +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(); + Because of = () => + mapping = mapper.BuildMappingFor(); - It should_have_a_version = () => - mapping.Version.Should().NotBeNull(); + 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"); + It should_have_picked_the_right_property_to_be_the_version = () => + mapping.Version.Name.Should().Be("AnUnobviousVersion"); - static AutoPersistenceModel mapper; - static ClassMapping mapping; + static AutoPersistenceModel mapper; + static ClassMapping mapping; - class TestConfig : DefaultAutomappingConfiguration + class TestConfig : DefaultAutomappingConfiguration + { + public override bool IsVersion(Member member) { - public override bool IsVersion(Member member) - { - return member.Name == "AnUnobviousVersion"; - } + return member.Name == "AnUnobviousVersion"; } } -} +} diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/AutomappingSpecExtensions.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/AutomappingSpecExtensions.cs index 6229afb94..6a2e1b275 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/AutomappingSpecExtensions.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/AutomappingSpecExtensions.cs @@ -7,107 +7,106 @@ using FluentNHibernate.MappingModel.Output; using Machine.Specifications; -namespace FluentNHibernate.Specs.Automapping.Fixtures +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +public static class AutomappingSpecExtensions { - public static class AutomappingSpecExtensions + public static ClassMapping BuildMappingFor(this AutoPersistenceModel model) { - public static ClassMapping BuildMappingFor(this AutoPersistenceModel model) - { - return model.BuildMappings() - .SelectMany(x => x.Classes) - .FirstOrDefault(x => x.Type == typeof(T)); - } + return model.BuildMappings() + .SelectMany(x => x.Classes) + .FirstOrDefault(x => x.Type == typeof(T)); + } - public static XmlDocument ToXml(this ClassMapping mapping) - { - var hbm = new HibernateMapping(); + public static XmlDocument ToXml(this ClassMapping mapping) + { + var hbm = new HibernateMapping(); - hbm.AddClass(mapping); + hbm.AddClass(mapping); - return new MappingXmlSerializer() - .Serialize(hbm); - } + return new MappingXmlSerializer() + .Serialize(hbm); + } +} + +public static class XmlTestExtensions +{ + public static XmlElementTester Element(this XmlDocument doc, string path) + { + return new XmlElementTester(doc, path); } - public static class XmlTestExtensions + public class XmlElementTester { - public static XmlElementTester Element(this XmlDocument doc, string path) + readonly XmlDocument doc; + string currentPath; + XmlElement currentElement; + + public XmlElementTester(XmlDocument doc, string path) { - return new XmlElementTester(doc, path); + currentElement = (XmlElement)doc.DocumentElement.SelectSingleNode(path); + this.doc = doc; + currentPath = path; } - public class XmlElementTester + public XmlElementTester ShouldExist() { - readonly XmlDocument doc; - string currentPath; - XmlElement currentElement; + if (currentElement == null) + throw new SpecificationException(string.Format("Should exist at {0} but does not.", currentPath)); - 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; - } + return this; + } - public XmlElementTester ShouldNotExist() - { - if (currentElement != null) - throw new SpecificationException(string.Format("Should not exist at {0} but does.", currentPath)); + public XmlElementTester ShouldNotExist() + { + if (currentElement != null) + throw new SpecificationException(string.Format("Should not exist at {0} but does.", currentPath)); - return this; - } + 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)); + 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; - } + return this; + } - public XmlElementTester HasAttribute(string name, string value) - { - ShouldExist(); - HasAttribute(name); + public XmlElementTester HasAttribute(string name, string value) + { + ShouldExist(); + HasAttribute(name); - var actual = currentElement.GetAttribute(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)); + 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; - } + return this; + } - public XmlElementTester HasAttribute(string name, Func predicate) - { - ShouldExist(); - HasAttribute(name); + public XmlElementTester HasAttribute(string name, Func predicate) + { + ShouldExist(); + HasAttribute(name); - var actual = currentElement.GetAttribute(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)); + 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; - } + return this; + } - public XmlElementTester DoesntHaveAttribute(string name) - { - ShouldExist(); + 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)); + if (currentElement.HasAttribute(name)) + throw new SpecificationException(string.Format("Should not have attribute named {0} at {1} but does.", name, currentPath)); - return this; - } + return this; } } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/DictionaryEntity.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/DictionaryEntity.cs index 2892e0360..915002cd2 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/DictionaryEntity.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/DictionaryEntity.cs @@ -2,12 +2,11 @@ using System.Collections.Generic; using FluentNHibernate.Specs.ExternalFixtures; -namespace FluentNHibernate.Specs.Automapping.Fixtures +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +class DictionaryEntity { - class DictionaryEntity - { - public int Id { get; set; } - public IDictionary GenericDictionary { get; set; } - public IDictionary Dictionary { get; set; } - } -} \ No newline at end of file + 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 5caf1477d..09dd42cfc 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityUsingPrivateFields.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityUsingPrivateFields.cs @@ -1,17 +1,16 @@ using System; using System.Collections.Generic; -namespace FluentNHibernate.Specs.Automapping.Fixtures +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +class EntityUsingPrivateFields { - class EntityUsingPrivateFields - { - int id; - string one; - DateTime two; - DateTime? three; - int _one; - IList _children; + int id; + string one; + DateTime two; + DateTime? three; + int _one; + IList _children; - public string PublicPropertyThatShouldBeIgnored { get; set; } - } -} \ No newline at end of file + public string PublicPropertyThatShouldBeIgnored { get; set; } +} diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityWithStaticProperties.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityWithStaticProperties.cs index f652a988b..ceb780520 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityWithStaticProperties.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityWithStaticProperties.cs @@ -1,8 +1,7 @@ -namespace FluentNHibernate.Specs.Automapping.Fixtures +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +public class EntityWithStaticProperties { - public class EntityWithStaticProperties - { - public int Id { get; set; } - public static int StaticProperty { get; set; } - } -} \ No newline at end of file + 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 5dfe0488d..2077598cb 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/FakeMembers.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/FakeMembers.cs @@ -1,42 +1,41 @@ using System; using System.Collections.Generic; -namespace FluentNHibernate.Specs.Automapping.Fixtures +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +public static class FakeMembers { - 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; + 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(); - } + 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; } - } + 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; } } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/Overrides/EntityTableOverride.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/Overrides/EntityTableOverride.cs index 1c825a06e..13e22a4f0 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/Overrides/EntityTableOverride.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/Overrides/EntityTableOverride.cs @@ -2,13 +2,12 @@ using FluentNHibernate.Automapping.Alterations; using FluentNHibernate.Specs.ExternalFixtures; -namespace FluentNHibernate.Specs.Automapping.Fixtures.Overrides +namespace FluentNHibernate.Specs.Automapping.Fixtures.Overrides; + +public class EntityTableOverride : IAutoMappingOverride { - public class EntityTableOverride : IAutoMappingOverride + public void Override(AutoMapping mapping) { - public void Override(AutoMapping mapping) - { - mapping.Table("OverriddenTableName"); - } + mapping.Table("OverriddenTableName"); } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/ParentChildSelfReferenceEntity.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/ParentChildSelfReferenceEntity.cs index 1609a7ce5..b5b74e9a5 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/ParentChildSelfReferenceEntity.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/ParentChildSelfReferenceEntity.cs @@ -1,11 +1,10 @@ using System.Collections.Generic; -namespace FluentNHibernate.Specs.Automapping.Fixtures +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +public class ParentChildSelfReferenceEntity { - public class ParentChildSelfReferenceEntity - { - public int Id { get; set; } - public ParentChildSelfReferenceEntity Parent { get; set; } - public IList Children { get; set; } - } -} \ No newline at end of file + 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 8b33f13b0..b4095d637 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/ReadOnlyEnumerableEntity.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/ReadOnlyEnumerableEntity.cs @@ -1,17 +1,16 @@ using System.Collections.Generic; using FluentNHibernate.Specs.ExternalFixtures; -namespace FluentNHibernate.Specs.Automapping.Fixtures +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +class ReadOnlyEnumerableEntity { - class ReadOnlyEnumerableEntity - { - IList backingFieldCollection; + IList backingFieldCollection; - public int Id { get; set; } - public IEnumerable AutoPropertyCollection { get; private set; } - public IEnumerable BackingFieldCollection - { - get { return backingFieldCollection; } - } + public int Id { get; set; } + public IEnumerable AutoPropertyCollection { get; private set; } + public IEnumerable BackingFieldCollection + { + get { return backingFieldCollection; } } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferenceEntity.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferenceEntity.cs index 3e70c5122..f7b4b6258 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferenceEntity.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferenceEntity.cs @@ -1,8 +1,7 @@ -namespace FluentNHibernate.Specs.Automapping.Fixtures +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +public class SelfReferenceEntity { - public class SelfReferenceEntity - { - public int Id { get; set; } - public SelfReferenceEntity Parent { get; set; } - } -} \ No newline at end of file + 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 856c491d9..abaa20853 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferencingCollectionEntity.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferencingCollectionEntity.cs @@ -1,10 +1,9 @@ using System.Collections.Generic; -namespace FluentNHibernate.Specs.Automapping.Fixtures +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +public class SelfReferencingCollectionEntity { - public class SelfReferencingCollectionEntity - { - public int Id { get; set; } - public IList Children { get; set; } - } -} \ No newline at end of file + 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 c8b50414b..4a84eaf5e 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/StubTypeSource.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/StubTypeSource.cs @@ -2,30 +2,29 @@ using System.Collections.Generic; using FluentNHibernate.Diagnostics; -namespace FluentNHibernate.Specs.Automapping.Fixtures +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +internal class StubTypeSource : ITypeSource { - internal class StubTypeSource : ITypeSource - { - private readonly IEnumerable types; + private readonly IEnumerable types; - public StubTypeSource(params Type[] types) - { - this.types = types; - } + public StubTypeSource(params Type[] types) + { + this.types = types; + } - public IEnumerable GetTypes() - { - return types; - } + public IEnumerable GetTypes() + { + return types; + } - public void LogSource(IDiagnosticLogger logger) - { - logger.LoadedFluentMappingsFromSource(this); - } + public void LogSource(IDiagnosticLogger logger) + { + logger.LoadedFluentMappingsFromSource(this); + } - public string GetIdentifier() - { - return "StubTypeSource"; - } + public string GetIdentifier() + { + return "StubTypeSource"; } -} +} diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/UserTypes.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/UserTypes.cs index 6402f656c..33c160748 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/UserTypes.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/UserTypes.cs @@ -10,169 +10,168 @@ using NHibernate.SqlTypes; using NHibernate.UserTypes; -namespace FluentNHibernate.Specs.Automapping.Fixtures +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +public class TypeWithNullableUT +{ + public int ID { get; set; } + public UserValueType? Simple { get; set; } +} + +public class TypeWithValueUT { - public class TypeWithNullableUT + 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) { - public int ID { get; set; } - public UserValueType? Simple { get; set; } + base.Apply(instance); + instance.Column("arbitraryName"); } +} - public class TypeWithValueUT +public class CustomTypeConvention : UserTypeConvention +{ + public override void Apply(IPropertyInstance instance) { - public int Id { get; set; } - public UserValueType Definite { get; set; } + base.Apply(instance); + instance.Column("someOtherName"); } +} - public class NotNullableUT +public class CustomUserType : IUserType +{ + public new bool Equals(object x, object y) { - public int ID { get; set; } - public CustomUserType Complex { get; set; } + return x == y; } - public class ValueTypeConvention : UserTypeConvention + public int GetHashCode(object x) { - public override void Apply(IPropertyInstance instance) - { - base.Apply(instance); - instance.Column("arbitraryName"); - } + return x.GetHashCode(); } - public class CustomTypeConvention : UserTypeConvention + public object NullSafeGet(IDataReader rs, string[] names, object owner) { - public override void Apply(IPropertyInstance instance) - { - base.Apply(instance); - instance.Column("someOtherName"); - } + return null; } - public class CustomUserType : IUserType + public void NullSafeSet(IDbCommand cmd, object value, int index) { - 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 object DeepCopy(object value) + { + return value; + } - public void NullSafeSet(IDbCommand cmd, object value, int index) - { + public object Replace(object original, object target, object owner) + { + return original; + } - } + public object Assemble(object cached, object owner) + { + return cached; + } - public object DeepCopy(object value) - { - return value; - } + public object Disassemble(object value) + { + return value; + } - public object Replace(object original, object target, object owner) - { - return original; - } + public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner) + { + throw new NotImplementedException(); + } - public object Assemble(object cached, object owner) - { - return cached; - } + public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session) + { + throw new NotImplementedException(); + } - public object Disassemble(object value) - { - return value; - } + public SqlType[] SqlTypes + { + get { return new[] { new SqlType(DbType.String) }; } + } - public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner) - { - throw new NotImplementedException(); - } + public Type ReturnedType + { + get { return typeof(CustomUserType); } + } - public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session) - { - throw new NotImplementedException(); - } + public bool IsMutable + { + get { return true; } + } +} - public SqlType[] SqlTypes - { - get { return new[] { new SqlType(DbType.String) }; } - } +public struct UserValueType : IUserType +{ + public string AddressLine1 { get; set; } + public string AddressLine2 { get; set; } - public Type ReturnedType - { - get { return typeof(CustomUserType); } - } + public new bool Equals(object x, object y) + { + throw new NotImplementedException(); + } - public bool IsMutable - { - get { return true; } - } + public int GetHashCode(object x) + { + throw new NotImplementedException(); } - public struct UserValueType : IUserType + public object NullSafeGet(IDataReader rs, string[] names, object owner) { - public string AddressLine1 { get; set; } - public string AddressLine2 { get; set; } + throw new NotImplementedException(); + } - public new bool Equals(object x, object y) - { - throw new NotImplementedException(); - } + public void NullSafeSet(IDbCommand cmd, object value, int index) + { + 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; } + 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 58fde7733..cc8a6ea1a 100644 --- a/src/FluentNHibernate.Specs/Automapping/Fixtures/VersionedEntity.cs +++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/VersionedEntity.cs @@ -1,9 +1,8 @@ -namespace FluentNHibernate.Specs.Automapping.Fixtures +namespace FluentNHibernate.Specs.Automapping.Fixtures; + +public class VersionedEntity { - public class VersionedEntity - { - public int Id { get; set; } - public int Timestamp { get; set; } - public string AnUnobviousVersion { get; set; } - } -} \ No newline at end of file + 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 cf93e87c7..25cce5214 100644 --- a/src/FluentNHibernate.Specs/Automapping/OverrideSpecs.cs +++ b/src/FluentNHibernate.Specs/Automapping/OverrideSpecs.cs @@ -9,144 +9,143 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.Automapping +namespace FluentNHibernate.Specs.Automapping; + +public class when_using_an_automapping_override_to_create_a_join { - 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))); + 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(); + Because of = () => + mapping = model.BuildMappingFor(); - It should_create_the_join_mapping = () => - mapping.Joins.Should().NotBeEmpty(); + 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_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"); + 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; - } + 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 => { })); +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(); + private Because of = () => + mapping = model.BuildMappingFor(); - It should_not_create_the_join_mapping = () => - mapping.Joins.Should().BeEmpty(); + It should_not_create_the_join_mapping = () => + mapping.Joins.Should().BeEmpty(); - It should_map_the_discriminator = () => - mapping.Discriminator.Should().NotBeNull(); + It should_map_the_discriminator = () => + mapping.Discriminator.Should().NotBeNull(); - It should_map_subclasses_as_joined_subclasses = () => - mapping.Subclasses.Should().OnlyContain(x => x.Joins.Any()); + It should_map_subclasses_as_joined_subclasses = () => + mapping.Subclasses.Should().OnlyContain(x => x.Joins.Any()); - static AutoPersistenceModel model; - static ClassMapping mapping; - } + 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")); - public class when_using_an_automapping_override_to_specify_a_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 = () => { - Establish context = () => - model = AutoMap.Source(new StubTypeSource(typeof(Parent), typeof(Child))) - .Override(map => - map.DiscriminateSubClassesOnColumn("discriminator")); + mapping.Subclasses.Count().Should().Be(1); + mapping.Subclasses.Should().OnlyContain(subclass => subclass.SubclassType == SubclassType.Subclass); + }; + + static AutoPersistenceModel model; + static ClassMapping mapping; +} - Because of = () => - mapping = model.BuildMappingFor(); +[Subject(typeof(IAutoMappingOverride<>))] +public class when_using_multiple_overrides_from_different_assemblies +{ + Establish context = () => + model = AutoMap.Source(new StubTypeSource(typeof(Entity))) + .UseOverridesFromAssemblyOf() + .UseOverridesFromAssemblyOf(); - It should_map_the_discriminator = () => - mapping.Discriminator.Should().NotBeNull(); + Because of = () => + mapping = model.BuildMappingFor(); - 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); - }; + It should_apply_override_from_the_first_assembly = () => + mapping.BatchSize.Should().Be(1234); - static AutoPersistenceModel model; - static ClassMapping mapping; - } + It should_apply_override_from_the_second_assembly = () => + mapping.TableName.Should().Be("OverriddenTableName"); - [Subject(typeof(IAutoMappingOverride<>))] - public class when_using_multiple_overrides_from_different_assemblies + static AutoPersistenceModel model; + static ClassMapping mapping; +} + +[Subject(typeof(IAutoMappingOverride<>))] +public class when_multiple_overrides_present_in_one_class +{ + Establish context = () => { - Establish context = () => - model = AutoMap.Source(new StubTypeSource(typeof(Entity))) - .UseOverridesFromAssemblyOf() - .UseOverridesFromAssemblyOf(); + model = AutoMap.Source(new StubTypeSource(typeof(Entity), typeof(Parent), typeof(B_Parent))); + model.Override(typeof(MultipleOverrides)); + }; - Because of = () => - mapping = model.BuildMappingFor(); + 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); + }; - 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 entityMapping; + static ClassMapping parentMapping; + static ClassMapping bParentMapping; +} - static AutoPersistenceModel model; - static ClassMapping mapping; +public class MultipleOverrides: IAutoMappingOverride, IAutoMappingOverride, IAutoMappingOverride +{ + public void Override(AutoMapping mapping) + { + mapping.EntityName("customEntityName"); } - [Subject(typeof(IAutoMappingOverride<>))] - public class when_multiple_overrides_present_in_one_class + public void Override(AutoMapping mapping) { - 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; + mapping.Table("fancyTableName_Parent"); } - public class MultipleOverrides: IAutoMappingOverride, IAutoMappingOverride, IAutoMappingOverride + public void Override(AutoMapping mapping) { - 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); - } + mapping.BatchSize(50); } -} +} diff --git a/src/FluentNHibernate.Specs/Automapping/PrivateAutomapperSpecs.cs b/src/FluentNHibernate.Specs/Automapping/PrivateAutomapperSpecs.cs index e509c5aee..70da9ca1e 100644 --- a/src/FluentNHibernate.Specs/Automapping/PrivateAutomapperSpecs.cs +++ b/src/FluentNHibernate.Specs/Automapping/PrivateAutomapperSpecs.cs @@ -5,32 +5,31 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.Automapping +namespace FluentNHibernate.Specs.Automapping; + +public class when_using_the_private_automapper_to_map_a_entity_with_private_fields_starting_with_an_underscore { - public class when_using_the_private_automapper_to_map_a_entity_with_private_fields_starting_with_an_underscore + Establish context = () => { - Establish context = () => - { - model = new PrivateAutoPersistenceModel() - .Setup(conventions => conventions.FindMembers = m => m.IsField && m.Name.StartsWith("_")); + model = new PrivateAutoPersistenceModel() + .Setup(conventions => conventions.FindMembers = m => m.IsField && m.Name.StartsWith("_")); - model.ValidationEnabled = false; - model.AddTypeSource(new StubTypeSource(typeof(EntityUsingPrivateFields))); - }; + model.ValidationEnabled = false; + model.AddTypeSource(new StubTypeSource(typeof(EntityUsingPrivateFields))); + }; - Because of = () => - mapping = model.BuildMappingFor(); + Because of = () => + mapping = model.BuildMappingFor(); - It should_map_fields_matching_the_convention = () => - mapping.Properties.Select(x => x.Name).Should().Contain("_one"); + 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_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"); + 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; - } -} \ No newline at end of file + static ClassMapping mapping; + static AutoPersistenceModel model; +} diff --git a/src/FluentNHibernate.Specs/Automapping/PrivateFieldsSpecs.cs b/src/FluentNHibernate.Specs/Automapping/PrivateFieldsSpecs.cs index 9a6372f9b..39b22ed78 100644 --- a/src/FluentNHibernate.Specs/Automapping/PrivateFieldsSpecs.cs +++ b/src/FluentNHibernate.Specs/Automapping/PrivateFieldsSpecs.cs @@ -7,33 +7,32 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.Automapping +namespace FluentNHibernate.Specs.Automapping; + +public class when_using_the_automapper_to_map_an_entity_that_uses_private_fields_for_storage { - 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); + Establish context = () => + mapper = AutoMap.Source(new StubTypeSource(typeof(EntityUsingPrivateFields))) + .Setup(s => s.FindMembers = m => m.IsField && m.IsPrivate); - Because of = () => - mapping = mapper.BuildMappingFor(); + Because of = () => + mapping = mapper.BuildMappingFor(); - It should_find_an_id = () => - mapping.Id.Should().NotBeNull(); + 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_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_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" }); + It should_map_fields = () => + mapping.Properties.Select(x => x.Name).Should().Contain(new string[] { "one", "two", "three" }); - static AutoPersistenceModel mapper; - static ClassMapping mapping; - } -} + static AutoPersistenceModel mapper; + static ClassMapping mapping; +} diff --git a/src/FluentNHibernate.Specs/Conventions/ApplyFilterSpecs.cs b/src/FluentNHibernate.Specs/Conventions/ApplyFilterSpecs.cs index 820aa61e5..f04742593 100644 --- a/src/FluentNHibernate.Specs/Conventions/ApplyFilterSpecs.cs +++ b/src/FluentNHibernate.Specs/Conventions/ApplyFilterSpecs.cs @@ -6,88 +6,87 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.Conventions +namespace FluentNHibernate.Specs.Conventions; + +public class when_applying_a_filter_to_an_entity_using_conventions { - public class when_applying_a_filter_to_an_entity_using_conventions + Establish context = () => { - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Conventions.Add(); - model.Add(new FilterTargetMap()); - }; + model = new FluentNHibernate.PersistenceModel(); + model.Conventions.Add(); + model.Add(new FilterTargetMap()); + }; - Because of = () => - mapping = model.BuildMappingFor(); + Because of = () => + mapping = model.BuildMappingFor(); - It should_add_a_filter_to_the_entity_s_mapping = () => - mapping.Filters.Should().NotBeEmpty(); + 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_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); + 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; - } + static FluentNHibernate.PersistenceModel model; + static ClassMapping mapping; +} - public class when_applying_a_filter_to_a_one_to_many_using_conventions +public class when_applying_a_filter_to_a_one_to_many_using_conventions +{ + Establish context = () => { - 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 + model = new FluentNHibernate.PersistenceModel(); + model.Conventions.Add(); + model.Add(new FilterTargetMap()); + model.Add(new FilterChildTargetMap()); + }; + + Because of = () => { - 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; - } + 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 9b5c7dda6..2345627b6 100644 --- a/src/FluentNHibernate.Specs/Conventions/BiDirectionalKeysSpecs.cs +++ b/src/FluentNHibernate.Specs/Conventions/BiDirectionalKeysSpecs.cs @@ -4,34 +4,33 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.Conventions +namespace FluentNHibernate.Specs.Conventions; + +public class when_mapping_a_many_to_one_one_to_many_bi_directional_relationship { - public class when_mapping_a_many_to_one_one_to_many_bi_directional_relationship + Establish context = () => { - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Add(new ParentMap()); - model.Add(new ChildMap()); - }; + 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)); - }; + 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 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"); + [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; - } -} + 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 6a1062c09..e768390f3 100644 --- a/src/FluentNHibernate.Specs/Conventions/CollectionTypeChangeSpecs.cs +++ b/src/FluentNHibernate.Specs/Conventions/CollectionTypeChangeSpecs.cs @@ -8,32 +8,31 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.Conventions +namespace FluentNHibernate.Specs.Conventions; + +public class when_changing_the_collection_type_with_conventions { - public class when_changing_the_collection_type_with_conventions + Establish context = () => { - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Conventions.Add(); - model.Add(new CollectionTargetMap()); - model.Add(new CollectionChildTargetMap()); - }; + model = new FluentNHibernate.PersistenceModel(); + model.Conventions.Add(); + model.Add(new CollectionTargetMap()); + model.Add(new CollectionChildTargetMap()); + }; - Because of = () => - mapping = model.BuildMappingFor(); + 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_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); + 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; - } -} + static FluentNHibernate.PersistenceModel model; + static ClassMapping mapping; +} diff --git a/src/FluentNHibernate.Specs/Conventions/ComponentConventionSpecs.cs b/src/FluentNHibernate.Specs/Conventions/ComponentConventionSpecs.cs index b9527f77e..fa1d5a29e 100644 --- a/src/FluentNHibernate.Specs/Conventions/ComponentConventionSpecs.cs +++ b/src/FluentNHibernate.Specs/Conventions/ComponentConventionSpecs.cs @@ -6,78 +6,77 @@ using Machine.Specifications; using System.Linq; -namespace FluentNHibernate.Specs.Conventions +namespace FluentNHibernate.Specs.Conventions; + +public class when_specifying_component_convention { - public class when_specifying_component_convention + Establish context = () => { - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Conventions.Add(); - model.Add(new AddressMap()); - model.Add(new EntityWithComponentMap()); - }; + model = new FluentNHibernate.PersistenceModel(); + model.Conventions.Add(); + model.Add(new AddressMap()); + model.Add(new EntityWithComponentMap()); + }; - Because of = () => - { - mapping = model.BuildMappingFor(); - }; + Because of = () => + { + mapping = model.BuildMappingFor(); + }; - It should_be_able_to_specify_column_name = () => - { - var property = mapping.Components.First() - .Properties.Single(x => x.Name == "Count"); + 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"); - }; + property.Columns.FirstOrDefault().Name.Should().Be("different"); + }; - private static FluentNHibernate.PersistenceModel model; - private static ClassMapping mapping; - } + 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 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; } - } +public class Address +{ + public int Count { get; set; } + public string Line1 { get; set; } + public string Line2 { get; set; } +} - internal class AddressMap : ComponentMap
+internal class AddressMap : ComponentMap
+{ + public AddressMap() { - public AddressMap() - { - Map(x => x.Line1); - Map(x => x.Line2); - Map(x => x.Count); - } + Map(x => x.Line1); + Map(x => x.Line2); + Map(x => x.Count); } +} - public class ComponentConvention : IComponentConvention +public class ComponentConvention : IComponentConvention +{ + public void Apply(IComponentInstance instance) { - public void Apply(IComponentInstance instance) + if (instance.Type == typeof(Address)) { - if (instance.Type == typeof(Address)) - { - var type = instance.Properties.First(p => p.Type == typeof(int)); - type.Column("different"); - } + var type = instance.Properties.First(p => p.Type == typeof(int)); + type.Column("different"); } } +} - public class EntityWithComponentMap : ClassMap +public class EntityWithComponentMap : ClassMap +{ + public EntityWithComponentMap() { - public EntityWithComponentMap() - { - Id(x => x.Id); - Map(x => x.Description); - Component(x => x.Address); - } + Id(x => x.Id); + Map(x => x.Description); + Component(x => x.Address); } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/Conventions/ConventionBuilderSpecs.cs b/src/FluentNHibernate.Specs/Conventions/ConventionBuilderSpecs.cs index 60baf4ff5..4c3b50886 100644 --- a/src/FluentNHibernate.Specs/Conventions/ConventionBuilderSpecs.cs +++ b/src/FluentNHibernate.Specs/Conventions/ConventionBuilderSpecs.cs @@ -6,31 +6,30 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.Conventions +namespace FluentNHibernate.Specs.Conventions; + +public class when_a_convention_builder_is_used_for_properties { - public class when_a_convention_builder_is_used_for_properties + Establish context = () => { - 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"))); - }; + 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(); + 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 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"); + 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; - } -} + 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 9ae5ea9a8..74ab45e0f 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/Child.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/Child.cs @@ -1,20 +1,19 @@ using FluentNHibernate.Mapping; -namespace FluentNHibernate.Specs.Conventions.Fixtures +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class Child { - public class Child - { - public int Id { get; set; } - public Parent Parent { get; set; } - } + public int Id { get; set; } + public Parent Parent { get; set; } +} - public class ChildMap : ClassMap +public class ChildMap : ClassMap +{ + public ChildMap() { - public ChildMap() - { - Id(x => x.Id); - References(x => x.Parent) - .Columns("one", "two"); - } + Id(x => x.Id); + References(x => x.Parent) + .Columns("one", "two"); } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionConvention.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionConvention.cs index 816ee6800..00d932baa 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionConvention.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionConvention.cs @@ -2,16 +2,15 @@ using FluentNHibernate.Conventions; using FluentNHibernate.Conventions.Instances; -namespace FluentNHibernate.Specs.Conventions.Fixtures +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class CollectionConvention : ICollectionConvention { - public class CollectionConvention : ICollectionConvention - { - public const string FilterName = "TestFilterName"; - public const string FilterCondition = "TestFilterCondition"; + public const string FilterName = "TestFilterName"; + public const string FilterCondition = "TestFilterCondition"; - public void Apply(ICollectionInstance instance) - { - instance.AsList(); - } + public void Apply(ICollectionInstance instance) + { + instance.AsList(); } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionTarget.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionTarget.cs index 2dbc82569..737fdf777 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionTarget.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionTarget.cs @@ -1,35 +1,34 @@ using System.Collections.Generic; using FluentNHibernate.Mapping; -namespace FluentNHibernate.Specs.Conventions.Fixtures +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class CollectionTarget { - public class CollectionTarget - { - public int Id { get; set; } - public IList Bag { get; set; } - public ISet Set { get; set; } - } + 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 CollectionChildTarget +{ + public int Id { get; set; } +} - public class CollectionTargetMap : ClassMap +public class CollectionTargetMap : ClassMap +{ + public CollectionTargetMap() { - public CollectionTargetMap() - { - Id(x => x.Id); - HasMany(x => x.Bag); - HasMany(x => x.Set); - } + Id(x => x.Id); + HasMany(x => x.Bag); + HasMany(x => x.Set); } +} - public class CollectionChildTargetMap : ClassMap +public class CollectionChildTargetMap : ClassMap +{ + public CollectionChildTargetMap() { - public CollectionChildTargetMap() - { - Id(x => x.Id); - } + Id(x => x.Id); } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterClassConvention.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterClassConvention.cs index 99668e557..772f8a847 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterClassConvention.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterClassConvention.cs @@ -1,38 +1,37 @@ using FluentNHibernate.Conventions; using FluentNHibernate.Conventions.Instances; -namespace FluentNHibernate.Specs.Conventions.Fixtures +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class FilterClassConvention : IClassConvention { - public class FilterClassConvention : IClassConvention - { - public const string FilterName = "TestFilterName"; - public const string FilterCondition = "TestFilterCondition"; + public const string FilterName = "TestFilterName"; + public const string FilterCondition = "TestFilterCondition"; - public void Apply(IClassInstance instance) - { - instance.ApplyFilter(FilterName, FilterCondition); - } + public void Apply(IClassInstance instance) + { + instance.ApplyFilter(FilterName, FilterCondition); } +} - public class FilterHasManyConvention : IHasManyConvention - { - public const string FilterName = "TestFilterName"; - public const string FilterCondition = "TestFilterCondition"; +public class FilterHasManyConvention : IHasManyConvention +{ + public const string FilterName = "TestFilterName"; + public const string FilterCondition = "TestFilterCondition"; - public void Apply(IOneToManyCollectionInstance instance) - { - instance.ApplyFilter(FilterName, FilterCondition); - } + public void Apply(IOneToManyCollectionInstance instance) + { + instance.ApplyFilter(FilterName, FilterCondition); } +} - public class FilterHasManyToManyConvention : IHasManyToManyConvention - { - public const string FilterName = "TestFilterName"; - public const string FilterCondition = "TestFilterCondition"; +public class FilterHasManyToManyConvention : IHasManyToManyConvention +{ + public const string FilterName = "TestFilterName"; + public const string FilterCondition = "TestFilterCondition"; - public void Apply(IManyToManyCollectionInstance instance) - { - instance.ApplyFilter(FilterName, FilterCondition); - } + public void Apply(IManyToManyCollectionInstance instance) + { + instance.ApplyFilter(FilterName, FilterCondition); } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterTarget.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterTarget.cs index 898bb3997..cd3bbdf30 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterTarget.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterTarget.cs @@ -1,35 +1,34 @@ using System.Collections.Generic; using FluentNHibernate.Mapping; -namespace FluentNHibernate.Specs.Conventions.Fixtures +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class FilterTarget { - public class FilterTarget - { - public int Id { get; set; } - public IList ChildOneToMany { get; set; } - public IList ChildManyToMany { get; set; } - } + 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 FilterChildTarget +{ + public int Id { get; set; } +} - public class FilterTargetMap : ClassMap +public class FilterTargetMap : ClassMap +{ + public FilterTargetMap() { - public FilterTargetMap() - { - Id(x => x.Id); - HasMany(x => x.ChildOneToMany); - HasManyToMany(x => x.ChildManyToMany); - } + Id(x => x.Id); + HasMany(x => x.ChildOneToMany); + HasManyToMany(x => x.ChildManyToMany); } +} - public class FilterChildTargetMap : ClassMap +public class FilterChildTargetMap : ClassMap +{ + public FilterChildTargetMap() { - public FilterChildTargetMap() - { - Id(x => x.Id); - } + Id(x => x.Id); } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/FormulaConvention.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/FormulaConvention.cs index a6c4d344d..d018bff02 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/FormulaConvention.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/FormulaConvention.cs @@ -1,20 +1,19 @@ using FluentNHibernate.Conventions; using FluentNHibernate.Conventions.Instances; -namespace FluentNHibernate.Specs.Conventions.Fixtures +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class FormulaConvention : IPropertyConvention, IReferenceConvention { - public class FormulaConvention : IPropertyConvention, IReferenceConvention - { - public const string FormulaValue = "select x from y"; + public const string FormulaValue = "select x from y"; - public void Apply(IPropertyInstance instance) - { - instance.Formula(FormulaValue); - } + public void Apply(IPropertyInstance instance) + { + instance.Formula(FormulaValue); + } - public void Apply(IManyToOneInstance instance) - { - instance.Formula(FormulaValue); - } + public void Apply(IManyToOneInstance instance) + { + instance.Formula(FormulaValue); } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/FormulaTarget.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/FormulaTarget.cs index 2f324c3f6..b3fc39222 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/FormulaTarget.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/FormulaTarget.cs @@ -1,21 +1,20 @@ using FluentNHibernate.Mapping; -namespace FluentNHibernate.Specs.Conventions.Fixtures +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class FormulaTarget { - public class FormulaTarget - { - public int Id { get; private set; } - public string Prop { get; private set; } - public FormulaTarget Target { get; private set; } - } + public int Id { get; private set; } + public string Prop { get; private set; } + public FormulaTarget Target { get; private set; } +} - public class FormulaTargetMap : ClassMap +public class FormulaTargetMap : ClassMap +{ + public FormulaTargetMap() { - public FormulaTargetMap() - { - Id(x => x.Id); - Map(x => x.Prop, "a-column"); - References(x => x.Target); - } + Id(x => x.Id); + Map(x => x.Prop, "a-column"); + References(x => x.Target); } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/Parent.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/Parent.cs index 85e2f3f36..3b57f079e 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/Parent.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/Parent.cs @@ -1,20 +1,19 @@ using System.Collections.Generic; using FluentNHibernate.Mapping; -namespace FluentNHibernate.Specs.Conventions.Fixtures +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class Parent { - public class Parent - { - public int Id { get; set; } - public IList Children { get; set; } - } + public int Id { get; set; } + public IList Children { get; set; } +} - public class ParentMap : ClassMap +public class ParentMap : ClassMap +{ + public ParentMap() { - public ParentMap() - { - Id(x => x.Id); - HasMany(x => x.Children); - } + Id(x => x.Id); + HasMany(x => x.Children); } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCollectionEntity.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCollectionEntity.cs index 9d3db69bc..f46f37ebe 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCollectionEntity.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCollectionEntity.cs @@ -1,10 +1,9 @@ using System.Collections.Generic; -namespace FluentNHibernate.Specs.Conventions.Fixtures +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class SetCollectionEntity { - public class SetCollectionEntity - { - public int Id { get; set; } - public ISet Children { get; set; } - } -} \ No newline at end of file + 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 1f8161d1a..b8778533e 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCollectionEntityMap.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCollectionEntityMap.cs @@ -1,13 +1,12 @@ using FluentNHibernate.Mapping; -namespace FluentNHibernate.Specs.Conventions.Fixtures +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class SetCollectionEntityMap : ClassMap { - public class SetCollectionEntityMap : ClassMap + public SetCollectionEntityMap() { - public SetCollectionEntityMap() - { - Id(x => x.Id); - HasMany(x => x.Children); - } + Id(x => x.Id); + HasMany(x => x.Children); } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCompositeElementCollectionEntity.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCompositeElementCollectionEntity.cs index cd6844023..c4c546d7b 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCompositeElementCollectionEntity.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCompositeElementCollectionEntity.cs @@ -1,10 +1,9 @@ using System.Collections.Generic; -namespace FluentNHibernate.Specs.Conventions.Fixtures +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class SetCompositeElementCollectionEntity { - public class SetCompositeElementCollectionEntity - { - public int Id { get; set; } - public ISet Values { get; set; } - } -} \ No newline at end of file + 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 4c8163742..a5631add8 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCompositeElementCollectionEntityMap.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetCompositeElementCollectionEntityMap.cs @@ -1,14 +1,13 @@ using FluentNHibernate.Mapping; -namespace FluentNHibernate.Specs.Conventions.Fixtures +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class SetCompositeElementCollectionEntityMap : ClassMap { - public class SetCompositeElementCollectionEntityMap : ClassMap + public SetCompositeElementCollectionEntityMap() { - public SetCompositeElementCollectionEntityMap() - { - Id(x => x.Id); - HasMany(x => x.Values) - .Component(c => c.Map(x => x.Property)); - } + Id(x => x.Id); + HasMany(x => x.Values) + .Component(c => c.Map(x => x.Property)); } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetElementCollectionEntity.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetElementCollectionEntity.cs index cc9721430..8ae8cda4a 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetElementCollectionEntity.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetElementCollectionEntity.cs @@ -1,10 +1,9 @@ using System.Collections.Generic; -namespace FluentNHibernate.Specs.Conventions.Fixtures +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class SetElementCollectionEntity { - public class SetElementCollectionEntity - { - public int Id { get; set; } - public ISet Strings { get; set; } - } -} \ No newline at end of file + 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 4a860e9d7..fbae68ef9 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/SetElementCollectionEntityMap.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/SetElementCollectionEntityMap.cs @@ -1,14 +1,13 @@ using FluentNHibernate.Mapping; -namespace FluentNHibernate.Specs.Conventions.Fixtures +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class SetElementCollectionEntityMap : ClassMap { - public class SetElementCollectionEntityMap : ClassMap + public SetElementCollectionEntityMap() { - public SetElementCollectionEntityMap() - { - Id(x => x.Id); - HasMany(x => x.Strings) - .Element("Value"); - } + Id(x => x.Id); + HasMany(x => x.Strings) + .Element("Value"); } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/TwoPropertyEntity.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/TwoPropertyEntity.cs index ec898bb39..927788c5a 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/TwoPropertyEntity.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/TwoPropertyEntity.cs @@ -1,9 +1,8 @@ -namespace FluentNHibernate.Specs.Conventions.Fixtures +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +class TwoPropertyEntity { - class TwoPropertyEntity - { - public int Id { get; set; } - public string TargetProperty { get; set; } - public string OtherProperty { get; set; } - } -} \ No newline at end of file + 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 b42c0282f..92c117ec8 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/TwoPropertyEntityMap.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/TwoPropertyEntityMap.cs @@ -1,14 +1,13 @@ using FluentNHibernate.Mapping; -namespace FluentNHibernate.Specs.Conventions.Fixtures +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +class TwoPropertyEntityMap : ClassMap { - class TwoPropertyEntityMap : ClassMap + public TwoPropertyEntityMap() { - public TwoPropertyEntityMap() - { - Id(x => x.Id); - Map(x => x.TargetProperty); - Map(x => x.OtherProperty); - } + Id(x => x.Id); + Map(x => x.TargetProperty); + Map(x => x.OtherProperty); } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/Value.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/Value.cs index 6461f3e44..64dd1e713 100644 --- a/src/FluentNHibernate.Specs/Conventions/Fixtures/Value.cs +++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/Value.cs @@ -1,7 +1,6 @@ -namespace FluentNHibernate.Specs.Conventions.Fixtures +namespace FluentNHibernate.Specs.Conventions.Fixtures; + +public class Value { - public class Value - { - public string Property { get; set; } - } -} \ No newline at end of file + public string Property { get; set; } +} diff --git a/src/FluentNHibernate.Specs/Conventions/ForeignKeyConventionSpecs.cs b/src/FluentNHibernate.Specs/Conventions/ForeignKeyConventionSpecs.cs index f27a0c280..5e55a2a6e 100644 --- a/src/FluentNHibernate.Specs/Conventions/ForeignKeyConventionSpecs.cs +++ b/src/FluentNHibernate.Specs/Conventions/ForeignKeyConventionSpecs.cs @@ -6,61 +6,60 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.Conventions +namespace FluentNHibernate.Specs.Conventions; + +public abstract class ForeignKeyConventionSpec { - public abstract class ForeignKeyConventionSpec + Establish context = () => { - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Conventions.Add(new TestForeignKeyConvention()); - }; + model = new FluentNHibernate.PersistenceModel(); + model.Conventions.Add(new TestForeignKeyConvention()); + }; - protected static FluentNHibernate.PersistenceModel model; - protected static ClassMapping mapping; + protected static FluentNHibernate.PersistenceModel model; + protected static ClassMapping mapping; - class TestForeignKeyConvention : ForeignKeyConvention + class TestForeignKeyConvention : ForeignKeyConvention + { + protected override string GetKeyName(Member property, Type type) { - protected override string GetKeyName(Member property, Type type) - { - return "KEY_NAME"; - } + return "KEY_NAME"; } } +} - public class when_a_foreign_key_convention_is_being_applied_to_a_set_mapping : ForeignKeyConventionSpec - { - Establish context = () => - model.Add(new SetCollectionEntityMap()); +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(); + Because of = () => + mapping = model.BuildMappingFor(); - It should_override_the_key_column_name = () => - mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("KEY_NAME"); - } + 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()); +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(); + Because of = () => + mapping = model.BuildMappingFor(); - It should_override_the_key_column_name = () => - mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("KEY_NAME"); - } + 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()); +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(); + Because of = () => + mapping = model.BuildMappingFor(); - It should_override_the_key_column_name = () => - mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("KEY_NAME"); - } -} + 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 27fff65a5..2bdc469fd 100644 --- a/src/FluentNHibernate.Specs/Conventions/FormulaConventionSpecs.cs +++ b/src/FluentNHibernate.Specs/Conventions/FormulaConventionSpecs.cs @@ -5,51 +5,50 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.Conventions +namespace FluentNHibernate.Specs.Conventions; + +[Subject(typeof(IPropertyConvention))] +public class when_a_formula_is_added_to_a_property { - [Subject(typeof(IPropertyConvention))] - public class when_a_formula_is_added_to_a_property + Establish context = () => { - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Conventions.Add(); - model.Add(new FormulaTargetMap()); - }; + model = new FluentNHibernate.PersistenceModel(); + model.Conventions.Add(); + model.Add(new FormulaTargetMap()); + }; - Because of = () => - mapping = model.BuildMappingFor(); + Because of = () => + mapping = model.BuildMappingFor(); - It should_remove_all_columns_from_the_property = () => - mapping.Properties.Single().Columns.Should().BeEmpty(); + 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); + It should_add_the_formula_to_the_property = () => + mapping.Properties.Single().Formula.Should().Be(FormulaConvention.FormulaValue); - static FluentNHibernate.PersistenceModel model; - static ClassMapping mapping; - } + static FluentNHibernate.PersistenceModel model; + static ClassMapping mapping; +} - [Subject(typeof(IReferenceConvention))] - public class when_a_formula_is_added_to_a_reference +[Subject(typeof(IReferenceConvention))] +public class when_a_formula_is_added_to_a_reference +{ + Establish context = () => { - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Conventions.Add(); - model.Add(new FormulaTargetMap()); - }; + model = new FluentNHibernate.PersistenceModel(); + model.Conventions.Add(); + model.Add(new FormulaTargetMap()); + }; - Because of = () => - mapping = model.BuildMappingFor(); + Because of = () => + mapping = model.BuildMappingFor(); - It should_remove_all_columns_from_the_property = () => - mapping.References.Single().Columns.Should().BeEmpty(); + 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); + It should_add_the_formula_to_the_property = () => + mapping.References.Single().Formula.Should().Be(FormulaConvention.FormulaValue); - static FluentNHibernate.PersistenceModel model; - static ClassMapping mapping; - } -} + 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 cfbc82e04..f27cb8d8b 100644 --- a/src/FluentNHibernate.Specs/Diagnostics/Registration_diagnostics_specs.cs +++ b/src/FluentNHibernate.Specs/Diagnostics/Registration_diagnostics_specs.cs @@ -9,394 +9,393 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.Diagnostics +namespace FluentNHibernate.Specs.Diagnostics; + +public class when_registering_types_with_diagnostics_enabled { - public class when_registering_types_with_diagnostics_enabled + Establish context = () => { - Establish context = () => - { - var dispatcher = new DefaultDiagnosticMessageDispatcher(); - dispatcher.RegisterListener(new StubListener(x => results = x)); + var dispatcher = new DefaultDiagnosticMessageDispatcher(); + dispatcher.RegisterListener(new StubListener(x => results = x)); - model = new FluentNHibernate.PersistenceModel(); - model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); - }; + 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(); - }; + 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_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_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_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_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_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)); + It should_not_register_non_fluent_mapping_types = () => + results.FluentMappings.Should().NotContain(typeof(First)); - static FluentNHibernate.PersistenceModel model; - static DiagnosticResults results; - } + static FluentNHibernate.PersistenceModel model; + static DiagnosticResults results; +} - public class when_registering_conventions_with_diagnostics_enabled +public class when_registering_conventions_with_diagnostics_enabled +{ + Establish context = () => { - Establish context = () => - { - var dispatcher = new DefaultDiagnosticMessageDispatcher(); - dispatcher.RegisterListener(new StubListener(x => results = x)); + var dispatcher = new DefaultDiagnosticMessageDispatcher(); + dispatcher.RegisterListener(new StubListener(x => results = x)); - model = new FluentNHibernate.PersistenceModel(); - model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); - }; + model = new FluentNHibernate.PersistenceModel(); + model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); + }; - Because of = () => - { - model.Conventions.AddSource(new StubTypeSource(typeof(ConventionA), typeof(ConventionB), typeof(NotAConvention))); - model.BuildMappings(); - }; + 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_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_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_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)); + It should_not_register_non_convention_types = () => + results.Conventions.Should().NotContain(typeof(NotAConvention)); - static FluentNHibernate.PersistenceModel model; - static DiagnosticResults results; - } + static FluentNHibernate.PersistenceModel model; + static DiagnosticResults results; +} - public class when_automapping_with_diagnostics_enabled +public class when_automapping_with_diagnostics_enabled +{ + Establish context = () => { - Establish context = () => - { - var dispatcher = new DefaultDiagnosticMessageDispatcher(); - dispatcher.RegisterListener(new StubListener(x => results = x)); + 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 = AutoMap.Source(new StubTypeSource(typeof(First), typeof(Second), typeof(Third)), new TestAutomappingConfiguration()); - model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); - }; + model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); + }; - Because of = () => - model.BuildMappings(); + Because of = () => + model.BuildMappings(); - It should_produce_results_when_enabled = () => - results.Should().NotBeNull(); + 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_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_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_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_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))); + 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; + static AutoPersistenceModel model; + static DiagnosticResults results; - class TestAutomappingConfiguration : DefaultAutomappingConfiguration + class TestAutomappingConfiguration : DefaultAutomappingConfiguration + { + public override bool ShouldMap(Type type) { - public override bool ShouldMap(Type type) - { - return type != typeof(First); - } + return type != typeof(First); } } +} - public class when_automapping_with_diagnostics_enabled_and_excluding_by_where +public class when_automapping_with_diagnostics_enabled_and_excluding_by_where +{ + Establish context = () => { - Establish context = () => - { - var dispatcher = new DefaultDiagnosticMessageDispatcher(); - dispatcher.RegisterListener(new StubListener(x => results = x)); + 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 = AutoMap.Source(new StubTypeSource(typeof(First), typeof(Second), typeof(Third))) + .Where(x => x != typeof(First)); - model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); - }; + model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); + }; - Because of = () => - model.BuildMappings(); + Because of = () => + model.BuildMappings(); - It should_produce_results_when_enabled = () => - results.Should().NotBeNull(); + 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_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_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_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_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))); + 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; - } + static AutoPersistenceModel model; + static DiagnosticResults results; +} - public class when_automapping_with_diagnostics_enabled_and_excluding_by_IgnoreBase +public class when_automapping_with_diagnostics_enabled_and_excluding_by_IgnoreBase +{ + Establish context = () => { - Establish context = () => - { - var dispatcher = new DefaultDiagnosticMessageDispatcher(); - dispatcher.RegisterListener(new StubListener(x => results = x)); + var dispatcher = new DefaultDiagnosticMessageDispatcher(); + dispatcher.RegisterListener(new StubListener(x => results = x)); - model = AutoMap.Source(new StubTypeSource(typeof(First), typeof(Second), typeof(Third))) - .IgnoreBase(); + model = AutoMap.Source(new StubTypeSource(typeof(First), typeof(Second), typeof(Third))) + .IgnoreBase(); - model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); - }; + model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); + }; - Because of = () => - model.BuildMappings(); + Because of = () => + model.BuildMappings(); - It should_produce_results_when_enabled = () => - results.Should().NotBeNull(); + 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_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_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_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_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))); + 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; - } + static AutoPersistenceModel model; + static DiagnosticResults results; +} - public class when_automapping_with_diagnostics_enabled_and_excluding_by_generic_IgnoreBase +public class when_automapping_with_diagnostics_enabled_and_excluding_by_generic_IgnoreBase +{ + Establish context = () => { - Establish context = () => - { - var dispatcher = new DefaultDiagnosticMessageDispatcher(); - dispatcher.RegisterListener(new StubListener(x => results = x)); + 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 = AutoMap.Source(new StubTypeSource(typeof(Something), typeof(Second), typeof(Third))) + .IgnoreBase(typeof(Something<>)); - model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); - }; + model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); + }; - Because of = () => - model.BuildMappings(); + Because of = () => + model.BuildMappings(); - It should_produce_results_when_enabled = () => - results.Should().NotBeNull(); + 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_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_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_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_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))); + 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; - } + static AutoPersistenceModel model; + static DiagnosticResults results; +} - public class when_automapping_with_diagnostics_enabled_and_excluding_by_layer_supertype +public class when_automapping_with_diagnostics_enabled_and_excluding_by_layer_supertype +{ + Establish context = () => { - Establish context = () => - { - var dispatcher = new DefaultDiagnosticMessageDispatcher(); - dispatcher.RegisterListener(new StubListener(x => results = x)); + 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 = AutoMap.Source(new StubTypeSource(typeof(Abstract), typeof(Second), typeof(Third)), new TestAutomappingConfiguration()); - model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); - }; + model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); + }; - Because of = () => - model.BuildMappings(); + Because of = () => + model.BuildMappings(); - It should_produce_results_when_enabled = () => - results.Should().NotBeNull(); + 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_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_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_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_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))); + 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; + static AutoPersistenceModel model; + static DiagnosticResults results; - class TestAutomappingConfiguration : DefaultAutomappingConfiguration + class TestAutomappingConfiguration : DefaultAutomappingConfiguration + { + public override bool AbstractClassIsLayerSupertype(Type type) { - public override bool AbstractClassIsLayerSupertype(Type type) - { - return type == typeof(Abstract); - } + return type == typeof(Abstract); } } +} - public class when_automapping_with_diagnostics_enabled_and_excluding_by_explicit_component +public class when_automapping_with_diagnostics_enabled_and_excluding_by_explicit_component +{ + Establish context = () => { - Establish context = () => - { - var dispatcher = new DefaultDiagnosticMessageDispatcher(); - dispatcher.RegisterListener(new StubListener(x => results = x)); + 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 = AutoMap.Source(new StubTypeSource(typeof(Component), typeof(Second), typeof(Third)), new TestAutomappingConfiguration()); - model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); - }; + model.SetLogger(new DefaultDiagnosticLogger(dispatcher)); + }; - Because of = () => - model.BuildMappings(); + Because of = () => + model.BuildMappings(); - It should_produce_results_when_enabled = () => - results.Should().NotBeNull(); + 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_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_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_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_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))); + 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; + static AutoPersistenceModel model; + static DiagnosticResults results; - class TestAutomappingConfiguration : DefaultAutomappingConfiguration + class TestAutomappingConfiguration : DefaultAutomappingConfiguration + { + public override bool IsComponent(Type type) { - public override bool IsComponent(Type type) - { - return type == typeof(Component); - } + return type == typeof(Component); } } +} - abstract class Abstract - {} +abstract class Abstract +{} - class FirstMap : ClassMap +class FirstMap : ClassMap +{ + public FirstMap() { - public FirstMap() - { - Id(x => x.Id); - } + Id(x => x.Id); } +} - class First - { - public int Id { get; set; } - } +class First +{ + public int Id { get; set; } +} - class Something - {} +class Something +{} - class SecondMap : ClassMap +class SecondMap : ClassMap +{ + public SecondMap() { - public SecondMap() - { - Id(x => x.Id); - } + Id(x => x.Id); } +} - class Second - { - public int Id { get; set; } - } +class Second +{ + public int Id { get; set; } +} - class Third - { - public int Id { get; set; } - } +class Third +{ + public int Id { get; set; } +} - class ChildMap : SubclassMap {} +class ChildMap : SubclassMap {} - class Child : Second {} +class Child : Second {} - class CompMap : ComponentMap {} - class Comp {} - class ConventionA : IConvention {} - class ConventionB : IConvention {} - class NotAConvention {} +class CompMap : ComponentMap {} +class Comp {} +class ConventionA : IConvention {} +class ConventionB : IConvention {} +class NotAConvention {} - class StubListener : IDiagnosticListener - { - readonly Action receiver; +class StubListener : IDiagnosticListener +{ + readonly Action receiver; - public StubListener(Action receiver) - { - this.receiver = receiver; - } + public StubListener(Action receiver) + { + this.receiver = receiver; + } - public void Receive(DiagnosticResults results) - { - receiver(results); - } + public void Receive(DiagnosticResults results) + { + receiver(results); } -} +} diff --git a/src/FluentNHibernate.Specs/Extensions.cs b/src/FluentNHibernate.Specs/Extensions.cs index ce616b256..e3165c56e 100644 --- a/src/FluentNHibernate.Specs/Extensions.cs +++ b/src/FluentNHibernate.Specs/Extensions.cs @@ -7,42 +7,41 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs +namespace FluentNHibernate.Specs; + +public static class Extensions { - public static class Extensions + public static T As(this object instance) { - public static T As(this object instance) - { - return (T)instance; - } + return (T)instance; + } - public static void ShouldContain(this IEnumerable collection, Func predicate) - { - collection.Any(predicate).Should().BeTrue(); - } + 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 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 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); + 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); - } + 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 77c321f99..c8383a90a 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/BiDirectionalKeyIssueSpecs.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/BiDirectionalKeyIssueSpecs.cs @@ -4,28 +4,27 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.FluentInterface +namespace FluentNHibernate.Specs.FluentInterface; + +public class when_there_are_two_references_to_the_same_entity { - public class when_there_are_two_references_to_the_same_entity + Establish context = () => { - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Add(new ContactMap()); - model.Add(new ContactEmailMap()); - model.Add(new ContactPhoneMap()); - model.Add(new CaseMap()); - }; + 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(); + 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"); + 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; - } -} + 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 23c629488..2a5436aa3 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Cache.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Cache.cs @@ -4,19 +4,18 @@ using FluentNHibernate.Specs.FluentInterface.Fixtures; using Machine.Specifications; -namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs +namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; + +public class when_class_map_is_told_to_configure_the_cache : ProviderSpec { - public class when_class_map_is_told_to_configure_the_cache : ProviderSpec - { - Because of = () => - mapping = map_as_class(m => m.Cache.ReadOnly()); + 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_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"); + It should_set_the_cache_usage_to_the_value_used = () => + mapping.Cache.Usage.Should().Be("read-only"); - static ClassMapping mapping; - } -} \ No newline at end of file + static ClassMapping mapping; +} diff --git a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Component.cs b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Component.cs index 2cf5d6e26..f091e07e2 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Component.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Component.cs @@ -6,113 +6,112 @@ using FluentNHibernate.Specs.FluentInterface.Fixtures; using Machine.Specifications; -namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs +namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; + +public class when_class_map_is_told_to_map_a_component : ProviderSpec { - 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 => {})); + Because of = () => + mapping = map_as_class(m => m.Component(x => x.Component, c => {})); - Behaves_like a_component_in_a_classlike; + Behaves_like a_component_in_a_classlike; - protected static ClassMapping mapping; - } + 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 => { })); +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; + Behaves_like a_component_in_a_classlike; - protected static ClassMapping mapping; - } + 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())); +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; + Behaves_like a_component_in_a_classlike; - protected static ClassMapping mapping; + protected static ClassMapping mapping; - private class ComponentMappingProviderStub : IComponentMappingProvider + private class ComponentMappingProviderStub : IComponentMappingProvider + { + public IComponentMapping GetComponentMapping() { - public IComponentMapping GetComponentMapping() - { - return null; - } + 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 => { })); +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; + Behaves_like a_component_in_a_classlike; - protected static ClassMapping mapping; - } + 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 => { })); +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; + Behaves_like a_component_in_a_classlike; - protected static ClassMapping mapping; - } + 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 => { })); +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; + Behaves_like a_component_in_a_classlike; - protected static ClassMapping mapping; - } + 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 => { })); +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; + Behaves_like a_component_in_a_classlike; - protected static ClassMapping mapping; - } + 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)); +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; + Behaves_like a_component_in_a_classlike; - protected static ClassMapping mapping; - } + 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)); +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; + Behaves_like a_component_in_a_classlike; - protected static ClassMapping mapping; - } + 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"))); +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; + Behaves_like a_component_in_a_classlike; - protected static ClassMapping mapping; - } -} \ No newline at end of file + 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 59fd126fa..fdaeceec9 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Discriminator.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Discriminator.cs @@ -4,35 +4,34 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs +namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; + +public class when_class_map_is_told_to_create_a_discriminator : ProviderSpec { - public class when_class_map_is_told_to_create_a_discriminator : ProviderSpec - { - Because of = () => - class_mapping = map_as_class(m => m.DiscriminateSubClassesOnColumn(column_name)); + 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_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_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); + 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"; - } + 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)); +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); + 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"; - } -} \ No newline at end of file + 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 cf2a47b1b..04972ddd8 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.HasMany.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.HasMany.cs @@ -5,113 +5,112 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs +namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; + +public class when_class_map_is_told_to_map_a_has_many_bag : ProviderSpec { - 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)); + Because of = () => + mapping = map_as_class(m => m.HasMany(x => x.BagOfChildren)); - Behaves_like a_bag_in_a_classlike_mapping; + 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"); + 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; - } + 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)); +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; + Behaves_like a_set_in_a_classlike_mapping; - protected static ClassMapping 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()); +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; + Behaves_like a_list_with_the_default_index_in_a_classlike_mapping; - protected static ClassMapping 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(); - })); +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; + Behaves_like a_list_with_a_custom_index_in_a_classlike_mapping; - protected static ClassMapping 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)); +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; + Behaves_like an_array_in_a_classlike_mapping; - protected static ClassMapping 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)); +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; + 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"); + 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; - } + 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"))); +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; + 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"); + 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; - } + 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)); - })); +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_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_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_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(); + It should_create_a_property_inside_the_nested_component = () => + mapping.Collections.Single().CompositeElement.CompositeElements.Single().Properties.Should().NotBeEmpty(); - static ClassMapping mapping; - } -} \ No newline at end of file + static ClassMapping mapping; +} diff --git a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.HasOne.cs b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.HasOne.cs index 5b69480cf..77b86cf78 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.HasOne.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.HasOne.cs @@ -2,25 +2,24 @@ using FluentNHibernate.Specs.FluentInterface.Fixtures; using Machine.Specifications; -namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs +namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; + +public class when_class_map_is_told_to_map_a_has_one : ProviderSpec { - 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)); + Because of = () => + mapping = map_as_class(m => m.HasOne(x => x.Reference)); - Behaves_like a_has_one_in_a_classlike_mapping; + Behaves_like a_has_one_in_a_classlike_mapping; - protected static ClassMapping 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"))); +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; + Behaves_like a_has_one_in_a_classlike_mapping; - protected static ClassMapping mapping; - } -} \ No newline at end of file + 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 c978e856a..bc4b32e6b 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Id.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Id.cs @@ -6,46 +6,45 @@ 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(); +namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; - It should_not_set_the_member_on_the_id = () => - Id.Member.Should().BeNull(); +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_not_specify_any_columns_for_the_id = () => - Id.Columns.Should().BeEmpty(); + It should_set_the_id_on_the_mapping = () => + Id.Should().NotBeNull(); - It should_specify_the_default_generator_for_the_id = () => - Id.Generator.Class.Should().Be("increment"); + It should_not_set_the_member_on_the_id = () => + Id.Member.Should().BeNull(); - It should_set_the_id_type_to_int_by_default = () => - Id.Type.Should().Be(new TypeReference(typeof(int))); + It should_not_specify_any_columns_for_the_id = () => + Id.Columns.Should().BeEmpty(); - static ClassMapping mapping; + It should_specify_the_default_generator_for_the_id = () => + Id.Generator.Class.Should().Be("increment"); - static IdMapping Id { get { return mapping.Id as IdMapping; }} - } + It should_set_the_id_type_to_int_by_default = () => + Id.Type.Should().Be(new TypeReference(typeof(int))); - 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")); + static ClassMapping mapping; - 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 IdMapping Id { get { return mapping.Id as IdMapping; }} +} - static ClassMapping mapping; - } -} \ No newline at end of file +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 d733fee02..04ab373eb 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Property.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Property.cs @@ -2,45 +2,44 @@ using FluentNHibernate.Specs.FluentInterface.Fixtures; using Machine.Specifications; -namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs +namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; + +public class when_class_map_is_told_to_map_a_property : ProviderSpec { - public class when_class_map_is_told_to_map_a_property : ProviderSpec - { - Because of = () => - mapping = map_as_class(o => o.Map(x => x.Name)); + Because of = () => + mapping = map_as_class(o => o.Map(x => x.Name)); - Behaves_like a_property_in_a_classlike_mapping; + Behaves_like a_property_in_a_classlike_mapping; - protected static ClassMapping 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)); +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; + Behaves_like a_property_in_a_classlike_mapping; - protected static ClassMapping 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"))); +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; + Behaves_like a_property_in_a_classlike_mapping; - protected static ClassMapping 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"))); +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; + Behaves_like a_property_in_a_classlike_mapping; - protected static ClassMapping mapping; - } -} \ No newline at end of file + 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 b84e882a2..a9f1373cb 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Subclass.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Subclass.cs @@ -5,43 +5,42 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs +namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; + +public class when_class_map_is_told_to_create_an_inline_subclass : ProviderSpec { - public class when_class_map_is_told_to_create_an_inline_subclass : ProviderSpec - { - // ignored warning for obsolete SubClass + // ignored warning for obsolete SubClass #pragma warning disable 612,618 - Because of = () => - class_mapping = map_as_class(m => m.DiscriminateSubClassesOnColumn("col").SubClass(sc => { })); + 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); + It should_add_subclass_to_class_mapping_subclasses_collection = () => + class_mapping.Subclasses.Count().Should().Be(1); - static ClassMapping class_mapping; - } + static ClassMapping class_mapping; +} - public class when_class_map_is_told_to_create_an_inline_joined_subclass : ProviderSpec - { - // ignored warning for obsolete JoinedSubClass +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 => { })); + 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_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_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"); + 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; - } -} \ No newline at end of file + 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 8946aac84..e99d4ebe2 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Version.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClassMapSpecs/ClassMapSpecs.Version.cs @@ -4,39 +4,38 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs +namespace FluentNHibernate.Specs.FluentInterface.ClassMapSpecs; + +public class when_class_map_is_told_to_map_a_version : ProviderSpec { - public class when_class_map_is_told_to_map_a_version : ProviderSpec - { - Because of = () => - mapping = map_as_class(m => m.Version(x => x.VersionNumber)); + 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_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_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"); + It should_use_the_property_name_for_the_column_name = () => + mapping.Version.Columns.Single().Name.Should().Be("VersionNumber"); - static ClassMapping mapping; - } + 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"))); +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_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_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"); + It should_use_the_property_name_for_the_column_name = () => + mapping.Version.Columns.Single().Name.Should().Be("VersionNumber"); - static ClassMapping mapping; - } -} \ No newline at end of file + static ClassMapping mapping; +} diff --git a/src/FluentNHibernate.Specs/FluentInterface/ClasslikeBehaviors.cs b/src/FluentNHibernate.Specs/FluentInterface/ClasslikeBehaviors.cs index c62a5efce..70a0f3720 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ClasslikeBehaviors.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ClasslikeBehaviors.cs @@ -6,195 +6,194 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.FluentInterface +namespace FluentNHibernate.Specs.FluentInterface; + +[Behaviors] +public class ClasslikePropertyBehaviour { - [Behaviors] - public class ClasslikePropertyBehaviour - { - protected static ClassMappingBase mapping; + 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_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_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_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"); - } + 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; +[Behaviors] +public class ClasslikeComponentBehaviour +{ + protected static ClassMappingBase mapping; - It should_add_a_component_to_the_components_collection = () => - mapping.Components.Count().Should().Be(1); - } + It should_add_a_component_to_the_components_collection = () => + mapping.Components.Count().Should().Be(1); +} - [Behaviors] - public class ClasslikeHasOneBehaviour - { - protected static ClassMappingBase mapping; +[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_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"); - } + 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); +[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_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_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_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_create_a_single_column_for_the_key = () => + mapping.Collections.Single().Key.Columns.Count().Should().Be(1); - protected static ClassMappingBase mapping; - } + protected static ClassMappingBase mapping; +} - [Behaviors] - public class ClasslikeSetBehaviour - { - It should_add_only_one_collection_to_the_mapping = () => - mapping.Collections.Count().Should().Be(1); +[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_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_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_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_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_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; - } + protected static ClassMappingBase mapping; +} - [Behaviors] - public class ClasslikeListWithDefaultIndexBehaviour : ClasslikeListBehaviour - { - It should_create_an_index_for_the_collection_mapping = () => - mapping.Collections.Single().Index.Should().NotBeNull(); +[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_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"); - } + 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(); +[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_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_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))); - } + 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); +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_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_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_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_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"); + 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; - } + protected static ClassMappingBase mapping; +} - [Behaviors] - public class ClasslikeArrayBehaviour - { - It should_add_only_one_collection_to_the_mapping = () => - mapping.Collections.Count().Should().Be(1); +[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_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_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_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_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_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_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_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"); + It should_use_specified_property_as_the_index_column_name = () => + mapping.Collections.Single().Index.Columns.Single().Name.Should().Be("Position"); - protected static ClassMappingBase mapping; - } + protected static ClassMappingBase mapping; +} - [Behaviors] - public class HasManyElementBehaviour - { - It should_create_a_collection = () => - collection.Should().NotBeNull(); +[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_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_an_inner_relationship = () => + collection.Relationship.Should().BeNull(); - It should_not_create_a_component = () => - collection.CompositeElement.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"); + It should_use_the_default_column_name_for_the_element = () => + collection.Element.Columns.Single().Name.Should().Be("value"); - protected static CollectionMapping collection; - } -} \ No newline at end of file + protected static CollectionMapping collection; +} diff --git a/src/FluentNHibernate.Specs/FluentInterface/ComponentMapSpecs.cs b/src/FluentNHibernate.Specs/FluentInterface/ComponentMapSpecs.cs index dbca78653..48c58a40b 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ComponentMapSpecs.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ComponentMapSpecs.cs @@ -8,333 +8,332 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.FluentInterface +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 { - public class when_creating_the_mapping_for_a_component_using_component_map + 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 = () => { - 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 - {} + 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; } } - public class when_mapping_a_component_in_an_entity_without_defining_any_mappings_for_the_component + private class TargetChild : Target { - Establish context = () => - { - classmap = new ClassMap(); - classmap.Id(x => x.Id); - classmap.Component(x => x.Component); - }; + public Component Component { get; set; } + } - Because of = () => - mapping = (classmap as IMappingProvider).GetClassMapping() - .Components.First(); + private class Component + { + public string Property { get; set; } + } +} - It should_create_a_reference_component_mapping = () => - mapping.Should().BeOfType(); +public class when_compiling_the_mappings_with_a_nested_reference_component_in_a_component_map +{ + Establish context = () => + { + component_map = new ComponentMap(); + }; - It should_store_the_property_in_the_reference_component_mapping = () => - (mapping as ReferenceComponentMapping).Member.Name.Should().Be("Component"); + Because of = () => + ex = Catch.Exception(() => component_map.Component(x => x.Compo)); - private static ClassMap classmap; - private static IComponentMapping mapping; + It should_throw_a_not_supported_exception = () => + ex.Should().BeOfType(); - private class Target - { - public int Id { get; set; } - public Component Component { get; set;} - } + static ComponentMap component_map; + static Exception ex; - private class Component {} + private class Component + { + public Component Compo { get; set; } } +} - public class when_compiling_the_mappings_with_a_reference_component_in_a_subclass +public class when_compiling_the_mappings_with_a_reference_component_and_a_related_external_component +{ + Establish context = () => { - 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; } - } + 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; } } - public class when_compiling_the_mappings_with_a_nested_reference_component_in_a_component_map + private class Component { - Establish context = () => - { - component_map = new ComponentMap(); - }; + public string Property { get; set; } + } +} - Because of = () => - ex = Catch.Exception(() => component_map.Component(x => x.Compo)); +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_throw_a_not_supported_exception = () => - ex.Should().BeOfType(); + It should_merge_the_component_mappings_with_the_mapping_from_the_component_map = () => + class_mapping.Components.Select(x => x.Name).Should().Contain("ComponentA", "ComponentB"); - static ComponentMap component_map; - static Exception ex; + 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 Component Compo { get; set; } - } + private class Component + { + public string Property { get; set; } } +} - public class when_compiling_the_mappings_with_a_reference_component_and_a_related_external_component +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 { - 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 int Id { get; set; } + public Component Component { get; set; } } - public class when_compiling_the_mappings_with_two_of_the_same_reference_component_and_a_related_external_component + private class 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 NestedComponent NestedComponent1 { get; set; } + public NestedComponent NestedComponent2 { get; set; } } - public class when_compiling_the_mappings_with_multiple_nested_component_mappings + private class NestedComponent { - 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; } - } + public string Property { get; set; } } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/FluentInterface/ExternalComponentOutputSpecs.cs b/src/FluentNHibernate.Specs/FluentInterface/ExternalComponentOutputSpecs.cs index a4198d95a..9a9b092a1 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ExternalComponentOutputSpecs.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ExternalComponentOutputSpecs.cs @@ -7,68 +7,67 @@ using Machine.Specifications.Model; using FluentAssertions; -namespace FluentNHibernate.Specs.FluentInterface +namespace FluentNHibernate.Specs.FluentInterface; + +public class when_generating_the_output_for_a_resolved_component_reference { - public class when_generating_the_output_for_a_resolved_component_reference + Establish context = () => { - 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)); + 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); + 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); - }; + reference_component = new ClassMap(); + reference_component.Id(x => x.Id); + reference_component.Component(x => x.ComponentProperty1); + reference_component.Component(x => x.ComponentProperty2); + }; - Because of = () => + Because of = () => + { + inline_xml = render_xml(x => x.Add(inline_component)); + referenced_xml = render_xml(x => { - inline_xml = render_xml(x => x.Add(inline_component)); - referenced_xml = render_xml(x => - { - x.Add(reference_component); - x.Add(external_component); - }); - }; + x.Add(reference_component); + x.Add(external_component); + }); + }; - It should_be_rendered_the_same_as_an_inline_component = () => - referenced_xml.Should().Be(inline_xml); + 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(); + private static string render_xml(Action addMappings) + { + var model = new FluentNHibernate.PersistenceModel(); - addMappings(model); + addMappings(model); - var mappings = model.BuildMappings(); - var doc = new MappingXmlSerializer().Serialize(mappings.First()); + var mappings = model.BuildMappings(); + var doc = new MappingXmlSerializer().Serialize(mappings.First()); - return doc.OuterXml; - } + 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 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 Target + { + public int Id { get; set;} + public Component ComponentProperty1 { get; set; } + public Component ComponentProperty2 { get; set; } + } - private class Component - { - public string Property { get; set; } - } + private class Component + { + public string Property { get; set; } } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/BiDirectionalKeyIssue.cs b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/BiDirectionalKeyIssue.cs index 35830ae6b..d6c93c279 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/BiDirectionalKeyIssue.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/BiDirectionalKeyIssue.cs @@ -2,78 +2,77 @@ using System.Collections.Generic; using FluentNHibernate.Mapping; -namespace FluentNHibernate.Specs.FluentInterface.Fixtures.BiDirectionalKeyIssue -{ - public abstract class Entity - { - public Guid Id { get; set; } - } +namespace FluentNHibernate.Specs.FluentInterface.Fixtures.BiDirectionalKeyIssue; - public class ContactMap : DomainMap - { - public ContactMap() - { - HasMany(x => x.EmailAddresses); - HasMany(x => x.PhoneNumbers); - } - } +public abstract class Entity +{ + public Guid Id { get; set; } +} - public class Contact : Entity +public class ContactMap : DomainMap +{ + public ContactMap() { - public virtual IEnumerable EmailAddresses { get; set; } - public virtual IEnumerable PhoneNumbers { get; set; } + HasMany(x => x.EmailAddresses); + HasMany(x => x.PhoneNumbers); } +} - public class ContactEmail : Entity - { - public virtual string EmailAddress { get; set; } - public virtual Contact Contact { get; set; } - } +public class Contact : Entity +{ + public virtual IEnumerable EmailAddresses { get; set; } + public virtual IEnumerable PhoneNumbers { get; set; } +} - public class ContactPhone : Entity - { - public virtual string PhoneNumber { get; set; } - } +public class ContactEmail : Entity +{ + public virtual string EmailAddress { get; set; } + public virtual Contact Contact { get; set; } +} - public class ContactEmailMap : DomainMap - { - public ContactEmailMap() - { - Map(c => c.EmailAddress); - References(x => x.Contact); - } - } +public class ContactPhone : Entity +{ + public virtual string PhoneNumber { get; set; } +} - public class ContactPhoneMap : DomainMap +public class ContactEmailMap : DomainMap +{ + public ContactEmailMap() { - public ContactPhoneMap() - { - Map(c => c.PhoneNumber); - } + Map(c => c.EmailAddress); + References(x => x.Contact); } +} - public class DomainMap : ClassMap where T : Entity +public class ContactPhoneMap : DomainMap +{ + public ContactPhoneMap() { - public DomainMap() - { - Id(x => x.Id).Column("id").GeneratedBy.GuidComb(); - Table(typeof(T).Name); - } + Map(c => c.PhoneNumber); } +} - public class CaseMap : DomainMap +public class DomainMap : ClassMap where T : Entity +{ + public DomainMap() { - public CaseMap() - { - References(c => c.AlternateContact); - References(c => c.Contact); - Table("Cases"); - } + Id(x => x.Id).Column("id").GeneratedBy.GuidComb(); + Table(typeof(T).Name); } +} - public class Case : Entity +public class CaseMap : DomainMap +{ + public CaseMap() { - public virtual Contact Contact { get; set; } - public virtual Contact AlternateContact { get; set; } + 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 b1b03ae02..567144113 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithCollections.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithCollections.cs @@ -1,31 +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; } +namespace FluentNHibernate.Specs.FluentInterface.Fixtures; - public IList BagOfStrings { get; set; } - } +class EntityWithCollections +{ + public EntityCollectionChild[] ArrayOfChildren { get; set; } + public IList BagOfChildren { get; set; } + public ISet SetOfChildren { get; set; } - class EntityWithFieldCollections - { - public IList BagOfChildren; - } + public IList BagOfStrings { get; set; } +} - class EntityCollectionChild - { - public int Position { get; set; } - public AreaComponent Area { get; set; } - } +class EntityWithFieldCollections +{ + public IList BagOfChildren; +} - class AreaComponent - { - public int Lat { get; set; } - public int Long { get; set; } - } +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 a7e2473f1..8611337a2 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithComponent.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithComponent.cs @@ -1,21 +1,20 @@ using System; using System.Collections; -namespace FluentNHibernate.Specs.FluentInterface.Fixtures +namespace FluentNHibernate.Specs.FluentInterface.Fixtures; + +class EntityWithComponent { - class EntityWithComponent - { - public ComponentTarget Component { get; set; } - public IDictionary DynamicComponent { get; set; } - } + public ComponentTarget Component { get; set; } + public IDictionary DynamicComponent { get; set; } +} - class EntityWithFieldComponent - { - public ComponentTarget Component; - public IDictionary DynamicComponent; - } +class EntityWithFieldComponent +{ + public ComponentTarget Component; + public IDictionary DynamicComponent; +} - class ComponentTarget - { - } -} \ No newline at end of file +class ComponentTarget +{ +} diff --git a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithFields.cs b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithFields.cs index 07a00006d..4791d2c01 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithFields.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithFields.cs @@ -1,7 +1,6 @@ -namespace FluentNHibernate.Specs.FluentInterface.Fixtures +namespace FluentNHibernate.Specs.FluentInterface.Fixtures; + +class EntityWithFields { - class EntityWithFields - { - public string Name; - } -} \ No newline at end of file + public string Name; +} diff --git a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithProperties.cs b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithProperties.cs index 3fdee6ee6..dda66c51a 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithProperties.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithProperties.cs @@ -1,13 +1,12 @@ -namespace FluentNHibernate.Specs.FluentInterface.Fixtures -{ - class EntityWithProperties - { - public string Name { get; set; } - } +namespace FluentNHibernate.Specs.FluentInterface.Fixtures; - class EntityWithPrivateProperties - { - private string Name { get; set; } - string name; - } +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 1196487d5..59f9e0992 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithReferences.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithReferences.cs @@ -1,10 +1,9 @@ -namespace FluentNHibernate.Specs.FluentInterface.Fixtures +namespace FluentNHibernate.Specs.FluentInterface.Fixtures; + +class EntityWithReferences { - class EntityWithReferences - { - public ReferenceTarget Reference { get; set; } - } + public ReferenceTarget Reference { get; set; } +} - class ReferenceTarget - {} -} \ No newline at end of file +class ReferenceTarget +{} diff --git a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithVersion.cs b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithVersion.cs index 4c0428b06..013d4b90d 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithVersion.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/EntityWithVersion.cs @@ -1,9 +1,8 @@ using System; -namespace FluentNHibernate.Specs.FluentInterface.Fixtures +namespace FluentNHibernate.Specs.FluentInterface.Fixtures; + +class EntityWithVersion { - class EntityWithVersion - { - public TimeSpan VersionNumber { get; set; } - } -} \ No newline at end of file + public TimeSpan VersionNumber { get; set; } +} diff --git a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/IndexTarget.cs b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/IndexTarget.cs index 8f19cfcbf..8ec856e61 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/IndexTarget.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/IndexTarget.cs @@ -1,5 +1,4 @@ -namespace FluentNHibernate.Specs.FluentInterface.Fixtures -{ - class IndexTarget - {} -} \ No newline at end of file +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 6eddc82f1..c3052ab6f 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/Fixtures/SuperTarget.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/Fixtures/SuperTarget.cs @@ -3,12 +3,11 @@ using System.Linq; using System.Text; -namespace FluentNHibernate.Specs.FluentInterface.Fixtures -{ - class SuperTarget - { - } +namespace FluentNHibernate.Specs.FluentInterface.Fixtures; - class ChildTarget : SuperTarget - {} +class SuperTarget +{ } + +class ChildTarget : SuperTarget +{} diff --git a/src/FluentNHibernate.Specs/FluentInterface/ProviderSpec.cs b/src/FluentNHibernate.Specs/FluentInterface/ProviderSpec.cs index ff93bfb93..eaf983ba8 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/ProviderSpec.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/ProviderSpec.cs @@ -3,26 +3,25 @@ using FluentNHibernate.Mapping.Providers; using FluentNHibernate.MappingModel.ClassBased; -namespace FluentNHibernate.Specs.FluentInterface +namespace FluentNHibernate.Specs.FluentInterface; + +public abstract class ProviderSpec { - public abstract class ProviderSpec + public static ClassMapping map_as_class(Action> setup) { - public static ClassMapping map_as_class(Action> setup) - { - var provider = new ClassMap(); + var provider = new ClassMap(); - setup(provider); + setup(provider); - return ((IMappingProvider)provider).GetClassMapping(); - } + return ((IMappingProvider)provider).GetClassMapping(); + } - public static SubclassMapping map_as_subclass(Action> setup) - { - var provider = new SubclassMap(); + public static SubclassMapping map_as_subclass(Action> setup) + { + var provider = new SubclassMap(); - setup(provider); + setup(provider); - return ((IIndeterminateSubclassMappingProvider)provider).GetSubclassMapping(SubclassType.Subclass); - } + return ((IIndeterminateSubclassMappingProvider)provider).GetSubclassMapping(SubclassType.Subclass); } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.Component.cs b/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.Component.cs index e1420f7e3..a5f85310e 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.Component.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.Component.cs @@ -3,95 +3,94 @@ using FluentNHibernate.Specs.FluentInterface.Fixtures; using Machine.Specifications; -namespace FluentNHibernate.Specs.FluentInterface.SubclassMapSpecs +namespace FluentNHibernate.Specs.FluentInterface.SubclassMapSpecs; + +public class when_subclass_map_is_told_to_map_a_component : ProviderSpec { - 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 => {})); + Because of = () => + mapping = map_as_subclass(m => m.Component(x => x.Component, c => {})); - Behaves_like a_component_in_a_classlike; + Behaves_like a_component_in_a_classlike; - protected static SubclassMapping mapping; - } + 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 => { })); +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; + Behaves_like a_component_in_a_classlike; - protected static SubclassMapping mapping; - } + 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 => { })); +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; + Behaves_like a_component_in_a_classlike; - protected static SubclassMapping mapping; - } + 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 => { })); +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; + Behaves_like a_component_in_a_classlike; - protected static SubclassMapping mapping; - } + 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 => { })); +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; + Behaves_like a_component_in_a_classlike; - protected static SubclassMapping mapping; - } + 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 => { })); +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; + Behaves_like a_component_in_a_classlike; - protected static SubclassMapping mapping; - } + 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)); +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; + Behaves_like a_component_in_a_classlike; - protected static SubclassMapping mapping; - } + 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)); +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; + Behaves_like a_component_in_a_classlike; - protected static SubclassMapping mapping; - } + 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"))); +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; + Behaves_like a_component_in_a_classlike; - protected static SubclassMapping mapping; - } -} \ No newline at end of file + 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 388366076..25f2d19da 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.HasMany.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.HasMany.cs @@ -4,78 +4,77 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.FluentInterface.SubclassMapSpecs +namespace FluentNHibernate.Specs.FluentInterface.SubclassMapSpecs; + +public class when_subclass_map_is_told_to_map_a_has_many_bag : ProviderSpec { - 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)); + Because of = () => + mapping = map_as_subclass(m => m.HasMany(x => x.BagOfChildren)); - Behaves_like a_bag_in_a_classlike_mapping; + 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"); + 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; - } + 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)); +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; + Behaves_like a_set_in_a_classlike_mapping; - protected static SubclassMapping 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()); +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; + Behaves_like a_list_with_the_default_index_in_a_classlike_mapping; - protected static SubclassMapping 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(); - })); +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; + Behaves_like a_list_with_a_custom_index_in_a_classlike_mapping; - protected static SubclassMapping 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)); +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; + 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"); + 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; - } + 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"))); +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; + 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"); + 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; - } -} \ No newline at end of file + 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 f1766cd8e..9b6b23c8d 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.HasOne.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.HasOne.cs @@ -2,25 +2,24 @@ using FluentNHibernate.Specs.FluentInterface.Fixtures; using Machine.Specifications; -namespace FluentNHibernate.Specs.FluentInterface.SubclassMapSpecs +namespace FluentNHibernate.Specs.FluentInterface.SubclassMapSpecs; + +public class when_subclass_map_is_told_to_map_a_has_one : ProviderSpec { - 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)); + Because of = () => + mapping = map_as_subclass(m => m.HasOne(x => x.Reference)); - Behaves_like a_has_one_in_a_classlike_mapping; + Behaves_like a_has_one_in_a_classlike_mapping; - protected static SubclassMapping 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"))); +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; + Behaves_like a_has_one_in_a_classlike_mapping; - protected static SubclassMapping mapping; - } -} \ No newline at end of file + 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 1b09ff5bf..6879047b1 100644 --- a/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.Property.cs +++ b/src/FluentNHibernate.Specs/FluentInterface/SubclassMapSpecs/SubclassMapSpecs.Property.cs @@ -3,35 +3,34 @@ using FluentNHibernate.Specs.FluentInterface.Fixtures; using Machine.Specifications; -namespace FluentNHibernate.Specs.FluentInterface.SubclassMapSpecs +namespace FluentNHibernate.Specs.FluentInterface.SubclassMapSpecs; + +public class when_subclass_map_is_told_to_map_a_property : ProviderSpec { - public class when_subclass_map_is_told_to_map_a_property : ProviderSpec - { - Because of = () => - mapping = map_as_subclass(o => o.Map(x => x.Name)); + Because of = () => + mapping = map_as_subclass(o => o.Map(x => x.Name)); - Behaves_like a_property_in_a_classlike_mapping; + Behaves_like a_property_in_a_classlike_mapping; - protected static SubclassMapping 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)); +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; + Behaves_like a_property_in_a_classlike_mapping; - protected static SubclassMapping 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"))); +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; + Behaves_like a_property_in_a_classlike_mapping; - protected static SubclassMapping mapping; - } -} \ No newline at end of file + protected static SubclassMapping mapping; +} diff --git a/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionChildEntity.cs b/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionChildEntity.cs index 4870b3ee5..f4862608e 100644 --- a/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionChildEntity.cs +++ b/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionChildEntity.cs @@ -1,5 +1,4 @@ -namespace FluentNHibernate.Specs.PersistenceModel.Fixtures -{ - class UnionChildEntity : UnionEntity - {} -} \ No newline at end of file +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 a16c9537b..7536c4dfd 100644 --- a/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionChildEntityMap.cs +++ b/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionChildEntityMap.cs @@ -1,7 +1,6 @@ using FluentNHibernate.Mapping; -namespace FluentNHibernate.Specs.PersistenceModel.Fixtures -{ - class UnionChildEntityMap : SubclassMap - {} -} \ No newline at end of file +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 49239dcce..73e5ce81c 100644 --- a/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionEntity.cs +++ b/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionEntity.cs @@ -1,7 +1,6 @@ -namespace FluentNHibernate.Specs.PersistenceModel.Fixtures +namespace FluentNHibernate.Specs.PersistenceModel.Fixtures; + +class UnionEntity { - class UnionEntity - { - public int Id { get; set; } - } -} \ No newline at end of file + public int Id { get; set; } +} diff --git a/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionEntityMap.cs b/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionEntityMap.cs index f64593efd..3c32a8ada 100644 --- a/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionEntityMap.cs +++ b/src/FluentNHibernate.Specs/PersistenceModel/Fixtures/UnionEntityMap.cs @@ -1,13 +1,12 @@ using FluentNHibernate.Mapping; -namespace FluentNHibernate.Specs.PersistenceModel.Fixtures +namespace FluentNHibernate.Specs.PersistenceModel.Fixtures; + +class UnionEntityMap : ClassMap { - class UnionEntityMap : ClassMap + public UnionEntityMap() { - public UnionEntityMap() - { - Id(x => x.Id); - UseUnionSubclassForInheritanceMapping(); - } + Id(x => x.Id); + UseUnionSubclassForInheritanceMapping(); } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/PersistenceModel/PersistenceModelSpecs.AddingProviders.cs b/src/FluentNHibernate.Specs/PersistenceModel/PersistenceModelSpecs.AddingProviders.cs index f3ba5d731..763fcf9f6 100644 --- a/src/FluentNHibernate.Specs/PersistenceModel/PersistenceModelSpecs.AddingProviders.cs +++ b/src/FluentNHibernate.Specs/PersistenceModel/PersistenceModelSpecs.AddingProviders.cs @@ -3,61 +3,60 @@ using FluentNHibernate.Specs.Automapping.Fixtures; using Machine.Specifications; -namespace FluentNHibernate.Specs.PersistenceModel +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 { - 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 { } - } -} \ No newline at end of file + 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 157d7d611..7623725aa 100644 --- a/src/FluentNHibernate.Specs/PersistenceModel/PersistenceModelSpecs.Validation.cs +++ b/src/FluentNHibernate.Specs/PersistenceModel/PersistenceModelSpecs.Validation.cs @@ -5,127 +5,126 @@ using Machine.Specifications; using FluentAssertions; -namespace FluentNHibernate.Specs.PersistenceModel +namespace FluentNHibernate.Specs.PersistenceModel; + +public class when_the_persistence_model_is_told_to_build_the_mappings_with_a_valid_class_mapping : PersistenceModelValidationSpec { - public class when_the_persistence_model_is_told_to_build_the_mappings_with_a_valid_class_mapping : PersistenceModelValidationSpec + Establish context = () => { - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); + model = new FluentNHibernate.PersistenceModel(); - var class_map = new ClassMap(); - class_map.Id(x => x.Id); + var class_map = new ClassMap(); + class_map.Id(x => x.Id); - model.Add(class_map); - }; + model.Add(class_map); + }; - Because of = () => - exception = Catch.Exception(() => model.BuildMappings()); + Because of = () => + exception = Catch.Exception(() => model.BuildMappings()); - It shouldnt_throw_any_validation_exceptions = () => - exception.Should().BeNull(); - } + 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 +public class when_the_persistence_model_is_told_to_build_the_mappings_with_a_class_mapping_that_doesnt_have_an_id : PersistenceModelValidationSpec +{ + Establish context = () => { - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Add(new ClassMap()); - }; + model = new FluentNHibernate.PersistenceModel(); + model.Add(new ClassMap()); + }; - Because of = () => - exception = Catch.Exception(() => model.BuildMappings()); + Because of = () => + exception = Catch.Exception(() => model.BuildMappings()); - It should_throw_a_validation_exception = () => - { - exception.Should().NotBeNull(); - exception.Should().BeOfType(); - }; + 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_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_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)."); - } + 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; - 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 + protected class Target { - 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 int Id { get; set; } } - 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 + protected class Left { - 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 int Id { get; set; } + public IList Rights { get; set; } } - public abstract class PersistenceModelValidationSpec + protected class Right { - 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; } - } + public int Id { get; set; } + public IList Lefts { get; set; } } -} \ No newline at end of file +} diff --git a/src/FluentNHibernate.Specs/PersistenceModel/SubclassSpecs.cs b/src/FluentNHibernate.Specs/PersistenceModel/SubclassSpecs.cs index 04763d034..432e2644b 100644 --- a/src/FluentNHibernate.Specs/PersistenceModel/SubclassSpecs.cs +++ b/src/FluentNHibernate.Specs/PersistenceModel/SubclassSpecs.cs @@ -10,98 +10,97 @@ using NHibernate.Tool.hbm2ddl; using FluentAssertions; -namespace FluentNHibernate.Specs.PersistenceModel +namespace FluentNHibernate.Specs.PersistenceModel; + +public class when_subclass_map_is_combined_with_a_class_map_flagged_as_union { - public class when_subclass_map_is_combined_with_a_class_map_flagged_as_union + Establish context = () => { - Establish context = () => - { - model = new FluentNHibernate.PersistenceModel(); - model.Add(new UnionEntityMap()); - model.Add(new UnionChildEntityMap()); - }; + model = new FluentNHibernate.PersistenceModel(); + model.Add(new UnionEntityMap()); + model.Add(new UnionChildEntityMap()); + }; - Because of = () => - mapping = model.BuildMappingFor(); + Because of = () => + mapping = model.BuildMappingFor(); - It should_map_the_subclass_as_a_union_subclass = () => - mapping.Subclasses.Single().SubclassType.Should().Be(SubclassType.UnionSubclass); + It should_map_the_subclass_as_a_union_subclass = () => + mapping.Subclasses.Single().SubclassType.Should().Be(SubclassType.UnionSubclass); - static FluentNHibernate.PersistenceModel model; - static ClassMapping mapping; - } + static FluentNHibernate.PersistenceModel model; + static ClassMapping mapping; +} - public class when_subclass_map_has_a_has_many_to_another_entity +public class when_subclass_map_has_a_has_many_to_another_entity +{ + Establish context = () => { - 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; } - } + 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