Esempio n. 1
0
        public void CreateNew_ShouldReturnNewGuid_WithoutCollisions_WhenTypeIsBinaryEnd()
        {
            // Arrange
            const int numberOfChars = SequentialGuidFactory.NumberOfSequentialBytes * 2;              // 2 chars per byte

            var uniqueResults  = new HashSet <Guid>();
            var sequentialData = new string[TestIterations];
            var subject        = new SequentialGuidFactory(SequentialGuidType.BinaryEnd);

            for (var i = 0; i < TestIterations; i++)
            {
                // Act
                var result = subject.CreateNew();

                // Assert
                uniqueResults.Add(result).Should().BeTrue();
                var guidString = result.ToString();
                sequentialData[i] = guidString.Substring(guidString.Length - numberOfChars, numberOfChars);
            }

            uniqueResults.Should().HaveCount(TestIterations);
            uniqueResults.Should().NotContain(Guid.Empty);

            sequentialData.Should().BeInAscendingOrder();
        }
Esempio n. 2
0
        public void CreateNew_Benchmark_WhenTypeIsBinary()
        {
            // Arrange
            var subject = new SequentialGuidFactory(SequentialGuidType.Binary);
            var timer   = Stopwatch.StartNew();

            for (var i = 0; i < TestIterations; i++)
            {
                // Act
                subject.CreateNew();
            }

            // Assert
            timer.Stop();
            timer.ElapsedMilliseconds.Should().BeLessOrEqualTo(500);
        }
Esempio n. 3
0
        public void CreateNew_ShouldReturnNewGuid_WithoutCollisions_WhenTypeIsBinary()
        {
            // Arrange
            var uniqueResults  = new HashSet <Guid>();
            var sequentialData = new string[TestIterations];
            var subject        = new SequentialGuidFactory(SequentialGuidType.Binary);

            for (var i = 0; i < TestIterations; i++)
            {
                // Act
                var result = subject.CreateNew();

                // Assert
                uniqueResults.Add(result).Should().BeTrue();
                var sequentialBytes = result.ToByteArray().Take(SequentialGuidFactory.NumberOfSequentialBytes).ToArray();
                sequentialData[i] = BitConverter.ToString(sequentialBytes);
            }

            uniqueResults.Should().HaveCount(TestIterations);
            uniqueResults.Should().NotContain(Guid.Empty);

            sequentialData.Should().BeInAscendingOrder();
        }