public void Xid_ToByte_ThrowsOnBufferTooSmall()
        {
            var buffer = new byte[11];
            var x      = Xid.NewXid();

            x.ToBytes(buffer);
        }
Example #2
0
        public void Xid_TryParse_ParsesValidXid()
        {
            var s  = "9m4e2mr0ui3e8a215n4g";
            var ok = Xid.TryParse(s, out Xid x);

            Assert.IsTrue(ok);
            Assert.AreEqual(Xid.Parse(s), x);
        }
        public void Xid_ToString_IgnoresFormatAndCulture()
        {
            var x  = Xid.NewXid();
            var s  = x.ToString();
            var s2 = x.ToString("X", System.Globalization.CultureInfo.CurrentCulture);

            Assert.AreEqual(s, s2);
        }
        public void Xid_ToString_ParsesBackToOriginalValue()
        {
            var x = Xid.NewXid();
            var s = x.ToString();
            var y = Xid.Parse(s);

            Assert.AreEqual(x, y);
        }
Example #5
0
        public void Xid_Equals_ReturnsTrueWhenEqual()
        {
            var x = Xid.NewXid();
            var y = new Xid(x.ToBytes());

            Assert.AreEqual <Xid>(x, y);
            Assert.AreEqual <string>(x.ToString(), y.ToString());
            Assert.IsTrue(x == y);
        }
 public void Xid_ToString_CreatesCorrectLengthString()
 {
     for (int cnt = 0; cnt < 100000; cnt++)
     {
         var x = Xid.NewXid();
         var s = x.ToString();
         Assert.AreEqual(Xid.EncodedLength, s.Length);
     }
 }
Example #7
0
        public void Xid_Equals_ReturnsFalseWhenUnequal()
        {
            var x = Xid.NewXid();
            var y = Xid.Empty;

            Assert.AreNotEqual <Xid>(x, y);
            Assert.AreNotEqual <string>(x.ToString(), y.ToString());
            Assert.IsFalse(x == y);
        }
Example #8
0
        public void Xid_New_GeneratesXid()
        {
            var xid = Xid.NewXid();
            var t   = xid.GetTimestamp();
            var p   = xid.GetProcessId();
            var p1  = System.Diagnostics.Process.GetCurrentProcess().Id;
            var c   = xid.GetCounter();

            System.Diagnostics.Trace.WriteLine(xid.ToString());
        }
        public void Xid_ToByte_FillsBuffer()
        {
            var buffer = new byte[12];
            var x      = Xid.NewXid();

            x.ToBytes(buffer);
            var y = new Xid(buffer);

            Assert.AreEqual(x, y);
        }
Example #10
0
        public void Xid_Parse_ParsesValueToExpectedBytes()
        {
            var x = Xid.Parse("9m4e2mr0ui3e8a215n4g");
            var y = new Xid(new byte[] { 0x4d, 0x88, 0xe1, 0x5b, 0x60, 0xf4, 0x86, 0xe4, 0x28, 0x41, 0x2d, 0xc9 });

            Assert.AreEqual(x, y);
            Assert.AreEqual("9m4e2mr0ui3e8a215n4g", y.ToString());
            Assert.AreEqual(4271561, x.GetCounter());
            Assert.AreEqual(63436413019, x.GetTimestamp().Subtract(DateTime.MinValue).TotalSeconds);
            Assert.AreEqual(0xe428, x.GetProcessId());
        }
Example #11
0
        public void Xid_GetHashCode_EqualCodesForEqualValues()
        {
            var maxIterations = 1000000;

            for (int cnt = 0; cnt < maxIterations; cnt++)
            {
                var x = Xid.NewXid();
                var y = Xid.Parse(x.ToString());
                Assert.AreEqual(x.GetHashCode(), y.GetHashCode());
            }
        }
Example #12
0
        public void Xid_GetHashCode_UnequalCodesForUnequalValues()
        {
            var maxIterations = 1000000;

            for (int cnt = 0; cnt < maxIterations; cnt++)
            {
                var x = Xid.NewXid();
                var y = Xid.NewXid();
                Assert.AreNotEqual(x.GetHashCode(), y.GetHashCode());
            }
        }
