Esempio n. 1
0
        public async Task TestMultipleEnterExitEvent()
        {
            Resolver resolver = new Resolver(true);

            resolver.BeaconManager.ExitTimeout = 100;

            int enterCounter = 0;
            int exitCounter  = 0;

            resolver.ActionsResolved += (sender, args) =>
            {
                if (args.BeaconEventType == BeaconEventType.Enter)
                {
                    enterCounter++;
                }
                if (args.BeaconEventType == BeaconEventType.Exit)
                {
                    exitCounter++;
                }
            };
            Beacon beacon = new Beacon()
            {
                Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929
            };
            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon    = beacon,
                EventType = BeaconEventType.Unknown
            });

            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon    = beacon,
                EventType = BeaconEventType.Unknown
            });

            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon    = beacon,
                EventType = BeaconEventType.Unknown
            });

            await Task.Delay(1000);

            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon    = beacon,
                EventType = BeaconEventType.Unknown
            });


            Assert.AreEqual(2, enterCounter, "Not 2 enter action found");


            Assert.AreEqual(1, exitCounter, "Not 1 exit action found");
        }
Esempio n. 2
0
        public async Task SimpleRequestQueueTest()
        {
            MockLayoutManager layoutManager = new MockLayoutManager();

            layoutManager.FindOneAction = true;
            IResolver resolver = new Resolver(false);

            ServiceManager.ReadOnlyForTests = false;
            ServiceManager.LayoutManager    = layoutManager;
            ServiceManager.ReadOnlyForTests = true;

            TaskCompletionSource <ResolvedActionsEventArgs> requestReady = new TaskCompletionSource <ResolvedActionsEventArgs>();

            resolver.ActionsResolved += (sender, args) =>
            {
                requestReady.TrySetResult(args);
            };
            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = new Beacon()
                {
                    Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929
                },
                EventType = BeaconEventType.Unknown
            });

            ResolvedActionsEventArgs state = await requestReady.Task;

            Assert.AreEqual(1, state.ResolvedActions.Count, "Request not successfull");
        }
Esempio n. 3
0
        public async Task Integration_connection()
        {
            beacon.Id1 = "7367672374000000ffff0000ffff0006";
            beacon.Id2 = 59242;
            beacon.Id3 = 27189;

            args.Beacon          = beacon;
            args.EventType       = BeaconEventType.Enter;
            res.ActionsResolved += Res_ActionResolved;
            await res.CreateRequest(args);

            _manualEvent.WaitOne();

            Assert.IsNotNull(_e);
            Assert.IsTrue(_e.ResolvedActions.Count == 1);
        }
Esempio n. 4
0
        /// <summary>
        /// Tries to find a beacon action based on the given beacon event arguments.
        /// </summary>
        /// <param name="eventArgs">The arguments of a beacon event.</param>
        /// <returns></returns>
        public async Task ResolveBeaconAction(BeaconEventArgs eventArgs)
        {
            if (eventArgs == null)
            {
                return;
            }
            if (IsInitialized)
            {
                string location = await _locationService.GetGeoHashedLocation();

                eventArgs.Location = location;
                await Resolver.CreateRequest(eventArgs);
            }
        }
        public async Task ResolveMultipleAction()
        {
            IResolver resolver = new Resolver(true);
            TaskCompletionSource<IList<ResolvedAction>> action = new TaskCompletionSource<IList<ResolvedAction>>();
            resolver.ActionsResolved += (sender, args) =>
            {
                action.SetResult(args.ResolvedActions);
            };
            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = new Beacon() {Id1 = "7367672374000000ffff0000ffff0003", Id2 = 48869, Id3 = 21321},
                EventType = BeaconEventType.Unknown
            });

            IList<ResolvedAction> result = await action.Task;

            Assert.AreEqual(4, result.Count, "Not 4 action found");
        }
Esempio n. 6
0
        public async Task MultipleRequestQueueTest()
        {
            MockLayoutManager layoutManager = new MockLayoutManager();

            layoutManager.FindOneAction = true;
            IResolver resolver = new Resolver(false);

            ServiceManager.ReadOnlyForTests = false;
            ServiceManager.LayoutManager    = layoutManager;
            ServiceManager.ReadOnlyForTests = true;

            TaskCompletionSource <List <ResolvedActionsEventArgs> > requestReady = new TaskCompletionSource <List <ResolvedActionsEventArgs> >();
            List <ResolvedActionsEventArgs> requestsList = new List <ResolvedActionsEventArgs>();

            resolver.ActionsResolved += (sender, args) =>
            {
                requestsList.Add(args);
                if (requestsList.Count == 10)
                {
                    requestReady.TrySetResult(requestsList);
                }
            };
            for (int i = 0; i < 10; i++)
            {
                await resolver.CreateRequest(new BeaconEventArgs()
                {
                    Beacon = new Beacon()
                    {
                        Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929
                    },
                    EventType = BeaconEventType.Unknown
                });
            }
            if (await Task.WhenAny(requestReady.Task, Task.Delay(500000)) == requestReady.Task)
            {
                Assert.AreEqual(10, requestReady.Task.Result.Count, "Request not successfull");

                Assert.AreEqual(10, requestsList.Count, "Not 10 request results");
            }
            else
            {
                Assert.Fail("Timout");
            }
        }
