|
| 1 | +// Copyright 2024 Cisco Systems, Inc. |
| 2 | +// Licensed under MIT-style license (see LICENSE.txt file). |
| 3 | + |
| 4 | +using System; |
| 5 | +using NetOffice.WordApi; |
| 6 | +using NetOffice.WordApi.Events; |
| 7 | +using NetOffice.Tests.Helpers; |
| 8 | +using NUnit.Framework; |
| 9 | + |
| 10 | +namespace NetOffice.Tests.WordApi.Events |
| 11 | +{ |
| 12 | + [TestFixture] |
| 13 | + public class DocumentEvents2_SinkHelperTests |
| 14 | + { |
| 15 | + /// <summary> |
| 16 | + /// Regression test for #453 - Ensures ContentControlBeforeContentUpdate event uses correct event name |
| 17 | + /// in both Validate() and EventBinding.RaiseCustomEvent() calls |
| 18 | + /// </summary> |
| 19 | + [Test] |
| 20 | + public void ContentControlBeforeContentUpdate_EventRaised_CallsHandlerWithCorrectEventName() |
| 21 | + { |
| 22 | + // Arrange |
| 23 | + var eventBinder = new TestableComObjectStub(); |
| 24 | + eventBinder.AddEventRecipient(nameof(DocumentEvents2_SinkHelper.ContentControlBeforeContentUpdate)); |
| 25 | + var connectionPoint = new ConnectionPointStub(); |
| 26 | + |
| 27 | + var events = new DocumentEvents2_SinkHelper(eventBinder, connectionPoint); |
| 28 | + var parameter1 = new FakeComObject(); |
| 29 | + var content = new object(); |
| 30 | + |
| 31 | + // Act |
| 32 | + events.ContentControlBeforeContentUpdate(parameter1, ref content); |
| 33 | + var actualParametersPassToEvent = eventBinder.LastRaisedEventParameters; |
| 34 | + |
| 35 | + // Assert |
| 36 | + Assert.AreEqual("ContentControlBeforeContentUpdate", eventBinder.LastRaisedEventName, |
| 37 | + "EventBinding.RaiseCustomEvent must be called with 'ContentControlBeforeContentUpdate' event name"); |
| 38 | + |
| 39 | + CollectionAssert.IsNotEmpty(actualParametersPassToEvent); |
| 40 | + var actualParameter1 = actualParametersPassToEvent[0]; |
| 41 | + Assert.IsInstanceOf<ContentControl>(actualParameter1, |
| 42 | + "Event ContentControlBeforeContentUpdate parameter must be of type ContentControl."); |
| 43 | + } |
| 44 | + } |
| 45 | +} |
0 commit comments