Example #13
0
        public void Xid_ToByte_FillsBufferAtOffset()
        {
            var buffer  = new byte[100];
            var x       = Xid.NewXid();
            var buffer2 = x.ToBytes();

            x.ToBytes(buffer, 50);
            for (int i = 50; i < 62; i++)
            {
                Assert.AreEqual(buffer[i], buffer2[i - 50]);
            }
        }
        public async Task <IActionResult> CreateApplication([FromBody] ApplicationInfo payload)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var appId = Xid.NewXid().ToString();

            payload.ApplicationId = appId;
            await _definitionStore.CreateApplication(appId, payload).ConfigureAwait(false);

            return(CreatedWithLocation(appId, payload));
        }
        public void Stream_ReadXid_ThrowsWhenInsufficientBytesRemaining()
        {
            using (var ms = new System.IO.MemoryStream(Xid.Length))
            {
                var x = Xid.NewXid();
                ms.WriteXid(x);

                Assert.AreEqual(Xid.Length, ms.Length);
                Assert.AreEqual(Xid.Length, ms.Position);

                ms.Seek(6, System.IO.SeekOrigin.Begin);
                var y = ms.ReadXid();
            }
        }
        public void Xid_New_Performance()
        {
            var iterations = 20000000;
            var sw         = new System.Diagnostics.Stopwatch();

            sw.Start();
            for (var cnt = 0; cnt < iterations; cnt++)
            {
                var x = Xid.NewXid();
            }
            sw.Stop();
            System.Diagnostics.Trace.WriteLine(sw.Elapsed);
            System.Diagnostics.Trace.WriteLine(((Convert.ToDouble(sw.Elapsed.TotalMilliseconds * TimeSpan.TicksPerMillisecond) / Convert.ToDouble(iterations)) * 100).ToString("#0.00") + "ns per op");
        }
Example #17
0
        public string Add(Transaction transaction)
        {
            using (_transactionIdsLock.Lock())
            {
                if (!_transactionIdToClientOrderIdMap.TryGetValue(transaction.TransactionId, out var clOrderId))
                {
                    clOrderId = Xid.NewXid().ToString();
                    _transactionIdToClientOrderIdMap[transaction.TransactionId] = clOrderId;
                    _clientOrderIdToTransactionIdMap[clOrderId] = transaction.TransactionId;
                }

                return clOrderId;
            }
        }
Example #18
0
        public void Xid_ToByte_Creates12ByteArray()
        {
            var x = Xid.NewXid().ToBytes();

            Assert.IsNotNull(x);
            Assert.AreEqual(12, x.Length);
            int value = 0;

            for (int cnt = 0; cnt < x.Length; cnt++)
            {
                value += x[cnt];
            }

            Assert.IsTrue(value > 0);
        }
Example #19
0
        public void Xid_New_NewXidsAreKSorted()
        {
            var lastXid = Xid.Empty;

            for (var cnt = 0; cnt < 1000000; cnt++)
            {
                var x = Xid.NewXid();
                Assert.AreEqual(1, x.CompareTo(lastXid));
                Assert.IsTrue(x > lastXid);
                Assert.AreEqual(-1, lastXid.CompareTo(x));
                Assert.IsTrue(lastXid < x);

                lastXid = x;
            }
        }
        /// <summary>
        /// Returns true if Model3dsData instances are equal
        /// </summary>
        /// <param name="other">Instance of Model3dsData to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(ThreeDSEnrollment other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Downgraded == other.Downgraded ||
                     Downgraded != null &&
                     Downgraded.Equals(other.Downgraded)
                     ) &&
                 (
                     Enrolled == other.Enrolled ||
                     Enrolled != null &&
                     Enrolled.Equals(other.Enrolled)
                 ) &&
                 (
                     SignatureValid == other.SignatureValid ||
                     SignatureValid != null &&
                     SignatureValid.Equals(other.SignatureValid)
                 ) &&
                 (
                     AuthenticationResponse == other.AuthenticationResponse ||
                     AuthenticationResponse != null &&
                     AuthenticationResponse.Equals(other.AuthenticationResponse)
                 ) &&
                 (
                     Cryptogram == other.Cryptogram ||
                     Cryptogram != null &&
                     Cryptogram.Equals(other.Cryptogram)
                 ) &&
                 (
                     Xid == other.Xid ||
                     Xid != null &&
                     Xid.Equals(other.Xid)
                 ) &&
                 (
                     Version == other.Version ||
                     Version != null &&
                     Version.Equals(other.Version)
                 ));
        }