Esempio n. 7
0
        public async Task TestEnterExitEvent()
        {
            Resolver resolver = new Resolver(true);

            resolver.BeaconManager.ExitTimeout = 20;
            TaskCompletionSource <IList <ResolvedAction> > enterAction = new TaskCompletionSource <IList <ResolvedAction> >();
            TaskCompletionSource <IList <ResolvedAction> > exitAction  = new TaskCompletionSource <IList <ResolvedAction> >();

            resolver.ActionsResolved += (sender, args) =>
            {
                if (args.BeaconEventType == BeaconEventType.Enter)
                {
                    enterAction.SetResult(args.ResolvedActions);
                }
                if (args.BeaconEventType == BeaconEventType.Exit)
                {
                    exitAction.SetResult(args.ResolvedActions);
                }
            };
            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = new Beacon()
                {
                    Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929
                },
                EventType = BeaconEventType.Unknown
            });

            await Task.Delay(2000);

//            await resolver.CreateRequest(new BeaconEventArgs()
//            {
//                Beacon = new Beacon() { Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929 },
//            });

            IList <ResolvedAction> result = await enterAction.Task;

            Assert.AreEqual(1, result.Count, "Not 1 action found");

            result = await exitAction.Task;

            Assert.AreEqual(1, result.Count, "Not 1 action found");
        }
Esempio n. 8
0
        public async Task ResolveSingleActionNoResult()
        {
            IResolver resolver = new Resolver(true);
            TaskCompletionSource <IList <ResolvedAction> > action = new TaskCompletionSource <IList <ResolvedAction> >();

            resolver.ActionsResolved += (sender, args) =>
            {
                action.SetResult(args.ResolvedActions);
            };
            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = new Beacon()
                {
                    Id1 = "7367672374000000ffff0000ffff1234", Id2 = 39178, Id3 = 30929
                },
                EventType = BeaconEventType.Unknown
            });

            IList <ResolvedAction> result = await action.Task;

            Assert.AreEqual(0, result.Count, "Not 0 action found");
        }
Esempio n. 9
0
        public async Task MultipleRequestWithFailuresQueueTest()
        {
            MockLayoutManager layoutManager = new MockLayoutManager();

            layoutManager.FindOneAction = true;
            IResolver resolver = new Resolver(false);

            ServiceManager.ReadOnlyForTests = false;
            ServiceManager.LayoutManager    = layoutManager;
            ServiceManager.ReadOnlyForTests = true;

            layoutManager.ShouldFail += (r, fail) =>
            {
                if (r.RequestId == 5 && r.TryCount == 1)
                {
                    fail.Fail = true;
                    return;
                }

                if (r.RequestId == 6)
                {
                    fail.Fail = true;
                    return;
                }
            };

            TaskCompletionSource <List <ResolvedActionsEventArgs> > requestReady = new TaskCompletionSource <List <ResolvedActionsEventArgs> >();
            List <ResolvedActionsEventArgs> requestsList = new List <ResolvedActionsEventArgs>();

            resolver.ActionsResolved += (sender, args) =>
            {
                requestsList.Add(args);
            };
            int i = 0;

            ((Resolver)resolver).Finished += () =>
            {
                if (i == 10)
                {
                    requestReady.TrySetResult(requestsList);
                }
            };

            for (; i < 10; i++)
            {
                await resolver.CreateRequest(new BeaconEventArgs()
                {
                    Beacon = new Beacon()
                    {
                        Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929
                    },
                    EventType = BeaconEventType.Unknown
                });
            }

            if (await Task.WhenAny(requestReady.Task, Task.Delay(5000)) == requestReady.Task)
            {
                Assert.AreEqual(9, requestReady.Task.Result.Count, "Request successfull (last should fail)");

                Assert.AreEqual(9, requestsList.Count, "Not 9 request results");
            }
            else
            {
                Assert.Fail("Timout");
            }
        }
