Example #1
0
    public void StaticCreateError(string error)
    {
        var info = ValidationInfo.CreateFailure(error);

        Assert.AreEqual(false, info.IsValid, "The constructor to create a info with a single error is wrongly valid.");
        Assert.IsNotNull(info.Errors, "The error list of the ValidationInfo is wrongly null.");
        Assert.AreEqual(1, info.Errors.Count, $"The ValidationInfo created with a single error contains {info.Errors.Count} errors.");
        Assert.AreEqual(error, info.Errors.ElementAt(0), $"The single error message is {info.Errors.ElementAt(0)} instead of {error}.");
    }
    public void AddSuccessToInvalid()
    {
        var info = ValidationInfo.CreateFailure("error");

        info.AddSuccess("success");
        Assert.IsFalse(info.IsValid);
        Assert.IsNotNull(info.Successes);
        Assert.AreEqual(1, info.Successes.Count);
        Assert.AreEqual("success", info.Successes.ElementAt(0));
    }
    public void AddWarningToInvalid()
    {
        var info = ValidationInfo.CreateFailure("error");

        info.AddWarning("warning");
        Assert.IsFalse(info.IsValid);
        Assert.IsNotNull(info.Warnings);
        Assert.AreEqual(1, info.Warnings.Count);
        Assert.AreEqual("warning", info.Warnings.ElementAt(0));
    }
Example #4
0
    public void AddInfoToInvalid()
    {
        var info = ValidationInfo.CreateFailure("error");

        info.AddInfo("info");
        Assert.IsFalse(info.IsValid);
        Assert.IsNotNull(info.Infos);
        Assert.AreEqual(1, info.Infos.Count);
        Assert.AreEqual("info", info.Infos.ElementAt(0));
    }
Example #5
0
    public void AssimilateFailureAsSuccess()
    {
        var info  = ValidationInfo.CreateSuccess;
        var info2 = ValidationInfo.CreateFailure("error");

        info.Assimilate(info2);
        Assert.IsFalse(info.IsValid);
        Assert.AreEqual(1, info.Errors.Count);
        Assert.AreEqual("error", info.Errors.ElementAt(0));
    }
    public void JoinMultipleErrors()
    {
        string[] errors = new string[]
        {
            "error1",
            "error2"
        };

        ValidationInfo info = ValidationInfo.CreateFailure(errors);

        Assert.AreEqual("error1,error2", info.JoinErrors(","));
    }
Example #7
0
    public void StaticCreateErrors(int errorCount)
    {
        string[] errors = new string[errorCount];
        for (int i = 0; i < errors.Length; i++)
        {
            errors[i] = $"error{i + 1}";
        }

        var info = ValidationInfo.CreateFailure(errors);

        Assert.AreEqual(false, info.IsValid, "The constructor to create a info with a single error is wrongly valid.");
        Assert.IsNotNull(info.Errors, "The error list of the ValidationInfo is wrongly null.");
        Assert.AreEqual(errorCount, info.Errors.Count, $"The ValidationInfo created with a {errorCount} errors contains {info.Errors.Count} error(s).");
    }
    public void AddMultipleSuccessToInvalid()
    {
        var info = ValidationInfo.CreateFailure("error");

        string[] success = new string[]
        {
            "success1",
            "success2"
        };
        info.AddSuccess(success);
        Assert.IsFalse(info.IsValid);
        Assert.IsNotNull(info.Successes);
        Assert.AreEqual(2, info.Successes.Count);
        Assert.AreEqual("success1", info.Successes.ElementAt(0));
        Assert.AreEqual("success2", info.Successes.ElementAt(1));
    }
    public void AddMultipleWarningsToInvalid()
    {
        var info = ValidationInfo.CreateFailure("error");

        string[] warnings = new string[]
        {
            "warning1",
            "warning2"
        };
        info.AddWarnings(warnings);
        Assert.IsFalse(info.IsValid);
        Assert.IsNotNull(info.Warnings);
        Assert.AreEqual(2, info.Warnings.Count);
        Assert.AreEqual("warning1", info.Warnings.ElementAt(0));
        Assert.AreEqual("warning2", info.Warnings.ElementAt(1));
    }
Example #10
0
    public void AddMultipleInfoToInvalid()
    {
        var info = ValidationInfo.CreateFailure("error");

        string[] infos = new string[]
        {
            "info1",
            "info2"
        };
        info.AddInfo(infos);
        Assert.IsFalse(info.IsValid);
        Assert.IsNotNull(info.Infos);
        Assert.AreEqual(2, info.Infos.Count);
        Assert.AreEqual("info1", info.Infos.ElementAt(0));
        Assert.AreEqual("info2", info.Infos.ElementAt(1));
    }
    public void JoinSingleError(string error)
    {
        ValidationInfo info = ValidationInfo.CreateFailure(error);

        Assert.AreEqual(error, info.JoinErrors());
    }