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

IEditableObject Tests #7

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

IEditableObject Tests #7

Grauenwolf opened this issue Jun 2, 2021 · 0 comments

Comments

@Grauenwolf
Copy link
Owner

foreach (var constructor in Class.Constructors.Where(c => c.IsCreatable)) 
{ 
	<text>
	
        @Tag("IEditableObject")
	    @TestAttribute
        public void @(Test.ClassName + "_IEditableObject_" + constructor.SafeName + "_BeginCancel_Simple")()
	    {
            @Class.FullName objectUnderTest;

		    try
		    {
			    objectUnderTest = @constructor.GetConstructorCode();
		    }
		    catch (ArgumentException)
		    {
			    //OK
                return;
		    }

            ((IEditableObject)objectUnderTest).BeginEdit();
            ((IEditableObject)objectUnderTest).CancelEdit();
	    }

        @Tag("IEditableObject")
        @TestAttribute
        public void @(Test.ClassName + "_IEditableObject_" + constructor.SafeName + "_BeginEnd_Simple")()
	    {
            @Class.FullName objectUnderTest;

		    try
		    {
			    objectUnderTest = @constructor.GetConstructorCode();
		    }
		    catch (ArgumentException)
		    {
			    //OK
                return;
		    }

            ((IEditableObject)objectUnderTest).BeginEdit();
            ((IEditableObject)objectUnderTest).EndEdit();
	    }

					


        @Tag("IEditableObject")
	    @TestAttribute
        public void @(Test.ClassName + "_IEditableObject_" + constructor.SafeName + "_BeginCancel")()
	    {
            @Class.FullName objectUnderTest;

		    try
		    {
			    objectUnderTest = GetObject(1);
		    }
		    catch (ArgumentException)
		    {
			    //OK
                return;
		    }

		    var expected = GetValues(objectUnderTest); //CancelEdit should return us to these values

		    ((IEditableObject)objectUnderTest).BeginEdit();
		    SetValues(objectUnderTest, 2);
            ((IEditableObject)objectUnderTest).CancelEdit();

		    var diffs = GetDiffs(expected, objectUnderTest);
		    @Assert.AreEqual("0", "diffs.Count");

	    }

        @Tag("IEditableObject")
        @TestAttribute
        public void @(Test.ClassName + "_IEditableObject_" + constructor.SafeName + "_BeginEnd")()
	    {
            @Class.FullName objectUnderTest;

		    try
		    {
			    objectUnderTest = GetObject(1);
		    }
		    catch (ArgumentException)
		    {
			    //OK
                return;
		    }

       
		    ((IEditableObject)objectUnderTest).BeginEdit();
		    SetValues(objectUnderTest, 2);
		    var expected = GetValues(objectUnderTest); //EndEdit shouldn't change any values
            ((IEditableObject)objectUnderTest).EndEdit();

		    var diffs = GetDiffs(expected, objectUnderTest);
		    @Assert.AreEqual("0", "diffs.Count");
	    }



        @Tag("IEditableObject")
	    @TestAttribute
        public void @(Test.ClassName + "_IEditableObject_" + constructor.SafeName + "_BeginBeginCancelCancel")()
	    {
            @Class.FullName objectUnderTest;

		    try
		    {
			    objectUnderTest = GetObject(1);
		    }
		    catch (ArgumentException)
		    {
			    //OK
                return;
		    }

		    var expected = GetValues(objectUnderTest); //The second CancelEdit should return us to these values

		    ((IEditableObject)objectUnderTest).BeginEdit();
		    SetValues(objectUnderTest, 2);

		    ((IEditableObject)objectUnderTest).BeginEdit(); //This is a no-op
		    SetValues(objectUnderTest, 3);

		    ((IEditableObject)objectUnderTest).CancelEdit(); //and we are back to the original values

		    var diffs1 = GetDiffs(expected, objectUnderTest);
		    @Assert.AreEqual("0", "diffs1.Count");

		    ((IEditableObject)objectUnderTest).CancelEdit(); //this is a no-op

		    var diffs2 = GetDiffs(expected, objectUnderTest); 
		    @Assert.AreEqual("0", "diffs2.Count");


	    }

        @Tag("IEditableObject")
	    @TestAttribute
        public void @(Test.ClassName + "_IEditableObject_" + constructor.SafeName + "_BeginBeginCancelEnd")()
	    {

            @Class.FullName objectUnderTest;

		    try
		    {
			    objectUnderTest = GetObject(1);
		    }
		    catch (ArgumentException)
		    {
			    //OK
                return;
		    }

		    var expected = GetValues(objectUnderTest); //The first CancelEdit should return us to these values

		    ((IEditableObject)objectUnderTest).BeginEdit();
		    SetValues(objectUnderTest, 2);


		    ((IEditableObject)objectUnderTest).BeginEdit();
		    SetValues(objectUnderTest, 3);

		    ((IEditableObject)objectUnderTest).CancelEdit();

		    var diffs1 = GetDiffs(expected, objectUnderTest);
		    @Assert.AreEqual("0", "diffs1.Count");

		    ((IEditableObject)objectUnderTest).EndEdit(); //this is a no-op

		    var diffs2 = GetDiffs(expected, objectUnderTest); 
		    @Assert.AreEqual("0", "diffs2.Count");


	    }


        @Tag("IEditableObject")
	    @TestAttribute
        public void @(Test.ClassName + "_IEditableObject_" + constructor.SafeName + "_BeginBeginEndEnd")()
	    {

            @Class.FullName objectUnderTest;

		    try
		    {
			    objectUnderTest = GetObject(1);
		    }
		    catch (ArgumentException)
		    {
			    //OK
                return;
		    }


		    ((IEditableObject)objectUnderTest).BeginEdit();
		    SetValues(objectUnderTest, 2);

		    ((IEditableObject)objectUnderTest).BeginEdit();
		    SetValues(objectUnderTest, 3);

		    var expected = GetValues(objectUnderTest);

		    ((IEditableObject)objectUnderTest).EndEdit();

		    var diffs1 = GetDiffs(expected, objectUnderTest);
		    @Assert.AreEqual("0", "diffs1.Count");

		    ((IEditableObject)objectUnderTest).EndEdit();

		    var diffs2 = GetDiffs(expected, objectUnderTest); 
		    @Assert.AreEqual("0", "diffs2.Count");

	    }

    </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