From bf4d7bc330b5d1db8d849ffebabf2bbccf822094 Mon Sep 17 00:00:00 2001 From: Dejan Milicic Date: Sat, 15 May 2021 16:49:06 +0200 Subject: [PATCH] unit test for checking number of sessions and number of requests --- src/Digitalis/Digitalis.csproj | 2 +- src/Specs/Features/AddNewEntry/HappyPath.cs | 14 +++++++++++++- src/Specs/Infrastructure/Fixture.cs | 17 +++++++++++++++++ src/nuget.config | 3 ++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/Digitalis/Digitalis.csproj b/src/Digitalis/Digitalis.csproj index b488541..238481c 100644 --- a/src/Digitalis/Digitalis.csproj +++ b/src/Digitalis/Digitalis.csproj @@ -16,7 +16,7 @@ - + diff --git a/src/Specs/Features/AddNewEntry/HappyPath.cs b/src/Specs/Features/AddNewEntry/HappyPath.cs index 2fb6907..d430119 100644 --- a/src/Specs/Features/AddNewEntry/HappyPath.cs +++ b/src/Specs/Features/AddNewEntry/HappyPath.cs @@ -29,7 +29,7 @@ public HappyPath() }; using var session = Store.OpenSession(); - session.Store(user ); + session.Store(user); session.SaveChanges(); var client = AuthClient(new Dictionary @@ -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 + } } } diff --git a/src/Specs/Infrastructure/Fixture.cs b/src/Specs/Infrastructure/Fixture.cs index 2b71106..aa0b7bf 100644 --- a/src/Specs/Infrastructure/Fixture.cs +++ b/src/Specs/Infrastructure/Fixture.cs @@ -31,6 +31,7 @@ public class Fixture : RavenTestDriver, IClassFixture SessionsRecorded; static Fixture() { @@ -49,6 +50,22 @@ public Fixture() Store = this.GetDocumentStore(); IndexCreation.CreateIndexes(typeof(Startup).Assembly, Store); + var session = Store.OpenSession(); + + SessionsRecorded = new Dictionary(); + + 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(); + TestServer = SetupHost().GetTestServer(); } diff --git a/src/nuget.config b/src/nuget.config index 784461c..bc14c4d 100644 --- a/src/nuget.config +++ b/src/nuget.config @@ -1,8 +1,9 @@ - + + \ No newline at end of file