Exemplo n.º 1
0
        public async Task SuppressTest()
        {
            var time   = Services.GetRequiredService <ITimeService>();
            var count1 = 0;
            var count2 = 0;

#pragma warning disable 1998
            var s1 = await StateFactory.NewComputed <int>(async (s, ct) => count1++).UpdateAsync(false);

            var s2 = await StateFactory.NewComputed <int>(async (s, ct) => count2++).UpdateAsync(false);

#pragma warning restore 1998
            var s12 = await StateFactory.NewComputed <(int, int)>(
                async (s, cancellationToken) => {
                var a       = await s1.UseAsync(cancellationToken);
                using var _ = Computed.IgnoreDependencies();
                var b       = await s2.UseAsync(cancellationToken);
                return(a, b);
            }).UpdateAsync(false);

            var v12a = await s12.UseAsync();

            s1.Computed.Invalidate(); // Should increment c1 & impact c12
            var v12b = await s12.UseAsync();

            v12b.Should().Be((v12a.Item1 + 1, v12a.Item2));
            s2.Computed.Invalidate(); // Should increment c2, but shouldn't impact c12
            var v12c = await s12.UseAsync();

            v12c.Should().Be(v12b);
        }