public void SwitchedContextDoesNotUpdatedTest() { var context = new TestContext <string> { Property = contextInitial }; var context2 = new TestContext <string> { Property = contextUpdated }; var view = new TestView <string> { Value = viewInitial }; view.Bind(view) .ViewProperty(v => v.Value) .ViewEvent(nameof(view.ValueChanged)) .To <TestContext <string> >(ctx => ctx.Property); BindingStorage.SetContext(view, context); BindingStorage.SetContext(view, context2); view.Value = viewUpdated; Assert.AreEqual(contextInitial, context.Property); Assert.AreEqual(viewUpdated, context2.Property); Assert.AreEqual(viewUpdated, view.Value); }
public void OneWayBindingFullFlowTest() { var context = new TestContext <string> { Property = contextInitial }; var view = new TestView <string> { Value = viewInitial }; // set binding => nothing should be cnahged view.Bind(view) .ViewProperty(v => v.Value) .To <TestContext <string> >(ctx => ctx.Property); Assert.AreEqual(contextInitial, context.Property); Assert.AreEqual(viewInitial, view.Value); // set context => view should be updated BindingStorage.SetContext(view, context); Assert.AreEqual(contextInitial, context.Property); Assert.AreEqual(contextInitial, view.Value); // context update => view should be updated context.Property = contextUpdated; Assert.AreEqual(contextUpdated, context.Property); Assert.AreEqual(contextUpdated, view.Value); }
public void ContextCanUpdateManyViewsTest() { var context = new TestContext <string> { Property = contextInitial }; var view = new TestView <string> { Value = viewInitial }; var view2 = new TestView <string> { Value = viewInitial }; view.Bind(view) .ViewProperty(v => v.Value) .To <TestContext <string> >(ctx => ctx.Property); view.Bind(view2) .ViewProperty(v => v.Value) .To <TestContext <string> >(ctx => ctx.Property); BindingStorage.SetContext(view, context); BindingStorage.SetContext(view2, context); context.Property = contextUpdated; Assert.AreEqual(contextUpdated, context.Property); Assert.AreEqual(contextUpdated, view.Value); Assert.AreEqual(contextUpdated, view2.Value); }
public void DetachedContextDoesNotAffectViewTest() { var context = new TestContext <string> { Property = contextInitial }; var context2 = new TestContext <string> { Property = contextUpdated }; var view = new TestView <string> { Value = viewInitial }; view.Bind(view) .ViewProperty(v => v.Value) .To <TestContext <string> >(ctx => ctx.Property); BindingStorage.SetContext(view, context); BindingStorage.SetContext(view, context2); context.Property = contextPropertyUpdated; Assert.AreEqual(contextPropertyUpdated, context.Property); Assert.AreEqual(contextUpdated, context2.Property); Assert.AreEqual(contextUpdated, view.Value); }
public void ViewWillAppear(bool animated) { ViewModel = ViewModel ?? (TViewModel)Activator.CreateInstance(typeof(TViewModel)); //todo ViewModel.ViewWillAppearing(); if (SetContextOrder == UpdateOrder.BeforeAppear) { BindingStorage.SetContext(owner, ViewModel); } }
public async void ViewDidAppear(bool animated) { await Task.Yield(); if (SetContextOrder == UpdateOrder.AfterAppear) { BindingStorage.SetContext(owner, ViewModel); } await ViewModel.ReloadDataAsync(); if (SetContextOrder == UpdateOrder.AfterReload) { BindingStorage.SetContext(owner, ViewModel); } }
public void SetContextTest() { var context = new TestContext <string> { Property = contextInitial }; var view = new TestView <string> { Value = viewInitial }; view.Bind(view) .ViewProperty(v => v.Value) .To <TestContext <string> >(ctx => ctx.Property); BindingStorage.SetContext(view, context); Assert.AreEqual(contextInitial, context.Property); Assert.AreEqual(contextInitial, view.Value); }
public void BindingConverterFullFlowTest() { var viewInitialLocal = "100"; var contextInitialLocal = 200; var viewUpdatedLocal = "300"; var contextUpdatedLocal = 400; var context = new TestContext <int> { Property = contextInitialLocal }; var view = new TestView <string> { Value = viewInitialLocal }; // set binding => nothing should be cnahged view.Bind(view) .ViewProperty(v => v.Value) .ViewEvent(nameof(view.ValueChanged)) .Converter(Converters.IntString) .To <TestContext <int> >(ctx => ctx.Property); Assert.AreEqual(contextInitialLocal, context.Property); Assert.AreEqual(viewInitialLocal, view.Value); // set context => view should be updated BindingStorage.SetContext(view, context); Assert.AreEqual(contextInitialLocal, context.Property); Assert.AreEqual(Converters.IntString.Convert(contextInitialLocal), view.Value); // view updated > context shold be updated view.Value = viewUpdatedLocal; Assert.AreEqual(Converters.IntString.ConvertBack(viewUpdatedLocal), context.Property); Assert.AreEqual(viewUpdatedLocal, view.Value); // context update => view should be updated context.Property = contextUpdatedLocal; Assert.AreEqual(contextUpdatedLocal, context.Property); Assert.AreEqual(Converters.IntString.Convert(contextUpdatedLocal), view.Value); }
public static void SetContext <TContext>(this UIView view, TContext context) where TContext : class, INotifyPropertyChanged { BindingStorage.SetContext <TContext>(view, context); }