diff --git a/.editorconfig b/.editorconfig
index 3481533bd..8a0c02ebd 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -2,10 +2,6 @@ root = true
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://EditorConfig.org
-
-[*]
-end_of_line = crlf
-
[*.ps1]
indent_style = space
indent_size = 2
diff --git a/.gitattributes b/.gitattributes
index 48adf82e5..1612d7799 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,2 +1,28 @@
-[core]
-autocrlf=false
+# Set the default behavior, in case people don't have core.autocrlf set.
+* text=auto
+
+# Explicitly declare text files you want to always be normalized and converted
+# to native line endings on checkout.
+*.cs text diff=csharp
+*.xaml text
+*.txt text
+*.tt text
+*.ps1 text
+*.cmd text
+*.msbuild text
+*.md text
+
+*.sln text eol=crlf
+*.csproj text eol=crlf
+*.vbproj text eol=crlf
+*.fsproj text eol=crlf
+*.dbproj text eol=crlf
+
+# Resharper DotSettings files are in Unix format
+*.DotSettings text eol=lf
+
+# Binary files
+*.png binary
+*.jpg binary
+*.dll binary
+*.exe binary
\ No newline at end of file
diff --git a/CODEOFCONDUCT.md b/CODEOFCONDUCT.md
index df7338359..e297904f0 100644
--- a/CODEOFCONDUCT.md
+++ b/CODEOFCONDUCT.md
@@ -1,24 +1,24 @@
-# Contributor Code of Conduct
-
-As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
-
-We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
-
-Examples of unacceptable behavior by participants include:
-
-- The use of sexualized language or imagery
-- Personal attacks
-- Trolling or insulting/derogatory comments
-- Public or private harassment
-- Publishing other's private information, such as physical or electronic addresses, without explicit permission
-- Other unethical or unprofessional conduct
-
-Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
-
-By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
-
-This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
-
-Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting a project maintainer. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Maintainers are obligated to maintain confidentiality with regard to the reporter of an incident.
-
+# Contributor Code of Conduct
+
+As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
+
+We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
+
+Examples of unacceptable behavior by participants include:
+
+- The use of sexualized language or imagery
+- Personal attacks
+- Trolling or insulting/derogatory comments
+- Public or private harassment
+- Publishing other's private information, such as physical or electronic addresses, without explicit permission
+- Other unethical or unprofessional conduct
+
+Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
+
+By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
+
+This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting a project maintainer. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Maintainers are obligated to maintain confidentiality with regard to the reporter of an incident.
+
This Code of Conduct is adapted from the Contributor Covenant, version 1.3.0, available from http://contributor-covenant.org/version/1/3/0/
\ No newline at end of file
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index b1508a0cb..2cd5d46fc 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,14 +1,5 @@
-# Contribution Guidelines
-
-The wiki has a page on contributing to FNH:
-
-https://github.com/nhibernate/fluent-nhibernate/wiki/Contributing
-
-## Important
-If you've just pulled the FNH code into a local git repository for the first time, its really important that you set the core.autocrlf setting to false to avoid running into whitespace/line ending issues. Do this using the following command:
-
-```
-git config core.autocrlf false
-```
-
-
+# Contribution Guidelines
+
+The wiki has a page on contributing to FNH:
+
+https://github.com/nhibernate/fluent-nhibernate/wiki/Contributing
diff --git a/README.md b/README.md
index a58b0281a..3ac96baf9 100644
--- a/README.md
+++ b/README.md
@@ -1,41 +1,41 @@
-
-
-[](https://ci.appveyor.com/project/nhibernate/fluent-nhibernate/branch/main)
-[](https://www.nuget.org/packages/FluentNHibernate)
-
-## What is FluentNHibernate?
-Fluent, XML-less, compile safe, automated, convention-based mappings for NHibernate. *Get your fluent on.*
-
-## Where can I get it?
-
-Install using the [FluentNHibernate NuGet package](https://www.nuget.org/packages/FluentNHibernate):
-
-```
-dotnet add package FluentNHibernate
-```
-
-## How do I use it?
-
-* Read the [introduction](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Getting-started).
-* Get latest version from NuGet
- - [.NETCore2.0, NETStandard2.0 or NET 4.6.1 with NHibernate 5.x](https://www.nuget.org/packages/FluentNHibernate)
- - [.NET 4.0 with NHibernate 4.x](https://www.nuget.org/packages/FluentNHibernate/2.0.3)
- - [.NET 3.5 with NHibernate 3 if you like it vintage](https://www.nuget.org/packages/FluentNHibernate.Net35)
-
-* Create your [first project](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Getting-started#wiki-yourfirstproject).
-
-## Further reading
-
-Once you've followed the above, you can compare our [auto mapping](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Auto-mapping) to our [fluent interface](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Fluent-mapping) to see which suits your application, read through our [API documentation](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Fluent-configuration), or just see what's available for reading in our [wiki](https://github.com/FluentNHibernate/fluent-nhibernate/wiki).
-
-Contributors
----------------------------------------------
-
-Fluent NHibernate wouldn't be possible without the time and effort of its contributors. The team comprises of [James Gregory](http://jagregory.com), [Paul Batum](http://www.paulbatum.com), Andrew Stewart, [Hudson Akridge](https://github.com/HudsonAkridge), [Gleb Chermennov](https://github.com/chester89) and [Jorge RodrÃguez Galán](https://github.com/jrgcubano).
-
-**Our valued committers are:** Aaron Jensen, Alexander Gross, Andrew Stewart, Barry Dahlberg, Bobby Johnson, Brian Donahue, Cameron Harris, Chad Myers, Chris Chilvers, Craig Neuwirt, Dan Malcolm, Daniel Mirapalheta, David Archer, David Longnecker, David R. Longnecker, Derick Bailey, Erik Ojebo, Firo, Hudson Akridge, Ivan Zlatev, James Freiwirth, James Gregory, James Kovacs, Jeremy Skinner, Lee Henson, Louis DeJardin, Patric Forsgard, Paul Batum, Roelof Blom, Stuart Childs, Tom Janssens, Tuna Toksoz, U-BSOD\pruiz, di97mni, dschilling, felixg, jeremydmiller, kevm, leebrandt, maxild, robsosno, [Jorge RodrÃguez Galán](https://github.com/jrgcubano) and many more.
-
-Thanks goes to [Jeremy Miller](http://codebetter.com/blogs/jeremy.miller) for the original idea and implementation.
-
-Fluent NHibernate is © 2008-2018 [James Gregory](http://jagregory.com) and contributors under the [BSD license](https://github.com/nhibernate/fluent-nhibernate/blob/main/LICENSE)
-
+
+
+[](https://ci.appveyor.com/project/nhibernate/fluent-nhibernate/branch/main)
+[](https://www.nuget.org/packages/FluentNHibernate)
+
+## What is FluentNHibernate?
+Fluent, XML-less, compile safe, automated, convention-based mappings for NHibernate. *Get your fluent on.*
+
+## Where can I get it?
+
+Install using the [FluentNHibernate NuGet package](https://www.nuget.org/packages/FluentNHibernate):
+
+```
+dotnet add package FluentNHibernate
+```
+
+## How do I use it?
+
+* Read the [introduction](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Getting-started).
+* Get latest version from NuGet
+ - [.NETCore2.0, NETStandard2.0 or NET 4.6.1 with NHibernate 5.x](https://www.nuget.org/packages/FluentNHibernate)
+ - [.NET 4.0 with NHibernate 4.x](https://www.nuget.org/packages/FluentNHibernate/2.0.3)
+ - [.NET 3.5 with NHibernate 3 if you like it vintage](https://www.nuget.org/packages/FluentNHibernate.Net35)
+
+* Create your [first project](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Getting-started#wiki-yourfirstproject).
+
+## Further reading
+
+Once you've followed the above, you can compare our [auto mapping](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Auto-mapping) to our [fluent interface](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Fluent-mapping) to see which suits your application, read through our [API documentation](https://github.com/FluentNHibernate/fluent-nhibernate/wiki/Fluent-configuration), or just see what's available for reading in our [wiki](https://github.com/FluentNHibernate/fluent-nhibernate/wiki).
+
+Contributors
+---------------------------------------------
+
+Fluent NHibernate wouldn't be possible without the time and effort of its contributors. The team comprises of [James Gregory](http://jagregory.com), [Paul Batum](http://www.paulbatum.com), Andrew Stewart, [Hudson Akridge](https://github.com/HudsonAkridge), [Gleb Chermennov](https://github.com/chester89) and [Jorge RodrÃguez Galán](https://github.com/jrgcubano).
+
+**Our valued committers are:** Aaron Jensen, Alexander Gross, Andrew Stewart, Barry Dahlberg, Bobby Johnson, Brian Donahue, Cameron Harris, Chad Myers, Chris Chilvers, Craig Neuwirt, Dan Malcolm, Daniel Mirapalheta, David Archer, David Longnecker, David R. Longnecker, Derick Bailey, Erik Ojebo, Firo, Hudson Akridge, Ivan Zlatev, James Freiwirth, James Gregory, James Kovacs, Jeremy Skinner, Lee Henson, Louis DeJardin, Patric Forsgard, Paul Batum, Roelof Blom, Stuart Childs, Tom Janssens, Tuna Toksoz, U-BSOD\pruiz, di97mni, dschilling, felixg, jeremydmiller, kevm, leebrandt, maxild, robsosno, [Jorge RodrÃguez Galán](https://github.com/jrgcubano) and many more.
+
+Thanks goes to [Jeremy Miller](http://codebetter.com/blogs/jeremy.miller) for the original idea and implementation.
+
+Fluent NHibernate is © 2008-2018 [James Gregory](http://jagregory.com) and contributors under the [BSD license](https://github.com/nhibernate/fluent-nhibernate/blob/main/LICENSE)
+
diff --git a/src/Examples.FirstAutomappedProject/CascadeConvention.cs b/src/Examples.FirstAutomappedProject/CascadeConvention.cs
index 9dc6bf5af..caa9cd08d 100644
--- a/src/Examples.FirstAutomappedProject/CascadeConvention.cs
+++ b/src/Examples.FirstAutomappedProject/CascadeConvention.cs
@@ -1,27 +1,27 @@
-using FluentNHibernate.Conventions;
-using FluentNHibernate.Conventions.Instances;
-
-namespace Examples.FirstAutomappedProject;
-
-///
-/// This is a convention that will be applied to all entities in your application. What this particular
-/// convention does is to specify that many-to-one, one-to-many, and many-to-many relationships will all
-/// have their Cascade option set to All.
-///
-class CascadeConvention : IReferenceConvention, IHasManyConvention, IHasManyToManyConvention
-{
- public void Apply(IManyToOneInstance instance)
- {
- instance.Cascade.All();
- }
-
- public void Apply(IOneToManyCollectionInstance instance)
- {
- instance.Cascade.All();
- }
-
- public void Apply(IManyToManyCollectionInstance instance)
- {
- instance.Cascade.All();
- }
+using FluentNHibernate.Conventions;
+using FluentNHibernate.Conventions.Instances;
+
+namespace Examples.FirstAutomappedProject;
+
+///
+/// This is a convention that will be applied to all entities in your application. What this particular
+/// convention does is to specify that many-to-one, one-to-many, and many-to-many relationships will all
+/// have their Cascade option set to All.
+///
+class CascadeConvention : IReferenceConvention, IHasManyConvention, IHasManyToManyConvention
+{
+ public void Apply(IManyToOneInstance instance)
+ {
+ instance.Cascade.All();
+ }
+
+ public void Apply(IOneToManyCollectionInstance instance)
+ {
+ instance.Cascade.All();
+ }
+
+ public void Apply(IManyToManyCollectionInstance instance)
+ {
+ instance.Cascade.All();
+ }
}
diff --git a/src/Examples.FirstAutomappedProject/Entities/Employee.cs b/src/Examples.FirstAutomappedProject/Entities/Employee.cs
index cfda3a8b3..2827dbe66 100644
--- a/src/Examples.FirstAutomappedProject/Entities/Employee.cs
+++ b/src/Examples.FirstAutomappedProject/Entities/Employee.cs
@@ -1,9 +1,9 @@
-namespace Examples.FirstAutomappedProject.Entities;
-
-public class Employee
-{
- public virtual int Id { get; protected set; }
- public virtual string FirstName { get; set; }
- public virtual string LastName { get; set; }
- public virtual Store Store { get; set; }
+namespace Examples.FirstAutomappedProject.Entities;
+
+public class Employee
+{
+ public virtual int Id { get; protected set; }
+ public virtual string FirstName { get; set; }
+ public virtual string LastName { get; set; }
+ public virtual Store Store { get; set; }
}
diff --git a/src/Examples.FirstAutomappedProject/Entities/Location.cs b/src/Examples.FirstAutomappedProject/Entities/Location.cs
index 3be27c222..7ac1f0338 100644
--- a/src/Examples.FirstAutomappedProject/Entities/Location.cs
+++ b/src/Examples.FirstAutomappedProject/Entities/Location.cs
@@ -1,7 +1,7 @@
-namespace Examples.FirstAutomappedProject.Entities;
-
-public class Location
-{
- public virtual int Aisle { get; set; }
- public virtual int Shelf { get; set; }
+namespace Examples.FirstAutomappedProject.Entities;
+
+public class Location
+{
+ public virtual int Aisle { get; set; }
+ public virtual int Shelf { get; set; }
}
diff --git a/src/Examples.FirstAutomappedProject/Entities/Product.cs b/src/Examples.FirstAutomappedProject/Entities/Product.cs
index 6ca0bf243..b340ad6c6 100644
--- a/src/Examples.FirstAutomappedProject/Entities/Product.cs
+++ b/src/Examples.FirstAutomappedProject/Entities/Product.cs
@@ -1,17 +1,17 @@
-using System.Collections.Generic;
-
-namespace Examples.FirstAutomappedProject.Entities;
-
-public class Product
-{
- public virtual int Id { get; protected set; }
- public virtual string Name { get; set; }
- public virtual double Price { get; set; }
- public virtual Location Location { get; set; }
- public virtual IList StoresStockedIn { get; set; }
-
- public Product()
- {
- StoresStockedIn = new List();
- }
+using System.Collections.Generic;
+
+namespace Examples.FirstAutomappedProject.Entities;
+
+public class Product
+{
+ public virtual int Id { get; protected set; }
+ public virtual string Name { get; set; }
+ public virtual double Price { get; set; }
+ public virtual Location Location { get; set; }
+ public virtual IList StoresStockedIn { get; set; }
+
+ public Product()
+ {
+ StoresStockedIn = new List();
+ }
}
diff --git a/src/Examples.FirstAutomappedProject/Entities/Store.cs b/src/Examples.FirstAutomappedProject/Entities/Store.cs
index 3e6884a09..dce1720fb 100644
--- a/src/Examples.FirstAutomappedProject/Entities/Store.cs
+++ b/src/Examples.FirstAutomappedProject/Entities/Store.cs
@@ -1,29 +1,29 @@
-using System.Collections.Generic;
-
-namespace Examples.FirstAutomappedProject.Entities;
-
-public class Store
-{
- public virtual int Id { get; protected set; }
- public virtual string Name { get; set; }
- public virtual IList Products { get; set; }
- public virtual IList Staff { get; set; }
-
- public Store()
- {
- Products = new List();
- Staff = new List();
- }
-
- public virtual void AddProduct(Product product)
- {
- product.StoresStockedIn.Add(this);
- Products.Add(product);
- }
-
- public virtual void AddEmployee(Employee employee)
- {
- employee.Store = this;
- Staff.Add(employee);
- }
+using System.Collections.Generic;
+
+namespace Examples.FirstAutomappedProject.Entities;
+
+public class Store
+{
+ public virtual int Id { get; protected set; }
+ public virtual string Name { get; set; }
+ public virtual IList Products { get; set; }
+ public virtual IList Staff { get; set; }
+
+ public Store()
+ {
+ Products = new List();
+ Staff = new List();
+ }
+
+ public virtual void AddProduct(Product product)
+ {
+ product.StoresStockedIn.Add(this);
+ Products.Add(product);
+ }
+
+ public virtual void AddEmployee(Employee employee)
+ {
+ employee.Store = this;
+ Staff.Add(employee);
+ }
}
diff --git a/src/Examples.FirstAutomappedProject/ExampleAutomappingConfiguration.cs b/src/Examples.FirstAutomappedProject/ExampleAutomappingConfiguration.cs
index e3bb64278..65e5f23a8 100644
--- a/src/Examples.FirstAutomappedProject/ExampleAutomappingConfiguration.cs
+++ b/src/Examples.FirstAutomappedProject/ExampleAutomappingConfiguration.cs
@@ -1,28 +1,28 @@
-using System;
-using Examples.FirstAutomappedProject.Entities;
-using FluentNHibernate.Automapping;
-
-namespace Examples.FirstAutomappedProject;
-
-///
-/// This is an example automapping configuration. You should create your own that either
-/// implements IAutomappingConfiguration directly, or inherits from DefaultAutomappingConfiguration.
-/// Overriding methods in this class will alter how the automapper behaves.
-///
-class ExampleAutomappingConfiguration : DefaultAutomappingConfiguration
-{
- public override bool ShouldMap(Type type)
- {
- // specify the criteria that types must meet in order to be mapped
- // any type for which this method returns false will not be mapped.
- return type.Namespace == "Examples.FirstAutomappedProject.Entities";
- }
-
- public override bool IsComponent(Type type)
- {
- // override this method to specify which types should be treated as components
- // if you have a large list of types, you should consider maintaining a list of them
- // somewhere or using some form of conventional and/or attribute design
- return type == typeof(Location);
- }
+using System;
+using Examples.FirstAutomappedProject.Entities;
+using FluentNHibernate.Automapping;
+
+namespace Examples.FirstAutomappedProject;
+
+///
+/// This is an example automapping configuration. You should create your own that either
+/// implements IAutomappingConfiguration directly, or inherits from DefaultAutomappingConfiguration.
+/// Overriding methods in this class will alter how the automapper behaves.
+///
+class ExampleAutomappingConfiguration : DefaultAutomappingConfiguration
+{
+ public override bool ShouldMap(Type type)
+ {
+ // specify the criteria that types must meet in order to be mapped
+ // any type for which this method returns false will not be mapped.
+ return type.Namespace == "Examples.FirstAutomappedProject.Entities";
+ }
+
+ public override bool IsComponent(Type type)
+ {
+ // override this method to specify which types should be treated as components
+ // if you have a large list of types, you should consider maintaining a list of them
+ // somewhere or using some form of conventional and/or attribute design
+ return type == typeof(Location);
+ }
}
diff --git a/src/Examples.FirstAutomappedProject/Examples.FirstAutomappedProject.csproj b/src/Examples.FirstAutomappedProject/Examples.FirstAutomappedProject.csproj
index 6422bfdf9..c2117a46d 100644
--- a/src/Examples.FirstAutomappedProject/Examples.FirstAutomappedProject.csproj
+++ b/src/Examples.FirstAutomappedProject/Examples.FirstAutomappedProject.csproj
@@ -1,25 +1,25 @@
-
-
-
- net48
- Exe
- AnyCpu
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+ net48
+ Exe
+ AnyCpu
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Examples.FirstAutomappedProject/Program.cs b/src/Examples.FirstAutomappedProject/Program.cs
index dd5d56833..91916ddba 100644
--- a/src/Examples.FirstAutomappedProject/Program.cs
+++ b/src/Examples.FirstAutomappedProject/Program.cs
@@ -1,171 +1,171 @@
-using System;
-using System.IO;
-using Examples.FirstAutomappedProject.Entities;
-using FluentNHibernate.Automapping;
-using FluentNHibernate.Cfg;
-using FluentNHibernate.Cfg.Db;
-using NHibernate;
-using NHibernate.Cfg;
-using NHibernate.Tool.hbm2ddl;
-
-namespace Examples.FirstAutomappedProject;
-
-///
-/// Example automapped project.
-///
-/// Points of interest:
-/// Program.CreateSessionFactory()
-/// Program.CreateAutomappings()
-///
-/// ExampleAutomappingConfiguration
-/// CascadeConvention
-///
-class Program
-{
- private const string DbFile = "firstProgram.db";
-
- static void Main()
- {
- // create our NHibernate session factory
- var sessionFactory = CreateSessionFactory();
-
- using (var session = sessionFactory.OpenSession())
- {
- // populate the database
- using (var transaction = session.BeginTransaction())
- {
- // create a couple of Stores each with some Products and Employees
- var barginBasin = new Store { Name = "Bargin Basin" };
- var superMart = new Store { Name = "SuperMart" };
-
- var potatoes = new Product { Name = "Potatoes", Price = 3.60 };
- var fish = new Product { Name = "Fish", Price = 4.49 };
- var milk = new Product { Name = "Milk", Price = 0.79 };
- var bread = new Product { Name = "Bread", Price = 1.29 };
- var cheese = new Product { Name = "Cheese", Price = 2.10 };
- var waffles = new Product { Name = "Waffles", Price = 2.41 };
-
- var daisy = new Employee { FirstName = "Daisy", LastName = "Harrison" };
- var jack = new Employee { FirstName = "Jack", LastName = "Torrance" };
- var sue = new Employee { FirstName = "Sue", LastName = "Walkters" };
- var bill = new Employee { FirstName = "Bill", LastName = "Taft" };
- var joan = new Employee { FirstName = "Joan", LastName = "Pope" };
-
- // add products to the stores, there's some crossover in the products in each
- // store, because the store-product relationship is many-to-many
- AddProductsToStore(barginBasin, potatoes, fish, milk, bread, cheese);
- AddProductsToStore(superMart, bread, cheese, waffles);
-
- // add employees to the stores, this relationship is a one-to-many, so one
- // employee can only work at one store at a time
- AddEmployeesToStore(barginBasin, daisy, jack, sue);
- AddEmployeesToStore(superMart, bill, joan);
-
- // save both stores, this saves everything else via cascading
- session.SaveOrUpdate(barginBasin);
- session.SaveOrUpdate(superMart);
-
- transaction.Commit();
- }
- }
-
- using (var session = sessionFactory.OpenSession())
- {
- // retreive all stores and display them
- using (session.BeginTransaction())
- {
- var stores = session.CreateCriteria(typeof(Store))
- .List();
-
- foreach (var store in stores)
- {
- WriteStorePretty(store);
- }
- }
- }
-
- Console.ReadKey();
- }
-
- static AutoPersistenceModel CreateAutomappings()
- {
- // This is the actual automapping - use AutoMap to start automapping,
- // then pick one of the static methods to specify what to map (in this case
- // all the classes in the assembly that contains Employee), and then either
- // use the Setup and Where methods to restrict that behaviour, or (preferably)
- // supply a configuration instance of your definition to control the automapper.
- return AutoMap.AssemblyOf(new ExampleAutomappingConfiguration())
- .Conventions.Add();
- }
-
- ///
- /// Configure NHibernate. This method returns an ISessionFactory instance that is
- /// populated with mappings created by Fluent NHibernate.
- ///
- /// Line 1: Begin configuration
- /// 2+3: Configure the database being used (SQLite file db)
- /// 4+5: Specify what mappings are going to be used (Automappings from the CreateAutomappings method)
- /// 6: Expose the underlying configuration instance to the BuildSchema method,
- /// this creates the database.
- /// 7: Finally, build the session factory.
- ///
- ///
- private static ISessionFactory CreateSessionFactory()
- {
- return Fluently.Configure()
- .Database(SQLiteConfiguration.Standard
- .UsingFile(DbFile))
- .Mappings(m =>
- m.AutoMappings.Add(CreateAutomappings))
- .ExposeConfiguration(BuildSchema)
- .BuildSessionFactory();
- }
-
- private static void BuildSchema(Configuration config)
- {
- // delete the existing db on each run
- if (File.Exists(DbFile))
- File.Delete(DbFile);
-
- // this NHibernate tool takes a configuration (with mapping info in)
- // and exports a database schema from it
- new SchemaExport(config)
- .Create(false, true);
- }
-
- private static void WriteStorePretty(Store store)
- {
- Console.WriteLine(store.Name);
- Console.WriteLine(" Products:");
-
- foreach (var product in store.Products)
- {
- Console.WriteLine(" " + product.Name);
- }
-
- Console.WriteLine(" Staff:");
-
- foreach (var employee in store.Staff)
- {
- Console.WriteLine(" " + employee.FirstName + " " + employee.LastName);
- }
-
- Console.WriteLine();
- }
-
- public static void AddProductsToStore(Store store, params Product[] products)
- {
- foreach (var product in products)
- {
- store.AddProduct(product);
- }
- }
-
- public static void AddEmployeesToStore(Store store, params Employee[] employees)
- {
- foreach (var employee in employees)
- {
- store.AddEmployee(employee);
- }
- }
+using System;
+using System.IO;
+using Examples.FirstAutomappedProject.Entities;
+using FluentNHibernate.Automapping;
+using FluentNHibernate.Cfg;
+using FluentNHibernate.Cfg.Db;
+using NHibernate;
+using NHibernate.Cfg;
+using NHibernate.Tool.hbm2ddl;
+
+namespace Examples.FirstAutomappedProject;
+
+///
+/// Example automapped project.
+///
+/// Points of interest:
+/// Program.CreateSessionFactory()
+/// Program.CreateAutomappings()
+///
+/// ExampleAutomappingConfiguration
+/// CascadeConvention
+///
+class Program
+{
+ private const string DbFile = "firstProgram.db";
+
+ static void Main()
+ {
+ // create our NHibernate session factory
+ var sessionFactory = CreateSessionFactory();
+
+ using (var session = sessionFactory.OpenSession())
+ {
+ // populate the database
+ using (var transaction = session.BeginTransaction())
+ {
+ // create a couple of Stores each with some Products and Employees
+ var barginBasin = new Store { Name = "Bargin Basin" };
+ var superMart = new Store { Name = "SuperMart" };
+
+ var potatoes = new Product { Name = "Potatoes", Price = 3.60 };
+ var fish = new Product { Name = "Fish", Price = 4.49 };
+ var milk = new Product { Name = "Milk", Price = 0.79 };
+ var bread = new Product { Name = "Bread", Price = 1.29 };
+ var cheese = new Product { Name = "Cheese", Price = 2.10 };
+ var waffles = new Product { Name = "Waffles", Price = 2.41 };
+
+ var daisy = new Employee { FirstName = "Daisy", LastName = "Harrison" };
+ var jack = new Employee { FirstName = "Jack", LastName = "Torrance" };
+ var sue = new Employee { FirstName = "Sue", LastName = "Walkters" };
+ var bill = new Employee { FirstName = "Bill", LastName = "Taft" };
+ var joan = new Employee { FirstName = "Joan", LastName = "Pope" };
+
+ // add products to the stores, there's some crossover in the products in each
+ // store, because the store-product relationship is many-to-many
+ AddProductsToStore(barginBasin, potatoes, fish, milk, bread, cheese);
+ AddProductsToStore(superMart, bread, cheese, waffles);
+
+ // add employees to the stores, this relationship is a one-to-many, so one
+ // employee can only work at one store at a time
+ AddEmployeesToStore(barginBasin, daisy, jack, sue);
+ AddEmployeesToStore(superMart, bill, joan);
+
+ // save both stores, this saves everything else via cascading
+ session.SaveOrUpdate(barginBasin);
+ session.SaveOrUpdate(superMart);
+
+ transaction.Commit();
+ }
+ }
+
+ using (var session = sessionFactory.OpenSession())
+ {
+ // retreive all stores and display them
+ using (session.BeginTransaction())
+ {
+ var stores = session.CreateCriteria(typeof(Store))
+ .List();
+
+ foreach (var store in stores)
+ {
+ WriteStorePretty(store);
+ }
+ }
+ }
+
+ Console.ReadKey();
+ }
+
+ static AutoPersistenceModel CreateAutomappings()
+ {
+ // This is the actual automapping - use AutoMap to start automapping,
+ // then pick one of the static methods to specify what to map (in this case
+ // all the classes in the assembly that contains Employee), and then either
+ // use the Setup and Where methods to restrict that behaviour, or (preferably)
+ // supply a configuration instance of your definition to control the automapper.
+ return AutoMap.AssemblyOf(new ExampleAutomappingConfiguration())
+ .Conventions.Add();
+ }
+
+ ///
+ /// Configure NHibernate. This method returns an ISessionFactory instance that is
+ /// populated with mappings created by Fluent NHibernate.
+ ///
+ /// Line 1: Begin configuration
+ /// 2+3: Configure the database being used (SQLite file db)
+ /// 4+5: Specify what mappings are going to be used (Automappings from the CreateAutomappings method)
+ /// 6: Expose the underlying configuration instance to the BuildSchema method,
+ /// this creates the database.
+ /// 7: Finally, build the session factory.
+ ///
+ ///
+ private static ISessionFactory CreateSessionFactory()
+ {
+ return Fluently.Configure()
+ .Database(SQLiteConfiguration.Standard
+ .UsingFile(DbFile))
+ .Mappings(m =>
+ m.AutoMappings.Add(CreateAutomappings))
+ .ExposeConfiguration(BuildSchema)
+ .BuildSessionFactory();
+ }
+
+ private static void BuildSchema(Configuration config)
+ {
+ // delete the existing db on each run
+ if (File.Exists(DbFile))
+ File.Delete(DbFile);
+
+ // this NHibernate tool takes a configuration (with mapping info in)
+ // and exports a database schema from it
+ new SchemaExport(config)
+ .Create(false, true);
+ }
+
+ private static void WriteStorePretty(Store store)
+ {
+ Console.WriteLine(store.Name);
+ Console.WriteLine(" Products:");
+
+ foreach (var product in store.Products)
+ {
+ Console.WriteLine(" " + product.Name);
+ }
+
+ Console.WriteLine(" Staff:");
+
+ foreach (var employee in store.Staff)
+ {
+ Console.WriteLine(" " + employee.FirstName + " " + employee.LastName);
+ }
+
+ Console.WriteLine();
+ }
+
+ public static void AddProductsToStore(Store store, params Product[] products)
+ {
+ foreach (var product in products)
+ {
+ store.AddProduct(product);
+ }
+ }
+
+ public static void AddEmployeesToStore(Store store, params Employee[] employees)
+ {
+ foreach (var employee in employees)
+ {
+ store.AddEmployee(employee);
+ }
+ }
}
diff --git a/src/Examples.FirstAutomappedProject/Properties/AssemblyInfo.cs b/src/Examples.FirstAutomappedProject/Properties/AssemblyInfo.cs
index 31b149844..a260a63e9 100644
--- a/src/Examples.FirstAutomappedProject/Properties/AssemblyInfo.cs
+++ b/src/Examples.FirstAutomappedProject/Properties/AssemblyInfo.cs
@@ -1,5 +1,5 @@
-using System;
-using System.Runtime.InteropServices;
-
-[assembly: ComVisible(false)]
+using System;
+using System.Runtime.InteropServices;
+
+[assembly: ComVisible(false)]
[assembly: CLSCompliant(true)]
diff --git a/src/Examples.FirstProject/Entities/Employee.cs b/src/Examples.FirstProject/Entities/Employee.cs
index 6f20f130d..c86f03e23 100644
--- a/src/Examples.FirstProject/Entities/Employee.cs
+++ b/src/Examples.FirstProject/Entities/Employee.cs
@@ -1,11 +1,11 @@
-using Examples.FirstProject.Entities;
-
-namespace Examples.FirstProject.Entities;
-
-public class Employee
-{
- public virtual int Id { get; protected set; }
- public virtual string FirstName { get; set; }
- public virtual string LastName { get; set; }
- public virtual Store Store { get; set; }
+using Examples.FirstProject.Entities;
+
+namespace Examples.FirstProject.Entities;
+
+public class Employee
+{
+ public virtual int Id { get; protected set; }
+ public virtual string FirstName { get; set; }
+ public virtual string LastName { get; set; }
+ public virtual Store Store { get; set; }
}
diff --git a/src/Examples.FirstProject/Entities/Product.cs b/src/Examples.FirstProject/Entities/Product.cs
index b8dc2c376..afb9d0522 100644
--- a/src/Examples.FirstProject/Entities/Product.cs
+++ b/src/Examples.FirstProject/Entities/Product.cs
@@ -1,23 +1,23 @@
-using System.Collections.Generic;
-
-namespace Examples.FirstProject.Entities;
-
-public class Product
-{
- public virtual int Id { get; protected set; }
- public virtual string Name { get; set; }
- public virtual double Price { get; set; }
- public virtual Location Location { get; set; }
- public virtual IList StoresStockedIn { get; set; }
-
- public Product()
- {
- StoresStockedIn = new List();
- }
-}
-
-public class Location
-{
- public virtual int Aisle { get; set; }
- public virtual int Shelf { get; set; }
+using System.Collections.Generic;
+
+namespace Examples.FirstProject.Entities;
+
+public class Product
+{
+ public virtual int Id { get; protected set; }
+ public virtual string Name { get; set; }
+ public virtual double Price { get; set; }
+ public virtual Location Location { get; set; }
+ public virtual IList StoresStockedIn { get; set; }
+
+ public Product()
+ {
+ StoresStockedIn = new List();
+ }
+}
+
+public class Location
+{
+ public virtual int Aisle { get; set; }
+ public virtual int Shelf { get; set; }
}
diff --git a/src/Examples.FirstProject/Entities/Store.cs b/src/Examples.FirstProject/Entities/Store.cs
index 72d874ffe..8db3a5eb4 100644
--- a/src/Examples.FirstProject/Entities/Store.cs
+++ b/src/Examples.FirstProject/Entities/Store.cs
@@ -1,29 +1,29 @@
-using System.Collections.Generic;
-
-namespace Examples.FirstProject.Entities;
-
-public class Store
-{
- public virtual int Id { get; protected set; }
- public virtual string Name { get; set; }
- public virtual IList Products { get; set; }
- public virtual IList Staff { get; set; }
-
- public Store()
- {
- Products = new List();
- Staff = new List();
- }
-
- public virtual void AddProduct(Product product)
- {
- product.StoresStockedIn.Add(this);
- Products.Add(product);
- }
-
- public virtual void AddEmployee(Employee employee)
- {
- employee.Store = this;
- Staff.Add(employee);
- }
+using System.Collections.Generic;
+
+namespace Examples.FirstProject.Entities;
+
+public class Store
+{
+ public virtual int Id { get; protected set; }
+ public virtual string Name { get; set; }
+ public virtual IList Products { get; set; }
+ public virtual IList Staff { get; set; }
+
+ public Store()
+ {
+ Products = new List();
+ Staff = new List();
+ }
+
+ public virtual void AddProduct(Product product)
+ {
+ product.StoresStockedIn.Add(this);
+ Products.Add(product);
+ }
+
+ public virtual void AddEmployee(Employee employee)
+ {
+ employee.Store = this;
+ Staff.Add(employee);
+ }
}
diff --git a/src/Examples.FirstProject/Examples.FirstProject.csproj b/src/Examples.FirstProject/Examples.FirstProject.csproj
index 5772e427f..a516032be 100644
--- a/src/Examples.FirstProject/Examples.FirstProject.csproj
+++ b/src/Examples.FirstProject/Examples.FirstProject.csproj
@@ -1,25 +1,25 @@
-
-
-
- net48
- Exe
- AnyCpu
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+ net48
+ Exe
+ AnyCpu
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Examples.FirstProject/Mappings/EmployeeMap.cs b/src/Examples.FirstProject/Mappings/EmployeeMap.cs
index c37fc4c2b..32724bba4 100644
--- a/src/Examples.FirstProject/Mappings/EmployeeMap.cs
+++ b/src/Examples.FirstProject/Mappings/EmployeeMap.cs
@@ -1,15 +1,15 @@
-using Examples.FirstProject.Entities;
-using FluentNHibernate.Mapping;
-
-namespace Examples.FirstProject.Mappings;
-
-public class EmployeeMap : ClassMap
-{
- public EmployeeMap()
- {
- Id(x => x.Id);
- Map(x => x.FirstName);
- Map(x => x.LastName);
- References(x => x.Store);
- }
+using Examples.FirstProject.Entities;
+using FluentNHibernate.Mapping;
+
+namespace Examples.FirstProject.Mappings;
+
+public class EmployeeMap : ClassMap
+{
+ public EmployeeMap()
+ {
+ Id(x => x.Id);
+ Map(x => x.FirstName);
+ Map(x => x.LastName);
+ References(x => x.Store);
+ }
}
diff --git a/src/Examples.FirstProject/Mappings/LocationMap.cs b/src/Examples.FirstProject/Mappings/LocationMap.cs
index e2b32f636..c59aa2d99 100644
--- a/src/Examples.FirstProject/Mappings/LocationMap.cs
+++ b/src/Examples.FirstProject/Mappings/LocationMap.cs
@@ -1,13 +1,13 @@
-using Examples.FirstProject.Entities;
-using FluentNHibernate.Mapping;
-
-namespace Examples.FirstProject.Mappings;
-
-public class LocationMap : ComponentMap
-{
- public LocationMap()
- {
- Map(x => x.Aisle);
- Map(x => x.Shelf);
- }
+using Examples.FirstProject.Entities;
+using FluentNHibernate.Mapping;
+
+namespace Examples.FirstProject.Mappings;
+
+public class LocationMap : ComponentMap
+{
+ public LocationMap()
+ {
+ Map(x => x.Aisle);
+ Map(x => x.Shelf);
+ }
}
diff --git a/src/Examples.FirstProject/Mappings/ProductMap.cs b/src/Examples.FirstProject/Mappings/ProductMap.cs
index b2e8e3d97..a14987af6 100644
--- a/src/Examples.FirstProject/Mappings/ProductMap.cs
+++ b/src/Examples.FirstProject/Mappings/ProductMap.cs
@@ -1,20 +1,20 @@
-using Examples.FirstProject.Entities;
-using FluentNHibernate.Mapping;
-
-namespace Examples.FirstProject.Mappings;
-
-public class ProductMap : ClassMap
-{
- public ProductMap()
- {
- Id(x => x.Id);
- Map(x => x.Name);
- Map(x => x.Price);
- HasManyToMany(x => x.StoresStockedIn)
- .Cascade.All()
- .Inverse()
- .Table("StoreProduct");
-
- Component(x => x.Location);
- }
+using Examples.FirstProject.Entities;
+using FluentNHibernate.Mapping;
+
+namespace Examples.FirstProject.Mappings;
+
+public class ProductMap : ClassMap
+{
+ public ProductMap()
+ {
+ Id(x => x.Id);
+ Map(x => x.Name);
+ Map(x => x.Price);
+ HasManyToMany(x => x.StoresStockedIn)
+ .Cascade.All()
+ .Inverse()
+ .Table("StoreProduct");
+
+ Component(x => x.Location);
+ }
}
diff --git a/src/Examples.FirstProject/Mappings/StoreMap.cs b/src/Examples.FirstProject/Mappings/StoreMap.cs
index 3f8f15b75..d9a2541a9 100644
--- a/src/Examples.FirstProject/Mappings/StoreMap.cs
+++ b/src/Examples.FirstProject/Mappings/StoreMap.cs
@@ -1,19 +1,19 @@
-using Examples.FirstProject.Entities;
-using FluentNHibernate.Mapping;
-
-namespace Examples.FirstProject.Mappings;
-
-public class StoreMap : ClassMap
-{
- public StoreMap()
- {
- Id(x => x.Id);
- Map(x => x.Name);
- HasManyToMany(x => x.Products)
- .Cascade.All()
- .Table("StoreProduct");
- HasMany(x => x.Staff)
- .Cascade.All()
- .Inverse();
- }
+using Examples.FirstProject.Entities;
+using FluentNHibernate.Mapping;
+
+namespace Examples.FirstProject.Mappings;
+
+public class StoreMap : ClassMap
+{
+ public StoreMap()
+ {
+ Id(x => x.Id);
+ Map(x => x.Name);
+ HasManyToMany(x => x.Products)
+ .Cascade.All()
+ .Table("StoreProduct");
+ HasMany(x => x.Staff)
+ .Cascade.All()
+ .Inverse();
+ }
}
diff --git a/src/Examples.FirstProject/Program.cs b/src/Examples.FirstProject/Program.cs
index 1f7236879..69a647b36 100644
--- a/src/Examples.FirstProject/Program.cs
+++ b/src/Examples.FirstProject/Program.cs
@@ -1,137 +1,137 @@
-using System;
-using System.IO;
-using Examples.FirstProject.Entities;
-using FluentNHibernate.Cfg;
-using FluentNHibernate.Cfg.Db;
-using NHibernate;
-using NHibernate.Cfg;
-using NHibernate.Tool.hbm2ddl;
-
-namespace Examples.FirstProject;
-
-class Program
-{
- private const string DbFile = "firstProgram.db";
-
- static void Main()
- {
- // create our NHibernate session factory
- var sessionFactory = CreateSessionFactory();
-
- using (var session = sessionFactory.OpenSession())
- {
- // populate the database
- using (var transaction = session.BeginTransaction())
- {
- // create a couple of Stores each with some Products and Employees
- var barginBasin = new Store { Name = "Bargin Basin" };
- var superMart = new Store { Name = "SuperMart" };
-
- var potatoes = new Product { Name = "Potatoes", Price = 3.60 };
- var fish = new Product { Name = "Fish", Price = 4.49 };
- var milk = new Product { Name = "Milk", Price = 0.79 };
- var bread = new Product { Name = "Bread", Price = 1.29 };
- var cheese = new Product { Name = "Cheese", Price = 2.10 };
- var waffles = new Product { Name = "Waffles", Price = 2.41 };
-
- var daisy = new Employee { FirstName = "Daisy", LastName = "Harrison" };
- var jack = new Employee { FirstName = "Jack", LastName = "Torrance" };
- var sue = new Employee { FirstName = "Sue", LastName = "Walkters" };
- var bill = new Employee { FirstName = "Bill", LastName = "Taft" };
- var joan = new Employee { FirstName = "Joan", LastName = "Pope" };
-
- // add products to the stores, there's some crossover in the products in each
- // store, because the store-product relationship is many-to-many
- AddProductsToStore(barginBasin, potatoes, fish, milk, bread, cheese);
- AddProductsToStore(superMart, bread, cheese, waffles);
-
- // add employees to the stores, this relationship is a one-to-many, so one
- // employee can only work at one store at a time
- AddEmployeesToStore(barginBasin, daisy, jack, sue);
- AddEmployeesToStore(superMart, bill, joan);
-
- // save both stores, this saves everything else via cascading
- session.SaveOrUpdate(barginBasin);
- session.SaveOrUpdate(superMart);
-
- transaction.Commit();
- }
- }
-
- using (var session = sessionFactory.OpenSession())
- {
- // retreive all stores and display them
- using (session.BeginTransaction())
- {
- var stores = session.CreateCriteria(typeof(Store))
- .List();
-
- foreach (var store in stores)
- {
- WriteStorePretty(store);
- }
- }
- }
-
- Console.ReadKey();
- }
-
- private static ISessionFactory CreateSessionFactory()
- {
- return Fluently.Configure()
- .Database(SQLiteConfiguration.Standard
- .UsingFile(DbFile))
- .Mappings(m =>
- m.FluentMappings.AddFromAssemblyOf())
- .ExposeConfiguration(BuildSchema)
- .BuildSessionFactory();
- }
-
- private static void BuildSchema(Configuration config)
- {
- // delete the existing db on each run
- if (File.Exists(DbFile))
- File.Delete(DbFile);
-
- // this NHibernate tool takes a configuration (with mapping info in)
- // and exports a database schema from it
- new SchemaExport(config)
- .Create(false, true);
- }
-
- private static void WriteStorePretty(Store store)
- {
- Console.WriteLine(store.Name);
- Console.WriteLine(" Products:");
-
- foreach (var product in store.Products)
- {
- Console.WriteLine(" " + product.Name);
- }
-
- Console.WriteLine(" Staff:");
-
- foreach (var employee in store.Staff)
- {
- Console.WriteLine(" " + employee.FirstName + " " + employee.LastName);
- }
-
- Console.WriteLine();
- }
-
- public static void AddProductsToStore(Store store, params Product[] products)
- {
- foreach (var product in products)
- {
- store.AddProduct(product);
- }
- }
-
- public static void AddEmployeesToStore(Store store, params Employee[] employees)
- {
- foreach (var employee in employees)
- {
- store.AddEmployee(employee);
- }
- }
+using System;
+using System.IO;
+using Examples.FirstProject.Entities;
+using FluentNHibernate.Cfg;
+using FluentNHibernate.Cfg.Db;
+using NHibernate;
+using NHibernate.Cfg;
+using NHibernate.Tool.hbm2ddl;
+
+namespace Examples.FirstProject;
+
+class Program
+{
+ private const string DbFile = "firstProgram.db";
+
+ static void Main()
+ {
+ // create our NHibernate session factory
+ var sessionFactory = CreateSessionFactory();
+
+ using (var session = sessionFactory.OpenSession())
+ {
+ // populate the database
+ using (var transaction = session.BeginTransaction())
+ {
+ // create a couple of Stores each with some Products and Employees
+ var barginBasin = new Store { Name = "Bargin Basin" };
+ var superMart = new Store { Name = "SuperMart" };
+
+ var potatoes = new Product { Name = "Potatoes", Price = 3.60 };
+ var fish = new Product { Name = "Fish", Price = 4.49 };
+ var milk = new Product { Name = "Milk", Price = 0.79 };
+ var bread = new Product { Name = "Bread", Price = 1.29 };
+ var cheese = new Product { Name = "Cheese", Price = 2.10 };
+ var waffles = new Product { Name = "Waffles", Price = 2.41 };
+
+ var daisy = new Employee { FirstName = "Daisy", LastName = "Harrison" };
+ var jack = new Employee { FirstName = "Jack", LastName = "Torrance" };
+ var sue = new Employee { FirstName = "Sue", LastName = "Walkters" };
+ var bill = new Employee { FirstName = "Bill", LastName = "Taft" };
+ var joan = new Employee { FirstName = "Joan", LastName = "Pope" };
+
+ // add products to the stores, there's some crossover in the products in each
+ // store, because the store-product relationship is many-to-many
+ AddProductsToStore(barginBasin, potatoes, fish, milk, bread, cheese);
+ AddProductsToStore(superMart, bread, cheese, waffles);
+
+ // add employees to the stores, this relationship is a one-to-many, so one
+ // employee can only work at one store at a time
+ AddEmployeesToStore(barginBasin, daisy, jack, sue);
+ AddEmployeesToStore(superMart, bill, joan);
+
+ // save both stores, this saves everything else via cascading
+ session.SaveOrUpdate(barginBasin);
+ session.SaveOrUpdate(superMart);
+
+ transaction.Commit();
+ }
+ }
+
+ using (var session = sessionFactory.OpenSession())
+ {
+ // retreive all stores and display them
+ using (session.BeginTransaction())
+ {
+ var stores = session.CreateCriteria(typeof(Store))
+ .List();
+
+ foreach (var store in stores)
+ {
+ WriteStorePretty(store);
+ }
+ }
+ }
+
+ Console.ReadKey();
+ }
+
+ private static ISessionFactory CreateSessionFactory()
+ {
+ return Fluently.Configure()
+ .Database(SQLiteConfiguration.Standard
+ .UsingFile(DbFile))
+ .Mappings(m =>
+ m.FluentMappings.AddFromAssemblyOf())
+ .ExposeConfiguration(BuildSchema)
+ .BuildSessionFactory();
+ }
+
+ private static void BuildSchema(Configuration config)
+ {
+ // delete the existing db on each run
+ if (File.Exists(DbFile))
+ File.Delete(DbFile);
+
+ // this NHibernate tool takes a configuration (with mapping info in)
+ // and exports a database schema from it
+ new SchemaExport(config)
+ .Create(false, true);
+ }
+
+ private static void WriteStorePretty(Store store)
+ {
+ Console.WriteLine(store.Name);
+ Console.WriteLine(" Products:");
+
+ foreach (var product in store.Products)
+ {
+ Console.WriteLine(" " + product.Name);
+ }
+
+ Console.WriteLine(" Staff:");
+
+ foreach (var employee in store.Staff)
+ {
+ Console.WriteLine(" " + employee.FirstName + " " + employee.LastName);
+ }
+
+ Console.WriteLine();
+ }
+
+ public static void AddProductsToStore(Store store, params Product[] products)
+ {
+ foreach (var product in products)
+ {
+ store.AddProduct(product);
+ }
+ }
+
+ public static void AddEmployeesToStore(Store store, params Employee[] employees)
+ {
+ foreach (var employee in employees)
+ {
+ store.AddEmployee(employee);
+ }
+ }
}
diff --git a/src/Examples.FirstProject/Properties/AssemblyInfo.cs b/src/Examples.FirstProject/Properties/AssemblyInfo.cs
index 31b149844..a260a63e9 100644
--- a/src/Examples.FirstProject/Properties/AssemblyInfo.cs
+++ b/src/Examples.FirstProject/Properties/AssemblyInfo.cs
@@ -1,5 +1,5 @@
-using System;
-using System.Runtime.InteropServices;
-
-[assembly: ComVisible(false)]
+using System;
+using System.Runtime.InteropServices;
+
+[assembly: ComVisible(false)]
[assembly: CLSCompliant(true)]
diff --git a/src/FluentNHibernate.Specs.ExternalFixtures/Component.cs b/src/FluentNHibernate.Specs.ExternalFixtures/Component.cs
index 0e2e0ed5f..85de4c297 100644
--- a/src/FluentNHibernate.Specs.ExternalFixtures/Component.cs
+++ b/src/FluentNHibernate.Specs.ExternalFixtures/Component.cs
@@ -1,3 +1,3 @@
-namespace FluentNHibernate.Specs.ExternalFixtures;
-
+namespace FluentNHibernate.Specs.ExternalFixtures;
+
public class Component {}
diff --git a/src/FluentNHibernate.Specs.ExternalFixtures/Entity.cs b/src/FluentNHibernate.Specs.ExternalFixtures/Entity.cs
index cff0b74c9..c93248f11 100644
--- a/src/FluentNHibernate.Specs.ExternalFixtures/Entity.cs
+++ b/src/FluentNHibernate.Specs.ExternalFixtures/Entity.cs
@@ -1,52 +1,52 @@
-using System.Collections.Generic;
-
-namespace FluentNHibernate.Specs.ExternalFixtures;
-
-public class Entity
-{
- EntityChild readOnlyChild;
-
- public int Id { get; set; }
- public string One { get; set; }
- public TestEnum Enum { get; set; }
- public Entity Parent { get; set; }
- public IList Children { get; set; }
- public Component Component { get; set; }
-
- public enum TestEnum {}
-
- public EntityChild ReadOnlyChild
- {
- get { return readOnlyChild; }
- }
-}
-
-public class EntityChild
-{}
-
-public abstract class A_Child : B_Parent
-{
-
-}
-
-public class B_Parent
-{
- public int Id { get; set; }
- public string Name { get; set; }
-}
-
-public class Child : Parent
-{
-
-}
-
-public class Parent
-{
- public int Id { get; set; }
- public Component Component { get; set; }
-}
-
-public class ChildChild : Child
-{
-
+using System.Collections.Generic;
+
+namespace FluentNHibernate.Specs.ExternalFixtures;
+
+public class Entity
+{
+ EntityChild readOnlyChild;
+
+ public int Id { get; set; }
+ public string One { get; set; }
+ public TestEnum Enum { get; set; }
+ public Entity Parent { get; set; }
+ public IList Children { get; set; }
+ public Component Component { get; set; }
+
+ public enum TestEnum {}
+
+ public EntityChild ReadOnlyChild
+ {
+ get { return readOnlyChild; }
+ }
+}
+
+public class EntityChild
+{}
+
+public abstract class A_Child : B_Parent
+{
+
+}
+
+public class B_Parent
+{
+ public int Id { get; set; }
+ public string Name { get; set; }
+}
+
+public class Child : Parent
+{
+
+}
+
+public class Parent
+{
+ public int Id { get; set; }
+ public Component Component { get; set; }
+}
+
+public class ChildChild : Child
+{
+
}
diff --git a/src/FluentNHibernate.Specs.ExternalFixtures/FluentNHibernate.Specs.ExternalFixtures.csproj b/src/FluentNHibernate.Specs.ExternalFixtures/FluentNHibernate.Specs.ExternalFixtures.csproj
index 62ddda331..efe8df941 100644
--- a/src/FluentNHibernate.Specs.ExternalFixtures/FluentNHibernate.Specs.ExternalFixtures.csproj
+++ b/src/FluentNHibernate.Specs.ExternalFixtures/FluentNHibernate.Specs.ExternalFixtures.csproj
@@ -1,11 +1,11 @@
-
-
- net48;netstandard2.0
- false
-
-
-
-
-
-
+
+
+ net48;netstandard2.0
+ false
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/FluentNHibernate.Specs.ExternalFixtures/Overrides/EntityBatchSizeOverride.cs b/src/FluentNHibernate.Specs.ExternalFixtures/Overrides/EntityBatchSizeOverride.cs
index d77eae0be..4b41d7956 100644
--- a/src/FluentNHibernate.Specs.ExternalFixtures/Overrides/EntityBatchSizeOverride.cs
+++ b/src/FluentNHibernate.Specs.ExternalFixtures/Overrides/EntityBatchSizeOverride.cs
@@ -1,12 +1,12 @@
-using FluentNHibernate.Automapping;
-using FluentNHibernate.Automapping.Alterations;
-
-namespace FluentNHibernate.Specs.ExternalFixtures.Overrides;
-
-public class EntityBatchSizeOverride : IAutoMappingOverride
-{
- public void Override(AutoMapping mapping)
- {
- mapping.BatchSize(1234);
- }
+using FluentNHibernate.Automapping;
+using FluentNHibernate.Automapping.Alterations;
+
+namespace FluentNHibernate.Specs.ExternalFixtures.Overrides;
+
+public class EntityBatchSizeOverride : IAutoMappingOverride
+{
+ public void Override(AutoMapping mapping)
+ {
+ mapping.BatchSize(1234);
+ }
}
diff --git a/src/FluentNHibernate.Specs.ExternalFixtures/Properties/AssemblyInfo.cs b/src/FluentNHibernate.Specs.ExternalFixtures/Properties/AssemblyInfo.cs
index 31b149844..a260a63e9 100644
--- a/src/FluentNHibernate.Specs.ExternalFixtures/Properties/AssemblyInfo.cs
+++ b/src/FluentNHibernate.Specs.ExternalFixtures/Properties/AssemblyInfo.cs
@@ -1,5 +1,5 @@
-using System;
-using System.Runtime.InteropServices;
-
-[assembly: ComVisible(false)]
+using System;
+using System.Runtime.InteropServices;
+
+[assembly: ComVisible(false)]
[assembly: CLSCompliant(true)]
diff --git a/src/FluentNHibernate.Specs/Automapping/AutoMapBackwardsCompatibilitySpecs.cs b/src/FluentNHibernate.Specs/Automapping/AutoMapBackwardsCompatibilitySpecs.cs
index 4815d100f..f79fd9f84 100644
--- a/src/FluentNHibernate.Specs/Automapping/AutoMapBackwardsCompatibilitySpecs.cs
+++ b/src/FluentNHibernate.Specs/Automapping/AutoMapBackwardsCompatibilitySpecs.cs
@@ -1,47 +1,47 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using FluentNHibernate.Automapping;
-using FluentNHibernate.Specs.Automapping.Fixtures;
-using Machine.Specifications;
-using FluentAssertions;
-
-namespace FluentNHibernate.Specs.Automapping;
-// just verify that the obsolete methods still work until we bin them entirely
-
-public class when_using_automap_obsolete_where_method_for_assembly_of : AutoMapObsoleteSpec
-{
- Because of = () =>
- AutoMap.AssemblyOf(where_clause)
- .BuildMappings();
-
- It should_use_the_where_clause_provided = () =>
- was_called.Should().BeTrue();
-}
-
-public class when_using_automap_obsolete_where_method_for_an_assembly : AutoMapObsoleteSpec
-{
- Because of = () =>
- AutoMap.Assembly(typeof(EntityUsingPrivateFields).Assembly, where_clause)
- .BuildMappings();
-
- It should_use_the_where_clause_provided = () =>
- was_called.Should().BeTrue();
-}
-
-public class when_using_automap_obsolete_where_method_for_a_source : AutoMapObsoleteSpec
-{
- Because of = () =>
- AutoMap.Source(new StubTypeSource(typeof(EntityUsingPrivateFields)), where_clause)
- .BuildMappings();
-
- It should_use_the_where_clause_provided = () =>
- was_called.Should().BeTrue();
-}
-
-public abstract class AutoMapObsoleteSpec
-{
- protected static Func where_clause = x => !(was_called = true);
- protected static bool was_called;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using FluentNHibernate.Automapping;
+using FluentNHibernate.Specs.Automapping.Fixtures;
+using Machine.Specifications;
+using FluentAssertions;
+
+namespace FluentNHibernate.Specs.Automapping;
+// just verify that the obsolete methods still work until we bin them entirely
+
+public class when_using_automap_obsolete_where_method_for_assembly_of : AutoMapObsoleteSpec
+{
+ Because of = () =>
+ AutoMap.AssemblyOf(where_clause)
+ .BuildMappings();
+
+ It should_use_the_where_clause_provided = () =>
+ was_called.Should().BeTrue();
+}
+
+public class when_using_automap_obsolete_where_method_for_an_assembly : AutoMapObsoleteSpec
+{
+ Because of = () =>
+ AutoMap.Assembly(typeof(EntityUsingPrivateFields).Assembly, where_clause)
+ .BuildMappings();
+
+ It should_use_the_where_clause_provided = () =>
+ was_called.Should().BeTrue();
+}
+
+public class when_using_automap_obsolete_where_method_for_a_source : AutoMapObsoleteSpec
+{
+ Because of = () =>
+ AutoMap.Source(new StubTypeSource(typeof(EntityUsingPrivateFields)), where_clause)
+ .BuildMappings();
+
+ It should_use_the_where_clause_provided = () =>
+ was_called.Should().BeTrue();
+}
+
+public abstract class AutoMapObsoleteSpec
+{
+ protected static Func where_clause = x => !(was_called = true);
+ protected static bool was_called;
}
diff --git a/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.Conventions.cs b/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.Conventions.cs
index d191520e2..6ead1f864 100644
--- a/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.Conventions.cs
+++ b/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.Conventions.cs
@@ -1,103 +1,103 @@
-using System;
-using System.Data;
-using System.Xml;
-using FluentNHibernate.Automapping;
-using FluentNHibernate.Conventions;
-using FluentNHibernate.Conventions.Inspections;
-using FluentNHibernate.Conventions.Instances;
-using FluentNHibernate.Specs.Automapping.Fixtures;
-using FluentNHibernate.Specs.ExternalFixtures;
-using Machine.Specifications;
-using NHibernate.SqlTypes;
-using NHibernate.UserTypes;
-
-namespace FluentNHibernate.Specs.Automapping;
-
-public class when_the_automapper_maps_with_a_property_convention
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(Entity)))
- .Conventions.Add();
-
- Because of = () =>
- xml = mapper.BuildMappingFor().ToXml();
-
- It should_apply_the_convention_to_any_properties = () =>
- xml.Element("class/property[@name='One']/column").HasAttribute("name", "OneXX");
-
- static AutoPersistenceModel mapper;
- static XmlDocument xml;
-
- class XXAppenderPropertyConvention : IPropertyConvention
- {
- public void Apply(IPropertyInstance instance)
- {
- instance.Column(instance.Name + "XX");
- }
- }
-}
-
-public class when_the_automapper_maps_a_readonly_reference_with_an_access_convention
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(Entity)))
- .Conventions.Add();
-
- Because of = () =>
- xml = mapper.BuildMappingFor().ToXml();
-
- It should_apply_the_convention_to_any_properties = () =>
- xml.Element("class/many-to-one[@name='ReadOnlyChild']").HasAttribute("access", "nosetter.camelcase-underscore");
-
- static AutoPersistenceModel mapper;
- static XmlDocument xml;
-
- class Convention : IReferenceConvention
- {
- public void Apply(IManyToOneInstance instance)
- {
- instance.Access.ReadOnlyPropertyThroughCamelCaseField(CamelCasePrefix.Underscore);
- }
- }
-}
-
-public class when_the_automapper_maps_with_a_usertype_convention_to_property_of_value_type
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(TypeWithNullableUT), typeof(TypeWithValueUT)))
- .Conventions.Add();
-
- Because of = () =>
- {
- nullableMapping = mapper.BuildMappingFor().ToXml();
- notNullableMapping = mapper.BuildMappingFor().ToXml();
- };
-
- It shold_apply_convention_to_properties_of_corresponding_nullable_type = () =>
- nullableMapping.Element("class/property[@name='Simple']/column").HasAttribute("name", "arbitraryName");
-
- It shold_apply_convention_to_properties_of_corresponding_non_nullable_value_type = () =>
- notNullableMapping.Element("class/property[@name='Definite']/column").HasAttribute("name", "arbitraryName");
-
- static XmlDocument nullableMapping;
- static XmlDocument notNullableMapping;
- static AutoPersistenceModel mapper;
-}
-
-public class when_the_automapper_maps_with_a_usertype_convention_to_property_of_reference_type
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(NotNullableUT)))
- .Conventions.Add();
-
- Because of = () =>
- xml = mapper.BuildMappingFor().ToXml();
-
- It shold_apply_convention_to_property = () =>
- xml.Element("class/property[@name='Complex']/column").HasAttribute("name", "someOtherName");
-
- static XmlDocument xml;
- static AutoPersistenceModel mapper;
-
-
+using System;
+using System.Data;
+using System.Xml;
+using FluentNHibernate.Automapping;
+using FluentNHibernate.Conventions;
+using FluentNHibernate.Conventions.Inspections;
+using FluentNHibernate.Conventions.Instances;
+using FluentNHibernate.Specs.Automapping.Fixtures;
+using FluentNHibernate.Specs.ExternalFixtures;
+using Machine.Specifications;
+using NHibernate.SqlTypes;
+using NHibernate.UserTypes;
+
+namespace FluentNHibernate.Specs.Automapping;
+
+public class when_the_automapper_maps_with_a_property_convention
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(Entity)))
+ .Conventions.Add();
+
+ Because of = () =>
+ xml = mapper.BuildMappingFor().ToXml();
+
+ It should_apply_the_convention_to_any_properties = () =>
+ xml.Element("class/property[@name='One']/column").HasAttribute("name", "OneXX");
+
+ static AutoPersistenceModel mapper;
+ static XmlDocument xml;
+
+ class XXAppenderPropertyConvention : IPropertyConvention
+ {
+ public void Apply(IPropertyInstance instance)
+ {
+ instance.Column(instance.Name + "XX");
+ }
+ }
+}
+
+public class when_the_automapper_maps_a_readonly_reference_with_an_access_convention
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(Entity)))
+ .Conventions.Add();
+
+ Because of = () =>
+ xml = mapper.BuildMappingFor().ToXml();
+
+ It should_apply_the_convention_to_any_properties = () =>
+ xml.Element("class/many-to-one[@name='ReadOnlyChild']").HasAttribute("access", "nosetter.camelcase-underscore");
+
+ static AutoPersistenceModel mapper;
+ static XmlDocument xml;
+
+ class Convention : IReferenceConvention
+ {
+ public void Apply(IManyToOneInstance instance)
+ {
+ instance.Access.ReadOnlyPropertyThroughCamelCaseField(CamelCasePrefix.Underscore);
+ }
+ }
+}
+
+public class when_the_automapper_maps_with_a_usertype_convention_to_property_of_value_type
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(TypeWithNullableUT), typeof(TypeWithValueUT)))
+ .Conventions.Add();
+
+ Because of = () =>
+ {
+ nullableMapping = mapper.BuildMappingFor().ToXml();
+ notNullableMapping = mapper.BuildMappingFor().ToXml();
+ };
+
+ It shold_apply_convention_to_properties_of_corresponding_nullable_type = () =>
+ nullableMapping.Element("class/property[@name='Simple']/column").HasAttribute("name", "arbitraryName");
+
+ It shold_apply_convention_to_properties_of_corresponding_non_nullable_value_type = () =>
+ notNullableMapping.Element("class/property[@name='Definite']/column").HasAttribute("name", "arbitraryName");
+
+ static XmlDocument nullableMapping;
+ static XmlDocument notNullableMapping;
+ static AutoPersistenceModel mapper;
+}
+
+public class when_the_automapper_maps_with_a_usertype_convention_to_property_of_reference_type
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(NotNullableUT)))
+ .Conventions.Add();
+
+ Because of = () =>
+ xml = mapper.BuildMappingFor().ToXml();
+
+ It shold_apply_convention_to_property = () =>
+ xml.Element("class/property[@name='Complex']/column").HasAttribute("name", "someOtherName");
+
+ static XmlDocument xml;
+ static AutoPersistenceModel mapper;
+
+
}
diff --git a/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.cs b/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.cs
index afd877604..d093205b1 100644
--- a/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.cs
+++ b/src/FluentNHibernate.Specs/Automapping/AutoPersistenceModelSpecs.cs
@@ -1,114 +1,114 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Xml;
-using FluentNHibernate.Automapping;
-using FluentNHibernate.Cfg;
-using FluentNHibernate.Cfg.Db;
-using FluentNHibernate.MappingModel.ClassBased;
-using FluentNHibernate.Specs.Automapping.Fixtures;
-using FluentNHibernate.Specs.ExternalFixtures;
-using Machine.Specifications;
-using FluentAssertions;
-
-namespace FluentNHibernate.Specs.Automapping;
-
-public class when_the_automapper_is_told_to_map_a_single_type
-{
- Because of = () =>
- xml = AutoMap.Source(new StubTypeSource(typeof(Entity)))
- .BuildMappingFor()
- .ToXml();
-
- It should_only_return_one_class_in_the_xml = () =>
- {
- xml.Element("class").ShouldExist();
- xml.Element("class[2]").ShouldNotExist();
- };
-
- It should_map_the_id = () =>
- xml.Element("class/id").ShouldExist();
-
- It should_map_properties = () =>
- xml.Element("class/property[@name='One']").ShouldExist();
-
- It should_map_enum_properties = () =>
- xml.Element("class/property[@name='Enum']").ShouldExist();
-
- It should_map_references = () =>
- xml.Element("class/many-to-one[@name='Parent']").ShouldExist();
-
- It should_map_collections = () =>
- xml.Element("class/bag[@name='Children']").ShouldExist();
-
- static XmlDocument xml;
-}
-
-public class when_the_automapper_is_ran_to_completion
-{
- Establish context = () =>
-
- setup = Fluently.Configure()
- .Database(
- CreateStandardInMemoryConfiguration())
- .Mappings(x => x.AutoMappings.Add(AutoMap.Source(new StubTypeSource(typeof(Entity)))));
-
- Because of = () =>
- ex = Catch.Exception(() => setup.BuildConfiguration());
-
- It should_generate_xml_that_is_accepted_by_the_nhibernate_schema_validation = () =>
- ex.Should().BeNull();
-
- static FluentConfiguration setup;
- static Exception ex;
-
- private static IPersistenceConfigurer CreateStandardInMemoryConfiguration()
- {
-#if NETFRAMEWORK
- var configuration = SQLiteConfiguration.Standard.InMemory();
-#else
- var configuration = MsSqliteConfiguration.Standard.InMemory();
-#endif
- return configuration;
- }
-}
-
-public class when_the_automapper_is_told_to_map_an_inheritance_hierarchy
-{
- Because of = () =>
- ex = Catch.Exception(() =>
- AutoMap.Source(new StubTypeSource(typeof(A_Child), typeof(B_Parent)))
- .BuildMappings());
-
- // this will fail with an exception if this is broken:
- // was failing because the child class was being mapped first
- // adding all properties from it and it's base class. Then the
- // base class was being mapped, duplicating those properties
- // that were already mapped in the child. Needed to change the
- // ordering so parents are always mapped before their children
- It should_map_the_top_most_class_first = () =>
- ex.Should().BeNull();
-
- static Exception ex;
-}
-
-public class when_the_automapper_maps_an_inheritance_hierarchy_with_three_levels_and_the_middle_ignored
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(ChildChild), typeof(Parent), typeof(Child)))
- .IgnoreBase();
-
- Because of = () =>
- mappings = mapper.BuildMappings()
- .SelectMany(x => x.Classes);
-
- It should_map_the_parent = () =>
- mappings.Count().Should().Be(1);
-
- It should_map_the_child_child_as_a_subclass_of_parent = () =>
- mappings.Single()
- .Subclasses.Single().Type.Should().Be(typeof(ChildChild));
-
- static AutoPersistenceModel mapper;
- static IEnumerable mappings;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Xml;
+using FluentNHibernate.Automapping;
+using FluentNHibernate.Cfg;
+using FluentNHibernate.Cfg.Db;
+using FluentNHibernate.MappingModel.ClassBased;
+using FluentNHibernate.Specs.Automapping.Fixtures;
+using FluentNHibernate.Specs.ExternalFixtures;
+using Machine.Specifications;
+using FluentAssertions;
+
+namespace FluentNHibernate.Specs.Automapping;
+
+public class when_the_automapper_is_told_to_map_a_single_type
+{
+ Because of = () =>
+ xml = AutoMap.Source(new StubTypeSource(typeof(Entity)))
+ .BuildMappingFor()
+ .ToXml();
+
+ It should_only_return_one_class_in_the_xml = () =>
+ {
+ xml.Element("class").ShouldExist();
+ xml.Element("class[2]").ShouldNotExist();
+ };
+
+ It should_map_the_id = () =>
+ xml.Element("class/id").ShouldExist();
+
+ It should_map_properties = () =>
+ xml.Element("class/property[@name='One']").ShouldExist();
+
+ It should_map_enum_properties = () =>
+ xml.Element("class/property[@name='Enum']").ShouldExist();
+
+ It should_map_references = () =>
+ xml.Element("class/many-to-one[@name='Parent']").ShouldExist();
+
+ It should_map_collections = () =>
+ xml.Element("class/bag[@name='Children']").ShouldExist();
+
+ static XmlDocument xml;
+}
+
+public class when_the_automapper_is_ran_to_completion
+{
+ Establish context = () =>
+
+ setup = Fluently.Configure()
+ .Database(
+ CreateStandardInMemoryConfiguration())
+ .Mappings(x => x.AutoMappings.Add(AutoMap.Source(new StubTypeSource(typeof(Entity)))));
+
+ Because of = () =>
+ ex = Catch.Exception(() => setup.BuildConfiguration());
+
+ It should_generate_xml_that_is_accepted_by_the_nhibernate_schema_validation = () =>
+ ex.Should().BeNull();
+
+ static FluentConfiguration setup;
+ static Exception ex;
+
+ private static IPersistenceConfigurer CreateStandardInMemoryConfiguration()
+ {
+#if NETFRAMEWORK
+ var configuration = SQLiteConfiguration.Standard.InMemory();
+#else
+ var configuration = MsSqliteConfiguration.Standard.InMemory();
+#endif
+ return configuration;
+ }
+}
+
+public class when_the_automapper_is_told_to_map_an_inheritance_hierarchy
+{
+ Because of = () =>
+ ex = Catch.Exception(() =>
+ AutoMap.Source(new StubTypeSource(typeof(A_Child), typeof(B_Parent)))
+ .BuildMappings());
+
+ // this will fail with an exception if this is broken:
+ // was failing because the child class was being mapped first
+ // adding all properties from it and it's base class. Then the
+ // base class was being mapped, duplicating those properties
+ // that were already mapped in the child. Needed to change the
+ // ordering so parents are always mapped before their children
+ It should_map_the_top_most_class_first = () =>
+ ex.Should().BeNull();
+
+ static Exception ex;
+}
+
+public class when_the_automapper_maps_an_inheritance_hierarchy_with_three_levels_and_the_middle_ignored
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(ChildChild), typeof(Parent), typeof(Child)))
+ .IgnoreBase();
+
+ Because of = () =>
+ mappings = mapper.BuildMappings()
+ .SelectMany(x => x.Classes);
+
+ It should_map_the_parent = () =>
+ mappings.Count().Should().Be(1);
+
+ It should_map_the_child_child_as_a_subclass_of_parent = () =>
+ mappings.Single()
+ .Subclasses.Single().Type.Should().Be(typeof(ChildChild));
+
+ static AutoPersistenceModel mapper;
+ static IEnumerable mappings;
}
diff --git a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Components.cs b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Components.cs
index bb47e5c12..982fffb76 100644
--- a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Components.cs
+++ b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Components.cs
@@ -1,152 +1,152 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using FluentNHibernate.Automapping;
-using FluentNHibernate.Mapping;
-using FluentNHibernate.MappingModel.ClassBased;
-using FluentNHibernate.Specs.Automapping.Fixtures;
-using FluentNHibernate.Specs.ExternalFixtures;
-using FluentNHibernate.Utils;
-using Machine.Specifications;
-using FluentAssertions;
-
-namespace FluentNHibernate.Specs.Automapping;
-
-public class when_the_automapper_is_told_to_map_an_entity_and_a_component
-{
- Establish context = () =>
- mapper = AutoMap.Source(
- new StubTypeSource(typeof(Entity), typeof(Component)),
- new TestConfiguration());
-
- Because of = () =>
- mappings = mapper.BuildMappings()
- .SelectMany(x => x.Classes);
-
- It should_map_the_entity = () =>
- mappings.ShouldContain(x => x.Type == typeof(Entity));
-
- It should_not_map_the_component_as_an_entity = () =>
- mappings.ShouldNotContain(x => x.Type == typeof(Component));
-
- It should_map_the_component_as_a_component_of_the_entity = () =>
- mappings.Single(x => x.Type == typeof(Entity))
- .Components.ShouldContain(x => x.Type == typeof(Component));
-
- static AutoPersistenceModel mapper;
- static IEnumerable mappings;
-
- class TestConfiguration : DefaultAutomappingConfiguration
- {
- public override bool IsComponent(Type type)
- {
- return type == typeof(Component);
- }
- }
-}
-
-public class when_the_automapper_is_told_to_map_an_entity_and_a_component_that_has_an_associated_ComponentMap
-{
- Establish context = () =>
- mapper = AutoMap.Source(
- new StubTypeSource(typeof(Entity), typeof(Component)),
- new TestConfiguration())
- .AddMappingsFromSource(new StubTypeSource(typeof(CompMap)));
-
- Because of = () =>
- mappings = mapper.BuildMappings()
- .SelectMany(x => x.Classes);
-
- It should_map_the_entity = () =>
- mappings.ShouldContain(x => x.Type == typeof(Entity));
-
- It should_not_map_the_component_as_an_entity = () =>
- mappings.ShouldNotContain(x => x.Type == typeof(Component));
-
- It should_map_the_component_as_a_component_of_the_entity = () =>
- mappings.Single(x => x.Type == typeof(Entity))
- .Components.ShouldContain(x => x.Type == typeof(Component));
-
- It should_use_the_component_map_for_mapping = () =>
- mappings.Single().Components.Single().Access.Should().Be("none");
-
- static AutoPersistenceModel mapper;
- static IEnumerable mappings;
-
- class TestConfiguration : DefaultAutomappingConfiguration
- {
- public override bool IsComponent(Type type)
- {
- return type == typeof(Component);
- }
- }
-
- class CompMap : ComponentMap
- {
- public CompMap()
- {
- Access.None();
- }
- }
-}
-
-public class when_the_automapper_maps_nested_comonents
-{
- Establish context = () =>
- mapper = AutoMap.Source(
- new StubTypeSource(typeof(Entity1), typeof(Location), typeof(FormatA), typeof(FormatB)),
- new TestConfiguration());
-
- Because of = () =>
- mapping = mapper.BuildMappingFor();
-
- It should_prefix_the_components_in_the_entity = () =>
- mapping.Components
- .SelectMany(x => x.Properties)
- .SelectMany(x => x.Columns)
- .Select(x => x.Name)
- .Should().Contain(new string[] { "LeftLocationProperty", "RightLocationProperty" });
-
- It should_prefix_the_components_in_the_components = () =>
- mapping.Components
- .SelectMany(x => x.Components)
- .SelectMany(x => x.Properties)
- .SelectMany(x => x.Columns)
- .Select(x => x.Name)
- .Should().Contain(new string[] { "LeftAPropertyA", "LeftBPropertyB", "RightAPropertyA", "RightBPropertyB" });
-
- static AutoPersistenceModel mapper;
- static ClassMapping mapping;
-
- class TestConfiguration : DefaultAutomappingConfiguration
- {
- public override bool IsComponent(Type type)
- {
- return type.In(typeof(Location), typeof(FormatA), typeof(FormatB));
- }
- }
-}
-
-public class Entity1
-{
- public int Id { get; set; }
- public Location Left { get; set; }
- public Location Right { get; set; }
-}
-
-public class Location
-{
- public string LocationProperty { get; set; }
- public FormatA A { get; set; }
- public FormatB B { get; set; }
-}
-
-public class FormatA
-{
- public string PropertyA { get; set; }
-}
-
-public class FormatB
-{
- public string PropertyB { get; set; }
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using FluentNHibernate.Automapping;
+using FluentNHibernate.Mapping;
+using FluentNHibernate.MappingModel.ClassBased;
+using FluentNHibernate.Specs.Automapping.Fixtures;
+using FluentNHibernate.Specs.ExternalFixtures;
+using FluentNHibernate.Utils;
+using Machine.Specifications;
+using FluentAssertions;
+
+namespace FluentNHibernate.Specs.Automapping;
+
+public class when_the_automapper_is_told_to_map_an_entity_and_a_component
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(
+ new StubTypeSource(typeof(Entity), typeof(Component)),
+ new TestConfiguration());
+
+ Because of = () =>
+ mappings = mapper.BuildMappings()
+ .SelectMany(x => x.Classes);
+
+ It should_map_the_entity = () =>
+ mappings.ShouldContain(x => x.Type == typeof(Entity));
+
+ It should_not_map_the_component_as_an_entity = () =>
+ mappings.ShouldNotContain(x => x.Type == typeof(Component));
+
+ It should_map_the_component_as_a_component_of_the_entity = () =>
+ mappings.Single(x => x.Type == typeof(Entity))
+ .Components.ShouldContain(x => x.Type == typeof(Component));
+
+ static AutoPersistenceModel mapper;
+ static IEnumerable mappings;
+
+ class TestConfiguration : DefaultAutomappingConfiguration
+ {
+ public override bool IsComponent(Type type)
+ {
+ return type == typeof(Component);
+ }
+ }
+}
+
+public class when_the_automapper_is_told_to_map_an_entity_and_a_component_that_has_an_associated_ComponentMap
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(
+ new StubTypeSource(typeof(Entity), typeof(Component)),
+ new TestConfiguration())
+ .AddMappingsFromSource(new StubTypeSource(typeof(CompMap)));
+
+ Because of = () =>
+ mappings = mapper.BuildMappings()
+ .SelectMany(x => x.Classes);
+
+ It should_map_the_entity = () =>
+ mappings.ShouldContain(x => x.Type == typeof(Entity));
+
+ It should_not_map_the_component_as_an_entity = () =>
+ mappings.ShouldNotContain(x => x.Type == typeof(Component));
+
+ It should_map_the_component_as_a_component_of_the_entity = () =>
+ mappings.Single(x => x.Type == typeof(Entity))
+ .Components.ShouldContain(x => x.Type == typeof(Component));
+
+ It should_use_the_component_map_for_mapping = () =>
+ mappings.Single().Components.Single().Access.Should().Be("none");
+
+ static AutoPersistenceModel mapper;
+ static IEnumerable mappings;
+
+ class TestConfiguration : DefaultAutomappingConfiguration
+ {
+ public override bool IsComponent(Type type)
+ {
+ return type == typeof(Component);
+ }
+ }
+
+ class CompMap : ComponentMap
+ {
+ public CompMap()
+ {
+ Access.None();
+ }
+ }
+}
+
+public class when_the_automapper_maps_nested_comonents
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(
+ new StubTypeSource(typeof(Entity1), typeof(Location), typeof(FormatA), typeof(FormatB)),
+ new TestConfiguration());
+
+ Because of = () =>
+ mapping = mapper.BuildMappingFor();
+
+ It should_prefix_the_components_in_the_entity = () =>
+ mapping.Components
+ .SelectMany(x => x.Properties)
+ .SelectMany(x => x.Columns)
+ .Select(x => x.Name)
+ .Should().Contain(new string[] { "LeftLocationProperty", "RightLocationProperty" });
+
+ It should_prefix_the_components_in_the_components = () =>
+ mapping.Components
+ .SelectMany(x => x.Components)
+ .SelectMany(x => x.Properties)
+ .SelectMany(x => x.Columns)
+ .Select(x => x.Name)
+ .Should().Contain(new string[] { "LeftAPropertyA", "LeftBPropertyB", "RightAPropertyA", "RightBPropertyB" });
+
+ static AutoPersistenceModel mapper;
+ static ClassMapping mapping;
+
+ class TestConfiguration : DefaultAutomappingConfiguration
+ {
+ public override bool IsComponent(Type type)
+ {
+ return type.In(typeof(Location), typeof(FormatA), typeof(FormatB));
+ }
+ }
+}
+
+public class Entity1
+{
+ public int Id { get; set; }
+ public Location Left { get; set; }
+ public Location Right { get; set; }
+}
+
+public class Location
+{
+ public string LocationProperty { get; set; }
+ public FormatA A { get; set; }
+ public FormatB B { get; set; }
+}
+
+public class FormatA
+{
+ public string PropertyA { get; set; }
+}
+
+public class FormatB
+{
+ public string PropertyB { get; set; }
}
diff --git a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.ElementCollections.cs b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.ElementCollections.cs
index 0adb7aebe..44f6ddb89 100644
--- a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.ElementCollections.cs
+++ b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.ElementCollections.cs
@@ -1,193 +1,193 @@
-using System.Linq;
-using FluentNHibernate.Automapping;
-using FluentNHibernate.Automapping.Steps;
-using FluentNHibernate.MappingModel;
-using FluentNHibernate.MappingModel.ClassBased;
-using FluentNHibernate.MappingModel.Collections;
-using FluentNHibernate.Specs.Automapping.Fixtures;
-using Machine.Specifications;
-using FluentAssertions;
-
-namespace FluentNHibernate.Specs.Automapping;
-
-public class when_the_automapper_is_asked_if_it_can_map_a_list_of_strings : AutoMapOneToManyVisitSpec
-{
- Because of = () =>
- maps_property = step.ShouldMap(FakeMembers.IListOfStrings);
-
- It should_accept_the_property = () =>
- maps_property.Should().BeTrue();
-
- static bool maps_property;
-}
-
-public class when_the_automapper_is_asked_if_it_can_map_a_list_of_ints : AutoMapOneToManyVisitSpec
-{
- Because of = () =>
- maps_property = step.ShouldMap(FakeMembers.IListOfInts);
-
- It should_accept_the_property = () =>
- maps_property.Should().BeTrue();
-
- static bool maps_property;
-}
-
-public class when_the_automapper_is_asked_if_it_can_map_a_list_of_doubles : AutoMapOneToManyVisitSpec
-{
- Because of = () =>
- maps_property = step.ShouldMap(FakeMembers.IListOfDoubles);
-
- It should_accept_the_property = () =>
- maps_property.Should().BeTrue();
-
- static bool maps_property;
-}
-
-public class when_the_automapper_is_asked_if_it_can_map_a_list_of_shorts : AutoMapOneToManyVisitSpec
-{
- Because of = () =>
- maps_property = step.ShouldMap(FakeMembers.IListOfShorts);
-
- It should_accept_the_property = () =>
- maps_property.Should().BeTrue();
-
- static bool maps_property;
-}
-
-public class when_the_automapper_is_asked_if_it_can_map_a_list_of_longs : AutoMapOneToManyVisitSpec
-{
- Because of = () =>
- maps_property = step.ShouldMap(FakeMembers.IListOfLongs);
-
- It should_accept_the_property = () =>
- maps_property.Should().BeTrue();
-
- static bool maps_property;
-}
-
-public class when_the_automapper_is_asked_if_it_can_map_a_list_of_floats : AutoMapOneToManyVisitSpec
-{
- Because of = () =>
- maps_property = step.ShouldMap(FakeMembers.IListOfFloats);
-
- It should_accept_the_property = () =>
- maps_property.Should().BeTrue();
-
- static bool maps_property;
-}
-
-public class when_the_automapper_is_asked_if_it_can_map_a_list_of_bools : AutoMapOneToManyVisitSpec
-{
- Because of = () =>
- maps_property = step.ShouldMap(FakeMembers.IListOfBools);
-
- It should_accept_the_property = () =>
- maps_property.Should().BeTrue();
-
- static bool maps_property;
-}
-
-public class when_the_automapper_is_asked_if_it_can_map_a_list_of_DateTimes : AutoMapOneToManyVisitSpec
-{
- Because of = () =>
- maps_property = step.ShouldMap(FakeMembers.IListOfDateTimes);
-
- It should_accept_the_property = () =>
- maps_property.Should().BeTrue();
-
- static bool maps_property;
-}
-
-public class when_the_automapper_is_told_to_map_a_list_of_simple_types_with_a_custom_column_defined : AutoMapOneToManySpec
-{
- Establish context = () =>
- cfg.FixedSimpleTypeCollectionValueColumn = "custom_column";
-
- Because of = () =>
- step.Map(container, FakeMembers.IListOfStrings);
-
- It should_create_use_the_element_column_name_defined_in_the_expressions = () =>
- container.Collections.Single().Element.Columns.Single().Name.Should().Be("custom_column");
-}
-
-public class when_the_automapper_is_told_to_map_a_list_of_simple_types : AutoMapOneToManySpec
-{
- Because of = () =>
- step.Map(container, FakeMembers.IListOfStrings);
-
- It should_create_a_collection = () =>
- container.Collections.Count().Should().Be(1);
-
- It should_create_a_collection_that_s_a_bag = () =>
- container.Collections.Single().Collection.Should().Be(Collection.Bag);
-
- It should_create_an_element_for_the_collection = () =>
- container.Collections.Single().Element.Should().NotBeNull();
-
- It should_use_the_default_element_column = () =>
- container.Collections.Single().Element.Columns.Single().Name.Should().Be("Value");
-
- It should_set_the_element_type_to_the_first_generic_argument_of_the_collection_type = () =>
- container.Collections.Single().Element.Type.Should().Be(new TypeReference(typeof(string)));
-
- It should_create_a_key = () =>
- container.Collections.Single().Key.Should().NotBeNull();
-
- It should_set_the_key_s_containing_entity_to_the_type_owning_the_property = () =>
- container.Collections.Single().Key.ContainingEntityType.Should().Be(FakeMembers.Type);
-
- It should_create_a_column_for_the_key_with_the_default_id_naming = () =>
- container.Collections.Single().Key.Columns.Single().Name.Should().Be("Target_id");
-
- It should_set_the_collection_s_containing_entity_type_to_the_type_owning_the_property = () =>
- container.Collections.Single().ContainingEntityType.Should().Be(FakeMembers.Type);
-
- It should_set_the_collection_s_member_to_the_property = () =>
- container.Collections.Single().Member.Should().Be(FakeMembers.IListOfStrings);
-
- It should_set_the_collection_s_name_to_the_property_name = () =>
- container.Collections.Single().Name.Should().Be(FakeMembers.IListOfStrings.Name);
-
- It should_not_create_a_relationship_for_the_collection = () =>
- container.Collections.Single().Relationship.Should().BeNull();
-
- It should_not_create_a_component_for_the_collection = () =>
- container.Collections.Single().CompositeElement.Should().BeNull();
-}
-
-public abstract class AutoMapOneToManySpec
-{
- Establish context = () =>
- {
- cfg = new TestConfiguration();
- step = new HasManyStep(cfg);
- container = new ClassMapping();
- container.Set(x => x.Type, Layer.Defaults, FakeMembers.Type);
- };
-
- protected static HasManyStep step;
- protected static ClassMapping container;
- protected static TestConfiguration cfg;
-
- protected class TestConfiguration : DefaultAutomappingConfiguration
- {
- public override string SimpleTypeCollectionValueColumn(Member member)
- {
- return FixedSimpleTypeCollectionValueColumn ?? base.SimpleTypeCollectionValueColumn(member);
- }
-
- public string FixedSimpleTypeCollectionValueColumn { get; set; }
- }
-}
-
-public abstract class AutoMapOneToManyVisitSpec
-{
- Establish context = () =>
- {
- cfg = new DefaultAutomappingConfiguration();
- step = new SimpleTypeCollectionStep(cfg);
- };
-
- protected static SimpleTypeCollectionStep step;
- protected static IAutomappingConfiguration cfg;
+using System.Linq;
+using FluentNHibernate.Automapping;
+using FluentNHibernate.Automapping.Steps;
+using FluentNHibernate.MappingModel;
+using FluentNHibernate.MappingModel.ClassBased;
+using FluentNHibernate.MappingModel.Collections;
+using FluentNHibernate.Specs.Automapping.Fixtures;
+using Machine.Specifications;
+using FluentAssertions;
+
+namespace FluentNHibernate.Specs.Automapping;
+
+public class when_the_automapper_is_asked_if_it_can_map_a_list_of_strings : AutoMapOneToManyVisitSpec
+{
+ Because of = () =>
+ maps_property = step.ShouldMap(FakeMembers.IListOfStrings);
+
+ It should_accept_the_property = () =>
+ maps_property.Should().BeTrue();
+
+ static bool maps_property;
+}
+
+public class when_the_automapper_is_asked_if_it_can_map_a_list_of_ints : AutoMapOneToManyVisitSpec
+{
+ Because of = () =>
+ maps_property = step.ShouldMap(FakeMembers.IListOfInts);
+
+ It should_accept_the_property = () =>
+ maps_property.Should().BeTrue();
+
+ static bool maps_property;
+}
+
+public class when_the_automapper_is_asked_if_it_can_map_a_list_of_doubles : AutoMapOneToManyVisitSpec
+{
+ Because of = () =>
+ maps_property = step.ShouldMap(FakeMembers.IListOfDoubles);
+
+ It should_accept_the_property = () =>
+ maps_property.Should().BeTrue();
+
+ static bool maps_property;
+}
+
+public class when_the_automapper_is_asked_if_it_can_map_a_list_of_shorts : AutoMapOneToManyVisitSpec
+{
+ Because of = () =>
+ maps_property = step.ShouldMap(FakeMembers.IListOfShorts);
+
+ It should_accept_the_property = () =>
+ maps_property.Should().BeTrue();
+
+ static bool maps_property;
+}
+
+public class when_the_automapper_is_asked_if_it_can_map_a_list_of_longs : AutoMapOneToManyVisitSpec
+{
+ Because of = () =>
+ maps_property = step.ShouldMap(FakeMembers.IListOfLongs);
+
+ It should_accept_the_property = () =>
+ maps_property.Should().BeTrue();
+
+ static bool maps_property;
+}
+
+public class when_the_automapper_is_asked_if_it_can_map_a_list_of_floats : AutoMapOneToManyVisitSpec
+{
+ Because of = () =>
+ maps_property = step.ShouldMap(FakeMembers.IListOfFloats);
+
+ It should_accept_the_property = () =>
+ maps_property.Should().BeTrue();
+
+ static bool maps_property;
+}
+
+public class when_the_automapper_is_asked_if_it_can_map_a_list_of_bools : AutoMapOneToManyVisitSpec
+{
+ Because of = () =>
+ maps_property = step.ShouldMap(FakeMembers.IListOfBools);
+
+ It should_accept_the_property = () =>
+ maps_property.Should().BeTrue();
+
+ static bool maps_property;
+}
+
+public class when_the_automapper_is_asked_if_it_can_map_a_list_of_DateTimes : AutoMapOneToManyVisitSpec
+{
+ Because of = () =>
+ maps_property = step.ShouldMap(FakeMembers.IListOfDateTimes);
+
+ It should_accept_the_property = () =>
+ maps_property.Should().BeTrue();
+
+ static bool maps_property;
+}
+
+public class when_the_automapper_is_told_to_map_a_list_of_simple_types_with_a_custom_column_defined : AutoMapOneToManySpec
+{
+ Establish context = () =>
+ cfg.FixedSimpleTypeCollectionValueColumn = "custom_column";
+
+ Because of = () =>
+ step.Map(container, FakeMembers.IListOfStrings);
+
+ It should_create_use_the_element_column_name_defined_in_the_expressions = () =>
+ container.Collections.Single().Element.Columns.Single().Name.Should().Be("custom_column");
+}
+
+public class when_the_automapper_is_told_to_map_a_list_of_simple_types : AutoMapOneToManySpec
+{
+ Because of = () =>
+ step.Map(container, FakeMembers.IListOfStrings);
+
+ It should_create_a_collection = () =>
+ container.Collections.Count().Should().Be(1);
+
+ It should_create_a_collection_that_s_a_bag = () =>
+ container.Collections.Single().Collection.Should().Be(Collection.Bag);
+
+ It should_create_an_element_for_the_collection = () =>
+ container.Collections.Single().Element.Should().NotBeNull();
+
+ It should_use_the_default_element_column = () =>
+ container.Collections.Single().Element.Columns.Single().Name.Should().Be("Value");
+
+ It should_set_the_element_type_to_the_first_generic_argument_of_the_collection_type = () =>
+ container.Collections.Single().Element.Type.Should().Be(new TypeReference(typeof(string)));
+
+ It should_create_a_key = () =>
+ container.Collections.Single().Key.Should().NotBeNull();
+
+ It should_set_the_key_s_containing_entity_to_the_type_owning_the_property = () =>
+ container.Collections.Single().Key.ContainingEntityType.Should().Be(FakeMembers.Type);
+
+ It should_create_a_column_for_the_key_with_the_default_id_naming = () =>
+ container.Collections.Single().Key.Columns.Single().Name.Should().Be("Target_id");
+
+ It should_set_the_collection_s_containing_entity_type_to_the_type_owning_the_property = () =>
+ container.Collections.Single().ContainingEntityType.Should().Be(FakeMembers.Type);
+
+ It should_set_the_collection_s_member_to_the_property = () =>
+ container.Collections.Single().Member.Should().Be(FakeMembers.IListOfStrings);
+
+ It should_set_the_collection_s_name_to_the_property_name = () =>
+ container.Collections.Single().Name.Should().Be(FakeMembers.IListOfStrings.Name);
+
+ It should_not_create_a_relationship_for_the_collection = () =>
+ container.Collections.Single().Relationship.Should().BeNull();
+
+ It should_not_create_a_component_for_the_collection = () =>
+ container.Collections.Single().CompositeElement.Should().BeNull();
+}
+
+public abstract class AutoMapOneToManySpec
+{
+ Establish context = () =>
+ {
+ cfg = new TestConfiguration();
+ step = new HasManyStep(cfg);
+ container = new ClassMapping();
+ container.Set(x => x.Type, Layer.Defaults, FakeMembers.Type);
+ };
+
+ protected static HasManyStep step;
+ protected static ClassMapping container;
+ protected static TestConfiguration cfg;
+
+ protected class TestConfiguration : DefaultAutomappingConfiguration
+ {
+ public override string SimpleTypeCollectionValueColumn(Member member)
+ {
+ return FixedSimpleTypeCollectionValueColumn ?? base.SimpleTypeCollectionValueColumn(member);
+ }
+
+ public string FixedSimpleTypeCollectionValueColumn { get; set; }
+ }
+}
+
+public abstract class AutoMapOneToManyVisitSpec
+{
+ Establish context = () =>
+ {
+ cfg = new DefaultAutomappingConfiguration();
+ step = new SimpleTypeCollectionStep(cfg);
+ };
+
+ protected static SimpleTypeCollectionStep step;
+ protected static IAutomappingConfiguration cfg;
}
diff --git a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.NestedClasses.cs b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.NestedClasses.cs
index 59b4ff9ec..271706399 100644
--- a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.NestedClasses.cs
+++ b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.NestedClasses.cs
@@ -1,99 +1,99 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using FluentNHibernate.Automapping;
-using FluentNHibernate.MappingModel.ClassBased;
-using FluentNHibernate.Specs.Automapping.Fixtures;
-using Machine.Specifications;
-
-namespace FluentNHibernate.Specs.Automapping;
-
-public class when_the_automapper_is_told_to_map_an_entity_with_a_nested_entity
-{
- Establish context = () =>
- mapper = AutoMap.Source(
- new StubTypeSource(typeof(Order), typeof(Order.OrderLine)));
-
- Because of = () =>
- mappings = mapper.BuildMappings()
- .SelectMany(x => x.Classes);
-
- It should_map_the_entity = () =>
- mappings.ShouldContain(x => x.Type == typeof(Order));
-
- It should_automap_the_nested_entity_per_default = () =>
- mappings.ShouldContain(x => x.Type == typeof(Order.OrderLine));
-
- static AutoPersistenceModel mapper;
- static IEnumerable mappings;
-}
-
-public class when_changing_the_behaviour_of_automapping_configuration_to_also_map_nested_entities
-{
- Establish context = () =>
- mapper = AutoMap.Source(
- new StubTypeSource(typeof(Order), typeof(Order.OrderLine)), new TestConfiguration());
-
- Because of = () =>
- mappings = mapper.BuildMappings()
- .SelectMany(x => x.Classes);
-
- It should_map_the_entity = () =>
- mappings.ShouldContain(x => x.Type == typeof(Order));
-
- It should_automap_the_nested_entity = () =>
- mappings.ShouldContain(x => x.Type == typeof(Order.OrderLine));
-
- static AutoPersistenceModel mapper;
- static IEnumerable mappings;
-
- class TestConfiguration : DefaultAutomappingConfiguration
- {
- public override bool ShouldMap(Type type)
- {
- return base.ShouldMap(type) || type.IsNested;
- }
- }
-}
-
-public class when_automapper_is_told_to_map_a_class_with_a_nested_classes
-{
- Establish context = () =>
- {
- nonPublicNestedType = typeof(PersonCard).GetNestedTypes(BindingFlags.NonPublic).Single();
- model = AutoMap.Source(new StubTypeSource(typeof(PersonCard), typeof(PersonCard.PublicAddress), nonPublicNestedType));
- };
-
- Because of = () => mappings = model.BuildMappings().SelectMany(m => m.Classes);
- It should_map_the_main_class = () => mappings.ShouldContain(m => m.Type == typeof(PersonCard));
- It should_map_public_nested_class = () => mappings.ShouldContain(m => m.Type == typeof(PersonCard.PublicAddress));
- It should_not_map_non_public_nested_class = () => mappings.ShouldNotContain(m => m.Type == nonPublicNestedType);
-
- static AutoPersistenceModel model;
- static DefaultAutomappingConfiguration configuration;
- static Type nonPublicNestedType;
- static IEnumerable mappings;
-}
-
-public class PersonCard
-{
- public int Id { get; set; }
- public class PublicAddress
- {
- public int Id { get; set; }
- }
- private class PrivateAddress
- {
- public int Id { get; set; }
- }
-}
-
-public class Order
-{
- public int Id { get; set; }
- public class OrderLine
- {
- public int Id { get; set; }
- }
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using FluentNHibernate.Automapping;
+using FluentNHibernate.MappingModel.ClassBased;
+using FluentNHibernate.Specs.Automapping.Fixtures;
+using Machine.Specifications;
+
+namespace FluentNHibernate.Specs.Automapping;
+
+public class when_the_automapper_is_told_to_map_an_entity_with_a_nested_entity
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(
+ new StubTypeSource(typeof(Order), typeof(Order.OrderLine)));
+
+ Because of = () =>
+ mappings = mapper.BuildMappings()
+ .SelectMany(x => x.Classes);
+
+ It should_map_the_entity = () =>
+ mappings.ShouldContain(x => x.Type == typeof(Order));
+
+ It should_automap_the_nested_entity_per_default = () =>
+ mappings.ShouldContain(x => x.Type == typeof(Order.OrderLine));
+
+ static AutoPersistenceModel mapper;
+ static IEnumerable mappings;
+}
+
+public class when_changing_the_behaviour_of_automapping_configuration_to_also_map_nested_entities
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(
+ new StubTypeSource(typeof(Order), typeof(Order.OrderLine)), new TestConfiguration());
+
+ Because of = () =>
+ mappings = mapper.BuildMappings()
+ .SelectMany(x => x.Classes);
+
+ It should_map_the_entity = () =>
+ mappings.ShouldContain(x => x.Type == typeof(Order));
+
+ It should_automap_the_nested_entity = () =>
+ mappings.ShouldContain(x => x.Type == typeof(Order.OrderLine));
+
+ static AutoPersistenceModel mapper;
+ static IEnumerable mappings;
+
+ class TestConfiguration : DefaultAutomappingConfiguration
+ {
+ public override bool ShouldMap(Type type)
+ {
+ return base.ShouldMap(type) || type.IsNested;
+ }
+ }
+}
+
+public class when_automapper_is_told_to_map_a_class_with_a_nested_classes
+{
+ Establish context = () =>
+ {
+ nonPublicNestedType = typeof(PersonCard).GetNestedTypes(BindingFlags.NonPublic).Single();
+ model = AutoMap.Source(new StubTypeSource(typeof(PersonCard), typeof(PersonCard.PublicAddress), nonPublicNestedType));
+ };
+
+ Because of = () => mappings = model.BuildMappings().SelectMany(m => m.Classes);
+ It should_map_the_main_class = () => mappings.ShouldContain(m => m.Type == typeof(PersonCard));
+ It should_map_public_nested_class = () => mappings.ShouldContain(m => m.Type == typeof(PersonCard.PublicAddress));
+ It should_not_map_non_public_nested_class = () => mappings.ShouldNotContain(m => m.Type == nonPublicNestedType);
+
+ static AutoPersistenceModel model;
+ static DefaultAutomappingConfiguration configuration;
+ static Type nonPublicNestedType;
+ static IEnumerable mappings;
+}
+
+public class PersonCard
+{
+ public int Id { get; set; }
+ public class PublicAddress
+ {
+ public int Id { get; set; }
+ }
+ private class PrivateAddress
+ {
+ public int Id { get; set; }
+ }
+}
+
+public class Order
+{
+ public int Id { get; set; }
+ public class OrderLine
+ {
+ public int Id { get; set; }
+ }
}
diff --git a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Properties.Enum.cs b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Properties.Enum.cs
index 84465c8b5..8fcda2beb 100644
--- a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Properties.Enum.cs
+++ b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Properties.Enum.cs
@@ -1,80 +1,80 @@
-using System.Linq;
-using FluentNHibernate.Automapping;
-using FluentNHibernate.MappingModel.ClassBased;
-using FluentNHibernate.Specs.Automapping.Fixtures;
-using Machine.Specifications;
-using FluentAssertions;
-using NHibernate.Type;
-
-namespace FluentNHibernate.Specs.Automapping;
-
-public class when_the_automapper_is_told_to_map_an_entity_with_static_properties
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(EntityWithStaticProperties)));
-
- Because of = () =>
- mapping = mapper.BuildMappings().SelectMany(x => x.Classes).First();
-
- It should_not_create_property_mappings_for_the_static_properties = () =>
- mapping.Properties.Any(x => x.Name == "StaticProperty").Should().BeFalse();
-
- static AutoPersistenceModel mapper;
- static ClassMapping mapping;
-}
-
-public class when_the_automapper_is_told_to_map_an_entity_with_a_enum_property : AutomapperEnumPropertySpec
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(Target)));
-
- Because of = () =>
- mapping = mapper.BuildMappings().SelectMany(x => x.Classes).First();
-
- It should_create_a_property_mapping_for_the_property = () =>
- mapping.Properties.ShouldContain(x => x.Name == "EnumProperty");
-
- It should_use_the_enum_string_type_for_the_property = () =>
- mapping.Properties.First().Type.GetUnderlyingSystemType().Should().Be(typeof(EnumStringType));
-
- It should_create_a_column_for_the_property_mapping_with_the_property_name = () =>
- mapping.Properties.First().Columns.ShouldContain(x => x.Name == "EnumProperty");
-}
-
-public class when_the_automapper_is_told_to_map_an_entity_with_a_nullable_enum_property : AutomapperEnumPropertySpec
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(NullableTarget)));
-
- Because of = () =>
- mapping = mapper.BuildMappings().SelectMany(x => x.Classes).First();
-
- It should_create_a_property_mapping_for_the_property = () =>
- mapping.Properties.ShouldContain(x => x.Name == "EnumProperty");
-
- It should_use_the_enum_string_mapper_for_the_property = () =>
- mapping.Properties.First().Type.GetUnderlyingSystemType().Should().Be(typeof(EnumStringType));
-
- It should_create_a_column_for_the_property_mapping_with_the_property_name = () =>
- mapping.Properties.First().Columns.ShouldContain(x => x.Name == "EnumProperty");
-}
-
-class Target
-{
- public int Id { get; set; }
- public Enum EnumProperty { get; set; }
-}
-
-class NullableTarget
-{
- public int Id { get; set; }
- public Enum? EnumProperty { get; set; }
-}
-
-enum Enum { }
-
-public abstract class AutomapperEnumPropertySpec
-{
- protected static AutoPersistenceModel mapper;
- protected static ClassMapping mapping;
+using System.Linq;
+using FluentNHibernate.Automapping;
+using FluentNHibernate.MappingModel.ClassBased;
+using FluentNHibernate.Specs.Automapping.Fixtures;
+using Machine.Specifications;
+using FluentAssertions;
+using NHibernate.Type;
+
+namespace FluentNHibernate.Specs.Automapping;
+
+public class when_the_automapper_is_told_to_map_an_entity_with_static_properties
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(EntityWithStaticProperties)));
+
+ Because of = () =>
+ mapping = mapper.BuildMappings().SelectMany(x => x.Classes).First();
+
+ It should_not_create_property_mappings_for_the_static_properties = () =>
+ mapping.Properties.Any(x => x.Name == "StaticProperty").Should().BeFalse();
+
+ static AutoPersistenceModel mapper;
+ static ClassMapping mapping;
+}
+
+public class when_the_automapper_is_told_to_map_an_entity_with_a_enum_property : AutomapperEnumPropertySpec
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(Target)));
+
+ Because of = () =>
+ mapping = mapper.BuildMappings().SelectMany(x => x.Classes).First();
+
+ It should_create_a_property_mapping_for_the_property = () =>
+ mapping.Properties.ShouldContain(x => x.Name == "EnumProperty");
+
+ It should_use_the_enum_string_type_for_the_property = () =>
+ mapping.Properties.First().Type.GetUnderlyingSystemType().Should().Be(typeof(EnumStringType));
+
+ It should_create_a_column_for_the_property_mapping_with_the_property_name = () =>
+ mapping.Properties.First().Columns.ShouldContain(x => x.Name == "EnumProperty");
+}
+
+public class when_the_automapper_is_told_to_map_an_entity_with_a_nullable_enum_property : AutomapperEnumPropertySpec
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(NullableTarget)));
+
+ Because of = () =>
+ mapping = mapper.BuildMappings().SelectMany(x => x.Classes).First();
+
+ It should_create_a_property_mapping_for_the_property = () =>
+ mapping.Properties.ShouldContain(x => x.Name == "EnumProperty");
+
+ It should_use_the_enum_string_mapper_for_the_property = () =>
+ mapping.Properties.First().Type.GetUnderlyingSystemType().Should().Be(typeof(EnumStringType));
+
+ It should_create_a_column_for_the_property_mapping_with_the_property_name = () =>
+ mapping.Properties.First().Columns.ShouldContain(x => x.Name == "EnumProperty");
+}
+
+class Target
+{
+ public int Id { get; set; }
+ public Enum EnumProperty { get; set; }
+}
+
+class NullableTarget
+{
+ public int Id { get; set; }
+ public Enum? EnumProperty { get; set; }
+}
+
+enum Enum { }
+
+public abstract class AutomapperEnumPropertySpec
+{
+ protected static AutoPersistenceModel mapper;
+ protected static ClassMapping mapping;
}
diff --git a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Relationships.cs b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Relationships.cs
index fdee055db..723acd31d 100644
--- a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Relationships.cs
+++ b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Relationships.cs
@@ -1,224 +1,224 @@
-using System;
-using System.Linq;
-using FluentNHibernate.Automapping;
-using FluentNHibernate.Conventions;
-using FluentNHibernate.Conventions.Instances;
-using FluentNHibernate.Mapping;
-using FluentNHibernate.MappingModel.ClassBased;
-using FluentNHibernate.MappingModel.Collections;
-using FluentNHibernate.Specs.Automapping.Fixtures;
-using Machine.Specifications;
-using FluentAssertions;
-
-namespace FluentNHibernate.Specs.Automapping;
-
-public class when_the_automapper_is_told_to_map_a_class_with_a_self_referencing_collection
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(SelfReferencingCollectionEntity)));
-
- Because of = () =>
- mapping = mapper.BuildMappingFor();
-
- It should_have_one_collection = () =>
- mapping.Collections.Should().NotBeEmpty();
-
- It should_have_it_s_own_type_for_the_collection_child_type = () =>
- mapping.Collections.Single().ChildType.Should().Be(typeof(SelfReferencingCollectionEntity));
-
- It should_have_the_property_name_for_the_collection_name = () =>
- mapping.Collections.Single().Name.Should().Be("Children");
-
- It should_have_a_one_to_many_collection = () =>
- mapping.Collections.Single().Relationship.Should().BeOfType();
-
- static AutoPersistenceModel mapper;
- static ClassMapping mapping;
-}
-
-public class when_the_automapper_is_told_to_map_a_class_with_a_self_reference
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(SelfReferenceEntity)));
-
- Because of = () =>
- mapping = mapper.BuildMappingFor();
-
- It should_have_one_reference = () =>
- mapping.References.Should().NotBeEmpty();
-
- It should_have_it_s_own_type_for_the_reference_type = () =>
- mapping.References.Single().Class.GetUnderlyingSystemType().Should().Be(typeof(SelfReferenceEntity));
-
- It should_have_the_property_name_for_the_reference_name = () =>
- mapping.References.Single().Name.Should().Be("Parent");
-
- static AutoPersistenceModel mapper;
- static ClassMapping mapping;
-}
-
-public class when_the_automapper_is_told_to_map_a_class_with_a_self_reference_and_a_self_referencing_collection
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(ParentChildSelfReferenceEntity)));
-
- Because of = () =>
- mapping = mapper.BuildMappingFor();
-
- It should_have_one_collection = () =>
- mapping.Collections.Should().NotBeEmpty();
-
- It should_have_it_s_own_type_for_the_collection_child_type = () =>
- mapping.Collections.Single().ChildType.Should().Be(typeof(ParentChildSelfReferenceEntity));
-
- It should_have_the_property_name_for_the_collection_name = () =>
- mapping.Collections.Single().Name.Should().Be("Children");
-
- It should_have_a_one_to_many_collection = () =>
- mapping.Collections.Single().Relationship.Should().BeOfType();
-
- It should_have_the_correct_collection_key_column = () =>
- mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("Parent_id");
-
- It should_have_one_reference = () =>
- mapping.References.Should().NotBeEmpty();
-
- It should_have_it_s_own_type_for_the_reference_type = () =>
- mapping.References.Single().Class.GetUnderlyingSystemType().Should().Be(typeof(ParentChildSelfReferenceEntity));
-
- It should_have_the_property_name_for_the_reference_name = () =>
- mapping.References.Single().Name.Should().Be("Parent");
-
- It should_have_the_correct_reference_key_column = () =>
- mapping.References.Single().Columns.Single().Name.Should().Be("Parent_id");
-
- static AutoPersistenceModel mapper;
- static ClassMapping mapping;
-}
-
-public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_with_a_backing_field
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity)));
-
- Because of = () =>
- mapping = mapper.BuildMappingFor();
-
- It should_map_the_read_only_property_collection = () =>
- mapping.Collections.Select(x => x.Name).Should().Contain("BackingFieldCollection");
-
- It should_map_the_property_using_property_through_field_access_strategy = () =>
- mapping.Collections.First(x => x.Name == "BackingFieldCollection").Access.Should().Be("nosetter.camelcase");
-
- static AutoPersistenceModel mapper;
- static ClassMapping mapping;
-}
-
-public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_with_a_backing_field_with_a_convention_which_changes_the_access_strategy
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity)))
- .Conventions.Add();
-
- Because of = () =>
- mapping = mapper.BuildMappingFor();
-
- It should_map_the_read_only_property_collection = () =>
- mapping.Collections.Select(x => x.Name).Should().Contain("BackingFieldCollection");
-
- It should_map_the_property_using_property_through_field_access_strategy = () =>
- mapping.Collections.First(x => x.Name == "BackingFieldCollection").Access.Should().Be("property");
-
- static AutoPersistenceModel mapper;
- static ClassMapping mapping;
-
- class Convention : IHasManyConvention
- {
- public void Apply(IOneToManyCollectionInstance instance)
- {
- instance.Access.Property();
- }
- }
-}
-
-public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_with_a_backing_field_with_an_overridden_configuration
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity)), new TestConfiguration());
-
- Because of = () =>
- mapping = mapper.BuildMappingFor();
-
- It should_map_the_property_using_the_access_strategy_from_the_configuration = () =>
- mapping.Collections.First(x => x.Name == "BackingFieldCollection").Access.Should().Be("noop");
-
- static AutoPersistenceModel mapper;
- static ClassMapping mapping;
-
- class TestConfiguration : DefaultAutomappingConfiguration
- {
- public override Access GetAccessStrategyForReadOnlyProperty(Member member)
- {
- return Access.NoOp;
- }
- }
-}
-
-public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_autoproperty
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity)));
-
- Because of = () =>
- mapping = mapper.BuildMappingFor();
-
- It should_map_the_read_only_property_collection = () =>
- mapping.Collections.Select(x => x.Name).Should().Contain("AutoPropertyCollection");
-
- It should_map_the_property_using_backfield_access_strategy = () =>
- mapping.Collections.First(x => x.Name == "AutoPropertyCollection").Access.Should().Be("backfield");
-
- static AutoPersistenceModel mapper;
- static ClassMapping mapping;
-}
-
-public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_autoproperty_with_an_overridden_configuration
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity)), new TestConfiguration());
-
- Because of = () =>
- mapping = mapper.BuildMappingFor();
-
- It should_map_the_property_using_the_access_strategy_from_the_configuration = () =>
- mapping.Collections.First(x => x.Name == "AutoPropertyCollection").Access.Should().Be("noop");
-
- static AutoPersistenceModel mapper;
- static ClassMapping mapping;
-
- class TestConfiguration : DefaultAutomappingConfiguration
- {
- public override Access GetAccessStrategyForReadOnlyProperty(Member member)
- {
- return Access.NoOp;
- }
- }
-}
-
-public class when_automapping_an_entity_with_dictionary_properties
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(DictionaryEntity)));
-
- Because of = () =>
- mapping = mapper.BuildMappingFor();
-
- It should_not_map_the_non_generic_dictionary = () =>
- mapping.Collections.Select(x => x.Name).Should().NotContain("Dictionary");
-
- It should_not_map_the_generic_dictionary = () =>
- mapping.Collections.Select(x => x.Name).Should().NotContain("GenericDictionary");
-
- static AutoPersistenceModel mapper;
- static ClassMapping mapping;
+using System;
+using System.Linq;
+using FluentNHibernate.Automapping;
+using FluentNHibernate.Conventions;
+using FluentNHibernate.Conventions.Instances;
+using FluentNHibernate.Mapping;
+using FluentNHibernate.MappingModel.ClassBased;
+using FluentNHibernate.MappingModel.Collections;
+using FluentNHibernate.Specs.Automapping.Fixtures;
+using Machine.Specifications;
+using FluentAssertions;
+
+namespace FluentNHibernate.Specs.Automapping;
+
+public class when_the_automapper_is_told_to_map_a_class_with_a_self_referencing_collection
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(SelfReferencingCollectionEntity)));
+
+ Because of = () =>
+ mapping = mapper.BuildMappingFor();
+
+ It should_have_one_collection = () =>
+ mapping.Collections.Should().NotBeEmpty();
+
+ It should_have_it_s_own_type_for_the_collection_child_type = () =>
+ mapping.Collections.Single().ChildType.Should().Be(typeof(SelfReferencingCollectionEntity));
+
+ It should_have_the_property_name_for_the_collection_name = () =>
+ mapping.Collections.Single().Name.Should().Be("Children");
+
+ It should_have_a_one_to_many_collection = () =>
+ mapping.Collections.Single().Relationship.Should().BeOfType();
+
+ static AutoPersistenceModel mapper;
+ static ClassMapping mapping;
+}
+
+public class when_the_automapper_is_told_to_map_a_class_with_a_self_reference
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(SelfReferenceEntity)));
+
+ Because of = () =>
+ mapping = mapper.BuildMappingFor();
+
+ It should_have_one_reference = () =>
+ mapping.References.Should().NotBeEmpty();
+
+ It should_have_it_s_own_type_for_the_reference_type = () =>
+ mapping.References.Single().Class.GetUnderlyingSystemType().Should().Be(typeof(SelfReferenceEntity));
+
+ It should_have_the_property_name_for_the_reference_name = () =>
+ mapping.References.Single().Name.Should().Be("Parent");
+
+ static AutoPersistenceModel mapper;
+ static ClassMapping mapping;
+}
+
+public class when_the_automapper_is_told_to_map_a_class_with_a_self_reference_and_a_self_referencing_collection
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(ParentChildSelfReferenceEntity)));
+
+ Because of = () =>
+ mapping = mapper.BuildMappingFor();
+
+ It should_have_one_collection = () =>
+ mapping.Collections.Should().NotBeEmpty();
+
+ It should_have_it_s_own_type_for_the_collection_child_type = () =>
+ mapping.Collections.Single().ChildType.Should().Be(typeof(ParentChildSelfReferenceEntity));
+
+ It should_have_the_property_name_for_the_collection_name = () =>
+ mapping.Collections.Single().Name.Should().Be("Children");
+
+ It should_have_a_one_to_many_collection = () =>
+ mapping.Collections.Single().Relationship.Should().BeOfType();
+
+ It should_have_the_correct_collection_key_column = () =>
+ mapping.Collections.Single().Key.Columns.Single().Name.Should().Be("Parent_id");
+
+ It should_have_one_reference = () =>
+ mapping.References.Should().NotBeEmpty();
+
+ It should_have_it_s_own_type_for_the_reference_type = () =>
+ mapping.References.Single().Class.GetUnderlyingSystemType().Should().Be(typeof(ParentChildSelfReferenceEntity));
+
+ It should_have_the_property_name_for_the_reference_name = () =>
+ mapping.References.Single().Name.Should().Be("Parent");
+
+ It should_have_the_correct_reference_key_column = () =>
+ mapping.References.Single().Columns.Single().Name.Should().Be("Parent_id");
+
+ static AutoPersistenceModel mapper;
+ static ClassMapping mapping;
+}
+
+public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_with_a_backing_field
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity)));
+
+ Because of = () =>
+ mapping = mapper.BuildMappingFor();
+
+ It should_map_the_read_only_property_collection = () =>
+ mapping.Collections.Select(x => x.Name).Should().Contain("BackingFieldCollection");
+
+ It should_map_the_property_using_property_through_field_access_strategy = () =>
+ mapping.Collections.First(x => x.Name == "BackingFieldCollection").Access.Should().Be("nosetter.camelcase");
+
+ static AutoPersistenceModel mapper;
+ static ClassMapping mapping;
+}
+
+public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_with_a_backing_field_with_a_convention_which_changes_the_access_strategy
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity)))
+ .Conventions.Add();
+
+ Because of = () =>
+ mapping = mapper.BuildMappingFor();
+
+ It should_map_the_read_only_property_collection = () =>
+ mapping.Collections.Select(x => x.Name).Should().Contain("BackingFieldCollection");
+
+ It should_map_the_property_using_property_through_field_access_strategy = () =>
+ mapping.Collections.First(x => x.Name == "BackingFieldCollection").Access.Should().Be("property");
+
+ static AutoPersistenceModel mapper;
+ static ClassMapping mapping;
+
+ class Convention : IHasManyConvention
+ {
+ public void Apply(IOneToManyCollectionInstance instance)
+ {
+ instance.Access.Property();
+ }
+ }
+}
+
+public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_with_a_backing_field_with_an_overridden_configuration
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity)), new TestConfiguration());
+
+ Because of = () =>
+ mapping = mapper.BuildMappingFor();
+
+ It should_map_the_property_using_the_access_strategy_from_the_configuration = () =>
+ mapping.Collections.First(x => x.Name == "BackingFieldCollection").Access.Should().Be("noop");
+
+ static AutoPersistenceModel mapper;
+ static ClassMapping mapping;
+
+ class TestConfiguration : DefaultAutomappingConfiguration
+ {
+ public override Access GetAccessStrategyForReadOnlyProperty(Member member)
+ {
+ return Access.NoOp;
+ }
+ }
+}
+
+public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_autoproperty
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity)));
+
+ Because of = () =>
+ mapping = mapper.BuildMappingFor();
+
+ It should_map_the_read_only_property_collection = () =>
+ mapping.Collections.Select(x => x.Name).Should().Contain("AutoPropertyCollection");
+
+ It should_map_the_property_using_backfield_access_strategy = () =>
+ mapping.Collections.First(x => x.Name == "AutoPropertyCollection").Access.Should().Be("backfield");
+
+ static AutoPersistenceModel mapper;
+ static ClassMapping mapping;
+}
+
+public class when_the_automapper_is_told_to_map_an_entity_with_a_collection_exposed_as_a_read_only_enumerable_autoproperty_with_an_overridden_configuration
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(ReadOnlyEnumerableEntity)), new TestConfiguration());
+
+ Because of = () =>
+ mapping = mapper.BuildMappingFor();
+
+ It should_map_the_property_using_the_access_strategy_from_the_configuration = () =>
+ mapping.Collections.First(x => x.Name == "AutoPropertyCollection").Access.Should().Be("noop");
+
+ static AutoPersistenceModel mapper;
+ static ClassMapping mapping;
+
+ class TestConfiguration : DefaultAutomappingConfiguration
+ {
+ public override Access GetAccessStrategyForReadOnlyProperty(Member member)
+ {
+ return Access.NoOp;
+ }
+ }
+}
+
+public class when_automapping_an_entity_with_dictionary_properties
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(DictionaryEntity)));
+
+ Because of = () =>
+ mapping = mapper.BuildMappingFor();
+
+ It should_not_map_the_non_generic_dictionary = () =>
+ mapping.Collections.Select(x => x.Name).Should().NotContain("Dictionary");
+
+ It should_not_map_the_generic_dictionary = () =>
+ mapping.Collections.Select(x => x.Name).Should().NotContain("GenericDictionary");
+
+ static AutoPersistenceModel mapper;
+ static ClassMapping mapping;
}
diff --git a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Version.cs b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Version.cs
index 327794674..d03c51b4e 100644
--- a/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Version.cs
+++ b/src/FluentNHibernate.Specs/Automapping/AutomappingSpecs.Version.cs
@@ -1,57 +1,57 @@
-using System;
-using System.Linq;
-using FluentNHibernate.Automapping;
-using FluentNHibernate.Conventions;
-using FluentNHibernate.Conventions.Instances;
-using FluentNHibernate.Mapping;
-using FluentNHibernate.MappingModel.ClassBased;
-using FluentNHibernate.MappingModel.Collections;
-using FluentNHibernate.Specs.Automapping.Fixtures;
-using Machine.Specifications;
-using FluentAssertions;
-
-namespace FluentNHibernate.Specs.Automapping;
-
-public class when_the_automapper_is_told_to_map_a_class_with_a_version
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(VersionedEntity)));
-
- Because of = () =>
- mapping = mapper.BuildMappingFor();
-
- It should_have_a_version = () =>
- mapping.Version.Should().NotBeNull();
-
- It should_have_picked_the_right_property_to_be_the_version = () =>
- mapping.Version.Name.Should().Be("Timestamp");
-
- static AutoPersistenceModel mapper;
- static ClassMapping mapping;
-}
-
-public class when_the_automapper_is_told_to_map_a_class_with_a_custom_version_defined_in_config
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(VersionedEntity)), new TestConfig());
-
- Because of = () =>
- mapping = mapper.BuildMappingFor();
-
- It should_have_a_version = () =>
- mapping.Version.Should().NotBeNull();
-
- It should_have_picked_the_right_property_to_be_the_version = () =>
- mapping.Version.Name.Should().Be("AnUnobviousVersion");
-
- static AutoPersistenceModel mapper;
- static ClassMapping mapping;
-
- class TestConfig : DefaultAutomappingConfiguration
- {
- public override bool IsVersion(Member member)
- {
- return member.Name == "AnUnobviousVersion";
- }
- }
+using System;
+using System.Linq;
+using FluentNHibernate.Automapping;
+using FluentNHibernate.Conventions;
+using FluentNHibernate.Conventions.Instances;
+using FluentNHibernate.Mapping;
+using FluentNHibernate.MappingModel.ClassBased;
+using FluentNHibernate.MappingModel.Collections;
+using FluentNHibernate.Specs.Automapping.Fixtures;
+using Machine.Specifications;
+using FluentAssertions;
+
+namespace FluentNHibernate.Specs.Automapping;
+
+public class when_the_automapper_is_told_to_map_a_class_with_a_version
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(VersionedEntity)));
+
+ Because of = () =>
+ mapping = mapper.BuildMappingFor();
+
+ It should_have_a_version = () =>
+ mapping.Version.Should().NotBeNull();
+
+ It should_have_picked_the_right_property_to_be_the_version = () =>
+ mapping.Version.Name.Should().Be("Timestamp");
+
+ static AutoPersistenceModel mapper;
+ static ClassMapping mapping;
+}
+
+public class when_the_automapper_is_told_to_map_a_class_with_a_custom_version_defined_in_config
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(VersionedEntity)), new TestConfig());
+
+ Because of = () =>
+ mapping = mapper.BuildMappingFor();
+
+ It should_have_a_version = () =>
+ mapping.Version.Should().NotBeNull();
+
+ It should_have_picked_the_right_property_to_be_the_version = () =>
+ mapping.Version.Name.Should().Be("AnUnobviousVersion");
+
+ static AutoPersistenceModel mapper;
+ static ClassMapping mapping;
+
+ class TestConfig : DefaultAutomappingConfiguration
+ {
+ public override bool IsVersion(Member member)
+ {
+ return member.Name == "AnUnobviousVersion";
+ }
+ }
}
diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/AutomappingSpecExtensions.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/AutomappingSpecExtensions.cs
index 6a2e1b275..3325408fc 100644
--- a/src/FluentNHibernate.Specs/Automapping/Fixtures/AutomappingSpecExtensions.cs
+++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/AutomappingSpecExtensions.cs
@@ -1,112 +1,112 @@
-using System;
-using System.Linq;
-using System.Xml;
-using FluentNHibernate.Automapping;
-using FluentNHibernate.MappingModel;
-using FluentNHibernate.MappingModel.ClassBased;
-using FluentNHibernate.MappingModel.Output;
-using Machine.Specifications;
-
-namespace FluentNHibernate.Specs.Automapping.Fixtures;
-
-public static class AutomappingSpecExtensions
-{
- public static ClassMapping BuildMappingFor(this AutoPersistenceModel model)
- {
- return model.BuildMappings()
- .SelectMany(x => x.Classes)
- .FirstOrDefault(x => x.Type == typeof(T));
- }
-
- public static XmlDocument ToXml(this ClassMapping mapping)
- {
- var hbm = new HibernateMapping();
-
- hbm.AddClass(mapping);
-
- return new MappingXmlSerializer()
- .Serialize(hbm);
- }
-}
-
-public static class XmlTestExtensions
-{
- public static XmlElementTester Element(this XmlDocument doc, string path)
- {
- return new XmlElementTester(doc, path);
- }
-
- public class XmlElementTester
- {
- readonly XmlDocument doc;
- string currentPath;
- XmlElement currentElement;
-
- public XmlElementTester(XmlDocument doc, string path)
- {
- currentElement = (XmlElement)doc.DocumentElement.SelectSingleNode(path);
- this.doc = doc;
- currentPath = path;
- }
-
- public XmlElementTester ShouldExist()
- {
- if (currentElement == null)
- throw new SpecificationException(string.Format("Should exist at {0} but does not.", currentPath));
-
- return this;
- }
-
- public XmlElementTester ShouldNotExist()
- {
- if (currentElement != null)
- throw new SpecificationException(string.Format("Should not exist at {0} but does.", currentPath));
-
- return this;
- }
-
- public XmlElementTester HasAttribute(string name)
- {
- if (!currentElement.HasAttribute(name))
- throw new SpecificationException(string.Format("Should have attribute named {0} at {1} but does not.", name, currentPath));
-
- return this;
- }
-
- public XmlElementTester HasAttribute(string name, string value)
- {
- ShouldExist();
- HasAttribute(name);
-
- var actual = currentElement.GetAttribute(name);
-
- if (!actual.Equals(value))
- throw new SpecificationException(string.Format("Should have attribute named {0} at {1} with value of {2} but was {3}", name, currentPath, value, actual));
-
- return this;
- }
-
- public XmlElementTester HasAttribute(string name, Func predicate)
- {
- ShouldExist();
- HasAttribute(name);
-
- var actual = currentElement.GetAttribute(name);
-
- if (!predicate(actual))
- throw new SpecificationException(string.Format("Should have attribute named {0} at {1} with value matching predicate but does not.", name, currentPath));
-
- return this;
- }
-
- public XmlElementTester DoesntHaveAttribute(string name)
- {
- ShouldExist();
-
- if (currentElement.HasAttribute(name))
- throw new SpecificationException(string.Format("Should not have attribute named {0} at {1} but does.", name, currentPath));
-
- return this;
- }
- }
+using System;
+using System.Linq;
+using System.Xml;
+using FluentNHibernate.Automapping;
+using FluentNHibernate.MappingModel;
+using FluentNHibernate.MappingModel.ClassBased;
+using FluentNHibernate.MappingModel.Output;
+using Machine.Specifications;
+
+namespace FluentNHibernate.Specs.Automapping.Fixtures;
+
+public static class AutomappingSpecExtensions
+{
+ public static ClassMapping BuildMappingFor(this AutoPersistenceModel model)
+ {
+ return model.BuildMappings()
+ .SelectMany(x => x.Classes)
+ .FirstOrDefault(x => x.Type == typeof(T));
+ }
+
+ public static XmlDocument ToXml(this ClassMapping mapping)
+ {
+ var hbm = new HibernateMapping();
+
+ hbm.AddClass(mapping);
+
+ return new MappingXmlSerializer()
+ .Serialize(hbm);
+ }
+}
+
+public static class XmlTestExtensions
+{
+ public static XmlElementTester Element(this XmlDocument doc, string path)
+ {
+ return new XmlElementTester(doc, path);
+ }
+
+ public class XmlElementTester
+ {
+ readonly XmlDocument doc;
+ string currentPath;
+ XmlElement currentElement;
+
+ public XmlElementTester(XmlDocument doc, string path)
+ {
+ currentElement = (XmlElement)doc.DocumentElement.SelectSingleNode(path);
+ this.doc = doc;
+ currentPath = path;
+ }
+
+ public XmlElementTester ShouldExist()
+ {
+ if (currentElement == null)
+ throw new SpecificationException(string.Format("Should exist at {0} but does not.", currentPath));
+
+ return this;
+ }
+
+ public XmlElementTester ShouldNotExist()
+ {
+ if (currentElement != null)
+ throw new SpecificationException(string.Format("Should not exist at {0} but does.", currentPath));
+
+ return this;
+ }
+
+ public XmlElementTester HasAttribute(string name)
+ {
+ if (!currentElement.HasAttribute(name))
+ throw new SpecificationException(string.Format("Should have attribute named {0} at {1} but does not.", name, currentPath));
+
+ return this;
+ }
+
+ public XmlElementTester HasAttribute(string name, string value)
+ {
+ ShouldExist();
+ HasAttribute(name);
+
+ var actual = currentElement.GetAttribute(name);
+
+ if (!actual.Equals(value))
+ throw new SpecificationException(string.Format("Should have attribute named {0} at {1} with value of {2} but was {3}", name, currentPath, value, actual));
+
+ return this;
+ }
+
+ public XmlElementTester HasAttribute(string name, Func predicate)
+ {
+ ShouldExist();
+ HasAttribute(name);
+
+ var actual = currentElement.GetAttribute(name);
+
+ if (!predicate(actual))
+ throw new SpecificationException(string.Format("Should have attribute named {0} at {1} with value matching predicate but does not.", name, currentPath));
+
+ return this;
+ }
+
+ public XmlElementTester DoesntHaveAttribute(string name)
+ {
+ ShouldExist();
+
+ if (currentElement.HasAttribute(name))
+ throw new SpecificationException(string.Format("Should not have attribute named {0} at {1} but does.", name, currentPath));
+
+ return this;
+ }
+ }
}
diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/DictionaryEntity.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/DictionaryEntity.cs
index 915002cd2..22a0673e3 100644
--- a/src/FluentNHibernate.Specs/Automapping/Fixtures/DictionaryEntity.cs
+++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/DictionaryEntity.cs
@@ -1,12 +1,12 @@
-using System.Collections;
-using System.Collections.Generic;
-using FluentNHibernate.Specs.ExternalFixtures;
-
-namespace FluentNHibernate.Specs.Automapping.Fixtures;
-
-class DictionaryEntity
-{
- public int Id { get; set; }
- public IDictionary GenericDictionary { get; set; }
- public IDictionary Dictionary { get; set; }
+using System.Collections;
+using System.Collections.Generic;
+using FluentNHibernate.Specs.ExternalFixtures;
+
+namespace FluentNHibernate.Specs.Automapping.Fixtures;
+
+class DictionaryEntity
+{
+ public int Id { get; set; }
+ public IDictionary GenericDictionary { get; set; }
+ public IDictionary Dictionary { get; set; }
}
diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityUsingPrivateFields.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityUsingPrivateFields.cs
index 09dd42cfc..fd028a8cf 100644
--- a/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityUsingPrivateFields.cs
+++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityUsingPrivateFields.cs
@@ -1,16 +1,16 @@
-using System;
-using System.Collections.Generic;
-
-namespace FluentNHibernate.Specs.Automapping.Fixtures;
-
-class EntityUsingPrivateFields
-{
- int id;
- string one;
- DateTime two;
- DateTime? three;
- int _one;
- IList _children;
-
- public string PublicPropertyThatShouldBeIgnored { get; set; }
+using System;
+using System.Collections.Generic;
+
+namespace FluentNHibernate.Specs.Automapping.Fixtures;
+
+class EntityUsingPrivateFields
+{
+ int id;
+ string one;
+ DateTime two;
+ DateTime? three;
+ int _one;
+ IList _children;
+
+ public string PublicPropertyThatShouldBeIgnored { get; set; }
}
diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityWithStaticProperties.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityWithStaticProperties.cs
index ceb780520..5b540627f 100644
--- a/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityWithStaticProperties.cs
+++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/EntityWithStaticProperties.cs
@@ -1,7 +1,7 @@
-namespace FluentNHibernate.Specs.Automapping.Fixtures;
-
-public class EntityWithStaticProperties
-{
- public int Id { get; set; }
- public static int StaticProperty { get; set; }
+namespace FluentNHibernate.Specs.Automapping.Fixtures;
+
+public class EntityWithStaticProperties
+{
+ public int Id { get; set; }
+ public static int StaticProperty { get; set; }
}
diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/FakeMembers.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/FakeMembers.cs
index 2077598cb..28f50da85 100644
--- a/src/FluentNHibernate.Specs/Automapping/Fixtures/FakeMembers.cs
+++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/FakeMembers.cs
@@ -1,41 +1,41 @@
-using System;
-using System.Collections.Generic;
-
-namespace FluentNHibernate.Specs.Automapping.Fixtures;
-
-public static class FakeMembers
-{
- public static readonly Type Type = typeof(Target);
- public static readonly Member IListOfStrings;
- public static readonly Member IListOfInts;
- public static readonly Member IListOfDoubles;
- public static readonly Member IListOfShorts;
- public static readonly Member IListOfLongs;
- public static readonly Member IListOfFloats;
- public static readonly Member IListOfBools;
- public static readonly Member IListOfDateTimes;
-
- static FakeMembers()
- {
- IListOfStrings = typeof(Target).GetProperty("IListOfStrings").ToMember();
- IListOfInts = typeof(Target).GetProperty("IListOfInts").ToMember();
- IListOfDoubles = typeof(Target).GetProperty("IListOfDoubles").ToMember();
- IListOfShorts = typeof(Target).GetProperty("IListOfShorts").ToMember();
- IListOfLongs = typeof(Target).GetProperty("IListOfLongs").ToMember();
- IListOfFloats = typeof(Target).GetProperty("IListOfFloats").ToMember();
- IListOfBools = typeof(Target).GetProperty("IListOfBools").ToMember();
- IListOfDateTimes = typeof(Target).GetProperty("IListOfDateTimes").ToMember();
- }
-
- class Target
- {
- public IList IListOfStrings { get; set; }
- public IList IListOfInts { get; set; }
- public IList IListOfDoubles { get; set; }
- public IList IListOfShorts { get; set; }
- public IList IListOfLongs { get; set; }
- public IList IListOfFloats { get; set; }
- public IList IListOfBools { get; set; }
- public IList IListOfDateTimes { get; set; }
- }
+using System;
+using System.Collections.Generic;
+
+namespace FluentNHibernate.Specs.Automapping.Fixtures;
+
+public static class FakeMembers
+{
+ public static readonly Type Type = typeof(Target);
+ public static readonly Member IListOfStrings;
+ public static readonly Member IListOfInts;
+ public static readonly Member IListOfDoubles;
+ public static readonly Member IListOfShorts;
+ public static readonly Member IListOfLongs;
+ public static readonly Member IListOfFloats;
+ public static readonly Member IListOfBools;
+ public static readonly Member IListOfDateTimes;
+
+ static FakeMembers()
+ {
+ IListOfStrings = typeof(Target).GetProperty("IListOfStrings").ToMember();
+ IListOfInts = typeof(Target).GetProperty("IListOfInts").ToMember();
+ IListOfDoubles = typeof(Target).GetProperty("IListOfDoubles").ToMember();
+ IListOfShorts = typeof(Target).GetProperty("IListOfShorts").ToMember();
+ IListOfLongs = typeof(Target).GetProperty("IListOfLongs").ToMember();
+ IListOfFloats = typeof(Target).GetProperty("IListOfFloats").ToMember();
+ IListOfBools = typeof(Target).GetProperty("IListOfBools").ToMember();
+ IListOfDateTimes = typeof(Target).GetProperty("IListOfDateTimes").ToMember();
+ }
+
+ class Target
+ {
+ public IList IListOfStrings { get; set; }
+ public IList IListOfInts { get; set; }
+ public IList IListOfDoubles { get; set; }
+ public IList IListOfShorts { get; set; }
+ public IList IListOfLongs { get; set; }
+ public IList IListOfFloats { get; set; }
+ public IList IListOfBools { get; set; }
+ public IList IListOfDateTimes { get; set; }
+ }
}
diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/Overrides/EntityTableOverride.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/Overrides/EntityTableOverride.cs
index 13e22a4f0..3340e9a98 100644
--- a/src/FluentNHibernate.Specs/Automapping/Fixtures/Overrides/EntityTableOverride.cs
+++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/Overrides/EntityTableOverride.cs
@@ -1,13 +1,13 @@
-using FluentNHibernate.Automapping;
-using FluentNHibernate.Automapping.Alterations;
-using FluentNHibernate.Specs.ExternalFixtures;
-
-namespace FluentNHibernate.Specs.Automapping.Fixtures.Overrides;
-
-public class EntityTableOverride : IAutoMappingOverride
-{
- public void Override(AutoMapping mapping)
- {
- mapping.Table("OverriddenTableName");
- }
+using FluentNHibernate.Automapping;
+using FluentNHibernate.Automapping.Alterations;
+using FluentNHibernate.Specs.ExternalFixtures;
+
+namespace FluentNHibernate.Specs.Automapping.Fixtures.Overrides;
+
+public class EntityTableOverride : IAutoMappingOverride
+{
+ public void Override(AutoMapping mapping)
+ {
+ mapping.Table("OverriddenTableName");
+ }
}
diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/ParentChildSelfReferenceEntity.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/ParentChildSelfReferenceEntity.cs
index b5b74e9a5..b93ee1efc 100644
--- a/src/FluentNHibernate.Specs/Automapping/Fixtures/ParentChildSelfReferenceEntity.cs
+++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/ParentChildSelfReferenceEntity.cs
@@ -1,10 +1,10 @@
-using System.Collections.Generic;
-
-namespace FluentNHibernate.Specs.Automapping.Fixtures;
-
-public class ParentChildSelfReferenceEntity
-{
- public int Id { get; set; }
- public ParentChildSelfReferenceEntity Parent { get; set; }
- public IList Children { get; set; }
+using System.Collections.Generic;
+
+namespace FluentNHibernate.Specs.Automapping.Fixtures;
+
+public class ParentChildSelfReferenceEntity
+{
+ public int Id { get; set; }
+ public ParentChildSelfReferenceEntity Parent { get; set; }
+ public IList Children { get; set; }
}
diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/ReadOnlyEnumerableEntity.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/ReadOnlyEnumerableEntity.cs
index b4095d637..07a761575 100644
--- a/src/FluentNHibernate.Specs/Automapping/Fixtures/ReadOnlyEnumerableEntity.cs
+++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/ReadOnlyEnumerableEntity.cs
@@ -1,16 +1,16 @@
-using System.Collections.Generic;
-using FluentNHibernate.Specs.ExternalFixtures;
-
-namespace FluentNHibernate.Specs.Automapping.Fixtures;
-
-class ReadOnlyEnumerableEntity
-{
- IList backingFieldCollection;
-
- public int Id { get; set; }
- public IEnumerable AutoPropertyCollection { get; private set; }
- public IEnumerable BackingFieldCollection
- {
- get { return backingFieldCollection; }
- }
+using System.Collections.Generic;
+using FluentNHibernate.Specs.ExternalFixtures;
+
+namespace FluentNHibernate.Specs.Automapping.Fixtures;
+
+class ReadOnlyEnumerableEntity
+{
+ IList backingFieldCollection;
+
+ public int Id { get; set; }
+ public IEnumerable AutoPropertyCollection { get; private set; }
+ public IEnumerable BackingFieldCollection
+ {
+ get { return backingFieldCollection; }
+ }
}
diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferenceEntity.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferenceEntity.cs
index f7b4b6258..3d17bd03c 100644
--- a/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferenceEntity.cs
+++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferenceEntity.cs
@@ -1,7 +1,7 @@
-namespace FluentNHibernate.Specs.Automapping.Fixtures;
-
-public class SelfReferenceEntity
-{
- public int Id { get; set; }
- public SelfReferenceEntity Parent { get; set; }
+namespace FluentNHibernate.Specs.Automapping.Fixtures;
+
+public class SelfReferenceEntity
+{
+ public int Id { get; set; }
+ public SelfReferenceEntity Parent { get; set; }
}
diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferencingCollectionEntity.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferencingCollectionEntity.cs
index abaa20853..f95755129 100644
--- a/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferencingCollectionEntity.cs
+++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/SelfReferencingCollectionEntity.cs
@@ -1,9 +1,9 @@
-using System.Collections.Generic;
-
-namespace FluentNHibernate.Specs.Automapping.Fixtures;
-
-public class SelfReferencingCollectionEntity
-{
- public int Id { get; set; }
- public IList Children { get; set; }
+using System.Collections.Generic;
+
+namespace FluentNHibernate.Specs.Automapping.Fixtures;
+
+public class SelfReferencingCollectionEntity
+{
+ public int Id { get; set; }
+ public IList Children { get; set; }
}
diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/StubTypeSource.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/StubTypeSource.cs
index 4a84eaf5e..a87a7c404 100644
--- a/src/FluentNHibernate.Specs/Automapping/Fixtures/StubTypeSource.cs
+++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/StubTypeSource.cs
@@ -1,30 +1,30 @@
-using System;
-using System.Collections.Generic;
-using FluentNHibernate.Diagnostics;
-
-namespace FluentNHibernate.Specs.Automapping.Fixtures;
-
-internal class StubTypeSource : ITypeSource
-{
- private readonly IEnumerable types;
-
- public StubTypeSource(params Type[] types)
- {
- this.types = types;
- }
-
- public IEnumerable GetTypes()
- {
- return types;
- }
-
- public void LogSource(IDiagnosticLogger logger)
- {
- logger.LoadedFluentMappingsFromSource(this);
- }
-
- public string GetIdentifier()
- {
- return "StubTypeSource";
- }
+using System;
+using System.Collections.Generic;
+using FluentNHibernate.Diagnostics;
+
+namespace FluentNHibernate.Specs.Automapping.Fixtures;
+
+internal class StubTypeSource : ITypeSource
+{
+ private readonly IEnumerable types;
+
+ public StubTypeSource(params Type[] types)
+ {
+ this.types = types;
+ }
+
+ public IEnumerable GetTypes()
+ {
+ return types;
+ }
+
+ public void LogSource(IDiagnosticLogger logger)
+ {
+ logger.LoadedFluentMappingsFromSource(this);
+ }
+
+ public string GetIdentifier()
+ {
+ return "StubTypeSource";
+ }
}
diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/UserTypes.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/UserTypes.cs
index 33c160748..57cf92ee6 100644
--- a/src/FluentNHibernate.Specs/Automapping/Fixtures/UserTypes.cs
+++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/UserTypes.cs
@@ -1,177 +1,177 @@
-using System;
-using System.Collections.Generic;
-using System.Data;
-using System.Data.Common;
-using System.Linq;
-using System.Text;
-using FluentNHibernate.Conventions;
-using FluentNHibernate.Conventions.Instances;
-using NHibernate.Engine;
-using NHibernate.SqlTypes;
-using NHibernate.UserTypes;
-
-namespace FluentNHibernate.Specs.Automapping.Fixtures;
-
-public class TypeWithNullableUT
-{
- public int ID { get; set; }
- public UserValueType? Simple { get; set; }
-}
-
-public class TypeWithValueUT
-{
- public int Id { get; set; }
- public UserValueType Definite { get; set; }
-}
-
-public class NotNullableUT
-{
- public int ID { get; set; }
- public CustomUserType Complex { get; set; }
-}
-
-public class ValueTypeConvention : UserTypeConvention
-{
- public override void Apply(IPropertyInstance instance)
- {
- base.Apply(instance);
- instance.Column("arbitraryName");
- }
-}
-
-public class CustomTypeConvention : UserTypeConvention
-{
- public override void Apply(IPropertyInstance instance)
- {
- base.Apply(instance);
- instance.Column("someOtherName");
- }
-}
-
-public class CustomUserType : IUserType
-{
- public new bool Equals(object x, object y)
- {
- return x == y;
- }
-
- public int GetHashCode(object x)
- {
- return x.GetHashCode();
- }
-
- public object NullSafeGet(IDataReader rs, string[] names, object owner)
- {
- return null;
- }
-
- public void NullSafeSet(IDbCommand cmd, object value, int index)
- {
-
- }
-
- public object DeepCopy(object value)
- {
- return value;
- }
-
- public object Replace(object original, object target, object owner)
- {
- return original;
- }
-
- public object Assemble(object cached, object owner)
- {
- return cached;
- }
-
- public object Disassemble(object value)
- {
- return value;
- }
-
- public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner)
- {
- throw new NotImplementedException();
- }
-
- public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session)
- {
- throw new NotImplementedException();
- }
-
- public SqlType[] SqlTypes
- {
- get { return new[] { new SqlType(DbType.String) }; }
- }
-
- public Type ReturnedType
- {
- get { return typeof(CustomUserType); }
- }
-
- public bool IsMutable
- {
- get { return true; }
- }
-}
-
-public struct UserValueType : IUserType
-{
- public string AddressLine1 { get; set; }
- public string AddressLine2 { get; set; }
-
- public new bool Equals(object x, object y)
- {
- throw new NotImplementedException();
- }
-
- public int GetHashCode(object x)
- {
- throw new NotImplementedException();
- }
-
- public object NullSafeGet(IDataReader rs, string[] names, object owner)
- {
- throw new NotImplementedException();
- }
-
- public void NullSafeSet(IDbCommand cmd, object value, int index)
- {
- throw new NotImplementedException();
- }
-
- public object DeepCopy(object value)
- {
- throw new NotImplementedException();
- }
-
- public object Replace(object original, object target, object owner)
- {
- throw new NotImplementedException();
- }
-
- public object Assemble(object cached, object owner)
- {
- throw new NotImplementedException();
- }
-
- public object Disassemble(object value)
- {
- throw new NotImplementedException();
- }
-
- public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner)
- {
- throw new NotImplementedException();
- }
-
- public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session)
- {
- throw new NotImplementedException();
- }
-
- public SqlType[] SqlTypes { get; private set; }
- public Type ReturnedType { get { return typeof(UserValueType); } }
- public bool IsMutable { get; private set; }
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Data.Common;
+using System.Linq;
+using System.Text;
+using FluentNHibernate.Conventions;
+using FluentNHibernate.Conventions.Instances;
+using NHibernate.Engine;
+using NHibernate.SqlTypes;
+using NHibernate.UserTypes;
+
+namespace FluentNHibernate.Specs.Automapping.Fixtures;
+
+public class TypeWithNullableUT
+{
+ public int ID { get; set; }
+ public UserValueType? Simple { get; set; }
+}
+
+public class TypeWithValueUT
+{
+ public int Id { get; set; }
+ public UserValueType Definite { get; set; }
+}
+
+public class NotNullableUT
+{
+ public int ID { get; set; }
+ public CustomUserType Complex { get; set; }
+}
+
+public class ValueTypeConvention : UserTypeConvention
+{
+ public override void Apply(IPropertyInstance instance)
+ {
+ base.Apply(instance);
+ instance.Column("arbitraryName");
+ }
+}
+
+public class CustomTypeConvention : UserTypeConvention
+{
+ public override void Apply(IPropertyInstance instance)
+ {
+ base.Apply(instance);
+ instance.Column("someOtherName");
+ }
+}
+
+public class CustomUserType : IUserType
+{
+ public new bool Equals(object x, object y)
+ {
+ return x == y;
+ }
+
+ public int GetHashCode(object x)
+ {
+ return x.GetHashCode();
+ }
+
+ public object NullSafeGet(IDataReader rs, string[] names, object owner)
+ {
+ return null;
+ }
+
+ public void NullSafeSet(IDbCommand cmd, object value, int index)
+ {
+
+ }
+
+ public object DeepCopy(object value)
+ {
+ return value;
+ }
+
+ public object Replace(object original, object target, object owner)
+ {
+ return original;
+ }
+
+ public object Assemble(object cached, object owner)
+ {
+ return cached;
+ }
+
+ public object Disassemble(object value)
+ {
+ return value;
+ }
+
+ public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session)
+ {
+ throw new NotImplementedException();
+ }
+
+ public SqlType[] SqlTypes
+ {
+ get { return new[] { new SqlType(DbType.String) }; }
+ }
+
+ public Type ReturnedType
+ {
+ get { return typeof(CustomUserType); }
+ }
+
+ public bool IsMutable
+ {
+ get { return true; }
+ }
+}
+
+public struct UserValueType : IUserType
+{
+ public string AddressLine1 { get; set; }
+ public string AddressLine2 { get; set; }
+
+ public new bool Equals(object x, object y)
+ {
+ throw new NotImplementedException();
+ }
+
+ public int GetHashCode(object x)
+ {
+ throw new NotImplementedException();
+ }
+
+ public object NullSafeGet(IDataReader rs, string[] names, object owner)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void NullSafeSet(IDbCommand cmd, object value, int index)
+ {
+ throw new NotImplementedException();
+ }
+
+ public object DeepCopy(object value)
+ {
+ throw new NotImplementedException();
+ }
+
+ public object Replace(object original, object target, object owner)
+ {
+ throw new NotImplementedException();
+ }
+
+ public object Assemble(object cached, object owner)
+ {
+ throw new NotImplementedException();
+ }
+
+ public object Disassemble(object value)
+ {
+ throw new NotImplementedException();
+ }
+
+ public object NullSafeGet(DbDataReader rs, string[] names, ISessionImplementor session, object owner)
+ {
+ throw new NotImplementedException();
+ }
+
+ public void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session)
+ {
+ throw new NotImplementedException();
+ }
+
+ public SqlType[] SqlTypes { get; private set; }
+ public Type ReturnedType { get { return typeof(UserValueType); } }
+ public bool IsMutable { get; private set; }
}
diff --git a/src/FluentNHibernate.Specs/Automapping/Fixtures/VersionedEntity.cs b/src/FluentNHibernate.Specs/Automapping/Fixtures/VersionedEntity.cs
index cc8a6ea1a..389e7ce8c 100644
--- a/src/FluentNHibernate.Specs/Automapping/Fixtures/VersionedEntity.cs
+++ b/src/FluentNHibernate.Specs/Automapping/Fixtures/VersionedEntity.cs
@@ -1,8 +1,8 @@
-namespace FluentNHibernate.Specs.Automapping.Fixtures;
-
-public class VersionedEntity
-{
- public int Id { get; set; }
- public int Timestamp { get; set; }
- public string AnUnobviousVersion { get; set; }
+namespace FluentNHibernate.Specs.Automapping.Fixtures;
+
+public class VersionedEntity
+{
+ public int Id { get; set; }
+ public int Timestamp { get; set; }
+ public string AnUnobviousVersion { get; set; }
}
diff --git a/src/FluentNHibernate.Specs/Automapping/OverrideSpecs.cs b/src/FluentNHibernate.Specs/Automapping/OverrideSpecs.cs
index 25cce5214..7779f6014 100644
--- a/src/FluentNHibernate.Specs/Automapping/OverrideSpecs.cs
+++ b/src/FluentNHibernate.Specs/Automapping/OverrideSpecs.cs
@@ -1,151 +1,151 @@
-using System.Linq;
-using FluentNHibernate.Automapping;
-using FluentNHibernate.Automapping.Alterations;
-using FluentNHibernate.MappingModel.ClassBased;
-using FluentNHibernate.Specs.Automapping.Fixtures;
-using FluentNHibernate.Specs.Automapping.Fixtures.Overrides;
-using FluentNHibernate.Specs.ExternalFixtures;
-using FluentNHibernate.Specs.ExternalFixtures.Overrides;
-using Machine.Specifications;
-using FluentAssertions;
-
-namespace FluentNHibernate.Specs.Automapping;
-
-public class when_using_an_automapping_override_to_create_a_join
-{
- Establish context = () =>
- model = AutoMap.Source(new StubTypeSource(typeof(Entity)))
- .Override(map =>
- map.Join("join_table", m => m.Map(x => x.One)));
-
- Because of = () =>
- mapping = model.BuildMappingFor();
-
- It should_create_the_join_mapping = () =>
- mapping.Joins.Should().NotBeEmpty();
-
- It should_have_a_property_in_the_join = () =>
- mapping.Joins.Single().Properties.Select(x => x.Name).Should().Contain("One");
-
- It should_exclude_the_join_mapped_property_from_the_main_automapping = () =>
- mapping.Properties.Select(x => x.Name).Should().NotContain("One");
-
- static AutoPersistenceModel model;
- static ClassMapping mapping;
-}
-
-public class when_using_an_automapping_override_to_specify_a_discriminators_and_join_on_subclass
-{
- private Establish context = () =>
- model = AutoMap.Source(new StubTypeSource(typeof (Parent), typeof (Child)))
- .Override(map =>
- map.DiscriminateSubClassesOnColumn("type"))
- .Override(map => map.Join("table", part => { }));
-
- private Because of = () =>
- mapping = model.BuildMappingFor();
-
- It should_not_create_the_join_mapping = () =>
- mapping.Joins.Should().BeEmpty();
-
- It should_map_the_discriminator = () =>
- mapping.Discriminator.Should().NotBeNull();
-
- It should_map_subclasses_as_joined_subclasses = () =>
- mapping.Subclasses.Should().OnlyContain(x => x.Joins.Any());
-
- static AutoPersistenceModel model;
- static ClassMapping mapping;
-}
-
-public class when_using_an_automapping_override_to_specify_a_discriminator
-{
- Establish context = () =>
- model = AutoMap.Source(new StubTypeSource(typeof(Parent), typeof(Child)))
- .Override(map =>
- map.DiscriminateSubClassesOnColumn("discriminator"));
-
- Because of = () =>
- mapping = model.BuildMappingFor();
-
- It should_map_the_discriminator = () =>
- mapping.Discriminator.Should().NotBeNull();
-
- It should_map_subclasses_as_subclass_instead_of_joined_subclass = () =>
- {
- mapping.Subclasses.Count().Should().Be(1);
- mapping.Subclasses.Should().OnlyContain(subclass => subclass.SubclassType == SubclassType.Subclass);
- };
-
- static AutoPersistenceModel model;
- static ClassMapping mapping;
-}
-
-[Subject(typeof(IAutoMappingOverride<>))]
-public class when_using_multiple_overrides_from_different_assemblies
-{
- Establish context = () =>
- model = AutoMap.Source(new StubTypeSource(typeof(Entity)))
- .UseOverridesFromAssemblyOf()
- .UseOverridesFromAssemblyOf();
-
- Because of = () =>
- mapping = model.BuildMappingFor();
-
- It should_apply_override_from_the_first_assembly = () =>
- mapping.BatchSize.Should().Be(1234);
-
- It should_apply_override_from_the_second_assembly = () =>
- mapping.TableName.Should().Be("OverriddenTableName");
-
- static AutoPersistenceModel model;
- static ClassMapping mapping;
-}
-
-[Subject(typeof(IAutoMappingOverride<>))]
-public class when_multiple_overrides_present_in_one_class
-{
- Establish context = () =>
- {
- model = AutoMap.Source(new StubTypeSource(typeof(Entity), typeof(Parent), typeof(B_Parent)));
- model.Override(typeof(MultipleOverrides));
- };
-
- Because of = () =>
- {
- entityMapping = model.BuildMappingFor();
- parentMapping = model.BuildMappingFor();
- bParentMapping = model.BuildMappingFor();
- };
-
- It should_apply_overrides_to_every_class_for_which_such_were_provided = () =>
- {
- entityMapping.EntityName.Should().Be("customEntityName");
- parentMapping.TableName.Should().Be("fancyTableName_Parent");
- bParentMapping.BatchSize.Should().Be(50);
- };
-
-
- static AutoPersistenceModel model;
- static ClassMapping entityMapping;
- static ClassMapping parentMapping;
- static ClassMapping bParentMapping;
-}
-
-public class MultipleOverrides: IAutoMappingOverride, IAutoMappingOverride, IAutoMappingOverride
-{
- public void Override(AutoMapping mapping)
- {
- mapping.EntityName("customEntityName");
- }
-
- public void Override(AutoMapping mapping)
- {
- mapping.Table("fancyTableName_Parent");
- }
-
- public void Override(AutoMapping mapping)
- {
- mapping.BatchSize(50);
- }
+using System.Linq;
+using FluentNHibernate.Automapping;
+using FluentNHibernate.Automapping.Alterations;
+using FluentNHibernate.MappingModel.ClassBased;
+using FluentNHibernate.Specs.Automapping.Fixtures;
+using FluentNHibernate.Specs.Automapping.Fixtures.Overrides;
+using FluentNHibernate.Specs.ExternalFixtures;
+using FluentNHibernate.Specs.ExternalFixtures.Overrides;
+using Machine.Specifications;
+using FluentAssertions;
+
+namespace FluentNHibernate.Specs.Automapping;
+
+public class when_using_an_automapping_override_to_create_a_join
+{
+ Establish context = () =>
+ model = AutoMap.Source(new StubTypeSource(typeof(Entity)))
+ .Override(map =>
+ map.Join("join_table", m => m.Map(x => x.One)));
+
+ Because of = () =>
+ mapping = model.BuildMappingFor();
+
+ It should_create_the_join_mapping = () =>
+ mapping.Joins.Should().NotBeEmpty();
+
+ It should_have_a_property_in_the_join = () =>
+ mapping.Joins.Single().Properties.Select(x => x.Name).Should().Contain("One");
+
+ It should_exclude_the_join_mapped_property_from_the_main_automapping = () =>
+ mapping.Properties.Select(x => x.Name).Should().NotContain("One");
+
+ static AutoPersistenceModel model;
+ static ClassMapping mapping;
+}
+
+public class when_using_an_automapping_override_to_specify_a_discriminators_and_join_on_subclass
+{
+ private Establish context = () =>
+ model = AutoMap.Source(new StubTypeSource(typeof (Parent), typeof (Child)))
+ .Override(map =>
+ map.DiscriminateSubClassesOnColumn("type"))
+ .Override(map => map.Join("table", part => { }));
+
+ private Because of = () =>
+ mapping = model.BuildMappingFor();
+
+ It should_not_create_the_join_mapping = () =>
+ mapping.Joins.Should().BeEmpty();
+
+ It should_map_the_discriminator = () =>
+ mapping.Discriminator.Should().NotBeNull();
+
+ It should_map_subclasses_as_joined_subclasses = () =>
+ mapping.Subclasses.Should().OnlyContain(x => x.Joins.Any());
+
+ static AutoPersistenceModel model;
+ static ClassMapping mapping;
+}
+
+public class when_using_an_automapping_override_to_specify_a_discriminator
+{
+ Establish context = () =>
+ model = AutoMap.Source(new StubTypeSource(typeof(Parent), typeof(Child)))
+ .Override(map =>
+ map.DiscriminateSubClassesOnColumn("discriminator"));
+
+ Because of = () =>
+ mapping = model.BuildMappingFor();
+
+ It should_map_the_discriminator = () =>
+ mapping.Discriminator.Should().NotBeNull();
+
+ It should_map_subclasses_as_subclass_instead_of_joined_subclass = () =>
+ {
+ mapping.Subclasses.Count().Should().Be(1);
+ mapping.Subclasses.Should().OnlyContain(subclass => subclass.SubclassType == SubclassType.Subclass);
+ };
+
+ static AutoPersistenceModel model;
+ static ClassMapping mapping;
+}
+
+[Subject(typeof(IAutoMappingOverride<>))]
+public class when_using_multiple_overrides_from_different_assemblies
+{
+ Establish context = () =>
+ model = AutoMap.Source(new StubTypeSource(typeof(Entity)))
+ .UseOverridesFromAssemblyOf()
+ .UseOverridesFromAssemblyOf();
+
+ Because of = () =>
+ mapping = model.BuildMappingFor();
+
+ It should_apply_override_from_the_first_assembly = () =>
+ mapping.BatchSize.Should().Be(1234);
+
+ It should_apply_override_from_the_second_assembly = () =>
+ mapping.TableName.Should().Be("OverriddenTableName");
+
+ static AutoPersistenceModel model;
+ static ClassMapping mapping;
+}
+
+[Subject(typeof(IAutoMappingOverride<>))]
+public class when_multiple_overrides_present_in_one_class
+{
+ Establish context = () =>
+ {
+ model = AutoMap.Source(new StubTypeSource(typeof(Entity), typeof(Parent), typeof(B_Parent)));
+ model.Override(typeof(MultipleOverrides));
+ };
+
+ Because of = () =>
+ {
+ entityMapping = model.BuildMappingFor();
+ parentMapping = model.BuildMappingFor();
+ bParentMapping = model.BuildMappingFor();
+ };
+
+ It should_apply_overrides_to_every_class_for_which_such_were_provided = () =>
+ {
+ entityMapping.EntityName.Should().Be("customEntityName");
+ parentMapping.TableName.Should().Be("fancyTableName_Parent");
+ bParentMapping.BatchSize.Should().Be(50);
+ };
+
+
+ static AutoPersistenceModel model;
+ static ClassMapping entityMapping;
+ static ClassMapping parentMapping;
+ static ClassMapping bParentMapping;
+}
+
+public class MultipleOverrides: IAutoMappingOverride, IAutoMappingOverride, IAutoMappingOverride
+{
+ public void Override(AutoMapping mapping)
+ {
+ mapping.EntityName("customEntityName");
+ }
+
+ public void Override(AutoMapping mapping)
+ {
+ mapping.Table("fancyTableName_Parent");
+ }
+
+ public void Override(AutoMapping mapping)
+ {
+ mapping.BatchSize(50);
+ }
}
diff --git a/src/FluentNHibernate.Specs/Automapping/PrivateAutomapperSpecs.cs b/src/FluentNHibernate.Specs/Automapping/PrivateAutomapperSpecs.cs
index 70da9ca1e..9200911b1 100644
--- a/src/FluentNHibernate.Specs/Automapping/PrivateAutomapperSpecs.cs
+++ b/src/FluentNHibernate.Specs/Automapping/PrivateAutomapperSpecs.cs
@@ -1,35 +1,35 @@
-using System.Linq;
-using FluentNHibernate.Automapping;
-using FluentNHibernate.MappingModel.ClassBased;
-using FluentNHibernate.Specs.Automapping.Fixtures;
-using Machine.Specifications;
-using FluentAssertions;
-
-namespace FluentNHibernate.Specs.Automapping;
-
-public class when_using_the_private_automapper_to_map_a_entity_with_private_fields_starting_with_an_underscore
-{
- Establish context = () =>
- {
- model = new PrivateAutoPersistenceModel()
- .Setup(conventions => conventions.FindMembers = m => m.IsField && m.Name.StartsWith("_"));
-
- model.ValidationEnabled = false;
- model.AddTypeSource(new StubTypeSource(typeof(EntityUsingPrivateFields)));
- };
-
- Because of = () =>
- mapping = model.BuildMappingFor();
-
- It should_map_fields_matching_the_convention = () =>
- mapping.Properties.Select(x => x.Name).Should().Contain("_one");
-
- It should_map_private_collections = () =>
- mapping.Collections.Select(x => x.Name).Should().Contain("_children");
-
- It should_not_map_fields_that_dont_match_the_convention = () =>
- mapping.Properties.Select(x => x.Name).Should().NotContain("one");
-
- static ClassMapping mapping;
- static AutoPersistenceModel model;
+using System.Linq;
+using FluentNHibernate.Automapping;
+using FluentNHibernate.MappingModel.ClassBased;
+using FluentNHibernate.Specs.Automapping.Fixtures;
+using Machine.Specifications;
+using FluentAssertions;
+
+namespace FluentNHibernate.Specs.Automapping;
+
+public class when_using_the_private_automapper_to_map_a_entity_with_private_fields_starting_with_an_underscore
+{
+ Establish context = () =>
+ {
+ model = new PrivateAutoPersistenceModel()
+ .Setup(conventions => conventions.FindMembers = m => m.IsField && m.Name.StartsWith("_"));
+
+ model.ValidationEnabled = false;
+ model.AddTypeSource(new StubTypeSource(typeof(EntityUsingPrivateFields)));
+ };
+
+ Because of = () =>
+ mapping = model.BuildMappingFor();
+
+ It should_map_fields_matching_the_convention = () =>
+ mapping.Properties.Select(x => x.Name).Should().Contain("_one");
+
+ It should_map_private_collections = () =>
+ mapping.Collections.Select(x => x.Name).Should().Contain("_children");
+
+ It should_not_map_fields_that_dont_match_the_convention = () =>
+ mapping.Properties.Select(x => x.Name).Should().NotContain("one");
+
+ static ClassMapping mapping;
+ static AutoPersistenceModel model;
}
diff --git a/src/FluentNHibernate.Specs/Automapping/PrivateFieldsSpecs.cs b/src/FluentNHibernate.Specs/Automapping/PrivateFieldsSpecs.cs
index 39b22ed78..b1061fdb7 100644
--- a/src/FluentNHibernate.Specs/Automapping/PrivateFieldsSpecs.cs
+++ b/src/FluentNHibernate.Specs/Automapping/PrivateFieldsSpecs.cs
@@ -1,38 +1,38 @@
-using System.Linq;
-using System.Reflection;
-using FluentNHibernate.Automapping;
-using FluentNHibernate.MappingModel.ClassBased;
-using FluentNHibernate.MappingModel.Identity;
-using FluentNHibernate.Specs.Automapping.Fixtures;
-using Machine.Specifications;
-using FluentAssertions;
-
-namespace FluentNHibernate.Specs.Automapping;
-
-public class when_using_the_automapper_to_map_an_entity_that_uses_private_fields_for_storage
-{
- Establish context = () =>
- mapper = AutoMap.Source(new StubTypeSource(typeof(EntityUsingPrivateFields)))
- .Setup(s => s.FindMembers = m => m.IsField && m.IsPrivate);
-
- Because of = () =>
- mapping = mapper.BuildMappingFor();
-
- It should_find_an_id = () =>
- mapping.Id.Should().NotBeNull();
-
- It should_use_the_correct_field_for_the_id = () =>
- {
- mapping.Id.As().Name.Should().Be("id");
- mapping.Id.As().Member.Should().Be(typeof(EntityUsingPrivateFields).GetField("id", BindingFlags.Instance | BindingFlags.NonPublic).ToMember());
- };
-
- It should_ignore_properties = () =>
- mapping.Properties.Where(x => x.Member.IsProperty).Should().BeEmpty();
-
- It should_map_fields = () =>
- mapping.Properties.Select(x => x.Name).Should().Contain(new string[] { "one", "two", "three" });
-
- static AutoPersistenceModel mapper;
- static ClassMapping mapping;
+using System.Linq;
+using System.Reflection;
+using FluentNHibernate.Automapping;
+using FluentNHibernate.MappingModel.ClassBased;
+using FluentNHibernate.MappingModel.Identity;
+using FluentNHibernate.Specs.Automapping.Fixtures;
+using Machine.Specifications;
+using FluentAssertions;
+
+namespace FluentNHibernate.Specs.Automapping;
+
+public class when_using_the_automapper_to_map_an_entity_that_uses_private_fields_for_storage
+{
+ Establish context = () =>
+ mapper = AutoMap.Source(new StubTypeSource(typeof(EntityUsingPrivateFields)))
+ .Setup(s => s.FindMembers = m => m.IsField && m.IsPrivate);
+
+ Because of = () =>
+ mapping = mapper.BuildMappingFor();
+
+ It should_find_an_id = () =>
+ mapping.Id.Should().NotBeNull();
+
+ It should_use_the_correct_field_for_the_id = () =>
+ {
+ mapping.Id.As().Name.Should().Be("id");
+ mapping.Id.As().Member.Should().Be(typeof(EntityUsingPrivateFields).GetField("id", BindingFlags.Instance | BindingFlags.NonPublic).ToMember());
+ };
+
+ It should_ignore_properties = () =>
+ mapping.Properties.Where(x => x.Member.IsProperty).Should().BeEmpty();
+
+ It should_map_fields = () =>
+ mapping.Properties.Select(x => x.Name).Should().Contain(new string[] { "one", "two", "three" });
+
+ static AutoPersistenceModel mapper;
+ static ClassMapping mapping;
}
diff --git a/src/FluentNHibernate.Specs/Conventions/ApplyFilterSpecs.cs b/src/FluentNHibernate.Specs/Conventions/ApplyFilterSpecs.cs
index f04742593..79742baca 100644
--- a/src/FluentNHibernate.Specs/Conventions/ApplyFilterSpecs.cs
+++ b/src/FluentNHibernate.Specs/Conventions/ApplyFilterSpecs.cs
@@ -1,92 +1,92 @@
-using System;
-using System.Linq;
-using FluentNHibernate.MappingModel.ClassBased;
-using FluentNHibernate.MappingModel.Collections;
-using FluentNHibernate.Specs.Conventions.Fixtures;
-using Machine.Specifications;
-using FluentAssertions;
-
-namespace FluentNHibernate.Specs.Conventions;
-
-public class when_applying_a_filter_to_an_entity_using_conventions
-{
- Establish context = () =>
- {
- model = new FluentNHibernate.PersistenceModel();
- model.Conventions.Add();
- model.Add(new FilterTargetMap());
- };
-
- Because of = () =>
- mapping = model.BuildMappingFor();
-
- It should_add_a_filter_to_the_entity_s_mapping = () =>
- mapping.Filters.Should().NotBeEmpty();
-
- It should_set_the_name_of_the_added_filter_correctly = () =>
- mapping.Filters.Single().Name.Should().Be(FilterClassConvention.FilterName);
-
- It should_set_the_condition_of_the_added_filter_correctly = () =>
- mapping.Filters.Single().Condition.Should().Be(FilterClassConvention.FilterCondition);
-
- static FluentNHibernate.PersistenceModel model;
- static ClassMapping mapping;
-}
-
-public class when_applying_a_filter_to_a_one_to_many_using_conventions
-{
- Establish context = () =>
- {
- model = new FluentNHibernate.PersistenceModel();
- model.Conventions.Add();
- model.Add(new FilterTargetMap());
- model.Add(new FilterChildTargetMap());
- };
-
- Because of = () =>
- {
- var classMapping = model.BuildMappingFor();
- mapping = classMapping.Collections.Single(x => x.Relationship is OneToManyMapping);
- };
-
- It should_add_a_filter_to_the_one_to_many_relationship_s_mapping = () =>
- mapping.Filters.Should().NotBeEmpty();
-
- It should_set_the_name_of_the_added_filter_correctly = () =>
- mapping.Filters.Single().Name.Should().Be(FilterHasManyConvention.FilterName);
-
- It should_set_the_condition_of_the_added_filter_correctly = () =>
- mapping.Filters.Single().Name.Should().Be(FilterHasManyConvention.FilterName);
-
- static FluentNHibernate.PersistenceModel model;
- static CollectionMapping mapping;
-}
-
-public class when_applying_a_filter_to_a_many_to_many_using_conventions
-{
- Establish context = () =>
- {
- model = new FluentNHibernate.PersistenceModel();
- model.Conventions.Add();
- model.Add(new FilterTargetMap());
- model.Add(new FilterChildTargetMap());
- };
-
- Because of = () =>
- {
- var classMapping = model.BuildMappingFor();
- mapping = classMapping.Collections.Single(x => x.Relationship is ManyToManyMapping);
- };
-
- It should_add_a_filter_to_the_one_to_many_relationship_s_mapping = () =>
- mapping.Filters.Should().NotBeEmpty();
-
- It should_set_the_name_of_the_added_filter_correctly = () =>
- mapping.Filters.Single().Name.Should().Be(FilterHasManyConvention.FilterName);
-
- It should_set_the_condition_of_the_added_filter_correctly = () =>
- mapping.Filters.Single().Name.Should().Be(FilterHasManyConvention.FilterName);
-
- static FluentNHibernate.PersistenceModel model;
- static CollectionMapping mapping;
+using System;
+using System.Linq;
+using FluentNHibernate.MappingModel.ClassBased;
+using FluentNHibernate.MappingModel.Collections;
+using FluentNHibernate.Specs.Conventions.Fixtures;
+using Machine.Specifications;
+using FluentAssertions;
+
+namespace FluentNHibernate.Specs.Conventions;
+
+public class when_applying_a_filter_to_an_entity_using_conventions
+{
+ Establish context = () =>
+ {
+ model = new FluentNHibernate.PersistenceModel();
+ model.Conventions.Add();
+ model.Add(new FilterTargetMap());
+ };
+
+ Because of = () =>
+ mapping = model.BuildMappingFor();
+
+ It should_add_a_filter_to_the_entity_s_mapping = () =>
+ mapping.Filters.Should().NotBeEmpty();
+
+ It should_set_the_name_of_the_added_filter_correctly = () =>
+ mapping.Filters.Single().Name.Should().Be(FilterClassConvention.FilterName);
+
+ It should_set_the_condition_of_the_added_filter_correctly = () =>
+ mapping.Filters.Single().Condition.Should().Be(FilterClassConvention.FilterCondition);
+
+ static FluentNHibernate.PersistenceModel model;
+ static ClassMapping mapping;
+}
+
+public class when_applying_a_filter_to_a_one_to_many_using_conventions
+{
+ Establish context = () =>
+ {
+ model = new FluentNHibernate.PersistenceModel();
+ model.Conventions.Add();
+ model.Add(new FilterTargetMap());
+ model.Add(new FilterChildTargetMap());
+ };
+
+ Because of = () =>
+ {
+ var classMapping = model.BuildMappingFor();
+ mapping = classMapping.Collections.Single(x => x.Relationship is OneToManyMapping);
+ };
+
+ It should_add_a_filter_to_the_one_to_many_relationship_s_mapping = () =>
+ mapping.Filters.Should().NotBeEmpty();
+
+ It should_set_the_name_of_the_added_filter_correctly = () =>
+ mapping.Filters.Single().Name.Should().Be(FilterHasManyConvention.FilterName);
+
+ It should_set_the_condition_of_the_added_filter_correctly = () =>
+ mapping.Filters.Single().Name.Should().Be(FilterHasManyConvention.FilterName);
+
+ static FluentNHibernate.PersistenceModel model;
+ static CollectionMapping mapping;
+}
+
+public class when_applying_a_filter_to_a_many_to_many_using_conventions
+{
+ Establish context = () =>
+ {
+ model = new FluentNHibernate.PersistenceModel();
+ model.Conventions.Add();
+ model.Add(new FilterTargetMap());
+ model.Add(new FilterChildTargetMap());
+ };
+
+ Because of = () =>
+ {
+ var classMapping = model.BuildMappingFor();
+ mapping = classMapping.Collections.Single(x => x.Relationship is ManyToManyMapping);
+ };
+
+ It should_add_a_filter_to_the_one_to_many_relationship_s_mapping = () =>
+ mapping.Filters.Should().NotBeEmpty();
+
+ It should_set_the_name_of_the_added_filter_correctly = () =>
+ mapping.Filters.Single().Name.Should().Be(FilterHasManyConvention.FilterName);
+
+ It should_set_the_condition_of_the_added_filter_correctly = () =>
+ mapping.Filters.Single().Name.Should().Be(FilterHasManyConvention.FilterName);
+
+ static FluentNHibernate.PersistenceModel model;
+ static CollectionMapping mapping;
}
diff --git a/src/FluentNHibernate.Specs/Conventions/BiDirectionalKeysSpecs.cs b/src/FluentNHibernate.Specs/Conventions/BiDirectionalKeysSpecs.cs
index 2345627b6..f91a73244 100644
--- a/src/FluentNHibernate.Specs/Conventions/BiDirectionalKeysSpecs.cs
+++ b/src/FluentNHibernate.Specs/Conventions/BiDirectionalKeysSpecs.cs
@@ -1,36 +1,36 @@
-using System.Linq;
-using FluentNHibernate.MappingModel.ClassBased;
-using FluentNHibernate.Specs.Conventions.Fixtures;
-using Machine.Specifications;
-using FluentAssertions;
-
-namespace FluentNHibernate.Specs.Conventions;
-
-public class when_mapping_a_many_to_one_one_to_many_bi_directional_relationship
-{
- Establish context = () =>
- {
- model = new FluentNHibernate.PersistenceModel();
- model.Add(new ParentMap());
- model.Add(new ChildMap());
- };
-
- Because of = () =>
- {
- var mappings = model.BuildMappings();
- parent = mappings.SelectMany(x => x.Classes).FirstOrDefault(x => x.Type == typeof(Parent));
- child = mappings.SelectMany(x => x.Classes).FirstOrDefault(x => x.Type == typeof(Child));
- };
-
- [Ignore("Ignored due to a regression this code caused - as this feature was added only as an experiment, I doubt anyone will miss it for the time being.")]
- It should_use_the_many_to_one_columns_for_the_one_to_many_key = () =>
- parent.Collections.Single().Key.Columns.Select(x => x.Name).Should().ContainSingle(name => name == "one" || name == "two");
-
- [Ignore("Ignored due to a regression this code caused - as this feature was added only as an experiment, I doubt anyone will miss it for the time being.")]
- It shouldnt_alter_the_many_to_one_columns = () =>
- child.References.Single().Columns.Select(x => x.Name).Should().ContainSingle(name => name == "one" || name == "two");
-
- static FluentNHibernate.PersistenceModel model;
- static ClassMapping parent;
- static ClassMapping child;
+using System.Linq;
+using FluentNHibernate.MappingModel.ClassBased;
+using FluentNHibernate.Specs.Conventions.Fixtures;
+using Machine.Specifications;
+using FluentAssertions;
+
+namespace FluentNHibernate.Specs.Conventions;
+
+public class when_mapping_a_many_to_one_one_to_many_bi_directional_relationship
+{
+ Establish context = () =>
+ {
+ model = new FluentNHibernate.PersistenceModel();
+ model.Add(new ParentMap());
+ model.Add(new ChildMap());
+ };
+
+ Because of = () =>
+ {
+ var mappings = model.BuildMappings();
+ parent = mappings.SelectMany(x => x.Classes).FirstOrDefault(x => x.Type == typeof(Parent));
+ child = mappings.SelectMany(x => x.Classes).FirstOrDefault(x => x.Type == typeof(Child));
+ };
+
+ [Ignore("Ignored due to a regression this code caused - as this feature was added only as an experiment, I doubt anyone will miss it for the time being.")]
+ It should_use_the_many_to_one_columns_for_the_one_to_many_key = () =>
+ parent.Collections.Single().Key.Columns.Select(x => x.Name).Should().ContainSingle(name => name == "one" || name == "two");
+
+ [Ignore("Ignored due to a regression this code caused - as this feature was added only as an experiment, I doubt anyone will miss it for the time being.")]
+ It shouldnt_alter_the_many_to_one_columns = () =>
+ child.References.Single().Columns.Select(x => x.Name).Should().ContainSingle(name => name == "one" || name == "two");
+
+ static FluentNHibernate.PersistenceModel model;
+ static ClassMapping parent;
+ static ClassMapping child;
}
diff --git a/src/FluentNHibernate.Specs/Conventions/CollectionTypeChangeSpecs.cs b/src/FluentNHibernate.Specs/Conventions/CollectionTypeChangeSpecs.cs
index e768390f3..06462b900 100644
--- a/src/FluentNHibernate.Specs/Conventions/CollectionTypeChangeSpecs.cs
+++ b/src/FluentNHibernate.Specs/Conventions/CollectionTypeChangeSpecs.cs
@@ -1,38 +1,38 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using FluentNHibernate.MappingModel.ClassBased;
-using FluentNHibernate.MappingModel.Collections;
-using FluentNHibernate.Specs.Conventions.Fixtures;
-using Machine.Specifications;
-using FluentAssertions;
-
-namespace FluentNHibernate.Specs.Conventions;
-
-public class when_changing_the_collection_type_with_conventions
-{
- Establish context = () =>
- {
- model = new FluentNHibernate.PersistenceModel();
- model.Conventions.Add();
- model.Add(new CollectionTargetMap());
- model.Add(new CollectionChildTargetMap());
- };
-
- Because of = () =>
- mapping = model.BuildMappingFor();
-
- It should_be_able_to_change_a_bag_to_a_list = () =>
- mapping.Collections
- .Single(x => x.Name == "Bag")
- .Collection.Should().Be(Collection.List);
-
- It should_be_able_to_change_a_set_to_a_list = () =>
- mapping.Collections
- .Single(x => x.Name == "Set")
- .Collection.Should().Be(Collection.List);
-
- static FluentNHibernate.PersistenceModel model;
- static ClassMapping mapping;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using FluentNHibernate.MappingModel.ClassBased;
+using FluentNHibernate.MappingModel.Collections;
+using FluentNHibernate.Specs.Conventions.Fixtures;
+using Machine.Specifications;
+using FluentAssertions;
+
+namespace FluentNHibernate.Specs.Conventions;
+
+public class when_changing_the_collection_type_with_conventions
+{
+ Establish context = () =>
+ {
+ model = new FluentNHibernate.PersistenceModel();
+ model.Conventions.Add();
+ model.Add(new CollectionTargetMap());
+ model.Add(new CollectionChildTargetMap());
+ };
+
+ Because of = () =>
+ mapping = model.BuildMappingFor();
+
+ It should_be_able_to_change_a_bag_to_a_list = () =>
+ mapping.Collections
+ .Single(x => x.Name == "Bag")
+ .Collection.Should().Be(Collection.List);
+
+ It should_be_able_to_change_a_set_to_a_list = () =>
+ mapping.Collections
+ .Single(x => x.Name == "Set")
+ .Collection.Should().Be(Collection.List);
+
+ static FluentNHibernate.PersistenceModel model;
+ static ClassMapping mapping;
}
diff --git a/src/FluentNHibernate.Specs/Conventions/ComponentConventionSpecs.cs b/src/FluentNHibernate.Specs/Conventions/ComponentConventionSpecs.cs
index fa1d5a29e..6a45da631 100644
--- a/src/FluentNHibernate.Specs/Conventions/ComponentConventionSpecs.cs
+++ b/src/FluentNHibernate.Specs/Conventions/ComponentConventionSpecs.cs
@@ -1,82 +1,82 @@
-using FluentAssertions;
-using FluentNHibernate.Conventions;
-using FluentNHibernate.Conventions.Instances;
-using FluentNHibernate.Mapping;
-using FluentNHibernate.MappingModel.ClassBased;
-using Machine.Specifications;
-using System.Linq;
-
-namespace FluentNHibernate.Specs.Conventions;
-
-public class when_specifying_component_convention
-{
- Establish context = () =>
- {
- model = new FluentNHibernate.PersistenceModel();
- model.Conventions.Add();
- model.Add(new AddressMap());
- model.Add(new EntityWithComponentMap());
- };
-
- Because of = () =>
- {
- mapping = model.BuildMappingFor();
- };
-
- It should_be_able_to_specify_column_name = () =>
- {
- var property = mapping.Components.First()
- .Properties.Single(x => x.Name == "Count");
-
- property.Columns.FirstOrDefault().Name.Should().Be("different");
- };
-
- private static FluentNHibernate.PersistenceModel model;
- private static ClassMapping mapping;
-}
-
-public class EntityWithComponent
-{
- public int Id { get; set; }
- public string Description { get; set; }
- public Address Address { get; set; }
-}
-
-public class Address
-{
- public int Count { get; set; }
- public string Line1 { get; set; }
- public string Line2 { get; set; }
-}
-
-internal class AddressMap : ComponentMap
-{
- public AddressMap()
- {
- Map(x => x.Line1);
- Map(x => x.Line2);
- Map(x => x.Count);
- }
-}
-
-public class ComponentConvention : IComponentConvention
-{
- public void Apply(IComponentInstance instance)
- {
- if (instance.Type == typeof(Address))
- {
- var type = instance.Properties.First(p => p.Type == typeof(int));
- type.Column("different");
- }
- }
-}
-
-public class EntityWithComponentMap : ClassMap
-{
- public EntityWithComponentMap()
- {
- Id(x => x.Id);
- Map(x => x.Description);
- Component(x => x.Address);
- }
+using FluentAssertions;
+using FluentNHibernate.Conventions;
+using FluentNHibernate.Conventions.Instances;
+using FluentNHibernate.Mapping;
+using FluentNHibernate.MappingModel.ClassBased;
+using Machine.Specifications;
+using System.Linq;
+
+namespace FluentNHibernate.Specs.Conventions;
+
+public class when_specifying_component_convention
+{
+ Establish context = () =>
+ {
+ model = new FluentNHibernate.PersistenceModel();
+ model.Conventions.Add();
+ model.Add(new AddressMap());
+ model.Add(new EntityWithComponentMap());
+ };
+
+ Because of = () =>
+ {
+ mapping = model.BuildMappingFor();
+ };
+
+ It should_be_able_to_specify_column_name = () =>
+ {
+ var property = mapping.Components.First()
+ .Properties.Single(x => x.Name == "Count");
+
+ property.Columns.FirstOrDefault().Name.Should().Be("different");
+ };
+
+ private static FluentNHibernate.PersistenceModel model;
+ private static ClassMapping mapping;
+}
+
+public class EntityWithComponent
+{
+ public int Id { get; set; }
+ public string Description { get; set; }
+ public Address Address { get; set; }
+}
+
+public class Address
+{
+ public int Count { get; set; }
+ public string Line1 { get; set; }
+ public string Line2 { get; set; }
+}
+
+internal class AddressMap : ComponentMap
+{
+ public AddressMap()
+ {
+ Map(x => x.Line1);
+ Map(x => x.Line2);
+ Map(x => x.Count);
+ }
+}
+
+public class ComponentConvention : IComponentConvention
+{
+ public void Apply(IComponentInstance instance)
+ {
+ if (instance.Type == typeof(Address))
+ {
+ var type = instance.Properties.First(p => p.Type == typeof(int));
+ type.Column("different");
+ }
+ }
+}
+
+public class EntityWithComponentMap : ClassMap
+{
+ public EntityWithComponentMap()
+ {
+ Id(x => x.Id);
+ Map(x => x.Description);
+ Component(x => x.Address);
+ }
}
diff --git a/src/FluentNHibernate.Specs/Conventions/ConventionBuilderSpecs.cs b/src/FluentNHibernate.Specs/Conventions/ConventionBuilderSpecs.cs
index 4c3b50886..7ad2893c0 100644
--- a/src/FluentNHibernate.Specs/Conventions/ConventionBuilderSpecs.cs
+++ b/src/FluentNHibernate.Specs/Conventions/ConventionBuilderSpecs.cs
@@ -1,35 +1,35 @@
-using System.Linq;
-using FluentNHibernate.Conventions;
-using FluentNHibernate.Conventions.Helpers;
-using FluentNHibernate.MappingModel.ClassBased;
-using FluentNHibernate.Specs.Conventions.Fixtures;
-using Machine.Specifications;
-using FluentAssertions;
-
-namespace FluentNHibernate.Specs.Conventions;
-
-public class when_a_convention_builder_is_used_for_properties
-{
- Establish context = () =>
- {
- model = new FluentNHibernate.PersistenceModel();
- model.Add(new TwoPropertyEntityMap());
- model.Conventions.Add(
- ConventionBuilder.Property.When(
- z => z.Expect(c => c.Name == "TargetProperty"),
- z => z.CustomSqlType("EXAMPLE")));
- };
-
- Because of = () =>
- mapping = model.BuildMappingFor();
-
- It shouldnt_apply_the_convention_to_any_properties_that_dont_match_the_acceptance_criteria = () =>
- mapping.Properties.Single(x => x.Name == "OtherProperty").Columns.Single().SqlType.Should().NotBe("EXAMPLE");
-
- It should_apply_the_convention_to_any_properties_that_match_the_acceptance_criteria = () =>
- mapping.Properties.Single(x => x.Name == "TargetProperty").Columns.Single().SqlType.Should().Be("EXAMPLE");
-
- static IPropertyConvention conventions;
- static FluentNHibernate.PersistenceModel model;
- static ClassMapping mapping;
+using System.Linq;
+using FluentNHibernate.Conventions;
+using FluentNHibernate.Conventions.Helpers;
+using FluentNHibernate.MappingModel.ClassBased;
+using FluentNHibernate.Specs.Conventions.Fixtures;
+using Machine.Specifications;
+using FluentAssertions;
+
+namespace FluentNHibernate.Specs.Conventions;
+
+public class when_a_convention_builder_is_used_for_properties
+{
+ Establish context = () =>
+ {
+ model = new FluentNHibernate.PersistenceModel();
+ model.Add(new TwoPropertyEntityMap());
+ model.Conventions.Add(
+ ConventionBuilder.Property.When(
+ z => z.Expect(c => c.Name == "TargetProperty"),
+ z => z.CustomSqlType("EXAMPLE")));
+ };
+
+ Because of = () =>
+ mapping = model.BuildMappingFor();
+
+ It shouldnt_apply_the_convention_to_any_properties_that_dont_match_the_acceptance_criteria = () =>
+ mapping.Properties.Single(x => x.Name == "OtherProperty").Columns.Single().SqlType.Should().NotBe("EXAMPLE");
+
+ It should_apply_the_convention_to_any_properties_that_match_the_acceptance_criteria = () =>
+ mapping.Properties.Single(x => x.Name == "TargetProperty").Columns.Single().SqlType.Should().Be("EXAMPLE");
+
+ static IPropertyConvention conventions;
+ static FluentNHibernate.PersistenceModel model;
+ static ClassMapping mapping;
}
diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/Child.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/Child.cs
index 74ab45e0f..94415f6f6 100644
--- a/src/FluentNHibernate.Specs/Conventions/Fixtures/Child.cs
+++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/Child.cs
@@ -1,19 +1,19 @@
-using FluentNHibernate.Mapping;
-
-namespace FluentNHibernate.Specs.Conventions.Fixtures;
-
-public class Child
-{
- public int Id { get; set; }
- public Parent Parent { get; set; }
-}
-
-public class ChildMap : ClassMap
-{
- public ChildMap()
- {
- Id(x => x.Id);
- References(x => x.Parent)
- .Columns("one", "two");
- }
+using FluentNHibernate.Mapping;
+
+namespace FluentNHibernate.Specs.Conventions.Fixtures;
+
+public class Child
+{
+ public int Id { get; set; }
+ public Parent Parent { get; set; }
+}
+
+public class ChildMap : ClassMap
+{
+ public ChildMap()
+ {
+ Id(x => x.Id);
+ References(x => x.Parent)
+ .Columns("one", "two");
+ }
}
diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionConvention.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionConvention.cs
index 00d932baa..e14bbcf23 100644
--- a/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionConvention.cs
+++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionConvention.cs
@@ -1,16 +1,16 @@
-using System;
-using FluentNHibernate.Conventions;
-using FluentNHibernate.Conventions.Instances;
-
-namespace FluentNHibernate.Specs.Conventions.Fixtures;
-
-public class CollectionConvention : ICollectionConvention
-{
- public const string FilterName = "TestFilterName";
- public const string FilterCondition = "TestFilterCondition";
-
- public void Apply(ICollectionInstance instance)
- {
- instance.AsList();
- }
+using System;
+using FluentNHibernate.Conventions;
+using FluentNHibernate.Conventions.Instances;
+
+namespace FluentNHibernate.Specs.Conventions.Fixtures;
+
+public class CollectionConvention : ICollectionConvention
+{
+ public const string FilterName = "TestFilterName";
+ public const string FilterCondition = "TestFilterCondition";
+
+ public void Apply(ICollectionInstance instance)
+ {
+ instance.AsList();
+ }
}
diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionTarget.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionTarget.cs
index 737fdf777..f20879ad5 100644
--- a/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionTarget.cs
+++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/CollectionTarget.cs
@@ -1,34 +1,34 @@
-using System.Collections.Generic;
-using FluentNHibernate.Mapping;
-
-namespace FluentNHibernate.Specs.Conventions.Fixtures;
-
-public class CollectionTarget
-{
- public int Id { get; set; }
- public IList Bag { get; set; }
- public ISet Set { get; set; }
-}
-
-public class CollectionChildTarget
-{
- public int Id { get; set; }
-}
-
-public class CollectionTargetMap : ClassMap
-{
- public CollectionTargetMap()
- {
- Id(x => x.Id);
- HasMany(x => x.Bag);
- HasMany(x => x.Set);
- }
-}
-
-public class CollectionChildTargetMap : ClassMap
-{
- public CollectionChildTargetMap()
- {
- Id(x => x.Id);
- }
+using System.Collections.Generic;
+using FluentNHibernate.Mapping;
+
+namespace FluentNHibernate.Specs.Conventions.Fixtures;
+
+public class CollectionTarget
+{
+ public int Id { get; set; }
+ public IList Bag { get; set; }
+ public ISet Set { get; set; }
+}
+
+public class CollectionChildTarget
+{
+ public int Id { get; set; }
+}
+
+public class CollectionTargetMap : ClassMap
+{
+ public CollectionTargetMap()
+ {
+ Id(x => x.Id);
+ HasMany(x => x.Bag);
+ HasMany(x => x.Set);
+ }
+}
+
+public class CollectionChildTargetMap : ClassMap
+{
+ public CollectionChildTargetMap()
+ {
+ Id(x => x.Id);
+ }
}
diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterClassConvention.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterClassConvention.cs
index 772f8a847..1970d9ca2 100644
--- a/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterClassConvention.cs
+++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterClassConvention.cs
@@ -1,37 +1,37 @@
-using FluentNHibernate.Conventions;
-using FluentNHibernate.Conventions.Instances;
-
-namespace FluentNHibernate.Specs.Conventions.Fixtures;
-
-public class FilterClassConvention : IClassConvention
-{
- public const string FilterName = "TestFilterName";
- public const string FilterCondition = "TestFilterCondition";
-
- public void Apply(IClassInstance instance)
- {
- instance.ApplyFilter(FilterName, FilterCondition);
- }
-}
-
-public class FilterHasManyConvention : IHasManyConvention
-{
- public const string FilterName = "TestFilterName";
- public const string FilterCondition = "TestFilterCondition";
-
- public void Apply(IOneToManyCollectionInstance instance)
- {
- instance.ApplyFilter(FilterName, FilterCondition);
- }
-}
-
-public class FilterHasManyToManyConvention : IHasManyToManyConvention
-{
- public const string FilterName = "TestFilterName";
- public const string FilterCondition = "TestFilterCondition";
-
- public void Apply(IManyToManyCollectionInstance instance)
- {
- instance.ApplyFilter(FilterName, FilterCondition);
- }
+using FluentNHibernate.Conventions;
+using FluentNHibernate.Conventions.Instances;
+
+namespace FluentNHibernate.Specs.Conventions.Fixtures;
+
+public class FilterClassConvention : IClassConvention
+{
+ public const string FilterName = "TestFilterName";
+ public const string FilterCondition = "TestFilterCondition";
+
+ public void Apply(IClassInstance instance)
+ {
+ instance.ApplyFilter(FilterName, FilterCondition);
+ }
+}
+
+public class FilterHasManyConvention : IHasManyConvention
+{
+ public const string FilterName = "TestFilterName";
+ public const string FilterCondition = "TestFilterCondition";
+
+ public void Apply(IOneToManyCollectionInstance instance)
+ {
+ instance.ApplyFilter(FilterName, FilterCondition);
+ }
+}
+
+public class FilterHasManyToManyConvention : IHasManyToManyConvention
+{
+ public const string FilterName = "TestFilterName";
+ public const string FilterCondition = "TestFilterCondition";
+
+ public void Apply(IManyToManyCollectionInstance instance)
+ {
+ instance.ApplyFilter(FilterName, FilterCondition);
+ }
}
diff --git a/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterTarget.cs b/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterTarget.cs
index cd3bbdf30..40497db9a 100644
--- a/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterTarget.cs
+++ b/src/FluentNHibernate.Specs/Conventions/Fixtures/FilterTarget.cs
@@ -1,34 +1,34 @@
-using System.Collections.Generic;
-using FluentNHibernate.Mapping;
-
-namespace FluentNHibernate.Specs.Conventions.Fixtures;
-
-public class FilterTarget
-{
- public int Id { get; set; }
- public IList