Beispiel #1
0
        public Form1()
        {
            InitializeComponent();

            textBox1.Text       = "initial text";
            textBox6.Text       = "switchmap inti";
            textLiveData1.Value = textBox1.Text;

            textLiveData2 = textLiveData1.Map <string, string>((text) =>
            {
                return(string.Concat("Mapped: ", text));
            });

            textLiveData3 = textLiveData1.SwitchMap <string, string>((text) =>
            {
                switchMapLive.Value += text;
                return(switchMapLive);
            });

            textLiveData1.Observe(t => textBox2.Text = t);
            textLiveData1.Observe(t => textBox4.Text = t);
            textLiveData2.Observe(t => textBox3.Text = t);
            textLiveData3.Observe(t => textBox5.Text = t);
        }
Beispiel #2
0
        public void LiveDataValueTypeDefaultSettingsIntegrationTest()
        {
            var randomGen    = new Random();
            var val0         = randomGen.Next();
            var val1         = randomGen.Next();
            var val2         = randomGen.Next();
            var testSequence = new List <int>(new[] { val1, val2, val2, val1, val2, val1, val1 });

            _liveDataValueType = new LiveData <int>(val0, _testRxSchedulerFacade.Object);

            _liveDataValueType.Observe(_lifecycleManager,
                                       i => _emittedVerificationListValue.Add(i),
                                       e => Assert.Fail("onError called"));

            Assert.AreEqual(0, _emittedVerificationListValue.Count);

            _lifecycleManager.OnResume();

            Assert.AreEqual(1, _emittedVerificationListValue.Count);
            Assert.AreEqual(val0, _emittedVerificationListValue[0]);

            testSequence.ForEach(i => _liveDataValueType.PostValue(i));

            Assert.AreEqual(6, _emittedVerificationListValue.Count);
            Assert.AreEqual(val0, _emittedVerificationListValue[0]);
            Assert.AreEqual(val1, _emittedVerificationListValue[1]);
            Assert.AreEqual(val2, _emittedVerificationListValue[2]);
            Assert.AreEqual(val1, _emittedVerificationListValue[3]);
            Assert.AreEqual(val2, _emittedVerificationListValue[4]);
            Assert.AreEqual(val1, _emittedVerificationListValue[5]);

            _lifecycleManager.OnPause();

            testSequence.ForEach(i => _liveDataValueType.PostValue(i));

            Assert.AreEqual(6, _emittedVerificationListValue.Count);

            _lifecycleManager.OnResume();

            Assert.AreEqual(6, _emittedVerificationListValue.Count);

            _lifecycleManager.OnPause();

            testSequence.ForEach(i => _liveDataValueType.PostValue(i));
            _liveDataValueType.PostValue(val0);
            _liveDataValueType.PostValue(val1);
            _liveDataValueType.PostValue(val2);

            _lifecycleManager.OnResume();

            Assert.AreEqual(7, _emittedVerificationListValue.Count);
            Assert.AreEqual(val2, _emittedVerificationListValue[6]);

            _lifecycleManager.OnDestroyView();

            Assert.AreEqual(7, _emittedVerificationListValue.Count);

            _liveDataValueType.Observe(_lifecycleManager,
                                       i => _emittedVerificationListValue.Add(i),
                                       e => Assert.Fail("onError called"));

            Assert.AreEqual(7, _emittedVerificationListValue.Count);

            _lifecycleManager.OnResume();

            Assert.AreEqual(8, _emittedVerificationListValue.Count);
            Assert.AreEqual(val2, _emittedVerificationListValue[7]);

            _lifecycleManager.OnPause();

            Assert.AreEqual(8, _emittedVerificationListValue.Count);

            _lifecycleManager.OnDestroyView();

            testSequence.ForEach(i => _liveDataValueType.PostValue(i));
            _liveDataValueType.PostValue(val0);
            _liveDataValueType.PostValue(val1);

            _liveDataValueType.Observe(_lifecycleManager,
                                       i => _emittedVerificationListValue.Add(i),
                                       e => Assert.Fail("onError called"));

            Assert.AreEqual(8, _emittedVerificationListValue.Count);

            _lifecycleManager.OnResume();

            Assert.AreEqual(9, _emittedVerificationListValue.Count);
            Assert.AreEqual(val1, _emittedVerificationListValue[8]);
        }
