Exemple #1
0
    public async Task SavedScriptSecretIsUsedDuringExecution()
    {
        var sut = Container.Resolve <ISecretRepository>() as SecretRepository;

        Assert.IsNotNull(sut);

        var errorsAndInfos = new ErrorsAndInfos();

        await SetShouldDefaultSecretsBeStored(sut, true, errorsAndInfos);

        Assert.IsFalse(errorsAndInfos.Errors.Any(), errorsAndInfos.ErrorsToString());

        var secret = new SecretStringFunction();

        sut.Reset(secret, false);
        var script = await sut.GetAsync(secret, errorsAndInfos);

        Assert.IsFalse(errorsAndInfos.Errors.Any(), errorsAndInfos.ErrorsToString());
        const string addedString = "/* This script has been altered */";

        Assert.IsFalse(script.LambdaExpression.Contains(addedString));
        script.LambdaExpression = addedString + "\r\n" + script.LambdaExpression;
        await sut.SetAsync(secret, errorsAndInfos);

        Assert.IsFalse(errorsAndInfos.Errors.Any(), errorsAndInfos.ErrorsToString());
        sut.Values.Clear();
        await sut.ValueOrDefaultAsync(secret, errorsAndInfos);

        Assert.IsFalse(errorsAndInfos.Errors.Any(), errorsAndInfos.ErrorsToString());
        script = (CsLambda)sut.Values[secret.Guid];
        Assert.IsTrue(script.LambdaExpression.StartsWith(addedString));
        CleanUpSecretRepository(false);
    }
Exemple #2
0
    public async Task DefaultScriptSecretIsNotReturnedIfSecretSaysItShouldNotBeSaved()
    {
        var sut = Container.Resolve <ISecretRepository>() as SecretRepository;

        Assert.IsNotNull(sut);

        var errorsAndInfos = new ErrorsAndInfos();

        await SetShouldDefaultSecretsBeStored(sut, false, errorsAndInfos);

        Assert.IsFalse(errorsAndInfos.Errors.Any(), errorsAndInfos.ErrorsToString());

        var secret = new SecretStringFunction();

        sut.Reset(secret, false);
        Assert.IsNull(await sut.GetAsync(secret, errorsAndInfos));
        Assert.IsTrue(errorsAndInfos.Errors.Any(e => e.Contains("Secret has not been defined", StringComparison.InvariantCultureIgnoreCase)), errorsAndInfos.ErrorsToString());
        CleanUpSecretRepository(false);
    }
Exemple #3
0
    public async Task DefaultScriptSecretIsSavedIfSecretSaysSo()
    {
        var sut = Container.Resolve <ISecretRepository>() as SecretRepository;

        Assert.IsNotNull(sut);

        var errorsAndInfos = new ErrorsAndInfos();

        await SetShouldDefaultSecretsBeStored(sut, true, errorsAndInfos);

        Assert.IsFalse(errorsAndInfos.Errors.Any(), errorsAndInfos.ErrorsToString());

        var secret = new SecretStringFunction();

        sut.Reset(secret, false);
        await sut.GetAsync(secret, errorsAndInfos);

        Assert.IsFalse(errorsAndInfos.Errors.Any(), errorsAndInfos.ErrorsToString());
        Assert.IsTrue(sut.Exists(secret, false));
        CleanUpSecretRepository(false);
    }
Exemple #4
0
    public async Task CanGetScriptSecret()
    {
        var sut = Container.Resolve <ISecretRepository>() as SecretRepository;

        Assert.IsNotNull(sut);

        var errorsAndInfos = new ErrorsAndInfos();

        await SetShouldDefaultSecretsBeStored(sut, true, errorsAndInfos);

        Assert.IsFalse(errorsAndInfos.Errors.Any(), errorsAndInfos.ErrorsToString());

        var secret = new SecretStringFunction();

        sut.Reset(secret, false);
        const string s = "This is not a string";
        var          r = (await sut.CompileCsLambdaAsync <string, string>(await sut.GetAsync(secret, errorsAndInfos)))(s);

        Assert.IsFalse(errorsAndInfos.Errors.Any(), errorsAndInfos.ErrorsToString());
        Assert.IsTrue(r.StartsWith(s));
        Assert.IsTrue(r.Contains("with greetings from a csx"));
    }