public void AuthenticationShouldSucceed()
        {
            const string testBaseUri        = "https://127.0.0.1";
            const string expectedRequestUrl = testBaseUri + "/v15/access_tokens";

            const string testClientId         = "1a2b3c4d5e6f7g8h9i0j";
            const string testMerchantUsername = "******";
            const string testMerchantPassword = "******";

            string expectedRequestbody = string.Format("{{\"access_token\": {{" +
                                                       "\"api_key\": \"{0}\"" +
                                                       ",\"username\": \"{1}\"" +
                                                       ",\"password\": \"{2}\"" +
                                                       "}}}}",
                                                       testClientId,
                                                       testMerchantUsername,
                                                       testMerchantPassword);

            // This response format does not matter for this test.
            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
            };

            IAuthenticate auth =
                ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <IAuthenticate, AccessTokenRequest>(
                    expectedResponse,
                    expectedRequestbody,
                    expectedAccessToken: null,
                    expectedRequestUrl: expectedRequestUrl,
                    environmentToUse: new LevelUpEnvironment(testBaseUri));

            var token = auth.Authenticate(testClientId, testMerchantUsername, testMerchantPassword);
        }
        public void ListOrdersShouldSucceedWhenMorePagesQueriedThanExist()
        {
            IQueryOrders client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModuleWithPaging <IQueryOrders>(successfulResponses, expectedRequestBaseUrl);
            var          orders = client.ListOrders("not_checking_this", locationId, 1, 10); // Note that we specify pages 1-10 when only 3 pages exist

            Assert.AreEqual(orders.Count, 9);
        }
