public async Task RetrieveLayoutTest()
        {
            MockApiConnection connection = (MockApiConnection)ServiceManager.ApiConnction;
            IStorageService   service    = ServiceManager.StorageService;

            ApplicationData.Current.LocalSettings.Values.Remove(LayoutManager.KeyLayoutHeaders);
            ApplicationData.Current.LocalSettings.Values.Remove(LayoutManager.KeyLayoutRetrievedTime);
            await TestHelper.RemoveFile(LayoutManager.KeyLayoutContent);

            connection.FailNetwork = true;
            LayoutResult layout = await service.RetrieveLayout();

            Assert.AreEqual(NetworkResult.NetworkError, layout.Result, "Not failed");
            connection.FailNetwork = false;

            layout = await service.RetrieveLayout();

            Assert.AreEqual(NetworkResult.Success, layout.Result, "Not successfull loaded");
            LayoutManagerTest.ValidateMockLayout(layout.Layout);

            connection.FailNetwork = true;
            //should be cached
            layout = await service.RetrieveLayout();

            Assert.AreEqual(NetworkResult.Success, layout.Result, "Not successfull loaded from cache");
            LayoutManagerTest.ValidateMockLayout(layout.Layout);
        }
        public async Task FlushHistoryTest()
        {
            StorageServiceExtend sse         = (StorageServiceExtend)ServiceManager.StorageService;
            MockStorage          mockStorage = new MockStorage();

            sse.SetStorage(mockStorage);
            mockStorage.UndeliveredActions = new List <HistoryAction> {
                new HistoryAction()
            };
            mockStorage.UndeliveredEvents = new List <HistoryEvent> {
                new HistoryEvent()
            };

            MockApiConnection connection = (MockApiConnection)ServiceManager.ApiConnction;
            IStorageService   service    = ServiceManager.StorageService;


            connection.FailNetwork = true;
            Assert.IsFalse(await service.FlushHistory(), "Flushing History not failed");
            connection.FailNetwork = false;
            Assert.IsTrue(mockStorage.UndeliveredEvents.Count != 0, "Event were resetet");
            Assert.IsTrue(mockStorage.UndeliveredActions.Count != 0, "Actions were resetet");

            Assert.IsTrue(await service.FlushHistory(), "Flushing History not succeed");
            Assert.IsTrue(mockStorage.UndeliveredEvents.Count == 0, "Event were not marked as send");
            Assert.IsTrue(mockStorage.UndeliveredActions.Count == 0, "Actions were not marked as send");
        }
Ejemplo n.º 3
0
        public async Task MultipleEventsFired()
        {
            SDKManager sdkManager     = SDKManager.Instance();
            int        resolvedAction = 0;

            sdkManager.BeaconActionResolved += (sender, action) => resolvedAction++;
            await sdkManager.InitializeAsync(new SdkConfiguration()
            {
                ApiKey = ApiKey, ManufacturerId = ManufacturerId, BeaconCode = BeaconCode
            });

            sdkManager.SdkEngine.Resolver.BeaconExitTimeout = 500;

            TaskCompletionSource <bool> actionResolved = new TaskCompletionSource <bool>();
            int requestCount  = 0;
            int REQUEST_COUNT = 10;

            ((Resolver)sdkManager.SdkEngine.Resolver).Finished += () =>
            {
                if (requestCount >= REQUEST_COUNT - 1)
                {
                    actionResolved.SetResult(true);
                }
            };

            MockBeaconScanner scanner = (MockBeaconScanner)ServiceManager.BeaconScanner;

            for (; requestCount < REQUEST_COUNT; requestCount++)
            {
                scanner.NotifyBeaconEvent(new Beacon()
                {
                    Id1 = "7367672374000000ffff0000ffff0006", Id2 = 23430, Id3 = 28018
                }, BeaconEventType.Unknown);
                await Task.Delay(1500);
            }

            await actionResolved.Task;

            await ServiceManager.StorageService.FlushHistory();

            MockApiConnection connection = (MockApiConnection)ServiceManager.ApiConnction;

            Assert.AreEqual(REQUEST_COUNT, requestCount);
            Assert.AreEqual(REQUEST_COUNT, connection.HistoryEvents.Count);
            Assert.AreEqual(REQUEST_COUNT, connection.HistoryActions.Count);
        }
        public async Task ValidateAPIKeyTest()
        {
            MockApiConnection connection = (MockApiConnection)ServiceManager.ApiConnction;

            IStorageService service = ServiceManager.StorageService;

            Assert.AreEqual(ApiKeyValidationResult.Valid, await service.ValidateApiKey("true"), "Not successfull");
            connection.APIInvalid = true;
            Assert.AreEqual(ApiKeyValidationResult.Invalid, await service.ValidateApiKey("false"), "Not invalid");
            connection.APIInvalid = false;


            connection.FailNetwork = true;
            Assert.AreEqual(ApiKeyValidationResult.NetworkError, await service.ValidateApiKey("true"), "No network issue");
            connection.FailNetwork = false;

            connection.UnknownError = true;
            Assert.AreEqual(ApiKeyValidationResult.UnknownError, await service.ValidateApiKey("true"), "No unknown issue");
            connection.UnknownError = false;
        }