예제 #1
0
        public async void GetAccounts()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("/accounts", context.Request.Uri.PathAndQuery);

                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);

                    await context.Response.WriteAsync(
                        @"{
                            'accounts': [
                                {
                                    'id': 'acc_00009237aqC8c5umZmrRdh',
                                    'description': 'Peter Pan\'s Account',
                                    'created': '2015-11-13T12:17:42Z'
                                }
                            ]
                        }"
                    );
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    var accounts = await client.GetAccountsAsync();

                    Assert.AreEqual(1, accounts.Count);
                    Assert.AreEqual("acc_00009237aqC8c5umZmrRdh", accounts[0].Id);
                    Assert.AreEqual("Peter Pan's Account", accounts[0].Description);
                    Assert.AreEqual(new DateTime(2015, 11, 13, 12, 17, 42, DateTimeKind.Utc), accounts[0].Created);
                }
            }
        }
예제 #2
0
        public async void GetAccounts()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("/accounts", context.Request.Uri.PathAndQuery);

                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);

                    await context.Response.WriteAsync(
                        @"{
                            'accounts': [
                                {
                                    'id': 'acc_00009237aqC8c5umZmrRdh',
                                    'description': 'Peter Pan\'s Account',
                                    'created': '2015-11-13T12:17:42Z'
                                }
                            ]
                        }"
                        );
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    var accounts = await client.GetAccountsAsync();

                    Assert.AreEqual(1, accounts.Count);
                    Assert.AreEqual("acc_00009237aqC8c5umZmrRdh", accounts[0].Id);
                    Assert.AreEqual("Peter Pan's Account", accounts[0].Description);
                    Assert.AreEqual(new DateTime(2015, 11, 13, 12, 17, 42, DateTimeKind.Utc), accounts[0].Created);
                }
            }
        }
예제 #3
0
        public async void GetWebhooks()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("/webhooks?account_id=1", context.Request.Uri.PathAndQuery);

                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);

                    await context.Response.WriteAsync(
                        @"{
                            'webhooks': [
                                {
                                    'account_id': 'acc_000091yf79yMwNaZHhHGzp',
                                    'id': 'webhook_000091yhhOmrXQaVZ1Irsv',
                                    'url': 'http://example.com/callback'
                                }
                            ]
                        }"
                        );
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    var webhooks = await client.GetWebhooksAsync("1");

                    Assert.AreEqual(1, webhooks.Count);
                    Assert.AreEqual("webhook_000091yhhOmrXQaVZ1Irsv", webhooks[0].Id);
                    Assert.AreEqual("acc_000091yf79yMwNaZHhHGzp", webhooks[0].AccountId);
                    Assert.AreEqual("http://example.com/callback", webhooks[0].Url);
                }
            }
        }
예제 #4
0
        public async void GetBalance()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("/balance?account_id=1", context.Request.Uri.PathAndQuery);

                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);

                    await context.Response.WriteAsync(
                        @"{
                            'balance': 5000,
                            'currency': 'GBP',
                            'spend_today': -100
                        }"
                    );
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    var balance = await client.GetBalanceAsync("1");

                    Assert.AreEqual(5000, balance.Value);
                    Assert.AreEqual("GBP", balance.Currency);
                    Assert.AreEqual(-100, balance.SpendToday);
                }
            }
        }
예제 #5
0
        public async void GetBalance()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("/balance?account_id=1", context.Request.Uri.PathAndQuery);

                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);

                    await context.Response.WriteAsync(
                        @"{
                            'balance': 5000,
                            'currency': 'GBP',
                            'spend_today': -100
                        }"
                        );
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    var balance = await client.GetBalanceAsync("1");

                    Assert.AreEqual(5000, balance.Value);
                    Assert.AreEqual("GBP", balance.Currency);
                    Assert.AreEqual(-100, balance.SpendToday);
                }
            }
        }
예제 #6
0
        public async void CreateFeedItem()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);
                    Assert.AreEqual("POST", context.Request.Method);
                    Assert.AreEqual("/feed", context.Request.Uri.PathAndQuery);

                    var formCollection = await context.Request.ReadFormAsync();
                    Assert.AreEqual("1", formCollection["account_id"]);
                    Assert.AreEqual("basic", formCollection["type"]);
                    Assert.AreEqual("https://www.example.com/a_page_to_open_on_tap.html", formCollection["url"]);
                    Assert.AreEqual("My custom item", formCollection["params[title]"]);

                    await context.Response.WriteAsync("{}");
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    await client.CreateFeedItemAsync("1", "basic", new Dictionary <string, string> {
                        { "title", "My custom item" }
                    }, "https://www.example.com/a_page_to_open_on_tap.html");
                }
            }
        }
