ReplaceCurrent() public méthode

Replaces the current item with the specified replacement.
/// Thrown when is . /// /// Thrown when the collection is empty. ///
public ReplaceCurrent ( PostedTime replacement ) : void
replacement PostedTime The replacement item.
Résultat void
        public void replacing_an_item_updates_the_range()
        {
            var model = new PostedTimeCollectionModel();
            var observer = model.CreateObserver();

            model.Add(PT(10, PostedTimeType.Normal, 1));
            Assert.Equal(TS(0), model.Range);
            model.ReplaceCurrent(PT(10, PostedTimeType.Normal, 1));
            Assert.Equal(TS(0), model.Range);
            model.Add(PT(20, PostedTimeType.Normal, 1));
            model.ReplaceCurrent(PT(10, PostedTimeType.Normal, 1));
            Assert.Equal(TS(10), model.Range);

            Assert.Equal(2, observer.GetChangeCount(x => x.Range));
        }
        public void replacing_an_item_updates_the_session_best_count()
        {
            var model = new PostedTimeCollectionModel();
            var observer = model.CreateObserver();

            model.Add(PT(15, PostedTimeType.SessionBest, 1));
            Assert.Equal(1, model.SessionBestCount);
            model.ReplaceCurrent(PT(15, PostedTimeType.SessionBest, 1));
            Assert.Equal(1, model.SessionBestCount);
            model.ReplaceCurrent(PT(15, PostedTimeType.Normal, 1));
            Assert.Equal(0, model.SessionBestCount);
            model.ReplaceCurrent(PT(15, PostedTimeType.SessionBest, 1));
            Assert.Equal(1, model.SessionBestCount);
            model.ReplaceCurrent(PT(15, PostedTimeType.PersonalBest, 1));
            Assert.Equal(0, model.SessionBestCount);

            Assert.Equal(4, observer.GetChangeCount(x => x.SessionBestCount));
        }
        public void replacing_an_item_updates_the_mean()
        {
            var model = new PostedTimeCollectionModel();
            var observer = model.CreateObserver();

            model.Add(PT(1, PostedTimeType.Normal, 1));
            model.ReplaceCurrent(PT(10, PostedTimeType.Normal, 1));
            Assert.Equal(TS(10), model.Mean);

            Assert.True(observer.HasChanged(x => x.Mean));
        }
        public void replacing_an_item_updates_the_minimum_if_it_has_changed()
        {
            var model = new PostedTimeCollectionModel();
            var observer = model.CreateObserver();
            var replacement = PT(20, PostedTimeType.Normal, 1);

            model.Add(PT(30, PostedTimeType.Normal, 1));
            observer.ClearChanges();

            model.ReplaceCurrent(replacement);
            Assert.Equal(replacement, model.Minimum);
            Assert.True(observer.HasChanged(x => x.Minimum));

            model.Add(PT(10, PostedTimeType.Normal, 1));
            observer.ClearChanges();

            replacement = PT(5, PostedTimeType.Normal, 1);
            model.ReplaceCurrent(replacement);
            Assert.Equal(replacement, model.Minimum);
            Assert.True(observer.HasChanged(x => x.Minimum));
        }
        public void replacing_an_item_updates_the_items()
        {
            var model = new PostedTimeCollectionModel();
            var replacement = PT(50, PostedTimeType.Normal, 1);

            model.Add(PT(1, PostedTimeType.Normal, 1));
            model.ReplaceCurrent(replacement);
            Assert.Equal(replacement, model.Items[0]);
        }
        public void replacing_an_item_does_not_update_the_count()
        {
            var model = new PostedTimeCollectionModel();
            var observer = model.CreateObserver();

            model.Add(PT(1, PostedTimeType.Normal, 1));
            observer.ClearChanges();

            model.ReplaceCurrent(PT(10, PostedTimeType.Normal, 1));
            Assert.Equal(1, model.Count);

            Assert.False(observer.HasChanged(x => x.Count));
        }
        public void replace_current_throws_if_replacement_is_null()
        {
            var model = new PostedTimeCollectionModel();

            Assert.Throws<ArgumentNullException>(() => model.ReplaceCurrent(null));
        }
        public void replace_current_throws_if_current_has_not_been_set()
        {
            var model = new PostedTimeCollectionModel();

            Assert.Throws<InvalidOperationException>(() => model.ReplaceCurrent(PT(10, PostedTimeType.Normal, 1)));
        }
        public void bug()
        {
            var model = new PostedTimeCollectionModel();
            var time = PT(23.3, PostedTimeType.SessionBest, 0);

            model.Add(time);

            model.ReplaceCurrent(PT(23.3, PostedTimeType.PersonalBest, 0));

            Assert.NotEqual(time, model.Minimum);
        }