Esempio n. 10
0
        public async Task TestBeaconEventExitChange()
        {
            Resolver resolver = new Resolver(true);
            resolver.BeaconManager.ExitTimeout = 1000;
            TaskCompletionSource<IList<ResolvedAction>> enterAction = new TaskCompletionSource<IList<ResolvedAction>>();
            TaskCompletionSource<IList<ResolvedAction>> exitAction = new TaskCompletionSource<IList<ResolvedAction>>();
            EventHandler<ResolvedActionsEventArgs> resolverOnActionsResolved = (sender, args) =>
            {
                if (args.BeaconEventType == BeaconEventType.Enter)
                {
                    enterAction.SetResult(args.ResolvedActions);
                }
                if (args.BeaconEventType == BeaconEventType.Exit)
                {
                    exitAction.SetResult(args.ResolvedActions);
                }

            };
            resolver.ActionsResolved += resolverOnActionsResolved;
            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = new Beacon() { Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929 },
                EventType = BeaconEventType.Unknown
            });
            await Task.Delay(1500);
            IList<ResolvedAction> result = await enterAction.Task;

            Assert.AreEqual(1, result.Count, "Not 1 action found");

            result = await exitAction.Task;

            Assert.AreEqual(1, result.Count, "Not 1 action found");
            resolver.ActionsResolved -= resolverOnActionsResolved;


            resolver.BeaconManager.ExitTimeout = 100;

            enterAction = new TaskCompletionSource<IList<ResolvedAction>>();
            exitAction = new TaskCompletionSource<IList<ResolvedAction>>();
            resolverOnActionsResolved = (sender, args) =>
            {
                if (args.BeaconEventType == BeaconEventType.Enter)
                {
                    enterAction.SetResult(args.ResolvedActions);
                }
                if (args.BeaconEventType == BeaconEventType.Exit)
                {
                    exitAction.SetResult(args.ResolvedActions);
                }

            };
            resolver.ActionsResolved += resolverOnActionsResolved;
            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = new Beacon() { Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929 },
                EventType = BeaconEventType.Unknown
            });
            await Task.Delay(300);
             result = await enterAction.Task;

            Assert.AreEqual(1, result.Count, "Not 1 action found");

            result = await exitAction.Task;

            Assert.AreEqual(1, result.Count, "Not 1 action found");
        }
Esempio n. 11
0
        public async Task TestMultipleEnterExitEvent()
        {
            Resolver resolver = new Resolver(true);
            resolver.BeaconManager.ExitTimeout = 100;

            int enterCounter = 0;
            int exitCounter = 0;
            resolver.ActionsResolved += (sender, args) =>
            {
                if (args.BeaconEventType == BeaconEventType.Enter)
                {
                    enterCounter++;
                }
                if (args.BeaconEventType == BeaconEventType.Exit)
                {
                    exitCounter++;
                }

            };
            Beacon beacon = new Beacon() { Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929 };
            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = beacon,
                EventType = BeaconEventType.Unknown
            });
            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = beacon,
                EventType = BeaconEventType.Unknown
            });
            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = beacon,
                EventType = BeaconEventType.Unknown
            });

            await Task.Delay(1000);

            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = beacon,
                EventType = BeaconEventType.Unknown
            });


            Assert.AreEqual(2, enterCounter, "Not 2 enter action found");


            Assert.AreEqual(1, exitCounter, "Not 1 exit action found");
        }
