Example #1
0
        /// <summary>
        /// Creates <see cref="IOfxClient" /> based on options provided.
        /// </summary>
        /// <param name="options">The OFX options.</param>
        /// <returns>
        /// Concrete OFX client implementation.
        /// </returns>
        public IOfxClient Create(OfxClientOptions options)
        {
            var serializer = _serializerFactory.Create(options.Version);
            var utils      = _utilsFactory.Create(options.BankFid);

            return(new OfxClient(options, utils, serializer));
        }
Example #2
0
        public async Task AccountListTest()
        {
            var expectedRequest =
                EmbeddedResourceReader.ReadRequestAsString("accountList.sgml");
            var expectedResponse =
                EmbeddedResourceReader.ReadResponseAsString("accountList.sgml");

            var options       = new OfxClientOptions(ApiUrl, "HAN", "5959", "testUserAccount", "testUserPassword");
            var transportMock = Substitute.For <IOfxClientTransport>();
            var utilsMock     = Substitute.For <IUtils>();

            transportMock.PostRequest(Arg.Any <Uri>(), Arg.Any <string>()).Returns(Task.FromResult(expectedResponse));

            utilsMock.GenerateTransactionId().Returns("0000000000");
            utilsMock.GetCurrentDateTime().Returns("20150127131257");
            utilsMock.GetClientUid(Arg.Is <string>(val => val == "testUserAccount")).Returns("SomeGuidHere");

            var client = new OfxClient(options, transportMock, utilsMock);
            var result = await client.GetAccounts();

            var account = result;

            Assert.NotEqual(ImmutableArray <Account> .Empty, account);
            Assert.Equal(2, account.Length);
        }
Example #3
0
        public void BankStatementTest()
        {
            var expectedRequest =
                EmbeddedResourceReader.ReadRequestAsString("bankTransactions.sgml");

            var options   = new OfxClientOptions(ApiUrl, "HAN", "5959", "testUserAccount", "testUserPassword");
            var utilsMock = Substitute.For <IProtocolUtils>();

            utilsMock.Requests.Returns(new DefaultOfxRequestLocator());

            utilsMock.GenerateTransactionId().Returns("0000000000");
            utilsMock.GetCurrentDateTime().Returns("XXXXXXXXXXXXXX");
            utilsMock.DateFormat.Returns(OfxProtocolUtils.DateTimeFormat);
            utilsMock.GetClientUid(Arg.Is("testUserAccount")).Returns("XXXXXXXXX");

            var client    = new OfxClient(options, utilsMock, new OfxSgmlSerializer());
            var startDate = new DateTime(2019, 1, 1);
            var endDate   = new DateTime(2019, 3, 1);


            var statement = client.PrepareBankStatementOfxRequest(new BankStatementArgs()
            {
                AccountNumber = "YYYYYYYY3158",
                RoutingNumber = "XXXXXXXXX",
                Type          = AccountTypeEnum.Checking,
                StartDate     = startDate,
                EndDate       = endDate
            });

            Assert.Equal(expectedRequest, statement);
        }
Example #4
0
        public async Task ProcessOfxMessageTest()
        {
            var expectedResponse =
                EmbeddedResourceReader.ReadResponseAsString("accountList.sgml");

            var options   = new OfxClientOptions(ApiUrl, "HAN", "5959", "testUserAccount", "testUserPassword");
            var utilsMock = Substitute.For <IProtocolUtils>();

            utilsMock.Requests.Returns(new DefaultOfxRequestLocator());
            utilsMock.PostRequest(Arg.Any <Uri>(), Arg.Any <string>()).Returns(Task.FromResult(expectedResponse));

            utilsMock.GenerateTransactionId().Returns("0000000000");
            utilsMock.GetCurrentDateTime().Returns("20150127131257");
            utilsMock.GetClientUid(Arg.Is <string>(val => val == "testUserAccount")).Returns("SomeGuidHere");

            var serializer = new OfxSgmlSerializer();
            var client     = new OfxClient(options, utilsMock, serializer);

            var ofx = serializer.Deserialize(client.PrepareAccountsOfxRequest());

            // reuse account request message
            var resultString = await client.ProcessOfxMessage(ofx.Items[1]);

            ofx = serializer.Deserialize(resultString);
            var account = OfxAccountsParser.Parse(ofx).ToArray();

            Assert.NotEqual(ImmutableArray <Account> .Empty, account);
            Assert.Equal(2, account.Length);
        }
