I've been working with Blake, testing the Codesmith templates (CSLA 3.8.2). I was doing some VB nunit tests for BLB objects and some code that saves a new list item and checks to confirm the Identity column is correctly returned and populated from the Save method.
Public Shared Function NewList() As ConsultantList
Return DataPortal.Create(Of ConsultantList)() ' (BusinessListBase)
Protected Overrides Sub DataPortal_Create()
<Test()> Sub BLB_AddNew()
Dim test As Iims.BL.ConsultantList
test = Iims.BL.ConsultantList.NewList
' Test with no data (Will fail)
Assert.IsFalse(test.IsValid, "New record was valid when it was not supposed to be.")
' Ok now setup the core requirements
.State = "foo"
.CountryID = NamedConstants.SystemCountry.Australia
' Saving at the root level will not save all children.
test = test.Save()
This test failes because the CSLA.Dataportal.Save method, line 239 only checks for
var bbase = obj as Core.BusinessBase;
But returns nothing for the "bbase" variable while my business object (Intellisense shows: "CSLA.BusinesBase"). The logic following then incorrectly skips over the Insert/update methods and try's to do a DataPortal_Update, which wouldn't retrieve that tables identity value.
Is this a problem with the Codesmith template configuration or a CSLA bug or PEBKAC by me?
I know I can change the my code to use ERL (via the codesmith templates) and that will work (as I have nunit tests that pass for this), I just wanted to ensure I could use either or as needed, depending on the UI save record strategy needed.
Note: The following passes.
Assert.IsTrue(TypeOf (test.Item(0)) Is Core.BusinessBase)
Looks like an issue with the BLB DataPortal update incorrectly saving changes. I'll let Blake know.
Protected Overrides Sub DataPortal_Update()
Dim cancel As Boolean = False
If (cancel) Then
RaiseListChangedEvents = False
' Current template code
'For Each item As Consultant In Items
' Suggested template code.
For myLoop As Integer = 0 To Me.Items.Count - 1
Me.Items.Item(myLoop) = Me.Items.Item(myLoop).Save()
RaiseListChangedEvents = True
Copyright (c) Marimer LLC