<commit_before>﻿using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
using Chatham.ServiceDiscovery.Abstractions;
using Chatham.ServiceDiscovery.Utilities;
using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;

namespace Chatham.ServiceDiscovery.Tests
{
    [TestClass]
    [ExcludeFromCodeCoverage]
    public class CachingServiceSubscriberTests
    {
        [TestMethod]
        public async Task Endpoints_PopulatesCacheImmediately()
        {
            var logger = Substitute.For<ILogger>();
            var serviceSubscriber = Substitute.For<IServiceSubscriber>();
            var cache = Substitute.For<ICacheClient>();
            var throttle = Substitute.For<IThrottle>();

            serviceSubscriber.Endpoints().Returns(Task.FromResult(new List<Uri>()));
            throttle.Queue(Arg.Any<Func<Task<List<Uri>>>>(), Arg.Any<CancellationToken>())
                .Returns(t =>
                {
                    Task.Delay(5000);
                    return Task.FromResult(new List<Uri>());
                });
            //Cache.Get<List<Uri>>(Arg.Any<string>()).Returns(new List<Uri>());
            cache.Set(Arg.Any<object>(), Arg.Any<List<Uri>>()).Returns(new List<Uri>());

            var cts = new CancellationTokenSource();
            var target = new CachingServiceSubscriber(logger, serviceSubscriber, cache, throttle, cts);

            var actual = await target.Endpoints();

            cache.Set(Arg.Any<object>(), Arg.Any<List<Uri>>()).Received(1);
            cache.Get<List<Uri>>(Arg.Any<string>()).Received(1);
        }

        public void Endpoints_StartsSubscriptionLoop() { }

        public void Endpoints_throttlesCallsInSubscriptionLoop() { }

        public void Dispose_cancelsAndDisposesTokenSource() { }

        public void Endpoints_whenCallerCancellationTokenCancels_doesSomething() { }
        
    }
}<commit_msg>Fixing bevavior test for Caching Subscriber<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
using Chatham.ServiceDiscovery.Abstractions;
using Chatham.ServiceDiscovery.Utilities;
using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;

namespace Chatham.ServiceDiscovery.Tests
{
    [TestClass]
    [ExcludeFromCodeCoverage]
    public class CachingServiceSubscriberTests
    {
        [TestMethod]
        public async Task Endpoints_PopulatesCacheImmediately()
        {
            var logger = Substitute.For<ILogger>();
            var serviceSubscriber = Substitute.For<IServiceSubscriber>();
            var cache = Substitute.For<ICacheClient>();
            var throttle = Substitute.For<IThrottle>();

            serviceSubscriber.Endpoints().Returns(Task.FromResult(new List<Uri>()));
            throttle.Queue(Arg.Any<Func<Task<List<Uri>>>>(), Arg.Any<CancellationToken>())
                .Returns(t =>
                {
                    Task.Delay(5000);
                    return Task.FromResult(new List<Uri>());
                });
            //Cache.Get<List<Uri>>(Arg.Any<string>()).Returns(new List<Uri>());
            cache.Set(Arg.Any<object>(), Arg.Any<List<Uri>>()).Returns(new List<Uri>());

            var cts = new CancellationTokenSource();
            var target = new CachingServiceSubscriber(logger, serviceSubscriber, cache, throttle, cts);

            var actual = await target.Endpoints();

            cache.Received(1).Set(Arg.Any<object>(), Arg.Any<List<Uri>>());
            cache.Received(1).Get<List<Uri>>(Arg.Any<string>());
        }

        public void Endpoints_StartsSubscriptionLoop() { }

        public void Endpoints_throttlesCallsInSubscriptionLoop() { }

        public void Dispose_cancelsAndDisposesTokenSource() { }

        public void Endpoints_whenCallerCancellationTokenCancels_doesSomething() { }
        
    }
}
{'fraction_non_alphanumeric': 0.11994076999012833, 'fraction_numerical': 0.0029615004935834156, 'mean_word_length': 2.981335952848723, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 55, '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': '6346868', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1114, 'n_words': 183}