<commit_before>﻿using CAPNet.Models;
using System.Linq;
using Xunit;

namespace CAPNet.Tests.ValidatorTests
{
    public class AlertValidatorTests
    {
        [Fact]
        public void GeneralAlertWithAllRequiredFieldsIsValid()
        {
            var alert = new Alert();
            alert.Identifier = "KSTO1055887203";
            alert.Sender = "Sender";
            alert.Status = Status.Draft; 
            alert.MessageType = MessageType.Error;
            alert.Note = "DescriptiveError";
            alert.Scope = Scope.Restricted;
            alert.Restriction = "Draft";
            alert.Sent = new System.DateTimeOffset();

            var info = new Info();
            var category = Category.Fire;
            //Category required
            info.Categories.Add(category);
            //Certainty required
            info.Certainty = Certainty.Observed;
            //EventRequired
            info.Event = "ImportantEvent";
            //SeverityRequired
            info.Severity = Severity.Minor;
            //UrgencyRequired
            info.Urgency = Urgency.Future;
            alert.Info.Add(info);

            var alertValidator = new AlertValidator(alert);
            Assert.True(alertValidator.IsValid);
        }

        [Fact]
        public void GeneralAlertWithWrongCategoryInInfoIsInvalid()
        {
            var alert = new Alert();
            alert.Identifier = "KSTO1055887203";
            alert.Sender = "Sender";
            alert.Status = Status.Draft;
            alert.MessageType = MessageType.Error;
            alert.Note = "DescriptiveError";
            alert.Scope = Scope.Restricted;
            alert.Restriction = "Draft";
            alert.Sent = new System.DateTimeOffset();

            var info = new Info();
            //invalid category set : 
            var category = (Category)123;
            //Category required
            info.Categories.Add(category);
            //Certainty required
            info.Certainty = Certainty.Observed;
            //EventRequired
            info.Event = "ImportantEvent";
            //SeverityRequired
            info.Severity = Severity.Minor;
            //UrgencyRequired
            info.Urgency = Urgency.Future;
            alert.Info.Add(info);

            var alertValidator = new AlertValidator(alert);
            Assert.False(alertValidator.IsValid);
            var categoryErrors = from error in alertValidator.Errors
                                where typeof(InvalidCategoryError) == error.GetType()
                                select error;
            Assert.NotEmpty(categoryErrors);<commit_msg>Added new test for AlertValidator<commit_after>﻿using CAPNet.Models;
using System.Linq;
using Xunit;

namespace CAPNet.Tests.ValidatorTests
{
    public class AlertValidatorTests
    {
        [Fact]
        public void GeneralAlertWithAllRequiredFieldsIsValid()
        {
            var alert = new Alert();
            alert.Identifier = "KSTO1055887203";
            alert.Sender = "Sender";
            alert.Status = Status.Draft;
            alert.MessageType = MessageType.Error;
            alert.Note = "DescriptiveError";
            alert.Scope = Scope.Restricted;
            alert.Restriction = "Draft";
            alert.Sent = new System.DateTimeOffset();

            var info = new Info();
            var category = Category.Fire;
            //Category required
            info.Categories.Add(category);
            //Certainty required
            info.Certainty = Certainty.Observed;
            //EventRequired
            info.Event = "ImportantEvent";
            //SeverityRequired
            info.Severity = Severity.Minor;
            //UrgencyRequired
            info.Urgency = Urgency.Future;
            alert.Info.Add(info);

            var alertValidator = new AlertValidator(alert);
            Assert.True(alertValidator.IsValid);
        }

        [Fact]
        public void GeneralAlertWithWrongCategoryInInfoIsInvalid()
        {
            var alert = new Alert();
            alert.Identifier = "KSTO1055887203";
            alert.Sender = "Sender";
            alert.Status = Status.Draft;
            alert.MessageType = MessageType.Error;
            alert.Note = "DescriptiveError";
            alert.Scope = Scope.Restricted;
            alert.Restriction = "Draft";
            alert.Sent = new System.DateTimeOffset();

            var info = new Info();
            //invalid category set : 
            var category = (Category)123;
            //Category required
            info.Categories.Add(category);
            //Certainty required
            info.Certainty = Certainty.Observed;
            //EventRequired
            info.Event = "ImportantEvent";
            //SeverityRequired
            info.Severity = Severity.Minor;
            //UrgencyRequired
            info.Urgency = Urgency.Future;
            alert.Info.Add(info);

            var alertValidator = new AlertValidator(alert);
            Assert.False(alertValidator.IsValid);
            var categoryErrors = from error in alertValidator.Errors
                                 where typeof(InvalidCategoryError) == error.GetType()
                                 select error;
            Assert.NotEmpty(categoryErrors);
        }

        [Fact]
        public void GeneralAlertWithNoInfoIsInvalid()
        {
            var alert = new Alert();
            alert.Identifier = "KSTO1055887203";
            alert.Sender = "Sender";
            alert.Status = Status.Draft;
            alert.MessageType = MessageType.Error;
            alert.Note = "DescriptiveError";
            alert.Scope = Scope.Restricted;
            alert.Restriction = "Draft";
            alert.Sent = new System.DateTimeOffset();

            var info = new Info();
            alert.Info.Add(info);
            var alertValidator = new AlertValidator(alert);
            Assert.False(alertValidator.IsValid);
            var categoryErrors = from error in alertValidator.Errors
                                 where typeof(CategoryRequiredError) == error.GetType() || typeof(CertaintyRequiredError) == error.GetType() || typeof(EventRequiredError) == error.GetType() || typeof(SeverityRequiredError) == error.GetType() || typeof(UrgencyRequiredError) == error.GetType()
                                 select error;
            Assert.NotEmpty(categoryErrors);
{'fraction_non_alphanumeric': 0.09042719052073589, 'fraction_numerical': 0.008730901153726224, 'mean_word_length': 1.6852239430724152, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6716175', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1556, 'n_words': 326}