예제 #7
0
        public async Task <ActionResult> OAuthCallback(string code, string state)
        {
            // verify anti-CSRF state token matches what was sent
            string expectedState = Session["state"] as string;

            if (!string.Equals(expectedState, state))
            {
                throw new SecurityException("State mismatch");
            }

            Session.Remove("state");

            // exchange authorization code for access token
            AccessToken accessToken = await _mondoAuthorizationClient.GetAccessTokenAsync(code, Url.Action("OAuthCallback", "Home", null, Request.Url.Scheme));

            // fetch transactions etc
            using (var client = new MondoClient(accessToken.Value, "https://production-api.gmon.io"))
            {
                IList <Account> accounts = await client.GetAccountsAsync();

                Balance balance = await client.GetBalanceAsync(accounts[0].Id);

                IList <Transaction> transactions = await client.GetTransactionsAsync(accounts[0].Id, expand : "merchant");

                return(View(new AccountSummaryModel {
                    Account = accounts[0], Balance = balance, Transactions = transactions
                }));
            }
        }
예제 #8
0
        public async void GetTransaction()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);

                    // workaround for mono bug
                    Assert.That(context.Request.Uri.PathAndQuery, Is.EqualTo("/transactions/1"));

                    await context.Response.WriteAsync(
                        @"{
                            'transaction': {
                                'account_balance': 13013,
                                'amount': -510,
                                'created': '2015-08-22T12:20:18Z',
                                'currency': 'GBP',
                                'description': 'THE DE BEAUVOIR DELI C LONDON        GBR',
                                'id': 'tx_00008zIcpb1TB4yeIFXMzx',
                                'merchant': 'merch_00008zIcpbAKe8shBxXUtl',
                                'metadata': {},
                                'notes': 'Salmon sandwich 🍞',
                                'is_load': false,
                                'settled': true
                            }
                        }"
                        );
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    var transaction = await client.GetTransactionAsync("1");

                    Assert.AreEqual(13013, transaction.AccountBalance);
                    Assert.AreEqual(-510, transaction.Amount);
                    Assert.AreEqual(new DateTime(2015, 8, 22, 12, 20, 18, DateTimeKind.Utc), transaction.Created);
                    Assert.AreEqual("GBP", transaction.Currency);
                    Assert.AreEqual("THE DE BEAUVOIR DELI C LONDON        GBR", transaction.Description);
                    Assert.AreEqual("tx_00008zIcpb1TB4yeIFXMzx", transaction.Id);
                    Assert.AreEqual(new Dictionary <string, string>(), transaction.Metadata);
                    Assert.AreEqual("Salmon sandwich 🍞", transaction.Notes);
                    Assert.IsFalse(transaction.IsLoad);

                    Assert.AreEqual("merch_00008zIcpbAKe8shBxXUtl", transaction.Merchant.Id);
                }
            }
        }
예제 #9
0
        public async void AnnotateTransaction()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);
                    Assert.AreEqual("PATCH", context.Request.Method);
                    Assert.AreEqual("/transactions/1", context.Request.Uri.PathAndQuery);

                    var formCollection = await context.Request.ReadFormAsync();

                    Assert.AreEqual("value1", formCollection["metadata[key1]"]);
                    Assert.AreEqual("", formCollection["metadata[key2]"]);

                    await context.Response.WriteAsync(
                        @"{
                            'transaction': {
                                'account_balance': 12334,
                                'amount': -679,
                                'created': '2015-08-23T16:15:03Z',
                                'currency': 'GBP',
                                'description': 'VUE BSL LTD            ISLINGTON     GBR',
                                'id': 'tx_00008zL2INM3xZ41THuRF3',
                                'merchant': 'merch_00008z6uFVhVBcaZzSQwCX',
                                'metadata': {
                                    'foo': 'bar'
                                },
                                'notes': '',
                                'is_load': false,
                                'settled': true,
                                'category': 'eating_out'
                            }
                        }"
                        );
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    var transaction = await client.AnnotateTransactionAsync("1", new Dictionary <string, string> {
                        { "key1", "value1" }, { "key2", "" }
                    });

                    Assert.AreEqual("foo", transaction.Metadata.First().Key);
                    Assert.AreEqual("bar", transaction.Metadata.First().Value);
                }
            }
        }
