public void Instance_Always_ReturnsFactory() { // Call IBalancedFieldLengthKernelFactory factory = BalancedFieldLengthKernelFactory.Instance; // Assert Assert.That(factory, Is.TypeOf <BalancedFieldLengthKernelFactory>()); }
public void Instance_Always_ReturnsSameInstance() { // Call IBalancedFieldLengthKernelFactory firstFactory = BalancedFieldLengthKernelFactory.Instance; IBalancedFieldLengthKernelFactory secondFactory = BalancedFieldLengthKernelFactory.Instance; // Assert Assert.That(firstFactory, Is.SameAs(secondFactory)); }
/// <summary> /// Creates a new instance of <see cref="BalancedFieldLengthKernelFactoryConfig"/> with a /// specific <see cref="IBalancedFieldLengthKernelFactory"/>. /// </summary> /// <param name="testFactory">The <see cref="IBalancedFieldLengthKernelFactory"/> /// to set the <see cref="BalancedFieldLengthKernelFactory.Instance"/> with.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="testFactory"/> /// is <c>null</c>.</exception> public BalancedFieldLengthKernelFactoryConfig(IBalancedFieldLengthKernelFactory testFactory) { if (testFactory == null) { throw new ArgumentNullException(nameof(testFactory)); } originalInstance = BalancedFieldLengthKernelFactory.Instance; BalancedFieldLengthKernelFactory.Instance = testFactory; }
public void CreateDistanceCalculatorKernel_Always_ReturnsKernel() { // Setup IBalancedFieldLengthKernelFactory factory = BalancedFieldLengthKernelFactory.Instance; // Call IAggregatedDistanceCalculatorKernel kernel = factory.CreateDistanceCalculatorKernel(); // Assert Assert.That(kernel, Is.TypeOf <AggregatedDistanceCalculatorKernel>()); }
public void Constructor_Always_SetsInstanceOfKernelFactory() { // Setup var testFactory = Substitute.For <IBalancedFieldLengthKernelFactory>(); using (new BalancedFieldLengthKernelFactoryConfig(testFactory)) { // Call IBalancedFieldLengthKernelFactory instance = BalancedFieldLengthKernelFactory.Instance; // Assert Assert.That(instance, Is.SameAs(testFactory)); } }
public void GivenConfigWithTestFactory_WhenDisposing_ThenOriginalInstanceRestored() { // Given IBalancedFieldLengthKernelFactory originalInstance = BalancedFieldLengthKernelFactory.Instance; var testFactory = Substitute.For <IBalancedFieldLengthKernelFactory>(); var config = new BalancedFieldLengthKernelFactoryConfig(testFactory); // Precondition Assert.That(BalancedFieldLengthKernelFactory.Instance, Is.SameAs(testFactory)); // When config.Dispose(); // Then Assert.That(BalancedFieldLengthKernelFactory.Instance, Is.SameAs(originalInstance)); }