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

Commit 574be6c

Browse files
committed
Make some more tests work on Oracle
1 parent 401ae8c commit 574be6c

File tree

7 files changed

+28
-15
lines changed

7 files changed

+28
-15
lines changed

tests/ServiceStack.OrmLite.Tests/Expression/SqlExpressionTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ private void GetIdStats(IDbConnection db)
4949
letterFrequencySumId = db.Scalar<int>(db.From<LetterFrequency>().Select(Sql.Sum("Id")));
5050
}
5151

52-
public static void InitLetters(IDbConnection db)
52+
public static int InitLetters(IDbConnection db)
5353
{
5454
db.DropAndCreateTable<LetterFrequency>();
5555

56-
db.Insert(new LetterFrequency { Letter = "A" });
56+
var firstId = db.Insert(new LetterFrequency { Letter = "A" }, selectIdentity: true);
5757
db.Insert(new LetterFrequency { Letter = "B" });
5858
db.Insert(new LetterFrequency { Letter = "B" });
5959
db.Insert(new LetterFrequency { Letter = "C" });
@@ -63,14 +63,15 @@ public static void InitLetters(IDbConnection db)
6363
db.Insert(new LetterFrequency { Letter = "D" });
6464
db.Insert(new LetterFrequency { Letter = "D" });
6565
db.Insert(new LetterFrequency { Letter = "D" });
66+
return (int)firstId;
6667
}
6768

6869
[Test]
6970
public void Can_select_Dictionary_with_SqlExpression()
7071
{
7172
using (var db = OpenDbConnection())
7273
{
73-
InitLetters(db);
74+
var firstId = InitLetters(db);
7475
var expected = new Dictionary<string, int> {
7576
{ "A", 1 }, { "B", 2 }, { "C", 3 },
7677
};
@@ -103,7 +104,7 @@ public void Can_select_Dictionary_with_SqlExpression()
103104
.Select(x => new { x.Id });
104105

105106
var list = db.SqlList<int>(query);
106-
Assert.That(list, Is.EquivalentTo(new[] { 1, 2, 3, 4, 5, 6 }));
107+
Assert.That(list, Is.EquivalentTo(new[] { 0, 1, 2, 3, 4, 5 }.AdjustIds(firstId)));
107108
}
108109
}
109110

tests/ServiceStack.OrmLite.Tests/Issues/CustomTypeTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void Can_select_Guid()
3131
Guid = Guid.NewGuid()
3232
};
3333

34-
long id = db.Insert(dto);
34+
long id = db.Insert(dto, selectIdentity: true);
3535
var row = db.Single<PocoWithGuid>(r => r.Id == id);
3636

3737
Assert.That(row.Guid, Is.EqualTo(dto.Guid));

tests/ServiceStack.OrmLite.Tests/Issues/UtcDateTimeIssueTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ public void Can_Select_DateTime_with_SelectFmt()
6464
ExpiryDate = DateTime.UtcNow.AddHours(1)
6565
});
6666

67-
var result = db.Select<TestDate>("ExpiryDate".SqlColumn() + " > @date",
68-
new { date = DateTime.UtcNow });
67+
var result = db.Select<TestDate>("ExpiryDate".SqlColumn() + " > @theDate".PreNormalizeSql(db),
68+
new { theDate = DateTime.UtcNow });
6969
db.GetLastSql().Print();
7070
Assert.That(result.Count, Is.EqualTo(1));
7171

72-
result = db.Select<TestDate>("ExpiryDate".SqlColumn() + " > @date",
73-
new { date = new DateTime(1999, 01, 02) });
72+
result = db.Select<TestDate>("ExpiryDate".SqlColumn() + " > @theDate".PreNormalizeSql(db),
73+
new { theDate = new DateTime(1999, 01, 02) });
7474
db.GetLastSql().Print();
7575
Assert.That(result.Count, Is.EqualTo(2));
7676
}

tests/ServiceStack.OrmLite.Tests/LocalizationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class Point
3838
}
3939

