public void EvaluateTest() { var evaluation = new RulesEvaluation( logger, mockDeviceGroups.Object); // Repeat times for broader coverage foreach (var unused in Enumerable.Range(0, 10)) { var totalConditions = rand.Next(3, 10); var message = rand.NextRawMessage(); var rule = new RuleApiModel { GroupId = rand.NextString(), Conditions = Enumerable.Range(0, totalConditions).Select(i => GenerateCondition(message, true)).ToList() }; mockDeviceGroups .Setup(x => x.GetDevicesAsync( It.IsAny <string>())) .ReturnsAsync(new[] { message.DeviceId }); var result = evaluation.Evaluate(rule, message); mockDeviceGroups .Verify(x => x.GetDevicesAsync( It.Is <string>(s => s == rule.GroupId)), Times.Once); Assert.True(result.Match); } }
public void UnmatchDeviceGroupTest() { var evaluation = new RulesEvaluation( logger, mockDeviceGroups.Object); mockDeviceGroups .Setup(x => x.GetDevicesAsync( It.IsAny <string>())) .ReturnsAsync(new string[] { }); var rule = new RuleApiModel { GroupId = rand.NextString() }; var message = rand.NextRawMessage(); var result = evaluation.Evaluate(rule, message); Assert.False(result.Match); }