Example #21
0
    public static Player GeneratePlayer()
    {
        Player player = new Player
        {
            Id = Xid.NewXid().ToString()
        };
        var properties = new Dictionary <string, Dictionary <string, int> >();
        var mmr        = new Dictionary <string, int>
        {
            { "rating", 1000 }
        };

        properties.Add("mmr", mmr);
        player.Properties = JsonConvert.SerializeObject(properties);
        return(player);
    }
        private Message GetMessage(object message)
        {
            var jsonBytes  = SerializationHelper.GetJsonBytes(message);
            var newMessage = new Message(jsonBytes);

            // echo back user headers
            foreach (var header in _incomingMessage.UserProperties)
            {
                newMessage.UserProperties.Add(header.Key, header.Value);
            }

            newMessage.CorrelationId = _incomingMessage.MessageId;
            newMessage.MessageId     = Xid.NewXid().ToString();
            newMessage.UserProperties[HeaderTypes.EnclosedType] = message.GetType().FullName;

            return(newMessage);
        }
        public void Stream_ReadXid_CorrectlyReadsXid()
        {
            using (var ms = new System.IO.MemoryStream(Xid.Length))
            {
                var x = Xid.NewXid();
                ms.WriteXid(x);

                Assert.AreEqual(Xid.Length, ms.Length);
                Assert.AreEqual(Xid.Length, ms.Position);

                ms.Seek(0, System.IO.SeekOrigin.Begin);
                var y = ms.ReadXid();

                Assert.AreEqual(x, y);
                Assert.AreEqual(Xid.Length, ms.Length);
                Assert.AreEqual(Xid.Length, ms.Position);
            }
        }
Example #24
0
        public void Xid_New_GeneratesSequence()
        {
            var previousId = Xid.Empty;

            for (var cnt = 0; cnt < 1000; cnt++)
            {
                var xid = Xid.NewXid();
                if (cnt > 0)
                {
                    var secs = xid.GetTimestamp().Subtract(previousId.GetTimestamp()).TotalSeconds;
                    Assert.IsTrue(secs >= 0 && secs <= 30);
                    Assert.AreEqual(previousId.GetProcessId(), xid.GetProcessId());
                    Assert.IsTrue(ArraysAreEqual(previousId.GetMachineId(), xid.GetMachineId()));
                    Assert.AreEqual(previousId.GetCounter() + 1, xid.GetCounter());
                }
                System.Diagnostics.Trace.WriteLine(xid.ToString());
                previousId = xid;
            }
        }
