public async Task ResolveMultipleAction() { LayoutManager layoutManager = (LayoutManager) ServiceManager.LayoutManager; await layoutManager.VerifyLayoutAsync(true); SdkEngine engine = new SdkEngine(false); await engine.InitializeAsync(); TaskCompletionSource<IList<BeaconAction>> action = new TaskCompletionSource<IList<BeaconAction>>(); IList<BeaconAction> list = new List<BeaconAction>(); engine.BeaconActionResolved += (sender, args) => { list.Add(args); if (list.Count >= 3) { action.TrySetResult(list); } }; await engine.ResolveBeaconAction(new BeaconEventArgs() { Beacon = new Beacon() {Id1 = "7367672374000000ffff0000ffff0003", Id2 = 48869, Id3 = 21321}, EventType = BeaconEventType.Enter }); IList<BeaconAction> result = await action.Task; Assert.AreEqual(4, result.Count, "Not 4 action found"); }
public async Task ResolveBackgroundBeaconsSingleAction() { LayoutManager layoutManager = (LayoutManager) ServiceManager.LayoutManager; await layoutManager.VerifyLayoutAsync(true); SdkEngine engine = new SdkEngine(false); await engine.InitializeAsync(); BeaconAction orgAction = layoutManager.Layout.ResolvedActions.FirstOrDefault(ra => ra.BeaconAction.Uuid == "9ded63644e424d758b0218f7c70f2473").BeaconAction; TaskCompletionSource<BeaconAction> action = new TaskCompletionSource<BeaconAction>(); engine.BeaconActionResolved += (sender, args) => { action.SetResult(args); }; await engine.ResolveBeaconAction(new BeaconEventArgs() { Beacon = new Beacon() {Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929}, EventType = BeaconEventType.Enter }); BeaconAction result = await action.Task; Assert.AreEqual(orgAction, result, "action not found"); }
public async Task UpdateExitTimeoutTest() { SdkEngine engine = new SdkEngine(true); await engine.InitializeAsync(); AppSettings appSettings = engine.AppSettings; Assert.AreEqual((ulong)123, appSettings.BeaconExitTimeout); Assert.AreEqual((ulong)123,engine.Resolver.BeaconExitTimeout); ((MockApiConnection) ServiceManager.ApiConnction).MockSettings = "{\"revision\":0,\"settings\":{\"scanner.backgroundWaitTime\":120000, \"scanner.exitTimeoutMillis\":123000, \"network.historyUploadInterval\":321}}"; ((SettingsManager)ServiceManager.SettingsManager).OnTimerTick(null); appSettings = engine.AppSettings; Assert.AreEqual((ulong)123000, appSettings.BeaconExitTimeout); Assert.AreEqual((ulong)123000, engine.Resolver.BeaconExitTimeout); }
public BackgroundEngine() { SdkEngine = new SdkEngine(false); _beaconArgs = new List<BeaconEventArgs>(); SdkEngine.BeaconActionResolved += OnBeaconActionResolvedAsync; }
public async Task ResolveSingleActionNoResult() { LayoutManager layoutManager = (LayoutManager) ServiceManager.LayoutManager; await layoutManager.VerifyLayoutAsync(true); SdkEngine engine = new SdkEngine(false); await engine.InitializeAsync(); TaskCompletionSource<IList<BeaconAction>> action = new TaskCompletionSource<IList<BeaconAction>>(); IList<BeaconAction> list = new List<BeaconAction>(); engine.BeaconActionResolved += (sender, args) => { list.Add(args); if (list.Count >= 3) { action.SetResult(list); } }; await engine.ResolveBeaconAction(new BeaconEventArgs() { Beacon = new Beacon() {Id1 = "7367672374000000ffff0000ffff1234", Id2 = 39178, Id3 = 30929}, EventType = BeaconEventType.Enter }); if (await Task.WhenAny(action.Task, Task.Delay(500)) == action.Task) { Assert.AreEqual(0, action.Task.Result, "Not 0 action found"); } else { //timeout is fine } }
public async Task TestSilentCampaign() { ((MockApiConnection) ServiceManager.ApiConnction).LayoutFile = "mock/mock_silent_layout.json"; ServiceManager.ReadOnlyForTests = false; MockStorage storage = new MockStorage(); ServiceManager.StorageService = new StorageService() {Storage = storage}; ServiceManager.ReadOnlyForTests = true; SdkEngine engine = new SdkEngine(false); await engine.InitializeAsync(); TaskCompletionSource<bool> action = new TaskCompletionSource<bool>(); engine.BeaconActionResolved += (sender, args) => { action.SetResult(true); }; await engine.ResolveBeaconAction(new BeaconEventArgs() { Beacon = new Beacon() {Id1 = "7367672374000000ffff0000ffff4321", Id2 = 39178, Id3 = 30929}, EventType = BeaconEventType.Enter }); if (await Task.WhenAny(action.Task, Task.Delay(500)) == action.Task) { Assert.Fail("no action should fired"); } else { Assert.AreEqual(1, storage.UndeliveredActions.Count, "Not 1 undlivered action"); Assert.AreEqual(1, storage.UndeliveredEvents.Count, "Not 1 undlivered event"); } }
/// <summary> /// Constructor. /// </summary> private SDKManager() { SdkEngine = new SdkEngine(true); Status = new SdkStatus(); _backgroundTaskManager = new BackgroundTaskManager(); _backgroundTaskManager.RegisterOnProgressEventHandler(); }