first commit

This commit is contained in:
2020-06-09 00:12:01 +02:00
commit 0f335617b4
13 changed files with 542 additions and 0 deletions

View 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}";
}
}

View 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);
}
}
}

View 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);
}
}
}

View 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());
}
}
}