<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Moq;

namespace AutoMoq
{
    public class AutoMoqTestFixture<T> where T: class
    {
        /// <summary>
        /// The Class being tested in this Test Fixture.
        /// </summary>
        public T Subject { get; private set; }

        private AutoMoqer _moqer = new AutoMoqer();
        
        public AutoMoqTestFixture()
        {
            Subject = _moqer.Resolve<T>();
        }

        /// <summary>
        /// A Mock dependency that was auto-injected into Subject
        /// </summary>
        /// <typeparam name="TMock"></typeparam>
        /// <returns></returns>
        public Mock<TMock> Mocked<TMock>() where TMock : class
        {
            return _moqer.GetMock<TMock>();
        }

        /// <summary>
        /// A depenency that was auto-injected into Subject.  Implementation is a Moq object.
        /// </summary>
        /// <typeparam name="TDepend"></typeparam>
        /// <returns></returns>
        public TDepend Dependency<TDepend>() where TDepend : class
        {
            return Mocked<TDepend>().Object;
        }

        /// <summary>
        /// Resets Subject instance.  A new instance will be created, with new depenencies auto-injected.
        /// Call this from NUnit's [SetUp] method, if you want each of your tests in the fixture to have a fresh instance of <typeparamref name="T"/>
        /// </summary>
        public void ResetSubject()
        {
            _moqer = new AutoMoqer();
            Subject = _moqer.Resolve<T>();
        }
    }
}
<commit_msg>'Subject' is lazy loaded rather than resolved on ctor.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Moq;

namespace AutoMoq
{
    public class AutoMoqTestFixture<T> where T: class
    {
        private AutoMoqer _moqer = new AutoMoqer();
        private T _subject;

        /// <summary>
        /// A Mock dependency that was auto-injected into Subject
        /// </summary>
        /// <typeparam name="TMock"></typeparam>
        /// <returns></returns>
        public Mock<TMock> Mocked<TMock>() where TMock : class
        {
            return _moqer.GetMock<TMock>();
        }

        /// <summary>
        /// A depenency that was auto-injected into Subject.  Implementation is a Moq object.
        /// </summary>
        /// <typeparam name="TDepend"></typeparam>
        /// <returns></returns>
        public TDepend Dependency<TDepend>() where TDepend : class
        {
            return Mocked<TDepend>().Object;
        }

        /// <summary>
        /// Resets Subject instance.  A new instance will be created, with new depenencies auto-injected.
        /// Call this from NUnit's [SetUp] method, if you want each of your tests in the fixture to have a fresh instance of <typeparamref name="T"/>
        /// </summary>
        public void ResetSubject()
        {
            _moqer = new AutoMoqer();
            _subject = null;
        }

        /// <summary>
        /// The Class being tested in this Test Fixture.
        /// </summary>
        /// 
        public T Subject
        {
            get { return _subject ?? (_subject = _moqer.Resolve<T>()); }
        }
    }
}

{'fraction_non_alphanumeric': 0.12042360060514372, 'fraction_numerical': 0.0, 'mean_word_length': 1.789873417721519, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 52, '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': '952472', 'n_tokens_mistral': 924, 'n_tokens_neox': 915, 'n_words': 281}