private IEnumerator NotifyTestA2() { var modelList = new List <ModelA>(); var bindingList = new List <Binding>(); for (int i = 0; i < bindingTestCount; i++) { var model = new ModelA(); modelList.Add(model); var view = new ViewA(); var binding = new Binding("IntValue", view, "IntValue"); binding.Bind(model); bindingList.Add(binding); binding = new Binding("StringValue", view, "StringValue"); binding.Bind(model); bindingList.Add(binding); } var test = RunActionAsync("NotifyTestA2", bindingTestCount, () => { // update value foreach (var item in modelList) { item.IntValue = 1; item.StringValue = "A"; } }); yield return(StartCoroutine(test)); }
private IEnumerator BindAndUnbindTest() { var model = new ModelA(); var view = new ViewA(); var bindingList = new List <Binding>(); var test = RunActionAsync("BindAndUnbindTest", bindingTestCount, () => { // bind for (int i = 0; i < bindingTestCount; i++) { var binding = new Binding("IntValue", view, "IntValue"); binding.Bind(model); bindingList.Add(binding); binding = new Binding("StringValue", view, "StringValue"); binding.Bind(model); bindingList.Add(binding); } // unbind foreach (var item in bindingList) { item.Unbind(); } }); yield return(StartCoroutine(test)); }
public void NullRefonHasFieldsWithSameValueWithInterfaces() { var modelA = new ModelA { Name = "Yoda" }; var modelB = new ModelB { Name = new ModelBName { Title = "Frank" } }; Check.That(modelA).HasFieldsWithSameValues(modelB); }
public void TestPropertyChanged() { var source = new ModelA(); var target = new ModelA(); var go = new GameObject(); var dc = go.AddComponent <DataContext>(); var binding = new Binding("IntValue", target, "IntValue"); dc.AddBinding(binding); BindingManager.Instance.AddSource(source, "Test"); BindingManager.Instance.AddDataContext(dc, "Test"); // set value source.IntValue = 2; Assert.AreEqual(0, target.IntValue); BindingManager.Instance.NotifyPropertyChanged(source, "IntValue"); // verify value changed Assert.AreEqual(2, target.IntValue); source.IntValue = 3; // notify with null path BindingManager.Instance.NotifyPropertyChanged(source, null); Assert.AreEqual(3, target.IntValue); GameObject.DestroyImmediate(go); BindingManager.Instance.Clear(); }
public void MultipleModelsDependenciesTest() { List<string> property_notifications = new List<string>(); ModelA ma = new ModelA() { PropA = 1 }; ModelB mb = new ModelB() { PropB = 2 }; ViewModel vm = new ViewModel(ma, mb); int current_total; ma.PropertyChanged += (sender, args) => property_notifications.Add("ModelA:" + args.PropertyName); mb.PropertyChanged += (sender, args) => property_notifications.Add("ModelB:" + args.PropertyName); vm.PropertyChanged += (sender, args) => property_notifications.Add("ViewModel:" + args.PropertyName); ma.PropA = 2; Assert.AreEqual(2, property_notifications.Count); Assert.IsTrue(property_notifications.Contains("ModelA:PropA")); Assert.IsTrue(property_notifications.Contains("ViewModel:Total")); property_notifications.Clear(); mb.PropB = 40; Assert.AreEqual(2, property_notifications.Count); Assert.IsTrue(property_notifications.Contains("ModelB:PropB")); Assert.IsTrue(property_notifications.Contains("ViewModel:Total")); var total_property = TypeDescriptor.GetProperties(vm)["Total"]; var total = total_property.GetValue(vm); Assert.AreEqual(42, total); }
private IEnumerator LoopTestA2() { var model = new ModelA(); var view = new ViewA(); var binding = new Binding("StringValue", view, "StringValue"); binding.Bind(model); string[] stringTable = new string[] { "A", "B", "C", }; var test = RunActionLoopAsync("LoopTestA2", loopTestCount, () => { for (int i = 0; i < innerLoopCount; i++) { var stringIndex = i % stringTable.Length; var str = stringTable[stringIndex]; // update value model.StringValue = str; Assert.AreEqual(str, view.StringValue); } }); yield return(StartCoroutine(test)); }
private static bool ModelAHandler(IRuleDescription rule, ModelA target) { if (target.SUbModel == null) { return(true); } return(false); }
internal void Load() { // TODO: Replace this with logic that is told (or "knows") where to get the active Models. someAs = new List <ModelA> { new ModelA(), new ModelA() }; _a = (someAs.Count > 0 ? someAs[0] : null); _owner.Text1 = (_a != null ? _a.TextA : "No ModelA"); }
public void DuplicateItemTest() { var source = new ModelB(); var target = new TestViewFactory(); // bind to collection var binding = new CollectionBinding("List", target); binding.Bind(source); // get ref dictionary var field = typeof(CollectionBinding).GetField("viewReferenceCountDictionary", BindingFlags.NonPublic | BindingFlags.Instance); var refDictionary = field.GetValue(binding) as Dictionary <GameObject, int>; // check initial state { Assert.AreEqual(0, target.ViewCount); Assert.IsTrue(refDictionary == null); } var item = new ModelA(); // add item { source.List.Add(item); source.List.Add(item); // verify view count Assert.AreEqual(1, binding.BindingDictionary.Count); // check ref count refDictionary = field.GetValue(binding) as Dictionary <GameObject, int>; Assert.IsTrue(refDictionary != null); Assert.AreEqual(2, refDictionary.First().Value); } // remove item { source.List.RemoveAt(0); Assert.AreEqual(1, binding.BindingDictionary.Count); // check ref count Assert.AreEqual(1, refDictionary.First().Value); } // remove item { source.List.RemoveAt(0); Assert.AreEqual(0, binding.BindingDictionary.Count); // check ref count Assert.AreEqual(0, refDictionary.Count); } target.Destroy(); }
public void UpdateItemValueTest() { var source = new ModelB(); var target = new TestViewFactory(); // bind to collection var binding = new CollectionBinding("List", target); binding.Bind(source); Assert.AreEqual(0, target.ViewCount); // add item var itemA = new ModelA(); source.List.Add(itemA); // add item var itemB = new ModelA(); source.List.Add(itemB); // add item view A var viewA = new ModelA(); var bindingA = new Binding("IntValue", viewA, "IntValue"); var dcA = binding.BindingDictionary[itemA].GetComponent <IDataContext>(); dcA.AddBinding(bindingA); // add item view B var viewB = new ModelA(); var bindingB = new Binding("IntValue", viewB, "IntValue"); var dcB = binding.BindingDictionary[itemB].GetComponent <IDataContext>(); dcB.AddBinding(bindingB); // verify state Assert.IsTrue(bindingA.IsBound); Assert.IsTrue(bindingB.IsBound); Assert.AreEqual(1, dcA.BindingList.Count); Assert.AreEqual(1, dcB.BindingList.Count); Assert.AreEqual(0, viewA.IntValue); Assert.AreEqual(0, viewB.IntValue); // update value itemA.IntValue = 1; itemB.IntValue = 2; Assert.AreEqual(1, viewA.IntValue); Assert.AreEqual(2, viewB.IntValue); target.Destroy(); }
public void TestItemNestedPropertyChanged() { var source = new ModelD(); var target = new TestViewFactory(); var go = new GameObject("Test"); var dc = go.AddComponent <DataContext>(); // create collection binding var binding = new CollectionBinding("List", target); dc.AddBinding(binding); BindingManager.Instance.AddSource(source, "Test"); BindingManager.Instance.AddDataContext(dc, "Test"); // add item var item = new ModelC(); item.NestedValue.IntValue = 2; source.List.Add(item); var itemView = binding.BindingDictionary[item]; var itemDataContext = itemView.GetComponent <IDataContext>(); // add item binding var itemTarget = new ModelA(); var itemBinding = new Binding("NestedValue.IntValue", itemTarget, "IntValue"); itemDataContext.AddBinding(itemBinding); // check item value Assert.AreEqual(2, itemTarget.IntValue); // update value item.NestedValue.IntValue = 3; Assert.AreEqual(2, itemTarget.IntValue); // notify BindingManager.Instance.NotifyItemPropertyChanged(source, source, source.List, item, item.NestedValue, "IntValue"); Assert.AreEqual(3, itemTarget.IntValue); // update value item.NestedValue.IntValue = 4; Assert.AreEqual(3, itemTarget.IntValue); // notify with null BindingManager.Instance.NotifyItemPropertyChanged(source, source, source.List, item, item.NestedValue, null); Assert.AreEqual(4, itemTarget.IntValue); BindingManager.Instance.Clear(); target.Clear(); GameObject.DestroyImmediate(go); }
private static bool Handler(IRuleDescription rule, ModelA target) { if (target.SUbModel == null) { return(false); } else if (target.SUbModel.ModelNumber != target.ModelNumber) { return(true); } return(false); }
static void Main(string[] args) { ModelA model1 = new ModelA("Samsung Galaxy S10"); ModelA model2 = new ModelA("Samsung Galaxy S10 Plus"); Manager manager = new Manager(); manager.AddModel(model1); manager.AddModel(model2); manager.Notify(); // Android güncelleme olsun ;) }
public void DuplicateItemTest() { var source = new ModelB(); var target = new TestViewFactory(); // setup function target.GetDynamicItemsFun = () => { var list = new List <object>(); foreach (var item in source.List) { list.Add(item); } return(list); }; // bind to collection var binding = new ListDynamicBinding("List", target); binding.Bind(source); // check initial state { Assert.AreEqual(0, target.ViewCount); } var model = new ModelA(); // add item { source.List.Add(model); source.List.Add(model); // verify view count Assert.AreEqual(1, binding.BindingDictionary.Count); } // remove item { source.List.RemoveAt(0); Assert.AreEqual(1, binding.BindingDictionary.Count); } // remove item { source.List.RemoveAt(0); Assert.AreEqual(0, binding.BindingDictionary.Count); } target.Destroy(); }
public void TestingLightMapper() { var mapper = new SimpleMapper(); var modelA = new ModelA { Age = 22, Id = 20, Name = "Arnold" }; var modelB = mapper.Map(modelA); Assert.Equal(modelA.Id, modelB.Id); }
public void ArrayType() { var modelA = new ModelA[] { GetModelA(), GetModelA(), GetModelA() }; var modelB = modelA.Map <ModelB[]>(); Assert.IsNotNull(modelB); Assert.AreEqual(modelA.Length, modelB.Length); }
public void AutoMapperTestForFlattening() { //Mapper.CreateMap<ModelA, NewModel>().ForMember(dest=> dest.Number ,opt=>opt.UseDestinationValue()); NewModel newModel = new NewModel() { Number = "47"}, destModel = new NewModel(){Number="127"}; NewModel new2 = newModel; ModelA modelA = new ModelA { Id = Guid.NewGuid(), InnerModel = new ModelB { InnerModel = new ModelC { FirstNumber = "456", Name = "Flattening" }, SecondNumber = "123" } }; //newModel = Mapper.Map<ModelA, NewModel>(modelA, destModel); var a = Mapper.Map<ModelA, NewModel>(new ModelA() { Id = Guid.NewGuid() }); Assert.AreEqual(newModel.Id, modelA.Id); Assert.AreEqual(newModel.Number, "456123"); Assert.AreEqual(newModel.InnerModelInnerModelName, "Flattening"); }
public void SimpleMapping() { injector.ConfigureServices(services => { services.AddAutoMapping(); services.AddAutoMapper <ModelA, ModelB>(); }).Build(); var autoMapper = injector.GetMapper <ModelA, ModelB>(); var modelA = new ModelA() { Id = 12, Age = 22, Name = "Lucas" }; var modelB = autoMapper.Map(modelA); Assert.Equal(modelA.Id, modelB.Id); }
public void TestToLambdaTypeParams() { // Arrange var a = new ModelA { Id = 1, Name = "ABC", Date = new DateTime(2017, 1, 1), Guid = new Guid("{C1AA6176-425D-4981-BE4A-8F5C459E0FF9}") }; var prop = TestContext.DataRow["Property"].ToString(); var type = Type.GetType(TestContext.DataRow["Type"].ToString()); var value = TestContext.DataRow["Value"].ToString().ToType(type); var method = TestContext.DataRow["Method"].ToString(); var expectedExpression = TestContext.DataRow["ExpectedExpression"].ToString(); var expectedResult = TestContext.DataRow["ExpectedResult"].ToString().ToBool(); var message = TestContext.DataRow["Message"].ToString(); // Act var expression = prop.ToLambda <ModelA>(type, new object[] { value, method }); var compiledLambda = expression.Compile(); var result = (bool)compiledLambda.DynamicInvoke(a); // Assert Assert.AreEqual(expectedExpression, expression.ToString()); Assert.AreEqual(expectedResult, result, message); }
public void AutoMapperTestForNestedMappings() { Mapper.CreateMap<ModelA, NewModel>(); Mapper.CreateMap<ModelB, InnerNewModel>(); NewModel newModel; ModelA modelA = new ModelA { Id = Guid.NewGuid(), InnerModel = new ModelB { InnerModel = new ModelC { Name = "Nested" }, Number = "456" } }; newModel = Mapper.Map<ModelA, NewModel>(modelA); Assert.AreEqual(newModel.Id, modelA.Id); Assert.AreEqual(newModel.InnerModelInnerModelName, "Nested"); Assert.AreEqual(newModel.InnerModel.InnerModelName, "Nested"); Assert.AreEqual(newModel.InnerModel.Number, "456"); }
public void BindToProperty() { var source = new ModelA(); var target = new ModelA(); var binding = new Binding("IntValue", target, "IntValue"); binding.Bind(source); source.IntValue = 2; Assert.AreEqual(0, target.IntValue); // notify property changed binding.HandleSourcePropertyChanged(source, "IntValue"); Assert.AreEqual(2, target.IntValue); source.IntValue = 3; // notify with null property name binding.HandleSourcePropertyChanged(source, null); Assert.AreEqual(3, target.IntValue); }
private IEnumerator LoopTestA1() { var model = new ModelA(); var view = new ViewA(); var binding = new Binding("IntValue", view, "IntValue"); binding.Bind(model); var test = RunActionLoopAsync("LoopTestA1", loopTestCount, () => { for (int i = 0; i < innerLoopCount; i++) { // update value model.IntValue = i; Assert.AreEqual(i, view.IntValue); } }); yield return(StartCoroutine(test)); }
public void InterfaceTest() { var list = new List <IDuck> { new DuckB { Name = "123" }, new DuckB { Name = "456" }, new DuckB { Name = "789" } }; var model = new ModelA { ID = 2233, Childs = list, }; var json = model.ToJson(); // 直接反序列化会抛出异常 Assert.Throws <Exception>(() => json.ToJsonEntity <ModelA>()); // 上对象容器 ObjectContainer.Current.AddTransient <IDuck, DuckB>(); // 再来一次反序列化 var model2 = json.ToJsonEntity <ModelA>(); Assert.NotNull(model2); Assert.Equal(2233, model2.ID); Assert.Equal(3, model2.Childs.Count); Assert.Equal("123", model.Childs[0].Name); Assert.Equal("456", model.Childs[1].Name); Assert.Equal("789", model.Childs[2].Name); }
public void PropertyNameLambdaExtensions_TestToLambda_Type_One_Params() { // Arrange var a = new ModelA { Id = 1, Name = "ABC", Date = new DateTime(2017, 1, 1), Guid = new Guid("{C1AA6176-425D-4981-BE4A-8F5C459E0FF9}") }; var prop = "Date"; var type = typeof(DateTime); var value = "01/01/2017".ToType(type); var method = "le"; var expectedExpression = "e => (e.Date <= 1/1/2017 12:00:00 AM)"; var expectedResult = true; var message = "Date is 01/01/2017 which is not less than or equal to 12/31/2016."; // Act var expression = prop.ToLambda <ModelA>(type, new object[] { value, method }); var compiledLambda = expression.Compile(); var result = (bool)compiledLambda.DynamicInvoke(a); // Assert Assert.AreEqual(expectedExpression, expression.ToString(), message); Assert.AreEqual(expectedResult, result, message); }
public void MultipleModelsDependenciesTest() { List <string> property_notifications = new List <string>(); ModelA ma = new ModelA() { PropA = 1 }; ModelB mb = new ModelB() { PropB = 2 }; ViewModel vm = new ViewModel(ma, mb); int current_total; ma.PropertyChanged += (sender, args) => property_notifications.Add("ModelA:" + args.PropertyName); mb.PropertyChanged += (sender, args) => property_notifications.Add("ModelB:" + args.PropertyName); vm.PropertyChanged += (sender, args) => property_notifications.Add("ViewModel:" + args.PropertyName); ma.PropA = 2; Assert.AreEqual(2, property_notifications.Count); Assert.IsTrue(property_notifications.Contains("ModelA:PropA")); Assert.IsTrue(property_notifications.Contains("ViewModel:Total")); property_notifications.Clear(); mb.PropB = 40; Assert.AreEqual(2, property_notifications.Count); Assert.IsTrue(property_notifications.Contains("ModelB:PropB")); Assert.IsTrue(property_notifications.Contains("ViewModel:Total")); var total_property = TypeDescriptor.GetProperties(vm)["Total"]; var total = total_property.GetValue(vm); Assert.AreEqual(42, total); }
public void NullRefonHasFieldsWithSameValueWithInterfaces() { Check.ThatCode(() => { var modelA = new ModelA { Name = "Yoda" }; var modelB = new ModelB { Name = new ModelBName { Title = "Frank" } }; Check.That(modelA).HasFieldsWithSameValues(modelB); }) .Throws<FluentCheckException>(); }
public ViewAViewModel(ModelA modelA) { ModelA = modelA; Message = modelA.Message; }
public ViewModel(ModelA ma, ModelB mb) { Property("Total", () => ma.PropA + mb.PropB); }
internal abstract void bindingMyText(ModelA source, A val);
override internal void bindingMyText(ModelA source, string val) { source.MyTextA = val; }
internal abstract A bindingMyText(ModelA source);
override internal string bindingMyText(ModelA source) { return(source.MyTextA); }
internal void SetCurrentModelA(IModelA desiredA) { // By design, IModelA always holds a ModelA (or null), so this cast always succeeds. _a = (ModelA)desiredA; }
public IActionResult GetA() { var model = new ModelA(); return(Ok(model)); }
public void Post(ModelA model) { }