2020-12-20 08:36:11 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
using NUnit.Framework;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Events;
|
2017-05-12 14:49:44 +02:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Scoping;
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class EventNameExtractorTests
|
2017-05-12 14:49:44 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
[Test]
|
|
|
|
|
public void Find_Event_Ing()
|
|
|
|
|
{
|
|
|
|
|
var 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()
|
|
|
|
|
{
|
|
|
|
|
var 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()
|
|
|
|
|
{
|
|
|
|
|
var 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()
|
2017-05-12 14:49:44 +02:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
var found = EventNameExtractor.FindEvent(this, new SaveEventArgs<double>(0), EventNameExtractor.MatchIngNames);
|
|
|
|
|
Assert.IsFalse(found.Success);
|
|
|
|
|
Assert.AreEqual(EventNameExtractorError.NoneFound, found.Result.Error);
|
2017-05-12 14:49:44 +02:00
|
|
|
}
|
2022-06-21 08:09:38 +02:00
|
|
|
|
|
|
|
|
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;
|
2017-07-20 11:21:28 +02:00
|
|
|
}
|