Beispiel #3
0
        public void LiveDataReferenceTypeAllowDuplicatesIntegrationTest()
        {
            var val0         = TestUtils.RandomString(32);
            var val1         = TestUtils.RandomString(32);
            var val2         = TestUtils.RandomString(32);
            var testSequence = new List <string>(new[] { val1, val2, val2, val1, val2, val1, val1 });

            _liveDataReferenceType = new LiveData <string>(val0, _testRxSchedulerFacade.Object, true);

            _liveDataReferenceType.Observe(_lifecycleManager,
                                           s => _emittedVerificationListReference.Add(s),
                                           e => Assert.Fail("onError called"));

            Assert.AreEqual(0, _emittedVerificationListReference.Count);

            _lifecycleManager.OnResume();

            Assert.AreEqual(1, _emittedVerificationListReference.Count);
            Assert.AreEqual(val0, _emittedVerificationListReference[0]);

            testSequence.ForEach(i => _liveDataReferenceType.PostValue(i));

            Assert.AreEqual(8, _emittedVerificationListReference.Count);
            for (var i = 1; i < _emittedVerificationListReference.Count; ++i)
            {
                Assert.AreEqual(testSequence[i - 1], _emittedVerificationListReference[i]);
            }

            _lifecycleManager.OnPause();

            testSequence.ForEach(s => _liveDataReferenceType.PostValue(s));

            Assert.AreEqual(8, _emittedVerificationListReference.Count);

            _lifecycleManager.OnResume();

            Assert.AreEqual(9, _emittedVerificationListReference.Count);
            Assert.AreEqual(val1, _emittedVerificationListReference[8]);

            _lifecycleManager.OnPause();

            testSequence.ForEach(s => _liveDataReferenceType.PostValue(s));
            _liveDataReferenceType.PostValue(val0);
            _liveDataReferenceType.PostValue(val1);
            _liveDataReferenceType.PostValue(val2);

            _lifecycleManager.OnResume();

            Assert.AreEqual(10, _emittedVerificationListReference.Count);
            Assert.AreEqual(val2, _emittedVerificationListReference[9]);

            _lifecycleManager.OnDestroyView();

            Assert.AreEqual(10, _emittedVerificationListReference.Count);

            _liveDataReferenceType.Observe(_lifecycleManager,
                                           s => _emittedVerificationListReference.Add(s),
                                           e => Assert.Fail("onError called"));

            Assert.AreEqual(10, _emittedVerificationListReference.Count);

            _lifecycleManager.OnResume();

            Assert.AreEqual(11, _emittedVerificationListReference.Count);
            Assert.AreEqual(val2, _emittedVerificationListReference[10]);

            _lifecycleManager.OnPause();

            Assert.AreEqual(11, _emittedVerificationListReference.Count);

            _lifecycleManager.OnDestroyView();

            testSequence.ForEach(i => _liveDataReferenceType.PostValue(i));
            _liveDataReferenceType.PostValue(val0);
            _liveDataReferenceType.PostValue(val1);

            _liveDataReferenceType.Observe(_lifecycleManager,
                                           s => _emittedVerificationListReference.Add(s),
                                           e => Assert.Fail("onError called"));

            Assert.AreEqual(11, _emittedVerificationListReference.Count);

            _lifecycleManager.OnResume();

            Assert.AreEqual(12, _emittedVerificationListReference.Count);
            Assert.AreEqual(val1, _emittedVerificationListReference[11]);
        }