TestCurrentFieldValueForNull

Posts   
 
    
Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 29-Jun-2006 10:40:19   

Hi

I've a problem with the TestCurrentFieldValueForNull method.

I've make this unit test that works :

        [Test]
        public void MyTest1() 
        {
            Timetable tt = new Timetable();
            Assert.IsTrue(tt.TestCurrentFieldValueForNull(TimetableFieldIndex.TtMaxConstant)); // works
        }

But this one doen't works:

[Test]
        public void MyTest2() 
        {
            Timetable tt = new Timetable();
            tt.TtMaxConstant = 1;
            tt.SetNewFieldValue((int)TimetableFieldIndex.TtMaxConstant, null);
            Assert.IsTrue(tt.Fields[(int)TimetableFieldIndex.TtMaxConstant].IsChanged);
            Assert.IsTrue(tt.TestCurrentFieldValueForNull(TimetableFieldIndex.TtMaxConstant)); // break here
        }

I don't understand why ?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 29-Jun-2006 15:04:25   

What the runtime library version you are using?

(edit) This was an old bug that was solved before, please use the latest version of LLBLGen Pro.

refer to: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=4782

Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 29-Jun-2006 15:15:21   

I've almost the lastest 2005.1 runtimes : v1.1.4322 (1.0.20051.060606)

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 29-Jun-2006 15:31:25   

Please make sure that your code is not using any old runtime library dll.

Aslo you may use a debug build of the runtime library (build the source code provided in debug mode and use it), and try to step into the TestCurrentFieldValueForNull method.

You should end up in the following method:

        
protected virtual bool CheckIfCurrentFieldValueIsNull(int fieldIndex)
{
    if(_isNew)
    {
    // a new entity field's value is null / not defined if it's not changed yet, or IF it's changed, it's set to null.
        return (!_fields[fieldIndex].IsChanged || ( _fields[fieldIndex].IsChanged && (_fields[fieldIndex].CurrentValue==null)));
    }
    else
    {
    // a non-new entity field's value is null / not defined if:
    // - it's not changed and original field value is null
    // - it's changed and the current value is null. 
        return ( (_fields[fieldIndex].IsChanged && (_fields[fieldIndex].CurrentValue==null)) ||
        (!_fields[fieldIndex].IsChanged && _fields[fieldIndex].IsNull));
    }
}

Which works as expected.

Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 29-Jun-2006 16:05:04   

I don't have time to retrieve the source code and compile. I've checked I don't reference an old version (and I never installed this old version... I started with the 2005 3 month ago.)

I've modified the nunit :

        [Test]
        public void MyTest2() 
        {
            System.Diagnostics.Debug.WriteLine("RuntimeLibraryVersion.Build : " + SD.LLBLGen.Pro.ORMSupportClasses.RuntimeLibraryVersion.Build);
            Timetable tt = new Timetable();
            tt.TtMaxConstant = 1;
            tt.SetNewFieldValue((int)TimetableFieldIndex.TtMaxConstant, null);
            System.Diagnostics.Debug.WriteLine("TimetableFieldIndex.TtMaxConstant isChanged : " + tt.Fields[(int)TimetableFieldIndex.TtMaxConstant].IsChanged);
            System.Diagnostics.Debug.WriteLine("TimetableFieldIndex.TtMaxConstant CurrentValue : " + tt.Fields[(int)TimetableFieldIndex.TtMaxConstant].CurrentValue);
            Assert.IsTrue(tt.Fields[(int)TimetableFieldIndex.TtMaxConstant].IsChanged);
            Assert.IsTrue(tt.TestCurrentFieldValueForNull(TimetableFieldIndex.TtMaxConstant)); // break here
        }
------ Test started: Assembly: HRATestCenter.dll ------

RuntimeLibraryVersion.Build : 06062006
TimetableFieldIndex.TtMaxConstant isChanged : True
TimetableFieldIndex.TtMaxConstant CurrentValue : 1
TestCase 'HRAccent.HRATestCenter.BusinessValidations.GenericValidatorTest.MyTest2' failed: 
    p:\hra_2006_07\hraccentserver.root\hraccentserver\hratestcenter\businessvalidations\genericvalidatortest.cs(274,0): at HRAccent.HRATestCenter.BusinessValidations.GenericValidatorTest.MyTest2()


0 succeeded, 1 failed, 0 skipped, took 1,05 seconds.

---------------------- Done ----------------------

As you can see: - The runtime libraries are the good one - The CurrentValue is still "1" after the "SetNewFieldValue" so the source code you paste (CheckIfCurrentFieldValueIsNull method) will of course return false.

So the real question is : why the CurrentValue is still to "1" after a "SetNewFieldValue" to null ?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 29-Jun-2006 17:27:28   

If the field isn't nullable the value won't be set. Is that the case?

Frans Bouma | Lead developer LLBLGen Pro
taylor74
User
Posts: 59
Joined: 06-Oct-2004
# Posted on: 29-Jun-2006 17:28:23   

Fabrice,

I'm guessing that TtMaxConstant is not nullable in the database. The runtime knows this and SetNewFieldValue is validating this situation and is not setting the field to null.

Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 29-Jun-2006 18:03:48   

Exact the field is not nullable in llblgen. I've made the test with a nullable field and it's works! Is it a new behaviour with 2005 ? Because this nunit was ok in 2004 version.

But thanks for your help :-)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 29-Jun-2006 19:49:53   

I've to check the previous version's code in subversion to see if it has changed, but if I remember correctly it was already so for a long time.

Frans Bouma | Lead developer LLBLGen Pro