Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 8ad8ec2

Browse files
committed
Moved OrmLite.SqlServer table option unit tests to TableOptionAttributes folder.
Moved OrmLite.SqlServer table option unit tests to TableOptionAttributes folder.
1 parent 5b98f88 commit 8ad8ec2

File tree

5 files changed

+251
-122
lines changed

5 files changed

+251
-122
lines changed

src/ServiceStack.OrmLite.SqlServerTests/MemoryOptimizedAttributeTests.cs

Lines changed: 0 additions & 76 deletions
This file was deleted.

src/ServiceStack.OrmLite.SqlServerTests/ServiceStack.OrmLite.SqlServerTests.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
<Compile Include="..\GlobalAssemblyInfo.cs">
8181
<Link>Properties\GlobalAssemblyInfo.cs</Link>
8282
</Compile>
83-
<Compile Include="Converters\FileStreamTests.cs" />
83+
<Compile Include="TableOptionAttributes\TableOptionsOrmLiteTestBase.cs" />
84+
<Compile Include="TableOptionAttributes\FileStreamTests.cs" />
8485
<Compile Include="Converters\SqlGeometryTests.cs" />
8586
<Compile Include="CustomSqlTests.cs" />
8687
<Compile Include="Datetime2Tests.cs" />
@@ -91,7 +92,7 @@
9192
<Compile Include="Issues\DeleteWithGeoTypesIssue.cs" />
9293
<Compile Include="Issues\JamesGeoIssue.cs" />
9394
<Compile Include="Issues\SerializationTests.cs" />
94-
<Compile Include="MemoryOptimizedAttributeTests.cs" />
95+
<Compile Include="TableOptionAttributes\MemoryOptimizedAttributeTests.cs" />
9596
<Compile Include="NestedTransactions.cs" />
9697
<Compile Include="EnumTests.cs" />
9798
<Compile Include="Expressions\AdditiveExpressionsTest.cs" />

src/ServiceStack.OrmLite.SqlServerTests/Converters/FileStreamTests.cs renamed to src/ServiceStack.OrmLite.SqlServerTests/TableOptionAttributes/FileStreamTests.cs

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,48 @@
22
using Microsoft.SqlServer.Types;
33
using NUnit.Framework;
44
using ServiceStack.DataAnnotations;
5-
using ServiceStack.OrmLite.SqlServer.Converters;
6-
using ServiceStack.Text;
75

8-
namespace ServiceStack.OrmLite.SqlServerTests.Converters
6+
namespace ServiceStack.OrmLite.SqlServerTests.TableOptions
97
{
108
[TestFixture]
11-
public class FileStreamTests : SqlServer2012ConvertersOrmLiteTestBase
9+
public class FileTableAttributeTests : SqlServer2012TableOptionsOrmLiteTestBase
1210
{
1311
[Explicit("Requires FileGroups enabled in DB")]
1412
[Test]
15-
public void Can_select_from_FileStream()
13+
public void Can_select_from_FileTable()
1614
{
15+
Db.DropAndCreateTable<FileTable>();
1716

18-
ConnectionString = "Data Source=localhost;Initial Catalog=test2;User Id=test;Password=test;Connect Timeout=120;MultipleActiveResultSets=True;Type System Version=SQL Server 2012;";
19-
var dialectProvider = SqlServerConverters.Configure(SqlServer2012Dialect.Provider);
20-
var dbFactory = new OrmLiteConnectionFactory(ConnectionString, dialectProvider);
21-
22-
using (var db = dbFactory.OpenDbConnection())
17+
var ft = new FileTable
2318
{
24-
db.DropTable<TestFile>();
25-
db.CreateTable<TestFile>();
26-
27-
db.Insert(new TestFile { Contents = "contents".ToUtf8Bytes() });
28-
29-
db.Select<TestFile>().PrintDump();
30-
31-
//db.DropTable<FileStream>();
32-
//db.CreateTable<FileStream>();
19+
Name = "content.txt",
20+
Path = SqlHierarchyId.Parse("/1/"),
21+
FileContent = "contents".ToUtf8Bytes(),
22+
FileType = MimeTypes.PlainText
23+
};
24+
Db.Insert(ft);
3325

34-
//db.Insert(new FileStream
35-
//{
36-
// Name = "file.txt",
37-
// Path = SqlHierarchyId.Parse("/1/2/3/"),
38-
// ParentPath = SqlHierarchyId.Parse("/1/2/"),
39-
// FileContent = "contents".ToUtf8Bytes(),
40-
// FileType = MimeTypes.PlainText,
41-
//});
26+
var fileTable = Db.Single<FileTable>(x => x.Name == "content.txt");
4227

43-
//var q = db.From<FileStream>();
44-
//db.Select(q);
45-
}
28+
Assert.IsNotNull(fileTable);
29+
Assert.IsTrue(ft.FileContent.EquivalentTo(fileTable.FileContent));
4630
}
4731
}
4832

