1+ using IdGen ;
2+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
3+ using System ;
4+
5+ namespace IdGenTests ;
6+
7+ [ TestClass ]
8+ public class DatacenterMachineIdGeneratorIdCreatorTests
9+
10+ {
11+ [ TestMethod ]
12+ public void Create_ShouldCreateCorrectId ( )
13+ {
14+ Assert . AreEqual ( 0 , DatacenterMachineIdGeneratorIdCreator . Create ( 0 , 0 , 4 , 4 ) ) ;
15+ Assert . AreEqual ( 52394 , DatacenterMachineIdGeneratorIdCreator . Create ( 204 , 170 , 8 , 8 ) ) ;
16+ Assert . AreEqual ( 2147483647 , DatacenterMachineIdGeneratorIdCreator . Create ( 536870911 , 3 , 29 , 2 ) ) ;
17+ Assert . AreEqual ( 255 , DatacenterMachineIdGeneratorIdCreator . Create ( 15 , 15 , 4 , 4 ) ) ;
18+ Assert . AreEqual ( 255 , DatacenterMachineIdGeneratorIdCreator . Create ( 127 , 1 , 7 , 1 ) ) ;
19+ }
20+
21+ [ TestMethod ]
22+ [ ExpectedException ( typeof ( InvalidOperationException ) ) ]
23+ public void Create_ShouldThrowOnMoreThan31TotalBits ( )
24+ => DatacenterMachineIdGeneratorIdCreator . Create ( 0 , 0 , 30 , 2 ) ;
25+
26+ [ TestMethod ]
27+ [ ExpectedException ( typeof ( ArgumentOutOfRangeException ) ) ]
28+ public void Create_ShouldThrowOnDatacenterIdExceedingBits ( )
29+ => DatacenterMachineIdGeneratorIdCreator . Create ( 4 , 0 , 2 , 8 ) ;
30+
31+ [ TestMethod ]
32+ [ ExpectedException ( typeof ( ArgumentOutOfRangeException ) ) ]
33+ public void Create_ShouldThrowOnWorkerIdExceedingBits ( )
34+ => DatacenterMachineIdGeneratorIdCreator . Create ( 0 , 4 , 8 , 2 ) ;
35+ }
0 commit comments