Exemple #1
0
        public void Warning_WhiteSpaceMessage()
        {
            // Act

            var exception = Record.Exception(
                () => ValidationIssue.Warning(" \t")
                );

            // Assert

            Assert.IsType <ArgumentException>(exception);
        }
Exemple #2
0
        public void Warning_NullMessage()
        {
            // Act

            var exception = Record.Exception(
                () => ValidationIssue.Warning(null)
                );

            // Assert

            Assert.IsType <ArgumentNullException>(exception);
        }
Exemple #3
0
 public TExecutionResult AddWarning(
     String message,
     String code = default(String),
     ISet <String> memberNames = default(ImmutableHashSet <String>))
 {
     return(this.AddValidationIssue(
                ValidationIssue.Warning(
                    message: message,
                    code: code,
                    memberNames: memberNames
                    )
                ));
 }
Exemple #4
0
        public void SetCode_AllStringsAreValid(string newCode)
        {
            // Arrange

            var initial = ValidationIssue.Warning("Bar", "Code?");

            // Act

            var updated = initial.SetCode(newCode);

            // Assert

            Assert.Equal(newCode, updated.Code);
        }
Exemple #5
0
        public void IsSuccessful_TrueWithWarnings_NonGeneric()
        {
            // Arrange

            const string message          = "WarnFoo";
            var          validationIssues = ImmutableHashSet.Create(ValidationIssue.Warning(message));

            // Act

            var result = new OperationResult(validationIssues);

            // Assert

            Assert.True(result.IsSuccessful);
            Assert.NotEmpty(result.ValidationIssues);
        }
Exemple #6
0
        public void Warning_WithJustMemberNames()
        {
            // Arrange

            var message     = "FooBar";
            var memberNames = ImmutableHashSet.Create("foo", "bar");

            // Act

            var warning = ValidationIssue.Warning(message, memberNames);

            // Assert

            Assert.Equal(message, warning.Message);
            Assert.Equal(ValidationIssueLevel.Warning, warning.Level);
            Assert.Null(warning.Code);
            Assert.Equal(memberNames, warning.MemberNames);
        }
Exemple #7
0
        public void Warning_WithJustCode()
        {
            // Arrange

            var message = "FooBar";
            var code    = "some-code";

            // Act

            var warning = ValidationIssue.Warning(message, code);

            // Assert

            Assert.Equal(message, warning.Message);
            Assert.Equal(ValidationIssueLevel.Warning, warning.Level);
            Assert.Equal(code, warning.Code);
            Assert.Null(warning.MemberNames);
        }
Exemple #8
0
        public void AddWarning_VaryingSets_Generic(
            int initialNumberOfValidationIssues)
        {
            // Arrange

            var initialValidationIssues =
                this.GenerateValidationIssues(initialNumberOfValidationIssues)
                .ToImmutableHashSet();

            var message = "FooBar";
            var initial = new OperationResult <Object>(initialValidationIssues);

            // Act

            var updated = initial.AddWarning(message);

            // Assert

            var issue = ValidationIssue.Warning(message);

            Assert.Contains(issue, updated.ValidationIssues);
            Assert.DoesNotContain(issue, initial.ValidationIssues);
        }
Exemple #9
0
        public void ExceptionMessage_MultipleIssues_Message()
        {
            // Arrange

            var message        = "Foo is beyond all reason.";
            var warningMessage = "What is Kung Fu Fighting?";
            var names          = ImmutableHashSet.Create("Foo", "Bar");
            var issues         = ImmutableHashSet.Create(
                ValidationIssue.Error(message, memberNames: names),
                ValidationIssue.Warning(warningMessage)
                );

            // Act

            var exception = new OperationResultException(issues);

            // Assert

            var memberNames = String.Join(", ", names);

            Assert.Contains($"Member(s): {memberNames}\nError Message: {message}", exception.Message);
            Assert.Contains($"Warning Message: {warningMessage}", exception.Message);
        }
Exemple #10
0
        public void Warning_Valid()
        {
            // Arrange

            var message = "FooBar";
            var code    = "some-code";
            var names   = ImmutableHashSet.Create("Foo", "Bar");

            // Act

            var warning = ValidationIssue.Warning(
                message,
                code,
                names
                );

            // Assert

            Assert.Equal(message, warning.Message);
            Assert.Equal(ValidationIssueLevel.Warning, warning.Level);
            Assert.Equal(code, warning.Code);
            Assert.Equal(names, warning.MemberNames);
        }
Exemple #11
0
        public void AddWarning_VaryingSetsWithMembers_NonGeneric(
            int initialNumberOfValidationIssues)
        {
            // Arrange

            var initialValidationIssues =
                this.GenerateValidationIssues(initialNumberOfValidationIssues)
                .ToImmutableHashSet();

            var message     = "FooBar";
            var memberNames = ImmutableHashSet.Create("Foo", "Bar");
            var initial     = new OperationResult(initialValidationIssues);

            // Act

            var updated = initial.AddWarning(message, memberNames: memberNames);

            // Assert

            var issue = ValidationIssue.Warning(message, memberNames: memberNames);

            Assert.Contains(issue, updated.ValidationIssues);
            Assert.DoesNotContain(issue, initial.ValidationIssues);
        }