public void Connectivity_Should_Connect_Disconnect_And_Connect()
        {
            // Given
            NetworkAccess             access        = NetworkAccess.None;
            var                       testScheduler = new TestScheduler();
            MockConnectivityEssential connectivity  =
                new MockConnectivityEssentialFixture()
                .WithScheduler(testScheduler)
                .WithAccesses(NetworkAccesses);

            connectivity
            .ConnectivityChanged
            .Subscribe(_ =>
            {
                access = _.NetworkAccess;
            });

            // When
            testScheduler.AdvanceToMs(TimeSpan.FromSeconds(2.5).TotalMilliseconds);

            // Then
            access.Should().Be(NetworkAccess.Internet);

            // When
            testScheduler.AdvanceToMs(TimeSpan.FromSeconds(4.5).TotalMilliseconds);

            // Then
            access.Should().Be(NetworkAccess.Unknown);

            // When
            testScheduler.AdvanceToMs(TimeSpan.FromSeconds(6.5).TotalMilliseconds);

            // Then
            access.Should().Be(NetworkAccess.Internet);
        }
Exemplo n.º 2
0
            public void Compass_Should_Change_Heading()
            {
                // Given
                var                  testScheduler = new TestScheduler();
                CompassData          reading       = new CompassData();
                MockCompassEssential compass       = new MockCompassEssentialFixture().WithScheduler(testScheduler);

                compass
                .CompassChanged
                .Subscribe(_ =>
                {
                    reading = _.Reading;
                });

                // When
                testScheduler.AdvanceToMs(TimeSpan.FromSeconds(1).TotalMilliseconds);

                // Then
                reading.HeadingMagneticNorth.Should().Be(0);

                // When
                testScheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks);

                // Then
                reading.HeadingMagneticNorth.Should().Be(10);

                // When
                testScheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks);

                // Then
                reading.HeadingMagneticNorth.Should().Be(20);
            }
Exemplo n.º 3
0
        public void CreateCollectionWithTimer()
        {
            var input = new[] { "Foo", "Bar", "Baz", "Bamf" };
            var sched = new TestScheduler();

            using (TestUtils.WithScheduler(sched)) {
                ReactiveCollection <string> fixture;

                fixture = input.ToObservable(sched).CreateCollection(TimeSpan.FromSeconds(0.5));
                sched.AdvanceToMs(1005);
                fixture.AssertAreEqual(input.Take(2));

                sched.AdvanceToMs(1505);
                fixture.AssertAreEqual(input.Take(3));

                sched.AdvanceToMs(10000);
                fixture.AssertAreEqual(input);
            }
        }
Exemplo n.º 4
0
        public void MultipleSubscribesShouldntResultInMultipleNotifications()
        {
            var input   = new[] { 1, 2, 1, 2 };
            var sched   = new TestScheduler();
            var fixture = createCommand(null, sched);

            var odd_list  = new List <int>();
            var even_list = new List <int>();

            fixture.Where(x => ((int)x) % 2 != 0).Subscribe(x => odd_list.Add((int)x));
            fixture.Where(x => ((int)x) % 2 == 0).Subscribe(x => even_list.Add((int)x));

            input.Run(x => fixture.Execute(x));
            sched.AdvanceToMs(1000);

            new[] { 1, 1 }.AssertAreEqual(odd_list);
            new[] { 2, 2 }.AssertAreEqual(even_list);
        }
        public void Connectivity_Should_Change()
        {
            // Given
            NetworkAccess access        = NetworkAccess.None;
            var           testScheduler = new TestScheduler();
            var           connectivity  = new MockConnectivityEssential(testScheduler);

            connectivity
            .ConnectivityChanged
            .Subscribe(_ =>
            {
                access = _.NetworkAccess;
            });

            // When
            testScheduler.AdvanceToMs(TimeSpan.FromSeconds(2.5).TotalMilliseconds);

            // Then
            access.Should().Be(NetworkAccess.Internet);
        }
