public void CreateConnectionUsesRegisteredProvider()
        {
            const string bankId1 = "TestBank1";
            const string bankId2 = "TestBank2";

            var testConnection1 = Substitute.For <IBankConnection>();
            var testConnection2 = Substitute.For <IBankConnection>();

            var testProvider1 = Substitute.For <IBankConnectionProvider>();

            testProvider1.BankId.Returns(bankId1);
            testProvider1.CreateConnection().Returns(testConnection1);

            var testProvider2 = Substitute.For <IBankConnectionProvider>();

            testProvider2.BankId.Returns(bankId2);
            testProvider2.CreateConnection().Returns(testConnection2);

            var connectionManager = new BankConnectionManager();

            connectionManager.RegisterConnectionProvider(testProvider1);
            connectionManager.RegisterConnectionProvider(testProvider2);

            var newConnection = connectionManager.CreateConnection(bankId1);

            Assert.That(newConnection, Is.EqualTo(testConnection1));
            Assert.That(newConnection, Is.Not.EqualTo(testConnection2));
        }
Example #2
0
        /// <summary>
        ///     Adds the IBankConnectionManager service with a list of registered connection providers for the application
        /// </summary>
        public static IServiceCollection AddBankConnections(this IServiceCollection services)
        {
            var connectionManager = new BankConnectionManager();

            connectionManager.RegisterConnectionProvider(new BizfiBankConnectionProvider());

            return(services
                   .AddSingleton <IBankConnectionManager>(connectionManager));
        }
        public void RegisterConnectionProviderPreventsDuplicateRegistration()
        {
            const string bankId = "TestBank";

            var testProvider1 = Substitute.For <IBankConnectionProvider>();

            testProvider1.BankId.Returns(bankId);

            var testProvider2 = Substitute.For <IBankConnectionProvider>();

            testProvider2.BankId.Returns(bankId);

            var connectionManager = new BankConnectionManager();

            connectionManager.RegisterConnectionProvider(testProvider1);

            Assert.Throws <ArgumentException>(
                () => connectionManager.RegisterConnectionProvider(testProvider2)
                );
        }
        public void RegisterConnectionProviderCanRegisterProvider()
        {
            const string bankId = "TestBank";

            var testProvider = Substitute.For <IBankConnectionProvider>();

            testProvider.BankId.Returns(bankId);

            var connectionManager = new BankConnectionManager();

            connectionManager.RegisterConnectionProvider(testProvider);

            var registeredConnections = connectionManager.GetRegisteredBankIds();

            Assert.That(registeredConnections.Count, Is.EqualTo(1));
            Assert.That(registeredConnections[0], Is.EqualTo(bankId));
        }
        public void CreateConnectionFailsWithNoRegisteredProvider()
        {
            const string bankId1 = "TestBank1";
            const string bankId2 = "TestBank2";

            var testConnection = Substitute.For <IBankConnection>();

            var testProvider1 = Substitute.For <IBankConnectionProvider>();

            testProvider1.BankId.Returns(bankId1);
            testProvider1.CreateConnection().Returns(testConnection);

            var connectionManager = new BankConnectionManager();

            connectionManager.RegisterConnectionProvider(testProvider1);

            Assert.Throws <InvalidOperationException>(
                () => connectionManager.CreateConnection(bankId2)
                );
        }