예제 #10
0
        public async void CreateAttachment()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("/attachment/register", context.Request.Uri.PathAndQuery);
                    Assert.AreEqual("POST", context.Request.Method);

                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);

                    var formCollection = await context.Request.ReadFormAsync();
                    Assert.AreEqual("tx_00008zIcpb1TB4yeIFXMzx", formCollection["external_id"]);
                    Assert.AreEqual("image/png", formCollection["file_type"]);
                    Assert.AreEqual("https://s3-eu-west-1.amazonaws.com/mondo-image-uploads/user_00009237hliZellUicKuG1/LcCu4ogv1xW28OCcvOTL-foo.png", formCollection["file_url"]);

                    await context.Response.WriteAsync(
                        @"{
                            'attachment': {
                                'id': 'attach_00009238aOAIvVqfb9LrZh',
                                'user_id': 'user_00009238aMBIIrS5Rdncq9',
                                'external_id': 'tx_00008zIcpb1TB4yeIFXMzx',
                                'file_url': 'https://s3-eu-west-1.amazonaws.com/mondo-image-uploads/user_00009237hliZellUicKuG1/LcCu4ogv1xW28OCcvOTL-foo.png',
                                'file_type': 'image/png',
                                'created': '2015-11-12T18:37:02Z'
                            }
                        }"
                        );
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    var attachment = await client.CreateAttachmentAsync("tx_00008zIcpb1TB4yeIFXMzx", "https://s3-eu-west-1.amazonaws.com/mondo-image-uploads/user_00009237hliZellUicKuG1/LcCu4ogv1xW28OCcvOTL-foo.png", "image/png");

                    Assert.AreEqual("attach_00009238aOAIvVqfb9LrZh", attachment.Id);
                    Assert.AreEqual("user_00009238aMBIIrS5Rdncq9", attachment.UserId);
                    Assert.AreEqual("tx_00008zIcpb1TB4yeIFXMzx", attachment.ExternalId);
                    Assert.AreEqual("https://s3-eu-west-1.amazonaws.com/mondo-image-uploads/user_00009237hliZellUicKuG1/LcCu4ogv1xW28OCcvOTL-foo.png", attachment.FileUrl);
                    Assert.AreEqual("image/png", attachment.FileType);
                    Assert.AreEqual(new DateTime(2015, 11, 12, 18, 37, 2, DateTimeKind.Utc), attachment.Created);
                }
            }
        }
예제 #11
0
        public async void DeleteWebhook()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("/webhooks/1", context.Request.Uri.PathAndQuery);
                    Assert.AreEqual("DELETE", context.Request.Method);

                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);

                    await context.Response.WriteAsync("{}");
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    await client.DeleteWebhookAsync("1");
                }
            }
        }
예제 #12
0
        public async void CreateWebhook()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);
                    Assert.AreEqual("POST", context.Request.Method);
                    Assert.AreEqual("/webhooks", context.Request.Uri.PathAndQuery);

                    var formCollection = await context.Request.ReadFormAsync();
                    Assert.AreEqual("1", formCollection["account_id"]);
                    Assert.AreEqual("http://example.com", formCollection["url"]);

                    await context.Response.WriteAsync(
                        @"{
                            'webhook': {
                                'account_id': 'account_id',
                                'id': 'webhook_id',
                                'url': 'http://example.com'
                            }
                        }"
                        );
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    var webhook = await client.CreateWebhookAsync("1", "http://example.com");

                    Assert.AreEqual("account_id", webhook.AccountId);
                    Assert.AreEqual("webhook_id", webhook.Id);
                    Assert.AreEqual("http://example.com", webhook.Url);
                }
            }
        }
예제 #13
0
        public async void DeleteAttachment()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("/attachment/deregister", context.Request.Uri.PathAndQuery);
                    Assert.AreEqual("POST", context.Request.Method);

                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);

                    var formCollection = await context.Request.ReadFormAsync();
                    Assert.AreEqual("attach_00009238aOAIvVqfb9LrZh", formCollection["id"]);

                    await context.Response.WriteAsync("{}");
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    await client.DeleteAttachmentAsync("attach_00009238aOAIvVqfb9LrZh");
                }
            }
        }
예제 #14
0
        public async void DeleteWebhook()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("/webhooks/1", context.Request.Uri.PathAndQuery);
                    Assert.AreEqual("DELETE", context.Request.Method);

                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);

                    await context.Response.WriteAsync("{}");
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    await client.DeleteWebhookAsync("1");
                }
            }
        }
예제 #15
0
        public async void GetWebhooks()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("/webhooks?account_id=1", context.Request.Uri.PathAndQuery);

                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);

                    await context.Response.WriteAsync(
                        @"{
                            'webhooks': [
                                {
                                    'account_id': 'acc_000091yf79yMwNaZHhHGzp',
                                    'id': 'webhook_000091yhhOmrXQaVZ1Irsv',
                                    'url': 'http://example.com/callback'
                                }
                            ]
                        }"
                    );
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    var webhooks = await client.GetWebhooksAsync("1");

                    Assert.AreEqual(1, webhooks.Count);
                    Assert.AreEqual("webhook_000091yhhOmrXQaVZ1Irsv", webhooks[0].Id);
                    Assert.AreEqual("acc_000091yf79yMwNaZHhHGzp", webhooks[0].AccountId);
                    Assert.AreEqual("http://example.com/callback", webhooks[0].Url);
                }
            }
        }
