Skip to content

Commit

Permalink
Fixed flaky tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
nscheibe committed Oct 17, 2024
1 parent d07029b commit 0a50903
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 75 deletions.
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<ItemGroup>
<PackageVersion Include="Moq" Version="4.16.1" />
<PackageVersion Include="Snapshooter.Xunit" Version="0.13.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Squadron.Mongo" Version="0.22.0" />
<PackageVersion Include="xunit" Version="2.4.2" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="Xunit.Priority" Version="1.1.6" />
<PackageVersion Include="FluentAssertions" Version="6.2.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
Expand Down
7 changes: 5 additions & 2 deletions src/Context.AllowedTypes.Tests/MongoDatabaseBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void AddAllowedTypes_AllowedTypesRegisteredByDefault_Success()
Assert.NotNull(context);
}

[Fact(Skip = "Flaky test")]
[Fact]
public void AddAllowedTypes_AddAllowedTypesOfAllDependencies_Success()
{
// Arrange
Expand All @@ -58,7 +58,10 @@ public void AddAllowedTypes_AddAllowedTypesOfAllDependencies_Success()
BsonSerializer.LookupSerializer<object>();

Assert.True(registeredSerializer is TypeObjectSerializer);
Snapshot.Match(TestHelpers.GetTypeObjectSerializerContent());
Snapshot.Match(TestHelpers.GetTypeObjectSerializerContent(),
options => options.Assert(fieldOption =>
Assert.Contains("MongoDB", fieldOption
.Fields<string>("AllowedTypesByDependencies[*]"))));
}

[Fact]
Expand Down
14 changes: 10 additions & 4 deletions src/Context.AllowedTypes.Tests/TypeObjectSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace MongoDB.Extensions.Context.AllowedTypes.Tests;

public class TypeObjectSerializerTests
{
[Fact(Skip = "Flaky test")]
[Fact]
public void AddAllowedTypes_AddAllowedTypesOfAllDependencies_Success()
{
// Arrange
Expand All @@ -17,7 +17,10 @@ public void AddAllowedTypes_AddAllowedTypesOfAllDependencies_Success()
TypeObjectSerializer.AddAllowedTypesOfAllDependencies();

// Assert
Snapshot.Match(TestHelpers.GetTypeObjectSerializerContent());
Snapshot.Match(TestHelpers.GetTypeObjectSerializerContent(),
options => options.Assert(fieldOption =>
Assert.Contains("MongoDB", fieldOption
.Fields<string>("AllowedTypesByDependencies[*]"))));
}

[Fact]
Expand Down Expand Up @@ -136,7 +139,7 @@ public void IsTypeAllowed_PartIsNotInAllowedNamespaces_False()
Snapshot.Match(TestHelpers.GetTypeObjectSerializerContent());
}