Пример #3
0
        public void RetrieveMerchantFundedGiftCardCreditShouldPass()
        {
            const int    locationId      = 19;
            const string qr_code         = "LU02000008ZS9OJFUBNEL6ZM030000LU";
            const int    gift_card_total = 2000;
            const string auth_Token      = "example_auth_token";

            string expectedRequestUrl = string.Format("https://sandbox.thelevelup.com/v15/locations/{0}/get_merchant_funded_gift_card_credit", locationId);

            string expectedRequestbody = string.Format(
                "{{\"get_merchant_funded_gift_card_credit\": {{\"payment_token_data\": \"{0}\"}} }}", qr_code);

            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    = string.Format("{{\"merchant_funded_gift_card_credit\": {{\"total_amount\": {0} }} }}", gift_card_total)
            };

            IRetrieveMerchantFundedGiftCardCredit client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule
                                                           <IRetrieveMerchantFundedGiftCardCredit, GiftCardCreditQueryRequest>(expectedResponse, expectedRequestbody,
                                                                                                                               expectedAccessToken: auth_Token, expectedRequestUrl: expectedRequestUrl);

            var credit = client.GetMerchantFundedGiftCardCredit(auth_Token, locationId, qr_code);

            Assert.AreEqual(credit.TotalAmount, gift_card_total);
        }
        public void ListFilteredOrdersShouldSucceedWithNoModifierFunctions()
        {
            IQueryOrders client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModuleWithPaging <IQueryOrders>(
                successfulResponses, expectedRequestBaseUrl);
            var orders = client.ListFilteredOrders("not_checking_this", locationId, 1, 3);

            Assert.AreEqual(orders.Count, 9);
        }
        public void ListOrdersShouldFailWith204ForInvalidStartPageNumbers()
        {
            IQueryOrders client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModuleWithPaging <IQueryOrders>(
                successfulResponses, expectedRequestBaseUrl);
            var orders = client.ListOrders("not_checking_this", locationId, 5, 10);

            Assert.AreEqual(orders.Count, 0);
        }
        public void CreateCreditCardShouldSucceed()
        {
            const string expectedRequestUrl = "https://sandbox.thelevelup.com/v15/credit_cards";

            // The below strings can be arbitrary for the purposes of this test -- These are just the examples from the api docs.
            const string encrypted_cvv = "$bt4|javascript_1_3_9$Zar7J1+0QNsrHtKFufeJ8UCpSd5RM1PwTjzNE1Dm1N0A969OuWfU03...";
            const string encrypted_expiration_month = "$bt4|javascript_1_3_9$7ad9aydahduiw+89w7dHusaihdas...";
            const string encrypted_expiration_year  = "$bt4|javascript_1_3_9$9asdjaIjashuUHsj+saiUSj...";
            const string encrypted_number           = "$bt4|javascript_1_3_9$FyreT+o2W/9VHHjS43ZJJe2SmdvTBcve58...";
            const string postal_code = "12345";

            string expectedRequestbody = string.Format(
                "{{" +
                "\"credit_card\": {{" +
                "\"encrypted_cvv\": \"{0}\"," +
                "\"encrypted_expiration_month\": \"{1}\"," +
                "\"encrypted_expiration_year\": \"{2}\"," +
                "\"encrypted_number\": \"{3}\"," +
                "\"postal_code\": \"{4}\" " +
                "}}" +
                "}}", encrypted_cvv, encrypted_expiration_month, encrypted_expiration_year, encrypted_number, postal_code);

            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    = "{" +
                             "\"credit_card\": {" +
                             "\"bin\": \"123456\"," +
                             "\"description\": \"JCB ending in 1234\"," +
                             "\"expiration_month\": 7," +
                             "\"expiration_year\": 2015," +
                             "\"id\": 305999," +
                             "\"last_4\": \"1234\"," +
                             "\"promoted\": true," +
                             "\"state\": \"active\"," +
                             "\"type\": \"JCB\"" +
                             "}" +
                             "}"
            };

            const string accessToken = "abc";

            ICreateCreditCards client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <ICreateCreditCards, CreateCreditCardRequest>(
                expectedResponse, expectedRequestbody, expectedAccessToken: accessToken, expectedRequestUrl: expectedRequestUrl);
            var card = client.CreateCreditCard(accessToken, encrypted_number, encrypted_expiration_month, encrypted_expiration_year, encrypted_cvv, postal_code);

            Assert.AreEqual(card.Bin, "123456");
            Assert.AreEqual(card.Description, "JCB ending in 1234");
            Assert.AreEqual(card.ExpirationMonth, 7);
            Assert.AreEqual(card.ExpirationYear, 2015);
            Assert.AreEqual(card.Id, 305999);
            Assert.AreEqual(card.Last4Numbers, "1234");
            Assert.AreEqual(card.Promoted, true);
            Assert.AreEqual(card.State, "active");
            Assert.AreEqual(card.Type, "JCB");
        }
        public void RefundOrderShouldSucceedSansManagerConfirmation()
        {
            const string uuid                          = "bf143c9084810132faf95a123bd6cde9";
            const string created_at                    = "2015-01-22T11:29:22-05:00";
            const int    location_id                   = 19;
            const int    loyalty_id                    = 20;
            const string refunded_at                   = "2015-01-22T14:28:05-05:00";
            const string user_display_name             = "TestCredsT.";
            const int    earn_amount                   = 0;
            const int    merchant_funded_credit_amount = 0;
            const int    spend_amount                  = 10;
            const int    tip_amount                    = 0;
            const int    total_amount                  = 10;


            string expectedRequestUrl = string.Format("https://sandbox.thelevelup.com/v15/orders/{0}/refund", uuid);

            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    = string.Format("{{" +
                                           "\"order\":{{" +
                                           "\"created_at\":\"{0}\"," +
                                           "\"location_id\":{1}," +
                                           "\"loyalty_id\":{2}," +
                                           "\"refunded_at\":\"{3}\"," +
                                           "\"user_display_name\":\"{4}\"," +
                                           "\"uuid\":\"{5}\"," +
                                           "\"earn_amount\":{6}," +
                                           "\"merchant_funded_credit_amount\":{7}," +
                                           "\"spend_amount\":{8}," +
                                           "\"tip_amount\":{9}," +
                                           "\"total_amount\":{10}" +
                                           "}}" +
                                           "}}", created_at, location_id, loyalty_id, refunded_at, user_display_name, uuid, earn_amount,
                                           merchant_funded_credit_amount, spend_amount, tip_amount, total_amount)
            };

            string expectedRequest = string.Empty;

            ICreateRefund client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <ICreateRefund, RefundRequest>(
                expectedResponse, expectedRequest, expectedRequestUrl: expectedRequestUrl);
            var order = client.RefundOrder("not_checking_this", uuid);

            Assert.AreEqual(order.EarnAmount, earn_amount);
            Assert.AreEqual(order.LocationId, location_id);
            Assert.AreEqual(order.LoyaltyId, loyalty_id);
            Assert.AreEqual(order.MerchantFundedCreditAmount, merchant_funded_credit_amount);
            Assert.AreEqual(order.OrderIdentifier, uuid);
            Assert.AreEqual(order.SpendAmount, spend_amount);
            Assert.AreEqual(order.TipAmount, tip_amount);
            Assert.AreEqual(order.UserName, user_display_name);
            Assert.AreEqual(order.TimeOfRefund, refunded_at);
            Assert.AreEqual(order.CreatedAt, created_at);
        }
        public void ListFilteredOrdersShouldSucceedWithAnOrderingFunction()
        {
            IQueryOrders client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModuleWithPaging <IQueryOrders>(
                successfulResponses, expectedRequestBaseUrl);
            var orders = client.ListFilteredOrders("not_checking_this", locationId, 1, 3, null,
                                                   ((x, y) => (0 - string.Compare(x.OrderIdentifier, y.OrderIdentifier)))); // i.e. orderbydecending

            Assert.AreEqual(orders.Count, 9);
            Assert.AreEqual(orders[0].OrderIdentifier, "i");
            Assert.AreEqual(orders[8].OrderIdentifier, "a");
        }
        public void ListOrdersShouldSucceedDespiteInvalidEndPageNumbers()
        {
            IQueryOrders client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModuleWithPaging <IQueryOrders>(successfulResponses, expectedRequestBaseUrl);

            var orders = client.ListOrders("not_checking_this", locationId, 1, 10);

            Assert.AreEqual(orders.Count, 9);

            orders = client.ListOrders("not_checking_this", locationId, 3, 11);
            Assert.AreEqual(orders.Count, 3);
        }
        public void ListFilteredOrdersShouldSucceedWithAFilterFunction()
        {
            IQueryOrders client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModuleWithPaging <IQueryOrders>(
                successfulResponses, expectedRequestBaseUrl);
            var orders = client.ListFilteredOrders("not_checking_this", locationId, 1, 3,
                                                   (x => (x.OrderIdentifier == "c" || x.OrderIdentifier == "i")), null);

            Assert.AreEqual(orders.Count, 2);
            Assert.AreEqual(orders[0].OrderIdentifier, "c");
            Assert.AreEqual(orders[1].OrderIdentifier, "i");
        }
        public void GetLoyaltyShouldSucceed()
        {
            const int     merchant_Id             = 456;
            const int     merchant_earn_amount    = 500;
            const int     merchant_spend_amount   = 5000;
            const int     orders_count            = 77;
            const int     potential_credit_amount = 7350;
            const int     savings_amount          = 835;
            const int     spend_remaining_amount  = 427;
            const int     total_volume_amount     = 6317;
            const int     user_id = 789;
            const bool    merchant_loyalty_enabled = true;
            const decimal progress_percentage      = 42.0m;

            string expectedRequestUrl = string.Format("https://sandbox.thelevelup.com/v14/merchants/{0}/loyalty", merchant_Id);

            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    = string.Format("{{" +
                                           "\"loyalty\":{{" +
                                           "\"merchant_earn_amount\":{0}," +
                                           "\"merchant_id\":{1}," +
                                           "\"merchant_loyalty_enabled\":{2}," +
                                           "\"merchant_spend_amount\":{3}," +
                                           "\"orders_count\":{4}," +
                                           "\"potential_credit_amount\":{5}," +
                                           "\"progress_percentage\":{6}," +
                                           "\"savings_amount\":{7}," +
                                           "\"spend_remaining_amount\":{8}," +
                                           "\"total_volume_amount\":{9}," +
                                           "\"user_id\":{10}" +
                                           "}}" +
                                           "}}", merchant_earn_amount, merchant_Id, merchant_loyalty_enabled ? "true" : "false", merchant_spend_amount, orders_count,
                                           potential_credit_amount, progress_percentage, savings_amount, spend_remaining_amount, total_volume_amount, user_id)
            };

            ILookupUserLoyalty client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <ILookupUserLoyalty>(
                expectedResponse, expectedRequestUrl: expectedRequestUrl);

            var loyalty = client.GetLoyalty("not_checking_this", merchant_Id);

            Assert.AreEqual(loyalty.MerchantEarnAmount, merchant_earn_amount);
            Assert.AreEqual(loyalty.MerchantId, merchant_Id);
            Assert.AreEqual(loyalty.MerchantLoyaltyEnabled, merchant_loyalty_enabled);
            Assert.AreEqual(loyalty.MerchantSpendAmount, merchant_spend_amount);
            Assert.AreEqual(loyalty.OrdersCount, orders_count);
            Assert.AreEqual(loyalty.PotentialCreditAmount, potential_credit_amount);
            Assert.AreEqual(loyalty.ProgressPercentage, progress_percentage);
            Assert.AreEqual(loyalty.SavingsAmount, savings_amount);
            Assert.AreEqual(loyalty.SpendRemainingAmount, spend_remaining_amount);
            Assert.AreEqual(loyalty.TotalVolumeAmount, total_volume_amount);
            Assert.AreEqual(loyalty.UserId, user_id);
        }
        public void UpdateUserShouldSucceed()
        {
            string expectedRequestUrl = "https://sandbox.thelevelup.com/v14/users/123";

            IModifyUser client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <IModifyUser>(
                expectedCreateOrUpdateUserResponse, expectedRequestUrl: expectedRequestUrl);
            var user = client.UpdateUser("not_checking_this", new UpdateUserRequestBody(123));

            Assert.AreEqual(user.GlobalCreditAmount, globalCreditAmount);
            Assert.AreEqual(user.Gender, gender);
            Assert.AreEqual(user.CustomAttributes[customAttributes.Key], customAttributes.Value);
        }
        public void GiftCardAddValueShouldSucceed()
        {
            const string accessToken              = "abc";
            const int    merchant_id              = 3554;
            const string payment_token_data       = "LU020000029080KFZ02I9A8V030000LU";
            const int    value_amount             = 1000;
            const int    location_id              = 1234;
            const string order_uuid               = "a7e23820d56802321bb64ab3b58dfe6c";
            const string identifier_from_merchant = "012345";
            const string tender_types             = "cash";

            string expectedRequestUrl = string.Format("https://sandbox.thelevelup.com/v15/merchants/{0}/gift_card_value_additions", merchant_id);

            string expectedRequestbody = string.Format(
                "{{" +
                "\"gift_card_value_addition\": {{" +
                "\"payment_token_data\": \"{0}\"," +
                "\"value_amount\": {1}," +
                "\"location_id\": {2}," +
                "\"order_uuid\": \"{3}\"," +
                "\"tender_types\": [\"{4}\"], " +
                "\"identifier_from_merchant\": \"{5}\" " +
                "}}" +
                "}}", payment_token_data, value_amount, location_id, order_uuid, tender_types, identifier_from_merchant);

            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    = "{" +
                             "\"gift_card_value_addition\": {" +
                             "\"added_value_amount\": 1000," +
                             "\"new_value_at_merchant_amount\": 1000," +
                             "\"old_value_at_merchant_amount\": 0," +
                             "}" +
                             "}"
            };

            ICreateGiftCardValue client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <ICreateGiftCardValue, GiftCardAddValueRequest>(
                expectedResponse, expectedRequestbody, expectedAccessToken: accessToken, expectedRequestUrl: expectedRequestUrl);

            var valueAddition = client.GiftCardAddValue(accessToken,
                                                        merchant_id,
                                                        location_id,
                                                        payment_token_data,
                                                        value_amount,
                                                        identifier_from_merchant,
                                                        new List <string>(new[] { tender_types }),
                                                        order_uuid);

            Assert.AreEqual(valueAddition.AmountAddedInCents, 1000);
            Assert.AreEqual(valueAddition.NewGiftCardAmountInCents, 1000);
            Assert.AreEqual(valueAddition.PreviousGiftCardAmountInCents, 0);
        }
        public void CompleteProposedOrderShouldSucceedForDiscountsDisabled()
        {
            string expectedRequestUrl = "https://sandbox.thelevelup.com/v15/completed_orders";

            string expectedRequest = "{" +
                                     "\"completed_order\": {" +
                                     "\"applied_discount_amount\": null," +
                                     "\"cashier\": \"Bob\"," +
                                     "\"exemption_amount\": 40," +
                                     "\"identifier_from_merchant\": \"001001\"," +
                                     "\"location_id\": 19," +
                                     "\"partial_authorization_allowed\": false," +
                                     "\"payment_token_data\": \"LU02000008ZS9OJFUBNEL6ZM030000LU\"," +
                                     "\"proposed_order_uuid\": \"1b3b3c4d5e6f7g8a9i9h8g7f6e5d4c3b2a1\"," +
                                     "\"receipt_message_html\": \"Pick up your order at <strong>counter #4</strong>\"," +
                                     "\"register\": \"3\"," +
                                     "\"spend_amount\": 200," +
                                     "\"tax_amount\": 0," +
                                     GetSampleItems().Item1 +
                                     "}" +
                                     "}";

            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    = "{ " +
                             "\"order\": { " +
                             "\"gift_card_total_amount\": 0, " +
                             "\"gift_card_tip_amount\": 0, " +
                             "\"spend_amount\": 200, " +
                             "\"tip_amount\": 0, " +
                             "\"total_amount\": 200, " +
                             "\"uuid\": \"5a1z9x2h31ah7g8a9i9h8g7f6e5d4c4a21o\"" +
                             "}" +
                             "}"
            };

            var items = GetSampleItems().Item2;

            IManageProposedOrders client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <IManageProposedOrders, CompleteProposedOrderRequest>(
                expectedResponse, expectedRequest, expectedRequestUrl: expectedRequestUrl);
            var completedOrder = client.CompleteProposedOrder("not_checking_this", 19, "LU02000008ZS9OJFUBNEL6ZM030000LU",
                                                              "1b3b3c4d5e6f7g8a9i9h8g7f6e5d4c3b2a1", 300, 200, 10, 130, null, "3", "Bob", "001001",
                                                              "Pick up your order at <strong>counter #4</strong>", false, items);

            Assert.AreEqual(completedOrder.GiftCardTotalAmount, 0);
            Assert.AreEqual(completedOrder.GiftCardTipAmount, 0);
            Assert.AreEqual(completedOrder.SpendAmount, 200);
            Assert.AreEqual(completedOrder.TipAmount, 0);
            Assert.AreEqual(completedOrder.Total, 200);
            Assert.AreEqual(completedOrder.OrderIdentifier, "5a1z9x2h31ah7g8a9i9h8g7f6e5d4c4a21o");
        }
        public void AuthenticationShouldFailForErrorCode404NotFound()
        {
            const string testClientId         = "1212whatsinthestew34noonesreallysure";
            const string testMerchantUsername = "******";
            const string testMerchantPassword = "******";

            RestResponse expected = new RestResponse {
                StatusCode = HttpStatusCode.NotFound
            };
            IAuthenticate auth = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <IAuthenticate>(expected);

            // Should throw exception for non-200 [OK] response
            auth.Authenticate(testClientId, testMerchantUsername, testMerchantPassword);
        }