49-
public class TestFile
33+
34+
public class FileWithCustomSelect : FileTable
5035
{
51-
[PrimaryKey]
52-
[CustomField("uniqueidentifier ROWGUIDCOL NOT NULL")]
53-
public Guid Id { get; set; }
54-
55-
[CustomField("varbinary(max) FILESTREAM")]
56-
public byte[] Contents { get; set; }
57-
58-
public bool IsDirectory { get; set; }
59-
6036
[CustomSelect("Contents.GetFileNamespacePath() + (CASE WHEN is_directory = 1 THEN '\' ELSE '' END)")]
6137
public string FullPath { get; set; }
6238
}
6339

64-
public class FileStream
40+
[SqlServerFileTable(directory: "FILESTREAM_DIR")]
41+
public class FileTable
6542
{
6643
[PrimaryKey]
6744
[CustomField("uniqueidentifier ROWGUIDCOL NOT NULL")]
45+
[Default("newuid()")]
46+
[Alias("stream_id")]
6847
public Guid Id { get; set; }
6948

7049
[CustomField("varbinary(max) FILESTREAM")]
@@ -81,6 +60,7 @@ public class FileStream
8160

8261
//[ForeignKey(typeof(FileStream))]
8362
[Alias("parent_path_locator")]
63+
[Compute]
8464
public SqlHierarchyId? ParentPath { get; set; }
8565

8666
[Alias("file_type")]
@@ -121,8 +101,5 @@ public class FileStream
121101

122102
[Alias("is_temporary")]
123103
public bool IsTemporary { get; set; }
124-
125-
[CustomSelect("file_stream.GetFileNamespacePath() + (CASE WHEN is_directory = 1 THEN '\' ELSE '' END)")]
126-
public string FullPath { get; set; }
127104
}
128105
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
using System;
2+
using System.Data.SqlClient;
3+
using NUnit.Framework;
4+
using ServiceStack.DataAnnotations;
5+
6+
namespace ServiceStack.OrmLite.SqlServerTests.TableOptions
7+
{
8+
[TestFixture]
9+
public class SqlServer2014MemoryOptimizedAttributeTests : SqlServer2014TableOptionsOrmLiteTestBase
10+
{
11+
[TestFixtureSetUp]
12+
public void Setup()
13+
{
14+
base.TestFixtureSetUp();
15+
16+
if (Db.TableExists<TypeWithMemTableNoDurability>())
17+
Db.DropTable<TypeWithMemTableNoDurability>();
18+
19+
if (Db.TableExists<TypeWithMemTableSchemaOnlyDurability>())
20+
Db.DropTable<TypeWithMemTableSchemaOnlyDurability>();
21+
22+
if (Db.TableExists<TypeWithMemTableSchemaAndDataDurability>())
23+
Db.DropTable<TypeWithMemTableSchemaAndDataDurability>();
24+
25+
if (Db.TableExists<TypeWithMemTableWithCollatedHashIndex>())
26+
Db.DropTable<TypeWithMemTableWithCollatedHashIndex>();
27+
}
28+
29+
[Test]
30+
public void Can_Create_Memory_Optimized_Table()
31+
{
32+
Db.CreateTable<TypeWithMemTableNoDurability>(true);
33+
34+
var sql = Db.GetLastSql();
35+
36+
Assert.IsTrue(sql.Contains("MEMORY_OPTIMIZED = ON"));
37+
Assert.IsFalse(sql.Contains("DURABILITY = SCHEMA_ONLY"));
38+
Assert.IsFalse(sql.Contains("DURABILITY = SCHEMA_AND_DATA"));
39+
40+
var name = "Test 1";
41+
var id = Db.Insert(new TypeWithMemTableNoDurability { Name = name }, selectIdentity: true);
42+
var fromDb = Db.SingleById<TypeWithMemTableNoDurability>(id);
43+
44+
Assert.AreEqual(name, fromDb.Name);
45+
}
46+
47+
[Test]
48+
public void Can_Create_Memory_Optimized_Table_With_Schema_Only_Durability()
49+
{
50+
Db.CreateTable<TypeWithMemTableSchemaOnlyDurability>(true);
51+
52+
var sql = Db.GetLastSql();
53+
54+
Assert.IsTrue(sql.Contains("MEMORY_OPTIMIZED = ON"));
55+
Assert.IsTrue(sql.Contains("DURABILITY = SCHEMA_ONLY"));
56+
Assert.IsFalse(sql.Contains("DURABILITY = SCHEMA_AND_DATA"));
57+
58+
var name = "Test 2";
59+
var id = Db.Insert(new TypeWithMemTableSchemaOnlyDurability { Name = name }, selectIdentity: true);
60+
var fromDb = Db.SingleById<TypeWithMemTableSchemaOnlyDurability>(id);
61+
62+
Assert.AreEqual(name, fromDb.Name);
63+
}
64+
65+
[Test]
66+
public void Can_Create_Memory_Optimized_Table_With_Schema_And_Data_Durability()
67+
{
68+
Db.CreateTable<TypeWithMemTableSchemaAndDataDurability>(true);
69+
70+
var sql = Db.GetLastSql();
71+
72+
Assert.IsTrue(sql.Contains("MEMORY_OPTIMIZED = ON"));
73+
Assert.IsFalse(sql.Contains("DURABILITY = SCHEMA_ONLY"));
74+
Assert.IsTrue(sql.Contains("DURABILITY = SCHEMA_AND_DATA"));
75+
76+
var name = "Test 3";
77+
var id = Db.Insert(new TypeWithMemTableSchemaAndDataDurability { Name = name }, selectIdentity: true);
78+
var fromDb = Db.SingleById<TypeWithMemTableSchemaAndDataDurability>(id);
79+
80+
Assert.AreEqual(name, fromDb.Name);
81+
}
82+
83+
[Test]
84+
public void Can_not_Create_Memory_Optimized_Table_Without_BIN2_Collate_Hash_Index()
85+
{
86+
try
87+
{
88+
Db.CreateTable<TypeWithMemTableWithoutBIN2HashIndex>(true);
89+
}
90+
catch (Exception ex)
91+
{
92+
Assert.IsInstanceOf<SqlException>(ex);
93+
}
94+
}
95+
96+
[Test]
97+
public void Can_Create_Memory_Optimized_Table_With_Collated_Hash_Index()
98+
{
99+
var name = "Test 5";
100+
var index = "Test Index";
101+
102+
Db.CreateTable<TypeWithMemTableWithCollatedHashIndex>(true);
103+
104+
var sql = Db.GetLastSql();
105+
106+
Assert.IsTrue(sql.Contains("MEMORY_OPTIMIZED = ON"));
107+
Assert.IsTrue(sql.Contains("COLLATE"));
108+
109+
var id = Db.Insert(new TypeWithMemTableWithCollatedHashIndex {Name = name, Index = index }, selectIdentity: true);
110+
var fromDb = Db.SingleById<TypeWithMemTableWithCollatedHashIndex>(id);
111+
112+
Assert.AreEqual(name, fromDb.Name);
113+
Assert.AreEqual(index, fromDb.Index);
114+
}
115+
}
116+
117+
public class TypeWithNoMemOptimization
118+
{
119+
[PrimaryKey]
120+
public int Id { get; set; }
121+
122+
public string Name { get; set; }
123+
}
124+
125+
[SqlServerMemoryOptimized]
126+
public class TypeWithMemTableNoDurability : TypeWithNoMemOptimization { }
127+
128+
[SqlServerMemoryOptimized(SqlServerDurability.SchemaOnly)]
129+
public class TypeWithMemTableSchemaOnlyDurability : TypeWithNoMemOptimization { }
130+
131+
[SqlServerMemoryOptimized(SqlServerDurability.SchemaAndData)]
132+
public class TypeWithMemTableSchemaAndDataDurability : TypeWithNoMemOptimization { }
133+
134+
[SqlServerMemoryOptimized]
135+
public class TypeWithMemTableWithoutBIN2HashIndex : TypeWithNoMemOptimization
136+
{
137+
[StringLength(25)]
138+
[SqlServerBucketCount(1000)]
139+
public string Index { get; set; }
140+
}
141+
142+
[SqlServerMemoryOptimized]
143+
public class TypeWithMemTableWithCollatedHashIndex : TypeWithNoMemOptimization
144+
{
145+
[StringLength(25)]
146+
[SqlServerCollate("Latin1_General_100_BIN2")]
147+
[SqlServerBucketCount(1000)]
148+
public string Index { get; set; }
149+
}
150+
}

0 commit comments

Comments
 (0)