예제 #16
0
        public async void CreateWebhook()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);
                    Assert.AreEqual("POST", context.Request.Method);
                    Assert.AreEqual("/webhooks", context.Request.Uri.PathAndQuery);

                    var formCollection = await context.Request.ReadFormAsync();
                    Assert.AreEqual("1", formCollection["account_id"]);
                    Assert.AreEqual("http://example.com", formCollection["url"]);

                    await context.Response.WriteAsync(
                        @"{
                            'webhook': {
                                'account_id': 'account_id',
                                'id': 'webhook_id',
                                'url': 'http://example.com'
                            }
                        }"
                    );
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    var webhook = await client.CreateWebhookAsync("1", "http://example.com");

                    Assert.AreEqual("account_id", webhook.AccountId);
                    Assert.AreEqual("webhook_id", webhook.Id);
                    Assert.AreEqual("http://example.com", webhook.Url);
                }
            }
        }
예제 #17
0
        public async void CreateFeedItem()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);
                    Assert.AreEqual("POST", context.Request.Method);
                    Assert.AreEqual("/feed", context.Request.Uri.PathAndQuery);

                    var formCollection = await context.Request.ReadFormAsync();
                    Assert.AreEqual("1", formCollection["account_id"]);
                    Assert.AreEqual("basic", formCollection["type"]);
                    Assert.AreEqual("https://www.example.com/a_page_to_open_on_tap.html", formCollection["url"]);
                    Assert.AreEqual("My custom item", formCollection["params[title]"]);

                    await context.Response.WriteAsync("{}");
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    await client.CreateFeedItemAsync("1", "basic", new Dictionary<string, string> { {"title", "My custom item" } }, "https://www.example.com/a_page_to_open_on_tap.html");
                }
            }
        }
예제 #18
0
        public async void AnnotateTransaction()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);
                    Assert.AreEqual("PATCH", context.Request.Method);
                    Assert.AreEqual("/transactions/1", context.Request.Uri.PathAndQuery);

                    var formCollection = await context.Request.ReadFormAsync();

                    Assert.AreEqual("value1", formCollection["metadata[key1]"]);
                    Assert.AreEqual("", formCollection["metadata[key2]"]);

                    await context.Response.WriteAsync(
                        @"{
                            'transaction': {
                                'account_balance': 12334,
                                'amount': -679,
                                'created': '2015-08-23T16:15:03Z',
                                'currency': 'GBP',
                                'description': 'VUE BSL LTD            ISLINGTON     GBR',
                                'id': 'tx_00008zL2INM3xZ41THuRF3',
                                'merchant': 'merch_00008z6uFVhVBcaZzSQwCX',
                                'metadata': {
                                    'foo': 'bar'
                                },
                                'notes': '',
                                'is_load': false,
                                'settled': true,
                                'category': 'eating_out'
                            }
                        }"
                    );
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    var transaction = await client.AnnotateTransactionAsync("1", new Dictionary<string, string> { { "key1", "value1" }, {"key2", "" } });

                    Assert.AreEqual("foo", transaction.Metadata.First().Key);
                    Assert.AreEqual("bar", transaction.Metadata.First().Value);
                }
            }
        }
