public void AddItem_SampleValue_ReturnAddedItem() { //arrange IUntypedRecord rec = new KeyValRecord(_items, _recNo, 1, 0, null, null, null, _typeDefs, _config, null, ActionOnDuplicateKey.IgnoreItem); //act var result = rec.AddItem("I_someNum", "360"); //assert result.Should().BeOfType(typeof(KeyValItem <int>)); result.Key.Should().Be("I_someNum"); result.Value.Should().Be(360); result.ItemDef.Type.Should().Be(ItemType.Int); rec.Count.Should().Be(5); rec.RecNo.Should().Be(26); rec[0].Should().BeOfType(typeof(string)); rec[0].Should().Be("71941"); rec[3].Should().BeOfType(typeof(string)); rec[3].Should().Be("184"); rec[4].Should().BeOfType(typeof(string)); rec[4].Should().Be("360"); rec.Keys[4].Should().Be("I_someNum"); }
public void AddItem_ExistingKey_ReturnVoidItem() { //arrange IUntypedRecord rec = new KeyValRecord(_items, _recNo, 1, 0, null, null, null, _typeDefs, _config, null, ActionOnDuplicateKey.IgnoreItem); //act var result = rec.AddItem("blah", "someOtherBlah"); //assert result.Should().BeOfType(typeof(VoidKeyValItem)); result.Value.Should().BeNull(); rec.Count.Should().Be(4); rec.RecNo.Should().Be(26); rec[0].Should().BeOfType(typeof(string)); rec[0].Should().Be("71941"); rec[3].Should().BeOfType(typeof(string)); rec[3].Should().Be("184"); }
public void AddItem_CannotAlterFields_ReturnNull() { //arrange _config.AllowTransformToAlterFields = false; //it was set to true in test Initialize method IRecord rec = new KeyValRecord(_items, _recNo, 1, 0, null, null, null, _typeDefs, _config, null, ActionOnDuplicateKey.IgnoreItem); //act var result = rec.AddItem("I_someNum", 360); //assert result.Should().BeNull(); rec.Count.Should().Be(4); rec.RecNo.Should().Be(26); rec[0].Should().BeOfType(typeof(string)); rec[0].Should().Be("71941"); rec[3].Should().BeOfType(typeof(int)); rec[3].Should().Be(184); }
public void AddItem_SimpleValuesButCannotAlterFields_NoChange() { //arrange var items = new IItem[] { KeyValItem.CreateItem("IDCD_ID", "71941", _typeDefs), KeyValItem.CreateItem("blah", "blahblah", _typeDefs), KeyValItem.CreateItem("I_num", 243, _typeDefs) }; _config.AllowTransformToAlterFields = false; //it was set to true in test Initialize method var rec = new KeyValRecord(items, 19, 13, 0, null, null, null, _typeDefs, _config, null, ActionOnDuplicateKey.IgnoreItem); IRecord recR = rec; IUntypedRecord recU = rec; dynamic recD = rec; //act var result = rec.AddItem("I_alsoNum", 120); //assert result.Should().BeNull(); rec.Count.Should().Be(3); rec.RecNo.Should().Be(19); rec.SourceNo.Should().Be(13); rec.Keys[0].Should().Be("IDCD_ID"); rec.GetItem("IDCD_ID").Key.Should().Be("IDCD_ID"); recR[0].Should().Be("71941"); recU[0].Should().Be("71941"); Assert.AreEqual("71941", recD.IDCD_ID); rec[1].Should().Be("blahblah"); rec["blah"].Should().Be("blahblah"); Assert.AreEqual("blahblah", recD.blah); rec[2].Should().Be(243); rec["I_num"].Should().Be(243); recR["I_num"].Should().Be(243); recU["I_num"].Should().Be("243"); Assert.AreEqual(243, recD.I_num); //act2 result = rec.AddItem("foo", "bar"); //assert2 result.Should().BeNull(); rec.Count.Should().Be(3); rec.RecNo.Should().Be(19); rec.SourceNo.Should().Be(13); rec.Keys[0].Should().Be("IDCD_ID"); rec.GetItem("IDCD_ID").Key.Should().Be("IDCD_ID"); recR[0].Should().Be("71941"); recU[0].Should().Be("71941"); Assert.AreEqual("71941", recD.IDCD_ID); rec[1].Should().Be("blahblah"); rec["blah"].Should().Be("blahblah"); Assert.AreEqual("blahblah", recD.blah); rec[2].Should().Be(243); rec["I_num"].Should().Be(243); recR["I_num"].Should().Be(243); recU["I_num"].Should().Be("243"); Assert.AreEqual(243, recD.I_num); //act3 recD.I_NUMBER = 1356; //attempt to set a value of non-existing item is simply ignored(!) - this behavior may be revised //assert3 Assert.IsNull(recD.I_NUMBER); rec.Count.Should().Be(3); rec.RecNo.Should().Be(19); rec.SourceNo.Should().Be(13); rec.Keys[0].Should().Be("IDCD_ID"); rec.GetItem("IDCD_ID").Key.Should().Be("IDCD_ID"); recR[0].Should().Be("71941"); recU[0].Should().Be("71941"); Assert.AreEqual("71941", recD.IDCD_ID); rec[1].Should().Be("blahblah"); rec["blah"].Should().Be("blahblah"); Assert.AreEqual("blahblah", recD.blah); rec[2].Should().Be(243); rec["I_num"].Should().Be(243); recR["I_num"].Should().Be(243); recU["I_num"].Should().Be("243"); Assert.AreEqual(243, recD.I_num); }
public void AddItem_SimpleValues_CorrectData() { //arrange var items = new IItem[] { KeyValItem.CreateItem("IDCD_ID", "71941", _typeDefs), KeyValItem.CreateItem("blah", "blahblah", _typeDefs), KeyValItem.CreateItem("I_num", 243, _typeDefs) }; var rec = new KeyValRecord(items, 18, 12, 0, null, null, null, _typeDefs, _config, null, ActionOnDuplicateKey.IgnoreItem); IRecord recR = rec; IUntypedRecord recU = rec; dynamic recD = rec; //act var result = rec.AddItem("I_alsoNum", 120); //assert result.Should().BeOfType <KeyValItem <int> >(); result.Key.Should().Be("I_alsoNum"); result.Value.Should().Be(120); rec.Count.Should().Be(4); rec.RecNo.Should().Be(18); rec.SourceNo.Should().Be(12); rec.Keys[0].Should().Be("IDCD_ID"); rec.GetItem("IDCD_ID").Key.Should().Be("IDCD_ID"); recR[0].Should().Be("71941"); recU[0].Should().Be("71941"); Assert.AreEqual("71941", recD.IDCD_ID); rec[1].Should().Be("blahblah"); rec["blah"].Should().Be("blahblah"); Assert.AreEqual("blahblah", recD.blah); rec[2].Should().Be(243); rec["I_num"].Should().Be(243); recR["I_num"].Should().Be(243); recU["I_num"].Should().Be("243"); Assert.AreEqual(243, recD.I_num); rec[3].Should().Be(120); recR[3].Should().Be(120); recU["I_alsoNum"].Should().Be("120"); recR[3].Should().Be(120); recU["I_alsoNum"].Should().Be("120"); Assert.AreEqual(120, recD.I_alsoNum); //act2 rec.AddItem("foo", "bar"); //assert2 rec.Count.Should().Be(5); rec.RecNo.Should().Be(18); rec.SourceNo.Should().Be(12); rec.Keys[0].Should().Be("IDCD_ID"); rec.GetItem("IDCD_ID").Key.Should().Be("IDCD_ID"); recR[0].Should().Be("71941"); recU[0].Should().Be("71941"); Assert.AreEqual("71941", recD.IDCD_ID); rec[1].Should().Be("blahblah"); rec["blah"].Should().Be("blahblah"); Assert.AreEqual("blahblah", recD.blah); rec[2].Should().Be(243); rec["I_num"].Should().Be(243); recR["I_num"].Should().Be(243); recU["I_num"].Should().Be("243"); Assert.AreEqual(243, recD.I_num); rec[3].Should().Be(120); recR[3].Should().Be(120); recU["I_alsoNum"].Should().Be("120"); recR[3].Should().Be(120); recU["I_alsoNum"].Should().Be("120"); Assert.AreEqual(120, recD.I_alsoNum); rec[4].Should().Be("bar"); recR[4].Should().Be("bar"); recU["foo"].Should().Be("bar"); recR[4].Should().Be("bar"); recU["foo"].Should().Be("bar"); Assert.AreEqual("bar", recD.foo); //act3 recD.I_NUMBER = 1356; //assert3 rec.Count.Should().Be(6); rec.RecNo.Should().Be(18); rec.SourceNo.Should().Be(12); rec.Keys[0].Should().Be("IDCD_ID"); rec.GetItem("IDCD_ID").Key.Should().Be("IDCD_ID"); recR[0].Should().Be("71941"); recU[0].Should().Be("71941"); Assert.AreEqual("71941", recD.IDCD_ID); rec[1].Should().Be("blahblah"); rec["blah"].Should().Be("blahblah"); Assert.AreEqual("blahblah", recD.blah); rec[2].Should().Be(243); rec["I_num"].Should().Be(243); recR["I_num"].Should().Be(243); recU["I_num"].Should().Be("243"); Assert.AreEqual(243, recD.I_num); rec[3].Should().Be(120); recR[3].Should().Be(120); recU["I_alsoNum"].Should().Be("120"); recR[3].Should().Be(120); recU["I_alsoNum"].Should().Be("120"); Assert.AreEqual(120, recD.I_alsoNum); rec[4].Should().Be("bar"); recR[4].Should().Be("bar"); recU["foo"].Should().Be("bar"); recR[4].Should().Be("bar"); recU["foo"].Should().Be("bar"); Assert.AreEqual("bar", recD.foo); rec[5].Should().Be(1356); recR[5].Should().Be(1356); recU["I_NUMBER"].Should().Be("1356"); recR[5].Should().Be(1356); recU["I_NUMBER"].Should().Be("1356"); Assert.AreEqual(1356, recD.I_NUMBER); }