Exemple #1
0
            public void ShouldGetTheSecondKeyFromTheHiValue()
            {
                // Arrange
                var mock = new Mock <IHiLoRepository>();

                mock.Setup(m => m.GetNextHi()).Returns(1);
                var generator = new HiLoGenerator(mock.Object, 10);

                // Act
                generator.GetKey();
                long key = generator.GetKey();

                // Assert
                Assert.Equal(11, key);
            }
Exemple #2
0
            public void ShouldGetThe11thKeyFromTheHiValue()
            {
                // Arrange
                int hi   = 1;
                var mock = new Mock <IHiLoRepository>();

                mock.Setup(m => m.GetNextHi()).Returns(() => hi++);
                var generator = new HiLoGenerator(mock.Object, 10);

                // Act
                for (int i = 1; i <= 10; i++)
                {
                    generator.GetKey();
                }
                long key = generator.GetKey();

                // Assert
                Assert.Equal(20, key);
            }
Exemple #3
0
            public void ShouldGetTheHiValueFromRepository()
            {
                // Arrange
                var mock = new Mock <IHiLoRepository>();

                mock.Setup(m => m.GetNextHi()).Returns(1);
                var generator = new HiLoGenerator(mock.Object, 10);

                // Act
                generator.GetKey();
                // Assert
                mock.Verify(m => m.GetNextHi(), Times.Once());
            }
Exemple #4
0
            public void ShouldGetTheHiValueFromRepositoryTwiceFor11KeyGenerationsWith10AsMaxLo()
            {
                // Arrange
                var mock = new Mock <IHiLoRepository>();

                mock.Setup(m => m.GetNextHi()).Returns(1);
                var generator = new HiLoGenerator(mock.Object, 10);

                // Act
                for (int i = 1; i <= 11; i++)
                {
                    generator.GetKey();
                }
                // Assert
                mock.Verify(m => m.GetNextHi(), Times.Exactly(2));
            }
Exemple #5
0
            public void ShouldGetDifferentKeysForEachCall()
            {
                // Arrange
                List <long> keys = new List <long>();
                int         hi   = 1;
                var         mock = new Mock <IHiLoRepository>();

                mock.Setup(m => m.GetNextHi()).Returns(() => hi++);
                var generator = new HiLoGenerator(mock.Object, 10);

                // Act
                for (int i = 1; i <= 30; i++)
                {
                    long key = generator.GetKey();
                    // Assert
                    Assert.DoesNotContain(key, keys);
                    keys.Add(key);
                }
            }