Пример #1
0
        /// <summary>
        /// -99 = null input
        /// -1 = wrong type
        /// 0 = same type, wrong id
        /// 1 = same reference (same id, same type)
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int CompareTo(ILiveData other)
        {
            if (other != null)
            {
                try
                {
                    if (other.GetType() != GetType())
                    {
                        return(-1);
                    }

                    if (other.BirthMark.Equals(BirthMark))
                    {
                        return(1);
                    }

                    return(0);
                }
                catch (Exception ex)
                {
                    LoggingUtility.LogError(ex);
                }
            }

            return(-99);
        }
Пример #2
0
        public void SubscribeOnResumeDefaultSettingsNoReEmissionTest()
        {
            var val0 = TestUtils.RandomString(32);
            var val1 = TestUtils.RandomString(32);
            var val2 = TestUtils.RandomString(32);

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

            _singleDisposable = _liveDataReferenceType.Subscribe(OnNextMock, OnErrorMock, OnCompletedMock);
            var testSequence = new List <string>(new[] { val1, val2, val2, val1, val2, val1, val1 });

            _liveDataReferenceType.PostValue(testSequence[0]);
            _liveDataReferenceType.PostValue(testSequence[1]);
            _liveDataReferenceType.PostValue(testSequence[2]);
            _singleDisposable.Dispose();
            _singleDisposable = _liveDataReferenceType.Subscribe(OnNextMock, OnErrorMock, OnCompletedMock);
            _liveDataReferenceType.PostValue(testSequence[3]);
            _liveDataReferenceType.PostValue(testSequence[4]);
            _singleDisposable.Dispose();
            _singleDisposable = _liveDataReferenceType.Subscribe(OnNextMock, OnErrorMock, OnCompletedMock);
            _liveDataReferenceType.PostValue(testSequence[5]);
            _liveDataReferenceType.PostValue(testSequence[6]);

            Assert.AreEqual(6, _emittedVerificationListReference.Count);
            Assert.AreEqual(val0, _emittedVerificationListReference[0]);
            Assert.AreEqual(val1, _emittedVerificationListReference[1]);
            Assert.AreEqual(val2, _emittedVerificationListReference[2]);
            Assert.AreEqual(val1, _emittedVerificationListReference[3]);
            Assert.AreEqual(val2, _emittedVerificationListReference[4]);
            Assert.AreEqual(val1, _emittedVerificationListReference[5]);
            Assert.AreEqual(val1, _liveDataReferenceType.Value);
        }
Пример #3
0
        public void InitValueIgnoreTypeDefaultReferenceTypeTest()
        {
            _liveDataReferenceType = new LiveData <string>(default(string), _testRxSchedulerFacade.Object);

            _singleDisposable = _liveDataReferenceType.Subscribe(OnNextMock, OnErrorMock, OnCompletedMock);

            Assert.AreEqual(0, _emittedVerificationListValue.Count);
            Assert.AreEqual(default(string), _liveDataReferenceType.Value);
        }
Пример #4
0
        public void ObserveTest()
        {
            _liveDataValueType = new LiveData <int>();
            Action <int>       onNextMock  = i => { };
            Action <Exception> onErrorMock = exception => { };

            _liveDataValueType.Observe(_lifecycleManagerMock.Object, onNextMock, onErrorMock);

            _lifecycleManagerMock.Verify(manager => manager.Register(_liveDataValueType, onNextMock, onErrorMock), Times.Once());
        }
 /// <summary>
 /// Registers new subscription and save observer info internally for resubscribing
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="liveData"></param>
 /// <param name="onNext"></param>
 /// <param name="onError"></param>
 public void Register <T>(ILiveData <T> liveData, Action <T> onNext, Action <Exception> onError)
 {
     _subscriptions.Add(new InternalObserverHolder <T>
     {
         LiveData = liveData,
         OnNext   = onNext,
         OnError  = onError,
         Id       = _internalIdSequence++
     });
 }
 /// <summary>
 /// Subscribe without saving observer
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="liveData"></param>
 /// <param name="onNext"></param>
 /// <param name="onError"></param>
 /// <param name="internalId">Internal observable holder id</param>
 protected void ReAdd <T>(ILiveData <T> liveData, Action <T> onNext, Action <Exception> onError, int internalId)
 {
     _disposable.Add(liveData.Subscribe(onNext, onError, () =>
     {
         var sub = _subscriptions.FirstOrDefault(holder => holder.Id == internalId);
         if (sub != null)
         {
             _subscriptions.Remove(sub);
         }
     }));
 }
Пример #7
0
        public void InitValueReferenceTypeTest()
        {
            var val0 = TestUtils.RandomString(32);

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

            _singleDisposable = _liveDataReferenceType.Subscribe(OnNextMock, OnErrorMock, OnCompletedMock);

            Assert.AreEqual(1, _emittedVerificationListReference.Count);
            Assert.AreEqual(val0, _emittedVerificationListReference[0]);
            Assert.AreEqual(val0, _liveDataReferenceType.Value);
        }
