public void CanAssociateWithSameRuntimeMultipleTimes()
        {
            var objRef    = new DotNetObjectRef(new object());
            var jsRuntime = new TestJsRuntime();

            objRef.EnsureAttachedToJsRuntime(jsRuntime);
            objRef.EnsureAttachedToJsRuntime(jsRuntime);
        }
        public void CannotAssociateWithDifferentRuntimes()
        {
            var objRef     = new DotNetObjectRef(new object());
            var jsRuntime1 = new TestJsRuntime();
            var jsRuntime2 = new TestJsRuntime();

            objRef.EnsureAttachedToJsRuntime(jsRuntime1);

            var ex = Assert.Throws <InvalidOperationException>(
                () => objRef.EnsureAttachedToJsRuntime(jsRuntime2));

            Assert.Contains("Do not attempt to re-use", ex.Message);
        }
        public void NotifiesAssociatedJsRuntimeOfDisposal()
        {
            // Arrange
            var objRef    = new DotNetObjectRef(new object());
            var jsRuntime = new TestJsRuntime();

            objRef.EnsureAttachedToJsRuntime(jsRuntime);

            // Act
            objRef.Dispose();

            // Assert
            Assert.Equal(new[] { objRef }, jsRuntime.UntrackedRefs);
        }