public void FindRecord() { Guid id = Guid.NewGuid(); using (var dbContextBase = new DbContextBase(options, new Dictionary <string, Type>() { { "tbl", typeof(Connector) } }, new List <Table>())) { db.Setup(c => c.SetupDataContext("Table")); db.SetupGet(c => c.Instance).Returns(dbContextBase); db.SetupGet(c => c.DbSetEntityType).Returns(typeof(Connector)); dbContextBase.Add(new Connector { Id = id, Name = "init", Port = 123 }); dbContextBase.SaveChanges(); Assert.AreEqual(1, dbContextBase.Set <Connector>().Count(), "Inital state invalid"); var connector = db.Object.Find("Table", new object[] { id }); Assert.AreEqual("init", ((Connector)connector).Name); Assert.AreEqual(123, ((Connector)connector).Port); db.Verify(c => c.SetupDataContext("Table"), Times.Once); } }
public void UpdateRecordUpdatesToDb() { using (var dbContextBase = new DbContextBase(options, new Dictionary <string, Type>() { { "tbl", typeof(Connector) } }, new List <Table>())) { dbContextBase.Add(new Connector { Name = "init" }); dbContextBase.SaveChanges(); Assert.AreEqual(1, dbContextBase.Set <Connector>().Count(), "Inital state invalid"); db.SetupGet(c => c.Instance).Returns(dbContextBase); db.SetupGet(c => c.DbSetEntityType).Returns(typeof(Connector)); var connector = dbContextBase.Set <Connector>().First(); connector.Name = "updated"; db.Object.Update(connector); db.Object.Save(); Assert.AreEqual("updated", dbContextBase.Set <Connector>().First().Name); } }