[Fact(Skip = "Flaky test")]
[Fact]
public void IsTypeAllowed_InAllowedTypesInDependencies_True()
{
// Arrange
Expand All @@ -148,6 +151,9 @@ public void IsTypeAllowed_InAllowedTypesInDependencies_True()

// Assert
Assert.True(isAllowed);
Snapshot.Match(TestHelpers.GetTypeObjectSerializerContent());
Snapshot.Match(TestHelpers.GetTypeObjectSerializerContent(),
options => options.Assert(fieldOption =>
Assert.Contains("MongoDB", fieldOption
.Fields<string>("AllowedTypesByDependencies[*]"))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,13 @@
"AllowedTypes": [],
"AllowedTypesByNamespaces": [],
"AllowedTypesByDependencies": [
"Amazon",
"AWSSDK",
"Castle",
"DnsClient",
"Docker",
"FluentAssertions",
"ICSharpCode",
"Internal",
"MongoDB",
"Moq",
"Newtonsoft",
"NuGet",
"Polly",
"SharpCompress",
"Snappier",
"Snapshooter",
"Squadron",
"ThirdParty",
"TypeNameFormatter",
"Xunit",
"ZstdSharp"
"Xunit"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,11 @@
"AllowedTypes": [],
"AllowedTypesByNamespaces": [],
"AllowedTypesByDependencies": [
"Amazon",
"Autofac",
"AWSSDK",
"CommandLine",
"CSharpx",
"DnsClient",
"Docker",
"JetBrains",
"Internal",
"MongoDB",
"Newtonsoft",
"Proxy",
"RailwaySharp",
"Serilog",
"SharpCompress",
"Snapshooter",
"Squadron",
"ThirdParty",
"Xunit"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,11 @@
],
"AllowedTypesByNamespaces": [],
"AllowedTypesByDependencies": [
"Amazon",
"AWSSDK",
"Castle",
"DnsClient",
"Docker",
"FluentAssertions",
"ICSharpCode",
"Internal",
"MongoDB",
"Moq",
"Newtonsoft",
"NuGet",
"Polly",
"SharpCompress",
"Snappier",
"Snapshooter",
"Squadron",
"ThirdParty",
"TypeNameFormatter",
"Xunit",
"ZstdSharp"
"Xunit"
]
}
6 changes: 5 additions & 1 deletion src/Context.Tests/Context.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(CCTestProjectProps)" Condition="Exists('$(CCTestProjectProps)')" />

<PropertyGroup>
Expand All @@ -16,4 +16,8 @@
<Compile Remove="IsExternalInit.cs" Condition="'$(TargetFramework)' == 'net8.0'" />
</ItemGroup>

<ItemGroup>
<Folder Include="Internal\__snapshots__\__mismatch__\" />
</ItemGroup>

</Project>
7 changes: 5 additions & 2 deletions src/Context.Tests/Internal/DependencyTypesResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace MongoDB.Extensions.Context.Tests.Internal;
[Collection("Sequential")]
public class DependencyTypesResolverTests
{
[Fact(Skip = "Flaky test")]
[Fact]
public void GetAllowedTypesByDependencies_All_Successful()
{
// Arrange
Expand All @@ -19,6 +19,9 @@ public void GetAllowedTypesByDependencies_All_Successful()
.OrderBy(x => x);

// Assert
Snapshot.Match(knownNamespaces);
Snapshot.Match(knownNamespaces,
options => options.Assert(fieldOption =>
Assert.Contains("MongoDB", fieldOption
.Fields<string>("[*]"))));
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
[
"Amazon",
"AWSSDK",
"Castle",
"DnsClient",
"Docker",
"FluentAssertions",
"ICSharpCode",
"Internal",
"MongoDB",
"Moq",
"Newtonsoft",
"NuGet",
"Polly",
"SharpCompress",
"Snappier",
"Snapshooter",
"Squadron",
"ThirdParty",
"TypeNameFormatter",
"Xunit",
"ZstdSharp"
"Xunit"
]
4 changes: 0 additions & 4 deletions src/Context/Context.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,4 @@
<ProjectReference Include="..\Transactions\Transactions.csproj" />
</ItemGroup>

<ItemGroup>
<PackageVersion Update="MongoDB.Driver" Version="2.30.0" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions src/MongoDB.Extensions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Migration.Tests", "Migratio
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".SolutionFiles", ".SolutionFiles", "{A21A1FF3-25C1-4FE1-994E-E16CDF98BB99}"
ProjectSection(SolutionItems) = preProject
Dependencies.props = Dependencies.props
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
..\Directory.Packages.props = ..\Directory.Packages.props
Package.props = Package.props
ResourceProject.props = ResourceProject.props
TestProject.props = TestProject.props
Version.props = Version.props
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Context.AllowedTypes.Tests", "Context.AllowedTypes.Tests\Context.AllowedTypes.Tests.csproj", "{C59B2068-C3F4-4900-A1CB-7BFD63F94095}"
Expand Down

0 comments on commit 0a50903

Please sign in to comment.