Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/NugetPackage/UnityAutoMoqPlus.3.0.0.nupkg
Binary file not shown.
2 changes: 1 addition & 1 deletion src/UnityAutoMoq.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Infodoc AS")]
[assembly: AssemblyProduct("UnityAutoMoq.Test")]
[assembly: AssemblyCopyright("Copyright © Infodoc AS 2009")]
[assembly: AssemblyCopyright("Copyright (C) Thomas Pedersen, Raj Aththanayake")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
18 changes: 10 additions & 8 deletions src/UnityAutoMoq.Tests/UnityAutoMoq.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>UnityAutoMoq.Tests</RootNamespace>
<AssemblyName>UnityAutoMoq.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
Expand Down Expand Up @@ -49,6 +49,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -57,18 +58,19 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Practices.Unity, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Reference Include="Microsoft.Practices.Unity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Unity.2.1.505.0\lib\NET35\Microsoft.Practices.Unity.dll</HintPath>
<HintPath>..\packages\Unity.3.5.1404.0\lib\net45\Microsoft.Practices.Unity.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Practices.Unity.Configuration, Version=2.1.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Reference Include="Microsoft.Practices.Unity.Configuration, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Unity.2.1.505.0\lib\NET35\Microsoft.Practices.Unity.Configuration.dll</HintPath>
<HintPath>..\packages\Unity.3.5.1404.0\lib\net45\Microsoft.Practices.Unity.Configuration.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Practices.Unity.RegistrationByConvention">
<HintPath>..\packages\Unity.3.5.1404.0\lib\net45\Microsoft.Practices.Unity.RegistrationByConvention.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.0.10827.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down
309 changes: 160 additions & 149 deletions src/UnityAutoMoq.Tests/UnityAutoMoqContainerFixture.cs
Original file line number Diff line number Diff line change
@@ -1,150 +1,161 @@
using System;
using System.Web;
using NUnit.Framework;
using Moq;
using Microsoft.Practices.Unity;

namespace UnityAutoMoq.Tests
{
[TestFixture]
public class UnityAutoMoqContainerFixture
{
private UnityAutoMoqContainer container;

[SetUp]
public void SetUp()
{
container = new UnityAutoMoqContainer();
}

[Test]
public void Can_get_instance_without_registering_it_first()
{
var mocked = container.Resolve<IService>();

mocked.ShouldNotBeNull();
}

[Test]
public void Can_get_mock()
{
Mock<IService> mock = container.GetMock<IService>();

mock.ShouldNotBeNull();
}

[Test]
public void Mocked_object_and_resolved_instance_should_be_the_same()
{
Mock<IService> mock = container.GetMock<IService>();
var mocked = container.Resolve<IService>();

mock.Object.ShouldBeSameAs(mocked);
}

[Test]
public void Mocked_object_and_resolved_instance_should_be_the_same_order_independent()
{
var mocked = container.Resolve<IService>();
Mock<IService> mock = container.GetMock<IService>();

mock.Object.ShouldBeSameAs(mocked);
}

[Test]
public void Should_apply_default_default_value_when_none_specified()
{
container = new UnityAutoMoqContainer();
var mocked = container.GetMock<IService>();

mocked.DefaultValue.ShouldEqual(DefaultValue.Mock);
}

[Test]
public void Should_apply_specified_default_value_when_specified()
{
container = new UnityAutoMoqContainer(DefaultValue.Empty);
var mocked = container.GetMock<IService>();

mocked.DefaultValue.ShouldEqual(DefaultValue.Empty);
}

[Test]
public void Should_apply_specified_default_value_when_specified_2()
{
container = new UnityAutoMoqContainer{DefaultValue = DefaultValue.Empty};
var mocked = container.GetMock<IService>();

mocked.DefaultValue.ShouldEqual(DefaultValue.Empty);
}

[Test]
public void Can_resolve_concrete_type_with_dependency()
{
var concrete = container.Resolve<Service>();

concrete.ShouldNotBeNull();
concrete.AnotherService.ShouldNotBeNull();
}

[Test]
public void Getting_mock_after_resolving_concrete_type_should_return_the_same_mock_as_passed_as_argument_to_the_concrete()
{
var concrete = container.Resolve<Service>();
Mock<IAnotherService> mock = container.GetMock<IAnotherService>();

concrete.AnotherService.ShouldBeSameAs(mock.Object);
}

[Test]
public void Can_configure_mock_as_several_interfaces()
{
container.ConfigureMock<IService>().As<IDisposable>();

container.GetMock<IService>().As<IDisposable>();
}

[Test]
public void Can_configure_mock_as_several_interfaces_2()
{
container.ConfigureMock<IService>().As<IDisposable>().As<IAnotherService>();

container.GetMock<IService>().As<IDisposable>();
container.GetMock<IService>().As<IAnotherService>();
}

[Test]
public void Can_lazy_load_dependencies()
{
var service = container.Resolve<LazyService>();

Assert.That(service.ServiceFunc(), Is.InstanceOf<IService>());
}

[Test]
public void Can_mock_abstract_classes()
{
var mock = container.GetMock<HttpContextBase>();

mock.ShouldBeOfType<Mock<HttpContextBase>>();
}

[Test]
public void Can_inject_mocked_abstract_class()
{
var concrete = container.Resolve<ServiceWithAbstractDependency>();
var mock = container.GetMock<HttpContextBase>();

concrete.HttpContextBase.ShouldBeSameAs(mock.Object);
}

[Test]
public void Can_get_registered_implementation()
{
container.RegisterType<IAnotherService, AnotherService>();
var real = container.Resolve<IAnotherService>();

real.ShouldBeOfType<AnotherService>();
}
}
using System;
using System.Web;
using NUnit.Framework;
using Moq;
using Microsoft.Practices.Unity;

namespace UnityAutoMoq.Tests
{
[TestFixture]
public class UnityAutoMoqContainerFixture
{
private UnityAutoMoqContainer container;

[SetUp]
public void SetUp()
{
container = new UnityAutoMoqContainer();
}

[Test]
public void Can_get_instance_without_registering_it_first()
{
var mocked = container.Resolve<IService>();

mocked.ShouldNotBeNull();
}

[Test]
public void Can_get_mock()
{
Mock<IService> mock = container.GetMock<IService>();

mock.ShouldNotBeNull();
}

[Test]
public void Mocked_object_and_resolved_instance_should_be_the_same()
{
Mock<IService> mock = container.GetMock<IService>();
var mocked = container.Resolve<IService>();

mock.Object.ShouldBeSameAs(mocked);
}

[Test]
public void Mocked_object_and_resolved_instance_should_be_the_same_order_independent()
{
var mocked = container.Resolve<IService>();
Mock<IService> mock = container.GetMock<IService>();

mock.Object.ShouldBeSameAs(mocked);
}

[Test]
public void Should_apply_default_default_value_when_none_specified()
{
container = new UnityAutoMoqContainer();
var mocked = container.GetMock<IService>();

mocked.DefaultValue.ShouldEqual(DefaultValue.Mock);
}

[Test]
public void Should_apply_specified_default_value_when_specified()
{
container = new UnityAutoMoqContainer(DefaultValue.Empty);
var mocked = container.GetMock<IService>();

mocked.DefaultValue.ShouldEqual(DefaultValue.Empty);
}

[Test]
public void Should_apply_specified_default_value_when_specified_2()
{
container = new UnityAutoMoqContainer{DefaultValue = DefaultValue.Empty};
var mocked = container.GetMock<IService>();

mocked.DefaultValue.ShouldEqual(DefaultValue.Empty);
}

[Test]
public void Can_resolve_concrete_type_with_dependency()
{
var concrete = container.Resolve<Service>();

concrete.ShouldNotBeNull();
concrete.AnotherService.ShouldNotBeNull();
}

[Test]
public void Getting_mock_after_resolving_concrete_type_should_return_the_same_mock_as_passed_as_argument_to_the_concrete()
{
var concrete = container.Resolve<Service>();
Mock<IAnotherService> mock = container.GetMock<IAnotherService>();

concrete.AnotherService.ShouldBeSameAs(mock.Object);
}

[Test]
public void Can_configure_mock_as_several_interfaces()
{
container.ConfigureMock<IService>().As<IDisposable>();

container.GetMock<IService>().As<IDisposable>();
}

[Test]
public void Can_configure_mock_as_several_interfaces_2()
{
container.ConfigureMock<IService>().As<IDisposable>().As<IAnotherService>();

container.GetMock<IService>().As<IDisposable>();
container.GetMock<IService>().As<IAnotherService>();
}

[Test]
public void Can_lazy_load_dependencies()
{
var service = container.Resolve<LazyService>();

Assert.That(service.ServiceFunc(), Is.InstanceOf<IService>());
}

[Test]
public void Can_mock_abstract_classes()
{
var mock = container.GetMock<HttpContextBase>();

mock.ShouldBeOfType<Mock<HttpContextBase>>();
}

[Test]
public void Can_inject_mocked_abstract_class()
{
var concrete = container.Resolve<ServiceWithAbstractDependency>();
var mock = container.GetMock<HttpContextBase>();

concrete.HttpContextBase.ShouldBeSameAs(mock.Object);
}

[Test]
public void Can_get_registered_implementation()
{
container.RegisterType<IAnotherService, AnotherService>();
var real = container.Resolve<IAnotherService>();

real.ShouldBeOfType<AnotherService>();
}

[Test]
public void GetStubMethod_ShouldReturn_TheSameMockedInstance()
{
container = new UnityAutoMoqContainer(DefaultValue.Empty);
var mocked = container.GetMock<IService>();

var stub = container.GetStub<IService>();

mocked.Object.ShouldBeSameAs(stub.Object);
}
}
}
5 changes: 2 additions & 3 deletions src/UnityAutoMoq.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommonServiceLocator" version="1.0" />
<package id="Unity" version="2.1.505.0" />
<package id="Moq" version="4.0.10827" targetFramework="net45" />
<package id="NUnit" version="2.5.10.11092" />
<package id="Moq" version="4.0.10827" />
<package id="Unity" version="3.5.1404.0" targetFramework="net45" />
</packages>
13 changes: 13 additions & 0 deletions src/UnityAutoMoq.ncrunchsolution
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<SolutionConfiguration>
<FileVersion>0</FileVersion>
<AutoEnableOnStartup>Default</AutoEnableOnStartup>
<AllowParallelTestExecution>false</AllowParallelTestExecution>
<AllowTestsToRunInParallelWithThemselves>true</AllowTestsToRunInParallelWithThemselves>
<FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit>
<FrameworkUtilisationTypeForGallio>UseStaticAnalysis</FrameworkUtilisationTypeForGallio>
<FrameworkUtilisationTypeForMSpec>UseStaticAnalysis</FrameworkUtilisationTypeForMSpec>
<FrameworkUtilisationTypeForMSTest>UseStaticAnalysis</FrameworkUtilisationTypeForMSTest>
<EngineModes>Run all tests automatically:BFRydWU=;Run all tests manually:BUZhbHNl;Run impacted tests automatically, others manually (experimental!):CklzSW1wYWN0ZWQ=;Run pinned tests automatically, others manually:CElzUGlubmVk</EngineModes>
<MetricsExclusionList>
</MetricsExclusionList>
</SolutionConfiguration>
Loading