Example #1
0
        public void Test011()
        {
            using var sut = new TestServiceProvider();
            var descriptor        = new ServiceDescriptor(typeof(DummyService), new DummyService());
            var anotherDescriptor = new ServiceDescriptor(typeof(AnotherDummyService), new AnotherDummyService());
            var oneMoreDescriptor = new ServiceDescriptor(typeof(OneMoreDummyService), new OneMoreDummyService());

            sut.Add(descriptor);
            sut.Add(anotherDescriptor);
            sut.Add(oneMoreDescriptor);

            sut.Remove(descriptor);
            sut.Count.ShouldBe(2);

            sut.RemoveAt(1);
            sut.Count.ShouldBe(1);

            sut.Clear();
            sut.ShouldBeEmpty();
        }
Example #2
0
        public void Test013()
        {
            var descriptor = new ServiceDescriptor(typeof(AnotherDummyService), new AnotherDummyService());

            using var sut = new TestServiceProvider();
            sut.AddSingleton(new DummyService());
            sut.GetService <DummyService>();

            // Try adding
            Should.Throw <InvalidOperationException>(() => sut.Add(descriptor));
            Should.Throw <InvalidOperationException>(() => sut.Insert(0, descriptor));
            Should.Throw <InvalidOperationException>(() => sut[0] = descriptor);

            // Try removing
            Should.Throw <InvalidOperationException>(() => sut.Remove(descriptor));
            Should.Throw <InvalidOperationException>(() => sut.RemoveAt(0));
            Should.Throw <InvalidOperationException>(() => sut.Clear());

            // Verify state
            sut.IsProviderInitialized.ShouldBeTrue();
            sut.IsReadOnly.ShouldBeTrue();
        }