mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-12-25 17:35:48 +08:00
initial commit
This commit is contained in:
25
FreeSql.Tests.VB/FreeSql.Tests.VB.vbproj
Normal file
25
FreeSql.Tests.VB/FreeSql.Tests.VB.vbproj
Normal file
@@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<RootNamespace>FreeSql.Tests.VB</RootNamespace>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Extensions\FreeSql.Extensions.BaseEntity\FreeSql.Extensions.BaseEntity.csproj" />
|
||||
<ProjectReference Include="..\Extensions\FreeSql.Extensions.LazyLoading\FreeSql.Extensions.LazyLoading.csproj" />
|
||||
<ProjectReference Include="..\FreeSql.DbContext\FreeSql.DbContext.csproj" />
|
||||
<ProjectReference Include="..\Providers\FreeSql.Provider.SqlServer\FreeSql.Provider.SqlServer.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
193
FreeSql.Tests.VB/UnitTest1.vb
Normal file
193
FreeSql.Tests.VB/UnitTest1.vb
Normal file
@@ -0,0 +1,193 @@
|
||||
Imports System
|
||||
Imports FreeSql.DataAnnotations
|
||||
Imports Xunit
|
||||
|
||||
Namespace FreeSql.Tests.VB
|
||||
Public Class UnitTest1
|
||||
|
||||
<Fact>
|
||||
Sub IsNothing()
|
||||
Dim sql = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Id = 100 AndAlso a.Title Is Nothing).ToSql()
|
||||
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||
FROM [Testvb] a
|
||||
WHERE (a.[Id] = 100 AND a.[Title] IS NULL)", sql)
|
||||
|
||||
Dim lst = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Id = 100 AndAlso a.Title Is Nothing).ToList()
|
||||
End Sub
|
||||
|
||||
<Fact>
|
||||
Sub TestSub()
|
||||
|
||||
REM VB.net <20><><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD>
|
||||
Dim id As Integer = 100
|
||||
|
||||
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||
FROM [Testvb] a
|
||||
WHERE (a.[Id] = 100)", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Id = 100).ToSql())
|
||||
Dim List1 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Id = 100).ToList()
|
||||
|
||||
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||
FROM [Testvb] a
|
||||
WHERE (a.[Id] = 100)", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Id = id).ToSql())
|
||||
Dim List2 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Id = id).ToList()
|
||||
|
||||
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||
FROM [Testvb] a
|
||||
WHERE (a.[IdNullable] = 100)", g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = 100).ToSql())
|
||||
Dim List11 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = 100).ToList()
|
||||
|
||||
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||
FROM [Testvb] a
|
||||
WHERE (a.[IdNullable] = 100)", g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = id).ToSql())
|
||||
Dim List22 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = id).ToList()
|
||||
|
||||
Dim idNullable As Integer? = 100
|
||||
|
||||
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||
FROM [Testvb] a
|
||||
WHERE (a.[IdNullable] = 100)", g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = idNullable).ToSql())
|
||||
Dim List222 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.IdNullable = idNullable).ToList()
|
||||
|
||||
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||
FROM [Testvb] a
|
||||
WHERE (a.[Title] = N'xxx')", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = "xxx").ToSql())
|
||||
Dim List3 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = "xxx").ToList()
|
||||
|
||||
Dim title As String = "xxx"
|
||||
|
||||
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||
FROM [Testvb] a
|
||||
WHERE (a.[Title] = N'xxx')", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = title).ToSql())
|
||||
Dim List4 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = title).ToList()
|
||||
|
||||
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||
FROM [Testvb] a
|
||||
WHERE (a.[Title] <> N'xxx')", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title <> "xxx").ToSql())
|
||||
Dim List5 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title <> "xxx").ToList()
|
||||
|
||||
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||
FROM [Testvb] a
|
||||
WHERE (a.[Title] <> N'xxx')", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title <> title).ToSql())
|
||||
Dim List6 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title <> title).ToList()
|
||||
|
||||
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||
FROM [Testvb] a
|
||||
WHERE (a.[Title] = a.[Title])", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = a.Title).ToSql())
|
||||
Dim List7 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = a.Title).ToList()
|
||||
|
||||
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||
FROM [Testvb] a
|
||||
WHERE (a.[Title] <> a.[Title])", g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title <> a.Title).ToSql())
|
||||
Dim List71 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.Title = a.Title).ToList()
|
||||
|
||||
Assert.Equal("SELECT a.[Id] as1, a.[Title] as2, a.[IsDeleted] as3, a.[IdNullable] as4, a.[Id] as5, a.[Title] as6
|
||||
FROM [Testvb] a", g.sqlserver.Select(Of Testvb).ToSql(Function(a) New With {a, a.Id, a.Title}))
|
||||
Dim List8 = g.sqlserver.Select(Of Testvb).ToList(Function(a) New With {a, a.Id, a.Title})
|
||||
|
||||
Assert.Equal("SELECT a.[Id] as1, a.[Title] as2
|
||||
FROM [Testvb] a", g.sqlserver.Select(Of Testvb).ToSql(Function(a) New With {a.Id, a.Title}))
|
||||
Dim List81 = g.sqlserver.Select(Of Testvb).ToList(Function(a) New With {a.Id, a.Title})
|
||||
|
||||
Assert.Equal("SELECT a.[Id], a.[Title], a.[IsDeleted], a.[IdNullable]
|
||||
FROM [Testvb] a
|
||||
WHERE (a.[IsDeleted] = 1)", g.sqlserver.Select(Of Testvb).Where(Function(a) a.IsDeleted).ToSql())
|
||||
Dim List9 = g.sqlserver.Select(Of Testvb).Where(Function(a) a.IsDeleted).ToList()
|
||||
|
||||
REM Microsoft.VisualBasic.CompilerServices.Operators.CompareObjectEqual(
|
||||
|
||||
|
||||
|
||||
g.sqlserver.Delete(Of Testvb2).Where("1=1").ExecuteAffrows()
|
||||
g.sqlserver.Delete(Of Testvb).Where("1=1").ExecuteAffrows()
|
||||
g.sqlserver.Insert(New Testvb With {.Id = 1, .Title = "title1"}).ExecuteAffrows()
|
||||
g.sqlserver.Insert(New Testvb With {.Id = 2, .Title = "title2"}).ExecuteAffrows()
|
||||
g.sqlserver.Insert(New Testvb With {.Id = 3, .Title = "title3"}).ExecuteAffrows()
|
||||
g.sqlserver.Insert(New Testvb2 With {.Id = 1, .TestvbId = 1, .Context = "Context11"}).ExecuteAffrows()
|
||||
g.sqlserver.Insert(New Testvb2 With {.Id = 2, .TestvbId = 1, .Context = "Context12"}).ExecuteAffrows()
|
||||
g.sqlserver.Insert(New Testvb2 With {.Id = 3, .TestvbId = 1, .Context = "Context13"}).ExecuteAffrows()
|
||||
g.sqlserver.Insert(New Testvb2 With {.Id = 4, .TestvbId = 2, .Context = "Context21"}).ExecuteAffrows()
|
||||
g.sqlserver.Insert(New Testvb2 With {.Id = 5, .TestvbId = 2, .Context = "Context22"}).ExecuteAffrows()
|
||||
g.sqlserver.Insert(New Testvb2 With {.Id = 6, .TestvbId = 3, .Context = "Context31"}).ExecuteAffrows()
|
||||
|
||||
Dim List10 = g.sqlserver.Select(Of Testvb).IncludeMany(Function(a) a.Testvb2s).ToList()
|
||||
|
||||
BaseEntity.Initialization(g.sqlserver, Nothing)
|
||||
Dim cowR As CowRecord = New CowRecord
|
||||
cowR.Id = 1
|
||||
cowR.Lact = 1
|
||||
cowR.VetCount = 1
|
||||
cowR.Save()
|
||||
|
||||
cowR.VetCount += 1
|
||||
cowR.Update()
|
||||
|
||||
|
||||
|
||||
End Sub
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
Class Testvb
|
||||
Property Id As Integer
|
||||
Property Title As String
|
||||
Property IsDeleted As Boolean
|
||||
Property IdNullable As Integer?
|
||||
|
||||
Property Testvb2s As List(Of Testvb2)
|
||||
End Class
|
||||
|
||||
Class Testvb2
|
||||
Property Id As Integer
|
||||
Property TestvbId As Integer
|
||||
Property Testvb As Testvb
|
||||
Property Context As String
|
||||
End Class
|
||||
|
||||
<Index("uk_Primary", "Id,Lact", True)>
|
||||
Public Class CowRecord
|
||||
Inherits BaseEntity(Of CowRecord)
|
||||
Private _Id As Integer
|
||||
Private _Lact As Integer
|
||||
Private _Pen As Integer
|
||||
Private _BDAT As Date?
|
||||
Private _FDAT As Date?
|
||||
Private _DDAT As Date?
|
||||
Private _EDAT As Date?
|
||||
Private _ARDAT As Date?
|
||||
Private _MKDAT As Date?
|
||||
Private _BFDAT As Date?
|
||||
Private _USDAT As Date?
|
||||
Private _RC As Integer
|
||||
Private _DMLK1 As Integer
|
||||
Private _VetCount As Integer
|
||||
|
||||
<Column(IsPrimary:=True)>
|
||||
Public Property Id As Integer
|
||||
Get
|
||||
Return _Id
|
||||
End Get
|
||||
Set(value As Integer)
|
||||
_Id = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
|
||||
<Column(IsPrimary:=True)>
|
||||
Public Property Lact As Integer
|
||||
Get
|
||||
Return _Lact
|
||||
End Get
|
||||
Set(value As Integer)
|
||||
_Lact = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Property VetCount As Integer
|
||||
Get
|
||||
Return _VetCount
|
||||
End Get
|
||||
Set(value As Integer)
|
||||
_VetCount = value
|
||||
End Set
|
||||
End Property
|
||||
End Class
|
||||
18
FreeSql.Tests.VB/g.vb
Normal file
18
FreeSql.Tests.VB/g.vb
Normal file
@@ -0,0 +1,18 @@
|
||||
Imports System.Threading
|
||||
|
||||
Public Class g
|
||||
|
||||
Shared sqlserverLazy As Lazy(Of IFreeSql) = New Lazy(Of IFreeSql)(New Func(Of IFreeSql)(Function() New FreeSqlBuilder() _
|
||||
.UseConnectionString(DataType.SqlServer, "Data Source=.;Integrated Security=True;Initial Catalog=freesqlTest;Pooling=true;Max Pool Size=3;TrustServerCertificate=true") _
|
||||
.UseAutoSyncStructure(True) _
|
||||
.UseMonitorCommand(Sub(cmd) Trace.WriteLine(vbCrLf & "线程" & Thread.CurrentThread.ManagedThreadId & ": " & cmd.CommandText)) _
|
||||
.UseLazyLoading(True) _
|
||||
.Build()))
|
||||
|
||||
Public Shared ReadOnly Property sqlserver As IFreeSql
|
||||
Get
|
||||
Return sqlserverLazy.Value
|
||||
End Get
|
||||
End Property
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user