Example #25
0
        public void Xid_New_GeneratesUniqueXids()
        {
            var maxIterations = 20000000;

            if (IntPtr.Size > 4)
            {
                maxIterations = 40000000;                 //Moa tests on 64 bit! (32 bit runs out of contiguous memory for dictionary)
            }
            var unique = new Dictionary <Xid, Xid>(maxIterations);
            var sw     = new System.Diagnostics.Stopwatch();

            sw.Start();
            for (var cnt = 0; cnt < maxIterations; cnt++)
            {
                var x = Xid.NewXid();
                unique.Add(x, x);
            }
            sw.Stop();
            System.Diagnostics.Trace.WriteLine(sw.Elapsed);
        }
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Downgraded != null)
         {
             hashCode = hashCode * 59 + Downgraded.GetHashCode();
         }
         if (Enrolled != null)
         {
             hashCode = hashCode * 59 + Enrolled.GetHashCode();
         }
         if (SignatureValid != null)
         {
             hashCode = hashCode * 59 + SignatureValid.GetHashCode();
         }
         if (AuthenticationResponse != null)
         {
             hashCode = hashCode * 59 + AuthenticationResponse.GetHashCode();
         }
         if (Cryptogram != null)
         {
             hashCode = hashCode * 59 + Cryptogram.GetHashCode();
         }
         if (Xid != null)
         {
             hashCode = hashCode * 59 + Xid.GetHashCode();
         }
         if (Version != null)
         {
             hashCode = hashCode * 59 + Version.GetHashCode();
         }
         return(hashCode);
     }
 }
        private Message CreateNewMessage(object message, SendOptions options = null)
        {
            var jsonBytes = SerializationHelper.GetJsonBytes(message);
            var msg       = new Message(jsonBytes)
            {
                ContentType = "application/json"
            };

            if (options != null)
            {
                foreach (var header in options.Headers)
                {
                    msg.UserProperties.Add(header.Key, header.Value);
                }
            }

            msg.ReplyTo       = Configuration.EndpointName;
            msg.MessageId     = Xid.NewXid().ToString();
            msg.CorrelationId = msg.MessageId;
            msg.UserProperties[HeaderTypes.ConversationId] = Xid.NewXid().ToString();
            msg.UserProperties[HeaderTypes.EnclosedType]   = message.GetType().FullName;

            return(msg);
        }
Example #28
0
 public void DtxSetTimeout(Xid Xid, long Timeout, params Option[] options) {
     Invoke(new DtxSetTimeout(Xid, Timeout, options));
 }
Example #29
0
 public IFuture DtxRollback(Xid Xid, params Option[] options) {
     return Invoke(new DtxRollback(Xid, options), new ResultFuture());
 }
Example #30
0
 public IFuture DtxGetTimeout(Xid Xid, params Option[] options) {
     return Invoke(new DtxGetTimeout(Xid, options), new ResultFuture());
 }
Example #31
0
 public void DtxForget(Xid Xid, params Option[] options) {
     Invoke(new DtxForget(Xid, options));
 }
Example #32
0
        public void Xid_Parse_ThrowsOnLongString()
        {
            var y = Xid.Parse("9m4e2mr0ui3e8a215n4g9m4e2mr0ui3e8a215n4g");

            Assert.Fail();
        }
Example #33
0
        public void Xid_Parse_ThrowsOnInvalidCharacters()
        {
            var y = Xid.Parse("9m4e2mrZui3e8a215n4g");

            Assert.Fail();
        }
Example #34
0
        public void Xid_New_GeneratesUniqueXids_Threaded()
        {
            var maxIterations = 10000000;

            var threadCount = Math.Max(2, Environment.ProcessorCount);
            var step        = maxIterations / threadCount;

            //var unique = new Dictionary<string, Xid>(maxIterations);
            var unique = new Dictionary <Xid, Xid>(maxIterations / 2);

            var threads      = new List <System.Threading.Thread>(threadCount);
            var dictionaries = new List <Dictionary <Xid, Xid> >(threadCount);

            for (var tcnt = 0; tcnt < threadCount; tcnt++)
            {
                dictionaries.Add(new Dictionary <Xid, Xid>(step));

                threads.Add
                (
                    new System.Threading.Thread
                    (
                        (o) =>
                {
                    var g  = dictionaries.Count;
                    var oa = (object[])o;

                    var i    = (int)oa[0];
                    var dict = (Dictionary <Xid, Xid>)oa[1];

                    var start = i * step;
                    var end   = start + step;

                    for (var cnt = start; cnt < end; cnt++)
                    {
                        var x = Xid.NewXid();
                        dict.Add(x, x);
                    }
                }
                    )
                );
            }

            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            for (var cnt = 0; cnt < threadCount; cnt++)
            {
                threads[cnt].Start(new object[] { cnt, dictionaries[cnt] });
            }

            foreach (var thread in threads)
            {
                thread.Join();
            }
            sw.Stop();

            foreach (var dict in dictionaries)
            {
                foreach (var kvp in dict)
                {
                    unique.Add(kvp.Key, kvp.Key);
                }
            }

            System.Diagnostics.Trace.WriteLine(sw.Elapsed);
            Assert.AreEqual(maxIterations, unique.Count);
        }