Files
cefsharp/CefSharp.Test/JavascriptBinding/JavaScriptObjectRepositoryFacts.cs
T
pedoc 893d03221f Javascript Binding - Allow binding to classes in the global namespace (#3467)
* fix IsComplexType NullReferenceException

Sometimes, the registered Javascript object does not have a namespace, at this time this function will throw a ```NullReferenceException```.

* add unit test for IsComplexType

* Simplify and remove useless code

* Update CefSharp/Internals/JavascriptObjectRepository.cs

Co-authored-by: campersau <buchholz.bastian@googlemail.com>

Co-authored-by: Alex Maitland <amaitland@users.noreply.github.com>
Co-authored-by: campersau <buchholz.bastian@googlemail.com>
2021-04-05 10:29:42 +10:00

39 lines
1.0 KiB
C#

using CefSharp.Internals;
using Xunit;
internal class NoNamespaceClass
{
public SomeElseClass SomeElseClass { get; set; }
public int Year { get; set; }
public string GetExampleString()
{
return "ok";
}
}
internal class SomeElseClass
{
}
namespace CefSharp.Test.JavascriptBinding
{
public class JavaScriptObjectRepositoryFacts
{
[Fact]
public void CanRegisterJavascriptObjectBindWhenNamespaceIsNull()
{
var javascriptObjectRepository = new JavascriptObjectRepository();
var name = nameof(NoNamespaceClass);
javascriptObjectRepository.Register(name, new NoNamespaceClass(), false, new BindingOptions() { });
Assert.True(javascriptObjectRepository.IsBound(name));
var result = ((IJavascriptObjectRepositoryInternal)javascriptObjectRepository).TryCallMethod(1, "getExampleString", new object[0]);
Assert.True(result.Success);
Assert.Equal("ok", result.ReturnValue.ToString());
}
}
}