public void FindByIdWorks() { var person = new PersonSimple { TenantId = 1, Email = "*****@*****.**", Name = "Lubos" }; Func <IObjectDBTransaction, ISimplePersonTable> creator; using (var tr = _db.StartTransaction()) { creator = tr.InitRelation <ISimplePersonTable>("PersonSimple"); var personSimpleTable = creator(tr); personSimpleTable.Insert(person); tr.Commit(); } using (var tr = _db.StartTransaction()) { var personSimpleTable = creator(tr); var foundPerson = personSimpleTable.FindById(person.TenantId, person.Email); Assert.True(person.Equals(foundPerson)); Assert.Throws <BTDBException>(() => personSimpleTable.FindById(0, "*****@*****.**")); foundPerson = personSimpleTable.FindByIdOrDefault(person.TenantId, person.Email); Assert.True(person.Equals(foundPerson)); foundPerson = personSimpleTable.FindByIdOrDefault(0, "*****@*****.**"); Assert.Equal(null, foundPerson); } }
public void BasicRelationWithTenantApartWorks() { var person = new PersonSimple { Email = "*****@*****.**", Name = "Lubos" }; Func <IObjectDBTransaction, ISimplePersonTableWithTenantId> creator; using (var tr = _db.StartTransaction()) { creator = tr.InitRelation <ISimplePersonTableWithTenantId>("PersonSimpleTenantId"); var personSimpleTable = creator(tr); personSimpleTable.TenantId = 1; personSimpleTable.Insert(person); personSimpleTable.TenantId = 2; personSimpleTable.Insert(person); tr.Commit(); } using (var tr = _db.StartTransaction()) { var personSimpleTable = creator(tr); personSimpleTable.TenantId = 0; Assert.False(personSimpleTable.RemoveById(person.Email)); personSimpleTable.TenantId = 1; Assert.True(personSimpleTable.RemoveById(person.Email)); personSimpleTable.TenantId = 2; Assert.True(personSimpleTable.RemoveById(person.Email)); } }
public void UpsertWorks() { var person = new PersonSimple { TenantId = 1, Email = "*****@*****.**", Name = "Boris" }; Func <IObjectDBTransaction, ISimplePersonTable> creator; using (var tr = _db.StartTransaction()) { creator = tr.InitRelation <ISimplePersonTable>("Person"); var personSimpleTable = creator(tr); Assert.True(personSimpleTable.Upsert(person), "Is newly inserted"); tr.Commit(); } using (var tr = _db.StartTransaction()) { var personSimpleTable = creator(tr); person.Name = "Lubos"; Assert.False(personSimpleTable.Upsert(person), "Was already there"); var p = GetNext(personSimpleTable.GetEnumerator()); Assert.Equal("Lubos", p.Name); tr.Commit(); } using (var tr = _db.StartTransaction()) { var personSimpleTable = creator(tr); var p = GetNext(personSimpleTable.GetEnumerator()); Assert.Equal("Lubos", p.Name); } }
public void CanInsertAndEnumerate() { var personBoris = new PersonSimple { TenantId = 1, Email = "*****@*****.**", Name = "Boris" }; var personLubos = new PersonSimple { TenantId = 2, Email = "*****@*****.**", Name = "Lubos" }; Func <IObjectDBTransaction, ISimplePersonTable> creator; using (var tr = _db.StartTransaction()) { creator = tr.InitRelation <ISimplePersonTable>("Person"); var personSimpleTable = creator(tr); personSimpleTable.Insert(personBoris); personSimpleTable.Insert(personLubos); tr.Commit(); } using (var tr = _db.StartReadOnlyTransaction()) { var personSimpleTable = creator(tr); var enumerator = personSimpleTable.GetEnumerator(); Assert.True(enumerator.MoveNext()); var person = enumerator.Current; Assert.Equal(personBoris, person); Assert.True(enumerator.MoveNext()); person = enumerator.Current; Assert.Equal(personLubos, person); Assert.False(enumerator.MoveNext(), "Only one Person should be evaluated"); } }
public void UpdateWorks() { var person = new PersonSimple { TenantId = 1, Email = "*****@*****.**", Name = "Boris", Ratings = new Dictionary <string, IList <byte> > { { "Czech", new List <byte> { 1, 2, 1 } } }, }; Func <IObjectDBTransaction, ISimplePersonTable> creator; using (var tr = _db.StartTransaction()) { creator = tr.InitRelation <ISimplePersonTable>("Person"); var personSimpleTable = creator(tr); Assert.Throws <BTDBException>(() => personSimpleTable.Update(person)); personSimpleTable.Insert(person); tr.Commit(); } ReopenDb(); using (var tr = _db.StartTransaction()) { creator = tr.InitRelation <ISimplePersonTable>("Person"); var personSimpleTable = creator(tr); person.Name = "Lubos"; person.Ratings.Add("History", new List <byte> { 3 }); personSimpleTable.Update(person); tr.Commit(); } using (var tr = _db.StartTransaction()) { var personSimpleTable = creator(tr); var p = GetNext(personSimpleTable.GetEnumerator()); Assert.Equal("Lubos", p.Name); Assert.Equal(new List <byte> { 3 }, p.Ratings["History"]); } }
public void RemoveByIdThrowsWhenNotFound() { var person = new PersonSimple { TenantId = 1, Email = "*****@*****.**", Name = "Lubos" }; Func <IObjectDBTransaction, ISimplePersonTableWithVoidRemove> creator; using (var tr = _db.StartTransaction()) { creator = tr.InitRelation <ISimplePersonTableWithVoidRemove>("PersonSimpleVoidRemove"); var personSimpleTable = creator(tr); personSimpleTable.Insert(person); tr.Commit(); } using (var tr = _db.StartTransaction()) { var personSimpleTable = creator(tr); Assert.Throws <BTDBException>(() => personSimpleTable.RemoveById(0, "*****@*****.**")); personSimpleTable.RemoveById(person.TenantId, person.Email); } }
public void RemoveByIdWorks() { var person = new PersonSimple { TenantId = 1, Email = "*****@*****.**", Name = "Lubos" }; Func <IObjectDBTransaction, ISimplePersonTable> creator; using (var tr = _db.StartTransaction()) { creator = tr.InitRelation <ISimplePersonTable>("PersonSimple"); var personSimpleTable = creator(tr); personSimpleTable.Insert(person); tr.Commit(); } using (var tr = _db.StartTransaction()) { var personSimpleTable = creator(tr); Assert.False(personSimpleTable.RemoveById(0, "*****@*****.**")); Assert.True(personSimpleTable.RemoveById(person.TenantId, person.Email)); Assert.False(personSimpleTable.GetEnumerator().MoveNext()); } }