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); }
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); }
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()); }
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)); }
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); } }