Skip to content

Commit

Permalink
Adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-stuart-cross committed Jan 23, 2024
1 parent 4498099 commit b31c8c0
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 13 deletions.
18 changes: 17 additions & 1 deletion Birder.Tests/Controller/Account/GetConfirmEmailAsync_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public async Task ConfirmEmailAsync_Returns_400_When_Username_Argument_Is_Not_Va
// Assert
var objectResult = Assert.IsType<StatusCodeResult>(result);
Assert.Equal(StatusCodes.Status400BadRequest, objectResult.StatusCode);

logger.Verify(x => x.Log(
It.Is<LogLevel>(l => l == LogLevel.Error),
It.IsAny<EventId>(),
It.Is<It.IsAnyType>((o, t) => string.Equals($"action argument invalid: username", o.ToString(), StringComparison.InvariantCultureIgnoreCase)),
It.IsAny<Exception>(),
It.IsAny<Func<It.IsAnyType, Exception, string>>()),
Times.Once);
}

[Theory, MemberData(nameof(Null_Empty_Whitespace_String_Test_Data))]
Expand All @@ -41,6 +49,14 @@ public async Task ConfirmEmailAsync_Returns_400_When_Code_Argument_Is_Not_Valid(
// Assert
var objectResult = Assert.IsType<StatusCodeResult>(result);
Assert.Equal(StatusCodes.Status400BadRequest, objectResult.StatusCode);

logger.Verify(x => x.Log(
It.Is<LogLevel>(l => l == LogLevel.Error),
It.IsAny<EventId>(),
It.Is<It.IsAnyType>((o, t) => string.Equals($"action argument invalid: code", o.ToString(), StringComparison.InvariantCultureIgnoreCase)),
It.IsAny<Exception>(),
It.IsAny<Func<It.IsAnyType, Exception, string>>()),
Times.Once);
}

[Fact]
Expand Down Expand Up @@ -175,7 +191,7 @@ public static IEnumerable<object[]> Null_Empty_Whitespace_String_Test_Data
new object[] { "" },
new object[] { string.Empty },
new object[] { " " },
new object[] { " " },
// new object[] { " " },
new object[] { " " }
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ public async Task Returns_OkResult_With_Network_Records()
var options = this.CreateUniqueMethodOptions<ApplicationDbContext>();

using var context = new ApplicationDbContext(options);
context.Database.EnsureClean();
// context.Database.EnsureClean();
//temporary increase timeout only for one Context instance.
context.Database.SetCommandTimeout(TimeSpan.FromMinutes(1));
// //context.Database.SetCommandTimeout(TimeSpan.FromMinutes(1));

context.Database.EnsureClean();

