This commit is contained in:
1
source/csla10/CSLA.Test/.cvsignore
Normal file
1
source/csla10/CSLA.Test/.cvsignore
Normal file
@@ -0,0 +1 @@
|
||||
CSLA.Test.xml
|
||||
31
source/csla10/CSLA.Test/AssemblyInfo.vb
Normal file
31
source/csla10/CSLA.Test/AssemblyInfo.vb
Normal file
@@ -0,0 +1,31 @@
|
||||
Imports System.Reflection
|
||||
Imports System.Runtime.InteropServices
|
||||
|
||||
' General Information about an assembly is controlled through the following
|
||||
' set of attributes. Change these attribute values to modify the information
|
||||
' associated with an assembly.
|
||||
|
||||
' Review the values of the assembly attributes
|
||||
|
||||
<Assembly: AssemblyTitle("")>
|
||||
<Assembly: AssemblyDescription("")>
|
||||
<Assembly: AssemblyCompany("")>
|
||||
<Assembly: AssemblyProduct("")>
|
||||
<Assembly: AssemblyCopyright("")>
|
||||
<Assembly: AssemblyTrademark("")>
|
||||
<Assembly: CLSCompliant(True)>
|
||||
|
||||
'The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
<Assembly: Guid("52CD186E-74AC-4213-8D3A-D3DF25033CC0")>
|
||||
|
||||
' Version information for an assembly consists of the following four values:
|
||||
'
|
||||
' Major Version
|
||||
' Minor Version
|
||||
' Build Number
|
||||
' Revision
|
||||
'
|
||||
' You can specify all the values or you can default the Build and Revision Numbers
|
||||
' by using the '*' as shown below:
|
||||
|
||||
<Assembly: AssemblyVersion("1.3.*")>
|
||||
95
source/csla10/CSLA.Test/Basics.vb
Normal file
95
source/csla10/CSLA.Test/Basics.vb
Normal file
@@ -0,0 +1,95 @@
|
||||
<TestFixture()> _
|
||||
Public Class Basics
|
||||
|
||||
<Test()> _
|
||||
Public Sub CreateGetRoot()
|
||||
Session.Clear()
|
||||
Dim root As GenRoot
|
||||
root = GenRoot.NewRoot
|
||||
Assert.IsNotNull(root)
|
||||
Assert.AreEqual("<new>", root.Data)
|
||||
Assert.AreEqual("Created", Session("GenRoot"))
|
||||
Assert.AreEqual(True, root.IsNew)
|
||||
Assert.AreEqual(False, root.IsDeleted)
|
||||
Assert.AreEqual(True, root.IsDirty)
|
||||
End Sub
|
||||
|
||||
<Test()> _
|
||||
Public Sub CreateRoot()
|
||||
Session.Clear()
|
||||
Dim root As root
|
||||
root = root.NewRoot
|
||||
Assert.IsNotNull(root)
|
||||
Assert.AreEqual("<new>", root.Data)
|
||||
Assert.AreEqual("Created", Session("Root"))
|
||||
Assert.AreEqual(True, root.IsNew)
|
||||
Assert.AreEqual(False, root.IsDeleted)
|
||||
Assert.AreEqual(True, root.IsDirty)
|
||||
End Sub
|
||||
|
||||
<Test()> _
|
||||
Public Sub AddChild()
|
||||
Session.Clear()
|
||||
Dim root As root = root.NewRoot
|
||||
root.Children.Add("1")
|
||||
Assert.AreEqual(1, root.Children.Count)
|
||||
Assert.AreEqual("1", root.Children(0).Data)
|
||||
End Sub
|
||||
|
||||
<Test()> _
|
||||
Public Sub AddRemoveChild()
|
||||
Session.Clear()
|
||||
Dim root As root = root.NewRoot
|
||||
root.Children.Add("1")
|
||||
root.Children.Remove(root.Children.Item(0))
|
||||
Assert.AreEqual(0, root.Children.Count)
|
||||
End Sub
|
||||
|
||||
<Test()> _
|
||||
Public Sub AddGrandChild()
|
||||
Session.Clear()
|
||||
Dim root As root = root.NewRoot
|
||||
root.Children.Add("1")
|
||||
Dim child As child = root.Children(0)
|
||||
child.GrandChildren.Add("1")
|
||||
Assert.AreEqual(1, child.GrandChildren.Count)
|
||||
Assert.AreEqual("1", child.GrandChildren(0).Data)
|
||||
End Sub
|
||||
|
||||
<Test()> _
|
||||
Public Sub AddRemoveGrandChild()
|
||||
Session.Clear()
|
||||
Dim root As root = root.NewRoot
|
||||
root.Children.Add("1")
|
||||
Dim child As child = root.Children(0)
|
||||
child.GrandChildren.Add("1")
|
||||
child.GrandChildren.Remove(child.GrandChildren.Item(0))
|
||||
Assert.AreEqual(0, child.GrandChildren.Count)
|
||||
End Sub
|
||||
|
||||
<Test()> _
|
||||
Public Sub CloneGraph()
|
||||
Session.Clear()
|
||||
Dim root As root = root.NewRoot
|
||||
root.Children.Add("1")
|
||||
Dim child As child = root.Children(0)
|
||||
child.GrandChildren.Add("1")
|
||||
Assert.AreEqual(1, child.GrandChildren.Count)
|
||||
Assert.AreEqual("1", child.GrandChildren(0).Data)
|
||||
|
||||
Dim clone As root = DirectCast(root.Clone, root)
|
||||
child = clone.Children(0)
|
||||
Assert.AreEqual(1, child.GrandChildren.Count)
|
||||
Assert.AreEqual("1", child.GrandChildren(0).Data)
|
||||
|
||||
Assert.AreEqual("root Deserialized", CStr(Session("Deserialized")))
|
||||
Assert.AreEqual("root Serialized", CStr(Session("Serialized")))
|
||||
Assert.AreEqual("root Serializing", CStr(Session("Serializing")))
|
||||
|
||||
Assert.AreEqual("GC Deserialized", CStr(Session("GCDeserialized")))
|
||||
Assert.AreEqual("GC Serialized", CStr(Session("GCSerialized")))
|
||||
Assert.AreEqual("GC Serializing", CStr(Session("GCSerializing")))
|
||||
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
12
source/csla10/CSLA.Test/BrokenRules.vb
Normal file
12
source/csla10/CSLA.Test/BrokenRules.vb
Normal file
@@ -0,0 +1,12 @@
|
||||
<TestFixture()> _
|
||||
Public Class BrokenRules
|
||||
|
||||
<Test()> _
|
||||
Public Sub BreakARule()
|
||||
Session.Clear()
|
||||
Dim root As HasRules = HasRules.NewHasRules
|
||||
Assert.AreEqual(root.IsValid, False)
|
||||
Assert.AreEqual(root.GetBrokenRulesCollection.Count, 1)
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
6
source/csla10/CSLA.Test/CSLA.Test.config
Normal file
6
source/csla10/CSLA.Test/CSLA.Test.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="Authentication" value="Windows" />
|
||||
</appSettings>
|
||||
</configuration>
|
||||
BIN
source/csla10/CSLA.Test/CSLA.Test.nunit
Normal file
BIN
source/csla10/CSLA.Test/CSLA.Test.nunit
Normal file
Binary file not shown.
53
source/csla10/CSLA.Test/CSLA.Test.vbproj
Normal file
53
source/csla10/CSLA.Test/CSLA.Test.vbproj
Normal file
@@ -0,0 +1,53 @@
|
||||
<VisualStudioProject>
|
||||
<VisualBasic ProjectType="Local" ProductVersion="7.10.3077" SchemaVersion="2.0" ProjectGuid="{D455F360-5347-4136-A825-64FFD41F9787}">
|
||||
<Build>
|
||||
<Settings ApplicationIcon="" AssemblyKeyContainerName="" AssemblyName="CSLA.Test" AssemblyOriginatorKeyFile="" AssemblyOriginatorKeyMode="None" DefaultClientScript="JScript" DefaultHTMLPageLayout="Grid" DefaultTargetSchema="IE50" DelaySign="false" OutputType="Library" OptionCompare="Binary" OptionExplicit="On" OptionStrict="On" RootNamespace="CSLA.Test" StartupObject="">
|
||||
<Config Name="Debug" BaseAddress="285212672" ConfigurationOverrideFile="" DefineConstants="" DefineDebug="true" DefineTrace="true" DebugSymbols="true" IncrementalBuild="true" Optimize="false" OutputPath="bin\" RegisterForComInterop="false" RemoveIntegerChecks="false" TreatWarningsAsErrors="false" WarningLevel="1" />
|
||||
<Config Name="Release" BaseAddress="285212672" ConfigurationOverrideFile="" DefineConstants="" DefineDebug="false" DefineTrace="true" DebugSymbols="false" IncrementalBuild="false" Optimize="true" OutputPath="bin\" RegisterForComInterop="false" RemoveIntegerChecks="false" TreatWarningsAsErrors="false" WarningLevel="1" />
|
||||
</Settings>
|
||||
<References>
|
||||
<Reference Name="System" AssemblyName="System" />
|
||||
<Reference Name="System.Data" AssemblyName="System.Data" />
|
||||
<Reference Name="System.XML" AssemblyName="System.Xml" />
|
||||
<Reference Name="CSLA" Project="{1B9A38BB-461A-47A4-AD72-099C694138A0}" Package="{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" />
|
||||
<Reference Name="CSLA.BatchQueue" Project="{F8E2709C-E0DE-4253-9A1A-59F4F59B0EBD}" Package="{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" />
|
||||
<Reference Name="CSLA.Core.Bindablebase" Project="{C2392355-12A9-4197-A1D3-603C390B1E62}" Package="{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" />
|
||||
<Reference Name="CSLA.Server.DataPortal" Project="{80828E2C-E9FB-4E73-A27C-7F9CDB96FCDE}" Package="{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" />
|
||||
<Reference Name="CSLA.Server.ServicedDataPortal" Project="{AD60DF60-2D14-4403-B5A8-41D4E06AB7AD}" Package="{F184B08F-C81C-45F6-A57F-5ABD9991F28F}" />
|
||||
<Reference Name="nunit.framework" AssemblyName="nunit.framework" HintPath="..\..\..\Program Files\NUnit V2.1\bin\nunit.framework.dll" />
|
||||
</References>
|
||||
<Imports>
|
||||
<Import Namespace="Microsoft.VisualBasic" />
|
||||
<Import Namespace="System" />
|
||||
<Import Namespace="System.Collections" />
|
||||
<Import Namespace="System.Data" />
|
||||
<Import Namespace="System.Diagnostics" />
|
||||
<Import Namespace="NUnit.Framework" />
|
||||
</Imports>
|
||||
</Build>
|
||||
<Files>
|
||||
<Include>
|
||||
<File RelPath="AssemblyInfo.vb" SubType="Code" BuildAction="Compile" />
|
||||
<File RelPath="Basics.vb" SubType="Code" BuildAction="Compile" />
|
||||
<File RelPath="BrokenRules.vb" SubType="Code" BuildAction="Compile" />
|
||||
<File RelPath="Child.vb" SubType="Code" BuildAction="Compile" />
|
||||
<File RelPath="Children.vb" SubType="Code" BuildAction="Compile" />
|
||||
<File RelPath="CSLA.Test.config" BuildAction="None" />
|
||||
<File RelPath="GenRoot.vb" SubType="Code" BuildAction="Compile" />
|
||||
<File RelPath="GenRootBase.vb" SubType="Code" BuildAction="Compile" />
|
||||
<File RelPath="Global.vb" SubType="Code" BuildAction="Compile" />
|
||||
<File RelPath="Grandchild.vb" SubType="Code" BuildAction="Compile" />
|
||||
<File RelPath="Grandchildren.vb" SubType="Code" BuildAction="Compile" />
|
||||
<File RelPath="HasRules.vb" SubType="Code" BuildAction="Compile" />
|
||||
<File RelPath="HasRulesManager.vb" SubType="Code" BuildAction="Compile" />
|
||||
<File RelPath="IO.vb" SubType="Code" BuildAction="Compile" />
|
||||
<File RelPath="MaxLengthArgs.vb" SubType="Code" BuildAction="Compile" />
|
||||
<File RelPath="Rollback.vb" SubType="Code" BuildAction="Compile" />
|
||||
<File RelPath="RollbackRoot.vb" SubType="Code" BuildAction="Compile" />
|
||||
<File RelPath="Root.vb" SubType="Code" BuildAction="Compile" />
|
||||
<File RelPath="RulesManager.vb" SubType="Code" BuildAction="Compile" />
|
||||
</Include>
|
||||
</Files>
|
||||
</VisualBasic>
|
||||
</VisualStudioProject>
|
||||
|
||||
48
source/csla10/CSLA.Test/CSLA.Test.vbproj.user
Normal file
48
source/csla10/CSLA.Test/CSLA.Test.vbproj.user
Normal file
@@ -0,0 +1,48 @@
|
||||
<VisualStudioProject>
|
||||
<VisualBasic LastOpenVersion = "7.10.3077" >
|
||||
<Build>
|
||||
<Settings ReferencePath = "" >
|
||||
<Config
|
||||
Name = "Debug"
|
||||
EnableASPDebugging = "false"
|
||||
EnableASPXDebugging = "false"
|
||||
EnableUnmanagedDebugging = "false"
|
||||
EnableSQLServerDebugging = "false"
|
||||
RemoteDebugEnabled = "false"
|
||||
RemoteDebugMachine = ""
|
||||
StartAction = "Project"
|
||||
StartArguments = ""
|
||||
StartPage = ""
|
||||
StartProgram = ""
|
||||
StartURL = ""
|
||||
StartWorkingDirectory = ""
|
||||
StartWithIE = "false"
|
||||
/>
|
||||
<Config
|
||||
Name = "Release"
|
||||
EnableASPDebugging = "false"
|
||||
EnableASPXDebugging = "false"
|
||||
EnableUnmanagedDebugging = "false"
|
||||
EnableSQLServerDebugging = "false"
|
||||
RemoteDebugEnabled = "false"
|
||||
RemoteDebugMachine = ""
|
||||
StartAction = "Project"
|
||||
StartArguments = ""
|
||||
StartPage = ""
|
||||
StartProgram = ""
|
||||
StartURL = ""
|
||||
StartWorkingDirectory = ""
|
||||
StartWithIE = "false"
|
||||
/>
|
||||
</Settings>
|
||||
</Build>
|
||||
<OtherProjectSettings
|
||||
CopyProjectDestinationFolder = ""
|
||||
CopyProjectUncPath = ""
|
||||
CopyProjectOption = "0"
|
||||
ProjectView = "ProjectFiles"
|
||||
ProjectTrust = "0"
|
||||
/>
|
||||
</VisualBasic>
|
||||
</VisualStudioProject>
|
||||
|
||||
63
source/csla10/CSLA.Test/Child.vb
Normal file
63
source/csla10/CSLA.Test/Child.vb
Normal file
@@ -0,0 +1,63 @@
|
||||
<Serializable()> _
|
||||
Public Class Child
|
||||
Inherits BusinessBase
|
||||
|
||||
Private mData As String = ""
|
||||
|
||||
Private mChildren As Grandchildren = Grandchildren.NewGrandChildren
|
||||
|
||||
Public Property Data() As String
|
||||
Get
|
||||
Return mData
|
||||
End Get
|
||||
Set(ByVal Value As String)
|
||||
If mData <> Value Then
|
||||
mData = Value
|
||||
MarkDirty()
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public ReadOnly Property GrandChildren() As Grandchildren
|
||||
Get
|
||||
Return mChildren
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Friend Shared Function NewChild(ByVal Data As String) As Child
|
||||
Dim obj As New Child()
|
||||
obj.mData = Data
|
||||
Return obj
|
||||
End Function
|
||||
|
||||
Friend Shared Function GetChild(ByVal dr As IDataReader) As Child
|
||||
Dim obj As New Child()
|
||||
obj.Fetch(dr)
|
||||
Return obj
|
||||
End Function
|
||||
|
||||
Private Sub New()
|
||||
' prevent direct creation
|
||||
MarkAsChild()
|
||||
End Sub
|
||||
|
||||
Private Sub Fetch(ByVal dr As IDataReader)
|
||||
MarkOld()
|
||||
End Sub
|
||||
|
||||
Friend Sub Update(ByVal tr As IDbTransaction)
|
||||
If IsDeleted Then
|
||||
' we would delete here
|
||||
MarkNew()
|
||||
Else
|
||||
If IsNew Then
|
||||
' we would insert here
|
||||
|
||||
Else
|
||||
' we would update here
|
||||
End If
|
||||
MarkOld()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
40
source/csla10/CSLA.Test/Children.vb
Normal file
40
source/csla10/CSLA.Test/Children.vb
Normal file
@@ -0,0 +1,40 @@
|
||||
<Serializable()> _
|
||||
Public Class Children
|
||||
Inherits BusinessCollectionBase
|
||||
|
||||
Default Public ReadOnly Property Item(ByVal index As Integer) As Child
|
||||
Get
|
||||
Return CType(list(index), Child)
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Sub Add(ByVal Data As String)
|
||||
list.Add(Child.NewChild(Data))
|
||||
End Sub
|
||||
|
||||
Public Sub Remove(ByVal child As Child)
|
||||
list.Remove(child)
|
||||
End Sub
|
||||
|
||||
Friend Shared Function NewChildren() As Children
|
||||
Return New Children()
|
||||
End Function
|
||||
|
||||
Friend Shared Function GetChildren(ByVal dr As IDataReader) As Children
|
||||
' TODO: load child data
|
||||
End Function
|
||||
|
||||
Friend Sub Update(ByVal tr As IDbTransaction)
|
||||
Dim child As child
|
||||
|
||||
For Each child In list
|
||||
child.Update(tr)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Private Sub New()
|
||||
' prevent direct creation
|
||||
MarkAsChild()
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
9
source/csla10/CSLA.Test/GenRoot.vb
Normal file
9
source/csla10/CSLA.Test/GenRoot.vb
Normal file
@@ -0,0 +1,9 @@
|
||||
<Serializable()> _
|
||||
Public Class GenRoot
|
||||
Inherits GenRootBase
|
||||
|
||||
Private Sub New()
|
||||
' prevent direct creation
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
90
source/csla10/CSLA.Test/GenRootBase.vb
Normal file
90
source/csla10/CSLA.Test/GenRootBase.vb
Normal file
@@ -0,0 +1,90 @@
|
||||
<Serializable()> _
|
||||
Public Class GenRootBase
|
||||
Inherits BusinessBase
|
||||
|
||||
Private mData As String = ""
|
||||
|
||||
Public Property Data() As String
|
||||
Get
|
||||
Return mData
|
||||
End Get
|
||||
Set(ByVal Value As String)
|
||||
If mData <> Value Then
|
||||
mData = Value
|
||||
MarkDirty()
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
|
||||
<Serializable()> _
|
||||
Private Class Criteria
|
||||
Inherits CriteriaBase
|
||||
|
||||
Public Data As String
|
||||
|
||||
Public Sub New()
|
||||
MyBase.New(GetType(GenRoot))
|
||||
Data = "<new>"
|
||||
End Sub
|
||||
|
||||
Public Sub New(ByVal Data As String)
|
||||
MyBase.New(GetType(GenRoot))
|
||||
Me.Data = Data
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Shared Function NewRoot() As GenRoot
|
||||
Return DirectCast(DataPortal.Create(New Criteria()), GenRoot)
|
||||
End Function
|
||||
|
||||
Public Shared Function GetRoot(ByVal Data As String) As GenRoot
|
||||
Return DirectCast(DataPortal.Fetch(New Criteria(Data)), GenRoot)
|
||||
End Function
|
||||
|
||||
Public Shared Sub DeleteRoot(ByVal Data As String)
|
||||
DataPortal.Delete(New Criteria(Data))
|
||||
End Sub
|
||||
|
||||
|
||||
Protected Sub New()
|
||||
' prevent direct creation
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Create(ByVal Criteria As Object)
|
||||
Dim crit As Criteria = DirectCast(Criteria, Criteria)
|
||||
mData = crit.Data
|
||||
Session.Add("GenRoot", "Created")
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Fetch(ByVal Criteria As Object)
|
||||
Dim crit As Criteria = DirectCast(Criteria, Criteria)
|
||||
mData = crit.Data
|
||||
MarkOld()
|
||||
Session.Add("GenRoot", "Fetched")
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Update()
|
||||
If IsDeleted Then
|
||||
' we would delete here
|
||||
Session.Add("GenRoot", "Deleted")
|
||||
MarkNew()
|
||||
Else
|
||||
If IsNew Then
|
||||
' we would insert here
|
||||
Session.Add("GenRoot", "Inserted")
|
||||
|
||||
Else
|
||||
' we would update here
|
||||
Session.Add("GenRoot", "Updated")
|
||||
End If
|
||||
MarkOld()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Delete(ByVal Criteria As Object)
|
||||
' we would delete here
|
||||
Session.Add("GenRoot", "Deleted")
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
5
source/csla10/CSLA.Test/Global.vb
Normal file
5
source/csla10/CSLA.Test/Global.vb
Normal file
@@ -0,0 +1,5 @@
|
||||
Module Global
|
||||
|
||||
Public Session As New Hashtable()
|
||||
|
||||
End Module
|
||||
70
source/csla10/CSLA.Test/Grandchild.vb
Normal file
70
source/csla10/CSLA.Test/Grandchild.vb
Normal file
@@ -0,0 +1,70 @@
|
||||
<Serializable()> _
|
||||
Public Class Grandchild
|
||||
Inherits BusinessBase
|
||||
|
||||
Private mData As String = ""
|
||||
|
||||
Public Property Data() As String
|
||||
Get
|
||||
Return mData
|
||||
End Get
|
||||
Set(ByVal Value As String)
|
||||
If mData <> Value Then
|
||||
mData = Value
|
||||
MarkDirty()
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Friend Shared Function NewGrandChild(ByVal Data As String) As Grandchild
|
||||
Dim obj As New Grandchild()
|
||||
obj.mData = Data
|
||||
Return obj
|
||||
End Function
|
||||
|
||||
Friend Shared Function GetGrandChild(ByVal dr As IDataReader) As Grandchild
|
||||
Dim obj As New Grandchild()
|
||||
obj.Fetch(dr)
|
||||
Return obj
|
||||
End Function
|
||||
|
||||
Private Sub New()
|
||||
' prevent direct creation
|
||||
MarkAsChild()
|
||||
End Sub
|
||||
|
||||
Private Sub Fetch(ByVal dr As IDataReader)
|
||||
MarkOld()
|
||||
End Sub
|
||||
|
||||
Friend Sub Update(ByVal tr As IDbTransaction)
|
||||
If IsDeleted Then
|
||||
' we would delete here
|
||||
MarkNew()
|
||||
Else
|
||||
If IsNew Then
|
||||
' we would insert here
|
||||
|
||||
Else
|
||||
' we would update here
|
||||
End If
|
||||
MarkOld()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub Deserialized()
|
||||
MyBase.Deserialized()
|
||||
Session.Add("GCDeserialized", "GC Deserialized")
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub Serialized()
|
||||
MyBase.Serialized()
|
||||
Session.Add("GCSerialized", "GC Serialized")
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub Serializing()
|
||||
MyBase.Serializing()
|
||||
Session.Add("GCSerializing", "GC Serializing")
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
40
source/csla10/CSLA.Test/Grandchildren.vb
Normal file
40
source/csla10/CSLA.Test/Grandchildren.vb
Normal file
@@ -0,0 +1,40 @@
|
||||
<Serializable()> _
|
||||
Public Class Grandchildren
|
||||
Inherits BusinessCollectionBase
|
||||
|
||||
Default Public ReadOnly Property Item(ByVal index As Integer) As Grandchild
|
||||
Get
|
||||
Return CType(list(index), Grandchild)
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Sub Add(ByVal Data As String)
|
||||
list.Add(Grandchild.NewGrandChild(Data))
|
||||
End Sub
|
||||
|
||||
Public Sub Remove(ByVal child As Grandchild)
|
||||
list.Remove(child)
|
||||
End Sub
|
||||
|
||||
Friend Shared Function NewGrandChildren() As Grandchildren
|
||||
Return New Grandchildren()
|
||||
End Function
|
||||
|
||||
Friend Shared Function GetGrandChildren(ByVal dr As IDataReader) As Grandchildren
|
||||
' TODO: load child data
|
||||
End Function
|
||||
|
||||
Friend Sub Update(ByVal tr As IDbTransaction)
|
||||
Dim child As Grandchild
|
||||
|
||||
For Each child In list
|
||||
child.Update(tr)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Private Sub New()
|
||||
' prevent direct creation
|
||||
MarkAsChild()
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
88
source/csla10/CSLA.Test/HasRules.vb
Normal file
88
source/csla10/CSLA.Test/HasRules.vb
Normal file
@@ -0,0 +1,88 @@
|
||||
Public Class HasRules
|
||||
Inherits BusinessBase
|
||||
|
||||
Private mName As String = ""
|
||||
|
||||
Public Property Name() As String
|
||||
Get
|
||||
Return mName
|
||||
End Get
|
||||
Set(ByVal Value As String)
|
||||
If mName <> Value Then
|
||||
mName = Value
|
||||
BrokenRules.Assert("NameReq", "Name required", Len(mName) = 0)
|
||||
BrokenRules.Assert("NameMax", "Name too long", Len(mName) > 10)
|
||||
MarkDirty()
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
<Serializable()> _
|
||||
Private Class Criteria
|
||||
Public Name As String
|
||||
|
||||
Public Sub New()
|
||||
Name = "<new>"
|
||||
End Sub
|
||||
|
||||
Public Sub New(ByVal Name As String)
|
||||
Me.Name = Name
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Shared Function NewHasRules() As HasRules
|
||||
Return DirectCast(DataPortal.Create(New Criteria()), HasRules)
|
||||
End Function
|
||||
|
||||
Public Shared Function GetHasRules(ByVal Name As String) As HasRules
|
||||
Return DirectCast(DataPortal.Fetch(New Criteria(Name)), HasRules)
|
||||
End Function
|
||||
|
||||
Public Shared Sub DeleteHasRules(ByVal Name As String)
|
||||
DataPortal.Delete(New Criteria(Name))
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub New()
|
||||
' prevent direct creation
|
||||
BrokenRules.Assert("NameReq", "Name required", Len(mName) = 0)
|
||||
BrokenRules.Assert("NameMax", "Name too long", Len(mName) > 10)
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Create(ByVal Criteria As Object)
|
||||
Dim crit As Criteria = DirectCast(Criteria, Criteria)
|
||||
mName = crit.Name
|
||||
Session.Add("HasRules", "Created")
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Fetch(ByVal Criteria As Object)
|
||||
Dim crit As Criteria = DirectCast(Criteria, Criteria)
|
||||
mName = crit.Name
|
||||
MarkOld()
|
||||
Session.Add("HasRules", "Fetched")
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Update()
|
||||
If IsDeleted Then
|
||||
' we would delete here
|
||||
Session.Add("HasRules", "Deleted")
|
||||
MarkNew()
|
||||
Else
|
||||
If IsNew Then
|
||||
' we would insert here
|
||||
Session.Add("HasRules", "Inserted")
|
||||
|
||||
Else
|
||||
' we would update here
|
||||
Session.Add("HasRules", "Updated")
|
||||
End If
|
||||
MarkOld()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Delete(ByVal Criteria As Object)
|
||||
' we would delete here
|
||||
Session.Add("HasRules", "Deleted")
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
115
source/csla10/CSLA.Test/HasRulesManager.vb
Normal file
115
source/csla10/CSLA.Test/HasRulesManager.vb
Normal file
@@ -0,0 +1,115 @@
|
||||
Imports CSLA.BrokenRules
|
||||
|
||||
<Serializable()> _
|
||||
Public Class HasRulesManager
|
||||
Inherits BusinessBase
|
||||
|
||||
Private mName As String = ""
|
||||
|
||||
Public Property Name() As String
|
||||
Get
|
||||
Return mName
|
||||
End Get
|
||||
Set(ByVal Value As String)
|
||||
If mName <> Value Then
|
||||
mName = Value
|
||||
BrokenRules.CheckRules("Name")
|
||||
MarkDirty()
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Protected Overrides Sub AddBusinessRules()
|
||||
With BrokenRules
|
||||
.SetTargetObject(Me)
|
||||
.AddRule(AddressOf NameRequired, "Name")
|
||||
.AddRule(AddressOf NameLength, "Name", New MaxLengthArgs(10))
|
||||
.CheckRules()
|
||||
End With
|
||||
End Sub
|
||||
|
||||
<Description("{0} required")> _
|
||||
Private Function NameRequired(ByVal target As Object, ByVal e As RuleArgs) As Boolean
|
||||
Return Len(mName) > 0
|
||||
End Function
|
||||
|
||||
<Description("{0} too long")> _
|
||||
Private Function NameLength(ByVal target As Object, ByVal e As RuleArgs) As Boolean
|
||||
If Len(mName) <= DirectCast(e, MaxLengthArgs).MaxLength Then
|
||||
Return True
|
||||
|
||||
Else
|
||||
e.Description = "The value for {0} is too long"
|
||||
Return False
|
||||
End If
|
||||
End Function
|
||||
|
||||
<Serializable()> _
|
||||
Private Class Criteria
|
||||
Public Name As String
|
||||
|
||||
Public Sub New()
|
||||
Name = "<new>"
|
||||
End Sub
|
||||
|
||||
Public Sub New(ByVal Name As String)
|
||||
Me.Name = Name
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Shared Function NewHasRulesManager() As HasRulesManager
|
||||
Return DirectCast(DataPortal.Create(New Criteria()), HasRulesManager)
|
||||
End Function
|
||||
|
||||
Public Shared Function GetHasRulesManager(ByVal Name As String) As HasRulesManager
|
||||
Return DirectCast(DataPortal.Fetch(New Criteria(Name)), HasRulesManager)
|
||||
End Function
|
||||
|
||||
Public Shared Sub DeleteHasRulesManager(ByVal Name As String)
|
||||
DataPortal.Delete(New Criteria(Name))
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub New()
|
||||
' prevent direct creation
|
||||
AddBusinessRules()
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Create(ByVal Criteria As Object)
|
||||
Dim crit As Criteria = DirectCast(Criteria, Criteria)
|
||||
mName = crit.Name
|
||||
Session.Add("HasRulesManager", "Created")
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Fetch(ByVal Criteria As Object)
|
||||
Dim crit As Criteria = DirectCast(Criteria, Criteria)
|
||||
mName = crit.Name
|
||||
MarkOld()
|
||||
Session.Add("HasRulesManager", "Fetched")
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Update()
|
||||
If IsDeleted Then
|
||||
' we would delete here
|
||||
Session.Add("HasRulesManager", "Deleted")
|
||||
MarkNew()
|
||||
Else
|
||||
If IsNew Then
|
||||
' we would insert here
|
||||
Session.Add("HasRulesManager", "Inserted")
|
||||
|
||||
Else
|
||||
' we would update here
|
||||
Session.Add("HasRulesManager", "Updated")
|
||||
End If
|
||||
MarkOld()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Delete(ByVal Criteria As Object)
|
||||
' we would delete here
|
||||
Session.Add("HasRulesManager", "Deleted")
|
||||
End Sub
|
||||
|
||||
|
||||
End Class
|
||||
109
source/csla10/CSLA.Test/IO.vb
Normal file
109
source/csla10/CSLA.Test/IO.vb
Normal file
@@ -0,0 +1,109 @@
|
||||
<TestFixture()> _
|
||||
Public Class IO
|
||||
|
||||
<Test()> _
|
||||
Public Sub SaveNewRoot()
|
||||
Session.Clear()
|
||||
Dim root As root
|
||||
root = root.NewRoot()
|
||||
|
||||
root.Data = "saved"
|
||||
Assert.AreEqual("saved", root.Data)
|
||||
Assert.AreEqual(True, root.IsDirty)
|
||||
Assert.AreEqual(True, root.IsValid)
|
||||
|
||||
Session.Clear()
|
||||
root = CType(root.Save, root)
|
||||
|
||||
Assert.IsNotNull(root)
|
||||
Assert.AreEqual("Inserted", Session("Root"))
|
||||
Assert.AreEqual("saved", root.Data)
|
||||
Assert.AreEqual(False, root.IsNew)
|
||||
Assert.AreEqual(False, root.IsDeleted)
|
||||
Assert.AreEqual(False, root.IsDirty)
|
||||
End Sub
|
||||
|
||||
<Test()> _
|
||||
Public Sub SaveOldRoot()
|
||||
Session.Clear()
|
||||
Dim root As root
|
||||
root = root.GetRoot("old")
|
||||
|
||||
root.Data = "saved"
|
||||
Assert.AreEqual("saved", root.Data)
|
||||
Assert.AreEqual(True, root.IsDirty, "IsDirty")
|
||||
Assert.AreEqual(True, root.IsValid, "IsValid")
|
||||
|
||||
Session.Clear()
|
||||
root = CType(root.Save, root)
|
||||
|
||||
Assert.IsNotNull(root)
|
||||
Assert.AreEqual("Updated", Session("Root"))
|
||||
Assert.AreEqual("saved", root.Data)
|
||||
Assert.AreEqual(False, root.IsNew, "IsNew")
|
||||
Assert.AreEqual(False, root.IsDeleted, "IsDeleted")
|
||||
Assert.AreEqual(False, root.IsDirty, "IsDirty")
|
||||
End Sub
|
||||
|
||||
<Test()> _
|
||||
Public Sub LoadRoot()
|
||||
Session.Clear()
|
||||
Dim root As root
|
||||
root = root.GetRoot("loaded")
|
||||
Assert.IsNotNull(root)
|
||||
Assert.AreEqual("Fetched", Session("Root"))
|
||||
Assert.AreEqual("loaded", root.Data)
|
||||
Assert.AreEqual(False, root.IsNew)
|
||||
Assert.AreEqual(False, root.IsDeleted)
|
||||
Assert.AreEqual(False, root.IsDirty)
|
||||
Assert.AreEqual(True, root.IsValid)
|
||||
End Sub
|
||||
|
||||
<Test()> _
|
||||
Public Sub DeleteNewRoot()
|
||||
Session.Clear()
|
||||
Dim root As root
|
||||
root = root.NewRoot
|
||||
|
||||
Session.Clear()
|
||||
root.Delete()
|
||||
Assert.AreEqual(True, root.IsNew)
|
||||
Assert.AreEqual(True, root.IsDeleted)
|
||||
Assert.AreEqual(True, root.IsDirty)
|
||||
|
||||
root = CType(root.Save, root)
|
||||
Assert.IsNotNull(root)
|
||||
Assert.AreEqual("Deleted", Session("Root"))
|
||||
Assert.AreEqual(True, root.IsNew)
|
||||
Assert.AreEqual(False, root.IsDeleted)
|
||||
Assert.AreEqual(True, root.IsDirty)
|
||||
End Sub
|
||||
|
||||
<Test()> _
|
||||
Public Sub DeleteOldRoot()
|
||||
Session.Clear()
|
||||
Dim root As root
|
||||
root = root.GetRoot("old")
|
||||
|
||||
Session.Clear()
|
||||
root.Delete()
|
||||
Assert.AreEqual(False, root.IsNew)
|
||||
Assert.AreEqual(True, root.IsDeleted)
|
||||
Assert.AreEqual(True, root.IsDirty)
|
||||
|
||||
root = CType(root.Save, root)
|
||||
Assert.IsNotNull(root)
|
||||
Assert.AreEqual("Deleted", Session("Root"))
|
||||
Assert.AreEqual(True, root.IsNew)
|
||||
Assert.AreEqual(False, root.IsDeleted)
|
||||
Assert.AreEqual(True, root.IsDirty)
|
||||
End Sub
|
||||
|
||||
<Test()> _
|
||||
Public Sub DeleteRootImmediate()
|
||||
Session.Clear()
|
||||
Root.DeleteRoot("test")
|
||||
Assert.AreEqual("Deleted", Session("Root"))
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
22
source/csla10/CSLA.Test/MaxLengthArgs.vb
Normal file
22
source/csla10/CSLA.Test/MaxLengthArgs.vb
Normal file
@@ -0,0 +1,22 @@
|
||||
Imports CSLA.BrokenRules
|
||||
|
||||
Public Class MaxLengthArgs
|
||||
Inherits RuleArgs
|
||||
|
||||
Private mMax As Integer
|
||||
|
||||
Public ReadOnly Property MaxLength() As Integer
|
||||
Get
|
||||
Return mMax
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Sub New(ByVal maxLength As Integer)
|
||||
mMax = maxLength
|
||||
End Sub
|
||||
|
||||
Public Sub New(ByVal propertyName As String, ByVal maxLength As Integer)
|
||||
MyBase.New(propertyName)
|
||||
mMax = maxLength
|
||||
End Sub
|
||||
End Class
|
||||
111
source/csla10/CSLA.Test/Rollback.vb
Normal file
111
source/csla10/CSLA.Test/Rollback.vb
Normal file
@@ -0,0 +1,111 @@
|
||||
<TestFixture()> _
|
||||
Public Class Rollback
|
||||
|
||||
<Test()> _
|
||||
Public Sub NoFail()
|
||||
Session.Clear()
|
||||
Dim root As RollbackRoot
|
||||
root = root.NewRoot()
|
||||
|
||||
root.BeginEdit()
|
||||
root.Data = "saved"
|
||||
Assert.AreEqual("saved", root.Data, "data is 'saved'")
|
||||
Assert.AreEqual(False, root.Fail, "fail is false")
|
||||
Assert.AreEqual(True, root.IsDirty, "isdirty is true")
|
||||
Assert.AreEqual(True, root.IsValid, "isvalid is true")
|
||||
Assert.AreEqual(True, root.IsNew, "isnew is true")
|
||||
|
||||
Session.Clear()
|
||||
Dim tmp As RollbackRoot = DirectCast(root.Clone, RollbackRoot)
|
||||
Try
|
||||
root.ApplyEdit()
|
||||
root = DirectCast(root.Save, RollbackRoot)
|
||||
|
||||
Catch
|
||||
root = tmp
|
||||
Assert.Fail("exception occurred")
|
||||
End Try
|
||||
|
||||
Assert.IsNotNull(root, "obj is not null")
|
||||
Assert.AreEqual("Inserted", Session("Root"), "obj was inserted")
|
||||
Assert.AreEqual("saved", root.Data, "data is 'saved'")
|
||||
Assert.AreEqual(False, root.IsNew, "isnew is false")
|
||||
Assert.AreEqual(False, root.IsDeleted, "isdeleted is false")
|
||||
Assert.AreEqual(False, root.IsDirty, "isdirty is false")
|
||||
|
||||
End Sub
|
||||
|
||||
<Test()> _
|
||||
Public Sub YesFail()
|
||||
Session.Clear()
|
||||
Dim root As RollbackRoot
|
||||
root = root.NewRoot()
|
||||
|
||||
root.BeginEdit()
|
||||
root.Data = "saved"
|
||||
root.Fail = True
|
||||
Assert.AreEqual("saved", root.Data, "data is 'saved'")
|
||||
Assert.AreEqual(True, root.Fail, "fail is true")
|
||||
Assert.AreEqual(True, root.IsDirty, "isdirty is true")
|
||||
Assert.AreEqual(True, root.IsValid, "isvalid is true")
|
||||
Assert.AreEqual(True, root.IsNew, "isnew is true")
|
||||
|
||||
Session.Clear()
|
||||
Dim tmp As RollbackRoot = DirectCast(root.Clone, RollbackRoot)
|
||||
Try
|
||||
root.ApplyEdit()
|
||||
root = DirectCast(root.Save, RollbackRoot)
|
||||
Assert.Fail("exception didn't occur")
|
||||
|
||||
Catch
|
||||
root = tmp
|
||||
End Try
|
||||
|
||||
Assert.IsNotNull(root, "obj is not null")
|
||||
Assert.AreEqual("Inserted", Session("Root"), "obj was inserted")
|
||||
Assert.AreEqual("saved", root.Data, "data is 'saved'")
|
||||
Assert.AreEqual(True, root.IsNew, "isnew is true")
|
||||
Assert.AreEqual(False, root.IsDeleted, "isdeleted is false")
|
||||
Assert.AreEqual(True, root.IsDirty, "isdirty is true")
|
||||
|
||||
End Sub
|
||||
|
||||
<Test()> _
|
||||
Public Sub YesFailCancel()
|
||||
Session.Clear()
|
||||
Dim root As RollbackRoot
|
||||
root = root.NewRoot()
|
||||
Assert.AreEqual(True, root.IsDirty, "isdirty is true")
|
||||
Assert.AreEqual("<new>", root.Data, "data is '<new>'")
|
||||
|
||||
root.BeginEdit()
|
||||
root.Data = "saved"
|
||||
root.Fail = True
|
||||
Assert.AreEqual("saved", root.Data, "data is 'saved'")
|
||||
Assert.AreEqual(True, root.Fail, "fail is true")
|
||||
Assert.AreEqual(True, root.IsDirty, "isdirty is true")
|
||||
Assert.AreEqual(True, root.IsValid, "isvalid is true")
|
||||
Assert.AreEqual(True, root.IsNew, "isnew is true")
|
||||
|
||||
Session.Clear()
|
||||
Dim tmp As RollbackRoot = DirectCast(root.Clone, RollbackRoot)
|
||||
Try
|
||||
root.ApplyEdit()
|
||||
root = DirectCast(root.Save, RollbackRoot)
|
||||
Assert.Fail("exception didn't occur")
|
||||
|
||||
Catch
|
||||
root = tmp
|
||||
root.CancelEdit()
|
||||
End Try
|
||||
|
||||
Assert.IsNotNull(root, "obj is not null")
|
||||
Assert.AreEqual("Inserted", Session("Root"), "obj was inserted")
|
||||
Assert.AreEqual("<new>", root.Data, "data is '<new>'")
|
||||
Assert.AreEqual(True, root.IsNew, "isnew is true")
|
||||
Assert.AreEqual(False, root.IsDeleted, "isdeleted is false")
|
||||
Assert.AreEqual(True, root.IsDirty, "isdirty is true")
|
||||
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
128
source/csla10/CSLA.Test/RollbackRoot.vb
Normal file
128
source/csla10/CSLA.Test/RollbackRoot.vb
Normal file
@@ -0,0 +1,128 @@
|
||||
<Serializable()> _
|
||||
Public Class RollbackRoot
|
||||
Inherits BusinessBase
|
||||
|
||||
Private mData As String = ""
|
||||
Private mFail As Boolean = False
|
||||
|
||||
Public Property Data() As String
|
||||
Get
|
||||
Return mData
|
||||
End Get
|
||||
Set(ByVal Value As String)
|
||||
If mData <> Value Then
|
||||
mData = Value
|
||||
MarkDirty()
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Property Fail() As Boolean
|
||||
Get
|
||||
Return mFail
|
||||
End Get
|
||||
Set(ByVal Value As Boolean)
|
||||
If mFail <> Value Then
|
||||
mFail = Value
|
||||
MarkDirty()
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
|
||||
|
||||
<Serializable()> _
|
||||
Private Class Criteria
|
||||
Public Data As String
|
||||
|
||||
Public Sub New()
|
||||
Data = "<new>"
|
||||
End Sub
|
||||
|
||||
Public Sub New(ByVal Data As String)
|
||||
Me.Data = Data
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Shared Function NewRoot() As RollbackRoot
|
||||
Return DirectCast(DataPortal.Create(New Criteria()), RollbackRoot)
|
||||
End Function
|
||||
|
||||
Public Shared Function GetRoot(ByVal Data As String) As RollbackRoot
|
||||
Return DirectCast(DataPortal.Fetch(New Criteria(Data)), RollbackRoot)
|
||||
End Function
|
||||
|
||||
Public Shared Sub DeleteRoot(ByVal Data As String)
|
||||
DataPortal.Delete(New Criteria(Data))
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub New()
|
||||
' prevent direct creation
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Create(ByVal Criteria As Object)
|
||||
Dim crit As Criteria = DirectCast(Criteria, Criteria)
|
||||
mData = crit.Data
|
||||
Session.Add("Root", "Created")
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Fetch(ByVal Criteria As Object)
|
||||
Dim crit As Criteria = DirectCast(Criteria, Criteria)
|
||||
mData = crit.Data
|
||||
MarkOld()
|
||||
Session.Add("Root", "Fetched")
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Update()
|
||||
|
||||
'BeginEdit()
|
||||
Try
|
||||
If IsDeleted Then
|
||||
' we would delete here
|
||||
Session.Add("Root", "Deleted")
|
||||
MarkNew()
|
||||
Else
|
||||
If IsNew Then
|
||||
' we would insert here
|
||||
Session.Add("Root", "Inserted")
|
||||
|
||||
Else
|
||||
' we would update here
|
||||
Session.Add("Root", "Updated")
|
||||
End If
|
||||
MarkOld()
|
||||
|
||||
If mFail Then Throw New Exception("fail update")
|
||||
|
||||
End If
|
||||
'ApplyEdit()
|
||||
|
||||
Catch
|
||||
'CancelEdit()
|
||||
Throw
|
||||
End Try
|
||||
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Delete(ByVal Criteria As Object)
|
||||
' we would delete here
|
||||
Session.Add("Root", "Deleted")
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub Deserialized()
|
||||
MyBase.Deserialized()
|
||||
Session.Add("Deserialized", "root Deserialized")
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub Serialized()
|
||||
MyBase.Serialized()
|
||||
Session.Add("Serialized", "root Serialized")
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub Serializing()
|
||||
MyBase.Serializing()
|
||||
Session.Add("Serializing", "root Serializing")
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
116
source/csla10/CSLA.Test/Root.vb
Normal file
116
source/csla10/CSLA.Test/Root.vb
Normal file
@@ -0,0 +1,116 @@
|
||||
<Serializable()> _
|
||||
Public Class Root
|
||||
Inherits BusinessBase
|
||||
|
||||
Private mData As String = ""
|
||||
|
||||
Private mChildren As Children = Children.NewChildren
|
||||
|
||||
Public Property Data() As String
|
||||
Get
|
||||
Return mData
|
||||
End Get
|
||||
Set(ByVal Value As String)
|
||||
If mData <> Value Then
|
||||
mData = Value
|
||||
MarkDirty()
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public ReadOnly Property Children() As Children
|
||||
Get
|
||||
Return mChildren
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Overrides ReadOnly Property IsDirty() As Boolean
|
||||
Get
|
||||
Return MyBase.IsDirty OrElse mChildren.IsDirty
|
||||
End Get
|
||||
End Property
|
||||
|
||||
|
||||
|
||||
<Serializable()> _
|
||||
Private Class Criteria
|
||||
Public Data As String
|
||||
|
||||
Public Sub New()
|
||||
Data = "<new>"
|
||||
End Sub
|
||||
|
||||
Public Sub New(ByVal Data As String)
|
||||
Me.Data = Data
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Shared Function NewRoot() As Root
|
||||
Return DirectCast(DataPortal.Create(New Criteria()), Root)
|
||||
End Function
|
||||
|
||||
Public Shared Function GetRoot(ByVal Data As String) As Root
|
||||
Return DirectCast(DataPortal.Fetch(New Criteria(Data)), Root)
|
||||
End Function
|
||||
|
||||
Public Shared Sub DeleteRoot(ByVal Data As String)
|
||||
DataPortal.Delete(New Criteria(Data))
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub New()
|
||||
' prevent direct creation
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Create(ByVal Criteria As Object)
|
||||
Dim crit As Criteria = DirectCast(Criteria, Criteria)
|
||||
mData = crit.Data
|
||||
Session.Add("Root", "Created")
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Fetch(ByVal Criteria As Object)
|
||||
Dim crit As Criteria = DirectCast(Criteria, Criteria)
|
||||
mData = crit.Data
|
||||
MarkOld()
|
||||
Session.Add("Root", "Fetched")
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Update()
|
||||
If IsDeleted Then
|
||||
' we would delete here
|
||||
Session.Add("Root", "Deleted")
|
||||
MarkNew()
|
||||
Else
|
||||
If IsNew Then
|
||||
' we would insert here
|
||||
Session.Add("Root", "Inserted")
|
||||
|
||||
Else
|
||||
' we would update here
|
||||
Session.Add("Root", "Updated")
|
||||
End If
|
||||
MarkOld()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub DataPortal_Delete(ByVal Criteria As Object)
|
||||
' we would delete here
|
||||
Session.Add("Root", "Deleted")
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub Deserialized()
|
||||
MyBase.Deserialized()
|
||||
Session.Add("Deserialized", "root Deserialized")
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub Serialized()
|
||||
MyBase.Serialized()
|
||||
Session.Add("Serialized", "root Serialized")
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub Serializing()
|
||||
MyBase.Serializing()
|
||||
Session.Add("Serializing", "root Serializing")
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
61
source/csla10/CSLA.Test/RulesManager.vb
Normal file
61
source/csla10/CSLA.Test/RulesManager.vb
Normal file
@@ -0,0 +1,61 @@
|
||||
<TestFixture()> _
|
||||
Public Class RulesManager
|
||||
|
||||
<Test()> _
|
||||
Public Sub BreakRequiredRule()
|
||||
Session.Clear()
|
||||
Dim root As HasRulesManager = HasRulesManager.NewHasRulesManager
|
||||
Assert.AreEqual(False, root.IsValid, "Should not be valid")
|
||||
Assert.AreEqual(1, root.GetBrokenRulesCollection.Count)
|
||||
Assert.AreEqual("Name required", root.GetBrokenRulesCollection.Item(0).Description)
|
||||
End Sub
|
||||
|
||||
<Test()> _
|
||||
Public Sub BreakLengthRule()
|
||||
Session.Clear()
|
||||
Dim root As HasRulesManager = HasRulesManager.NewHasRulesManager
|
||||
root.Name = "12345678901"
|
||||
Assert.AreEqual(False, root.IsValid, "Should not be valid")
|
||||
Assert.AreEqual(1, root.GetBrokenRulesCollection.Count)
|
||||
'Assert.AreEqual("Name too long", root.GetBrokenRulesCollection.Item(0).Description)
|
||||
Assert.AreEqual("The value for Name is too long", root.GetBrokenRulesCollection.Item(0).Description)
|
||||
End Sub
|
||||
|
||||
<Test()> _
|
||||
Public Sub UnBreakLengthRule()
|
||||
Session.Clear()
|
||||
Dim root As HasRulesManager = HasRulesManager.NewHasRulesManager
|
||||
root.Name = "12345678901"
|
||||
Assert.AreEqual(False, root.IsValid, "Should not be valid")
|
||||
Assert.AreEqual(1, root.GetBrokenRulesCollection.Count)
|
||||
'Assert.AreEqual("Name too long", root.GetBrokenRulesCollection.Item(0).Description)
|
||||
Assert.AreEqual("The value for Name is too long", root.GetBrokenRulesCollection.Item(0).Description)
|
||||
|
||||
root.Name = "1234567890"
|
||||
Assert.AreEqual(True, root.IsValid, "Should be valid")
|
||||
Assert.AreEqual(0, root.GetBrokenRulesCollection.Count)
|
||||
End Sub
|
||||
|
||||
<Test()> _
|
||||
Public Sub BreakLengthRuleAndClone()
|
||||
Session.Clear()
|
||||
Dim root As HasRulesManager = HasRulesManager.NewHasRulesManager
|
||||
root.Name = "12345678901"
|
||||
Assert.AreEqual(False, root.IsValid, "Should not be valid")
|
||||
Assert.AreEqual(1, root.GetBrokenRulesCollection.Count)
|
||||
'Assert.AreEqual("Name too long", root.GetBrokenRulesCollection.Item(0).Description)
|
||||
Assert.AreEqual("The value for Name is too long", root.GetBrokenRulesCollection.Item(0).Description)
|
||||
|
||||
root = DirectCast(root.Clone, HasRulesManager)
|
||||
Assert.AreEqual(False, root.IsValid, "Should not be valid")
|
||||
Assert.AreEqual(1, root.GetBrokenRulesCollection.Count)
|
||||
'Assert.AreEqual("Name too long", root.GetBrokenRulesCollection.Item(0).Description)
|
||||
Assert.AreEqual("The value for Name is too long", root.GetBrokenRulesCollection.Item(0).Description)
|
||||
|
||||
root.Name = "1234567890"
|
||||
Assert.AreEqual(True, root.IsValid, "Should be valid")
|
||||
Assert.AreEqual(0, root.GetBrokenRulesCollection.Count)
|
||||
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user