Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Scoping/EventNameExtractorTests.cs
Paul Johnson 00133e880d Move test projects from src/ to tests/ (#11357)
* Update gitignore

* Move csproj

* Update project references

* Update solutions

* Update build scripts

* Tests used to share editorconfig with projects in src

* Fix broken tests.

* Stop copying around .editorconfig

merged root one with linting

* csharp_style_expression_bodied -> suggestion

* Move StyleCop rulesets to matching directories and update shared build properties

* Remove legacy build files, update NuGet.cofig and solution files

* Restore myget source

* Clean up .gitignore

* Update .gitignore

* Move new test classes to tests after merge

* Gitignore + nuget config

* Move new test

Co-authored-by: Ronald Barendse <ronald@barend.se>
2021-10-18 08:14:04 +01:00

60 lines
2.1 KiB
C#

// Copyright (c) Umbraco.
// See LICENSE for more details.
using System;
using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Scoping
{
[TestFixture]
public class EventNameExtractorTests
{
[Test]
public void Find_Event_Ing()
{
Attempt<EventNameExtractorResult> found = EventNameExtractor.FindEvent(this, new SaveEventArgs<string>("test"), EventNameExtractor.MatchIngNames);
Assert.IsTrue(found.Success);
Assert.AreEqual("FoundMe", found.Result.Name);
}
[Test]
public void Find_Event_Non_Ing()
{
Attempt<EventNameExtractorResult> found = EventNameExtractor.FindEvent(this, new SaveEventArgs<string>("test"), EventNameExtractor.MatchNonIngNames);
Assert.IsTrue(found.Success);
Assert.AreEqual("FindingMe", found.Result.Name);
}
[Test]
public void Ambiguous_Match()
{
Attempt<EventNameExtractorResult> found = EventNameExtractor.FindEvent(this, new SaveEventArgs<int>(0), EventNameExtractor.MatchIngNames);
Assert.IsFalse(found.Success);
Assert.AreEqual(EventNameExtractorError.Ambiguous, found.Result.Error);
}
[Test]
public void No_Match()
{
Attempt<EventNameExtractorResult> found = EventNameExtractor.FindEvent(this, new SaveEventArgs<double>(0), EventNameExtractor.MatchIngNames);
Assert.IsFalse(found.Success);
Assert.AreEqual(EventNameExtractorError.NoneFound, found.Result.Error);
}
public static event EventHandler<SaveEventArgs<string>> FindingMe;
public static event EventHandler<SaveEventArgs<string>> FoundMe;
// will lead to ambiguous matches
public static event EventHandler<SaveEventArgs<int>> SavingThis;
public static event EventHandler<SaveEventArgs<int>> SavedThis;
public static event EventHandler<SaveEventArgs<int>> SavingThat;
public static event EventHandler<SaveEventArgs<int>> SavedThat;
}
}