Пример #8
0
        public SaveViewModel(ISaveEnvironmentService saveEnvironmentService,
                             IGameEnvironmentGetRepository loadedGameEnvironmentGetRepository,
                             IInGameMessageService messageService)
        {
            _saveEnvironmentService             = saveEnvironmentService;
            _saveEnvironmentService             = saveEnvironmentService;
            _loadedGameEnvironmentGetRepository = loadedGameEnvironmentGetRepository;
            _messageService = messageService;

            savingResultEvent = new LiveData <SavingResult>();
            savingDetailDialogVisibilityEvent = new LiveData <bool>();
        }
Пример #9
0
        public void InitValueValueTypeTest()
        {
            var randomGen = new Random();
            var val0      = randomGen.Next();

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

            _singleDisposable = _liveDataValueType.Subscribe(OnNextMock, OnErrorMock, OnCompletedMock);

            Assert.AreEqual(1, _emittedVerificationListValue.Count);
            Assert.AreEqual(val0, _emittedVerificationListValue[0]);
            Assert.AreEqual(val0, _liveDataValueType.Value);
        }
Пример #10
0
        /// <summary>
        /// Compares this object to another one to see if they are the same object
        /// </summary>
        /// <param name="other">the object to compare to</param>
        /// <returns>true if the same object</returns>
        public bool Equals(ILiveData other)
        {
            if (other != default(ILiveData))
            {
                try
                {
                    return(other.GetType() == GetType() && other.BirthMark.Equals(BirthMark));
                }
                catch (Exception ex)
                {
                    LoggingUtility.LogError(ex);
                }
            }

            return(false);
        }
Пример #11
0
        public void SubscribeReferenceTypeAllowDuplicatesTest()
        {
            var val0 = TestUtils.RandomString(32);
            var val1 = TestUtils.RandomString(32);
            var val2 = TestUtils.RandomString(32);

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

            _singleDisposable = _liveDataReferenceType.Subscribe(OnNextMock, OnErrorMock, OnCompletedMock);
            var testSequence = new List <string>(new[] { val1, val2, val2, val1, val2, val1, val1 });

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

            Assert.AreEqual(8, _emittedVerificationListReference.Count);
            Assert.AreEqual(val0, _emittedVerificationListReference[0]);
            for (var i = 1; i < _emittedVerificationListReference.Count; ++i)
            {
                Assert.AreEqual(testSequence[i - 1], _emittedVerificationListReference[i]);
            }
            Assert.AreEqual(testSequence[testSequence.Count - 1], _liveDataReferenceType.Value);
        }
Пример #12
0
        public void SubscribeValueTypeAllowDuplicatesTest()
        {
            var randomGen = new Random();
            var val0      = randomGen.Next();
            var val1      = randomGen.Next();
            var val2      = randomGen.Next();

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

            _singleDisposable = _liveDataValueType.Subscribe(OnNextMock, OnErrorMock, OnCompletedMock);
            var testSequence = new List <int>(new[] { val1, val2, val2, val1, val2, val1, val1 });

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

            Assert.AreEqual(8, _emittedVerificationListValue.Count);
            Assert.AreEqual(val0, _emittedVerificationListValue[0]);
            for (var i = 1; i < _emittedVerificationListValue.Count; ++i)
            {
                Assert.AreEqual(testSequence[i - 1], _emittedVerificationListValue[i]);
            }
            Assert.AreEqual(testSequence[testSequence.Count - 1], _liveDataValueType.Value);
        }
Пример #13
0
        public void SubscribeValueTypeDefaultSettingsTest()
        {
            var randomGen = new Random();
            var val0      = randomGen.Next();
            var val1      = randomGen.Next();
            var val2      = randomGen.Next();

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

            _singleDisposable = _liveDataValueType.Subscribe(OnNextMock, OnErrorMock, OnCompletedMock);
            var testSequence = new List <int>(new [] { val1, val2, val2, val1, val2, val1, val1 });

            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]);
            Assert.AreEqual(val1, _liveDataValueType.Value);
        }
Пример #14
0
 /// <summary>
 /// Get the hash code for comparison purposes
 /// </summary>
 /// <param name="obj">the thing to get the hashcode for</param>
 /// <returns>the hash code</returns>
 public int GetHashCode(ILiveData obj)
 {
     return(obj.GetType().GetHashCode() + obj.BirthMark.GetHashCode());
 }
Пример #15
0
 /// <summary>
 /// Compares an object to another one to see if they are the same object
 /// </summary>
 /// <param name="x">the object to compare to</param>
 /// <param name="y">the object to compare to</param>
 /// <returns>true if the same object</returns>
 public bool Equals(ILiveData x, ILiveData y)
 {
     return(x.Equals(y));
 }
Пример #16
0
 /// <summary>
 /// Make a new cache key using the object
 /// </summary>
 /// <param name="data">the object</param>
 public LiveCacheKey(ILiveData data)
 {
     ObjectType = data.GetType();
     BirthMark  = data.BirthMark;
 }