Пример #1
0
        public void Replace_ReplacedAndEventRaised()
        {
            TestDataManager dm = new TestDataManager();
            TestDataType    data1 = new TestDataType {
                Id = 1U
            }, data2 = new TestDataType {
                Id = 2U
            };

            dm.Add(data1);

            TestDataObserver obs = new TestDataObserver();

            using IDisposable unsubscriber = dm.Subscribe(obs);
            Assert.AreEqual(dm.Get(1U), data1);
            dm.ReplaceData(new HashSet <TestDataType> {
                data2
            });
            Assert.AreEqual(dm.Get(2U), data2);
            Assert.AreEqual(0, obs.CompleteCount);
            Assert.AreEqual(0, obs.Errors.Count);
            Assert.AreEqual(1, obs.Next.Count);
            DataChanged <TestDataType> change = obs.Next.Dequeue();

            Assert.IsTrue(change.Action == DataChangedAction.Replace &&
                          change.OldItems?.FirstOrDefault() == data1 &&
                          change.NewItems?.FirstOrDefault() == data2);
        }
Пример #2
0
        public void Add_AddedOnceAndEventRaised()
        {
            TestDataManager  dm   = new TestDataManager();
            TestDataType     data = new TestDataType();
            TestDataObserver obs  = new TestDataObserver();

            using IDisposable unsubscriber = dm.Subscribe(obs);
            dm.Add(data);
            Assert.ThrowsException <ArgumentException>(() => dm.Add(data));
            Assert.AreEqual(0, obs.CompleteCount);
            Assert.AreEqual(0, obs.Errors.Count);
            Assert.AreEqual(1, obs.Next.Count);
            DataChanged <TestDataType> change = obs.Next.Dequeue();

            Assert.IsTrue(change.Action == DataChangedAction.Add && change.NewItems?.FirstOrDefault() == data);
        }
Пример #3
0
        public void GetAdded_ReturnsNotNull()
        {
            TestDataManager dm = new TestDataManager();

            dm.Add(new TestDataType {
                Id = 1U
            });
            Assert.IsNotNull(dm.Get(1U));
        }
Пример #4
0
        public void Reset_ResetAndEventRaised()
        {
            TestDataManager dm   = new TestDataManager();
            TestDataType    data = new TestDataType();

            dm.Add(data);
            TestDataObserver obs = new TestDataObserver();

            using IDisposable unsubscriber = dm.Subscribe(obs);
            dm.Reset();
            Assert.IsFalse(dm.GetAll().Any());
            Assert.AreEqual(0, obs.CompleteCount);
            Assert.AreEqual(0, obs.Errors.Count);
            Assert.AreEqual(1, obs.Next.Count);
            DataChanged <TestDataType> change = obs.Next.Dequeue();

            Assert.IsTrue(change.Action == DataChangedAction.Reset && change.OldItems?.FirstOrDefault() == data);
        }