Пример #1
0
        public void TestDelayedActionFromString()
        {
            Guid guid = Guid.NewGuid();
            DelayedActionHelper simpleDelayedActionFromString = FileStorageHelper.SimpleDelayedActionFromString(guid + ",1429192800000,False,eyJBY3Rpb24iOnsiQmVhY29uQWN0aW9uIjp7IklkIjoxLCJUeXBlIjozLCJlaWQiOiJ1dWlkIiwiU3ViamVjdCI6IlN1YmplY3QiLCJCb2R5IjoiYm9keSIsIlVybCI6Imh0dHA6Ly9zZW5zb3JiZXJnLmNvbSIsIlBheWxvYWRTdHJpbmciOiJ7XCJwYXlcIjpcImxvYWRcIn0ifSwiYmVhY29ucyI6WyIxIiwiMiIsIjMiLCI0Il0sInRyaWdnZXIiOjMsIkRlbGF5IjoxMjMsIlNlbmRPbmx5T25jZSI6dHJ1ZSwic3VwcHJlc3Npb25UaW1lIjozMjEsIlJlcG9ydEltbWVkaWF0ZWx5Ijp0cnVlLCJUaW1lZnJhbWVzIjpbeyJTdGFydCI6IjIwMTUtMDQtMTVUMTI6MDA6MDArMDA6MDAiLCJFbmQiOiIyMDE1LTA0LTE2VDEyOjAwOjAwKzAwOjAwIn1dfSwiVGltZSI6IjIwMTUtMDQtMTZUMTQ6MDA6MDArMDA6MDAiLCJCZWFjb24iOiIxMjMiLCJFdmVudCI6MX0=");

            Assert.AreEqual(DateTimeOffset.Parse("2015-04-16T14:00:00.000+0000"), simpleDelayedActionFromString.Offset, "Wrong offset");
            Assert.IsFalse(simpleDelayedActionFromString.Executed, "Is executed");
            string s =
                "eyJBY3Rpb24iOnsiQmVhY29uQWN0aW9uIjp7IklkIjoxLCJUeXBlIjozLCJlaWQiOiJ1dWlkIiwiU3ViamVjdCI6IlN1YmplY3QiLCJCb2R5IjoiYm9keSIsIlVybCI6Imh0dHA6Ly9zZW5zb3JiZXJnLmNvbSIsIlBheWxvYWRTdHJpbmciOiJ7XCJwYXlcIjpcImxvYWRcIn0ifSwiYmVhY29ucyI6WyIxIiwiMiIsIjMiLCI0Il0sInRyaWdnZXIiOjMsIkRlbGF5IjoxMjMsIlNlbmRPbmx5T25jZSI6dHJ1ZSwic3VwcHJlc3Npb25UaW1lIjozMjEsIlJlcG9ydEltbWVkaWF0ZWx5Ijp0cnVlLCJUaW1lZnJhbWVzIjpbeyJTdGFydCI6IjIwMTUtMDQtMTVUMTI6MDA6MDArMDA6MDAiLCJFbmQiOiIyMDE1LTA0LTE2VDEyOjAwOjAwKzAwOjAwIn1dfSwiVGltZSI6IjIwMTUtMDQtMTZUMTQ6MDA6MDArMDA6MDAiLCJCZWFjb24iOiIxMjMiLCJFdmVudCI6MX0=";

            Assert.AreEqual(s, simpleDelayedActionFromString.Content, "Wrong content");

            ResolvedAction action = new ResolvedAction();

            action.BeaconAction         = new BeaconAction();
            action.BeaconAction.Body    = "body";
            action.BeaconAction.Id      = 1;
            action.BeaconAction.Payload = JsonObject.Parse("{\"pay\":\"load\"}");
            action.BeaconAction.Subject = "Subject";
            action.BeaconAction.Type    = BeaconActionType.InApp;
            action.BeaconAction.Url     = "http://sensorberg.com";
            action.BeaconAction.Uuid    = "uuid";
            action.Delay      = 123;
            action.BeaconPids = new List <string>()
            {
                "1", "2", "3", "4"
            };
            action.EventTypeDetectedByDevice = BeaconEventType.EnterExit;
            action.ReportImmediately         = true;
            action.SendOnlyOnce    = true;
            action.SuppressionTime = 321;
            action.Timeframes      = new List <Timeframe>()
            {
                new Timeframe()
                {
                    End = DateTimeOffset.Parse("2015-04-16T12:00:00.000+0000"), Start = DateTimeOffset.Parse("2015-04-15T12:00:00.000+0000")
                }
            };
            DelayedActionData data = FileStorageHelper.DelayedActionFromHelper(simpleDelayedActionFromString);

            Assert.AreEqual("123", data.BeaconPid, "Wrong beacon pid");
            Assert.AreEqual(BeaconEventType.Enter, data.EventTypeDetectedByDevice, "Wrong event type");
            Assert.AreEqual(DateTimeOffset.Parse("2015-04-16T14:00:00.000+0000"), data.DueTime, "Wrong time");
            Assert.AreEqual(guid.ToString(), data.Id, "ID isnt set");
            Assert.AreEqual(action, data.ResolvedAction);

            Assert.IsNull(FileStorageHelper.SimpleDelayedActionFromString(""));
            Assert.IsNull(FileStorageHelper.SimpleDelayedActionFromString(null));
            Assert.IsNull(FileStorageHelper.DelayedActionFromHelper(null));
        }