public void InstantToStringParse()
        {
            Instant normalNow  = new Instant(DateTime.Now);
            string  toStringed = normalNow.ToString();

            Message.PrintLine("ToStringed: {0}", toStringed);
            Instant parsed = Instant.FromString(toStringed);

            Expect.AreEqual(0, parsed.DiffInMilliseconds(normalNow));
        }
Example #2
0
        /// <summary>
        /// Checks that the specified nonce is no more than
        /// 3 minutes in the past or future
        /// </summary>
        /// <param name="nonce"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public static EncryptedTokenValidationStatus ValidateNonce(string nonce, int offset)
        {
            EncryptedTokenValidationStatus result = EncryptedTokenValidationStatus.Success;
            Instant requestInstant = Instant.FromString(nonce);
            Instant currentInstant = new Instant();

            int difference = currentInstant.DiffInMilliseconds(requestInstant);

            difference = difference - offset;
            if (TimeSpan.FromMilliseconds(difference).TotalMinutes > 3)
            {
                result = EncryptedTokenValidationStatus.NonceFailed;
            }
            return(result);
        }
        public void PropertyTypeTest()
        {
            Expect.IsTrue(_testDatabases.Count > 0);
            string methodName = MethodBase.GetCurrentMethod().Name;

            _testDatabases.Each(db =>
            {
                Message.PrintLine("{0}.{1}: {2}", ConsoleColor.DarkYellow, this.GetType().Name, methodName, db.GetType().Name);
                DateTime utc           = DateTime.UtcNow;
                DaoReferenceObject obj = new DaoReferenceObject(db)
                {
                    IntProperty      = RandomNumber.Between(0, 100),
                    DecimalProperty  = 10.15m,
                    LongProperty     = 99999,
                    DateTimeProperty = utc,
                    BoolProperty     = true
                };
                string testName       = 16.RandomLetters();
                obj.ByteArrayProperty = new TestSerializable(testName).ToBinaryBytes();
                Instant now           = new Instant();
                obj.StringProperty    = now.ToString();

                obj.Save(db);

                DaoReferenceObject retrieved = DaoReferenceObject.OneWhere(c => c.Id == obj.Id, db);
                Expect.AreEqual(obj.Id, retrieved.Id, "Ids didn't match");
                Expect.AreEqual(obj.IntProperty, retrieved.IntProperty, "IntProperty didn't match");
                Expect.AreEqual(obj.DecimalProperty, retrieved.DecimalProperty, "DecimalProperty didn't match");
                Expect.AreEqual(obj.LongProperty, retrieved.LongProperty, "LongProperty didn't match");
                DateTime shouldBe = obj.DateTimeProperty.Value.DropMilliseconds();
                DateTime _is      = retrieved.DateTimeProperty.Value.DropMilliseconds();
                Expect.AreEqual(shouldBe, _is, "DateTimeProperty didn't match");
                Expect.AreEqual(obj.BoolProperty, retrieved.BoolProperty, "BoolProperty didn't match");
                Expect.AreEqual(obj.StringProperty, retrieved.StringProperty, "StringProperty didn't match");
                TestSerializable deserialized = obj.ByteArrayProperty.FromBinaryBytes <TestSerializable>();
                Expect.AreEqual(testName, deserialized.Name);
                Instant then = Instant.FromString(retrieved.StringProperty);
                Expect.AreEqual(now.ToDateTime(), then.ToDateTime());
            });
        }