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

Property Assign Tests #14

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

Property Assign Tests #14

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.IsNullable || p.Type.HasCommonValues)))
        {
            if (property.IsNullable) 
            { 
                <text>
                @Tag("PropertyAssign")
                @TestAttribute
                public void @(Test.ClassName + "_Property_" + property.Name + "_PropertyNullAssigned") ()
                {
                    var objectUnderTest = CreateObject();
                    try
                    {
                        [email protected] = null;
                        @Assert.IsNull("objectUnderTest." + @property.Name);
                    }
                    catch (System.ArgumentNullException)
                    {
                        //OK
                        return;
                    }
                }    
                </text>
            }

            if (property.Type.HasCommonValues) 
            {
				var testCount = 1;


				foreach (var testValue in property.Type.CommonValues)
				{ 
					<text>
					@Tag("PropertyAssign")
					@TestAttribute
					public void @(Test.ClassName + "_Property_" + property.Name + "_PropertyAssigned_" + testCount) ()
					{
						var objectUnderTest = CreateObject();
						@property.Type.FullName expectedValue;
					</text>



						<text>
						try
						{
							expectedValue = @testValue;
							[email protected] = expectedValue;
							@Assert.AreEqual(@property.Type, "expectedValue", "objectUnderTest." + @property.Name);
						}
						catch (System.ArgumentException)
						{
							//OK
							return;
						}
						</text>

                       
					<text>
					}    
					</text>
		
					testCount++;
				}
            }
        }
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