예제 #19
0
        public async void GetTransactionExpanded()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);
                    
                    // workaround for mono bug
                    Assert.That(context.Request.Uri.PathAndQuery, Is.EqualTo("/transactions/1?expand[]=merchant").Or.EqualTo("/transactions/1?expand%5B%5D=merchant"));

                    await context.Response.WriteAsync(
                        @"{
                            'transaction': {
                                'account_balance': 13013,
                                'amount': -510,
                                'created': '2015-08-22T12:20:18Z',
                                'currency': 'GBP',
                                'description': 'THE DE BEAUVOIR DELI C LONDON        GBR',
                                'id': 'tx_00008zIcpb1TB4yeIFXMzx',
                                'merchant': {
                                    'address': {
                                        'address': '98 Southgate Road',
                                        'city': 'London',
                                        'country': 'GB',
                                        'latitude': 51.54151,
                                        'longitude': -0.08482400000002599,
                                        'postcode': 'N1 3JD',
                                        'region': 'Greater London'
                                    },
                                    'created': '2015-08-22T12:20:18Z',
                                    'group_id': 'grp_00008zIcpbBOaAr7TTP3sv',
                                    'id': 'merch_00008zIcpbAKe8shBxXUtl',
                                    'logo': 'https://pbs.twimg.com/profile_images/527043602623389696/68_SgUWJ.jpeg',
                                    'emoji': '🍞',
                                    'name': 'The De Beauvoir Deli Co.',
                                    'category': 'eating_out'
                                },
                                'metadata': {},
                                'notes': 'Salmon sandwich 🍞',
                                'is_load': false,
                                'settled': true
                            }
                        }"
                    );
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    var transaction = await client.GetTransactionAsync("1", "merchant");

                    Assert.AreEqual(13013, transaction.AccountBalance);
                    Assert.AreEqual(-510, transaction.Amount);
                    Assert.AreEqual(new DateTime(2015, 8, 22, 12, 20, 18, DateTimeKind.Utc), transaction.Created);
                    Assert.AreEqual("GBP", transaction.Currency);
                    Assert.AreEqual("THE DE BEAUVOIR DELI C LONDON        GBR", transaction.Description);
                    Assert.AreEqual("tx_00008zIcpb1TB4yeIFXMzx", transaction.Id);
                    Assert.AreEqual(new Dictionary<string, string>(), transaction.Metadata);
                    Assert.AreEqual("Salmon sandwich 🍞", transaction.Notes);
                    Assert.IsFalse(transaction.IsLoad);

                    Assert.AreEqual("98 Southgate Road", transaction.Merchant.Address.Address);
                    Assert.AreEqual("London", transaction.Merchant.Address.City);
                    Assert.AreEqual(51.54151, transaction.Merchant.Address.Latitude);
                    Assert.AreEqual(-0.08482400000002599, transaction.Merchant.Address.Longitude);
                    Assert.AreEqual("N1 3JD", transaction.Merchant.Address.Postcode);
                    Assert.AreEqual("Greater London", transaction.Merchant.Address.Region);

                    Assert.AreEqual(new DateTime(2015, 8, 22, 12, 20, 18, DateTimeKind.Utc), transaction.Merchant.Created);
                    Assert.AreEqual("grp_00008zIcpbBOaAr7TTP3sv", transaction.Merchant.GroupId);
                    Assert.AreEqual("merch_00008zIcpbAKe8shBxXUtl", transaction.Merchant.Id);
                    Assert.AreEqual("https://pbs.twimg.com/profile_images/527043602623389696/68_SgUWJ.jpeg", transaction.Merchant.Logo);
                    Assert.AreEqual("🍞", transaction.Merchant.Emoji);
                    Assert.AreEqual("The De Beauvoir Deli Co.", transaction.Merchant.Name);
                    Assert.AreEqual("eating_out", transaction.Merchant.Category);
                }
            }
        }
예제 #20
0
        public async void GetTransactions()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    // workaround for mono bug
                    Assert.That(context.Request.Uri.PathAndQuery, Is.EqualTo("/transactions?account_id=1"));

                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);

                    await context.Response.WriteAsync(
                        @"{
                            'transactions': [
                                {
                                    'account_balance': 13013,
                                    'amount': -510,
                                    'created': '2015-08-22T12:20:18Z',
                                    'currency': 'GBP',
                                    'description': 'THE DE BEAUVOIR DELI C LONDON        GBR',
                                    'id': 'tx_00008zIcpb1TB4yeIFXMzx',
                                    'merchant': 'merch_00008zIcpbAKe8shBxXUtl',
                                    'metadata': {},
                                    'notes': 'Salmon sandwich 🍞',
                                    'is_load': false,
                                    'settled': true,
                                    'category': 'eating_out'
                                },
                                {
                                    'account_balance': 12334,
                                    'amount': -679,
                                    'created': '2015-08-23T16:15:03Z',
                                    'currency': 'GBP',
                                    'description': 'VUE BSL LTD            ISLINGTON     GBR',
                                    'id': 'tx_00008zL2INM3xZ41THuRF3',
                                    'merchant': 'merch_00008z6uFVhVBcaZzSQwCX',
                                    'metadata': {},
                                    'notes': '',
                                    'is_load': false,
                                    'settled': true,
                                    'category': 'eating_out'
                                },
                            ]
                        }"
                    );
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    var transactions = await client.GetTransactionsAsync("1");

                    Assert.AreEqual(2, transactions.Count);
                    
                    Assert.AreEqual(13013, transactions[0].AccountBalance);
                    Assert.AreEqual(-510, transactions[0].Amount);
                    Assert.AreEqual(new DateTime(2015, 08, 22, 12, 20, 18, DateTimeKind.Utc), transactions[0].Created);
                    Assert.AreEqual("GBP", transactions[0].Currency);
                    Assert.AreEqual("THE DE BEAUVOIR DELI C LONDON        GBR", transactions[0].Description);
                    Assert.AreEqual("tx_00008zIcpb1TB4yeIFXMzx", transactions[0].Id);
                    Assert.AreEqual("merch_00008zIcpbAKe8shBxXUtl", transactions[0].Merchant.Id);
                    Assert.AreEqual(new Dictionary<string, string>(), transactions[0].Metadata);
                    Assert.AreEqual("Salmon sandwich 🍞", transactions[0].Notes);
                    Assert.IsFalse(transactions[0].IsLoad);
                    Assert.AreEqual("eating_out", transactions[0].Category);
                }
            }
        }
