public void Test__Set_Fail() { // Arrange var source = new EntityA { Name1 = "A" }; var multiTypeItems = new MultiTypeBinderBuilder <Key>() .WithType <EntityA>(opt1 => opt1 .WithProperty(x => x.Name1, opt2 => opt2 .Bind(Key.Name) .WithGetter(x => x.Name1) .WithSetter((x, y) => x.Name1 = y)) .FinalizeType()) .WithType <EntityB>(opt1 => opt1 .WithProperty(x => x.Name2, opt2 => opt2 .Bind(Key.Name) .WithGetter(x => x.Name2) .WithSetter((x, y) => x.Name2 = y)) .FinalizeType()) .Build() .Map(new List <object> { source }); // Act, Assert Assert.Throws <InvalidCastException>(() => multiTypeItems.First()[Key.Name] = 123); }
public void Test__Set() { // Arrange var a = new EntityA { Name1 = "A" }; var b = new EntityB { Name2 = "B" }; var multiTypeItems = new MultiTypeBinderBuilder <Key>() .WithType <EntityA>(opt1 => opt1 .WithProperty(x => x.Name1, opt2 => opt2 .Bind(Key.Name) .WithGetter(x => x.Name1) .WithSetter((x, y) => x.Name1 = y)) .FinalizeType()) .WithType <EntityB>(opt1 => opt1 .WithProperty(x => x.Name2, opt2 => opt2 .Bind(Key.Name) .WithGetter(x => x.Name2) .WithSetter((x, y) => x.Name2 = y)) .FinalizeType()) .Build() .Map(new List <object> { a, b }); // Act multiTypeItems.First()[Key.Name] = "updated A"; multiTypeItems.Last()[Key.Name] = "updated B"; var v1 = multiTypeItems.First()[Key.Name]; var v2 = multiTypeItems.Last()[Key.Name]; // Assert Assert.Equal(2, multiTypeItems.Count); Assert.Equal("updated A", v1); Assert.Equal("updated B", v2); }