93 lines
3.2 KiB
C#
93 lines
3.2 KiB
C#
using System.Text.Json;
|
|
using Tiku.Application.Content;
|
|
using Tiku.Domain.Content;
|
|
|
|
namespace Tiku.UnitTests;
|
|
|
|
public sealed class ContentV2RulesTests
|
|
{
|
|
[Fact]
|
|
public void Applicability_uses_or_between_groups_and_and_within_group()
|
|
{
|
|
var region = Guid.NewGuid();
|
|
var institution = Guid.NewGuid();
|
|
var province = Guid.NewGuid();
|
|
var city = Guid.NewGuid();
|
|
var university = Guid.NewGuid();
|
|
var profile = new[]
|
|
{
|
|
new TargetProfileFact(region, city, new HashSet<Guid> { province }),
|
|
new TargetProfileFact(institution, university, new HashSet<Guid>())
|
|
};
|
|
var groups = new[]
|
|
{
|
|
new PlacementRuleGroupFact(0,
|
|
[
|
|
new PlacementRuleConditionFact(region, province, TargetRuleOperator.DescendantOf),
|
|
new PlacementRuleConditionFact(institution, university, TargetRuleOperator.Exact)
|
|
]),
|
|
new PlacementRuleGroupFact(1,
|
|
[
|
|
new PlacementRuleConditionFact(region, Guid.NewGuid(), TargetRuleOperator.Exact)
|
|
])
|
|
};
|
|
|
|
Assert.True(QuestionApplicabilityEvaluator.Matches(profile, groups));
|
|
}
|
|
|
|
[Fact]
|
|
public void Applicability_supports_explicit_exclusion()
|
|
{
|
|
var region = Guid.NewGuid();
|
|
var province = Guid.NewGuid();
|
|
var excludedCity = Guid.NewGuid();
|
|
var profile = new[]
|
|
{
|
|
new TargetProfileFact(region, excludedCity, new HashSet<Guid> { province })
|
|
};
|
|
var groups = new[]
|
|
{
|
|
new PlacementRuleGroupFact(0,
|
|
[
|
|
new PlacementRuleConditionFact(region, province, TargetRuleOperator.DescendantOf),
|
|
new PlacementRuleConditionFact(region, excludedCity, TargetRuleOperator.NotExact)
|
|
])
|
|
};
|
|
|
|
Assert.False(QuestionApplicabilityEvaluator.Matches(profile, groups));
|
|
}
|
|
|
|
[Fact]
|
|
public void Delivery_fingerprint_is_canonical_and_includes_the_answer()
|
|
{
|
|
var first = Input(" Two plus two? ", "4", "[{\"text\":\"4\",\"key\":\"A\"}]");
|
|
var equivalent = Input("Two plus two?", "4", "[{\"key\":\"A\",\"text\":\"4\"}]");
|
|
var differentAnswer = Input("Two plus two?", "5", "[{\"key\":\"A\",\"text\":\"4\"}]");
|
|
|
|
Assert.Equal(QuestionDeliveryFingerprint.Compute(first), QuestionDeliveryFingerprint.Compute(equivalent));
|
|
Assert.NotEqual(QuestionDeliveryFingerprint.Compute(first), QuestionDeliveryFingerprint.Compute(differentAnswer));
|
|
}
|
|
|
|
[Fact]
|
|
public void Delivery_fingerprint_preserves_visible_letter_case()
|
|
{
|
|
Assert.NotEqual(
|
|
QuestionDeliveryFingerprint.Compute(Input("US policy", "A", "[]")),
|
|
QuestionDeliveryFingerprint.Compute(Input("us policy", "A", "[]")));
|
|
}
|
|
|
|
private static QuestionDeliveryFingerprintInput Input(string content, string answer, string options)
|
|
{
|
|
return new QuestionDeliveryFingerprintInput(
|
|
"choice",
|
|
content,
|
|
JsonDocument.Parse(options).RootElement.Clone(),
|
|
0,
|
|
JsonDocument.Parse("[]").RootElement.Clone(),
|
|
answer,
|
|
JsonDocument.Parse("[]").RootElement.Clone(),
|
|
null,
|
|
null);
|
|
}
|
|
}
|