public void SetUp() { _storageContext = new StorageProviderContext { SerialNumber = "00-00-000-000", CounterId = 1, Precision = Precision.mWh }; IServiceProvider serviceProvider = new ServiceCollection() .AddSingleton(_storageContext) .BuildServiceProvider(); _sut = new StorageProviderFactory(new NullLogger <StorageProviderFactory>(), serviceProvider, typeof(StorageProviderStub)); }
public void When_getting_provider_cant_be_created_should_throw() { Type invalidProviderType = typeof(StorageProviderStubWithMissingCtorParams); _sut = new StorageProviderFactory(new NullLogger <StorageProviderFactory>(), new ServiceCollection().BuildServiceProvider(), invalidProviderType); // Act Action act = () => _sut.GetStorageProvider(new StorageProviderContext()); // Assert StorageException ex = act.Should().Throw <StorageException>().Which; ex.Message.Should().Be($"Unable to create storage provider {typeof(StorageProviderStubWithMissingCtorParams).FullName}."); ex.InnerException.Should().BeOfType <InvalidOperationException>(); }