4040
[Test]
41-
public void Can_query_using_float_in_alernate_culuture()
41+
public void Can_query_using_float_in_alernate_culture()
4242
{
4343
using (var db = OpenDbConnection())
4444
{
@@ -47,7 +47,7 @@ public void Can_query_using_float_in_alernate_culuture()
4747
db.Insert(new Point { Width = 4, Height = 1.123f, Top = 3.456d, Left = 2.345m });
4848
db.GetLastSql().Print();
4949

50-
var sql = "Height = @height".NormalizeSql();
50+
var sql = "Height = @height".PreNormalizeSql(db);
5151
var points = db.Select<Point>(sql, new { height = 1.123 });
5252
db.GetLastSql().Print();
5353

tests/ServiceStack.OrmLite.Tests/OrmLiteSelectTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void Can_select_with_filter_from_ModelWithOnlyStringFields_table()
102102

103103
db.Insert(filterRow);
104104

105-
var rows = db.Select<ModelWithOnlyStringFields>("AlbumName".SqlColumn() + " = @album", new { album = filterRow.AlbumName });
105+
var rows = db.Select<ModelWithOnlyStringFields>("AlbumName".SqlColumn() + " = @album".PreNormalizeSql(db), new { album = filterRow.AlbumName });
106106
var dbRowIds = rows.ConvertAll(x => x.Id);
107107

108108
Assert.That(dbRowIds, Has.Count.EqualTo(1));
@@ -187,7 +187,7 @@ public void Can_loop_each_with_filter_from_ModelWithOnlyStringFields_table()
187187
db.Insert(filterRow);
188188

189189
var dbRowIds = new List<string>();
190-
var rows = db.SelectLazy<ModelWithOnlyStringFields>("AlbumName".SqlColumn() + " = @AlbumName", new { filterRow.AlbumName });
190+
var rows = db.SelectLazy<ModelWithOnlyStringFields>("AlbumName".SqlColumn() + " = @AlbumName".PreNormalizeSql(db), new { filterRow.AlbumName });
191191
foreach (var row in rows)
192192
{
193193
dbRowIds.Add(row.Id);
@@ -331,7 +331,7 @@ public void Can_Select_In_for_string_value()
331331
var rows = db.Select<ModelWithIdAndName>("Name IN ({0})".Fmt(selectInNames.SqlInParams()),
332332
new { values = selectInNames.SqlInValues() });
333333
Assert.That(rows.Count, Is.EqualTo(selectInNames.Length));
334-
rows = db.Select<ModelWithIdAndName>("Name IN (@p1, @p2)", new { p1 = "Name1", p2 = "Name2" });
334+
rows = db.Select<ModelWithIdAndName>("Name IN (@p1, @p2)".PreNormalizeSql(db), new { p1 = "Name1", p2 = "Name2" });
335335
Assert.That(rows.Count, Is.EqualTo(selectInNames.Length));
336336
}
337337
}

tests/ServiceStack.OrmLite.Tests/StringSerializerTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ public void Can_use_XmlSerializer_StringSerializer()
151151
InsertModelWithComplexType(db);
152152

153153
var str = db.SqlScalar<string>(TestSql);
154-
Assert.That(str, Is.EqualTo("<?xml version=\"1.0\" encoding=\"utf-8\"?><ComplexType xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Id>2</Id><SubType><Name>Sub</Name></SubType></ComplexType>"));
154+
Assert.That(str, Contains.Substring("<?xml version=\"1.0\" encoding=\"utf-8\"?><ComplexType "));
155+
Assert.That(str, Contains.Substring("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""));
156+
Assert.That(str, Contains.Substring("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""));
157+
Assert.That(str, Contains.Substring("<Id>2</Id><SubType><Name>Sub</Name></SubType></ComplexType>"));
155158

156159
var data = db.SingleById<ModelWithComplexType>(1);
157160
Assert.That(data.ComplexType.SubType.Name, Is.EqualTo("Sub"));

tests/ServiceStack.OrmLite.Tests/TestHelpers.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Collections.Generic;
12
using System.Data;
23

34
namespace ServiceStack.OrmLite.Tests
@@ -35,5 +36,13 @@ public static string PreNormalizeSql(this string sql, IDbConnection db)
3536
return sql;
3637
return sql.Replace("@", paramString);
3738
}
39+
40+
public static List<int> AdjustIds(this IEnumerable<int> ids, int initialId)
41+
{
42+
var result = new List<int>();
43+
foreach (var id in ids)
44+
result.Add(id + initialId);
45+
return result;
46+
}
3847
}
3948
}

0 commit comments

Comments
 (0)