<commit_before>﻿using System;
using NUnit.Framework;

namespace Demo.WorkingWithLegacyCode.UnitTests.Ch10CannotRunMethodInTestHarnessTests
{
    [TestFixture]
    public class given_a_method_with_static_third_party_dependent
    {
        [Test]
        public void when_testing_can_use_skin_and_wrapper_method()
        {
            new ClassWithMethodWithStaticDependent().MethodWithStaticDependentWithMethodInjection(new FakeDateTimeProvider(new DateTime(2014, 1, 1)));   
        }
    }

    public class ClassWithMethodWithStaticDependent
    {
        public void MethodWithStaticDependent()
        {
            if (DateTime.Now == new DateTime(2014, 1, 1))
                Console.WriteLine("We have a matching date.");
        }

        public void MethodWithStaticDependentWithMethodInjection(IDateTimeProvider provider)
        {
            if (provider.GetCurrentDateTime() == new DateTime(2014, 1, 1))<commit_msg>Adding other forms of skin and wrap for static classes.<commit_after>﻿using System;
using System.Diagnostics.Eventing.Reader;
using NUnit.Framework;

namespace Demo.WorkingWithLegacyCode.UnitTests.Ch10CannotRunMethodInTestHarnessTests
{
    [TestFixture]
    public class given_a_method_with_static_third_party_dependent
    {
        [Test]
        public void when_testing_can_use_skin_and_wrapper_method()
        {
            new ClassWithMethodWithStaticDependentUsingMethodInjection().MethodWithStaticDependent(new FakeDateTimeProvider(new DateTime(2014, 1, 1)));
            
            new ClassWithMethodWithStaticDependentUsingPropertyInjection
            {
                GetCurrentDate = () => new DateTime(2014, 1, 1)
            }.MethodWithStaticDependent();

            new ClassWithMethodWithStaticDependentUsingConstructorInjection(new FakeDateTimeProvider(new DateTime(2014, 1, 1))).MethodWithStaticDependent();
        }
    }

    public class ClassWithMethodWithStaticDependentUsingMethodInjection
    {
        public void MethodWithStaticDependent()
        {
            MethodWithStaticDependent(new DateTimeWrapper());
        }

        public void MethodWithStaticDependent(IDateTimeProvider provider)
        {
            if (provider.GetCurrentDateTime() == new DateTime(2014, 1, 1))
                Console.WriteLine("We have a matching date.");
        }
    }

    public class ClassWithMethodWithStaticDependentUsingPropertyInjection
    {
        public ClassWithMethodWithStaticDependentUsingPropertyInjection()
        {
            GetCurrentDate = GetCurrentDateLocalDefault;
        }

        public void MethodWithStaticDependent()
        {
            if (GetCurrentDate() == new DateTime(2014, 1, 1))
                Console.WriteLine("We have a matching date.");
        }

        public Func<DateTime> GetCurrentDate { get; set; }

        private DateTime GetCurrentDateLocalDefault()
        {
            return DateTime.Now;
        }
    }

    public class ClassWithMethodWithStaticDependentUsingConstructorInjection
    {
        private readonly IDateTimeProvider _provider;

        public ClassWithMethodWithStaticDependentUsingConstructorInjection(IDateTimeProvider provider)
        {
            _provider = provider;
        }

        public void MethodWithStaticDependent()
        {
            if (_provider.GetCurrentDateTime() == new DateTime(2014, 1, 1))
{'fraction_non_alphanumeric': 0.06813448378458792, 'fraction_numerical': 0.017256768818803926, 'mean_word_length': 2.8912037037037037, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, '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': '3757486', 'n_tokens_mistral': 901, 'n_tokens_neox': 834, 'n_words': 166}