Skip to content

Commit d9d422e

Browse files
authored
Fix bug in DocumentEvents2 sink implementation of the ContentControlBeforeContentUpdate event (#454)
Fixes #453
2 parents d952fff + de31b5b commit d9d422e

5 files changed

Lines changed: 62 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v1.9.8
4+
5+
### Fixed
6+
* Fix bug in `ContentControlBeforeContentUpdate` code by verifying the correct event name [#454](https://github.com/NetOfficeFw/NetOffice/pull/454)
7+
8+
39
## v1.9.7
410

511
### Added

Source/NetOffice.Tests/NetOffice.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<ProjectReference Include="..\NetOffice\NetOffice.csproj" />
2929
<ProjectReference Include="..\Outlook\OutlookApi.csproj" />
3030
<ProjectReference Include="..\PowerPoint\PowerPointApi.csproj" />
31+
<ProjectReference Include="..\Word\WordApi.csproj" />
3132
</ItemGroup>
3233
<ItemGroup>
3334
<Content Include="NetOffice\Tools\data\NativeAddinResiliency.bin">
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
}

Source/NetOffice.Tests/packages.lock.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@
142142
"NetOfficeFw.Core": "[1.9.3, )",
143143
"NetOfficeFw.Office": "[1.9.3, )"
144144
}
145+
},
146+
"NetOfficeFw.Word": {
147+
"type": "Project",
148+
"dependencies": {
149+
"NetOfficeFw.Core": "[1.9.3, )",
150+
"NetOfficeFw.Office": "[1.9.3, )",
151+
"NetOfficeFw.VBIDE": "[1.9.3, )",
152+
"stdole": "[7.0.3300, )"
153+
}
145154
}
146155
}
147156
}

Source/Word/Events/DocumentEvents2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public void ContentControlBeforeStoreUpdate([In, MarshalAs(UnmanagedType.IDispat
279279

280280
public void ContentControlBeforeContentUpdate([In, MarshalAs(UnmanagedType.IDispatch)] object contentControl, [In] [Out] ref object content)
281281
{
282-
if (!Validate("ContentControlBeforeStoreUpdate"))
282+
if (!Validate("ContentControlBeforeContentUpdate"))
283283
{
284284
Invoker.ReleaseParamsArray(contentControl, content);
285285
return;

0 commit comments

Comments
 (0)