Steven Robbins is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this againTinyIoC / TinyIoC.Tests / TinyIoCFunctionalTests.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | //===============================================================================
// TinyIoC
//
// An easy to use, hassle free, Inversion of Control Container for small projects
// and beginners alike.
//
// http://hg.grumpydev.com/tinyioc
//===============================================================================
// Copyright © Steven Robbins. All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TinyIoC.Tests.TestData;
using TinyIoC.Tests.TestData.BasicClasses;
using NestedInterfaceDependencies = TinyIoC.Tests.TestData.NestedInterfaceDependencies;
using NestedClassDependencies = TinyIoC.Tests.TestData.NestedClassDependencies;
namespace TinyIoC.Tests
{
[TestClass]
public class TinyIoCFunctionalTests
{
[TestMethod]
public void NestedInterfaceDependencies_CorrectlyRegistered_ResolvesRoot()
{
var container = UtilityMethods.GetContainer();
container.Register<NestedInterfaceDependencies.IService1, NestedInterfaceDependencies.Service1>();
container.Register<NestedInterfaceDependencies.IService2, NestedInterfaceDependencies.Service2>();
container.Register<NestedInterfaceDependencies.IService3, NestedInterfaceDependencies.Service3>();
container.Register<NestedInterfaceDependencies.RootClass>();
var result = container.Resolve<NestedInterfaceDependencies.RootClass>();
Assert.IsInstanceOfType(result, typeof(NestedInterfaceDependencies.RootClass));
}
[TestMethod]
[ExpectedException(typeof(TinyIoCResolutionException))]
public void NestedInterfaceDependencies_MissingIService3Registration_ThrowsExceptionWithDefaultSettings()
{
var container = UtilityMethods.GetContainer();
container.Register<NestedInterfaceDependencies.IService1, NestedInterfaceDependencies.Service1>();
container.Register<NestedInterfaceDependencies.IService2, NestedInterfaceDependencies.Service2>();
container.Register<NestedInterfaceDependencies.RootClass>();
var result = container.Resolve<NestedInterfaceDependencies.RootClass>();
Assert.IsInstanceOfType(result, typeof(NestedInterfaceDependencies.RootClass));
}
[TestMethod]
public void NestedClassDependencies_CorrectlyRegistered_ResolvesRoot()
{
var container = UtilityMethods.GetContainer();
container.Register<NestedClassDependencies.Service1>();
container.Register<NestedClassDependencies.Service2>();
container.Register<NestedClassDependencies.Service3>();
container.Register<NestedClassDependencies.RootClass>();
var result = container.Resolve<NestedClassDependencies.RootClass>();
Assert.IsInstanceOfType(result, typeof(NestedClassDependencies.RootClass));
}
[TestMethod]
public void NestedClassDependencies_MissingService3Registration_ResolvesRootResolutionOn()
{
var container = UtilityMethods.GetContainer();
container.Register<NestedClassDependencies.Service1>();
container.Register<NestedClassDependencies.Service2>();
container.Register<NestedClassDependencies.RootClass>();
var result = container.Resolve<NestedClassDependencies.RootClass>(new ResolveOptions() { UnregisteredResolutionAction = UnregisteredResolutionActions.AttemptResolve });
Assert.IsInstanceOfType(result, typeof(NestedClassDependencies.RootClass));
}
[TestMethod]
[ExpectedException(typeof(TinyIoCResolutionException))]
public void NestedClassDependencies_MissingService3RegistrationAndUnRegisteredResolutionOff_ThrowsException()
{
var container = UtilityMethods.GetContainer();
container.Register<NestedClassDependencies.Service1>();
container.Register<NestedClassDependencies.Service2>();
container.Register<NestedClassDependencies.RootClass>();
var result = container.Resolve<NestedClassDependencies.RootClass>(new ResolveOptions() { UnregisteredResolutionAction = UnregisteredResolutionActions.Fail });
Assert.IsInstanceOfType(result, typeof(NestedClassDependencies.RootClass));
}
[TestMethod]
public void NestedInterfaceDependencies_JustAutoRegisterCalled_ResolvesRoot()
{
var container = UtilityMethods.GetContainer();
container.AutoRegister(this.GetType().Assembly);
var result = container.Resolve<NestedInterfaceDependencies.RootClass>();
Assert.IsInstanceOfType(result, typeof(NestedInterfaceDependencies.RootClass));
}
[TestMethod]
public void Dependency_Hierarchy_With_Named_Factories_Resolves_All_Correctly()
{
var container = UtilityMethods.GetContainer();
var mainView = new MainView();
container.Register<IViewManager>(mainView);
container.Register<IView, MainView>(mainView, "MainView");
container.Register<IView, SplashView>("SplashView").UsingConstructor(() => new SplashView());
container.Resolve<IView>("MainView");
container.Register<IStateManager, StateManager>();
var stateManager = container.Resolve<IStateManager>();
stateManager.Init();
Assert.IsInstanceOfType(mainView.LoadedView, typeof(SplashView));
}
}
}
|