<commit_before>﻿//
// NProxy is a library for the .NET framework to create lightweight dynamic proxies.
// Copyright © 2012 <NAME>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
using System;
using NProxy.Core.Interceptors;
using NProxy.Core.Test.Interceptors.Types;
using NUnit.Framework;

namespace NProxy.Core.Test.Interceptors
{
    [TestFixture]
    public sealed class ProxyFactoryTestFixture
    {
        private ProxyFactory _proxyFactory;

        [TestFixtureSetUp]
        public void SetUp()
        {
            _proxyFactory = new ProxyFactory();
        }

        [Test]
        public void NewProxyFromInterfaceWithMixinTest()
        {
            // Arrange
            // Act
            var proxy = _proxyFactory.NewProxy<IVoidMethod>()
                .Extends<Mixin>()
                .Targets<VoidMethod>();

            // Assert
            Assert.That(proxy, Is.InstanceOf<IVoidMethod>());
            Assert.DoesNotThrow(() => proxy.Method());

            Assert.That(proxy, Is.InstanceOf<IMixin>());
            var mixin = (IMixin) proxy;

            Assert.DoesNotThrow(() => mixin.Method());
        }

        [Test]
        public void NewProxyFromAbstractClassWithMixinTest()
        {
            // Arrange
            // Act
            var proxy = _proxyFactory.NewProxy<VoidMethodBase>()
                .Extends<Mixin>()
                .Targets<VoidMethod>();

            // Assert
            Assert.That(proxy, Is.InstanceOf<VoidMethodBase>());
            Assert.DoesNotThrow(() => proxy.Method());

            Assert.That(proxy, Is.InstanceOf<IMixin>());
            var mixin = (IMixin) proxy;

            Assert.DoesNotThrow(() => mixin.Method());
        }

        [Test]
        public void NewProxyFromClassWithMixinTest()
        {
            // Arrange
            // Act
            var proxy = _proxyFactory.NewProxy<VoidMethod>()
                .Extends<Mixin>()
                .Targets<VoidMethod>();

            // Assert
            Assert.That(proxy, Is.InstanceOf<VoidMethod>());
            Assert.DoesNotThrow(() => proxy.Method());

            Assert.That(proxy, Is.InstanceOf<IMixin>());
            var mixin = (IMixin) proxy;

            Assert.DoesNotThrow(() => mixin.Method());
        }

        [Test]
        public void NewProxyFromDelegateWithMixinTest()
        {
            // Arrange
            // Act
            Action proxy = _proxyFactory.NewProxy<Action>()
                .Extends<Mixin>()
                .Targets(() => {});

            // Assert
            Assert.That(proxy, Is.InstanceOf<Action>());
            Assert.DoesNotThrow(() => proxy());

            Assert.That(proxy.Target, Is.InstanceOf<IMixin>());
            var mixin = (IMixin) proxy.Target;

            Assert.DoesNotThrow(() => mixin.Method());
        }

        [Test]
        public void NewProxyWithLazyInterceptorTest()
        {
            // Arrange
            var employee = _proxyFactory.NewProxy<IEmployee>()
                .Extends<LazyMixin>()
                .Targets<Employee>();

            // Act
            employee.Name = "2";

            // Assert
            Assert.That(employee, Is.InstanceOf<IEmployee>());
            Assert.That(employee.Name, Is.EqualTo("2"));

            Assert.That(employee, Is.InstanceOf<ILazy>());
            var lazy = (ILazy) employee;

            Assert.That(lazy.Loaded, Is.EqualTo(true));
        }<commit_msg>Minor changes.<commit_after>﻿//
// NProxy is a library for the .NET framework to create lightweight dynamic proxies.
// Copyright © 2012 <NAME>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
using System;
using NProxy.Core.Interceptors;
using NProxy.Core.Test.Interceptors.Types;
using NUnit.Framework;

namespace NProxy.Core.Test.Interceptors
{
    [TestFixture]
    public sealed class ProxyFactoryTestFixture
    {
        private ProxyFactory _proxyFactory;

        [TestFixtureSetUp]
        public void SetUp()
        {
            _proxyFactory = new ProxyFactory();
        }

        [Test]
        public void NewProxyFromInterfaceWithMixinTest()
        {
            // Arrange
            // Act
            var proxy = _proxyFactory.NewProxy<IVoidMethod>()
                .Extends<Mixin>()
                .Targets<VoidMethod>();

            // Assert
            Assert.That(proxy, Is.InstanceOf<IVoidMethod>());
            Assert.DoesNotThrow(() => proxy.Method());

            Assert.That(proxy, Is.InstanceOf<IMixin>());
            var mixin = (IMixin) proxy;

            Assert.DoesNotThrow(() => mixin.Method());
        }

        [Test]
        public void NewProxyFromAbstractClassWithMixinTest()
        {
            // Arrange
            // Act
            var proxy = _proxyFactory.NewProxy<VoidMethodBase>()
                .Extends<Mixin>()
                .Targets<VoidMethod>();

            // Assert
            Assert.That(proxy, Is.InstanceOf<VoidMethodBase>());
            Assert.DoesNotThrow(() => proxy.Method());

            Assert.That(proxy, Is.InstanceOf<IMixin>());
            var mixin = (IMixin) proxy;

            Assert.DoesNotThrow(() => mixin.Method());
        }

        [Test]
        public void NewProxyFromClassWithMixinTest()
        {
            // Arrange
            // Act
            var proxy = _proxyFactory.NewProxy<VoidMethod>()
                .Extends<Mixin>()
                .Targets<VoidMethod>();

            // Assert
            Assert.That(proxy, Is.InstanceOf<VoidMethod>());
            Assert.DoesNotThrow(() => proxy.Method());

            Assert.That(proxy, Is.InstanceOf<IMixin>());
            var mixin = (IMixin) proxy;

            Assert.DoesNotThrow(() => mixin.Method());
        }

        [Test]
        public void NewProxyFromDelegateWithMixinTest()
        {
            // Arrange
            // Act
            Action proxy = _proxyFactory.NewProxy<Action>()
                .Extends<Mixin>()
                .Targets(() => {});

            // Assert
            Assert.That(proxy, Is.InstanceOf<Action>());
            Assert.DoesNotThrow(() => proxy());

            Assert.That(proxy.Target, Is.InstanceOf<IMixin>());
            var mixin = (IMixin) proxy.Target;

            Assert.DoesNotThrow(() => mixin.Method());
        }

        [Test]
        public void NewProxyWithLazyInterceptorTest()
        {
            // Arrange
            var employee = _proxyFactory.NewProxy<IEmployee>()
                .Extends<LazyMixin>()
                .Targets<Employee>();

            // Act
            employee.Name = "Saturnus";

            // Assert
            Assert.That(employee, Is.InstanceOf<IEmployee>());
            Assert.That(employee.Name, Is.EqualTo("Saturnus"));

            Assert.That(employee, Is.InstanceOf<ILazy>());
            var lazy = (ILazy) employee;

            Assert.That(lazy.Loaded, Is.EqualTo(true));
        }
{'fraction_non_alphanumeric': 0.11726504104889107, 'fraction_numerical': 0.001470408038230609, 'mean_word_length': 1.8330440819160014, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7250342', 'n_tokens_mistral': 2201, 'n_tokens_neox': 2125, 'n_words': 535}