Ejemplo n.º 1
0
        public void GetNextNuid_PrefixIsConstant()
        {
            // Arrange
            var nuid = new Nuid();

            // Act
            var firstNuid  = nuid.GetNext().Substring(0, 12);
            var secondNuid = nuid.GetNext().Substring(0, 12);

            // Assert
            Assert.Equal(firstNuid, secondNuid);
        }
Ejemplo n.º 2
0
        public void GetNextNuid_ReturnsDifferentNuidEachTime()
        {
            // Arrange
            var nuid = new Nuid();

            // Act
            var firstNuid  = nuid.GetNext();
            var secondNuid = nuid.GetNext();

            // Assert
            Assert.NotEqual(firstNuid, secondNuid);
        }
Ejemplo n.º 3
0
        public void GetNextNuid_ReturnsNuidOfLength22()
        {
            // Arrange
            var nuid = new Nuid();

            //Act
            var result = nuid.GetNext();

            // Assert
            Assert.Equal(22, result.Length);
        }
Ejemplo n.º 4
0
        public void GetNextNuid_PrefixAsExpected()
        {
            // Arrange
            var rngBytes = new byte[12] {
                0, 1, 2, 3, 4, 5, 6, 7, 11, 253, 254, 255
            };
            var rng = new ControlledRng(new Queue <byte[]>(new byte[][] { rngBytes, rngBytes }));

            var nuid = new Nuid(rng);

            // Act
            var prefix = nuid.GetNext().Substring(0, 12);

            // Assert
            Assert.Equal("ABCDEFGHL9-_", prefix);
        }
Ejemplo n.º 5
0
        public void GetNextNuid_NuidsAreUnique()
        {
            // Arrange
            const int count = 1_000_000;
            var       nuid  = new Nuid();
            var       nuids = new HashSet <string>(StringComparer.Ordinal);

            // Act
            for (var i = 0; i < count; i++)
            {
                var currentNuid = nuid.GetNext();

                //HashSet.Add returns false if the set already contains the item
                if (nuids.Add(currentNuid))
                {
                    continue;
                }

                _outputHelper.WriteLine($"Duplicate Nuid {currentNuid}");
                Assert.True(false, "Duplicate Nuid detected");
            }
        }