Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INotifyPropertyChanged Tests #13

Open
Grauenwolf opened this issue Jun 2, 2021 · 0 comments
Open

INotifyPropertyChanged Tests #13

Grauenwolf opened this issue Jun 2, 2021 · 0 comments

Comments

@Grauenwolf
Copy link
Owner

    @{

        foreach (var property in Class.Properties.Where(p => !p.IsIndexer && p.CanRead && p.CanWrite && p.Type.HasCommonValues))
        { 

    
    <text>
    @Tag("INotifyPropertyChanged")
    @TestAttribute
    public void @(Test.ClassName + "_Property_" + property.Name + "_NotifyPropertyChanged_SelfAssign") ()
    {
        var objectUnderTest = CreateObject();
        var events = new List<PropertyChangedEventArgs>();
        ((INotifyPropertyChanged)objectUnderTest).PropertyChanged += (s, e) => events.Add(e);


		//Setting the value to the current value should always work and not raise any events
		var originalValue = [email protected];
		[email protected] = originalValue;
		@Assert.IsTrue("events.Count() == 0", "\"No change events should have been raised, the property's value didn't change.\"")
    }    
    </text>
        
        
    <text>
    @Tag("INotifyPropertyChanged")
    @TestAttribute
    public void @(Test.ClassName + "_Property_" + property.Name + "_NotifyPropertyChanged") ()
    {
        var objectUnderTest = CreateObject();
        var events = new List<PropertyChangedEventArgs>();
        ((INotifyPropertyChanged)objectUnderTest).PropertyChanged += (s, e) => events.Add(e);

        //perform a self-assignment to avoid duplicating the above test
		var originalValue = [email protected];
		[email protected] = originalValue;

    </text>



            foreach (var testValue in property.Type.CommonValues)
            { 
        <text>
        events.Clear();
        try
        {
            @property.Type.FullName expectedValue = @testValue;
            var valueChanged = !Object.Equals(expectedValue, [email protected]);
            [email protected] = expectedValue;
            
        	if (valueChanged)
				@Assert.IsTrue("events.Any(e => e.PropertyName == \"" + property.Name + "\")", "\"No property changed event was raised for \\\"" + property.Name + "\\\".\"")
			else
				@Assert.IsTrue("events.Count() == 0", "\"No change events should have been raised, the property's value didn't change.\"")

        }
        catch (ArgumentException)
        {
            //OK
            return;
        }
        </text>
            }

                       
    <text>
    }    
    </text>
        }

    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant