Skip to content

Commit

Permalink
Repro for type is not registered (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
yardee authored Nov 21, 2024
1 parent 4a97e43 commit 67491a5
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
39 changes: 39 additions & 0 deletions BTDBTest/ObjectDBTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2934,4 +2934,43 @@ public void CanRemovePropertyTogetherWithClass()
Assert.Equal(42, root.I);
}
}

public interface IFace
{
int I { get; set; }
}

public class ObjFace: IFace
{
public int I { get; set; }
}

public class RootObj
{
public IFace O { get; set; }
public int I { get; set; }
}

[Fact]
public void CanRemoveDerivedClassWhenPropertyWithBaseClassExists()
{
_db.RegisterType(typeof(RootObj));
_db.RegisterType(typeof(ObjFace));
using (var tr = _db.StartTransaction())
{
var root = tr.Singleton<RootObj>();
root.I = 42;
root.O = new ObjFace { I = 5 };
tr.Commit();
}

ReopenDb();
_db.RegisterType(typeof(RootObj));
using (var tr = _db.StartTransaction())
{
var root = tr.Singleton<RootObj>();
Assert.Equal(42, root.I);
Assert.Null(root.O);
}
}
}
46 changes: 46 additions & 0 deletions BTDBTest/ObjectDbTableUpgradeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,4 +1061,50 @@ public void CanRemovePropertyTogetherWithClass()
Assert.Equal(43, root.After);
}
}

public interface IFace
{
int I { get; set; }
}

public class ObjFace: IFace
{
public int I { get; set; }
}

public class RootObj
{
public IFace O { get; set; }
public int I { get; set; }
}

public interface IRootObjTable : IRelation<RootObj>
{
}

[Fact]
public void CanRemoveDerivedClassWhenPropertyWithBaseClassExists()
{
_db.RegisterType(typeof(ObjFace));
using (var tr = _db.StartTransaction())
{
var t = tr.GetRelation<IRootObjTable>();
var root = new RootObj
{
I = 42,
O = new ObjFace { I = 5 }
};
t.Upsert(root);
tr.Commit();
}

ReopenDb();
using (var tr = _db.StartTransaction())
{
var t = tr.GetRelation<IRootObjTable>();
var root = t.First();
Assert.Equal(42, root.I);
Assert.Null(root.O);
}
}
}

0 comments on commit 67491a5

Please sign in to comment.