public void GetRandomWeightedItem_WithCollection_ReturnsCorrectItem(int randomNumber, int expectedItem) { var mockRandomNumberGenerator = new Mock <IRandomNumberGenerator>(); mockRandomNumberGenerator.Setup(x => x.GetRandomInteger(6)).Returns(randomNumber); var randomItemSelector = new RandomItemSelector(mockRandomNumberGenerator.Object); var items = new WeightedItem[] { new WeightedItem { RandomizationWeight = 1 }, new WeightedItem { RandomizationWeight = 2 }, new WeightedItem { RandomizationWeight = 3 }, }; var item = randomItemSelector.GetRandomWeightedItem <WeightedItem>(items); Assert.AreEqual(items[expectedItem], item); mockRandomNumberGenerator.Verify(x => x.GetRandomInteger(6), Times.Once); mockRandomNumberGenerator.VerifyNoOtherCalls(); }
public void GetRandomWeightedItem_WithEmptyArray_Throws() { var randomItemSelector = new RandomItemSelector(new RandomNumberGenerator()); Assert.Throws <ArgumentException>(() => randomItemSelector.GetRandomWeightedItem <WeightedItem>(new WeightedItem[0])); }