GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Refactor StackOverflowTasks · ServiceStackApps/StackApis@2bc23ae

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • StackApis.Tests
      • StackApis.Tests.csproj
      • StackOverflowTasks.cs
    • StackApis/App_Data
      • db.sqlite
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/StackApis.Tests/StackApis.Tests.csproj‎

Copy file name to clipboardExpand all lines: src/StackApis.Tests/StackApis.Tests.csproj
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
</Reference>
9797
</ItemGroup>
9898
<ItemGroup>
99-
<Compile Include="UnitTests.cs" />
99+
<Compile Include="StackOverflowTasks.cs" />
100100
<Compile Include="Properties\AssemblyInfo.cs" />
101101
</ItemGroup>
102102
<ItemGroup>
Collapse file

‎src/StackApis.Tests/UnitTests.cs‎ ‎src/StackApis.Tests/StackOverflowTasks.cs‎src/StackApis.Tests/UnitTests.cs renamed to src/StackApis.Tests/StackOverflowTasks.cs

Copy file name to clipboardExpand all lines: src/StackApis.Tests/StackOverflowTasks.cs
+36-56Lines changed: 36 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,67 +6,29 @@
66
using ServiceStack;
77
using ServiceStack.Data;
88
using ServiceStack.OrmLite;
9-
using ServiceStack.Testing;
109
using ServiceStack.Text;
11-
using StackApis.ServiceInterface;
1210
using StackApis.ServiceModel;
1311
using StackApis.ServiceModel.Types;
1412

1513
namespace StackApis.Tests
1614
{
1715
[TestFixture]
18-
public class UnitTests
16+
public class StackOverflowTasks
1917
{
20-
private readonly ServiceStackHost appHost;
18+
private IDbConnectionFactory dbFactory;
2119

22-
public UnitTests()
20+
[OneTimeSetUp]
21+
public void OneTimeSetUp()
2322
{
24-
appHost = new BasicAppHost(typeof(MyServices).Assembly)
25-
{
26-
ConfigureContainer = container =>
27-
{
28-
//Add your IoC dependencies here
29-
container.Register<IDbConnectionFactory>(
30-
new OrmLiteConnectionFactory(
31-
"~/../../../StackApis/App_Data/db.sqlite".MapServerPath(),
32-
SqliteDialect.Provider));
33-
34-
using (var db = container.Resolve<IDbConnectionFactory>().OpenDbConnection())
35-
{
36-
db.DropAndCreateTable<Question>();
37-
db.DropAndCreateTable<Answer>();
38-
db.DropAndCreateTable<QuestionTag>();
39-
}
40-
41-
SeedStackOverflowData(container.Resolve<IDbConnectionFactory>());
42-
}
43-
}
44-
.Init();
45-
}
46-
47-
[TestFixtureTearDown]
48-
public void TestFixtureTearDown()
49-
{
50-
appHost.Dispose();
23+
dbFactory = new OrmLiteConnectionFactory(
24+
"~/../../../StackApis/App_Data/db.sqlite".MapServerPath(), SqliteDialect.Provider);
5125
}
5226

5327
[Test]
54-
public void TestImport()
55-
{
56-
var dbConnectionFactory = appHost.TryResolve<IDbConnectionFactory>();
57-
using (var db = dbConnectionFactory.OpenDbConnection())
58-
{
59-
var numberOfQuestions = db.Count<Question>();
60-
var numberOfAnswers = db.Count<Answer>();
61-
Assert.That(numberOfQuestions > 0);
62-
Assert.That(numberOfAnswers > 0);
63-
}
64-
}
65-
66-
private void SeedStackOverflowData(IDbConnectionFactory dbConnectionFactory)
28+
public void Import_from_StackOverflow()
6729
{
6830
var client = new JsonServiceClient();
69-
int numberOfPages = 80;
31+
int numberOfPages = 10;
7032
int pageSize = 100;
7133
var dbQuestions = new List<Question>();
7234
var dbAnswers = new List<Answer>();
@@ -76,9 +38,8 @@ private void SeedStackOverflowData(IDbConnectionFactory dbConnectionFactory)
7638
{
7739
//Throttle queries
7840
Thread.Sleep(100);
79-
var questionsResponse =
80-
client.Get("https://api.stackexchange.com/2.2/questions?page={0}&pagesize={1}&site={2}&tagged=servicestack"
81-
.Fmt(i, pageSize, "stackoverflow"));
41+
var questionsResponse = client.Get("https://api.stackexchange.com/2.2/questions?page={0}&pagesize={1}&site={2}&tagged=servicestack"
42+
.Fmt(i, pageSize, "stackoverflow"));
8243

8344
QuestionsResponse qResponse;
8445
using (new ConfigScope())
@@ -107,6 +68,7 @@ private void SeedStackOverflowData(IDbConnectionFactory dbConnectionFactory)
10768
catch (Exception ex)
10869
{
10970
//ignore
71+
ex.Message.Print();
11072
}
11173

11274
//Filter duplicates
@@ -115,26 +77,43 @@ private void SeedStackOverflowData(IDbConnectionFactory dbConnectionFactory)
11577
var questionTags = dbQuestions.SelectMany(q =>
11678
q.Tags.Select(t => new QuestionTag { QuestionId = q.QuestionId, Tag = t }));
11779

118-
using (var db = dbConnectionFactory.OpenDbConnection())
80+
using (var db = dbFactory.OpenDbConnection())
11981
{
82+
db.DropAndCreateTable<Question>();
83+
db.DropAndCreateTable<Answer>();
84+
db.DropAndCreateTable<QuestionTag>();
85+
12086
db.InsertAll(dbQuestions);
12187
db.InsertAll(dbAnswers);
12288
db.InsertAll(questionTags);
12389
}
12490
}
91+
92+
[Test]
93+
public void Test_Import()
94+
{
95+
using (var db = dbFactory.OpenDbConnection())
96+
{
97+
var numberOfQuestions = db.Count<Question>();
98+
var numberOfAnswers = db.Count<Answer>();
99+
Assert.That(numberOfQuestions > 0);
100+
Assert.That(numberOfAnswers > 0);
101+
}
102+
}
125103
}
126104

127105
public class ConfigScope : IDisposable
128106
{
129107
private readonly WriteComplexTypeDelegate holdQsStrategy;
130-
private readonly JsConfigScope jsConfigScope;
108+
private readonly JsConfigScope scope;
131109

132110
public ConfigScope()
133111
{
134-
jsConfigScope = JsConfig.With(dateHandler: DateHandler.UnixTime,
135-
propertyConvention: PropertyConvention.Lenient,
136-
emitLowercaseUnderscoreNames: true,
137-
emitCamelCaseNames: false);
112+
scope = JsConfig.With(
113+
dateHandler: DateHandler.UnixTime,
114+
propertyConvention: PropertyConvention.Lenient,
115+
emitLowercaseUnderscoreNames: true,
116+
emitCamelCaseNames: false);
138117

139118
holdQsStrategy = QueryStringSerializer.ComplexTypeStrategy;
140119
QueryStringSerializer.ComplexTypeStrategy = QueryStringStrategy.FormUrlEncoded;
@@ -143,7 +122,8 @@ public ConfigScope()
143122
public void Dispose()
144123
{
145124
QueryStringSerializer.ComplexTypeStrategy = holdQsStrategy;
146-
jsConfigScope.Dispose();
125+
scope.Dispose();
147126
}
148127
}
128+
149129
}
Collapse file

‎src/StackApis/App_Data/db.sqlite‎

Copy file name to clipboard
0 Bytes
Binary file not shown.

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.