How to use Method2 method of TestClasses.BaseClass class

Best Vstest code snippet using TestClasses.BaseClass.Method2

ViewModelSourceTests.cs

Source:ViewModelSourceTests.cs Github

copy

Full Screen

...425 public class DuplicateNamesViewModel {426 [Command(Name = "MyCommand")]427 public void Method1() { }428 [Command(Name = "MyCommand")]429 public void Method2() { }430 }431 [Test]432 public void CommandAttribute_DuplicateNamesTest() {433 AssertHelper.AssertThrows<ViewModelSourceException>(() => {434 CreatePOCOViewModel<DuplicateNamesViewModel>();435 }, x => Assert.AreEqual("Member with the same command name already exists: MyCommand.", x.Message));436 }437 public class NotPublicMethodViewModel {438 [Command]439 void NotPublicMethod() { }440 }441 [Test]442 public void CommandAttribute_NotPublicMethodTest() {443 AssertHelper.AssertThrows<ViewModelSourceException>(() => {444 CreatePOCOViewModel<NotPublicMethodViewModel>();445 }, x => Assert.AreEqual("Method should be public: NotPublicMethod.", x.Message));446 }447 public class TooMuchArgumentsMethodViewModel {448 [Command]449 public void TooMuchArgumentsMethod(int a, int b) { }450 }451 [Test]452 public void CommandAttribute_TooMuchArgumentsMethodTest() {453 AssertHelper.AssertThrows<ViewModelSourceException>(() => {454 CreatePOCOViewModel<TooMuchArgumentsMethodViewModel>();455 }, x => Assert.AreEqual("Method cannot have more than one parameter: TooMuchArgumentsMethod.", x.Message));456 }457 public class OutParameterMethodViewModel {458 [Command]459 public void OutParameterMethod(out int a) { a = 0; }460 }461 [Test]462 public void CommandAttribute_OutParameterMethodTest() {463 AssertHelper.AssertThrows<ViewModelSourceException>(() => {464 CreatePOCOViewModel<OutParameterMethodViewModel>();465 }, x => Assert.AreEqual("Method cannot have out or reference parameter: OutParameterMethod.", x.Message));466 }467 public class RefParameterMethodViewModel {468 [Command]469 public void RefParameterMethod(ref int a) { a = 0; }470 }471 [Test]472 public void CommandAttribute_RefParameterMethodTest() {473 AssertHelper.AssertThrows<ViewModelSourceException>(() => {474 CreatePOCOViewModel<RefParameterMethodViewModel>();475 }, x => Assert.AreEqual("Method cannot have out or reference parameter: RefParameterMethod.", x.Message));476 }477 public class CanExecuteParameterCountMismatchViewModel {478 [Command]479 public void Method() { }480 public bool CanMethod(int a) { return true; }481 }482 [Test]483 public void CommandAttribute_CanExecuteParameterCountMismatchTest() {484 AssertHelper.AssertThrows<ViewModelSourceException>(() => {485 CreatePOCOViewModel<CanExecuteParameterCountMismatchViewModel>();486 }, x => Assert.AreEqual("Can execute method has incorrect parameters: CanMethod.", x.Message));487 }488 public class CanExecuteParametersMismatchViewModel {489 [Command]490 public void Method(long a) { }491 public bool CanMethod(int a) { return true; }492 }493 [Test]494 public void CommandAttribute_CanExecuteParametersMismatchTest() {495 AssertHelper.AssertThrows<ViewModelSourceException>(() => {496 CreatePOCOViewModel<CanExecuteParametersMismatchViewModel>();497 }, x => Assert.AreEqual("Can execute method has incorrect parameters: CanMethod.", x.Message));498 }499 public class CanExecuteParametersMismatchViewModel2 {500 [Command]501 public void Method(int a) { }502 public bool CanMethod(out int a) { a = 0; return true; }503 }504 [Test]505 public void CommandAttribute_CanExecuteParametersMismatchTest2() {506 AssertHelper.AssertThrows<ViewModelSourceException>(() => {507 CreatePOCOViewModel<CanExecuteParametersMismatchViewModel2>();508 }, x => Assert.AreEqual("Can execute method has incorrect parameters: CanMethod.", x.Message));509 }510 public class NotPublicCanExecuteViewModel {511 [Command]512 public void Method() { }513 bool CanMethod() { return true; }514 }515 [Test]516 public void CommandAttribute_NotPublicCanExecuteTest() {517 AssertHelper.AssertThrows<ViewModelSourceException>(() => {518 CreatePOCOViewModel<NotPublicCanExecuteViewModel>();519 }, x => Assert.AreEqual("Method should be public: CanMethod.", x.Message));520 }521 public class InvalidCanExecuteMethodNameViewModel {522 [Command(CanExecuteMethodName = "CanMethod_")]523 public void Method() { }524 }525 [Test]526 public void CommandAttribute_InvalidCanExecuteMethodNameTest() {527 AssertHelper.AssertThrows<ViewModelSourceException>(() => {528 CreatePOCOViewModel<InvalidCanExecuteMethodNameViewModel>();529 }, x => Assert.AreEqual("Method not found: CanMethod_.", x.Message));530 }531 #endregion532 #region ctors533 public class InternalCtor {534 public InternalCtor() { }535 internal InternalCtor(int x) { }536 }537 [Test]538 public void InternalCtorTest() {539 AssertHelper.AssertThrows<ViewModelSourceException>(() => {540 CreatePocoViewModel(() => new InternalCtor(0));541 }, x => Assert.AreEqual("Constructor not found.", x.Message));542 }543 public class OnlyInternalCtor {544 internal OnlyInternalCtor(int x) { }545 }546 [Test]547 public void OnlyInternalCtorTest() {548 AssertHelper.AssertThrows<ViewModelSourceException>(() => {549 CreatePocoViewModel(() => new OnlyInternalCtor(0));550 }, x => Assert.AreEqual("Type has no accessible constructors: OnlyInternalCtor.", x.Message));551 }552 [Test]553 public void CreateViaGenericParameters_InvalidParaneterTypes() {554 AssertHelper.AssertThrows<ViewModelSourceException>(() => {555 var viewModel = ViewModelSource<POCOViewModel_CreateViaGenericParameters>.Create(1);556 }, x => Assert.AreEqual("Constructor not found.", x.Message));557 }558 [Test]559 public void GetFactory_MemberInitializers() {560 AssertHelper.AssertThrows<ViewModelSourceException>(() => {561 ViewModelSource.Factory((string p1) => new POCOViewModel_CreateViaGenericParameters(p1));562 ViewModelSource.Factory((string p1) => new POCOViewModel_CreateViaGenericParameters(p1) { ConstructorInfo = "" });563 }, x => Assert.AreEqual("Constructor expression can only be of NewExpression type.", x.Message));564 }565 [Test]566 public void GetFactory_InvalidCtorParameters() {567 AssertHelper.AssertThrows<ViewModelSourceException>(() => {568 ViewModelSource.Factory((string p1) => new POCOViewModel_CreateViaGenericParameters(p1));569 ViewModelSource.Factory((string p1) => new POCOViewModel_CreateViaGenericParameters("x"));570 }, x => Assert.AreEqual("Constructor expression can refer only to its arguments.", x.Message));571 }572 #endregion573 #region services574 public class Services_NotServiceType {575 [ServiceProperty]576 public virtual SomeService Property { get { return null; } }577 }578 [Test]579 public void Services_NotServiceTypeTest() {580 AssertHelper.AssertThrows<ViewModelSourceException>(() => {581 CreatePocoViewModel(() => new Services_NotServiceType());582 }, x => Assert.AreEqual("Service properties should have an interface type: Property.", x.Message));583 }584 public class Services_PropertyIsNotVirtual {585 [ServiceProperty]586 public IMessageBoxService Property { get { return null; } }587 }588 [Test]589 public void Services_PropertyIsNotVirtualTest() {590 AssertHelper.AssertThrows<ViewModelSourceException>(() => {591 CreatePocoViewModel(() => new Services_PropertyIsNotVirtual());592 }, x => Assert.AreEqual("Property is not virtual: Property.", x.Message));593 }594 public class Services_PropertyIsSealedBase {595 public virtual IMessageBoxService Property { get { return null; } }596 }597 public class Services_PropertyIsSealed : Services_PropertyIsSealedBase {598 [ServiceProperty]599 public override sealed IMessageBoxService Property { get { return null; } }600 }601 [Test]602 public void Services_PropertyIsSealedTest() {603 AssertHelper.AssertThrows<ViewModelSourceException>(() => {604 CreatePocoViewModel(() => new Services_PropertyIsSealed());605 }, x => Assert.AreEqual("Cannot override final property: Property.", x.Message));606 }607 public class Services_PropertyHasSetter {608 [ServiceProperty]609 public virtual IMessageBoxService Property { get; set; }610 }611 [Test]612 public void Services_PropertyHasSetterTest() {613 AssertHelper.AssertThrows<ViewModelSourceException>(() => {614 CreatePocoViewModel(() => new Services_PropertyHasSetter());615 }, x => Assert.AreEqual("Property with setter cannot be Service Property: Property.", x.Message));616 }617 #endregion618 public class T370425VM { }619 [Test]620 public void T370425() {621 var vm = CreatePOCOViewModel<T370425VM>();622 AssertHelper.AssertThrows<InvalidOperationException>(() => ((ISupportParentViewModel)vm).ParentViewModel = vm,623 e => Assert.AreEqual("ViewModel cannot be parent of itself.", e.Message));624 }625#pragma warning restore 0618626 #endregion627 public class DesignTimeViewModel {628 public virtual string Property { get; set; }629 }630 [Test]631 public void DesignTimeGeneration() {632 ViewModelDesignHelper.IsInDesignModeOverride = true;633 try {634 DesignTimeViewModel viewModel1 = CreatePOCOViewModel<DesignTimeViewModel>();635 Assert.AreNotEqual(typeof(DesignTimeViewModel), viewModel1.GetType());636 } finally {637 ViewModelDesignHelper.IsInDesignModeOverride = null;638 }639 }640 [Test]641 public void IsInDesignMode_NotPOCOViewModelTest() {642 POCOViewModel_PropertyChanged viewModel = new POCOViewModel_PropertyChanged();643 Assert.IsFalse(viewModel.IsInDesignMode());644 }645 [Test]646 public void OverridingPropertyTest() {647 POCOViewModel viewModel = CreatePOCOViewModel<POCOViewModel>();648 Assert.AreEqual(viewModel.GetType(), viewModel.GetType().GetProperty("Property1").DeclaringType);649 CheckBindableProperty(viewModel, x => x.Property1, (vm, x) => vm.Property1 = x, "x", "y");650 CheckBindableProperty(viewModel, x => x.Property2, (vm, x) => vm.Property2 = x, "m", "n");651 CheckBindableProperty(viewModel, x => x.Property3, (vm, x) => vm.Property3 = x, "a", "b");652 CheckBindableProperty(viewModel, x => x.Property4, (vm, x) => vm.Property4 = x, 1, 2);653 CheckBindableProperty(viewModel, x => x.Property5, (vm, x) => vm.Property5 = x, new Point(1, 1), new Point(2, 2));654 CheckBindableProperty(viewModel, x => x.Property6, (vm, x) => vm.Property6 = x, 5, null);655 CheckBindableProperty(viewModel, x => x.ProtectedSetterProperty, (vm, x) => vm.ProtectedSetterProperty = x, "x", "y");656 Assert.IsNull(viewModel.GetType().GetProperty("ProtectedSetterProperty").GetSetMethod());657 CheckNotBindableProperty(viewModel, x => x.NotVirtualProperty, (vm, x) => vm.NotVirtualProperty = x, "x", "y");658 CheckNotBindableProperty(viewModel, x => x.NotPublicProperty, (vm, x) => vm.NotPublicProperty = x, "x", "y");659 CheckNotBindableProperty(viewModel, x => x.ProtectedGetterProperty, (vm, x) => vm.ProtectedGetterProperty = x, "x", "y");660 CheckNotBindableProperty(viewModel, x => x.InternalSetterProperty, (vm, x) => vm.InternalSetterProperty = x, "x", "y");661 CheckNotBindableProperty(viewModel, x => x.NotAutoImplementedProperty, (vm, x) => vm.NotAutoImplementedProperty = x, "x", "y");662 }663 #region INPChanging664 public class POCOWithoutINPChanging {665 public virtual int Property { get; set; }666 }667 public class POCOImplementingINPChanging1 : INotifyPropertyChanging {668 public event PropertyChangingEventHandler PropertyChanging;669 public void Raise() {670 PropertyChanging.Do(x => x(null, null));671 }672 }673 [POCOViewModel(ImplementINotifyPropertyChanging = true)]674 public class POCOImplementingINPChanging2 : INotifyPropertyChanging {675 public event PropertyChangingEventHandler PropertyChanging;676 public void Raise() {677 PropertyChanging.Do(x => x(null, null));678 }679 }680 [POCOViewModel(ImplementINotifyPropertyChanging = true)]681 public class POCOImplementingINPChanging3 : INotifyPropertyChanging {682 public event PropertyChangingEventHandler PropertyChanging;683 public void RaisePropertyChanging(string propertyName) {684 PropertyChanging.Do(x => x(null, null));685 }686 }687 [Test]688 public void NPChangingExceptions() {689 AssertHelper.AssertThrows<ViewModelSourceException>(() => {690 IPOCOViewModel iPOCOViewModel = (IPOCOViewModel)CreatePOCOViewModel<POCOWithoutINPChanging>();691 iPOCOViewModel.RaisePropertyChanging(null);692 }, x => x.Message.AreEqual(string.Format(693 ViewModelSourceException.Error_INotifyPropertyChangingIsNotImplemented,694 typeof(POCOWithoutINPChanging).Name)));695 AssertHelper.AssertThrows<ViewModelSourceException>(() => {696 IPOCOViewModel iPOCOViewModel = (IPOCOViewModel)CreatePOCOViewModel<POCOImplementingINPChanging1>();697 iPOCOViewModel.RaisePropertyChanging(null);698 }, x => x.Message.AreEqual(string.Format(699 ViewModelSourceException.Error_INotifyPropertyChangingIsNotImplemented,700 typeof(POCOImplementingINPChanging1).Name)));701 AssertHelper.AssertThrows<ViewModelSourceException>(() => {702 CreatePOCOViewModel<POCOImplementingINPChanging2>();703 }, x => x.Message.AreEqual(string.Format(704 ViewModelSourceException.Error_RaisePropertyChangingMethodNotFound,705 typeof(POCOImplementingINPChanging2).Name)));706 AssertHelper.AssertDoesNotThrow(() => {707 CreatePOCOViewModel<POCOImplementingINPChanging3>();708 });709 }710 [POCOViewModel(ImplementINotifyPropertyChanging = true)]711 public class POCOWithINPChanging1 {712 public virtual int Property { get; set; }713 }714 public class POCOWithINPChanging2 : INotifyPropertyChanging {715 public virtual int Property { get; set; }716 public event PropertyChangingEventHandler PropertyChanging;717 protected void RaisePropertyChanging(string propName) {718 PropertyChanging.Do(x => x(this, new PropertyChangingEventArgs(propName)));719 }720 }721 [POCOViewModel(ImplementINotifyPropertyChanging = true)]722 public class POCOWithINPChanging3 : POCOWithINPChanging2 { }723 [Test]724 public void NPChangingTest1() {725 NPChangingTestCore(typeof(POCOWithINPChanging1), x => ((POCOWithINPChanging1)x).Property, (x, v) => ((POCOWithINPChanging1)x).Property = v);726 }727 [Test]728 public void NPChangingTest3() {729 NPChangingTestCore(typeof(POCOWithINPChanging3), x => ((POCOWithINPChanging3)x).Property, (x, v) => ((POCOWithINPChanging3)x).Property = v);730 }731 void NPChangingTestCore(Type type, Func<object, int> getProperty, Action<object, int> setProperty) {732 var vm = CreatePOCOViewModel(type);733 INotifyPropertyChanging inpc = (INotifyPropertyChanging)vm;734 int propertyChangingCounter = 0;735 int oldValue = 0;736 inpc.PropertyChanging += (d, e) => {737 Assert.AreSame(vm, d);738 e.PropertyName.AreEqual("Property");739 propertyChangingCounter++;740 oldValue = getProperty(vm);741 };742 setProperty(vm, 1);743 oldValue.AreEqual(0);744 propertyChangingCounter.AreEqual(1);745 setProperty(vm, 2);746 oldValue.AreEqual(1);747 propertyChangingCounter.AreEqual(2);748 }749 [Test]750 public void NPChangingTest2() {751 var vm = CreatePOCOViewModel<POCOWithINPChanging2>();752 INotifyPropertyChanging inpc = (INotifyPropertyChanging)vm;753 int propertyChangingCounter = 0;754 inpc.PropertyChanging += (d, e) => {755 propertyChangingCounter++;756 };757 vm.Property = 1;758 vm.Property = 2;759 propertyChangingCounter.AreEqual(0);760 }761 #endregion762 #region property changed763 public class POCOViewModel_PropertyChangedBase {764 protected virtual void OnProtectedChangedMethodWithParamChanged(string oldValue) { }765 public virtual bool SealedProperty { get; set; }766 }767 public class POCOViewModel_PropertyChanged : POCOViewModel_PropertyChangedBase {768 public string ProtectedChangedMethodWithParamOldValue;769 public bool OnProtectedChangedMethodWithParamChangedCalled;770 public virtual string ProtectedChangedMethodWithParam { get; set; }771 protected override void OnProtectedChangedMethodWithParamChanged(string oldValue) {772 Assert.AreNotEqual(ProtectedChangedMethodWithParam, ProtectedChangedMethodWithParamOldValue);773 OnProtectedChangedMethodWithParamChangedCalled = true;774 ProtectedChangedMethodWithParamOldValue = oldValue;775 }776 public sealed override bool SealedProperty { get; set; }777 public int PublicChangedMethodWithoutParamOldValue;778 public virtual int PublicChangedMethodWithoutParam { get; set; }779 public void OnPublicChangedMethodWithoutParamChanged() {780 PublicChangedMethodWithoutParamOldValue++;781 }782 public int ProtectedInternalChangedMethodWithoutParamOldValue;783 public virtual int ProtectedInternalChangedMethodWithoutParam { get; set; }784 protected internal void OnProtectedInternalChangedMethodWithoutParamChanged() {785 ProtectedInternalChangedMethodWithoutParamOldValue++;786 }787 }788 [Test]789 public void PropertyChangedTest() {790 POCOViewModel_PropertyChanged viewModel = CreatePOCOViewModel<POCOViewModel_PropertyChanged>();791 ((INotifyPropertyChanged)viewModel).PropertyChanged += (o, e) => Assert.IsFalse(viewModel.OnProtectedChangedMethodWithParamChangedCalled);792 CheckBindableProperty(viewModel, x => x.ProtectedChangedMethodWithParam, (vm, x) => vm.ProtectedChangedMethodWithParam = x, "x", "y", (x, val) => {793 Assert.IsTrue(x.OnProtectedChangedMethodWithParamChangedCalled);794 x.OnProtectedChangedMethodWithParamChangedCalled = false;795 Assert.AreEqual(val, x.ProtectedChangedMethodWithParamOldValue);796 });797 CheckBindableProperty(viewModel, x => x.PublicChangedMethodWithoutParam, (vm, x) => vm.PublicChangedMethodWithoutParam = x, 1, 2, (x, val) => Assert.AreEqual(val + 1, x.PublicChangedMethodWithoutParamOldValue));798 CheckBindableProperty(viewModel, x => x.ProtectedInternalChangedMethodWithoutParam, (vm, x) => vm.ProtectedInternalChangedMethodWithoutParam = x, 1, 2, (x, val) => Assert.AreEqual(val + 1, x.ProtectedInternalChangedMethodWithoutParamOldValue));799 }800 public class ViewModelWithFunctionCommandMethod {801 [Command]802 public bool Save() {803 return true;804 }805 }806 [Test]807 public void GetCommandFromFunction_VB() {808 ViewModelWithFunctionCommandMethod viewModel = CreatePOCOViewModel<ViewModelWithFunctionCommandMethod>();809 ParameterExpression parameter1 = Expression.Parameter(typeof(ViewModelWithFunctionCommandMethod), "x");810 MethodCallExpression methodCallExpression = Expression.Call((Expression)parameter1, typeof(ViewModelWithFunctionCommandMethod).GetMethod("Save", BindingFlags.Public | BindingFlags.Instance), new Expression[0]);811 var expression = Expression.Lambda<Func<ViewModelWithFunctionCommandMethod, bool>>(methodCallExpression, parameter1);812 ParameterExpression parameter2 = Expression.Parameter(typeof(ViewModelWithFunctionCommandMethod), "a0");813 var methodExpression = Expression.Lambda<Action<ViewModelWithFunctionCommandMethod>>(Expression.Invoke(expression, parameter2), parameter2);814 Assert.IsNotNull(POCOViewModelExtensions.GetCommand(viewModel, methodExpression));815 }816 [Test]817 public void PropertyChangedTest_VB() {818 VbPOCOViewModel viewModel = CreatePOCOViewModel<VbPOCOViewModel>();819 CheckBindableProperty(viewModel, x => x.AutoImlementedProperty, (vm, x) => vm.AutoImlementedProperty = x, 1, 2, (x, val) => Assert.AreEqual(val, x.AutoImlementedPropertyOldValue));820 CheckNotBindableProperty(viewModel, x => x.AutoImlementedNonVirtualProperty, (vm, x) => vm.AutoImlementedNonVirtualProperty = x, 1, 2);821 CheckBindableProperty(viewModel, x => x.AutoImlementedEntityProperty, (vm, x) => vm.AutoImlementedEntityProperty = x, new TestEntity(), new TestEntity());822 CheckNotBindableProperty(viewModel, x => x.PseudoAutoImplementedProperty_WrongFieldName, (vm, x) => vm.PseudoAutoImplementedProperty_WrongFieldName = x, 1, 2);823 CheckNotBindableProperty(viewModel, x => x.PseudoAutoImplementedProperty_NoAttributeOnField, (vm, x) => vm.PseudoAutoImplementedProperty_NoAttributeOnField = x, 1, 2);824 CheckNotBindableProperty(viewModel, x => x.PseudoAutoImplementedProperty_WrongParameterName, (vm, x) => vm.PseudoAutoImplementedProperty_WrongParameterName = x, 1, 2);825 CheckNotBindableProperty(viewModel, x => x.PseudoAutoImplementedProperty_WrongFieldType, (vm, x) => vm.PseudoAutoImplementedProperty_WrongFieldType = x, 1, 2);826 CheckBindableProperty(viewModel, x => x.PseudoAutoImplementedProperty, (vm, x) => vm.PseudoAutoImplementedProperty = x, 1, 2);827 }828 [Test]829 public void PropertyNameInSetterAndGetterShouldMatchTest_VB() {830 var obj = new PropertyNameInSetterAndGetterShouldMatch();831 obj.Test(BindableBase.GetPropertyName);832 Assert.IsNotNull(obj.nameInGetter);833 Assert.AreEqual(obj.nameInGetter, obj.nameInSetter);834 }835 #endregion836 #region property changing837 public class POCOViewModel_PropertyChanging {838 public virtual string Property1 { get; set; }839 public string Property1NewValue;840 protected void OnProperty1Changing(string newValue) {841 Assert.AreNotEqual(newValue, Property1);842 Property1NewValue = newValue;843 }844 public virtual string Property2 { get; set; }845 public int Property2ChangingCallCount;846 protected void OnProperty2Changing() {847 Assert.AreEqual(null, Property2);848 Property2ChangingCallCount++;849 }850 string property3;851 [BindableProperty]852 public virtual string Property3 { get { return property3; } set { property3 = value; } }853 protected void OnProperty3Changing() {854 throw new NotImplementedException();855 }856 }857 [Test]858 public void PropertyChangingTest() {859 POCOViewModel_PropertyChanging viewModel = CreatePOCOViewModel<POCOViewModel_PropertyChanging>();860 viewModel.Property1 = null;861 viewModel.Property1 = "x";862 Assert.AreEqual("x", viewModel.Property1NewValue);863 viewModel.Property2 = null;864 viewModel.Property2 = "x";865 Assert.AreEqual(1, viewModel.Property2ChangingCallCount);866 viewModel.Property3 = "x";867 }868 #endregion869 #region subscribe in constructor870 public class POCOViewModel_SubscribeInCtor {871 public POCOViewModel_SubscribeInCtor() {872 ((INotifyPropertyChanged)this).PropertyChanged += POCOViewModel_SubscribeInCtor_PropertyChanged;873 Property = "x";874 }875 public int propertyChangedCallCount;876 void POCOViewModel_SubscribeInCtor_PropertyChanged(object sender, PropertyChangedEventArgs e) {877 propertyChangedCallCount++;878 }879 public virtual string Property { get; set; }880 }881 [Test]882 public void POCOViewModel_SubscribeInCtorTest() {883 POCOViewModel_SubscribeInCtor viewModel = CreatePOCOViewModel<POCOViewModel_SubscribeInCtor>();884 Assert.AreEqual(1, viewModel.propertyChangedCallCount);885 }886 #endregion887 #region metadata888 public class POCOViewModel_WithMetadata {889 [BindableProperty(false)]890 public virtual string NotBindableProperty { get; set; }891 string notAutoImplementedProperty;892 [BindableProperty]893 public virtual string NotAutoImplementedProperty { get { return notAutoImplementedProperty; } set { notAutoImplementedProperty = value; } }894 public string CustomProperytChangedOldValue;895 string customProperytChanged;896 [BindableProperty(OnPropertyChangedMethodName = "OnCustomProperytChanged")]897 public virtual string CustomProperytChanged { get { return customProperytChanged; } set { customProperytChanged = value; } }898 protected void OnCustomProperytChanged(string oldValue) {899 CustomProperytChangedOldValue = oldValue;900 }901 [BindableProperty(OnPropertyChangingMethodName = "MyPropertyChanging")]902 public virtual string PropertyChanging { get; set; }903 public string PropertyChangingNewValue;904 protected void MyPropertyChanging(string newValue) {905 Assert.AreNotEqual(newValue, PropertyChanging);906 PropertyChangingNewValue = newValue;907 }908 }909 [MetadataType(typeof(POCOViewModel_WithMetadata_FluentAPIMetadata))]910 public class POCOViewModel_WithMetadata_FluentAPI {911 public class POCOViewModel_WithMetadata_FluentAPIMetadata : IMetadataProvider<POCOViewModel_WithMetadata_FluentAPI> {912 void IMetadataProvider<POCOViewModel_WithMetadata_FluentAPI>.BuildMetadata(MetadataBuilder<POCOViewModel_WithMetadata_FluentAPI> builder) {913 builder.Property(x => x.NotBindableProperty).DoNotMakeBindable();914 builder.Property(x => x.NotAutoImplementedProperty).MakeBindable();915 builder.Property(x => x.CustomProperytChanged).OnPropertyChangedCall(x => x.OnCustomProperytChanged(null));916 builder.Property(x => x.PropertyChanging).OnPropertyChangingCall(x => x.MyPropertyChanging(null));917 }918 }919 public virtual string NotBindableProperty { get; set; }920 string notAutoImplementedProperty;921 public virtual string NotAutoImplementedProperty { get { return notAutoImplementedProperty; } set { notAutoImplementedProperty = value; } }922 public string CustomProperytChangedOldValue;923 string customProperytChanged;924 public virtual string CustomProperytChanged { get { return customProperytChanged; } set { customProperytChanged = value; } }925 protected void OnCustomProperytChanged() {926 }927 protected void OnCustomProperytChanged(string oldValue) {928 CustomProperytChangedOldValue = oldValue;929 }930 public virtual string PropertyChanging { get; set; }931 public string PropertyChangingNewValue;932 protected void MyPropertyChanging(string newValue) {933 Assert.AreNotEqual(newValue, PropertyChanging);934 PropertyChangingNewValue = newValue;935 }936 }937 [Test]938 public void OverridingPropertyTest_Metadata() {939 POCOViewModel_WithMetadata viewModel = CreatePOCOViewModel<POCOViewModel_WithMetadata>();940 CheckNotBindableProperty(viewModel, x => x.NotBindableProperty, (vm, x) => vm.NotBindableProperty = x, "x", "y");941 CheckBindableProperty(viewModel, x => x.NotAutoImplementedProperty, (vm, x) => vm.NotAutoImplementedProperty = x, "x", "y");942 CheckBindableProperty(viewModel, x => x.CustomProperytChanged, (vm, x) => vm.CustomProperytChanged = x, "x", "y", (x, val) => Assert.AreEqual(val, x.CustomProperytChangedOldValue));943 viewModel.PropertyChanging = null;944 viewModel.PropertyChanging = "x";945 Assert.AreEqual("x", viewModel.PropertyChangingNewValue);946 }947 [Test]948 public void OverridingPropertyTest_Metadata_FluentAPI() {949 POCOViewModel_WithMetadata_FluentAPI viewModel = CreatePOCOViewModel<POCOViewModel_WithMetadata_FluentAPI>();950 CheckNotBindableProperty(viewModel, x => x.NotBindableProperty, (vm, x) => vm.NotBindableProperty = x, "x", "y");951 CheckBindableProperty(viewModel, x => x.NotAutoImplementedProperty, (vm, x) => vm.NotAutoImplementedProperty = x, "x", "y");952 CheckBindableProperty(viewModel, x => x.CustomProperytChanged, (vm, x) => vm.CustomProperytChanged = x, "x", "y", (x, val) => Assert.AreEqual(val, x.CustomProperytChangedOldValue));953 viewModel.PropertyChanging = null;954 viewModel.PropertyChanging = "x";955 Assert.AreEqual("x", viewModel.PropertyChangingNewValue);956 }957 public class INPCDefaultPriorityViewModel {958 public int onChangedCalledCount = 0;959 public virtual string Property { get; set; }960 public void OnPropertyChanged() {961 onChangedCalledCount++;962 }963 }964 [POCOViewModel(InvokeOnPropertyChangedMethodBeforeRaisingINPC = true)]965 public class INPCOnChangedFirstPriorityViewModel : INPCDefaultPriorityViewModel { }966 [Test]967 public void INPCPriorityTest() {968 var vm = CreatePOCOViewModel<INPCDefaultPriorityViewModel>();969 var inpc = (INotifyPropertyChanged)vm;970 inpc.PropertyChanged += (s, a) => {971 Assert.AreEqual("Property", a.PropertyName);972 Assert.AreEqual(vm.onChangedCalledCount, 0);973 };974 vm.Property = "value";975 Assert.AreEqual(vm.onChangedCalledCount, 1);976 vm = CreatePOCOViewModel<INPCOnChangedFirstPriorityViewModel>();977 inpc = (INotifyPropertyChanged)vm;978 inpc.PropertyChanged += (s, a) => {979 Assert.AreEqual("Property", a.PropertyName);980 Assert.AreEqual(vm.onChangedCalledCount, 1);981 };982 vm.Property = "value";983 Assert.AreEqual(vm.onChangedCalledCount, 1);984 }985 #endregion986 #region IPOCOViewModelImplementation987 [Test]988 public void IPOCOViewModelImplementation() {989 var viewModel = CreatePOCOViewModel<POCOViewModel>();990 string propertyName = null;991 ((INotifyPropertyChanged)viewModel).PropertyChanged += (o, e) => propertyName = e.PropertyName;992 ((IPOCOViewModel)viewModel).RaisePropertyChanged("Property1");993 Assert.AreEqual("Property1", propertyName);994 viewModel.RaisePropertyChanged(x => x.Property5);995 Assert.AreEqual("Property5", propertyName);996 viewModel.RaisePropertiesChanged();997 Assert.AreEqual(string.Empty, propertyName);998 }999 [Test]1000 public void GetSetParentViewModel() {1001 var viewModel = CreatePOCOViewModel<POCOViewModel>();1002 Assert.IsNull(viewModel.GetParentViewModel<Button>());1003 var b = new Button();1004 Assert.AreSame(viewModel, viewModel.SetParentViewModel(b));1005 Assert.AreEqual(b, viewModel.GetParentViewModel<Button>());1006 }1007 #endregion1008 #region commands1009 public class NotBrowsableCommand {1010 [Browsable(false)]1011 public void Method1() { }1012 [Browsable(true)]1013 public void Method2() { }1014 }1015 [Test]1016 public void NotBrowsableCommandTest() {1017 TypeDescriptor.GetProperties(ViewModelSource.GetPOCOType(typeof(NotBrowsableCommand)))["Method1Command"]1018 .Attributes.OfType<BrowsableAttribute>()1019 .First().IsFalse(x => x.Browsable);1020 TypeDescriptor.GetProperties(ViewModelSource.GetPOCOType(typeof(NotBrowsableCommand)))["Method2Command"]1021 .Attributes.OfType<BrowsableAttribute>()1022 .First().IsTrue(x => x.Browsable);1023 }1024 public class ProtecteCanExecuteMethod {1025 public bool IsMethod1Enabled;1026 public void Method1() {1027 MessageBox.Show("Hello");1028 }1029 protected bool CanMethod1() {1030 return IsMethod1Enabled;1031 }1032 public bool IsMethod2Enabled;1033 public void Method2() {1034 MessageBox.Show("Hello");1035 }1036 protected internal bool CanMethod2() {1037 return IsMethod2Enabled;1038 }1039 }1040 [Test]1041 public void ProtectedCanExecuteMethod() {1042 var viewModel = CreatePOCOViewModel<ProtecteCanExecuteMethod>();1043 viewModel1044 .IsFalse(x => x.GetCommand(y => y.Method1()).CanExecute(null))1045 .Do(x => x.IsMethod1Enabled = true)1046 .IsTrue(x => x.GetCommand(y => y.Method1()).CanExecute(null))1047 .IsFalse(x => x.GetCommand(y => y.Method2()).CanExecute(null))1048 .Do(x => x.IsMethod2Enabled = true)1049 .IsTrue(x => x.GetCommand(y => y.Method2()).CanExecute(null))1050 ;1051 }1052 [CLSCompliant(false)]1053 public class POCOCommandsViewModel {1054 public virtual string Property1 { get; set; }1055 protected int _ShowCommand;1056 public int ShowCallCount;1057 public void Show() {1058 ShowCallCount++;1059 }1060 public int ShowAsyncCallCount;1061 public Task ShowAsync() {1062 return Task.Factory.StartNew(() =>1063 ShowAsyncCallCount++...