Пример #16
0
        public void GetLocationDetailsShouldSucceed()
        {
            const int locationId = 17;

            string expectedRequestUrl = "https://sandbox.thelevelup.com/v15/locations/" + locationId;

            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    = string.Format("{{" +
                                           "\"location\": {{" +
                                           "\"categories\": [" +
                                           "50" +
                                           "]," +
                                           "\"extended_address\": \"\"," +
                                           "\"facebook_url\": \"http://www.facebook.com/pages/PizzaPalace\"," +
                                           "\"foodler_url\": \"http://deeplink.me/www.foodler.com/pizza-palace/1234\"," +
                                           "\"hours\": null," +
                                           "\"id\": {0}," +
                                           "\"latitude\": 42.351639," +
                                           "\"locality\": \"Boston\"," +
                                           "\"longitude\": -71.121797," +
                                           "\"menu_url\": null," +
                                           "\"merchant_id\": 18," +
                                           "\"merchant_description_html\": \"This is a place that has pizza!\"," +
                                           "\"merchant_name\": \"Pizza Palace\"," +
                                           "\"merchant_tip_preference\": \"no preference\"," +
                                           "\"name\": null," +
                                           "\"newsletter_url\": null," +
                                           "\"opentable_url\": null," +
                                           "\"phone\": null," +
                                           "\"postal_code\": \"02215\"," +
                                           "\"region\": \"MA\"," +
                                           "\"street_address\": \"1024 Pizza Road\"," +
                                           "\"twitter_url\": null," +
                                           "\"updated_at\": \"2014-11-30T10:28:23-05:00\"," +
                                           "\"yelp_url\": \"http://www.yelp.com/biz/pizza-palace\"," +
                                           "\"shown\": true" +
                                           "}}" +
                                           "}}", locationId)
            };

            IQueryMerchantData client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <IQueryMerchantData>(
                expectedResponse, expectedRequestUrl: expectedRequestUrl);
            var details = client.GetLocationDetails("not_checking_this", locationId);

            Assert.AreEqual(details.LocationId, locationId);
            Assert.AreEqual(details.Address.PostalCode, "02215");
        }
        public void GetLoyaltyShouldFailForBadStatusCode()
        {
            const int merchant_Id        = 456;
            string    expectedRequestUrl = string.Format("https://sandbox.thelevelup.com/v14/merchants/{0}/loyalty", merchant_Id);

            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.NotFound,
            };

            ILookupUserLoyalty client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <ILookupUserLoyalty>(
                expectedResponse, expectedRequestUrl: expectedRequestUrl);

            client.GetLoyalty("not_checking_this", merchant_Id);
        }
        public void PasswordResetRequestShouldSucceed()
        {
            const string expectedRequestUrl  = "https://sandbox.thelevelup.com/v14/passwords";
            const string expectedRequestBody = "{\"email\": \"[email protected]\"}";

            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.NoContent
            };

            IModifyUser client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <IModifyUser, PasswordResetRequest>(
                expectedResponse, expectedRequestBody, expectedRequestUrl);

            client.PasswordResetRequest("*****@*****.**");
        }
        public void ListOrdersShouldSucceedWhenAllPagesQueried()
        {
            IQueryOrders client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModuleWithPaging <IQueryOrders>(successfulResponses, expectedRequestBaseUrl);
            var          orders = client.ListOrders("not_checking_this", locationId, 1, 3);

            Assert.AreEqual(orders.Count, 9);
            Assert.AreEqual(orders[0].OrderIdentifier, "a");
            Assert.AreEqual(orders[1].OrderIdentifier, "b");
            Assert.AreEqual(orders[2].OrderIdentifier, "c");
            Assert.AreEqual(orders[3].OrderIdentifier, "d");
            Assert.AreEqual(orders[4].OrderIdentifier, "e");
            Assert.AreEqual(orders[5].OrderIdentifier, "f");
            Assert.AreEqual(orders[6].OrderIdentifier, "g");
            Assert.AreEqual(orders[7].OrderIdentifier, "h");
            Assert.AreEqual(orders[8].OrderIdentifier, "i");
        }
        public void CreateDetachedRefundShouldFailDeserialization()
        {
            // Note: This test is not really specific to Detached Refunds.
            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    = "{{" +
                             "\"detached_refund\": {{" +
                             "\"cashier\": \"blah\"," +
                             "}}" +
                             "}}"
            };

            ICreateDetachedRefund client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <ICreateDetachedRefund>(expectedResponse);
            var resp = client.CreateDetachedRefund("we", 0, "are", 0, "not", "checking", "any", "of", "these", "strings");
        }
        public void ListCreditCardsShouldSucceed()
        {
            string expectedRequestUrl = "https://sandbox.thelevelup.com/v15/credit_cards";

            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    =
                    "[" +
                    "{" +
                    "\"credit_card\": {" +
                    "\"bin\": \"123456\"," +
                    "\"description\": \"JCB ending in 1234\"," +
                    "\"expiration_month\": 7," +
                    "\"expiration_year\": 2015," +
                    "\"id\": 305999," +
                    "\"last_4\": \"1234\"," +
                    "\"promoted\": true," +
                    "\"state\": \"active\"," +
                    "\"type\": \"JCB\"" +
                    "}" +
                    "}," +
                    "{" +
                    "\"credit_card\": {" +
                    "\"bin\": \"654321\"," +
                    "\"description\": \"JCB ending in 4321\"," +
                    "\"expiration_month\": 3," +
                    "\"expiration_year\": 2015," +
                    "\"id\": 999503," +
                    "\"last_4\": \"4321\"," +
                    "\"promoted\": false," +
                    "\"state\": \"active\"," +
                    "\"type\": \"JCB\"" +
                    "}" +
                    "}" +
                    "]"
            };

            IQueryCreditCards client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <IQueryCreditCards>(
                expectedResponse, expectedAccessToken: "access_token", expectedRequestUrl: expectedRequestUrl);
            var cards = client.ListCreditCards("access_token");

            Assert.AreEqual(cards.Count, 2);
            Assert.AreEqual(cards[0].Bin, "123456");
            Assert.AreEqual(cards[1].Bin, "654321");
        }
        public void ListOrdersShouldSucceedAndAreThereMorePagesShouldBeValid()
        {
            IQueryOrders client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModuleWithPaging <IQueryOrders>(successfulResponses, expectedRequestBaseUrl);
            bool         areThereMorePages;

            var orders = client.ListOrders("not_checking_this", locationId, 1, 1, out areThereMorePages);

            Assert.IsTrue(areThereMorePages);

            orders = client.ListOrders("not_checking_this", locationId, 1, 3, out areThereMorePages);
            Assert.IsFalse(areThereMorePages);

            orders = client.ListOrders("not_checking_this", locationId, 3, 3, out areThereMorePages);
            Assert.IsFalse(areThereMorePages);

            orders = client.ListOrders("not_checking_this", locationId, 2, 5, out areThereMorePages);
            Assert.IsFalse(areThereMorePages);
        }
        public void CreateCreditCardShouldFailForInvalidCardDetails()
        {
            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = (HttpStatusCode)422,
                Content    = "[{\"error\":{\"object\":\"credit_card\",\"property\":\"expiration_year\",\"message\":\"Expiration year is invalid.\"}}]"
            };

            try
            {
                ICreateCreditCards client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <ICreateCreditCards>(expectedResponse);
                var card = client.CreateCreditCard("abc", new CreateCreditCardRequestBody("we", "aren't", "checking", "these", "params"));
                Assert.IsTrue(false, "Failed to throw a LevelUpApiException for invalid card data (422 response code)");
            }
            catch (LevelUpApiException ex)
            {
                Assert.AreEqual((int)ex.StatusCode, 422);
                Assert.AreEqual(ex.Message.Trim(), "Expiration year is invalid.");
            }
        }
