public void Evaluate_SingleVersionRange(string sdkVersion, bool allowed) { var config = new { identity = "test-constraint-01", constraints = new { specVersions = new { type = "sdk-version", args = "(1.2.3-*, 4.5]" } } }; var configModel = SimpleConfigModel.FromJObject(JObject.FromObject(config)); ISdkInfoProvider sdkInfoProvider = new SdkInfoProviderMock(sdkVersion); //A.Fake<ISdkInfoProvider>(); IEngineEnvironmentSettings settings = A.Fake <IEngineEnvironmentSettings>(); A.CallTo(() => settings.Components.OfType <ISdkInfoProvider>()).Returns(new[] { sdkInfoProvider }); A.CallTo(() => settings.Components.OfType <ITemplateConstraintFactory>()).Returns(new[] { new SdkVersionConstraintFactory() }); var constraintManager = new TemplateConstraintManager(settings); //Workaround needed //A.CallTo(() => sdkInfoProvider.GetVersionAsync(A<CancellationToken>._)).Returns(t); var evaluateResult = constraintManager.EvaluateConstraintAsync(configModel.Constraints.Single().Type, configModel.Constraints.Single().Args, default).Result; Assert.Equal(allowed ? TemplateConstraintResult.Status.Allowed : TemplateConstraintResult.Status.Restricted, evaluateResult.EvaluationStatus); }
public async Task Evaluate_AlternativeInstalledVersions(string sdkVersion, IReadOnlyList <string> installedVersions, bool hasAlternativeInstalled) { var config = new { identity = "test-constraint-01", constraints = new { specVersions = new { type = "sdk-version", args = new[] { "1.2.3-*", "4.5.*" } } } }; var configModel = SimpleConfigModel.FromJObject(JObject.FromObject(config)); ISdkInfoProvider sdkInfoProvider = new SdkInfoProviderMock(sdkVersion, installedVersions); //A.Fake<ISdkInfoProvider>(); IEngineEnvironmentSettings settings = A.Fake <IEngineEnvironmentSettings>(); A.CallTo(() => settings.Components.OfType <ISdkInfoProvider>()).Returns(new[] { sdkInfoProvider }); A.CallTo(() => settings.Components.OfType <ITemplateConstraintFactory>()).Returns(new[] { new SdkVersionConstraintFactory() }); var constraintManager = new TemplateConstraintManager(settings); var evaluateResult = await constraintManager.EvaluateConstraintAsync(configModel.Constraints.Single().Type, configModel.Constraints.Single().Args, default).ConfigureAwait(false); Assert.Equal(TemplateConstraintResult.Status.Restricted, evaluateResult.EvaluationStatus); Assert.StartsWith( hasAlternativeInstalled ? "Sample CTA with alternatives" : "Sample CTA without alternatives", evaluateResult.CallToAction); }