Example #5
0
        public async Task ErrorRequestTest()
        {
            var options       = new OfxClientOptions(ApiUrl, "HAN", "5959", "testUserAccount", "testUserPassword");
            var transportMock = Substitute.For <IOfxClientTransport>();
            var utilsMock     = Substitute.For <IUtils>();

            utilsMock.GenerateTransactionId().Returns("0000000000");
            utilsMock.GetCurrentDateTime().Returns("XXXXXXXXXXXXXX");

            transportMock.PostRequest(Arg.Any <Uri>(), Arg.Any <string>()).Returns(Task.FromResult(string.Empty));

            var client = new OfxClient(options, transportMock, utilsMock);
            var ex     = await Assert.ThrowsAsync <FormatException>(() => client.GetAccounts());

            Assert.Equal("<OFX> element is not present in the response body", ex.Message);
        }
Example #6
0
        public async Task FailedRequestTest()
        {
            var expectedResponse =
                EmbeddedResourceReader.ReadResponseAsString("error.sgml");

            var options       = new OfxClientOptions(ApiUrl, "HAN", "5959", "testUserAccount", "testUserPassword");
            var transportMock = Substitute.For <IOfxClientTransport>();
            var utilsMock     = Substitute.For <IUtils>();

            utilsMock.GenerateTransactionId().Returns("0000000000");
            utilsMock.GetCurrentDateTime().Returns("XXXXXXXXXXXXXX");

            transportMock.PostRequest(Arg.Any <Uri>(), Arg.Any <string>()).Returns(Task.FromResult(expectedResponse));

            var client = new OfxClient(options, transportMock, utilsMock);
            var ex     = await Assert.ThrowsAsync <OfxResponseException>(() => client.GetAccounts());

            Assert.Equal("An incorrect username/password combination has been entered. Please try again.", ex.Message);
        }
Example #7
0
        public async Task CreditCardTransactionsListTest()
        {
            var expectedResponse =
                EmbeddedResourceReader.ReadResponseAsString("creditCardTransactions.sgml");

            var options   = new OfxClientOptions(ApiUrl, "HAN", "5959", "testUserAccount", "testUserPassword");
            var utilsMock = Substitute.For <IProtocolUtils>();

            utilsMock.Requests.Returns(new DefaultOfxRequestLocator());
            utilsMock.PostRequest(Arg.Any <Uri>(), Arg.Any <string>()).Returns(Task.FromResult(expectedResponse));

            utilsMock.GenerateTransactionId().Returns("0000000000");
            utilsMock.GetCurrentDateTime().Returns("XXXXXXXXXXXXXX");

            var client    = new OfxClient(options, utilsMock, new OfxSgmlSerializer());
            var statement = await client.GetStatement(new CreditCardStatementArgs()
            {
                AccountNumber = "XXXXXXXXXXXX3158"
            });

            Assert.NotNull(statement);
            Assert.Equal(2, statement.Transactions.Length);
        }
Example #8
0
        public async Task BankTransactionsListTest()
        {
            var expectedRequest =
                EmbeddedResourceReader.ReadRequestAsString("bankTransactions.sgml");
            var expectedResponse =
                EmbeddedResourceReader.ReadResponseAsString("bankTransactions.sgml");

            var options       = new OfxClientOptions(ApiUrl, "HAN", "5959", "testUserAccount", "testUserPassword");
            var transportMock = Substitute.For <IOfxClientTransport>();
            var utilsMock     = Substitute.For <IUtils>();

            transportMock.PostRequest(Arg.Any <Uri>(), Arg.Any <string>()).Returns(Task.FromResult(expectedResponse));

            utilsMock.GenerateTransactionId().Returns("0000000000");
            utilsMock.GetCurrentDateTime().Returns("XXXXXXXXXXXXXX");

            var client = new OfxClient(options, transportMock, utilsMock);
            var result = await client.GetTransactions(new Account(AccountTypeEnum.Checking, "YYYYYYYY1924", "XXXXXXXXX"));

            var transactions = result;

            Assert.NotEqual(null, transactions);
            Assert.Equal(2, transactions.Items.Length);
        }