first commit
This commit is contained in:
13
ConsoleApp1/Model/Person.cs
Normal file
13
ConsoleApp1/Model/Person.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace ConsoleApp1.Model
|
||||
{
|
||||
public class Person
|
||||
{
|
||||
public virtual Guid Id { get; set; }
|
||||
public virtual string FirstName { get; set; }
|
||||
public virtual string LastName { get; set; }
|
||||
|
||||
public virtual string GetFullName() => $"{FirstName} {LastName}";
|
||||
}
|
||||
}
|
15
ConsoleApp1/Model/PersonMap.cs
Normal file
15
ConsoleApp1/Model/PersonMap.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using NHibernate.Mapping.ByCode;
|
||||
using NHibernate.Mapping.ByCode.Conformist;
|
||||
|
||||
namespace ConsoleApp1.Model
|
||||
{
|
||||
public class PersonMap : ClassMapping<Person>
|
||||
{
|
||||
public PersonMap()
|
||||
{
|
||||
Id(x => x.Id, m => m.Generator(Generators.GuidComb));
|
||||
Property(x => x.FirstName);
|
||||
Property(x => x.LastName);
|
||||
}
|
||||
}
|
||||
}
|
23
ConsoleApp1/Model/PersonMapTest.cs
Normal file
23
ConsoleApp1/Model/PersonMapTest.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Xml.Serialization;
|
||||
using NHibernate.Mapping.ByCode;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ConsoleApp1.Model
|
||||
{
|
||||
[TestFixture]
|
||||
public class PersonMapTest
|
||||
{
|
||||
[Test]
|
||||
public void CanGenerateXmlMapping()
|
||||
{
|
||||
var mapper = new ModelMapper();
|
||||
mapper.AddMapping<PersonMap>();
|
||||
|
||||
var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
|
||||
var xmlSerializer = new XmlSerializer(mapping.GetType());
|
||||
|
||||
xmlSerializer.Serialize(Console.Out, mapping);
|
||||
}
|
||||
}
|
||||
}
|
23
ConsoleApp1/Model/PersonTest.cs
Normal file
23
ConsoleApp1/Model/PersonTest.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ConsoleApp1.Model
|
||||
{
|
||||
[TestFixture]
|
||||
public class PersonTest
|
||||
{
|
||||
[Test]
|
||||
public void GetFullNameTest()
|
||||
{
|
||||
var person = new Person
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "Kees"
|
||||
};
|
||||
|
||||
Assert.AreEqual("Test", person.FirstName);
|
||||
Assert.AreEqual("Kees", person.LastName);
|
||||
|
||||
Assert.AreEqual("Test Kees", person.GetFullName());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user