context.Users.Add(SharedFunctions.CreateUser("testUser1"));
context.Users.Add(SharedFunctions.CreateUser("testUser2"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ public async Task GetUserWithNetworkAsync_ReturnsUser_WithNetwork()
// when handling Network object, need to use sql database not sqlite in-memory
var options = this.CreateUniqueMethodOptions<ApplicationDbContext>();
using var context = new ApplicationDbContext(options);

context.Database.EnsureClean();

context.Database.SetCommandTimeout(TimeSpan.FromMinutes(1));
// //context.Database.SetCommandTimeout(TimeSpan.FromMinutes(1));

context.Users.Add(SharedFunctions.CreateUser(usernameToAct));
context.Users.Add(SharedFunctions.CreateUser(usernameToFollow));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task GetUsersAsync_FollowersNotFollowedEmptyCollectionArgument_Retu

context.Database.EnsureCreated();
//temporary increase timeout only for one Context instance.
context.Database.SetCommandTimeout(TimeSpan.FromMinutes(1));
//context.Database.SetCommandTimeout(TimeSpan.FromMinutes(1));
// Arrange
string requestingUsername = "TestUser1";
string usernameToFollow = "TestUser2";
Expand Down Expand Up @@ -54,7 +54,7 @@ public async Task GetUsersAsync_OneFollowerNotFollowed_ReturnsOneUser()
using var context = new ApplicationDbContext(options);
context.Database.EnsureClean();
//temporary increase timeout only for one Context instance.
context.Database.SetCommandTimeout(TimeSpan.FromMinutes(1));
//context.Database.SetCommandTimeout(TimeSpan.FromMinutes(1));

context.Users.Add(SharedFunctions.CreateUser(requestingUsername));
context.Users.Add(SharedFunctions.CreateUser(followerUsername));
Expand Down Expand Up @@ -106,7 +106,7 @@ public async Task GetUsersAsync_OneSuggestedUserToFollow_ReturnsUser()
using var context = new ApplicationDbContext(options);
context.Database.EnsureCreated();
//temporary increase timeout only for one Context instance.
context.Database.SetCommandTimeout(TimeSpan.FromMinutes(1));
//context.Database.SetCommandTimeout(TimeSpan.FromMinutes(1));

context.Users.Add(SharedFunctions.CreateUser(requestingUsername));
context.Users.Add(SharedFunctions.CreateUser(usernameToFollow));
Expand Down Expand Up @@ -136,7 +136,7 @@ public async Task GetUsersAsync_NoSuggestedUserToFollow_ReturnsNoUser()
using var context = new ApplicationDbContext(options);
context.Database.EnsureCreated();
//temporary increase timeout only for one Context instance.
context.Database.SetCommandTimeout(TimeSpan.FromMinutes(1));
//context.Database.SetCommandTimeout(TimeSpan.FromMinutes(1));

context.Users.Add(SharedFunctions.CreateUser(requestingUsername));
context.Users.Add(SharedFunctions.CreateUser(usernameToFollow));
Expand Down Expand Up @@ -179,7 +179,7 @@ public async Task GetUsersAsync_SearchCriterion_ReturnsOneUser(string searchCrit
using var context = new ApplicationDbContext(options);
context.Database.EnsureCreated();
//temporary increase timeout only for one Context instance.
context.Database.SetCommandTimeout(TimeSpan.FromMinutes(1));
//context.Database.SetCommandTimeout(TimeSpan.FromMinutes(1));

context.Users.Add(SharedFunctions.CreateUser(requestingUsername));
context.Users.Add(SharedFunctions.CreateUser(usernameToFollow));
Expand Down Expand Up @@ -211,7 +211,7 @@ public async Task GetUsersAsync_SearchCriterion_ReturnsNoUser(string searchCrite
using var context = new ApplicationDbContext(options);
context.Database.EnsureCreated();
//temporary increase timeout only for one Context instance.
context.Database.SetCommandTimeout(TimeSpan.FromMinutes(1));
//context.Database.SetCommandTimeout(TimeSpan.FromMinutes(1));

context.Users.Add(SharedFunctions.CreateUser(requestingUsername));
context.Users.Add(SharedFunctions.CreateUser(usernameToFollow));
Expand Down
2 changes: 1 addition & 1 deletion Birder.Tests/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"UnitTestConnection": "Server=(localdb)\\mssqllocaldb;Database=EfCore.TestSupport-Test;Trusted_Connection=True;MultipleActiveResultSets=true;Connection Timeout=500"
"UnitTestConnection": "Server=(localdb)\\mssqllocaldb;Database=EfCore.TestSupport-Test;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"LogLevel": {
Expand Down
2 changes: 1 addition & 1 deletion Birder.Tests/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"UnitTestConnection": "Server=(localdb)\\mssqllocaldb;Database=EfCore.TestSupport-Test;Trusted_Connection=True;MultipleActiveResultSets=true;Connection Timeout=500"
"UnitTestConnection": "Server=(localdb)\\mssqllocaldb;Database=EfCore.TestSupport-Test;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"MyInt": 1,
"MyObject": {
Expand Down
2 changes: 1 addition & 1 deletion Birder/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "8.0.0",
"version": "8.0.1",
"commands": [
"dotnet-ef"
]
Expand Down
1 change: 1 addition & 0 deletions Birder/Birder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<PackageReference Include="System.Runtime.Caching" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.1" />
</ItemGroup>

</Project>

0 comments on commit b31c8c0

Please sign in to comment.