<commit_before>﻿using NUnit.Framework;
using Workbench.Core.Models;

namespace Workbench.Core.Tests.Unit.Models
{
    [TestFixture]
    public class ModelModelInvalidModelTests
    {
        [Test]
        public void ValidateWithAnInvalidModelReturnsFalse()
        {
            var sut = MakeModelWithMissingVariable();
            var actualValidationResult = sut.Validate();
            Assert.That(actualValidationResult, Is.False);
        }

        [Test]
        public void ValidateWithAModelMissingVariablePopulatesErrors()
        {
            var sut = MakeModelWithMissingVariable();
            var validationContext = new ModelValidationContext();
            sut.Validate(validationContext);
            Assert.That(validationContext.Errors, Is.Not.Empty);
        }

        [Test]
        public void ValidateWithAModelMissingVariableHasErrrosIsTrue()
        {
            var sut = MakeModelWithMissingVariable();
            var validationContext = new ModelValidationContext();
            sut.Validate(validationContext);
            Assert.That(validationContext.HasErrors, Is.True);
        }

        [Test]
        public void ValidateWithAModelMissingSharedDomainPopulatesErrors()
        {
            var sut = MakeModelWithMissingSharedDomain();
            var validationContext = new ModelValidationContext();
            sut.Validate();
            sut.Validate(validationContext);
            Assert.That(validationContext.Errors, Is.Not.Empty);
        }

        [Test]
        public void ValidateWithAModelMissingSharedDomainHasErrorsIsTrue()
        {
            var sut = MakeModelWithMissingSharedDomain();
            var validationContext = new ModelValidationContext();
            sut.Validate();
            sut.Validate(validationContext);
            Assert.That(validationContext.HasErrors, Is.True);
        }

        private static ModelModel MakeModelWithMissingVariable()
        {
            var workspace = WorkspaceModel.Create("An invalid model")
                                          .AddSingleton("x", "1..9")
                                          .AddSingleton("y", "1..9")
                                          .WithConstraintExpression("x > z")
                                          .Build();

            return workspace.Model;
        }

        private static ModelModel MakeModelWithMissingSharedDomain()
        {
            var workspace = WorkspaceModel.Create("A model missing shared domain")
                                          .WithSharedDomain("a", "1..10")
                                          .AddSingleton("x", "b")
                                          .AddSingleton("y", "1..9")
                                          .WithConstraintExpression("x > y")
                                          .Build();

            return workspace.Model;
        }
    }
}
<commit_msg>Removes duplicate calls to ModelModel.Validate method.<commit_after>﻿using NUnit.Framework;
using Workbench.Core.Models;

namespace Workbench.Core.Tests.Unit.Models
{
    [TestFixture]
    public class ModelModelInvalidModelTests
    {
        [Test]
        public void ValidateWithAnInvalidModelReturnsFalse()
        {
            var sut = MakeModelWithMissingVariable();
            var actualValidationResult = sut.Validate();
            Assert.That(actualValidationResult, Is.False);
        }

        [Test]
        public void ValidateWithAModelMissingVariablePopulatesErrors()
        {
            var sut = MakeModelWithMissingVariable();
            var validationContext = new ModelValidationContext();
            sut.Validate(validationContext);
            Assert.That(validationContext.Errors, Is.Not.Empty);
        }

        [Test]
        public void ValidateWithAModelMissingVariableHasErrrosIsTrue()
        {
            var sut = MakeModelWithMissingVariable();
            var validationContext = new ModelValidationContext();
            sut.Validate(validationContext);
            Assert.That(validationContext.HasErrors, Is.True);
        }

        [Test]
        public void ValidateWithAModelMissingSharedDomainPopulatesErrors()
        {
            var sut = MakeModelWithMissingSharedDomain();
            var validationContext = new ModelValidationContext();
            sut.Validate(validationContext);
            Assert.That(validationContext.Errors, Is.Not.Empty);
        }

        [Test]
        public void ValidateWithAModelMissingSharedDomainHasErrorsIsTrue()
        {
            var sut = MakeModelWithMissingSharedDomain();
            var validationContext = new ModelValidationContext();
            sut.Validate(validationContext);
            Assert.That(validationContext.HasErrors, Is.True);
        }

        private static ModelModel MakeModelWithMissingVariable()
        {
            var workspace = WorkspaceModel.Create("An invalid model")
                                          .AddSingleton("x", "1..9")
                                          .AddSingleton("y", "1..9")
                                          .WithConstraintExpression("x > z")
                                          .Build();

            return workspace.Model;
        }

        private static ModelModel MakeModelWithMissingSharedDomain()
        {
            var workspace = WorkspaceModel.Create("A model missing shared domain")
                                          .WithSharedDomain("a", "1..10")
                                          .AddSingleton("x", "b")
                                          .AddSingleton("y", "1..9")
                                          .WithConstraintExpression("x > y")
                                          .Build();

            return workspace.Model;
        }
    }
}

{'fraction_non_alphanumeric': 0.08067510548523207, 'fraction_numerical': 0.0030379746835443038, 'mean_word_length': 1.5088907705334462, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7060549', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1249, 'n_words': 243}