<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Subjects;
using Reactive.Bindings.Extensions;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ReactiveProperty.Tests.Extensions
{
    [TestClass]
    public class DisposePreviousValueExtensionsTest
    {
        [TestMethod]
        public void DisposePrevious()
        {
            var source = new Subject<DisposableObject>();
            source.DisposePreviousValue().Subscribe();

            var first = new DisposableObject();
            var second = new DisposableObject();

            first.IsDisposed.IsFalse();
            second.IsDisposed.IsFalse();

            source.OnNext(first);
            first.IsDisposed.IsFalse();
            second.IsDisposed.IsFalse();

            source.OnNext(second);
            first.IsDisposed.IsTrue();
            second.IsDisposed.IsFalse();
        }

        [TestMethod]
        public void DisposeCurrentValueOnCompleted()
        {
            var source = new Subject<DisposableObject>();
            var dispose = source.DisposePreviousValue().Subscribe();

            var value = new DisposableObject();
            source.OnNext(value);

            value.IsDisposed.IsFalse();
            dispose.Dispose();
            value.IsDisposed.IsTrue();
        }

        [TestMethod]
        public void DisposeCurrentValueOnError()
        {
            var source = new Subject<DisposableObject>();
            source.DisposePreviousValue().Subscribe();

            var value = new DisposableObject();
            source.OnNext(value);

            value.IsDisposed.IsFalse();
            source.OnError(new Exception());
            value.IsDisposed.IsTrue();
        }
    }
<commit_msg>improve test cases for DisposePreviousValue<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Subjects;
using Reactive.Bindings.Extensions;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Reactive.Testing;
using System.Security.Cryptography.X509Certificates;

namespace ReactiveProperty.Tests.Extensions
{
    [TestClass]
    public class DisposePreviousValueExtensionsTest : ReactiveTest
    {
        [TestMethod]
        public void DisposePrevious()
        {
            var testScheduler = new TestScheduler();
            var recorder = testScheduler.CreateObserver<DisposableObject>();
            var source = new Subject<DisposableObject>();
            source.DisposePreviousValue().Subscribe(recorder);

            var first = new DisposableObject();
            var second = new DisposableObject();

            first.IsDisposed.IsFalse();
            second.IsDisposed.IsFalse();

            source.OnNext(first);
            first.IsDisposed.IsFalse();
            second.IsDisposed.IsFalse();

            source.OnNext(second);
            first.IsDisposed.IsTrue();
            second.IsDisposed.IsFalse();

            recorder.Messages.Is(
               OnNext<DisposableObject>(0, x => x == first),
               OnNext<DisposableObject>(0, x => x == second));
        }

        [TestMethod]
        public void DisposeCurrentValueDispose()
        {
            var testScheduler = new TestScheduler();
            var recorder = testScheduler.CreateObserver<DisposableObject>();
            var source = new Subject<DisposableObject>();
            var dispose = source.DisposePreviousValue().Subscribe(recorder);

            var value = new DisposableObject();
            source.OnNext(value);

            value.IsDisposed.IsFalse();
            dispose.Dispose();
            value.IsDisposed.IsTrue();

            recorder.Messages.Is(
                OnNext<DisposableObject>(0, x => x == value));
        }

        [TestMethod]
        public void DisposeCurrentValueOnCompleted()
        {
            var testScheduler = new TestScheduler();
            var recorder = testScheduler.CreateObserver<DisposableObject>();
            var source = new Subject<DisposableObject>();
            source.DisposePreviousValue().Subscribe(recorder);

            var value = new DisposableObject();
            source.OnNext(value);

            value.IsDisposed.IsFalse();
            source.OnCompleted();
            value.IsDisposed.IsTrue();

            recorder.Messages.Is(
                OnNext<DisposableObject>(0, x => x == value),
                OnCompleted<DisposableObject>(0));
        }

        [TestMethod]
        public void DisposeCurrentValueOnError()
        {
            var testScheduler = new TestScheduler();
            var recorder = testScheduler.CreateObserver<DisposableObject>();
            var source = new Subject<DisposableObject>();
            source.DisposePreviousValue().Subscribe(recorder);

            var value = new DisposableObject();
            source.OnNext(value);

            value.IsDisposed.IsFalse();
            source.OnError(new Exception("test error"));
            value.IsDisposed.IsTrue();

            recorder.Messages.Is(
                OnNext<DisposableObject>(0, x => x == value),
                OnError<DisposableObject>(0, x => x.Message == "test error"));
        }
    }

{'fraction_non_alphanumeric': 0.10199098422238918, 'fraction_numerical': 0.0018782870022539444, 'mean_word_length': 2.169642857142857, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6649955', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1312, 'n_words': 253}