예제 #21
0
        public async void CreateAttachment()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("/attachment/register", context.Request.Uri.PathAndQuery);
                    Assert.AreEqual("POST", context.Request.Method);

                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);

                    var formCollection = await context.Request.ReadFormAsync();
                    Assert.AreEqual("tx_00008zIcpb1TB4yeIFXMzx", formCollection["external_id"]);
                    Assert.AreEqual("image/png", formCollection["file_type"]);
                    Assert.AreEqual("https://s3-eu-west-1.amazonaws.com/mondo-image-uploads/user_00009237hliZellUicKuG1/LcCu4ogv1xW28OCcvOTL-foo.png", formCollection["file_url"]);

                    await context.Response.WriteAsync(
                        @"{
                            'attachment': {
                                'id': 'attach_00009238aOAIvVqfb9LrZh',
                                'user_id': 'user_00009238aMBIIrS5Rdncq9',
                                'external_id': 'tx_00008zIcpb1TB4yeIFXMzx',
                                'file_url': 'https://s3-eu-west-1.amazonaws.com/mondo-image-uploads/user_00009237hliZellUicKuG1/LcCu4ogv1xW28OCcvOTL-foo.png',
                                'file_type': 'image/png',
                                'created': '2015-11-12T18:37:02Z'
                            }
                        }"
                    );
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    var attachment = await client.CreateAttachmentAsync("tx_00008zIcpb1TB4yeIFXMzx", "https://s3-eu-west-1.amazonaws.com/mondo-image-uploads/user_00009237hliZellUicKuG1/LcCu4ogv1xW28OCcvOTL-foo.png", "image/png");

                    Assert.AreEqual("attach_00009238aOAIvVqfb9LrZh", attachment.Id);
                    Assert.AreEqual("user_00009238aMBIIrS5Rdncq9", attachment.UserId);
                    Assert.AreEqual("tx_00008zIcpb1TB4yeIFXMzx", attachment.ExternalId);
                    Assert.AreEqual("https://s3-eu-west-1.amazonaws.com/mondo-image-uploads/user_00009237hliZellUicKuG1/LcCu4ogv1xW28OCcvOTL-foo.png", attachment.FileUrl);
                    Assert.AreEqual("image/png", attachment.FileType);
                    Assert.AreEqual(new DateTime(2015, 11, 12, 18, 37, 2, DateTimeKind.Utc), attachment.Created);
                }
            }
        }
예제 #22
0
        public async void GetTransactions()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    // workaround for mono bug
                    Assert.That(context.Request.Uri.PathAndQuery, Is.EqualTo("/transactions?account_id=1"));

                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);

                    await context.Response.WriteAsync(
                        @"{
                            'transactions': [
                                {
                                    'account_balance': 13013,
                                    'amount': -510,
                                    'created': '2015-08-22T12:20:18Z',
                                    'currency': 'GBP',
                                    'description': 'THE DE BEAUVOIR DELI C LONDON        GBR',
                                    'id': 'tx_00008zIcpb1TB4yeIFXMzx',
                                    'merchant': 'merch_00008zIcpbAKe8shBxXUtl',
                                    'metadata': {},
                                    'notes': 'Salmon sandwich 🍞',
                                    'is_load': false,
                                    'settled': true,
                                    'category': 'eating_out'
                                },
                                {
                                    'account_balance': 12334,
                                    'amount': -679,
                                    'created': '2015-08-23T16:15:03Z',
                                    'currency': 'GBP',
                                    'description': 'VUE BSL LTD            ISLINGTON     GBR',
                                    'id': 'tx_00008zL2INM3xZ41THuRF3',
                                    'merchant': 'merch_00008z6uFVhVBcaZzSQwCX',
                                    'metadata': {},
                                    'notes': '',
                                    'is_load': false,
                                    'settled': true,
                                    'category': 'eating_out'
                                },
                            ]
                        }"
                        );
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    var transactions = await client.GetTransactionsAsync("1");

                    Assert.AreEqual(2, transactions.Count);

                    Assert.AreEqual(13013, transactions[0].AccountBalance);
                    Assert.AreEqual(-510, transactions[0].Amount);
                    Assert.AreEqual(new DateTime(2015, 08, 22, 12, 20, 18, DateTimeKind.Utc), transactions[0].Created);
                    Assert.AreEqual("GBP", transactions[0].Currency);
                    Assert.AreEqual("THE DE BEAUVOIR DELI C LONDON        GBR", transactions[0].Description);
                    Assert.AreEqual("tx_00008zIcpb1TB4yeIFXMzx", transactions[0].Id);
                    Assert.AreEqual("merch_00008zIcpbAKe8shBxXUtl", transactions[0].Merchant.Id);
                    Assert.AreEqual(new Dictionary <string, string>(), transactions[0].Metadata);
                    Assert.AreEqual("Salmon sandwich 🍞", transactions[0].Notes);
                    Assert.IsFalse(transactions[0].IsLoad);
                    Assert.AreEqual("eating_out", transactions[0].Category);
                }
            }
        }
