-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransientServiceFactoryTests.cs
More file actions
32 lines (26 loc) · 1.1 KB
/
TransientServiceFactoryTests.cs
File metadata and controls
32 lines (26 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using Couchbase.AnalyticsClient.Internal.DI;
using Moq;
using Xunit;
namespace Couchbase.Analytics.UnitTests.Internal.DI;
public class TransientServiceFactoryTests
{
[Fact]
public void TransientServiceFactory_Dispose_DoesNotDisposeGeneratedInstances()
{
// Arrange
var mockDisposable = new Mock<IDisposable>();
var factory = new TransientServiceFactory(_ => mockDisposable.Object);
var mockServiceProvider = new Mock<IServiceProvider>();
factory.Initialize(mockServiceProvider.Object);
// Act
// We simulate the lifetime: The user asks for a Transient object, then later the Cluster shuts down entirely.
var instance = factory.CreateService(typeof(IDisposable));
factory.Dispose();
// Assert
// We explicitly confirm that the Transient factory completely ignores the instances
// it generates, thus avoiding long-term memory leaks in the Cluster's DI container!
Assert.NotNull(instance);
mockDisposable.Verify(d => d.Dispose(), Times.Never);
}
}