private void AddInvocation(JsRuntimeInvocation invocation)
 {
     if (!_invocations.ContainsKey(invocation.Identifier))
     {
         _invocations.Add(invocation.Identifier, new List <JsRuntimeInvocation>());
     }
     _invocations[invocation.Identifier].Add(invocation);
 }
            public ValueTask <TValue> InvokeAsync <TValue>(string identifier, CancellationToken cancellationToken, object[] args)
            {
                var invocation = new JsRuntimeInvocation(identifier, cancellationToken, args);

                _handlers.AddInvocation(invocation);

                return(TryHandlePlannedInvocation <TValue>(identifier, invocation)
                       ?? new ValueTask <TValue>(default(TValue) !));
            }
 public void Test002(JsRuntimeInvocation left, JsRuntimeInvocation right, bool expectedResult)
 {
     left.Equals(right).ShouldBe(expectedResult);
     right.Equals(left).ShouldBe(expectedResult);
     (left == right).ShouldBe(expectedResult);
     (left != right).ShouldNotBe(expectedResult);
     left.Equals((object)right).ShouldBe(expectedResult);
     right.Equals((object)left).ShouldBe(expectedResult);
 }
        public static IEnumerable <object[]> GetEqualsTestData()
        {
            var token = new CancellationToken(true);
            var args  = new object[] { 1, "baz" };

            var i1 = new JsRuntimeInvocation("foo", token, args);
            var i2 = new JsRuntimeInvocation("foo", token, args);
            var i3 = new JsRuntimeInvocation("bar", token, args);
            var i4 = new JsRuntimeInvocation("foo", CancellationToken.None, args);
            var i5 = new JsRuntimeInvocation("foo", token, Array.Empty <object>());
            var i6 = new JsRuntimeInvocation("foo", token, new object[] { 2, "woop" });

            yield return(new object[] { i1, i1, true });

            yield return(new object[] { i1, i2, true });

            yield return(new object[] { i1, i3, false });

            yield return(new object[] { i1, i4, false });

            yield return(new object[] { i1, i5, false });

            yield return(new object[] { i1, i6, false });
        }
            private ValueTask <TValue>?TryHandlePlannedInvocation <TValue>(string identifier, JsRuntimeInvocation invocation)
            {
                ValueTask <TValue>?result = default;

                if (_handlers._plannedInvocations.TryGetValue(identifier, out var plannedInvocations))
                {
                    var planned = plannedInvocations.OfType <JsRuntimePlannedInvocationBase <TValue> >()
                                  .SingleOrDefault(x => x.Matches(invocation));

                    if (planned is { })
 public void Test004(JsRuntimeInvocation left, JsRuntimeInvocation right, bool expectedResult)
 {
     left.GetHashCode().Equals(right.GetHashCode()).ShouldBe(expectedResult);
 }
Exemple #7
0
 /// <summary>
 /// Creates a new instance of the <see cref="UnplannedJsInvocationException"/>
 /// with the provided <see cref="Invocation"/> attached.
 /// </summary>
 /// <param name="invocation">The unplanned invocation.</param>
 public UnplannedJsInvocationException(JsRuntimeInvocation invocation)
     : base($"The invocation of '{invocation.Identifier}' {PrintArguments(invocation.Arguments)} was not expected.")
 {
     Invocation = invocation;
 }