public void WhenViewExistsAndDoesNotImplementINavigationAware_ThenReturnsView() { // Arrange var serviceLocatorMock = new Mock<IServiceLocator>(); var region = new Region(); var view = new TestView(); region.Add(view); var navigationContext = new NavigationContext(null, new Uri(view.GetType().Name, UriKind.Relative)); var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object); // Act var returnedView = navigationTargetHandler.LoadContent(region, navigationContext); // Assert Assert.AreSame(view, returnedView); }
public void WhenNoCurrentMatchingViewExists_ThenReturnsNewlyCreatedInstanceWithServiceLocatorAddedToTheRegion() { // Arrange var serviceLocatorMock = new Mock<IServiceLocator>(); var region = new Region(); var view = new TestView(); serviceLocatorMock .Setup(sl => sl.GetInstance<object>(view.GetType().Name)) .Returns(view); var navigationContext = new NavigationContext(null, new Uri(view.GetType().Name, UriKind.Relative)); var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object); // Act var returnedView = navigationTargetHandler.LoadContent(region, navigationContext); // Assert Assert.AreSame(view, returnedView); Assert.IsTrue(region.Views.Contains(view)); }
public void WhenRegionHasMultipleViews_ThenViewsWithMatchingFullTypeNameAreConsidered() { // Arrange var serviceLocatorMock = new Mock<IServiceLocator>(); var region = new Region(); var view1 = new TestView(); var view2 = "view"; region.Add(view1); region.Add(view2); var navigationContext = new NavigationContext(null, new Uri(view2.GetType().FullName, UriKind.Relative)); var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object); // Act var returnedView = navigationTargetHandler.LoadContent(region, navigationContext); // Assert Assert.AreSame(view2, returnedView); }
static void Main(string[] args) { ResponsivenessSingleton.GetInstance().Initialize(); TestView view = new TestView(); TestController controller = new TestController( new ConsoleResponsiveHelper(ConcurrencyMode.Modal), view); controller.DoWork(); }
public void NestedTemplateBindings () { var testView = new TestView (); var label = (Label)testView.LogicalChildren[0].LogicalChildren[0]; testView.Platform = new UnitPlatform (); Assert.IsNull (label.Text); testView.Name = "Bar"; Assert.AreEqual ("Bar", label.Text); }
public void ResettingControlTemplateNullsPresenterContent () { var testView = new TestView { Platform = new UnitPlatform (), ControlTemplate = new ControlTemplate (typeof (PresenterWrapper)) }; var label = new Label (); testView.Content = label; var originalPresenter = (ContentPresenter)testView.LogicalChildren[0].LogicalChildren[0]; Assert.AreEqual (label, originalPresenter.Content); testView.ControlTemplate = new ControlTemplate (typeof (PresenterWrapper)); Assert.IsNull (originalPresenter.Content); }
public void FindPartialView_ViewExists_ReturnsView() { // Arrange SetupFileExists("~/vpath/controllerName/partialName.partial"); SetupCacheHit(CreateCacheKey(Cache.Partial), "~/vpath/controllerName/partialName.partial"); SetupFileDoesNotExist("~/vpath/controllerName/partialName.Mobile.partial"); SetupCacheMiss(CreateCacheKey(Cache.Partial, displayMode: "Mobile")); // Act ViewEngineResult result = _engine.FindPartialView(_context, "partialName", false); // Assert TestView view = Assert.IsType <TestView>(result.View); Assert.Null(result.SearchedLocations); Assert.Same(_context, view.ControllerContext); Assert.Equal("~/vpath/controllerName/partialName.partial", view.Path); }
public void Test_WeakBinding_AttachTargetEvent_3() { var viewModel = new TestViewModel(); var view = new TestView(); new WeakPropertyBinding(view, "Text1", viewModel, "Name") .Initialize <WeakPropertyBinding>() .SetMode(BindMode.TwoWay) .AttachTargetEvent(typeof(TestView), "StaticTestViewEvent"); viewModel.Name = Name1; Assert.AreEqual(view.Text1, Name1); view.Text1 = Name2; Assert.AreNotEqual(viewModel.Name, Name2); TestView.RaiseStaticTestViewEvent(); Assert.AreEqual(viewModel.Name, Name2); }
public void Test_BindingEngine_PropertyBinding_Expression() { var viewModel = new TestViewModel(); var view = new TestView(); BindingEngine.SetPropertyBinding(view, o => o.Text1, viewModel, i => i.Name) .SetMode(BindMode.TwoWay) .AttachTargetEvent("TestViewEvent"); viewModel.Name = Name1; Assert.AreEqual(view.Text1, Name1); view.Text1 = Name2; Assert.AreNotEqual(viewModel.Name, Name2); view.RaiseTestViewEvent(); Assert.AreEqual(viewModel.Name, Name2); }
public void ComplexValidationRulesShouldBeBoundToView() { const string errorMessage = "Both inputs should be the same"; var view = new TestView(new TestViewModel { Name = "Josuke Hikashikata", Name2 = "Jotaro Kujo" }); view.ViewModel.ValidationRule( m => m.Name, m => m.WhenAnyValue(x => x.Name, x => x.Name2, (name, name2) => name == name2), (vm, isValid) => isValid ? string.Empty : errorMessage); view.BindValidation(view.ViewModel, x => x.Name, x => x.NameErrorLabel); Assert.NotEmpty(view.NameErrorLabel); Assert.Equal(errorMessage, view.NameErrorLabel); }
public void FindView_PathViewExistsAndNoMaster_ReturnsView(string path) { // Arrange _engine.ClearMasterLocations(); SetupFileExists(path); SetupCacheHit(CreateCacheBaseKey(Cache.View, path, "", ""), path); // Act ViewEngineResult result = _engine.FindView(_context, path, null, false); // Assert TestView view = Assert.IsType <TestView>(result.View); Assert.Null(result.SearchedLocations); Assert.Same(_context, view.ControllerContext); Assert.Equal(path, view.Path); Assert.Equal(String.Empty, view.MasterPath); }
public void ShouldUpdateViewModelValidityWhenValidationHelpersDetach() { var view = new TestView(new TestViewModel { Name = string.Empty }); var nameRule = view.ViewModel.ValidationRule( viewModel => viewModel.Name, name => !string.IsNullOrWhiteSpace(name), "Name is empty."); var name2Rule = view.ViewModel.ValidationRule( viewModel => viewModel.Name2, name => !string.IsNullOrWhiteSpace(name), "Name2 is empty."); view.Bind(view.ViewModel, x => x.Name, x => x.NameLabel); view.BindValidation(view.ViewModel, x => x.NameErrorContainer.Text); Assert.Equal(2, view.ViewModel.ValidationContext.Validations.Count); Assert.False(view.ViewModel.ValidationContext.IsValid); Assert.Equal("Name is empty. Name2 is empty.", view.NameErrorContainer.Text); nameRule.Dispose(); Assert.Equal(1, view.ViewModel.ValidationContext.Validations.Count); Assert.False(view.ViewModel.ValidationContext.IsValid); Assert.Equal("Name2 is empty.", view.NameErrorContainer.Text); name2Rule.Dispose(); Assert.Equal(0, view.ViewModel.ValidationContext.Validations.Count); Assert.True(view.ViewModel.ValidationContext.IsValid); Assert.Empty(view.NameErrorContainer.Text); view.ViewModel.ValidationRule( viewModel => viewModel.Name, name => !string.IsNullOrWhiteSpace(name), "Name is empty."); Assert.Equal(1, view.ViewModel.ValidationContext.Validations.Count); Assert.False(view.ViewModel.ValidationContext.IsValid); Assert.Equal("Name is empty.", view.NameErrorContainer.Text); }
public void Test_BindingEngine_GenericBinding() { var viewModel = new TestViewModel(); var view = new TestView(); BindingEngine.SetBinding <WeakPropertyBinding>(view, "Text1", viewModel, "Name") .SetMode(BindMode.TwoWay) .AttachTargetEvent("TestViewEvent"); viewModel.Name = Name1; Assert.AreEqual(view.Text1, Name1); view.Text1 = Name2; Assert.AreNotEqual(viewModel.Name, Name2); view.RaiseTestViewEvent(); Assert.AreEqual(viewModel.Name, Name2); }
public void WhenViewExistsAndHasDataContextThatImplementsINavigationAware_ThenDataContextIsQueriedForNavigationAndNewInstanceIsCreatedIfItRejectsIt() { // Arrange var serviceLocatorMock = new Mock <IServiceLocator>(); var region = new Region(); var dataContextMock = new Mock <INavigationAware>(); dataContextMock .Setup(v => v.IsNavigationTarget(It.IsAny <NavigationContext>())) .Returns(false) .Verifiable(); var viewMock = new Mock <FrameworkElement>(); viewMock.Object.DataContext = dataContextMock.Object; region.Add(viewMock.Object); var newView = new TestView(); serviceLocatorMock .Setup(sl => sl.GetInstance <object>(viewMock.Object.GetType().Name)) .Returns(newView); var navigationContext = new NavigationContext(null, new Uri(viewMock.Object.GetType().Name, UriKind.Relative)); var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object); // Act var returnedView = navigationTargetHandler.LoadContent(region, navigationContext); // Assert Assert.AreSame(newView, returnedView); Assert.IsTrue(region.Views.Contains(newView)); dataContextMock.VerifyAll(); }
public void ShouldBindValidationRuleEmittingValidationStatesGeneric() { const StringComparison comparison = StringComparison.InvariantCulture; const string viewModelIsBlockedMessage = "View model is blocked."; const string nameErrorMessage = "Name shouldn't be empty."; var view = new TestView(new TestViewModel { Name = string.Empty }); using var isViewModelBlocked = new ReplaySubject <bool>(1); isViewModelBlocked.OnNext(true); // Use the observable directly in the rules, which use the generic version of the ex view.ViewModel.ValidationRule( viewModel => viewModel.Name, view.ViewModel.WhenAnyValue( vm => vm.Name, name => new CustomValidationState( !string.IsNullOrWhiteSpace(name), nameErrorMessage))); view.ViewModel.ValidationRule( isViewModelBlocked.Select(blocked => new CustomValidationState(!blocked, viewModelIsBlockedMessage))); view.Bind(view.ViewModel, x => x.Name, x => x.NameLabel); view.BindValidation(view.ViewModel, x => x.Name, x => x.NameErrorLabel); view.BindValidation(view.ViewModel, x => x.NameErrorContainer.Text); Assert.Equal(2, view.ViewModel.ValidationContext.Validations.Count); Assert.False(view.ViewModel.ValidationContext.IsValid); Assert.Contains(nameErrorMessage, view.NameErrorLabel, comparison); Assert.Contains(viewModelIsBlockedMessage, view.NameErrorContainer.Text, comparison); view.ViewModel.Name = "Qwerty"; isViewModelBlocked.OnNext(false); Assert.Equal(2, view.ViewModel.ValidationContext.Validations.Count); Assert.True(view.ViewModel.ValidationContext.IsValid); Assert.DoesNotContain(nameErrorMessage, view.NameErrorLabel, comparison); Assert.DoesNotContain(viewModelIsBlockedMessage, view.NameErrorContainer.Text, comparison); }
public void Can_Insert_With_Custom_Binding() { using (var dataProvider = TestHelpers.CreateTestProvider()) { var container = TestHelpers.CreateContainer(services => { services.AddDataContext <TestContext>(dataProvider); services.Configure <MappingOptions>(options => { options.AddBindingOverride <TestView, TestEntity>(binding => { binding.Bind(t => t.Id, s => s.TheId); binding.Bind(t => t.Value, s => s.TheValue, value => value / 2); }); }); }); dataProvider.ExecuteNonQuery(Sqlite3QueryExpression.Raw($@" CREATE TABLE Entities ( [Id] INTEGER PRIMARY KEY AUTOINCREMENT, [Value] INTEGER )" )); using (var scope = container.CreateScope()) { var dataContext = scope.ServiceProvider.GetRequiredService <TestContext>(); var entityView = new TestView { TheValue = 4 }; Batch.Create() .Insert(dataContext.Entities.Insert(entityView)) .Single(dataContext.Entities.Select(), out var fetchResult) .Execute(); var fetchedEntity = fetchResult.Result; Assert.AreEqual(1, fetchedEntity.Id); Assert.AreEqual(entityView.TheValue / 2, fetchedEntity.Value); } } }
public void Test_WeakPropertyBinding_Index_Observable() { var view = new TestView(); var viewModel = new TestViewModel(); // 1. OneWay binding. new WeakPropertyBinding(view, "Text1", viewModel, "TestViewModel2.TestViewModel3.TestViewModels[1].Name") .Initialize <WeakPropertyBinding>().OfType <WeakPropertyBinding>() .SetMode(BindMode.TwoWay) .AttachTargetEvent("TestViewEvent"); var viewModel2 = new TestViewModel2(); viewModel.TestViewModel2 = viewModel2; var viewModel3 = new TestViewModel3(); viewModel2.TestViewModel3 = viewModel3; var testViewModels = new ObservableCollection <TestViewModel4>(); viewModel3.TestViewModels = testViewModels; var t4 = new TestViewModel4(); var t41 = new TestViewModel4(); testViewModels.Add(t4); testViewModels.Add(t41); t41.Name = Name1; Assert.AreEqual(Name1, view.Text1); view.Text1 = Name2; view.RaiseTestViewEvent(); Assert.AreEqual(Name2, t41.Name); var t42 = new TestViewModel4(); testViewModels[1] = t42; Assert.AreEqual(null, view.Text1); }
public void Test_WeakCommandBinding_CanExecute() { var viewModel = new TestViewModel(); var view = new TestView(); new WeakCommandBinding(view, null, viewModel, "AddAgeCommand") .Initialize <WeakCommandBinding>() .AttachTargetEvent("TestViewEvent"); Assert.AreEqual(0, viewModel.Age); view.RaiseTestViewEvent(); Assert.AreEqual(1, viewModel.Age); view.RaiseTestViewEvent(); Assert.AreEqual(2, viewModel.Age); view.RaiseTestViewEvent(); Assert.AreEqual(2, viewModel.Age); }
public void Test_WeakBinding_DeActive() { var viewModel = new TestViewModel(); var view = new TestView(); WeakBinding binding = new WeakPropertyBinding(view, "Text1", viewModel, "Name") .Initialize <WeakPropertyBinding>() .SetMode(BindMode.OneWay) .AttachTargetEvent("TestViewEvent"); viewModel.Name = Name1; binding.DeActivate(); viewModel.Name = Name2; Assert.AreNotEqual(view.Text1, Name2); binding.Activate(); Assert.AreEqual(view.Text1, Name2); }
public void Test_WeakBinding_DetachTargetEvent() { var viewModel = new TestViewModel(); var view = new TestView(); WeakBinding properyBinding = new WeakPropertyBinding(view, "Text1", viewModel, "Name") .Initialize <WeakPropertyBinding>() .AttachSourceEvent("TestViewModelEvent"); viewModel.Name = Name1; Assert.AreNotEqual(view.Text1, Name1); viewModel.RaiseTestViewModelEvent(); Assert.AreEqual(view.Text1, Name1); properyBinding.DetachTargetEvent(); viewModel.Name = Name2; Assert.AreNotEqual(view.Text1, Name2); }
public void Test_WeakBinding_AttachTargetEvent_2() { var viewModel = new TestViewModel(); var view = new TestView(); var button = new Button(); new WeakPropertyBinding(view, "Text1", viewModel, "Name") .Initialize <WeakPropertyBinding>() .SetMode(BindMode.TwoWay) .AttachTargetEvent(button, null, "Click"); viewModel.Name = Name1; Assert.AreEqual(view.Text1, Name1); view.Text1 = Name2; Assert.AreNotEqual(viewModel.Name, Name2); button.PerformClick(); Assert.AreEqual(viewModel.Name, Name2); }
public void ShouldAllowUsingCustomFormatters() { const string validationConstant = "View model is invalid."; var view = new TestView(new TestViewModel { Name = string.Empty }); view.ViewModel.ValidationRule( vm => vm.Name, s => !string.IsNullOrEmpty(s), "Name should not be empty."); view.Bind(view.ViewModel, vm => vm.Name, v => v.NameLabel); view.BindValidation(view.ViewModel, v => v.NameErrorLabel, new ConstFormatter(validationConstant)); Assert.False(view.ViewModel.ValidationContext.IsValid); Assert.Equal(1, view.ViewModel.ValidationContext.Validations.Count); Assert.NotEmpty(view.NameErrorLabel); Assert.Equal(validationConstant, view.NameErrorLabel); }
public void WhenViewExistsAndImplementsIRegionAware_ThenViewIsQueriedForNavigationAndNewInstanceIsCreatedIfItRejectsIt() { // Arrange var containerMock = new Mock <IContainerExtension>(); containerMock.Setup(x => x.Resolve(typeof(IActiveRegionHelper))) .Returns(new RegionResolverOverrides()); var region = new Region(); var viewMock = new Mock <View>(); viewMock .As <IRegionAware>() .Setup(v => v.IsNavigationTarget(It.IsAny <INavigationContext>())) .Returns(false) .Verifiable(); region.Add(viewMock.Object); var newView = new TestView(); containerMock.Setup(sl => sl.Resolve(typeof(object), viewMock.Object.GetType().Name)).Returns(newView); var navigationContext = new NavigationContext(null, new Uri(viewMock.Object.GetType().Name, UriKind.Relative)); var navigationTargetHandler = new TestRegionNavigationContentLoader(containerMock.Object); // Act var returnedView = navigationTargetHandler.LoadContent(region, navigationContext); // Assert Assert.Same(newView, returnedView); Assert.True(region.Views.Contains(newView)); viewMock.VerifyAll(); }
public async Task <IActionResult> CreateTest([FromBody] TestView model) { if (ModelState.IsValid) { var UserId = _userManager.GetUserId(User); var test = new TEST { ID_USER = UserId, NAME_TEST = model.T.NAME_TEST, RESULT = model.T.RESULT, QUESTION = model.T.QUESTION, ID_TYPE = model.T.ID_TYPE }; await testService.Add(test); return(Ok(test)); } return(BadRequest(ModelState)); }
public void ResettingControlTemplateNullsPresenterContent() { var testView = new TestView { ControlTemplate = new ControlTemplate(typeof(PresenterWrapper)) }; var label = new Label(); testView.Content = label; var child1 = ((IElementController)testView).LogicalChildren[0]; var child2 = ((IElementController)child1).LogicalChildren[0]; var originalPresenter = (ContentPresenter)child2; Assert.AreEqual(label, originalPresenter.Content); testView.ControlTemplate = new ControlTemplate(typeof(PresenterWrapper)); Assert.IsNull(originalPresenter.Content); }
public void Test_WeakPropertyBinding_TwoWay() { var viewModel = new TestViewModel(); var view = new TestView(); new WeakPropertyBinding(view, "Text1", viewModel, "Name") .Initialize <WeakPropertyBinding>().OfType <WeakPropertyBinding>() .SetMode(BindMode.TwoWay) .AttachTargetEvent("TestViewEvent") .AttachSourceEvent("TestViewModelEvent"); view.Text1 = Name2; view.RaiseTestViewEvent(); Assert.AreEqual(viewModel.Name, Name2); viewModel.Name = Name1; viewModel.RaiseTestViewModelEvent(); Assert.AreEqual(view.Text1, Name1); }
public void On_child_updated_the_render_operation_is_synchronized() { _console.Height = 40; _console.Width = 100; _console.CursorLeft = _console.CursorTop = 20; var screen = new ScreenView(_renderer, _synchronizationContext); var view = new TestView(); screen.Child = view; //Simulate multiple concurrent updates view.RaiseUpdated(); view.RaiseUpdated(); _synchronizationContext.InvokePostCallbacks(); _synchronizationContext.PostInvocationCount.Should().Be(1); view.RenderedRegions .Should() .BeEquivalentSequenceTo(new Region(0, 0, 100, 40)); }
public void ShouldUpdateValidationHelperBindingOnPropertyChange() { var view = new TestView(new TestViewModel { Name = string.Empty }); const string nameErrorMessage = "Name shouldn't be empty."; view.ViewModel.NameRule = view.ViewModel .ValidationRule( viewModel => viewModel.Name, name => !string.IsNullOrWhiteSpace(name), nameErrorMessage); view.Bind(view.ViewModel, x => x.Name, x => x.NameLabel); view.BindValidation(view.ViewModel, x => x.NameRule, x => x.NameErrorLabel); Assert.Equal(1, view.ViewModel.ValidationContext.Validations.Count); Assert.False(view.ViewModel.ValidationContext.IsValid); Assert.Equal(nameErrorMessage, view.NameErrorLabel); view.ViewModel.NameRule.Dispose(); view.ViewModel.NameRule = null; Assert.Equal(0, view.ViewModel.ValidationContext.Validations.Count); Assert.True(view.ViewModel.ValidationContext.IsValid); Assert.Empty(view.NameErrorLabel); const string secretMessage = "This is the secret message."; view.ViewModel.NameRule = view.ViewModel .ValidationRule( viewModel => viewModel.Name, name => !string.IsNullOrWhiteSpace(name), secretMessage); Assert.Equal(1, view.ViewModel.ValidationContext.Validations.Count); Assert.False(view.ViewModel.ValidationContext.IsValid); Assert.Equal(secretMessage, view.NameErrorLabel); }
public void ShouldSupportBindingTwoValidationsForOneProperty() { const int minimumLength = 5; var viewModel = new TestViewModel { Name = "some" }; var view = new TestView(viewModel); var firstValidation = new BasePropertyValidation <TestViewModel, string>( viewModel, vm => vm.Name, s => !string.IsNullOrEmpty(s), "Name is required."); var minimumLengthErrorMessage = $"Minimum length is {minimumLength}"; var secondValidation = new BasePropertyValidation <TestViewModel, string>( viewModel, vm => vm.Name, s => s.Length > minimumLength, s => minimumLengthErrorMessage); // Add validations viewModel.ValidationContext.Add(firstValidation); viewModel.ValidationContext.Add(secondValidation); // View bindings view.Bind(view.ViewModel, vm => vm.Name, v => v.NameLabel); // View validations bindings view.BindValidation(view.ViewModel, vm => vm.Name, v => v.NameErrorLabel); viewModel.Name = "som"; Assert.False(viewModel.ValidationContext.IsValid); Assert.Equal(2, viewModel.ValidationContext.Validations.Count); // Checks if second validation error message is shown Assert.Equal(minimumLengthErrorMessage, view.NameErrorLabel); }
// POST api/Diagram public TestResult Post([FromBody] TestView diagramView) { if (!ModelState.IsValid) { return(new TestResult("Model state isn't valid")); } TestResult result = null; try { var trueAnswers = _cx.Questions.Where(x => x.Pattern.Id == diagramView.Pattern.Id) .Select(y => y.Answers.Where(z => z.IsTrue).FirstOrDefault()).ToList(); result = new TestResult(diagramView.Pattern, diagramView.Answers, trueAnswers); var userManager = new ApplicationUserManager(new UserStore <ApplicationUser>(_cx)); var user = userManager.Users.Where(x => x.UserName == User.Identity.Name).Single(); var mark = new Mark() { difficulty = Difficulty.Easy, mark = result.Mark, pattern = _cx.Patterns.Find(result.Pattern.Id), percent = result.Percentage, User = user }; _cx.Marks.Add(mark); _cx.SaveChanges(); } catch (Exception e) { return(new TestResult("Bad Request " + e.Message)); } return(result); }
public void Test_WeakNotify_WeakReference() { var button = new Button(); var view = new TestView(); int changedCount = 0; int targetCount = 0; BindingValueChangedHandler sourceChanged = (source, args) => { changedCount++; }; BindingValueChangedHandler targetChanged = (source, args) => { targetCount++; }; new WeakNotifyBinding(view, null, button, null) .Initialize <WeakNotifyBinding>() .AttachTargetEvent("TestViewEvent") .AttachSourceEvent("Click") .OfType <WeakNotifyBinding>() .SetTargetChanged(sourceChanged, true) .SetSourceChanged(targetChanged, true); Assert.AreEqual(0, changedCount); view.RaiseTestViewEvent(); Assert.AreEqual(1, changedCount); button.PerformClick(); Assert.AreEqual(1, targetCount); sourceChanged = null; GC.Collect(); view.RaiseTestViewEvent(); Assert.AreEqual(1, changedCount); targetChanged = null; GC.Collect(); button.PerformClick(); Assert.AreEqual(1, targetCount); }
public void Test_BindingEngine_PropertyBinding() { var viewModel = new TestViewModel(); var view = new TestView(); var binding = BindingEngine.SetPropertyBinding(view, "Text1", viewModel, "Name") .SetMode(BindMode.TwoWay) .AttachTargetEvent("TestViewEvent"); Assert.AreEqual("Name", binding.SourceProperty); Assert.AreEqual("Text1", binding.TargetProperty); viewModel.Name = Name1; Assert.AreEqual(Name1, view.Text1); view.Text1 = Name2; Assert.AreNotEqual(Name2, viewModel.Name); view.RaiseTestViewEvent(); Assert.AreEqual(Name2, viewModel.Name); }
public void Test_WeakSource_ClearAllBindings() { var viewModel = new TestViewModel(); var view = new TestView(); var ws = new WeakTarget(view); ws.SetBinding <WeakPropertyBinding>("Text1", viewModel, "Name"); ws.SetBinding <WeakPropertyBinding>("ValueInt", viewModel, "Age"); viewModel.Name = Name1; Assert.AreEqual(view.Text1, Name1); viewModel.Age = 2; Assert.AreEqual(view.ValueInt, 2); ws.ClearBindings(); viewModel.Name = Name2; viewModel.Age = 3; Assert.AreNotEqual(view.Text1, Name2); Assert.AreNotEqual(view.ValueInt, Name2); }
public void FindView_ViewExistsAndNoMaster_ReturnsView() { // Arrange _engine.ClearMasterLocations(); // If master is not provided, master locations can be empty SetupFileExists("~/vpath/controllerName/viewName.view"); SetupCacheHit(CreateCacheKey(Cache.View), "~/vpath/controllerName/viewName.view"); SetupFileDoesNotExist("~/vpath/controllerName/viewName.Mobile.view"); SetupCacheMiss(CreateCacheKey(Cache.View, displayMode: "Mobile")); // Act ViewEngineResult result = _engine.FindView(_context, "viewName", null, false); // Assert TestView view = Assert.IsType <TestView>(result.View); Assert.Null(result.SearchedLocations); Assert.Same(_context, view.ControllerContext); Assert.Equal("~/vpath/controllerName/viewName.view", view.Path); Assert.Equal(String.Empty, view.MasterPath); }
public void Test_WeakPropertyBinding_DataConverter_WithParameter() { var viewModel = new TestViewModel(); var view = new TestView(); new WeakPropertyBinding(view, "Text1", viewModel, "Age") .Initialize <WeakPropertyBinding>() .SetMode <WeakPropertyBinding>(BindMode.TwoWay) .SetConverter(new TestDataParameterConverter()) .SetParameter(9) .AttachTargetEvent("TestViewEvent"); viewModel.Age = 2; Assert.AreEqual(view.Text1, TestDataParameterConverter.Prefix + 11); view.Text1 = TestDataParameterConverter.Prefix + "13"; view.RaiseTestViewEvent(); Assert.AreEqual(viewModel.Age, 4); }
public void Test_WeakPropertyBinding_Index_Expression_String() { var view = new TestView(); var viewModel = new TestViewModel(); // 1. OneWay binding. BindingEngine.SetPropertyBinding(view, v => v.Text1, viewModel, vm => vm.TestViewModel2.TestViewModel3.TestViewModel4s["12"].Name) .Initialize <WeakPropertyBinding>().OfType <WeakPropertyBinding>() .SetMode(BindMode.TwoWay) .AttachTargetEvent("TestViewEvent"); var viewModel2 = new TestViewModel2(); viewModel.TestViewModel2 = viewModel2; var viewModel3 = new TestViewModel3(); viewModel2.TestViewModel3 = viewModel3; var testViewModels = new ObservableDictionary <string, TestViewModel4>(); viewModel3.TestViewModel4s = testViewModels; var t4 = new TestViewModel4(); testViewModels.Add("12", t4); t4.Name = Name1; Assert.AreEqual(Name1, view.Text1); view.Text1 = Name2; view.RaiseTestViewEvent(); Assert.AreEqual(Name2, t4.Name); var t42 = new TestViewModel4(); testViewModels["12"] = t42; Assert.AreEqual(null, view.Text1); }
public void CreateAndBindViewForModelReturnsViewIfAlreadySet() { var view = new TestView(); var viewModel = new Mock<IViewAware>(); viewModel.SetupGet(x => x.View).Returns(view); var returnedView = this.viewManager.CreateAndBindViewForModelIfNecessary(viewModel.Object); Assert.AreEqual(view, returnedView); }
public void CreateAndBindViewForModelIfNecessaryCallsFetchesViewAndCallsInitializeComponent() { var view = new TestView(); var viewManager = new LocatingViewManager(type => view, new List<Assembly>()); viewManager.LocatedViewType = typeof(TestView); var returnedView = viewManager.CreateAndBindViewForModelIfNecessary(new object()); Assert.True(view.InitializeComponentCalled); Assert.AreEqual(view, returnedView); }
public void Init() { _view = new TestView(); _symbols = new ScriptingViewSymbolDictionary(_view); _scope = IronPython.Hosting.Python.CreateEngine().CreateScope(_symbols); }
public void OnActiveViewChanged_SupplyViewOfNonExistingType_CallsAddView() { _presenter.Run(); IView viewFake = new TestView(); ; _view.Setup(x => x.Views).Returns(new ReadOnlyCollection<IView>(new List<IView>() { new Mock<IView>().Object })); _view.Setup(x => x.AddView(viewFake)); _view.Raise(x => x.OnActiveViewChanged += null, null, viewFake); _view.Verify(x => x.AddView(viewFake), Times.Once); }
public void CreateAndInitializeViewTest1() { TestView viewModel = new TestView(); TestView parentViewModel = new TestView(); TestView currentViewModel = null; TestViewLocator locator = new TestViewLocator(); ViewLocator.Default = locator; ViewHelper.CreateAndInitializeView(ViewLocator.Default, "foo", viewModel, null, null); currentViewModel = (TestView)locator.ResolvedView.DataContext; Assert.AreEqual(currentViewModel, viewModel); ViewHelper.CreateAndInitializeView(ViewLocator.Default, "foo", viewModel, "1", parentViewModel); currentViewModel = (TestView)locator.ResolvedView.DataContext; Assert.AreEqual(currentViewModel, viewModel); Assert.AreEqual(((ISupportParameter)currentViewModel).Parameter, "1"); Assert.AreEqual(((ISupportParentViewModel)currentViewModel).ParentViewModel, parentViewModel); ViewHelper.CreateAndInitializeView(ViewLocator.Default, "foo", null, "1", parentViewModel); currentViewModel = (TestView)locator.ResolvedView.DataContext; Assert.AreNotEqual(currentViewModel, viewModel); Assert.AreEqual(((ISupportParameter)currentViewModel).Parameter, "1"); Assert.AreEqual(((ISupportParentViewModel)currentViewModel).ParentViewModel, parentViewModel); ViewLocator.Default = null; }
public void ReleaseViewCallsDispose() { // Arrange IView view = new TestView(); // Act _engine.ReleaseView(_context, view); // Assert Assert.True(((TestView)view).Disposed); }
public void WhenViewAddedByHandlerDoesNotImplementINavigationAware_ThenReturnsView() { // Arrange var serviceLocatorMock = new Mock<IServiceLocator>(); var region = new Region(); var view = new TestView(); serviceLocatorMock .Setup(sl => sl.GetInstance<object>(view.GetType().Name)) .Returns(view); var navigationContext = new NavigationContext(null, new Uri(view.GetType().Name, UriKind.Relative)); var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object); // Act var firstReturnedView = navigationTargetHandler.LoadContent(region, navigationContext); var secondReturnedView = navigationTargetHandler.LoadContent(region, navigationContext); // Assert Assert.AreSame(view, firstReturnedView); Assert.AreSame(view, secondReturnedView); serviceLocatorMock.Verify(sl => sl.GetInstance<object>(view.GetType().Name), Times.Once()); }
public void ParentControlTemplateDoesNotClearChildTemplate () { var parentView = new TestView (); var childView = new TestView (); parentView.Platform = new UnitPlatform (); parentView.Content = childView; childView.Content = new Button (); var childPresenter = (ContentPresenter)childView.LogicalChildren[0].LogicalChildren[1]; parentView.ControlTemplate = new ControlTemplate (typeof (ContentControl)); Assert.IsNotNull (childPresenter.Content); }
public TestViewElement() { DataContext = new TestView(); }
public void TestQ536034() { object parameter = 1; TestViewElement view = new TestViewElement() { DataContext = null }; BindingOperations.SetBinding(view, ViewModelExtensions.ParameterProperty, new Binding() { Source = parameter }); TestView viewModel = new TestView(); view.DataContext = viewModel; Assert.AreEqual(1, ((ISupportParameter)viewModel).Parameter); viewModel = new TestView(); view.DataContext = viewModel; Assert.AreEqual(1, ((ISupportParameter)viewModel).Parameter); parameter = 2; ViewModelExtensions.SetParameter(view, 2); Assert.AreEqual(2, ((ISupportParameter)viewModel).Parameter); Assert.AreEqual(1, Interaction.GetBehaviors(view).Count); }
public void init() { _testView = gameObject.AddComponent<TestView>(); _testView.init(); }
public void WhenViewExistsAndHasDataContextThatImplementsINavigationAware_ThenDataContextIsQueriedForNavigationAndNewInstanceIsCreatedIfItRejectsIt() { // Arrange var serviceLocatorMock = new Mock<IServiceLocator>(); var region = new Region(); var dataContextMock = new Mock<INavigationAware>(); dataContextMock .Setup(v => v.IsNavigationTarget(It.IsAny<NavigationContext>())) .Returns(false) .Verifiable(); var viewMock = new Mock<FrameworkElement>(); viewMock.Object.DataContext = dataContextMock.Object; region.Add(viewMock.Object); var newView = new TestView(); serviceLocatorMock .Setup(sl => sl.GetInstance<object>(viewMock.Object.GetType().Name)) .Returns(newView); var navigationContext = new NavigationContext(null, new Uri(viewMock.Object.GetType().Name, UriKind.Relative)); var navigationTargetHandler = new TestRegionNavigationContentLoader(serviceLocatorMock.Object); // Act var returnedView = navigationTargetHandler.LoadContent(region, navigationContext); // Assert Assert.AreSame(newView, returnedView); Assert.IsTrue(region.Views.Contains(newView)); dataContextMock.VerifyAll(); }