Best Vstest code snippet using TestClasses.BaseClass.Method1
ViewModelSourceTests.cs
Source:ViewModelSourceTests.cs
...423 }, x => Assert.AreEqual("Command not found: NoAttributeCommand.", x.Message));424 }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;...
ViewModelSourceTestsOLD.cs
Source:ViewModelSourceTestsOLD.cs
...378 }, x => Assert.AreEqual("Command not found: NoAttributeCommand.", x.Message));379 }380 public class DuplicateNamesViewModel {381 [Command(Name = "MyCommand")]382 public void Method1() { }383 [Command(Name = "MyCommand")]384 public void Method2() { }385 }386 [Test]387 public void CommandAttribute_DuplicateNamesTest() {388 AssertHelper.AssertThrows<ViewModelSourceException>(() => {389 ViewModelSource.Create<DuplicateNamesViewModel>();390 }, x => Assert.AreEqual("Member with the same command name already exists: MyCommand.", x.Message));391 }392 public class NotPublicMethodViewModel {393 [Command]394 void NotPublicMethod() { }395 }396 [Test]397 public void CommandAttribute_NotPublicMethodTest() {398 AssertHelper.AssertThrows<ViewModelSourceException>(() => {399 ViewModelSource.Create<NotPublicMethodViewModel>();400 }, x => Assert.AreEqual("Method should be public: NotPublicMethod.", x.Message));401 }402 public class TooMuchArgumentsMethodViewModel {403 [Command]404 public void TooMuchArgumentsMethod(int a, int b) { }405 }406 [Test]407 public void CommandAttribute_TooMuchArgumentsMethodTest() {408 AssertHelper.AssertThrows<ViewModelSourceException>(() => {409 ViewModelSource.Create<TooMuchArgumentsMethodViewModel>();410 }, x => Assert.AreEqual("Method cannot have more than one parameter: TooMuchArgumentsMethod.", x.Message));411 }412 public class OutParameterMethodViewModel {413 [Command]414 public void OutParameterMethod(out int a) { a = 0; }415 }416 [Test]417 public void CommandAttribute_OutParameterMethodTest() {418 AssertHelper.AssertThrows<ViewModelSourceException>(() => {419 ViewModelSource.Create<OutParameterMethodViewModel>();420 }, x => Assert.AreEqual("Method cannot have out or reference parameter: OutParameterMethod.", x.Message));421 }422 public class RefParameterMethodViewModel {423 [Command]424 public void RefParameterMethod(ref int a) { a = 0; }425 }426 [Test]427 public void CommandAttribute_RefParameterMethodTest() {428 AssertHelper.AssertThrows<ViewModelSourceException>(() => {429 ViewModelSource.Create<RefParameterMethodViewModel>();430 }, x => Assert.AreEqual("Method cannot have out or reference parameter: RefParameterMethod.", x.Message));431 }432 public class CanExecuteParameterCountMismatchViewModel {433 [Command]434 public void Method() { }435 public bool CanMethod(int a) { return true; }436 }437 [Test]438 public void CommandAttribute_CanExecuteParameterCountMismatchTest() {439 AssertHelper.AssertThrows<ViewModelSourceException>(() => {440 ViewModelSource.Create<CanExecuteParameterCountMismatchViewModel>();441 }, x => Assert.AreEqual("Can execute method has incorrect parameters: CanMethod.", x.Message));442 }443 public class CanExecuteParametersMismatchViewModel {444 [Command]445 public void Method(long a) { }446 public bool CanMethod(int a) { return true; }447 }448 [Test]449 public void CommandAttribute_CanExecuteParametersMismatchTest() {450 AssertHelper.AssertThrows<ViewModelSourceException>(() => {451 ViewModelSource.Create<CanExecuteParametersMismatchViewModel>();452 }, x => Assert.AreEqual("Can execute method has incorrect parameters: CanMethod.", x.Message));453 }454 public class CanExecuteParametersMismatchViewModel2 {455 [Command]456 public void Method(int a) { }457 public bool CanMethod(out int a) { a = 0; return true; }458 }459 [Test]460 public void CommandAttribute_CanExecuteParametersMismatchTest2() {461 AssertHelper.AssertThrows<ViewModelSourceException>(() => {462 ViewModelSource.Create<CanExecuteParametersMismatchViewModel2>();463 }, x => Assert.AreEqual("Can execute method has incorrect parameters: CanMethod.", x.Message));464 }465 public class NotPublicCanExecuteViewModel {466 [Command]467 public void Method() { }468 bool CanMethod() { return true; }469 }470 [Test]471 public void CommandAttribute_NotPublicCanExecuteTest() {472 AssertHelper.AssertThrows<ViewModelSourceException>(() => {473 ViewModelSource.Create<NotPublicCanExecuteViewModel>();474 }, x => Assert.AreEqual("Method should be public: CanMethod.", x.Message));475 }476 public class InvalidCanExecuteMethodNameViewModel {477 [Command(CanExecuteMethodName = "CanMethod_")]478 public void Method() { }479 }480 [Test]481 public void CommandAttribute_InvalidCanExecuteMethodNameTest() {482 AssertHelper.AssertThrows<ViewModelSourceException>(() => {483 ViewModelSource.Create<InvalidCanExecuteMethodNameViewModel>();484 }, x => Assert.AreEqual("Method not found: CanMethod_.", x.Message));485 }486 #endregion487 #region ctors488 public class InternalCtor {489 public InternalCtor() { }490 internal InternalCtor(int x) { }491 }492 [Test]493 public void InternalCtorTest() {494 AssertHelper.AssertThrows<ViewModelSourceException>(() => {495 ViewModelSource.Create(() => new InternalCtor(0));496 }, x => Assert.AreEqual("Constructor not found.", x.Message));497 }498 public class OnlyInternalCtor {499 internal OnlyInternalCtor(int x) { }500 }501 [Test]502 public void OnlyInternalCtorTest() {503 AssertHelper.AssertThrows<ViewModelSourceException>(() => {504 ViewModelSource.Create(() => new OnlyInternalCtor(0));505 }, x => Assert.AreEqual("Type has no accessible constructors: OnlyInternalCtor.", x.Message));506 }507 [Test]508 public void CreateViaGenericParameters_InvalidParaneterTypes() {509 AssertHelper.AssertThrows<ViewModelSourceException>(() => {510 var viewModel = ViewModelSource<POCOViewModel_CreateViaGenericParameters>.Create(1);511 }, x => Assert.AreEqual("Constructor not found.", x.Message));512 }513 [Test]514 public void GetFactory_MemberInitializers() {515 AssertHelper.AssertThrows<ViewModelSourceException>(() => {516 ViewModelSource.Factory((string p1) => new POCOViewModel_CreateViaGenericParameters(p1));517 ViewModelSource.Factory((string p1) => new POCOViewModel_CreateViaGenericParameters(p1) { ConstructorInfo = "" });518 }, x => Assert.AreEqual("Constructor expression can only be of NewExpression type.", x.Message));519 }520 [Test]521 public void GetFactory_InvalidCtorParameters() {522 AssertHelper.AssertThrows<ViewModelSourceException>(() => {523 ViewModelSource.Factory((string p1) => new POCOViewModel_CreateViaGenericParameters(p1));524 ViewModelSource.Factory((string p1) => new POCOViewModel_CreateViaGenericParameters("x"));525 }, x => Assert.AreEqual("Constructor expression can refer only to its arguments.", x.Message));526 }527 #endregion528 #region services529 public class Services_NotServiceType {530 [ServiceProperty]531 public virtual SomeService Property { get { return null; } }532 }533 [Test]534 public void Services_NotServiceTypeTest() {535 AssertHelper.AssertThrows<ViewModelSourceException>(() => {536 ViewModelSource.Create(() => new Services_NotServiceType());537 }, x => Assert.AreEqual("Service properties should have an interface type: Property.", x.Message));538 }539 public class Services_PropertyIsNotVirtual {540 [ServiceProperty]541 public IMessageBoxService Property { get { return null; } }542 }543 [Test]544 public void Services_PropertyIsNotVirtualTest() {545 AssertHelper.AssertThrows<ViewModelSourceException>(() => {546 ViewModelSource.Create(() => new Services_PropertyIsNotVirtual());547 }, x => Assert.AreEqual("Property is not virtual: Property.", x.Message));548 }549 public class Services_PropertyIsSealedBase {550 public virtual IMessageBoxService Property { get { return null; } }551 }552 public class Services_PropertyIsSealed : Services_PropertyIsSealedBase {553 [ServiceProperty]554 public override sealed IMessageBoxService Property { get { return null; } }555 }556 [Test]557 public void Services_PropertyIsSealedTest() {558 AssertHelper.AssertThrows<ViewModelSourceException>(() => {559 ViewModelSource.Create(() => new Services_PropertyIsSealed());560 }, x => Assert.AreEqual("Cannot override final property: Property.", x.Message));561 }562 public class Services_PropertyHasSetter {563 [ServiceProperty]564 public virtual IMessageBoxService Property { get; set; }565 }566 [Test]567 public void Services_PropertyHasSetterTest() {568 AssertHelper.AssertThrows<ViewModelSourceException>(() => {569 ViewModelSource.Create(() => new Services_PropertyHasSetter());570 }, x => Assert.AreEqual("Property with setter cannot be Service Property: Property.", x.Message));571 }572 #endregion573 public class T370425VM { }574 [Test]575 public void T370425() {576 var vm = ViewModelSource.Create<T370425VM>();577 AssertHelper.AssertThrows<InvalidOperationException>(() => ((ISupportParentViewModel)vm).ParentViewModel = vm,578 e => Assert.AreEqual("ViewModel cannot be parent of itself.", e.Message));579 }580#pragma warning restore 0618581 #endregion582 public class DesignTimeViewModel {583 public virtual string Property { get; set; }584 }585 [Test]586 public void DesignTimeGeneration() {587 ViewModelDesignHelper.IsInDesignModeOverride = true;588 try {589 DesignTimeViewModel viewModel1 = ViewModelSource.Create<DesignTimeViewModel>();590 Assert.AreNotEqual(typeof(DesignTimeViewModel), viewModel1.GetType());591 } finally {592 ViewModelDesignHelper.IsInDesignModeOverride = null;593 }594 }595 [Test]596 public void IsInDesignMode_NotPOCOViewModelTest() {597 POCOViewModel_PropertyChanged viewModel = new POCOViewModel_PropertyChanged();598 Assert.IsFalse(viewModel.IsInDesignMode());599 }600 [Test]601 public void OverridingPropertyTest() {602 POCOViewModel viewModel = ViewModelSource.Create<POCOViewModel>();603 Assert.AreEqual(viewModel.GetType(), viewModel.GetType().GetProperty("Property1").DeclaringType);604 CheckBindableProperty(viewModel, x => x.Property1, (vm, x) => vm.Property1 = x, "x", "y");605 CheckBindableProperty(viewModel, x => x.Property2, (vm, x) => vm.Property2 = x, "m", "n");606 CheckBindableProperty(viewModel, x => x.Property3, (vm, x) => vm.Property3 = x, "a", "b");607 CheckBindableProperty(viewModel, x => x.Property4, (vm, x) => vm.Property4 = x, 1, 2);608 CheckBindableProperty(viewModel, x => x.Property5, (vm, x) => vm.Property5 = x, new Point(1, 1), new Point(2, 2));609 CheckBindableProperty(viewModel, x => x.Property6, (vm, x) => vm.Property6 = x, 5, null);610 CheckBindableProperty(viewModel, x => x.ProtectedSetterProperty, (vm, x) => vm.ProtectedSetterProperty = x, "x", "y");611 Assert.IsNull(viewModel.GetType().GetProperty("ProtectedSetterProperty").GetSetMethod());612 CheckNotBindableProperty(viewModel, x => x.NotVirtualProperty, (vm, x) => vm.NotVirtualProperty = x, "x", "y");613 CheckNotBindableProperty(viewModel, x => x.NotPublicProperty, (vm, x) => vm.NotPublicProperty = x, "x", "y");614 CheckNotBindableProperty(viewModel, x => x.ProtectedGetterProperty, (vm, x) => vm.ProtectedGetterProperty = x, "x", "y");615 CheckNotBindableProperty(viewModel, x => x.InternalSetterProperty, (vm, x) => vm.InternalSetterProperty = x, "x", "y");616 CheckNotBindableProperty(viewModel, x => x.NotAutoImplementedProperty, (vm, x) => vm.NotAutoImplementedProperty = x, "x", "y");617 }618 #region INPChanging619 public class POCOWithoutINPChanging {620 public virtual int Property { get; set; }621 }622 public class POCOImplementingINPChanging1 : INotifyPropertyChanging {623 public event PropertyChangingEventHandler PropertyChanging;624 public void Raise() {625 PropertyChanging.Do(x => x(null, null));626 }627 }628 [POCOViewModel(ImplementINotifyPropertyChanging = true)]629 public class POCOImplementingINPChanging2 : INotifyPropertyChanging {630 public event PropertyChangingEventHandler PropertyChanging;631 public void Raise() {632 PropertyChanging.Do(x => x(null, null));633 }634 }635 [POCOViewModel(ImplementINotifyPropertyChanging = true)]636 public class POCOImplementingINPChanging3 : INotifyPropertyChanging {637 public event PropertyChangingEventHandler PropertyChanging;638 public void RaisePropertyChanging(string propertyName) {639 PropertyChanging.Do(x => x(null, null));640 }641 }642 [Test]643 public void NPChangingExceptions() {644 AssertHelper.AssertThrows<ViewModelSourceException>(() => {645 IPOCOViewModel iPOCOViewModel = (IPOCOViewModel)ViewModelSource.Create<POCOWithoutINPChanging>();646 iPOCOViewModel.RaisePropertyChanging(null);647 }, x => x.Message.AreEqual(string.Format(648 ViewModelSourceException.Error_INotifyPropertyChangingIsNotImplemented,649 typeof(POCOWithoutINPChanging).Name)));650 AssertHelper.AssertThrows<ViewModelSourceException>(() => {651 IPOCOViewModel iPOCOViewModel = (IPOCOViewModel)ViewModelSource.Create<POCOImplementingINPChanging1>();652 iPOCOViewModel.RaisePropertyChanging(null);653 }, x => x.Message.AreEqual(string.Format(654 ViewModelSourceException.Error_INotifyPropertyChangingIsNotImplemented,655 typeof(POCOImplementingINPChanging1).Name)));656 AssertHelper.AssertThrows<ViewModelSourceException>(() => {657 ViewModelSource.Create<POCOImplementingINPChanging2>();658 }, x => x.Message.AreEqual(string.Format(659 ViewModelSourceException.Error_RaisePropertyChangingMethodNotFound,660 typeof(POCOImplementingINPChanging2).Name)));661 AssertHelper.AssertDoesNotThrow(() => {662 ViewModelSource.Create<POCOImplementingINPChanging3>();663 });664 }665 [POCOViewModel(ImplementINotifyPropertyChanging = true)]666 public class POCOWithINPChanging1 {667 public virtual int Property { get; set; }668 }669 public class POCOWithINPChanging2 : INotifyPropertyChanging {670 public virtual int Property { get; set; }671 public event PropertyChangingEventHandler PropertyChanging;672 protected void RaisePropertyChanging(string propName) {673 PropertyChanging.Do(x => x(this, new PropertyChangingEventArgs(propName)));674 }675 }676 [POCOViewModel(ImplementINotifyPropertyChanging = true)]677 public class POCOWithINPChanging3 : POCOWithINPChanging2 { }678 [Test]679 public void NPChangingTest1() {680 NPChangingTestCore(typeof(POCOWithINPChanging1), x => ((POCOWithINPChanging1)x).Property, (x, v) => ((POCOWithINPChanging1)x).Property = v);681 }682 [Test]683 public void NPChangingTest3() {684 NPChangingTestCore(typeof(POCOWithINPChanging3), x => ((POCOWithINPChanging3)x).Property, (x, v) => ((POCOWithINPChanging3)x).Property = v);685 }686 void NPChangingTestCore(Type type, Func<object, int> getProperty, Action<object, int> setProperty) {687 var vm = ViewModelSource.Create(type);688 INotifyPropertyChanging inpc = (INotifyPropertyChanging)vm;689 int propertyChangingCounter = 0;690 int oldValue = 0;691 inpc.PropertyChanging += (d, e) => {692 Assert.AreSame(vm, d);693 e.PropertyName.AreEqual("Property");694 propertyChangingCounter++;695 oldValue = getProperty(vm);696 };697 setProperty(vm, 1);698 oldValue.AreEqual(0);699 propertyChangingCounter.AreEqual(1);700 setProperty(vm, 2);701 oldValue.AreEqual(1);702 propertyChangingCounter.AreEqual(2);703 }704 [Test]705 public void NPChangingTest2() {706 var vm = ViewModelSource.Create<POCOWithINPChanging2>();707 INotifyPropertyChanging inpc = (INotifyPropertyChanging)vm;708 int propertyChangingCounter = 0;709 inpc.PropertyChanging += (d, e) => {710 propertyChangingCounter++;711 };712 vm.Property = 1;713 vm.Property = 2;714 propertyChangingCounter.AreEqual(0);715 }716 #endregion717 #region property changed718 public class POCOViewModel_PropertyChangedBase {719 protected virtual void OnProtectedChangedMethodWithParamChanged(string oldValue) { }720 public virtual bool SealedProperty { get; set; }721 }722 public class POCOViewModel_PropertyChanged : POCOViewModel_PropertyChangedBase {723 public string ProtectedChangedMethodWithParamOldValue;724 public bool OnProtectedChangedMethodWithParamChangedCalled;725 public virtual string ProtectedChangedMethodWithParam { get; set; }726 protected override void OnProtectedChangedMethodWithParamChanged(string oldValue) {727 Assert.AreNotEqual(ProtectedChangedMethodWithParam, ProtectedChangedMethodWithParamOldValue);728 OnProtectedChangedMethodWithParamChangedCalled = true;729 ProtectedChangedMethodWithParamOldValue = oldValue;730 }731 public sealed override bool SealedProperty { get; set; }732 public int PublicChangedMethodWithoutParamOldValue;733 public virtual int PublicChangedMethodWithoutParam { get; set; }734 public void OnPublicChangedMethodWithoutParamChanged() {735 PublicChangedMethodWithoutParamOldValue++;736 }737 public int ProtectedInternalChangedMethodWithoutParamOldValue;738 public virtual int ProtectedInternalChangedMethodWithoutParam { get; set; }739 protected internal void OnProtectedInternalChangedMethodWithoutParamChanged() {740 ProtectedInternalChangedMethodWithoutParamOldValue++;741 }742 }743 [Test]744 public void PropertyChangedTest() {745 POCOViewModel_PropertyChanged viewModel = ViewModelSource.Create<POCOViewModel_PropertyChanged>();746 ((INotifyPropertyChanged)viewModel).PropertyChanged += (o, e) => Assert.IsFalse(viewModel.OnProtectedChangedMethodWithParamChangedCalled);747 CheckBindableProperty(viewModel, x => x.ProtectedChangedMethodWithParam, (vm, x) => vm.ProtectedChangedMethodWithParam = x, "x", "y", (x, val) => {748 Assert.IsTrue(x.OnProtectedChangedMethodWithParamChangedCalled);749 x.OnProtectedChangedMethodWithParamChangedCalled = false;750 Assert.AreEqual(val, x.ProtectedChangedMethodWithParamOldValue);751 });752 CheckBindableProperty(viewModel, x => x.PublicChangedMethodWithoutParam, (vm, x) => vm.PublicChangedMethodWithoutParam = x, 1, 2, (x, val) => Assert.AreEqual(val + 1, x.PublicChangedMethodWithoutParamOldValue));753 CheckBindableProperty(viewModel, x => x.ProtectedInternalChangedMethodWithoutParam, (vm, x) => vm.ProtectedInternalChangedMethodWithoutParam = x, 1, 2, (x, val) => Assert.AreEqual(val + 1, x.ProtectedInternalChangedMethodWithoutParamOldValue));754 }755 public class ViewModelWithFunctionCommandMethod {756 [Command]757 public bool Save() {758 return true;759 }760 }761 [Test]762 public void GetCommandFromFunction_VB() {763 ViewModelWithFunctionCommandMethod viewModel = ViewModelSource.Create<ViewModelWithFunctionCommandMethod>();764 ParameterExpression parameter1 = Expression.Parameter(typeof(ViewModelWithFunctionCommandMethod), "x");765 MethodCallExpression methodCallExpression = Expression.Call((Expression)parameter1, typeof(ViewModelWithFunctionCommandMethod).GetMethod("Save", BindingFlags.Public | BindingFlags.Instance), new Expression[0]);766 var expression = Expression.Lambda<Func<ViewModelWithFunctionCommandMethod, bool>>(methodCallExpression, parameter1);767 ParameterExpression parameter2 = Expression.Parameter(typeof(ViewModelWithFunctionCommandMethod), "a0");768 var methodExpression = Expression.Lambda<Action<ViewModelWithFunctionCommandMethod>>(Expression.Invoke(expression, parameter2), parameter2);769 Assert.IsNotNull(POCOViewModelExtensions.GetCommand(viewModel, methodExpression));770 }771 [Test]772 public void PropertyChangedTest_VB() {773 VbPOCOViewModel viewModel = ViewModelSource.Create<VbPOCOViewModel>();774 CheckBindableProperty(viewModel, x => x.AutoImlementedProperty, (vm, x) => vm.AutoImlementedProperty = x, 1, 2, (x, val) => Assert.AreEqual(val, x.AutoImlementedPropertyOldValue));775 CheckNotBindableProperty(viewModel, x => x.AutoImlementedNonVirtualProperty, (vm, x) => vm.AutoImlementedNonVirtualProperty = x, 1, 2);776 CheckBindableProperty(viewModel, x => x.AutoImlementedEntityProperty, (vm, x) => vm.AutoImlementedEntityProperty = x, new TestEntity(), new TestEntity());777 CheckNotBindableProperty(viewModel, x => x.PseudoAutoImplementedProperty_WrongFieldName, (vm, x) => vm.PseudoAutoImplementedProperty_WrongFieldName = x, 1, 2);778 CheckNotBindableProperty(viewModel, x => x.PseudoAutoImplementedProperty_NoAttributeOnField, (vm, x) => vm.PseudoAutoImplementedProperty_NoAttributeOnField = x, 1, 2);779 CheckNotBindableProperty(viewModel, x => x.PseudoAutoImplementedProperty_WrongParameterName, (vm, x) => vm.PseudoAutoImplementedProperty_WrongParameterName = x, 1, 2);780 CheckNotBindableProperty(viewModel, x => x.PseudoAutoImplementedProperty_WrongFieldType, (vm, x) => vm.PseudoAutoImplementedProperty_WrongFieldType = x, 1, 2);781 CheckBindableProperty(viewModel, x => x.PseudoAutoImplementedProperty, (vm, x) => vm.PseudoAutoImplementedProperty = x, 1, 2);782 }783 [Test]784 public void PropertyNameInSetterAndGetterShouldMatchTest_VB() {785 var obj = new PropertyNameInSetterAndGetterShouldMatch();786 obj.Test(BindableBase.GetPropertyName);787 Assert.IsNotNull(obj.nameInGetter);788 Assert.AreEqual(obj.nameInGetter, obj.nameInSetter);789 }790 #endregion791 #region property changing792 public class POCOViewModel_PropertyChanging {793 public virtual string Property1 { get; set; }794 public string Property1NewValue;795 protected void OnProperty1Changing(string newValue) {796 Assert.AreNotEqual(newValue, Property1);797 Property1NewValue = newValue;798 }799 public virtual string Property2 { get; set; }800 public int Property2ChangingCallCount;801 protected void OnProperty2Changing() {802 Assert.AreEqual(null, Property2);803 Property2ChangingCallCount++;804 }805 string property3;806 [BindableProperty]807 public virtual string Property3 { get { return property3; } set { property3 = value; } }808 protected void OnProperty3Changing() {809 throw new NotImplementedException();810 }811 }812 [Test]813 public void PropertyChangingTest() {814 POCOViewModel_PropertyChanging viewModel = ViewModelSource.Create<POCOViewModel_PropertyChanging>();815 viewModel.Property1 = null;816 viewModel.Property1 = "x";817 Assert.AreEqual("x", viewModel.Property1NewValue);818 viewModel.Property2 = null;819 viewModel.Property2 = "x";820 Assert.AreEqual(1, viewModel.Property2ChangingCallCount);821 viewModel.Property3 = "x";822 }823 #endregion824 #region subscribe in constructor825 public class POCOViewModel_SubscribeInCtor {826 public POCOViewModel_SubscribeInCtor() {827 ((INotifyPropertyChanged)this).PropertyChanged += POCOViewModel_SubscribeInCtor_PropertyChanged;828 Property = "x";829 }830 public int propertyChangedCallCount;831 void POCOViewModel_SubscribeInCtor_PropertyChanged(object sender, PropertyChangedEventArgs e) {832 propertyChangedCallCount++;833 }834 public virtual string Property { get; set; }835 }836 [Test]837 public void POCOViewModel_SubscribeInCtorTest() {838 POCOViewModel_SubscribeInCtor viewModel = ViewModelSource.Create<POCOViewModel_SubscribeInCtor>();839 Assert.AreEqual(1, viewModel.propertyChangedCallCount);840 }841 #endregion842 #region metadata843 public class POCOViewModel_WithMetadata {844 [BindableProperty(false)]845 public virtual string NotBindableProperty { get; set; }846 string notAutoImplementedProperty;847 [BindableProperty]848 public virtual string NotAutoImplementedProperty { get { return notAutoImplementedProperty; } set { notAutoImplementedProperty = value; } }849 public string CustomProperytChangedOldValue;850 string customProperytChanged;851 [BindableProperty(OnPropertyChangedMethodName = "OnCustomProperytChanged")]852 public virtual string CustomProperytChanged { get { return customProperytChanged; } set { customProperytChanged = value; } }853 protected void OnCustomProperytChanged(string oldValue) {854 CustomProperytChangedOldValue = oldValue;855 }856 [BindableProperty(OnPropertyChangingMethodName = "MyPropertyChanging")]857 public virtual string PropertyChanging { get; set; }858 public string PropertyChangingNewValue;859 protected void MyPropertyChanging(string newValue) {860 Assert.AreNotEqual(newValue, PropertyChanging);861 PropertyChangingNewValue = newValue;862 }863 }864 [MetadataType(typeof(POCOViewModel_WithMetadata_FluentAPIMetadata))]865 public class POCOViewModel_WithMetadata_FluentAPI {866 public class POCOViewModel_WithMetadata_FluentAPIMetadata : IMetadataProvider<POCOViewModel_WithMetadata_FluentAPI> {867 void IMetadataProvider<POCOViewModel_WithMetadata_FluentAPI>.BuildMetadata(MetadataBuilder<POCOViewModel_WithMetadata_FluentAPI> builder) {868 builder.Property(x => x.NotBindableProperty).DoNotMakeBindable();869 builder.Property(x => x.NotAutoImplementedProperty).MakeBindable();870 builder.Property(x => x.CustomProperytChanged).OnPropertyChangedCall(x => x.OnCustomProperytChanged(null));871 builder.Property(x => x.PropertyChanging).OnPropertyChangingCall(x => x.MyPropertyChanging(null));872 }873 }874 public virtual string NotBindableProperty { get; set; }875 string notAutoImplementedProperty;876 public virtual string NotAutoImplementedProperty { get { return notAutoImplementedProperty; } set { notAutoImplementedProperty = value; } }877 public string CustomProperytChangedOldValue;878 string customProperytChanged;879 public virtual string CustomProperytChanged { get { return customProperytChanged; } set { customProperytChanged = value; } }880 protected void OnCustomProperytChanged() {881 }882 protected void OnCustomProperytChanged(string oldValue) {883 CustomProperytChangedOldValue = oldValue;884 }885 public virtual string PropertyChanging { get; set; }886 public string PropertyChangingNewValue;887 protected void MyPropertyChanging(string newValue) {888 Assert.AreNotEqual(newValue, PropertyChanging);889 PropertyChangingNewValue = newValue;890 }891 }892 [Test]893 public void OverridingPropertyTest_Metadata() {894 POCOViewModel_WithMetadata viewModel = ViewModelSource.Create<POCOViewModel_WithMetadata>();895 CheckNotBindableProperty(viewModel, x => x.NotBindableProperty, (vm, x) => vm.NotBindableProperty = x, "x", "y");896 CheckBindableProperty(viewModel, x => x.NotAutoImplementedProperty, (vm, x) => vm.NotAutoImplementedProperty = x, "x", "y");897 CheckBindableProperty(viewModel, x => x.CustomProperytChanged, (vm, x) => vm.CustomProperytChanged = x, "x", "y", (x, val) => Assert.AreEqual(val, x.CustomProperytChangedOldValue));898 viewModel.PropertyChanging = null;899 viewModel.PropertyChanging = "x";900 Assert.AreEqual("x", viewModel.PropertyChangingNewValue);901 }902 [Test]903 public void OverridingPropertyTest_Metadata_FluentAPI() {904 POCOViewModel_WithMetadata_FluentAPI viewModel = ViewModelSource.Create<POCOViewModel_WithMetadata_FluentAPI>();905 CheckNotBindableProperty(viewModel, x => x.NotBindableProperty, (vm, x) => vm.NotBindableProperty = x, "x", "y");906 CheckBindableProperty(viewModel, x => x.NotAutoImplementedProperty, (vm, x) => vm.NotAutoImplementedProperty = x, "x", "y");907 CheckBindableProperty(viewModel, x => x.CustomProperytChanged, (vm, x) => vm.CustomProperytChanged = x, "x", "y", (x, val) => Assert.AreEqual(val, x.CustomProperytChangedOldValue));908 viewModel.PropertyChanging = null;909 viewModel.PropertyChanging = "x";910 Assert.AreEqual("x", viewModel.PropertyChangingNewValue);911 }912 public class INPCDefaultPriorityViewModel {913 public int onChangedCalledCount = 0;914 public virtual string Property { get; set; }915 public void OnPropertyChanged() {916 onChangedCalledCount++;917 }918 }919 [POCOViewModel(InvokeOnPropertyChangedMethodBeforeRaisingINPC = true)]920 public class INPCOnChangedFirstPriorityViewModel : INPCDefaultPriorityViewModel { }921 [Test]922 public void INPCPriorityTest() {923 var vm = ViewModelSource.Create<INPCDefaultPriorityViewModel>();924 var inpc = (INotifyPropertyChanged)vm;925 inpc.PropertyChanged += (s, a) => {926 Assert.AreEqual("Property", a.PropertyName);927 Assert.AreEqual(vm.onChangedCalledCount, 0);928 };929 vm.Property = "value";930 Assert.AreEqual(vm.onChangedCalledCount, 1);931 vm = ViewModelSource.Create<INPCOnChangedFirstPriorityViewModel>();932 inpc = (INotifyPropertyChanged)vm;933 inpc.PropertyChanged += (s, a) => {934 Assert.AreEqual("Property", a.PropertyName);935 Assert.AreEqual(vm.onChangedCalledCount, 1);936 };937 vm.Property = "value";938 Assert.AreEqual(vm.onChangedCalledCount, 1);939 }940 #endregion941 #region IPOCOViewModelImplementation942 [Test]943 public void IPOCOViewModelImplementation() {944 var viewModel = ViewModelSource.Create<POCOViewModel>();945 string propertyName = null;946 ((INotifyPropertyChanged)viewModel).PropertyChanged += (o, e) => propertyName = e.PropertyName;947 ((IPOCOViewModel)viewModel).RaisePropertyChanged("Property1");948 Assert.AreEqual("Property1", propertyName);949 viewModel.RaisePropertyChanged(x => x.Property5);950 Assert.AreEqual("Property5", propertyName);951 viewModel.RaisePropertiesChanged();952 Assert.AreEqual(string.Empty, propertyName);953 }954 [Test]955 public void GetSetParentViewModel() {956 var viewModel = ViewModelSource.Create<POCOViewModel>();957 Assert.IsNull(viewModel.GetParentViewModel<Button>());958 var b = new Button();959 Assert.AreSame(viewModel, viewModel.SetParentViewModel(b));960 Assert.AreEqual(b, viewModel.GetParentViewModel<Button>());961 }962 #endregion963 #region commands964 public class NotBrowsableCommand {965 [Browsable(false)]966 public void Method1() { }967 [Browsable(true)]968 public void Method2() { }969 }970 [Test]971 public void NotBrowsableCommandTest() {972 TypeDescriptor.GetProperties(ViewModelSource.GetPOCOType(typeof(NotBrowsableCommand)))["Method1Command"]973 .Attributes.OfType<BrowsableAttribute>()974 .First().IsFalse(x => x.Browsable);975 TypeDescriptor.GetProperties(ViewModelSource.GetPOCOType(typeof(NotBrowsableCommand)))["Method2Command"]976 .Attributes.OfType<BrowsableAttribute>()977 .First().IsTrue(x => x.Browsable);978 }979 public class ProtecteCanExecuteMethod {980 public bool IsMethod1Enabled;981 public void Method1() {982 MessageBox.Show("Hello");983 }984 protected bool CanMethod1() {985 return IsMethod1Enabled;986 }987 public bool IsMethod2Enabled;988 public void Method2() {989 MessageBox.Show("Hello");990 }991 protected internal bool CanMethod2() {992 return IsMethod2Enabled;993 }994 }995 [Test]996 public void ProtectedCanExecuteMethod() {997 var viewModel = ViewModelSource.Create<ProtecteCanExecuteMethod>();998 viewModel999 .IsFalse(x => x.GetCommand(y => y.Method1()).CanExecute(null))1000 .Do(x => x.IsMethod1Enabled = true)1001 .IsTrue(x => x.GetCommand(y => y.Method1()).CanExecute(null))1002 .IsFalse(x => x.GetCommand(y => y.Method2()).CanExecute(null))1003 .Do(x => x.IsMethod2Enabled = true)1004 .IsTrue(x => x.GetCommand(y => y.Method2()).CanExecute(null))1005 ;1006 }1007 [CLSCompliant(false)]1008 public class POCOCommandsViewModel {1009 public virtual string Property1 { get; set; }1010 protected int _ShowCommand;1011 public int ShowCallCount;1012 public void Show() {1013 ShowCallCount++;1014 }1015 public int ShowAsyncCallCount;...
TestClasses.cs
Source:TestClasses.cs
...11}12internal class BaseClass13{14 public void Method0(int i) { }15 public void Method1(int i) { }16}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) { }...
Method1
Using AI Code Generation
1TestClasses.BaseClass.Method1();2TestClasses.BaseClass.Method1();3TestClasses.BaseClass.Method1();4TestClasses.BaseClass.Method1();5TestClasses.BaseClass.Method1();6TestClasses.BaseClass.Method1();7TestClasses.BaseClass.Method1();8TestClasses.BaseClass.Method1();9TestClasses.BaseClass.Method1();10TestClasses.BaseClass.Method1();11TestClasses.BaseClass.Method1();12TestClasses.BaseClass.Method1();13TestClasses.BaseClass.Method1();14TestClasses.BaseClass.Method1();15TestClasses.BaseClass.Method1();16TestClasses.BaseClass.Method1();17TestClasses.BaseClass.Method1();18TestClasses.BaseClass.Method1();
Method1
Using AI Code Generation
1var baseClass = new TestClasses.BaseClass();2baseClass.Method1();3var derivedClass = new TestClasses.DerivedClass();4derivedClass.Method1();5var derivedDerivedClass = new TestClasses.DerivedDerivedClass();6derivedDerivedClass.Method1();7var baseClass = new TestClasses.BaseClass();8baseClass.Method1();9var derivedClass = new TestClasses.DerivedClass();10derivedClass.Method1();11var derivedDerivedClass = new TestClasses.DerivedDerivedClass();12derivedDerivedClass.Method1();13var baseClass = new TestClasses.BaseClass();14baseClass.Method1();15var derivedClass = new TestClasses.DerivedClass();16derivedClass.Method1();17var derivedDerivedClass = new TestClasses.DerivedDerivedClass();18derivedDerivedClass.Method1();19var baseClass = new TestClasses.BaseClass();20baseClass.Method1();21var derivedClass = new TestClasses.DerivedClass();22derivedClass.Method1();23var derivedDerivedClass = new TestClasses.DerivedDerivedClass();24derivedDerivedClass.Method1();25var baseClass = new TestClasses.BaseClass();26baseClass.Method1();27var derivedClass = new TestClasses.DerivedClass();28derivedClass.Method1();
Method1
Using AI Code Generation
1TestClass.BaseClass.Method1();2TestClass.BaseClass.Method1();3TestClass.BaseClass.Method1();4TestClass.BaseClass.Method1();5TestClass.BaseClass.Method1();6TestClass.BaseClass.Method1();7TestClass.BaseClass.Method1();8TestClass.BaseClass.Method1();9TestClass.BaseClass.Method1();10TestClass.BaseClass.Method1();11TestClass.BaseClass.Method1();12TestClass.BaseClass.Method1();13TestClass.BaseClass.Method1();14TestClass.BaseClass.Method1();15TestClass.BaseClass.Method1();16TestClass.BaseClass.Method1();17TestClass.BaseClass.Method1();18TestClass.BaseClass.Method1();19TestClass.BaseClass.Method1();
Method1
Using AI Code Generation
1TestClass.BaseClass.Method1();2TestClass.BaseClass.Method2();3TestClass.BaseClass.Method3();4TestClass.BaseClass.Method1();5TestClass.BaseClass.Method2();6TestClass.BaseClass.Method3();7TestClass.BaseClass.Method1();8TestClass.BaseClass.Method2();9TestClass.BaseClass.Method3();10TestClass.BaseClass.Method1();11TestClass.BaseClass.Method2();12TestClass.BaseClass.Method3();13TestClass.BaseClass.Method1();14TestClass.BaseClass.Method2();15TestClass.BaseClass.Method3();16TestClass.BaseClass.Method1();17TestClass.BaseClass.Method2();18TestClass.BaseClass.Method3();19TestClass.BaseClass.Method1();20TestClass.BaseClass.Method2();21TestClass.BaseClass.Method3();22TestClass.BaseClass.Method1();23TestClass.BaseClass.Method2();
Method1
Using AI Code Generation
1using TestClasses;2{3 static void Main(string[] args)4 {5 BaseClass bc = new BaseClass();6 bc.Method1();7 }8}9using TestClasses;10{11 static void Main(string[] args)12 {13 BaseClass bc = new BaseClass();14 bc.Method2();15 }16}17{18 {19 static void Main(string[] args)20 {21 BaseClass bc = new BaseClass();22 bc.Method1();23 }24 }25}26{27 {28 static void Main(string[] args)29 {30 BaseClass bc = new BaseClass();31 bc.Method2();32 }33 }34}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!