예제 #23
0
        public async void DeleteAttachment()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("/attachment/deregister", context.Request.Uri.PathAndQuery);
                    Assert.AreEqual("POST", context.Request.Method);

                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);

                    var formCollection = await context.Request.ReadFormAsync();
                    Assert.AreEqual("attach_00009238aOAIvVqfb9LrZh", formCollection["id"]);

                    await context.Response.WriteAsync("{}");
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    await client.DeleteAttachmentAsync("attach_00009238aOAIvVqfb9LrZh");
                }
            }
        }
예제 #24
0
        public async void GetTransaction()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);

                    // workaround for mono bug
                    Assert.That(context.Request.Uri.PathAndQuery, Is.EqualTo("/transactions/1"));

                    await context.Response.WriteAsync(
                        @"{
                            'transaction': {
                                'account_balance': 13013,
                                'amount': -510,
                                'created': '2015-08-22T12:20:18Z',
                                'currency': 'GBP',
                                'description': 'THE DE BEAUVOIR DELI C LONDON        GBR',
                                'id': 'tx_00008zIcpb1TB4yeIFXMzx',
                                'merchant': 'merch_00008zIcpbAKe8shBxXUtl',
                                'metadata': {},
                                'notes': 'Salmon sandwich 🍞',
                                'is_load': false,
                                'settled': true
                            }
                        }"
                    );
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    var transaction = await client.GetTransactionAsync("1");

                    Assert.AreEqual(13013, transaction.AccountBalance);
                    Assert.AreEqual(-510, transaction.Amount);
                    Assert.AreEqual(new DateTime(2015, 8, 22, 12, 20, 18, DateTimeKind.Utc), transaction.Created);
                    Assert.AreEqual("GBP", transaction.Currency);
                    Assert.AreEqual("THE DE BEAUVOIR DELI C LONDON        GBR", transaction.Description);
                    Assert.AreEqual("tx_00008zIcpb1TB4yeIFXMzx", transaction.Id);
                    Assert.AreEqual(new Dictionary<string, string>(), transaction.Metadata);
                    Assert.AreEqual("Salmon sandwich 🍞", transaction.Notes);
                    Assert.IsFalse(transaction.IsLoad);

                    Assert.AreEqual("merch_00008zIcpbAKe8shBxXUtl", transaction.Merchant.Id);
                }
            }
        }
        private async void Login()
        {
            try
            {
                if (string.IsNullOrWhiteSpace(_loginPageViewModel.Username) ||
                    string.IsNullOrWhiteSpace(_loginPageViewModel.Password))
                {
                    _loginPageViewModel.ErrorMessage = "Please enter your username and password.";
                    return;
                }

                _loginPageViewModel.ErrorMessage = null;
                _loginPageViewModel.IsEnabled    = false;
                _loginPageViewModel.IsBusy       = true;

                _loginPageViewModel.StatusText = "Authenticating...";

                _loginPageViewModel.AccessToken = await _mondoAuthorizationClient.AuthenticateAsync(_loginPageViewModel.Username, _loginPageViewModel.Password);

                using (var mondoClient = new MondoClient(_loginPageViewModel.AccessToken.Value, "https://production-api.gmon.io"))
                {
                    ScheduleAccessTokenRefresh();

                    _loginPageViewModel.StatusText = "Fetching accounts...";
                    IList <Account> accounts = await mondoClient.GetAccountsAsync();

                    _loginPageViewModel.StatusText = "Fetching balance...";
                    Balance balance = await mondoClient.GetBalanceAsync(accounts[0].Id);

                    _loginPageViewModel.StatusText = "Fetching transactions...";
                    IList <Transaction> transactions =
                        await mondoClient.GetTransactionsAsync(accounts[0].Id, expand : "merchant");

                    _accountPageViewModel.AccountName = accounts[0].Description;
                    _accountPageViewModel.Balance     = balance.Value / 100m;
                    _accountPageViewModel.SpentToday  = Math.Abs(balance.SpendToday / 100m);

                    foreach (Transaction transaction in transactions.OrderByDescending(t => t.Created))
                    {
                        var transactionViewModel = new TransactionViewModel();

                        transactionViewModel.Amount      = transaction.Amount / 100m;
                        transactionViewModel.ImageUrl    = transaction.Merchant?.Logo;
                        transactionViewModel.Description = transaction.Merchant?.Name ?? transaction.Description;

                        _accountPageViewModel.Transactions.Add(transactionViewModel);
                    }

                    _navigationService.NavigateTo <AccountSummaryPage>(_accountPageViewModel);

                    _loginPageViewModel.Password = null;
                    _loginPageViewModel.Username = null;
                }
            }
            catch (Exception ex)
            {
                _loginPageViewModel.ErrorMessage = ex.Message;
            }
            finally
            {
                _loginPageViewModel.StatusText = null;
                _loginPageViewModel.IsBusy     = false;
                _loginPageViewModel.IsEnabled  = true;
            }
        }
