-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceCollectionAdapterTests.cs
More file actions
66 lines (55 loc) · 2.94 KB
/
ServiceCollectionAdapterTests.cs
File metadata and controls
66 lines (55 loc) · 2.94 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections;
using Reqnroll.BoDi;
using Microsoft.Extensions.DependencyInjection;
namespace CSF.Screenplay;
[TestFixture,Parallelizable]
public class ServiceCollectionAdapterTests
{
[Test]
public void UnsupportedFunctionalityShouldThrowNotSupportedException()
{
var container = new ObjectContainer();
var sut = new ServiceCollectionAdapter(container);
using var scope = Assert.EnterMultipleScope();
Assert.That(() => sut[0], Throws.InstanceOf<NotSupportedException>(), "Indexer get");
Assert.That(() => sut[0] = null, Throws.InstanceOf<NotSupportedException>(), "Indexer set");
Assert.That(() => sut.Clear(), Throws.InstanceOf<NotSupportedException>(), nameof(IServiceCollection.Clear));
Assert.That(() => sut.Contains(null), Throws.InstanceOf<NotSupportedException>(), nameof(IServiceCollection.Contains));
Assert.That(() => sut.CopyTo(null, default), Throws.InstanceOf<NotSupportedException>(), nameof(IServiceCollection.CopyTo));
Assert.That(() => sut.GetEnumerator(), Throws.InstanceOf<NotSupportedException>(), nameof(IServiceCollection.GetEnumerator));
Assert.That(() => ((IEnumerable) sut).GetEnumerator(), Throws.InstanceOf<NotSupportedException>(), nameof(IServiceCollection.GetEnumerator) + ": " + nameof(IEnumerable));
Assert.That(() => sut.IndexOf(default), Throws.InstanceOf<NotSupportedException>(), nameof(IServiceCollection.IndexOf));
Assert.That(() => sut.Insert(default, null), Throws.InstanceOf<NotSupportedException>(), nameof(IServiceCollection.Insert));
Assert.That(() => sut.Remove(null), Throws.InstanceOf<NotSupportedException>(), nameof(IServiceCollection.Remove));
Assert.That(() => sut.RemoveAt(default), Throws.InstanceOf<NotSupportedException>(), nameof(IServiceCollection.RemoveAt));
}
[Test]
public void AddTypeShouldAddToObjectContainer()
{
var container = new ObjectContainer();
var sut = new ServiceCollectionAdapter(container);
sut.AddSingleton<ISampleInterface, SampleType>();
Assert.That(container.Resolve<ISampleInterface>, Is.InstanceOf<SampleType>());
}
[Test]
public void AddInstanceShouldAddToObjectContainer()
{
var container = new ObjectContainer();
var sut = new ServiceCollectionAdapter(container);
var instance = new SampleType();
sut.AddSingleton<ISampleInterface>(instance);
Assert.That(container.Resolve<ISampleInterface>(), Is.SameAs(instance));
}
[Test]
public void AddFactoryShouldAddToObjectContainer()
{
var container = new ObjectContainer();
var sut = new ServiceCollectionAdapter(container);
var instance = new SampleType();
sut.AddSingleton<ISampleInterface>(_ => instance);
Assert.That(container.Resolve<ISampleInterface>(), Is.SameAs(instance));
}
interface ISampleInterface {}
class SampleType : ISampleInterface {}
}