Skip to content

Commit

Permalink
unit test for checking number of sessions and number of requests
Browse files Browse the repository at this point in the history
  • Loading branch information
DejanMilicic committed May 15, 2021
1 parent 0df6a08 commit bf4d7bc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Digitalis/Digitalis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.3" />
<PackageReference Include="NSwag.AspNetCore" Version="13.10.2" />
<PackageReference Include="NUlid" Version="1.5.0" />
<PackageReference Include="RavenDB.Client" Version="5.1.4" />
<PackageReference Include="RavenDB.Client" Version="5.2.0-nightly-20210515-0721" />
<PackageReference Include="Scrutor" Version="3.3.0" />
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
<PackageReference Include="Serilog.Sinks.RavenDB" Version="3.0.0" />
Expand Down
14 changes: 13 additions & 1 deletion src/Specs/Features/AddNewEntry/HappyPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public HappyPath()
};

using var session = Store.OpenSession();
session.Store(user );
session.Store(user);
session.SaveChanges();

var client = AuthClient(new Dictionary<string, string>
Expand Down Expand Up @@ -114,5 +114,17 @@ public void EmailBodyContainsAllTags()
.MustHaveHappenedOnceExactly();
}
}

[Fact(DisplayName = "8. Expected number of sessions and requests")]
public void NumberOfSessionsAndRequests()
{
SessionsRecorded.Count.Should().Be(3); // three sessions opened

var requests = SessionsRecorded.Values.Select(x => x).ToList();

requests[0].Should().Be(1); // authorization of request
requests[1].Should().Be(1); // operation
requests[2].Should().Be(1); // logging
}
}
}
17 changes: 17 additions & 0 deletions src/Specs/Infrastructure/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class Fixture : RavenTestDriver, IClassFixture<WebApplicationFactory<Star
protected readonly IDocumentStore Store;
protected readonly IMailer Mailer;
protected readonly TestServer TestServer;
protected Dictionary<string, int> SessionsRecorded;

static Fixture()
{
Expand All @@ -49,6 +50,22 @@ public Fixture()
Store = this.GetDocumentStore();
IndexCreation.CreateIndexes(typeof(Startup).Assembly, Store);

var session = Store.OpenSession();

SessionsRecorded = new Dictionary<string, int>();

Store.OnSessionDisposing += (sender, args) =>
{
string sessionId = args.Session.Id.ToString();

if (SessionsRecorded.ContainsKey(sessionId))
SessionsRecorded[sessionId] = args.Session.NumberOfRequests;
else
SessionsRecorded.Add(sessionId, args.Session.NumberOfRequests);
};

SessionsRecorded = new Dictionary<string, int>();

TestServer = SetupHost().GetTestServer();
}

Expand Down
3 changes: 2 additions & 1 deletion src/nuget.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="RavenDB MyGet" value="https://www.myget.org/F/ravendb/api/v3/index.json" />
</packageSources>
</configuration>

0 comments on commit bf4d7bc

Please sign in to comment.