Inheritance: IStorage
        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");
        }
Exemplo n.º 2
0
        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");
            }
        }