예제 #26
0
        public async void GetTransactionExpanded()
        {
            using (var server = TestServer.Create(app =>
            {
                app.Run(async context =>
                {
                    Assert.AreEqual("Bearer testAccessToken", context.Request.Headers["Authorization"]);

                    // workaround for mono bug
                    Assert.That(context.Request.Uri.PathAndQuery, Is.EqualTo("/transactions/1?expand[]=merchant").Or.EqualTo("/transactions/1?expand%5B%5D=merchant"));

                    await context.Response.WriteAsync(
                        @"{
                            'transaction': {
                                'account_balance': 13013,
                                'amount': -510,
                                'created': '2015-08-22T12:20:18Z',
                                'currency': 'GBP',
                                'description': 'THE DE BEAUVOIR DELI C LONDON        GBR',
                                'id': 'tx_00008zIcpb1TB4yeIFXMzx',
                                'merchant': {
                                    'address': {
                                        'address': '98 Southgate Road',
                                        'city': 'London',
                                        'country': 'GB',
                                        'latitude': 51.54151,
                                        'longitude': -0.08482400000002599,
                                        'postcode': 'N1 3JD',
                                        'region': 'Greater London'
                                    },
                                    'created': '2015-08-22T12:20:18Z',
                                    'group_id': 'grp_00008zIcpbBOaAr7TTP3sv',
                                    'id': 'merch_00008zIcpbAKe8shBxXUtl',
                                    'logo': 'https://pbs.twimg.com/profile_images/527043602623389696/68_SgUWJ.jpeg',
                                    'emoji': '🍞',
                                    'name': 'The De Beauvoir Deli Co.',
                                    'category': 'eating_out'
                                },
                                'metadata': {},
                                'notes': 'Salmon sandwich 🍞',
                                'is_load': false,
                                'settled': true
                            }
                        }"
                        );
                });
            }))
            {
                using (var client = new MondoClient(server.HttpClient, "testAccessToken"))
                {
                    var transaction = await client.GetTransactionAsync("1", "merchant");

                    Assert.AreEqual(13013, transaction.AccountBalance);
                    Assert.AreEqual(-510, transaction.Amount);
                    Assert.AreEqual(new DateTime(2015, 8, 22, 12, 20, 18, DateTimeKind.Utc), transaction.Created);
                    Assert.AreEqual("GBP", transaction.Currency);
                    Assert.AreEqual("THE DE BEAUVOIR DELI C LONDON        GBR", transaction.Description);
                    Assert.AreEqual("tx_00008zIcpb1TB4yeIFXMzx", transaction.Id);
                    Assert.AreEqual(new Dictionary <string, string>(), transaction.Metadata);
                    Assert.AreEqual("Salmon sandwich 🍞", transaction.Notes);
                    Assert.IsFalse(transaction.IsLoad);

                    Assert.AreEqual("98 Southgate Road", transaction.Merchant.Address.Address);
                    Assert.AreEqual("London", transaction.Merchant.Address.City);
                    Assert.AreEqual(51.54151, transaction.Merchant.Address.Latitude);
                    Assert.AreEqual(-0.08482400000002599, transaction.Merchant.Address.Longitude);
                    Assert.AreEqual("N1 3JD", transaction.Merchant.Address.Postcode);
                    Assert.AreEqual("Greater London", transaction.Merchant.Address.Region);

                    Assert.AreEqual(new DateTime(2015, 8, 22, 12, 20, 18, DateTimeKind.Utc), transaction.Merchant.Created);
                    Assert.AreEqual("grp_00008zIcpbBOaAr7TTP3sv", transaction.Merchant.GroupId);
                    Assert.AreEqual("merch_00008zIcpbAKe8shBxXUtl", transaction.Merchant.Id);
                    Assert.AreEqual("https://pbs.twimg.com/profile_images/527043602623389696/68_SgUWJ.jpeg", transaction.Merchant.Logo);
                    Assert.AreEqual("🍞", transaction.Merchant.Emoji);
                    Assert.AreEqual("The De Beauvoir Deli Co.", transaction.Merchant.Name);
                    Assert.AreEqual("eating_out", transaction.Merchant.Category);
                }
            }
        }