public async Task BasicTest() { await using var serving = await WebHost.Serve(); var publisher = WebServices.GetRequiredService <IPublisher>(); var replicator = ClientServices.GetRequiredService <IReplicator>(); using var scope = WebServices.CreateScope(); var sp = scope.ServiceProvider.GetRequiredService <ISimplestProvider>(); sp.SetValue(""); var p1 = await publisher.Publish(_ => sp.GetValue()); p1.Should().NotBeNull(); var r1 = replicator.GetOrAdd <string>(p1.Ref, true); var r1c = await r1.Computed.Update(); r1c.IsConsistent().Should().BeTrue(); r1c.Value.Should().Be(""); r1.Computed.Should().Be(r1c); sp.SetValue("1"); await Task.Delay(100); r1c.IsConsistent().Should().BeFalse(); r1.Computed.Should().Be(r1c); r1c = await r1c.Update(); r1c.Value.Should().Be("1"); var r1c1 = await r1c.Update(); r1c1.Should().Be(r1c); }
public async Task CommunicationTest() { await using var serving = await WebHost.Serve(); var publisher = WebServices.GetRequiredService <IPublisher>(); using var wss = WebServices.CreateScope(); var sp = wss.ServiceProvider.GetRequiredService <ISimplestProvider>(); var cp = CreateChannelPair("c1"); publisher.ChannelHub.Attach(cp.Channel1).Should().BeTrue(); var cReader = cp.Channel2.Reader; sp.SetValue(""); var p1 = await publisher.Publish(_ => sp.GetValue()); p1.Should().NotBeNull(); Debug.WriteLine("a1"); await publisher.Subscribe(cp.Channel1, p1, true); Debug.WriteLine("a2"); var m = await cReader.AssertRead(); m.Should().BeOfType <PublicationStateReply <string, string> >() .Which.Output !.Value.Value.Should().Be(""); Debug.WriteLine("a3"); await cReader.AssertCannotRead(); Debug.WriteLine("b1"); sp.SetValue("1"); Debug.WriteLine("b2"); m = await cReader.AssertRead(); Debug.WriteLine("b3"); m.Should().BeOfType <PublicationStateReply <string> >() .Which.IsConsistent.Should().BeFalse(); Debug.WriteLine("b4"); var pm = (PublicationReply)m; pm.PublisherId.Should().Be(publisher.Id); pm.PublicationId.Should().Be(p1.Id); Debug.WriteLine("b5"); await cReader.AssertCannotRead(); Debug.WriteLine("c1"); sp.SetValue("12"); // No auto-update after invalidation Debug.WriteLine("c2"); await cReader.AssertCannotRead(); Debug.WriteLine("d1"); await publisher.Subscribe(cp.Channel1, p1, true); Debug.WriteLine("d2"); m = await cReader.AssertRead(); Debug.WriteLine("d3"); m.Should().BeOfType <PublicationStateReply <string, string> >() .Which.IsConsistent.Should().BeTrue(); m.Should().BeOfType <PublicationStateReply <string, string> >() .Which.Output !.Value.Value.Should().Be("12"); Debug.WriteLine("d4"); await cReader.AssertCannotRead(); Debug.WriteLine("e1"); await p1.DisposeAsync(); Debug.WriteLine("e2"); await cReader.AssertCannotRead(); Debug.WriteLine("f1"); await publisher.Subscribe(cp.Channel1, p1, true); Debug.WriteLine("f2"); m = await cReader.AssertRead(); Debug.WriteLine("f3"); m.Should().BeOfType <PublicationAbsentsReply>(); }