Skip to content

Commit 409f6f7

Browse files
committed
Normalize modernization test conventions
1 parent 5c8f429 commit 409f6f7

11 files changed

Lines changed: 805 additions & 502 deletions

test/Exceptionless.MessagePack.Tests/MessagePackStorageSerializerTests.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,33 +68,39 @@ public override void CanSerializeUserInfo() {
6868
}
6969

7070
[Fact]
71-
public void LiteralJsonStringsRemainStringsAcrossStorageRoundTrip() {
71+
public void Serialize_WithLiteralJsonString_PreservesStringAcrossStorageRoundTrip() {
72+
// Arrange
7273
var original = new Event {
7374
Type = Event.KnownTypes.Log,
7475
Data = { ["literal"] = /* lang=json */ "{\"value\":true}" }
7576
};
7677

78+
// Act
7779
Event roundTripped;
7880
using (var stream = new MemoryStream()) {
7981
Resolver.GetStorageSerializer().Serialize(original, stream);
8082
stream.Position = 0;
8183
roundTripped = Resolver.GetStorageSerializer().Deserialize<Event>(stream);
8284
}
8385

84-
Assert.Equal("{\"value\":true}", roundTripped.Data["literal"]);
8586
using var document = JsonDocument.Parse(Resolver.GetJsonSerializer().Serialize(roundTripped));
87+
88+
// Assert
89+
Assert.Equal("{\"value\":true}", roundTripped.Data["literal"]);
8690
Assert.Equal(JsonValueKind.String, document.RootElement.GetProperty("data").GetProperty("literal").ValueKind);
8791
}
8892

8993
[Fact]
90-
public void RawJsonValuesRemainStructuredAcrossStorageRoundTrip() {
94+
public void Serialize_WithRawJsonValue_PreservesStructureAcrossStorageRoundTrip() {
95+
// Arrange
9196
const string json = "{\"type\":\"log\",\"data\":{\"payload\":{"
9297
+ "\"timestamp\":\"2026-07-25T12:34:56.0000000+00:00\","
9398
+ "\"count\":42,\"enabled\":true,\"items\":[1,null,\"value\"]}}}";
9499
var jsonSerializer = Resolver.GetJsonSerializer();
95100
var original = (Event)jsonSerializer.Deserialize(json, typeof(Event));
96-
Assert.IsType<string>(original.Data["payload"]);
101+
object originalPayload = original.Data["payload"];
97102

103+
// Act
98104
Event roundTripped;
99105
using (var stream = new MemoryStream()) {
100106
Resolver.GetStorageSerializer().Serialize(original, stream);
@@ -104,6 +110,9 @@ public void RawJsonValuesRemainStructuredAcrossStorageRoundTrip() {
104110

105111
using var document = JsonDocument.Parse(jsonSerializer.Serialize(roundTripped));
106112
JsonElement payload = document.RootElement.GetProperty("data").GetProperty("payload");
113+
114+
// Assert
115+
Assert.IsType<string>(originalPayload);
107116
Assert.Equal(JsonValueKind.Object, payload.ValueKind);
108117
Assert.Equal("2026-07-25T12:34:56.0000000+00:00", payload.GetProperty("timestamp").GetString());
109118
Assert.Equal(42, payload.GetProperty("count").GetInt32());

test/Exceptionless.Tests/Configuration/ConfigurationTests.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,36 +101,42 @@ public void CanReadFromAttributes() {
101101
}
102102

103103
#if NETSTANDARD
104-
[Fact]
105-
public void CanRegisterStorageSerializerFromConfigurationTypeName() {
104+
[Theory]
105+
[InlineData("System.String, System.Private.CoreLib")]
106+
[InlineData("Missing.StorageSerializer, Missing.Assembly")]
107+
public void ReadFromConfiguration_WithInvalidStorageSerializerType_PreservesDefaultSerializer(string typeName) {
108+
// Arrange
106109
using var resolver = DependencyResolver.CreateDefault();
107110
var config = new ExceptionlessConfiguration(resolver);
108111
IConfiguration settings = new ConfigurationBuilder()
109112
.AddInMemoryCollection(new Dictionary<string, string> {
110-
["Exceptionless:StorageSerializer"] = typeof(ConfigurationStorageSerializer).AssemblyQualifiedName
113+
["Exceptionless:StorageSerializer"] = typeName
111114
})
112115
.Build();
113116

117+
// Act
114118
config.ReadFromConfiguration(settings);
115119

116-
Assert.IsType<ConfigurationStorageSerializer>(resolver.GetStorageSerializer());
120+
// Assert
121+
Assert.IsType<DefaultJsonSerializer>(resolver.GetStorageSerializer());
117122
}
118123

119-
[Theory]
120-
[InlineData("System.String, System.Private.CoreLib")]
121-
[InlineData("Missing.StorageSerializer, Missing.Assembly")]
122-
public void InvalidConfiguredStorageSerializerLeavesDefaultRegistration(string typeName) {
124+
[Fact]
125+
public void ReadFromConfiguration_WithValidStorageSerializerType_RegistersStorageSerializer() {
126+
// Arrange
123127
using var resolver = DependencyResolver.CreateDefault();
124128
var config = new ExceptionlessConfiguration(resolver);
125129
IConfiguration settings = new ConfigurationBuilder()
126130
.AddInMemoryCollection(new Dictionary<string, string> {
127-
["Exceptionless:StorageSerializer"] = typeName
131+
["Exceptionless:StorageSerializer"] = typeof(ConfigurationStorageSerializer).AssemblyQualifiedName
128132
})
129133
.Build();
130134

135+
// Act
131136
config.ReadFromConfiguration(settings);
132137

133-
Assert.IsType<DefaultJsonSerializer>(resolver.GetStorageSerializer());
138+
// Assert
139+
Assert.IsType<ConfigurationStorageSerializer>(resolver.GetStorageSerializer());
134140
}
135141
#endif
136142

test/Exceptionless.Tests/Dependency/DependencyTests.cs

Lines changed: 104 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -47,130 +47,173 @@ public void CanHaveIsolatedContainers() {
4747
}
4848

4949
[Fact]
50-
public void ConcreteRegistrationsAreTransient() {
50+
public void CreateDefault_WithCustomService_OverridesClientDefault() {
51+
// Arrange
52+
var serializer = new DefaultJsonSerializer();
53+
var services = new ServiceCollection();
54+
services.AddSingleton<IJsonSerializer>(serializer);
55+
56+
// Act
57+
using var client = new ExceptionlessClient(services);
58+
59+
// Assert
60+
Assert.Same(serializer, client.Configuration.Resolver.GetJsonSerializer());
61+
}
62+
63+
[Fact]
64+
public void Dispose_WithContainerOwnedSingleton_DisposesInstance() {
65+
// Arrange
5166
var resolver = new DefaultDependencyResolver();
52-
resolver.Register<ServiceA>();
67+
resolver.Register<IDisposableService, DisposableService>();
68+
var service = resolver.Resolve<IDisposableService>();
69+
70+
// Act
71+
resolver.Dispose();
5372

54-
Assert.NotSame(resolver.Resolve<ServiceA>(), resolver.Resolve<ServiceA>());
73+
// Assert
74+
Assert.True(service.IsDisposed);
5575
}
5676

5777
[Fact]
58-
public void FactoryRegistrationsAreTransient() {
78+
public void Dispose_WithExplicitInstance_PreservesInstance() {
79+
// Arrange
5980
var resolver = new DefaultDependencyResolver();
60-
resolver.Register(typeof(IServiceA), () => new ServiceA());
81+
var service = new DisposableService();
82+
resolver.Register<IDisposableService>(service);
83+
resolver.Resolve<IDisposableService>();
84+
85+
// Act
86+
resolver.Dispose();
87+
88+
// Assert
89+
Assert.False(service.IsDisposed);
90+
}
91+
92+
[Fact]
93+
public void Dispose_WithProviderSnapshots_DisposesEachSnapshotOnce() {
94+
// Arrange
95+
var resolver = new DefaultDependencyResolver();
96+
resolver.Register<ICountingDisposable, CountingDisposable>();
97+
var original = resolver.Resolve<ICountingDisposable>();
98+
resolver.Register<IServiceA, ServiceA>();
99+
var replacement = resolver.Resolve<ICountingDisposable>();
61100

62-
Assert.NotSame(resolver.Resolve<IServiceA>(), resolver.Resolve<IServiceA>());
101+
// Act
102+
resolver.Dispose();
103+
104+
// Assert
105+
Assert.NotSame(original, replacement);
106+
Assert.Equal(1, original.DisposeCount);
107+
Assert.Equal(1, replacement.DisposeCount);
63108
}
64109

65110
[Fact]
66-
public void CanReplaceRegistrationAfterResolution() {
111+
public void Register_AfterInitialResolution_ReplacesRegistration() {
112+
// Arrange
67113
var resolver = new DefaultDependencyResolver();
68114
resolver.Register<IServiceA, ServiceA>();
69115
var original = resolver.Resolve<IServiceA>();
70116

117+
// Act
71118
resolver.Register<IServiceA, AlternateServiceA>();
119+
var replacement = resolver.Resolve<IServiceA>();
72120

73-
Assert.IsType<AlternateServiceA>(resolver.Resolve<IServiceA>());
74-
Assert.NotSame(original, resolver.Resolve<IServiceA>());
121+
// Assert
122+
Assert.IsType<AlternateServiceA>(replacement);
123+
Assert.NotSame(original, replacement);
75124
}
76125

77126
[Fact]
78-
public void LateReplacementCreatesConsistentServiceGraphSnapshot() {
127+
public void Resolve_AfterLateReplacement_CreatesConsistentServiceGraph() {
128+
// Arrange
79129
using var resolver = new DefaultDependencyResolver();
80130
resolver.Register<IServiceA, ServiceA>();
81131
resolver.Register<IServiceB, ServiceB>();
82132
var original = resolver.Resolve<IServiceB>();
83133

134+
// Act
84135
resolver.Register<IServiceA, AlternateServiceA>();
85136
var replacement = resolver.Resolve<IServiceB>();
86137

138+
// Assert
87139
Assert.IsType<ServiceA>(original.ServiceA);
88140
Assert.IsType<AlternateServiceA>(replacement.ServiceA);
89141
Assert.NotSame(original, replacement);
90142
}
91143

92144
[Fact]
93-
public void CanUseServiceCollectionRegistrations() {
94-
var services = new ServiceCollection();
95-
services.AddSingleton<IServiceA, AlternateServiceA>();
96-
var resolver = new DefaultDependencyResolver(services);
145+
public void Resolve_WithConcreteRegistration_ReturnsTransientInstances() {
146+
// Arrange
147+
var resolver = new DefaultDependencyResolver();
148+
resolver.Register<ServiceA>();
149+
150+
// Act
151+
var first = resolver.Resolve<ServiceA>();
152+
var second = resolver.Resolve<ServiceA>();
153+
154+
// Assert
155+
Assert.NotSame(first, second);
156+
}
97157

98-
Assert.IsType<AlternateServiceA>(resolver.Resolve<IServiceA>());
158+
[Fact]
159+
public void Resolve_WithFactoryRegistration_ReturnsTransientInstances() {
160+
// Arrange
161+
var resolver = new DefaultDependencyResolver();
162+
resolver.Register(typeof(IServiceA), () => new ServiceA());
163+
164+
// Act
165+
var first = resolver.Resolve<IServiceA>();
166+
var second = resolver.Resolve<IServiceA>();
167+
168+
// Assert
169+
Assert.NotSame(first, second);
99170
}
100171

101172
[Fact]
102-
public void CanResolveAllServiceCollectionRegistrations() {
173+
public void Resolve_WithMultipleServiceCollectionRegistrations_ReturnsAllServices() {
174+
// Arrange
103175
var services = new ServiceCollection();
104176
services.AddSingleton<IServiceA, ServiceA>();
105177
services.AddSingleton<IServiceA, AlternateServiceA>();
106178
using var resolver = new DefaultDependencyResolver(services);
107179

180+
// Act
108181
var registrations = resolver.Resolve<IEnumerable<IServiceA>>().ToArray();
109182

183+
// Assert
110184
Assert.Collection(
111185
registrations,
112186
service => Assert.IsType<ServiceA>(service),
113187
service => Assert.IsType<AlternateServiceA>(service));
114188
}
115189

116190
[Fact]
117-
public void CanResolveOpenGenericRegistrations() {
191+
public void Resolve_WithOpenGenericRegistration_ReturnsClosedService() {
192+
// Arrange
118193
var resolver = new DefaultDependencyResolver();
119194
resolver.Register(typeof(IGenericService<>), typeof(GenericService<>));
120195

196+
// Act
121197
var service = resolver.Resolve(typeof(IGenericService<string>));
198+
var repeated = resolver.Resolve(typeof(IGenericService<string>));
122199

200+
// Assert
123201
Assert.IsType<GenericService<string>>(service);
124-
Assert.Same(service, resolver.Resolve(typeof(IGenericService<string>)));
202+
Assert.Same(service, repeated);
125203
}
126204

127205
[Fact]
128-
public void CustomServicesOverrideClientDefaults() {
129-
var serializer = new DefaultJsonSerializer();
206+
public void Resolve_WithServiceCollectionRegistration_ReturnsRegisteredService() {
207+
// Arrange
130208
var services = new ServiceCollection();
131-
services.AddSingleton<IJsonSerializer>(serializer);
132-
133-
using var client = new ExceptionlessClient(services);
134-
135-
Assert.Same(serializer, client.Configuration.Resolver.GetJsonSerializer());
136-
}
137-
138-
[Fact]
139-
public void DisposesContainerOwnedSingletons() {
140-
var resolver = new DefaultDependencyResolver();
141-
resolver.Register<IDisposableService, DisposableService>();
142-
var service = resolver.Resolve<IDisposableService>();
143-
144-
resolver.Dispose();
145-
146-
Assert.True(service.IsDisposed);
147-
}
148-
149-
[Fact]
150-
public void DoesNotDisposeExplicitInstances() {
151-
var resolver = new DefaultDependencyResolver();
152-
var service = new DisposableService();
153-
resolver.Register<IDisposableService>(service);
154-
resolver.Resolve<IDisposableService>();
155-
156-
resolver.Dispose();
157-
158-
Assert.False(service.IsDisposed);
159-
}
160-
161-
[Fact]
162-
public void DisposesEveryProviderSnapshotExactlyOnce() {
163-
var resolver = new DefaultDependencyResolver();
164-
resolver.Register<ICountingDisposable, CountingDisposable>();
165-
var original = resolver.Resolve<ICountingDisposable>();
166-
resolver.Register<IServiceA, ServiceA>();
167-
var replacement = resolver.Resolve<ICountingDisposable>();
209+
services.AddSingleton<IServiceA, AlternateServiceA>();
210+
var resolver = new DefaultDependencyResolver(services);
168211

169-
resolver.Dispose();
212+
// Act
213+
var service = resolver.Resolve<IServiceA>();
170214

171-
Assert.NotSame(original, replacement);
172-
Assert.Equal(1, original.DisposeCount);
173-
Assert.Equal(1, replacement.DisposeCount);
215+
// Assert
216+
Assert.IsType<AlternateServiceA>(service);
174217
}
175218
}
176219

0 commit comments

Comments
 (0)