public void FromTypesBuildTransfer_MustOk() { var t = IdentityMapNameTransfer.FromTypesAttributes(new Type[] { typeof(object) }); Assert.AreEqual(1, t.Count); Assert.AreEqual(typeof(object), t.Keys.First()); }
public void GivenNullInstance_ReturnPropertyName() { var transfer = new IdentityMapNameTransfer(new Dictionary <PropertyIdentity, string>()); var val = transfer.Transfer(null, "a"); Assert.AreEqual("a", val); }
public NamedAnalysis() { type = typeof(StudentClass); nameTransfer = IdentityMapNameTransfer.FromTypeAttributes(type); objectNamedCreator = new ObjectNamedCreator(type, nameTransfer, IdentityNamedCreator.Instance, ReflectionPropertyVisitor.Instance); }
public void GivenNullArgsCall_MustThrowException() { var transfer = new IdentityMapNameTransfer(new Dictionary <PropertyIdentity, string>()); Assert.ThrowsException <ArgumentException>(() => transfer.Transfer(new object(), null)); Assert.ThrowsException <ArgumentNullException>(() => new IdentityMapNameTransfer(null)); }
public NamedBuild() { var type = typeof(StudentClass); var nameTransfer = IdentityMapNameTransfer.FromTypeAttributes(type); var builder = new ConfigurationBuilder(); var map = new Dictionary <string, string> { ["Name0"] = "1", ["Name1"] = "2", ["Name2"] = "3", ["Name3"] = "4", ["Name4"] = "5" }; for (int i = 1; i < 5; i++) { for (int j = 0; j < 4; j++) { map[$"Student" + i + ":" + "Student" + j] = (i * j + j).ToString(); } } builder.AddInMemoryCollection(map); config = builder.BuildSavable(); objectNamedCreatorRef = new ObjectNamedCreator(type, nameTransfer, IdentityNamedCreator.Instance, ReflectionPropertyVisitor.Instance); valueReflection = objectNamedCreatorRef.Build(config); valueReflection = objectNamedCreatorRef.Build(valueReflection, config); objectNamedCreatorCom = new ObjectNamedCreator(type, nameTransfer, IdentityNamedCreator.Instance, CompilePropertyVisitor.Instance); valueCompiled = objectNamedCreatorCom.Build(config); valueCompiled = objectNamedCreatorCom.Build(valueCompiled, config); }
public void CreateWithRedirectPath_MustProxThatPaths(Type type, string prefx) { var root = ConfigHelper.CreateEmptyRoot(); var prox = ProxyUtil.CreateProx(); var named = new Dictionary <PropertyIdentity, string> { [new PropertyIdentity(typeof(SomeBox), nameof(RedirectClass.Age))] = "Age", [new PropertyIdentity(typeof(SomeBox), nameof(RedirectClass.Name))] = prefx + "Name", [new PropertyIdentity(typeof(SomeBox), nameof(RedirectClass.Score))] = prefx + "Score", }; var map = new IdentityMapNameTransfer(named); var creator = new ProxyCreator(prox, type, map, IdentityNamedCreator.Instance, CompilePropertyVisitor.Instance); creator.Analysis(); var x = (dynamic)creator.Build(root); x.Red.Age = 123; x.Red.Name = "456"; x.Red.Score = 789.123d; root["Age"] = "123"; root[prefx + "Name"] = "456"; root[prefx + "Score"] = "789.123"; Assert.AreEqual("123", root["Age"]); Assert.AreEqual("456", root[prefx + "Name"]); Assert.AreEqual("789.123", root[prefx + "Score"]); }
public void EnsureCreateProx_MustCreated() { var root = ConfigHelper.CreateEmptyRoot(); var proxy = ProxyUtil.CreateProx(); var val = proxy.EnsureCreateProx <NullClass>(root, IdentityMapNameTransfer.FromTypeAttributes(typeof(NullClass))); Assert.IsTrue(proxy.ProxMap.ContainsKey(typeof(NullClass))); Assert.IsNotNull(val); }
protected override void OnBind() { if (Mode != ConfigBindMode.OneTime) { var type = BindSettings.Value.GetType(); objectNamedCreator = new ObjectNamedCreator(type, NameTransfer ?? IdentityMapNameTransfer.FromTypeAttributes(type), NamedCreator ?? IdentityNamedCreator.Instance, CompilePropertyVisitor.Instance); objectNamedCreator.Analysis(); } }
public void CreateProxType_MustOk() { var root = ConfigHelper.CreateEmptyRoot(); var proxType = ProxyUtil.CreateProx(); var res = proxType.BuildProx(typeof(Setting1)); Assert.IsTrue(res); var newType = proxType.CreateProxy(typeof(Setting1), root, IdentityMapNameTransfer.FromTypeAttributes(typeof(Setting1))); Assert.IsNotNull(newType); Assert.IsInstanceOfType(newType, typeof(Setting1)); }
public void GivenBasePath_TransterIt_ReturnMustCombinedBasePath() { var basePath = "BasePath"; var map = new Dictionary <PropertyIdentity, string> { [new PropertyIdentity(typeof(ABox), "A")] = "B" }; var transfer = new IdentityMapNameTransfer(basePath, map); Assert.AreEqual(basePath, transfer.BasePath); var n = transfer.Transfer(new ABox(), "A"); Assert.AreEqual("B", n); }
public void UsingClassPath_MustCombineWithIt() { var t = IdentityMapNameTransfer.FromTypeAttributes("A", typeof(Class1), true); Assert.AreEqual("A:Cl", t.BasePath); }