Full Screen

Full Screen

TestClasses.cs

Source:TestClasses.cs Github

copy

Full Screen

...17internal class Outer18{19 public void Method0() { }20 public void Method1(int i) { }21 public void Method2(List<string> ls) { }22 public void Method3(string p, int l) { }23 internal class Inner24 {25 public void Method0() { }26 public void Method1(int i) { }27 public void Method2<U>(int i) { }28 public void Method3<U, T>(int i) { }29 }30}31internal class OuterPrime : Outer { }32internal class Outer<T>33{34 public void Method0() { }35 public void Method1(T t) { }36 public void Method2<U>(U[] u) { }37 public void Method3<U>(T t, U u) { }38 internal class Inner<V>39 {40 public void Method0() { }41 public void Method1(T t) { }42 public void Method2(V v) { }43 public void Method3<U>(T t, U u, V v) { }44 public void Method4<U, X>(X x, U u) { }45 public void Method5<U, X>(List<X> x, U u) { }46 internal class MoreInner<I>47 {48 public void Method0<U>(T t, V v, I i, U u) { }49 }50 }51}52internal class OuterPrime<Z> : Outer<Z> { }53internal class OuterPrime<Y, Z> : Outer<Z> { }54internal class OuterString : Outer<string> { }55internal interface IImplementation56{57 void ImplMethod0();58 void ImplMethod1(int i);59}60internal class Impl : IImplementation61{62 void IImplementation.ImplMethod0() { }63 void IImplementation.ImplMethod1(int i) { }64}65internal interface IImplementation<T>66{67 void ImplMethod0();68 void ImplMethod1(T t);69 void ImplMethod2<U>(T t, U u, string s);70}71internal class Impl<T> : IImplementation<T>72{73 void IImplementation<T>.ImplMethod0() { }74 void IImplementation<T>.ImplMethod1(T t) { }75 void IImplementation<T>.ImplMethod2<U>(T t, U u, string s) { }76}77internal class Overloads78{79 public void Overload0() { }80 public void Overload0(int i) { }81 public void Overload0(int i, Overloads c) { }82 public unsafe void Overload0(int* p) { }83 public void Overload0(dynamic d) { }84 public void Overload0<U>(U u) { }85 public void Overload0<U>() { }86 public void Overload0<U, T>() { }87 public void Overload0<U>(U[] u) { }88 public void Overload0<U>(U[][] u) { }89 public void Overload0<U>(U[,] u) { }...

Full Screen

Full Screen

Program.cs

Source:Program.cs Github

copy

Full Screen

...35 // ManagedNameHelper.GetManagedName(baseMethod0, out var managedType, out var managedMethod, out var hierarchies);36 // var methodBase = ManagedNameHelper.GetMethod(derivedClass.Assembly, managedType, managedMethod);37 //}38 {39 var method = typeof(TestClasses.IImplementation<string>).GetMethods(PrivateBindingFlags).SingleOrDefault(i => i.Name == "ImplMethod2")!;40 method = method.MakeGenericMethod(typeof(int));41 ManagedNameHelper.GetManagedName(method, out var managedType, out var managedMethod, out var hierarchies);42 var methodBase = ManagedNameHelper.GetMethod(derivedClass.Assembly, managedType, managedMethod);43 }44 }45}...

Full Screen

Full Screen

Method2

Using AI Code Generation

copy

Full Screen

1TestClasses.BaseClass.Method2();2TestClasses.BaseClass.Method2();3TestClasses.BaseClass.Method2();4TestClasses.BaseClass.Method2();5TestClasses.BaseClass.Method2();6TestClasses.BaseClass.Method2();7TestClasses.BaseClass.Method2();8TestClasses.BaseClass.Method2();9TestClasses.BaseClass.Method2();10TestClasses.BaseClass.Method2();11TestClasses.BaseClass.Method2();12TestClasses.BaseClass.Method2();13TestClasses.BaseClass.Method2();14TestClasses.BaseClass.Method2();15TestClasses.BaseClass.Method2();16TestClasses.BaseClass.Method2();17TestClasses.BaseClass.Method2();18TestClasses.BaseClass.Method2();

Full Screen

Full Screen

Method2

Using AI Code Generation

copy

Full Screen

1using TestClasses;2BaseClass bc = new BaseClass();3bc.Method2();4BaseClass bc = new BaseClass();5bc.Method2();6BaseClass bc = new BaseClass();7bc.Method2();8BaseClass bc = new BaseClass();9bc.Method2();10BaseClass bc = new BaseClass();11bc.Method2();12BaseClass bc = new BaseClass();13bc.Method2();14BaseClass bc = new BaseClass();15bc.Method2();16BaseClass bc = new BaseClass();17bc.Method2();18BaseClass bc = new BaseClass();19bc.Method2();20BaseClass bc = new BaseClass();21bc.Method2();22BaseClass bc = new BaseClass();23bc.Method2();24BaseClass bc = new BaseClass();25bc.Method2();26BaseClass bc = new BaseClass();27bc.Method2();28BaseClass bc = new BaseClass();29bc.Method2();30BaseClass bc = new BaseClass();31bc.Method2();

Full Screen

Full Screen

Method2

Using AI Code Generation

copy

Full Screen

1using TestClasses;2{3 static void Main(string[] args)4 {5 BaseClass baseClass = new BaseClass();6 baseClass.Method2();7 }8}9Error 1 The type or namespace name 'TestClasses' could not be found (are you missing a using directive or an assembly reference?)10using TestClasses;11{12 static void Main(string[] args)13 {14 BaseClass baseClass = new BaseClass();15 baseClass.Method2();16 }17}18using TestClasses;19{20 {21 public void Method1()22 {23 }24 public void Method2()25 {26 }27 }28}

Full Screen

Full Screen

Method2

Using AI Code Generation

copy

Full Screen

1TestClasses.BaseClass.Method2();2TestClasses.BaseClass.Method1();3TestClasses.BaseClass.Method1();4TestClasses.BaseClass.Method2();5TestClasses.BaseClass.Method1();6TestClasses.BaseClass.Method1();7TestClasses.BaseClass.Method2();8TestClasses.BaseClass.Method1();9TestClasses.BaseClass.Method2();10TestClasses.BaseClass.Method1();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Vstest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in BaseClass

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful