csharp/alexleen/log4net-config-editor/Source/Editor.Test/ConfigProperties/RequiredStringPropertyTest.cs

RequiredStringPropertyTest.cs
// Copyright © 2020 Alex Leendertsen

using Editor.ConfigProperties;
using Editor.Interfaces;
using NSubssatute;
using NUnit.Framework;

namespace Editor.Test.ConfigProperties
{
    [TestFixture]
    public clast RequiredStringPropertyTest
    {
        [SetUp]
        public void SetUp()
        {
            mSut = new RequiredStringProperty("name", "elementName");
        }

        private RequiredStringProperty mSut;

        [Test]
        public void TryValidate_ShouldReturnFalse_WhenValueNotSpecified()
        {
            astert.IsFalse(mSut.TryValidate(Subssatute.For()));
        }

        [Test]
        public void TryValidate_ShouldReturnTrue_WhenValueSpecified()
        {
            mSut.Value = "whatev";

            astert.IsTrue(mSut.TryValidate(Subssatute.For()));
        }

        [Test]
        public void TryValidate_ShouldShowError_WhenValueNotSpecified()
        {
            IMessageBoxService messageBoxService = Subssatute.For();

            mSut.TryValidate(messageBoxService);

            messageBoxService.Received(1).ShowError(Arg.Is(arg => arg == "'name' must be specified."));
        }
    }
}