Skip to content

Commit 58e4622

Browse files
committed
Test - Improve reliability of JavaScriptObjectRepositoryFacts.CanRegisterJavascriptObjectBindWhenNamespaceIsNull
- JavascriptObjectRepository generates object ids using a static counter, we need to get the object Id for this test to be reliable, using an Object Id of 1 will fail if the test order isn't in a very specific order
1 parent 138cbca commit 58e4622

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

CefSharp.Test/JavascriptBinding/JavaScriptObjectRepositoryFacts.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
44

55
using CefSharp.Internals;
6+
using System.Collections.Generic;
67
using Xunit;
78

89
internal class NoNamespaceClass
@@ -29,7 +30,7 @@ public class JavaScriptObjectRepositoryFacts
2930
[Fact]
3031
public void CanRegisterJavascriptObjectBindWhenNamespaceIsNull()
3132
{
32-
var javascriptObjectRepository = new JavascriptObjectRepository();
33+
IJavascriptObjectRepositoryInternal javascriptObjectRepository = new JavascriptObjectRepository();
3334
var name = nameof(NoNamespaceClass);
3435
#if NETCOREAPP
3536
javascriptObjectRepository.Register(name, new NoNamespaceClass(), new BindingOptions());
@@ -38,7 +39,10 @@ public void CanRegisterJavascriptObjectBindWhenNamespaceIsNull()
3839
#endif
3940
Assert.True(javascriptObjectRepository.IsBound(name));
4041

41-
var result = ((IJavascriptObjectRepositoryInternal)javascriptObjectRepository).TryCallMethod(1, "getExampleString", new object[0]);
42+
var boundObjects = javascriptObjectRepository.GetObjects(new List<string> { name });
43+
Assert.Equal(1, boundObjects.Count);
44+
45+
var result = javascriptObjectRepository.TryCallMethod(boundObjects[0].Id, "getExampleString", new object[0]);
4246
Assert.True(result.Success);
4347
Assert.Equal("ok", result.ReturnValue.ToString());
4448
}

0 commit comments

Comments
 (0)