Skip to content

Commit

Permalink
Add a test - need to debug test
Browse files Browse the repository at this point in the history
  • Loading branch information
tj_devel709 committed Oct 9, 2023
1 parent 1158356 commit bca6d1c
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 6 deletions.
76 changes: 76 additions & 0 deletions src/PassKit/PKPayLaterView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#nullable enable

#if IOS

using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using ObjCRuntime;
using Foundation;
using PassKit;

#if !NET
using NativeHandle = System.IntPtr;
#endif

namespace PassKit {

public partial class PKPayLaterView {

#if !NET
delegate void PKPayLaterValidateAmountCompletionHandler (IntPtr block, bool eligible);
static PKPayLaterValidateAmountCompletionHandler static_ValidateAmount = TrampolineValidateAmount;

[MonoPInvokeCallback (typeof (PKPayLaterValidateAmountCompletionHandler))]
#else
[UnmanagedCallersOnly]
#endif
static void TrampolineValidateAmount (IntPtr block, bool eligible)
{
var del = BlockLiteral.GetTarget<Action<bool>> (block);
if (del is not null) {
del (eligible);
}
}

#if NET
[SupportedOSPlatform ("ios17.0")]
[UnsupportedOSPlatform ("macos")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
#else
[NoWatch, NoTV, NoMac, iOS (17, 0), NoMacCatalyst]
#endif
[BindingImpl (BindingImplOptions.Optimizable)]
public void ValidateAmount (decimal amount, string currencyCode, Action<bool> callback)
{
if (callback is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (callback));

unsafe {
#if NET
delegate* unmanaged<IntPtr, bool, void> trampoline = &TrampolineValidateAmount;
using var block = new BlockLiteral (trampoline, callback, typeof (PKPayLaterView), nameof (TrampolineValidateAmount));
#else
using var block = new BlockLiteral ();
block.SetupBlockUnsafe (static_ValidateAmount, callback);
#endif
using var nsCurrencyCode = new NSString (currencyCode);
PKPayLaterValidateAmount (amount, nsCurrencyCode.Handle, &block);
}
}

#if NET
[SupportedOSPlatform ("ios17.0")]
[UnsupportedOSPlatform ("macos")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
#else
[NoWatch, NoTV, NoMac, iOS (17, 0), NoMacCatalyst]
#endif
[DllImport (Constants.PassKitLibrary)]
unsafe static extern void PKPayLaterValidateAmount (decimal amount, IntPtr /* NSString */ currencyCode, BlockLiteral* callback);
}
}

#endif
40 changes: 40 additions & 0 deletions tests/monotouch-test/PassKit/PKPayLaterViewTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#if IOS

using System;
using Foundation;
using UIKit;
using PassKit;
using NUnit.Framework;

namespace MonoTouchFixtures.PassKit {

[TestFixture]
[Preserve (AllMembers = true)]
public class PKPayLaterViewTest {

[Test]
public void ValidateAmountTest ()
{
TestRuntime.AssertXcodeVersion (15, 0);

var payLaterView = new PKPayLaterView (100, "USD");
payLaterView.ValidateAmount(50, "USD", (eligible) => {
Assert.True (eligible);
});

payLaterView.ValidateAmount(1, "USD", (eligible) => {
Assert.False (eligible);
});

payLaterView.ValidateAmount(1000000, "USD", (eligible) => {
Assert.False (eligible);
});

payLaterView.ValidateAmount(50, "USD", (eligible) => {
Assert.True (eligible);
});
}
}
}

#endif
3 changes: 0 additions & 3 deletions tests/xtro-sharpie/api-annotations-dotnet/iOS-PassKit.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@

# No longer used enum, will be removed in XAMCORE_5_0
!unknown-native-enum! PKDisbursementRequestSchedule bound

# TODO
!missing-pinvoke! PKPayLaterValidateAmount is not bound
3 changes: 0 additions & 3 deletions tests/xtro-sharpie/iOS-PassKit.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@

# No longer used enum, will be removed in XAMCORE_5_0
!unknown-native-enum! PKDisbursementRequestSchedule bound

# TODO
!missing-pinvoke! PKPayLaterValidateAmount is not bound

0 comments on commit bca6d1c

Please sign in to comment.