public void Test010() { using var sut = new TestServiceProvider(); sut.Add(new ServiceDescriptor(typeof(DummyService), new DummyService())); sut.Insert(0, new ServiceDescriptor(typeof(AnotherDummyService), new AnotherDummyService())); sut[1] = new ServiceDescriptor(typeof(DummyService), new DummyService()); sut.Count.ShouldBe(2); sut[0].ServiceType.ShouldBe(typeof(AnotherDummyService)); sut[1].ServiceType.ShouldBe(typeof(DummyService)); }
/// <summary> /// Adds the <see cref="MockJsRuntimeInvokeHandler"/> to the <see cref="TestServiceProvider"/>. /// </summary> /// <returns>The added <see cref="MockJsRuntimeInvokeHandler"/>.</returns> public static MockJsRuntimeInvokeHandler AddMockJsRuntime(this TestServiceProvider serviceProvider, JsRuntimeMockMode mode = JsRuntimeMockMode.Loose) { if (serviceProvider is null) { throw new ArgumentNullException(nameof(serviceProvider)); } var result = new MockJsRuntimeInvokeHandler(mode); serviceProvider.AddSingleton(result.ToJsRuntime()); return(result); }
/// <summary> /// Create a <see cref="MockHttpMessageHandler"/> and adds it to the /// <paramref name="serviceProvider"/> as a <see cref="HttpClient"/>. /// </summary> /// <param name="serviceProvider"></param> /// <returns>The <see cref="MockHttpMessageHandler"/>.</returns> public static MockHttpMessageHandler AddMockHttp(this TestServiceProvider serviceProvider) { if (serviceProvider is null) { throw new ArgumentNullException(nameof(serviceProvider)); } var mockHttp = new MockHttpMessageHandler(); var httpClient = mockHttp.ToHttpClient(); httpClient.BaseAddress = new Uri("http://example.com"); serviceProvider.AddService(httpClient); return(mockHttp); }
public void Test012() { using var sut = new TestServiceProvider(); var descriptor = new ServiceDescriptor(typeof(DummyService), new DummyService()); var copyToTarget = new ServiceDescriptor[1]; sut.Add(descriptor); sut.IndexOf(descriptor).ShouldBe(0); sut.Contains(descriptor).ShouldBeTrue(); sut.CopyTo(copyToTarget, 0); copyToTarget[0].ShouldBe(descriptor); sut.IsReadOnly.ShouldBeFalse(); ((IEnumerable)sut).OfType <ServiceDescriptor>().Count().ShouldBe(1); }
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(); }
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(); }
public void Test001() { using var sut = new TestServiceProvider(); sut.Count.ShouldBe(0); }