Exemplo n.º 6
0
        public static async Task MainAsync()
        {
            var sched = new TestScheduler();
            var test  = sched.CreateColdObservable(
                sched.OnNextAt(200, 1),
                sched.OnNextAt(400, 1),
                sched.OnNextAt(600, 2),
                sched.OnNextAt(800, 3),
                sched.OnNextAt(1000, 1),
                sched.OnNextAt(1200, 1),
                sched.OnNextAt(1400, 4),
                sched.OnNextAt(1600, 1),
                sched.OnNextAt(1800, 4),
                sched.OnNextAt(2000, 2),
                sched.OnNextAt(2200, 1),
                sched.OnNextAt(2400, 3),
                sched.OnNextAt(2600, 1),
                sched.OnNextAt(3000, 1),
                sched.OnNextAt(6000, 4)
                );

            test
            .Dump(G.Writer)
            .Trigger(i => i == 1, o => o.Where(i => i > 1 && i < 4), () => TimeSpan.FromSeconds(2), sched)
            .Subscribe(
                _ =>
            {
                G.Writer.WriteLine("launched");
            });
            var count = 0;

            do
            {
                count += 100;
                sched.AdvanceToMs(count);
                Console.WriteLine("Time " + count);
            }while (string.IsNullOrWhiteSpace(Console.ReadLine()));
        }
    public async Task CachingTest()
    {
        var testScheduler = new TestScheduler();
        var cache         = new InMemoryBlobCache(testScheduler);
        var cacheTimeout  = TimeSpan.FromSeconds(10);
        var someApi       = new Mock <ISomeApi>();

        someApi.Setup(s => s.GetSomeStrings())
        .Returns(Task.FromResult("helloworld")).Verifiable();

        var apiWrapper = new SomeApiWrapper(someApi.Object, cache, cacheTimeout);
        var string1    = await apiWrapper.GetSomeStrings();

        someApi.Verify(s => s.GetSomeStrings(), Times.Once());
        StringAssert.AreEqualIgnoringCase("helloworld", string1);
        testScheduler.AdvanceToMs(5000);

        var observer = testScheduler.CreateObserver <string>();

        apiWrapper.GetSomeStrings().Subscribe(observer);
        testScheduler.AdvanceByMs(cacheTimeout.TotalMilliseconds);
        someApi.Verify(s => s.GetSomeStrings(), Times.Once());
        StringAssert.AreEqualIgnoringCase("helloworld", observer.Messages[0].Value.Value);
    }
        public void MultipleSubscribesShouldntResultInMultipleNotifications()
        {
            var input = new[] { 1, 2, 1, 2 };
            var sched = new TestScheduler();
            var fixture = createCommand(null, sched);

            var odd_list = new List<int>();
            var even_list = new List<int>();
            fixture.Where(x => ((int)x) % 2 != 0).Subscribe(x => odd_list.Add((int)x));
            fixture.Where(x => ((int)x) % 2 == 0).Subscribe(x => even_list.Add((int)x));

            input.Run(x => fixture.Execute(x));
            sched.AdvanceToMs(1000);

            new[]{1,1}.AssertAreEqual(odd_list);
            new[]{2,2}.AssertAreEqual(even_list);
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            var sched     = new TestScheduler();
            var newConnOb = sched.CreateHotObservable(
                sched.OnNextAt(100, "1"),
                sched.OnNextAt(200, "2"),
                sched.OnNextAt(600, "3")
                );

            var remConnOb = sched.CreateHotObservable(
                sched.OnNextAt(500, "2"),
                sched.OnNextAt(900, "1"),
                sched.OnNextAt(1000, "3")
                );

            var packageSimulator = sched.CreateHotObservable(
                sched.OnNextAt(101, Tuple.Create("1", "p1")),
                sched.OnNextAt(120, Tuple.Create("1", "p2")),
                sched.OnNextAt(250, Tuple.Create("2", "p1")),
                sched.OnNextAt(450, Tuple.Create("2", "p2")),
                sched.OnNextAt(700, Tuple.Create("3", "p3")),
                sched.OnNextAt(950, Tuple.Create("1", "p1"))
                );


            var ob = Observable.Interval(TimeSpan.FromMilliseconds(50), sched).Publish().RefCount();

            packageSimulator
            .Window(newConnOb, s => remConnOb.Where(c => c == s))
            .Subscribe(window =>
            {
                string connection = null;
                var windowPublish = window.Publish();

                windowPublish.FirstOrDefaultAsync().Subscribe(p =>
                {
                    if (p == null)
                    {
                        connection = p.Item1;
                    }
                    Console.WriteLine("Created {1} at {0}", sched.Now.Millisecond, connection);
                });

                windowPublish.Where(p => p.Item1 == connection).Subscribe(_ =>
                {
                    Console.WriteLine("New item in {2} [{0}] at {1}", _, sched.Now.Millisecond, connection);
                }, () =>
                {
                    Console.WriteLine("Completed {1} at {0}", sched.Now.Millisecond, connection);
                });
                windowPublish.Connect();
            });

            sched.AdvanceToMs(1001);
            Console.ReadLine();



//			G.Writer = ConsoleWriter.Default;
//            Application.MainAsync().Wait();
//			Console.ReadLine();
        }