|
| 1 | +using System; |
| 2 | +using System.IO; |
| 3 | +using System.Reflection; |
| 4 | +using System.Runtime.InteropServices.ComTypes; |
| 5 | +using Bunq.Sdk.Model.Core; |
| 6 | +using Bunq.Sdk.Model.Generated.Endpoint; |
| 7 | +using Bunq.Sdk.Model.Generated.Object; |
| 8 | +using Newtonsoft.Json.Linq; |
| 9 | +using Xunit; |
| 10 | + |
| 11 | +namespace Bunq.Sdk.Tests.Model.Generated.Object |
| 12 | +{ |
| 13 | + public class NotificationUrlTest : BunqSdkTestBase |
| 14 | + { |
| 15 | + /// <summary> |
| 16 | + /// Getter constans. |
| 17 | + /// </summary> |
| 18 | + private const string GET_PAYMENT = "Payment"; |
| 19 | + private const string GET_BUNQ_ME_TAB = "BunqMeTab"; |
| 20 | + private const string GET_CHAT_MESSAGE_ANNOUNCEMENT = "ChatMessageAnnouncement"; |
| 21 | + private const string GET_DRAFT_PAYMENT = "DraftPayment"; |
| 22 | + private const string GET_MASTER_CARD_ACTION = "MasterCardAction"; |
| 23 | + private const string GET_MONETARY_ACCOUNT_BANK = "MonetaryAccountBank"; |
| 24 | + private const string GET_PAYMENT_BATCH = "PaymentBatch"; |
| 25 | + private const string GET_REQUEST_INQUIRY = "RequestInquiry"; |
| 26 | + private const string GET_REQUEST_RESPONSE = "RequestResponse"; |
| 27 | + private const string GET_SCHEDULE_PAYMENT = "ScheduledPayment"; |
| 28 | + private const string GET_SCHEDULE_INSTANCE = "ScheduledInstance"; |
| 29 | + private const string GET_SHARE_INVITE_BANK_INQUIRY = "ShareInviteBankInquiry"; |
| 30 | + private const string GET_SHARE_INVITE_BANK_RESPONSE = "ShareInviteBankResponse"; |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// Assert error constants. |
| 34 | + /// </summary> |
| 35 | + private const string ASSERT_SHOULD_NOT_REACH_THIS_CODE_ERROR = "Congratulations you\"ve reached unreachable code."; |
| 36 | + private const string ASSERT_JSON_DECODE_ERROR = "Error accorded while decoding the JSON file."; |
| 37 | + private const string ASSERT_OBJECT_IS_NULL_ERROR = "The field object of NotificationUrl is null."; |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Model json paths constants. |
| 41 | + /// </summary> |
| 42 | + private const string BASE_PATH_JSON_MODEL = "../../../Resources/NotificationUrlJsons"; |
| 43 | + private const string JSON_PATH_MUTATION_MODEL = BASE_PATH_JSON_MODEL + "/Mutation.json"; |
| 44 | + private const string JSON_PATH_BUNQ_ME_TAB_MODEL = BASE_PATH_JSON_MODEL + "/BunqMeTab.json"; |
| 45 | + private const string JSON_PATH_CHAT_MESSAGE_ANNOUNCEMENT_MODEL = BASE_PATH_JSON_MODEL + |
| 46 | + "/ChatMessageAnnouncement.json"; |
| 47 | + private const string JSON_PATH_DRAFT_PAYMENT_MODEL = BASE_PATH_JSON_MODEL + "/DraftPayment.json"; |
| 48 | + private const string JSON_PATH_MASTER_CARD_ACTION_MODEL = BASE_PATH_JSON_MODEL + "/MasterCardAction.json"; |
| 49 | + private const string JSON_PATH_MONETARY_ACCOUNT_BANK_MODEL = BASE_PATH_JSON_MODEL + "/MonetaryAccountBank.json"; |
| 50 | + private const string JSON_PATH_PAYMENT_BATCH_MODEL = BASE_PATH_JSON_MODEL + "/PaymentBatch.json"; |
| 51 | + private const string JSON_PATH_REQUEST_INQUIRY_MODEL = BASE_PATH_JSON_MODEL + "/RequestInquiry.json"; |
| 52 | + private const string JSON_PATH_REQUEST_RESPONSE_MODEL = BASE_PATH_JSON_MODEL + "/RequestResponse.json"; |
| 53 | + private const string JSON_PATH_SCHEDULE_PAYMENT_MODEL = BASE_PATH_JSON_MODEL + "/ScheduledPayment.json"; |
| 54 | + private const string JSON_PATH_SCHEDULE_INSTANCE_MODEL = BASE_PATH_JSON_MODEL + "/ScheduledInstance.json"; |
| 55 | + private const string JSON_PATH_SHARE_INVITE_BANK_INQUIRY_MODEL = BASE_PATH_JSON_MODEL + |
| 56 | + "/ShareInviteBankInquiry.json"; |
| 57 | + |
| 58 | + private const string JSON_PATH_SHARE_INVITE_BANK_RESPONSE_MODEL = BASE_PATH_JSON_MODEL + |
| 59 | + "/ShareInviteBankResponse.json"; |
| 60 | + |
| 61 | + /// <summary> |
| 62 | + /// Model root key. |
| 63 | + /// </summary> |
| 64 | + private const string KEY_NOTIFICATION_URL_MODEL = "NotificationUrl"; |
| 65 | + |
| 66 | + private void ExeceuteNotificationUrlTest( |
| 67 | + string expectedJsonFileName, |
| 68 | + Type classNameExpected, |
| 69 | + string referencedObjectGetterName) |
| 70 | + { |
| 71 | + var jsonString = ReadJsonFromFile(expectedJsonFileName); |
| 72 | + var notificationUrl = BunqModel.FromJsonString<NotificationUrl>(jsonString); |
| 73 | + |
| 74 | + Assert.NotNull(notificationUrl); |
| 75 | + Assert.NotNull(notificationUrl.Object); |
| 76 | + |
| 77 | + var model = notificationUrl.Object.GetType().GetProperty(referencedObjectGetterName).GetValue( |
| 78 | + notificationUrl.Object); |
| 79 | + var referencedModel = notificationUrl.Object.GetReferencedObject(); |
| 80 | + |
| 81 | + Assert.NotNull(model); |
| 82 | + Assert.NotNull(referencedModel); |
| 83 | + Assert.IsType(classNameExpected, referencedModel); |
| 84 | + Assert.Equal(classNameExpected, referencedModel.GetType()); |
| 85 | + } |
| 86 | + |
| 87 | + private static string ReadJsonFromFile(string fileName) |
| 88 | + { |
| 89 | + var fileContentString = File.ReadAllText(fileName); |
| 90 | + var jsonObj = JObject.Parse(fileContentString); |
| 91 | + var notificationUrlObject = jsonObj[KEY_NOTIFICATION_URL_MODEL]; |
| 92 | + |
| 93 | + Assert.NotNull(notificationUrlObject); |
| 94 | + |
| 95 | + return notificationUrlObject.ToString(); |
| 96 | + } |
0 commit comments