public void GetId_Get65536OrLessIds_NoDelay(int numberOfIds) { // Arrange // When delay is called, start moving the millisecond timer. _timingProvider.When(x => x.DelayMilliseconds(Arg.Any <int>())) .Do(arg => _wasDelayed = true); _timingProvider.GetNowMilliseconds() .ReturnsForAnyArgs(x => _wasDelayed ? ++_nowMilliseconds : _nowMilliseconds); // Act Int128 id = null; for (int i = 0; i < numberOfIds; i++) { id = _generator.GenId(); } // Assert _timingProvider.DidNotReceiveWithAnyArgs().DelayMilliseconds(Arg.Any <int>()); Assert.That(id?.Lo & 0xffff, Is.EqualTo(numberOfIds - 1), "Count part of ID"); }
public CompteEnBanque Post([FromBody] CompteEnBanqueAjouter value) { CompteEnBanque compte = new CompteEnBanque { ID = IdGenerator.GenId(), Argent = value.Argent, Nom = value.Nom, NumeroCompte = value.NumeroCompte, }; labanque.Add(compte); return(compte); }
public void GetId_MacAddressOverridden_IdUsesOverriddenMacAddress() { // Arrange const string macAddressOverride = "12345"; const long expectedMacAddress = 12345L; _idGeneratorOptions.Value.Returns(new IdGeneratorOptions { MacAddress = macAddressOverride }); IdGenerator generator = CreateIdGenerator(); // Act Int128 id = generator.GenId(); // Assert Assert.That(id?.Lo >> 16, Is.EqualTo(expectedMacAddress), "MAC address part of ID"); }
public void GetId_Get65537Ids_DelaysToNextMillisecond() { // Arrange // When delay is called, start moving the millisecond timer. _timingProvider.When(x => x.DelayMilliseconds(Arg.Any <int>())) .Do(arg => _wasDelayed = true); _timingProvider.GetNowMilliseconds() .ReturnsForAnyArgs(x => _wasDelayed ? ++_nowMilliseconds : _nowMilliseconds); IdGenerator generator = CreateIdGenerator(); // Act int numberOfIds = 0x10001; Int128 id = null; for (int i = 0; i < numberOfIds; i++) { id = generator.GenId(); } // Assert _timingProvider.Received(1).DelayMilliseconds(Arg.Any <int>()); Assert.That(id?.Lo & 0xffff, Is.EqualTo(0), "Count part of ID"); }