Пример #24
0
        public void ListManagedLocationsShouldSucceed()
        {
            string expectedRequestUrl = "https://sandbox.thelevelup.com/v15/managed_locations";

            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    =
                    "[{" +
                    "\"location\": {" +
                    "\"address\": \"101 Arch St., Boston, MA\"," +
                    "\"id\": 3," +
                    "\"merchant_id\": 1," +
                    "\"merchant_name\": \"LevelUp Cafe\"," +
                    "\"name\": \"LU#3 - 101 Arch St.\"," +
                    "\"tip_preference\": \"expected\"" +
                    "}" +
                    "}," +
                    "{" +
                    "\"location\": {" +
                    "\"address\": \"1 Beach Dr, Honolulu, HI\"," +
                    "\"id\": 10," +
                    "\"merchant_id\": 1001," +
                    "\"merchant_name\": \"Hang Ten Cafe\"," +
                    "\"name\": \"LU#10 - 1 Beach Dr.\"," +
                    "\"tip_preference\": \"unwanted\"" +
                    "}" +
                    "}]"
            };

            string expectedAccessToken = "token merchant=\"my_access_token\"";

            IQueryMerchantData client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <IQueryMerchantData>(
                expectedResponse, expectedRequestUrl: expectedRequestUrl, expectedAccessToken: expectedAccessToken);
            var locations = client.ListManagedLocations("my_access_token");

            Assert.IsTrue(locations.Count == 2);
            Assert.IsTrue(locations[0].LocationId == 3);
            Assert.IsTrue(locations[0].TipPreference == "expected");
        }
        public void GiftCardDestroyValueShouldSucceed()
        {
            string paymentTokenData = "LU020000029080KFZ02I9A8V030000LU";
            int    merchantId       = 3;
            int    valueAmountCents = 100;
            int    initialTotalValueAtMerchantCents = 202;

            string expectedRequestUrl = string.Format("https://sandbox.thelevelup.com/v15/merchants/{0}/gift_card_value_removals", merchantId);

            string expectedRequestBody = string.Format("{{" +
                                                       "\"gift_card_value_removal\":{{" +
                                                       "\"payment_token_data\":\"{0}\"," +
                                                       "\"value_amount\":{1}" +
                                                       "}}" +
                                                       "}}",
                                                       paymentTokenData, valueAmountCents);


            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    = string.Format("{{" +
                                           "\"gift_card_value_removal\":{{" +
                                           "\"removed_value_amount\":{0}," +
                                           "\"new_value_at_merchant_amount\":{1}," +
                                           "\"old_value_at_merchant_amount\":{2}," +
                                           "}}" +
                                           "}}",
                                           valueAmountCents, (initialTotalValueAtMerchantCents - valueAmountCents), initialTotalValueAtMerchantCents)
            };

            IDestroyGiftCardValue client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <IDestroyGiftCardValue, GiftCardRemoveValueRequest>(
                expectedResponse, expectedRequestBody, expectedRequestUrl: expectedRequestUrl);

            var destroyed = client.GiftCardDestroyValue("not_checking_this", merchantId, paymentTokenData, valueAmountCents);

            Assert.AreEqual(destroyed.AmountRemovedInCents, valueAmountCents);
            Assert.AreEqual(destroyed.PreviousGiftCardAmountInCents, initialTotalValueAtMerchantCents);
            Assert.AreEqual(destroyed.NewGiftCardAmountInCents, initialTotalValueAtMerchantCents - valueAmountCents);
        }
        public void GiftCardDestroyValueShouldFailForBadHttpStatusCodes()
        {
            List <RestResponse> possibleErrors = new List <RestResponse>(new RestResponse[]
            {
                new RestResponse // Invalid QR code
                {
                    StatusCode = HttpStatusCode.NotFound
                },

                new RestResponse // Destroy value was negative
                {
                    StatusCode = (HttpStatusCode)422,
                    Content    = "[{\"error\":{\"object\":\"gift_cards/value_adder\",\"property\":\"base\",\"message\":\"You must remove a positive value.\"}}]"
                },

                new RestResponse // Destroy value was more than giftcard value
                {
                    StatusCode = (HttpStatusCode)422,
                    Content    = "[{\"error\":{\"object\":\"gift_cards/value_adder\",\"property\":\"base\",\"message\":\"This giftcard has a balance of $X.XX. Please retry with that amount.\"}}]"
                },

                new RestResponse // Bad merchant token
                {
                    StatusCode = HttpStatusCode.Unauthorized
                }
            });

            foreach (var response in possibleErrors)
            {
                IDestroyGiftCardValue client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <IDestroyGiftCardValue>(response);

                try
                {
                    var destroyed = client.GiftCardDestroyValue("not_checking_this", 1, "not_checking_this", 1000);
                    Assert.Fail("GiftCardDestroyValue failed to throw for an invalid HTTP return code of " + response.StatusCode);
                }
                catch (LevelUp.Api.Http.LevelUpApiException) { }
            }
        }
        public void CreateUserShouldSucceed()
        {
            string expectedRequestUrl = "https://sandbox.thelevelup.com/v14/users";

            string expectedRequestBody = string.Format("{{" +
                                                       "\"api_key\": \"{0}\"," +
                                                       "\"user\":{{" +
                                                       "\"email\":\"{1}\"," +
                                                       "\"first_name\":\"{2}\"," +
                                                       "\"last_name\":\"{3}\"," +
                                                       "\"password\":\"{4}\"" +
                                                       "}}," +
                                                       "}}", apiKey, email, firstName, lastName, password);

            IModifyUser client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <IModifyUser, CreateUserRequest>(
                expectedCreateOrUpdateUserResponse, expectedRequestBody, expectedRequestUrl: expectedRequestUrl);
            var user = client.CreateUser(apiKey, firstName, lastName, email, password);

            Assert.AreEqual(user.GlobalCreditAmount, globalCreditAmount);
            Assert.AreEqual(user.Gender, gender);
            Assert.AreEqual(user.CustomAttributes[customAttributes.Key], customAttributes.Value);
        }
        public void DeleteCreditCardShouldSucceed()
        {
            const int    id  = 305999;
            const int    bin = 123456;
            const int    expiration_month = 7;
            const int    expiration_year  = 2015;
            const bool   promoted         = true;
            const string description      = "JCBendingin1234";
            const string last_4           = "1234";
            const string state            = "inactive";
            const string @type            = "JCB";

            string expectedRequestUrl = string.Format("https://sandbox.thelevelup.com/v14/credit_cards/{0}", id);

            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    = string.Format("{{" +
                                           "\"credit_card\":{{" +
                                           "\"bin\":\"{0}\"," +
                                           "\"description\":\"{1}\"," +
                                           "\"expiration_month\":{2}," +
                                           "\"expiration_year\":{3}," +
                                           "\"id\":{4}," +
                                           "\"last_4\":\"{5}\"," +
                                           "\"promoted\":{6}," +
                                           "\"state\":\"{7}\"," +
                                           "\"type\":\"{8}\"" +
                                           "}}" +
                                           "}}",
                                           bin, description, expiration_month, expiration_year, id, last_4, promoted, state, @type)
            };

            IDestroyCreditCards client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <IDestroyCreditCards>(
                expectedResponse, expectedRequestUrl: expectedRequestUrl);

            client.DeleteCreditCard("not_checking_this", id);
        }
        public void GetPaymentTokenShouldSucceed()
        {
            const string expectedRequestUrl = "https://sandbox.thelevelup.com/v15/payment_token";

            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    =
                    "{" +
                    "\"payment_token\": {" +
                    "\"data\": \"LU02000008ZS9OJFUBNEL6ZM\"," +
                    "\"id\": 323" +
                    "}" +
                    "}"
            };

            IRetrievePaymentToken client = ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <IRetrievePaymentToken>(
                expectedResponse, expectedRequestUrl: expectedRequestUrl);
            var paymentToken = client.GetPaymentToken("not_checking_this");

            Assert.AreEqual(paymentToken.Id, 323);
            Assert.AreEqual(paymentToken.Data, "LU02000008ZS9OJFUBNEL6ZM");
        }
        public void AuthenticationShouldSucceedForCode200OK()
        {
            const int expectedUserId     = 54321;
            const int expectedmerchantId = 32225;

            RestResponse expectedResponse = new RestResponse
            {
                StatusCode = HttpStatusCode.OK,
                Content    = "{\"access_token\":" +
                             "{\"merchant_id\":" + expectedmerchantId +
                             ",\"token\":\"5564290-ee38925c6de8f4fd945e1606b232296f52f805563fb882fed1c6bq465dc367\"" + // this is not a real token
                             ",\"user_id\":" + expectedUserId + "}}"
            };

            IAuthenticate iAuth =
                ClientModuleUnitTestingUtilities.GetMockedLevelUpModule <IAuthenticate>(expectedResponse);

            var token = iAuth.Authenticate("This doesn't matter", "This has no bearing", "This can be whatever you want");

            Assert.IsNotNull(token, "The deserialization of this successful authentication response should have succeeded");
            Assert.AreEqual(token.MerchantId, expectedmerchantId);
            Assert.AreEqual(token.UserId, expectedUserId);
        }