Example #1
0
        public void ObservableCanExecuteShouldShowUpInCommand()
        {
            var input = new[] {true, false, false, true, false, true};
            var result = (new TestScheduler()).With(sched => {
                var can_execute = new Subject<bool>();
                var fixture = createCommand(can_execute, sched);
                var changes_as_observable = fixture.CanExecuteObservable.CreateCollection();

                int change_event_count = 0;
                fixture.CanExecuteChanged += (o, e) => { change_event_count++; };
                input.Run(x => {
                    can_execute.OnNext(x);
                    sched.Start();
                    Assert.Equal(x, fixture.CanExecute(null));
                });

                // N.B. We check against '5' instead of 6 because we're supposed to 
                // suppress changes that aren't actually changes i.e. false => false
                sched.AdvanceToMs(10*1000);
                return changes_as_observable;
            });

            // NB: Skip(1) is because CanExecuteObservable should have
            // BehaviorSubject Nature(tm)
            input.DistinctUntilChanged().AssertAreEqual(result.Skip(1).ToList());
        }
Example #2
0
        static void Main()
        {
$if$ ($sharpdx_platform_winrt_xaml$ == true)            global::Windows.UI.Xaml.Application.Start((p) => new App());
$else$            using (var program = new $safeclassname$())
                program.Run();
$endif$
        }
        public void EnsureSyncPointInformationDoesntSerializeExtraJunk()
        {
            var template = new SyncPointInformation(Guid.NewGuid(), Guid.NewGuid(), typeof (string), "Foo", DateTimeOffset.MinValue);
            var json = JSONHelper.Serialize(template);
            this.Log().Debug(json);

            var expected = new[] {
                "RootObjectHash",
                "ParentSyncPoint",
                "RootObjectTypeName",
                "Qualifier",
                "CreatedOn"
            };

            // TODO: This test sucks out loud
            expected.Run(x => Assert.True(json.Contains(x)));
        }
        public void MessageBusSmokeTest()
        {
            var input = new[] {1, 2, 3, 4};

            var result = (new TestScheduler()).With(sched => {
                var source = new Subject<int>();
                var fixture = new MessageBus();

                fixture.RegisterMessageSource(source, "Test");
                Assert.False(fixture.IsRegistered(typeof (int)));
                Assert.False(fixture.IsRegistered(typeof (int), "Foo"));

                var output = fixture.Listen<int>("Test").CreateCollection();

                input.Run(source.OnNext);

                sched.Start();
                return output;
            });

            input.AssertAreEqual(result);
        }
        public void ObservableCanExecuteShouldShowUpInCommand()
        {
            var input = new[] {true, false, false, true, false, true};
            var result = (new TestScheduler()).With(sched => {
                var can_execute = new Subject<bool>();
                var fixture = new ReactiveCommand(can_execute, null);
                var changes_as_observable = new ListObservable<bool>(fixture.CanExecuteObservable);

                int change_event_count = 0;
                fixture.CanExecuteChanged += (o, e) => { change_event_count++; };
                input.Run(x => {
                    can_execute.OnNext(x);
                    sched.Run();
                    Assert.AreEqual(x, fixture.CanExecute(null));
                });

                // N.B. We check against '5' instead of 6 because we're supposed to
                // suppress changes that aren't actually changes i.e. false => false
                can_execute.OnCompleted();
                sched.Run();
                Assert.AreEqual(5, change_event_count);

                return changes_as_observable;
            });

            input.AssertAreEqual(result.ToList());
        }
        public void MultipleSubscribesShouldntResultInMultipleNotifications()
        {
            var input = new[] { 1, 2, 1, 2 };
            var sched = new TestScheduler();
            var fixture = new ReactiveCommand(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.RunToMilliseconds(1000);

            new[]{1,1}.AssertAreEqual(odd_list);
            new[]{2,2}.AssertAreEqual(even_list);
        }
Example #7
0
        public void ObservableCanExecuteShouldShowUpInCommand()
        {
            var input = new[] {true, false, false, true, false, true};
            var result = (new TestScheduler()).With(sched => {
                var can_execute = new Subject<bool>();
                var fixture = createCommand(can_execute, sched);
                var changes_as_observable = fixture.CanExecuteObservable.CreateCollection();

                int change_event_count = 0;
                fixture.CanExecuteChanged += (o, e) => { change_event_count++; };
                input.Run(x => {
                    this.Log().InfoFormat("input = {0}", x);
                    can_execute.OnNext(x);
                    sched.Run();
                    Assert.Equal(x, fixture.CanExecute(null));
                });

                // N.B. We check against '5' instead of 6 because we're supposed to
                // suppress changes that aren't actually changes i.e. false => false
                sched.RunToMilliseconds(10 * 1000);
                return changes_as_observable;
            });

            input.DistinctUntilChanged().AssertAreEqual(result.ToList());
        }
        public void ObservableCanExecuteShouldShowUpInCommand()
        {
            var can_execute = new Subject<bool>();
            var fixture = new ReactiveCommand(can_execute, null);
            var changes_as_observable = new ListObservable<bool>(fixture.CanExecuteObservable);

            var input = new[] { true, false, false, true, false, true };

            int change_event_count = 0;
            fixture.CanExecuteChanged += (o, e) => { change_event_count++; };
            input.Run(x => {
                can_execute.OnNext(x);
                Assert.AreEqual(x, fixture.CanExecute(null));
            });

            // N.B. We check against '5' instead of 6 because we're supposed to
            // suppress changes that aren't actually changes i.e. false => false
            can_execute.OnCompleted();
            Assert.AreEqual(5, change_event_count);

            input.Zip(changes_as_observable.ToList(), (expected, actual) => new { expected, actual })
                 .Do(Console.WriteLine)
                 .Run(x => Assert.AreEqual(x.expected, x.actual));
        }
        public void MultipleSubscribesShouldntResultInMultipleNotifications()
        {
            var input = new[] { 1, 2, 1, 2 };
            var fixture = new ReactiveCommand(null, null);

            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));

            new[]{1,1}.Zip(odd_list, (expected, actual) => new { expected, actual })
                .Run(x => Assert.AreEqual(x.expected, x.actual));

            new[]{2,2}.Zip(even_list, (expected, actual) => new { expected, actual })
                .Run(x => Assert.AreEqual(x.expected, x.actual));
        }
        public void DisposeTest()
        {
            var input = new[] { 1, 1, 1, 1, 1 };
            var fixture = new QueuedAsyncMRUCache<int, int>(x => { Thread.Sleep(1000); return x * 5; }, 5, 2);

            input.Run(x => fixture.AsyncGet(x));
            fixture.Dispose();

            bool threw = false;
            try {
                fixture.AsyncGet(2);
            } catch(Exception ex) {
                this.Log().Info("Threw exception correctly", ex);
                threw = true;
            }
            Assert.IsTrue(threw);
        }
        public void CanGenerate_Multithreaded()
        {
            var ids = new ConcurrentBag<KeyValuePair<Int32, UInt64>>();

            var cts = new CancellationTokenSource();
            
            ParameterizedThreadStart generateIds = (token) =>
            {
                var ct = (CancellationToken)token;

                while (!ct.IsCancellationRequested)
                {
                    var newIds = new ulong[10000];
                    for (int i = 0; i < 10000; i++)
                    {
                        newIds[i] = _generator.Generate();
                    }

                    newIds.Run(x => ids.Add(KeyValuePair.Create(Thread.CurrentThread.ManagedThreadId, x)));
                }
            };

            var threads = new[]
            {
                new Thread(generateIds),
                new Thread(generateIds),
                new Thread(generateIds),
                new Thread(generateIds)
            };

            threads.Run(t => t.Start(cts.Token));

            Thread.Sleep(1000);

            cts.Cancel();

            threads.Run(t => t.Join());

            var distinctIds = ids.Select(x => x.Value).Distinct().ToArray();
            Assert.IsTrue(ids.Count > 0, "Count wasn't greater than zero.");
            Assert.IsTrue(ids.Count == distinctIds.Count(), "Counts don't match!");

            Console.WriteLine("Id count: {0}", ids.Count);

            var distinctThreadIds = ids.Select(x => x.Key).Distinct().ToArray();
            Assert.IsTrue(distinctThreadIds.Length > 1, "Distinct threads not greater than one.");
        }