public void TestCreate() { uint id; using (IRepositoryConnection connection = this.Factory.GetConnection()) { IRepository <Person> repository = connection.GetRepository <Person>(); Person person = new Person() { Name = "John", TelephoneNumber = "12345" }; Assert.IsFalse(person.HasIdentity, "Person does not yet have an identity"); repository.Create(person); Assert.IsTrue(person.HasIdentity, "Person now has an identity"); id = person.GetIdentity().Value; } using (IRepositoryConnection connection = this.Factory.GetConnection()) { IRepository <Person> repository = connection.GetRepository <Person>(); Person person = repository.Read(new Identity <uint>(typeof(Person), id)); Assert.AreEqual("John", person.Name, "Correct name"); } }
/// <summary> /// <para> /// Overloaded. Creates this entity within the repository exposed by the given <paramref name="connection"/>. /// </para> /// </summary> /// <param name="connection"> /// A <see cref="IRepositoryConnection"/> /// </param> public virtual void Create(IRepositoryConnection connection) { if (connection == null) { throw new ArgumentNullException("connection"); } IRepository repository = connection.GetRepository(this.GetType()); repository.Create(this); this.OnCreated(); }
public void TestCreateWithIdentity() { using (IRepositoryConnection connection = this.Factory.GetConnection()) { IRepository <Person> repository = connection.GetRepository <Person>(); Person person = new Person() { Name = "John", TelephoneNumber = "12345" }; Assert.IsFalse(person.HasIdentity, "Person does not yet have an identity"); person.SetIdentity(1); repository.Create(person); Assert.Fail("Test should not reach this point"); } }