Esempio n. 12
0
        public async Task MultipleRequestBlocksQueueTest()
        {
            MockLayoutManager layoutManager = new MockLayoutManager();
            layoutManager.FindOneAction = true;
            IResolver resolver = new Resolver(false);
            ServiceManager.ReadOnlyForTests = false;
            ServiceManager.LayoutManager = layoutManager;
            ServiceManager.ReadOnlyForTests = true;


            TaskCompletionSource<List<ResolvedActionsEventArgs>> requestReady = new TaskCompletionSource<List<ResolvedActionsEventArgs>>();
            List<ResolvedActionsEventArgs> requestsList = new List<ResolvedActionsEventArgs>();
            EventHandler<ResolvedActionsEventArgs> resolverOnActionsResolved = (sender, args) =>
            {
                requestsList.Add(args);
            };
            resolver.ActionsResolved += resolverOnActionsResolved;
            ((Resolver) resolver).Finished += () =>
            {
                if (requestsList.Count == 10)
                {
                    requestReady.TrySetResult(requestsList);
                }
            };

            for (int i = 0; i < 10; i++)
            {
                await resolver.CreateRequest(new BeaconEventArgs()
                {
                    Beacon = new Beacon() {Id1 = "7367672374000000ffff0000ffff0004", Id2 = (ushort) (39178+i), Id3 = 30929},
                    EventType = BeaconEventType.Unknown
                });
            }

            if (await Task.WhenAny(requestReady.Task, Task.Delay(500000)) == requestReady.Task)
            {
                Assert.AreEqual(10, requestReady.Task.Result.Count, "Request not successfull");

                Assert.AreEqual(10, requestsList.Count, "Not 10 request results");
            }
            else
            {
                Assert.Fail("Timout");
            }
            resolver.ActionsResolved -= resolverOnActionsResolved;

            requestsList = new List<ResolvedActionsEventArgs>();
            TaskCompletionSource<List<ResolvedActionsEventArgs>> requestReady2 = new TaskCompletionSource<List<ResolvedActionsEventArgs>>();

            resolver.ActionsResolved += (sender, args) =>
            {
                requestsList.Add(args);
            };
            ((Resolver) resolver).Finished += () =>
            {
                if (requestsList.Count == 10)
                {
                    requestReady2.TrySetResult(requestsList);
                }
            };
            for (int i = 0; i < 10; i++)
            {
                await resolver.CreateRequest(new BeaconEventArgs()
                {
                    Beacon = new Beacon() {Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929},
                    EventType = BeaconEventType.Unknown
                });
            }

            if (await Task.WhenAny(requestReady2.Task, Task.Delay(500000)) == requestReady2.Task)
            {
                Assert.AreEqual(10, requestReady2.Task.Result.Count, "Request not successfull");

                Assert.AreEqual(10, requestsList.Count, "Not 10 request results");
            }
            else
            {
                Assert.Fail("Timout2");
            }
        }
Esempio n. 13
0
        public async Task MultipleRequestWithFailuresQueueTest()
        {
            MockLayoutManager layoutManager = new MockLayoutManager();
            layoutManager.FindOneAction = true;
            IResolver resolver = new Resolver(false);
            ServiceManager.ReadOnlyForTests = false;
            ServiceManager.LayoutManager = layoutManager;
            ServiceManager.ReadOnlyForTests = true;

            layoutManager.ShouldFail += (r, fail) =>
            {
                if (r.RequestId == 5 && r.TryCount == 1)
                {
                    fail.Fail = true;
                    return;
                }

                if (r.RequestId == 6)
                {
                    fail.Fail = true;
                    return;
                }
            };

            TaskCompletionSource<List<ResolvedActionsEventArgs>> requestReady = new TaskCompletionSource<List<ResolvedActionsEventArgs>>();
            List<ResolvedActionsEventArgs> requestsList = new List<ResolvedActionsEventArgs>();
            resolver.ActionsResolved += (sender, args) =>
            {
                requestsList.Add(args);
            };
            int i = 0;
            ((Resolver) resolver).Finished += () =>
            {
                if (i == 10)
                {
                    requestReady.TrySetResult(requestsList);
                }
            };

            for (; i < 10; i++)
            {
                await resolver.CreateRequest(new BeaconEventArgs()
                {
                    Beacon = new Beacon() {Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929},
                    EventType = BeaconEventType.Unknown
                });
            }

            if (await Task.WhenAny(requestReady.Task, Task.Delay(5000)) == requestReady.Task)
            {
                Assert.AreEqual(9, requestReady.Task.Result.Count, "Request successfull (last should fail)");

                Assert.AreEqual(9, requestsList.Count, "Not 9 request results");
            }
            else
            {
                Assert.Fail("Timout");
            }
        }
Esempio n. 14
0
        public async Task SimpleRequestQueueTest()
        {
            MockLayoutManager layoutManager = new MockLayoutManager();
            layoutManager.FindOneAction = true;
            IResolver resolver = new Resolver(false);
            ServiceManager.ReadOnlyForTests = false;
            ServiceManager.LayoutManager = layoutManager;
            ServiceManager.ReadOnlyForTests = true;

            TaskCompletionSource<ResolvedActionsEventArgs> requestReady = new TaskCompletionSource<ResolvedActionsEventArgs>();
            resolver.ActionsResolved += (sender, args) =>
            {
                requestReady.TrySetResult(args);
            };
            await resolver.CreateRequest(new BeaconEventArgs()
            {
                Beacon = new Beacon() {Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929},
                EventType = BeaconEventType.Unknown
            });

            ResolvedActionsEventArgs state = await requestReady.Task;
            Assert.AreEqual(1, state.ResolvedActions.Count, "Request not successfull");
        }