public void SimpleViewModelCreationTestMethod() { using (StateMachineContextMoc _sm = new StateMachineContextMoc()) { SimpleViewModel _svm = new SimpleViewModel(); } }
public void TestPropertyChanges() { var simple = new SimpleViewModel(true); var newC = new TrackableCollection <string>(); simple.ACollection = newC; Assert.AreEqual(simple.ACollection, newC); simple.ADouble = 5; Assert.AreEqual(simple.ADouble, 5); simple.AnInt = 5; Assert.AreEqual(simple.AnInt, 5); simple.AString = "yupperz"; Assert.AreEqual(simple.AString, "yupperz"); simple.AnEnum = SimpleViewModel.TestEnum.Three; Assert.AreEqual(SimpleViewModel.TestEnum.Three, simple.AnEnum); simple.NullableDouble = null; Assert.IsNull(simple.NullableDouble); simple.NullableInt = null; Assert.IsNull(simple.NullableInt); simple.NullableEnum = null; Assert.IsNull(simple.NullableEnum); simple.ACollection = null; Assert.IsNull(simple.ACollection); simple.StrongReference = null; Assert.IsNull(simple.StrongReference); simple.StrongReferenceBoxed = null; Assert.IsNull(simple.StrongReferenceBoxed); }
static void Main(string[] args) { var simpleViewModel = new SimpleViewModel(); simpleViewModel.FirstName = "Michael"; simpleViewModel.LastName = "Stonis"; using (simpleViewModel.DelayChangeNotifications()) { simpleViewModel.FirstName = "Miguel"; simpleViewModel.FirstName = "Mike"; } Console.WriteLine("Finishing Suppressing Change Notifications"); Console.ReadLine(); Console.WriteLine("Starting Delay Change Notifications"); using (simpleViewModel.DelayChangeNotifications()) { simpleViewModel.FirstName = "Michal"; simpleViewModel.FirstName = "Thomas"; Console.ReadLine(); } Console.WriteLine("Finishing Delay Change Notifications"); Console.ReadLine(); }
public void ContextIsConsistentBetweenGetsTest() { viewModel = new SimpleViewModel() { EmployeeName = "Dave Smith" }; //view supplies initial state mockContainer.Expect(mc => mc.DataContext).IgnoreArguments().Return(viewModel); //will store in datastorage object binderContext = binder.DataContext; Assert.IsNotNull(dataStorageService.Retrieve <object>(VIEW_MODEL_KEY)); //set is post back to true mockContainer.Expect(mc => mc.IsPostBack).IgnoreArguments().Return(true); //retreive = should get the vm from storage SimpleViewModel vm = binder.DataContext as SimpleViewModel; vm.EmployeeName = "Sam Shiles"; SimpleViewModel vm2 = binder.DataContext as SimpleViewModel; Assert.AreEqual(vm.EmployeeName, vm2.EmployeeName); }
public void ValidateViewModelWithoutValidationLogicExpectedErrorIsEmpty() { var simpleViewModel = new SimpleViewModel(); simpleViewModel.IsValid.Should().BeTrue(); simpleViewModel.Error.Should().BeEmpty(); }
public MainWindow() { VM = new SimpleViewModel(); this.DataContext = VM; InitializeComponent(); }
public RedViewModel(SimpleViewModel blueViewModel) { _blueViewModel = blueViewModel; _yellowViewModel = new YellowViewModel(this); GotoBackCommand = new SimpleRelayCommand(GotoBack); GotoBlueCommand = new SimpleRelayCommand(GotoBlue); GotoYellowCommand = new SimpleRelayCommand(GotoYellow); }
public App() { InitializeComponent(); //create ViewModel var viewModel = new SimpleViewModel(); MainPage = new SimplePage(viewModel); }
private void AddToHistory(SimpleViewModel navObj) { if (NavigationHistory.Count >= MaxHistoryObjects) { NavigationHistory.RemoveAt(0); } NavigationHistory.Add(navObj); }
public async Task TestUndo() { var simple = new SimpleViewModel(true); var originalC = simple.ACollection; Assert.AreEqual(0, originalC.Count); var origBoxed = simple.StrongReferenceBoxed; var origStrong = simple.StrongReference; var acc = new Accumulator("test"); simple.Accumulator = acc; var newC = new TrackableCollection <string>(acc, true); simple.ACollection = newC; Assert.AreEqual(simple.ACollection, newC); newC.Add("poop"); newC.Add("stinks"); simple.ADouble = 5; Assert.AreEqual(simple.ADouble, 5); simple.AnInt = 5; Assert.AreEqual(simple.AnInt, 5); simple.AString = "yupperz"; Assert.AreEqual(simple.AString, "yupperz"); simple.AnEnum = SimpleViewModel.TestEnum.Three; Assert.AreEqual(SimpleViewModel.TestEnum.Three, simple.AnEnum); simple.NullableDouble = null; Assert.IsNull(simple.NullableDouble); simple.NullableInt = null; Assert.IsNull(simple.NullableInt); simple.NullableEnum = null; Assert.IsNull(simple.NullableEnum); simple.ACollection = null; Assert.IsNull(simple.ACollection); simple.StrongReference = null; Assert.IsNull(simple.StrongReference); simple.StrongReferenceBoxed = null; Assert.IsNull(simple.StrongReferenceBoxed); Assert.AreEqual(13, acc.Records.Count); await acc.UndoAll(acc.Name); Assert.AreEqual(simple.AString, nameof(SimpleViewModel.AString)); Assert.AreEqual(simple.AnInt, 542); Assert.AreEqual(simple.ADouble, 542); Assert.AreEqual(simple.StrongReferenceBoxed, origBoxed); Assert.AreEqual(simple.StrongReference, origStrong); Assert.AreEqual(simple.ACollection, originalC); Assert.AreEqual(0, originalC.Count); Assert.AreEqual(simple.NullableInt, 0); Assert.AreEqual(simple.NullableDouble, 0); Assert.AreEqual(simple.NullableEnum, SimpleViewModel.TestEnum.Two); }
public HomeController(ILogger <HomeController> logger) { var rnd = new Random(); _vm = new SimpleViewModel { Value = rnd.Next(minValue: 0, maxValue: 100) }; _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
/// <summary> /// Setup the core navigation requirements /// </summary> /// <param name="navigationHandler">Object that handles navigation</param> /// <param name="defaultNavigation">View that navigation defaults to</param> /// <param name="forceDefaultNavigation">Force default view on startup?</param> public void Startup(ISimpleNavigationProvider navigationHandler, SimpleViewModel defaultNavigation = null, bool forceDefaultNavigation = false) { service.RegisterProvider(navigationHandler); Handler = navigationHandler; if (defaultNavigation != null) { service.SetDefaultNavigation(defaultNavigation, forceDefaultNavigation); } }
public ActionResult AboutCopy() { ViewBag.Message = "You clicked on link 'AboutCopy'"; var viewModel = new SimpleViewModel { MyName = "About", MyThoughts = "This Action references About cshtml file" }; return(View("About", viewModel)); }
/// <summary> /// Set the ViewModel navigation defaults to /// </summary> /// <param name="navigationObject"></param> /// <param name="forceIfProviderEmpty"></param> public void SetDefaultNavigation(SimpleViewModel navigationObject, bool forceIfProviderEmpty = false) { DefaultNavigation = navigationObject; if (forceIfProviderEmpty) { if (Provider != null) { Provider.Current = navigationObject; } } }
public ActionResult About() { ViewBag.Message = "You clicked on link 'About'"; var viewModel = new SimpleViewModel { MyName = "Darkness", MyThoughts = "Hello darkness my old friend!" }; return(View(viewModel)); }
public void SetupForTest() { mockContainer = MockRepository.GenerateMock <IServiceProviderBindingContainer>(); dataStorageService = MockRepository.GenerateMock <IDataStorageService>(); controlService = MockRepository.GenerateMock <IControlService>(); viewModel = new SimpleViewModel(); //object under test binder = new ViewStateBinder(mockContainer, dataStorageService, controlService); mockContainer.Expect(mc => mc.IsPostBack).IgnoreArguments().Return(true); mockContainer.Expect(mc => mc.DataContext).IgnoreArguments().Return(viewModel); }
protected override void Navigate(SimpleViewModel navigationObject) { if (navigationObject is AuthorizedViewModel authVM) { if (VerifyNavigation(authVM)) { base.Navigate(navigationObject); return; } base.NavigateWindow(service.DefaultNavigation, new LoginWindow()); return; } base.Navigate(navigationObject); }
/// <summary> /// Navigate to a ViewModel with a new window /// </summary> /// <param name="navObject">ViewModel to navigate to</param> /// <param name="newWindow">Window to navigate to</param> public void NavigateWithNewWindow(SimpleViewModel navObject, ISimpleWindow newWindow) { if (Provider == null) { throw new NullReferenceException("The navigation service does not have a registered 'ISimpleNavigationProvider'"); } var args = new WindowEventArgs(newWindow, Provider.Window); Navigate(navObject); OnBeforeClosing(this, args); Provider.Window.TransitionWindow(newWindow); OnAfterClosing(this, args); }
public void TestPropertyChanged() { var simple = new SimpleViewModel(true); Dictionary <string, int> propChanges = new Dictionary <string, int>(); simple.PropertyChanged += (s, e) => { if (propChanges.ContainsKey(e.PropertyName)) { propChanges[e.PropertyName]++; } else { propChanges[e.PropertyName] = 1; } }; var newC = new TrackableCollection <string>(); simple.ACollection = newC; Assert.AreEqual(simple.ACollection, newC); simple.ADouble = 5; Assert.AreEqual(simple.ADouble, 5); simple.AnInt = 5; Assert.AreEqual(simple.AnInt, 5); simple.AString = "yupperz"; Assert.AreEqual(simple.AString, "yupperz"); simple.AnEnum = SimpleViewModel.TestEnum.Three; Assert.AreEqual(SimpleViewModel.TestEnum.Three, simple.AnEnum); simple.NullableDouble = null; Assert.IsNull(simple.NullableDouble); simple.NullableInt = null; Assert.IsNull(simple.NullableInt); simple.NullableEnum = null; Assert.IsNull(simple.NullableEnum); simple.ACollection = null; Assert.IsNull(simple.ACollection); simple.StrongReference = null; Assert.IsNull(simple.StrongReference); simple.StrongReferenceBoxed = null; Assert.IsNull(simple.StrongReferenceBoxed); foreach (var prop in simple.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(p => p.CanRead && p.CanWrite && p.Name != nameof(TrackableViewModel.Accumulator))) { Assert.IsTrue(propChanges.ContainsKey(prop.Name), $"Property {prop.Name} was not raised!"); Assert.IsTrue(propChanges[prop.Name] > 0 && propChanges[prop.Name] < 3); } }
public SliderPage() { InitializeComponent(); //var radialSlider = new RadialSlider(); //radialSlider.Height = 200; //radialSlider.Width = radialSlider.Height; //radialSlider.MaximumValue = 60; //radialSlider.MinimumValue = 0; //radialSlider.ManipulationCompleted += radialSlider_ManipulationCompleted; //ContentPanel.Children.Add(radialSlider); _viewModel = new SimpleViewModel(); DataContext = _viewModel; }
public async Task TwoWay_ResultCommand_Can_Be_Listened_From_Javascript() { const string original = "original"; const string stringExpected = "NewName"; var result = new SimpleViewModel { Name = original }; var function = NSubstitute.Substitute.For <Func <int, SimpleViewModel> >(); function.Invoke(Arg.Any <int>()).Returns(result); var dc = new FakeFactory <int, SimpleViewModel>(function); var test = new TestInContextAsync() { Path = TestContext.IndexPromise, Bind = (win) => HtmlBinding.Bind(win, dc, JavascriptBindingMode.TwoWay), Test = async(mb) => { var js = mb.JsRootObject; var jsCommand = GetAttribute(js, "CreateObject"); var cb = GetCallBackObject(); this.CallWithRes(jsCommand, "Execute", _WebView.Factory.CreateInt(25), cb); await Task.Delay(700); var resValue = _WebView.GetGlobal().GetValue("res"); await Task.Delay(100); var originalValue = GetAttribute(resValue, nameof(SimpleViewModel.Name)).GetStringValue(); originalValue.Should().Be(original); DoSafeUI(() => result.Name = stringExpected); await Task.Delay(100); var newValue = GetAttribute(resValue, nameof(SimpleViewModel.Name)).GetStringValue(); newValue.Should().Be(stringExpected); } }; await RunAsync(test); }
public SimpleViewModel(bool setup) { if (!setup) { return; } AString = nameof(AString); AnInt = 542; ADouble = 542.0; StrongReferenceBoxed = new SimpleViewModel(false); StrongReference = new SimpleViewModel(false); NullableInt = 0; NullableDouble = 0; NullableEnum = TestEnum.Two; AnEnum = TestEnum.Two; ACollection = new TrackableCollection <string>(); }
public SimplePage(SimpleViewModel simpleViewModel) { this.simpleViewModel = simpleViewModel; //The binding context refers to the object we are binding against. //This can also be set from XAML BindingContext = this.simpleViewModel; //Create XAML objects InitializeComponent(); //Binding method #1: Set bindings using unsafe Text okButton.SetBinding(Button.IsEnabledProperty, "FornavnOk", BindingMode.OneWay); //Binding method #2 Set binding using lambda and typesafety fornavnEntry.SetBinding <SimpleViewModel>(Entry.TextProperty, vm => vm.Fornavn, BindingMode.OneWayToSource); //Binding method #3 - see the XAML file ;) }
public ActionResult Complex2ex( [Bind(Include = "Username , Password, ConfirmPassword")] //要驗證的欄位 SimpleViewModel item1, [Bind(Include = "Username , Password, ConfirmPassword")] //要驗證的欄位 SimpleViewModel item2) { //驗證失敗 if (!ModelState.IsValid) { //可有可無 //ViewBag.item1 = item1; //ViewBag.item2 = item2; //return View("Complex2ex", item1); return(View()); } //驗證成功 return(Content("Complex2ex : " + item1.UserName + "/" + item1.Password + "/" + item1.ConfirmPassword + "<br/>" + "Complex2ex : " + item2.UserName + "/" + item2.Password + "/" + item2.ConfirmPassword)); }
/// <summary> /// Navigate to ViewModel /// </summary> /// <param name="navObject">ViewModel to navigate to</param> public void Navigate(SimpleViewModel navObject) { if (Provider == null) { throw new NullReferenceException("The navigation service does not have a registered 'ISimpleNavigationProvider'"); } var args = new NavigationEventArgs(navObject, Provider.Current); OnBeforeNavigate(this, args); if (Provider.Current != null && Provider.Current != navObject) { AddToHistory(Provider.Current); } Provider.Current = navObject; OnAfterNavigate(this, args); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Create your application here var serializer = new JsonSerializer(); if (bundle != null) { this.model = serializer.Deserialize<SimpleViewModel>(bundle.GetString("model")); } var button = this.FindViewById<Button>(Resource.Id.buttonClose); button.Click += (sender, args) => { var intent = new Intent(); intent.PutExtra("model", serializer.Serialize(this.model)); this.SetResult(Result.Ok, intent); this.Finish(); }; }
public void TestScopeEachChange_On() { Globals.ScopeEachChange = true; var simple = new SimpleViewModel(true); var newC = new TrackableCollection <string>(); simple.ACollection = newC; Assert.AreEqual(simple.ACollection, newC); newC.Add("poop"); newC.Add("stinks"); simple.ADouble = 5; Assert.AreEqual(simple.ADouble, 5); simple.AnInt = 5; Assert.AreEqual(simple.AnInt, 5); simple.AString = "yupperz"; Assert.AreEqual(simple.AString, "yupperz"); simple.AnEnum = SimpleViewModel.TestEnum.Three; Assert.AreEqual(SimpleViewModel.TestEnum.Three, simple.AnEnum); simple.NullableDouble = null; Assert.IsNull(simple.NullableDouble); simple.NullableInt = null; Assert.IsNull(simple.NullableInt); simple.NullableEnum = null; Assert.IsNull(simple.NullableEnum); simple.ACollection = null; Assert.IsNull(simple.ACollection); simple.StrongReference = null; Assert.IsNull(simple.StrongReference); simple.StrongReferenceBoxed = null; Assert.IsNull(simple.StrongReferenceBoxed); var mgr = AccumulatorManager.Instance; Assert.AreEqual(mgr.Undoables.Count, 46); Globals.ScopeEachChange = false; }
public IActionResult Index() { SimpleModel model = new SimpleModel() { Name = "Przemyslaw Bak", Email = "*****@*****.**", SomeLongText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua", ItemsList = new List <string>() { "Chair", "Pen", "Cellphone", "Handmade something" } }; SimpleViewModel vm = new SimpleViewModel() { NameImages = ConvertToMultipleImages(model.Name), EmailImages = ConvertToMultipleImages(model.Email), SomeLongTextImages = ConvertToMultipleImages(model.SomeLongText), ListImages = GetListImages(model.ItemsList) }; return(View(vm)); }
public void TestTracking() { var simple = new SimpleViewModel(true); var acc = new Accumulator("test"); simple.Accumulator = acc; var newC = new TrackableCollection <string>(acc, true); simple.ACollection = newC; Assert.AreEqual(simple.ACollection, newC); newC.Add("poop"); newC.Add("stinks"); simple.ADouble = 5; Assert.AreEqual(simple.ADouble, 5); simple.AnInt = 5; Assert.AreEqual(simple.AnInt, 5); simple.AString = "yupperz"; Assert.AreEqual(simple.AString, "yupperz"); simple.AnEnum = SimpleViewModel.TestEnum.Three; Assert.AreEqual(SimpleViewModel.TestEnum.Three, simple.AnEnum); simple.NullableDouble = null; Assert.IsNull(simple.NullableDouble); simple.NullableInt = null; Assert.IsNull(simple.NullableInt); simple.NullableEnum = null; Assert.IsNull(simple.NullableEnum); simple.ACollection = null; Assert.IsNull(simple.ACollection); simple.StrongReference = null; Assert.IsNull(simple.StrongReference); simple.StrongReferenceBoxed = null; Assert.IsNull(simple.StrongReferenceBoxed); Assert.AreEqual(13, acc.Records.Count); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it var button = FindViewById<Button>(Resource.Id.buttonOpen); var viewModel = new SimpleViewModel() { Label = "Text", Text = string.Empty }; button.Click += delegate { var serializer = new JsonSerializer(); var intent = new Intent(this, typeof(Activity2)); intent.PutExtra("model", serializer.Serialize(viewModel)); this.StartActivityForResult(intent, Resource.Id.buttonOpen); }; }
internal ConfigWindow(SimpleViewModel sourceViewModel) : this() { _sourceViewModel = sourceViewModel; DataContext = new SimpleViewModel(sourceViewModel); }
public void SetViewModel(SimpleViewModel model) { _viewModel = model; }
public NavigationEventArgs(SimpleViewModel navigatingTo, SimpleViewModel navigatingFrom = null) { ViewModelTo = navigatingTo; ViewModelFrom = navigatingFrom; }
private void InitializeCouchbase() { _db = Manager.SharedInstance.GetDatabase("wpf-lite"); _viewModel = new SimpleViewModel(new SimpleModel(Manager.SharedInstance, "wpf-lite")); if (_viewModel.SyncURL != null) { UpdateReplications(_viewModel.SyncURL); } _viewModel.PropertyChanged += (sender, args) => { Console.WriteLine("Replication URL changed to {0}", _viewModel.SyncURL); UpdateReplications(_viewModel.SyncURL); }; var view = _db.GetView("todos"); if (view.Map == null) { view.SetMap((props, emit) => { object date; if (!props.TryGetValue(CREATION_DATE_PROPERTY_NAME, out date)) { return; } object deleted; if (props.TryGetValue("_deleted", out deleted)) { return; } emit(date, props["text"]); }, "1"); } _query = view.CreateQuery().ToLiveQuery(); _query.Changed += QueryChanged; _query.Start(); }