sharee.bike-App/SharedBusinessLogic.Tests/Services/TestServicesContainerMutable.cs
2024-04-09 12:53:23 +02:00

98 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using NUnit.Framework;
using ShareeBike.Services;
namespace SharedBusinessLogic.Tests.Services
{
[TestFixture]
public class TestServicesContainerMutable
{
[Test]
public void TestCtor()
{
var typeA = new MyTypeA();
var typeB = new MyTypeB();
var serviceContainer = new ServicesContainerMutableT<object>(
new List<object> { typeA, typeB, typeB },
typeA.GetType().FullName);
Assert.That(
serviceContainer,
Is.EqualTo(new List<object> { typeA, typeB }).AsCollection);
Assert.That(
serviceContainer.Active,
Is.EqualTo(typeA));
}
[Test]
public void TestSetActive()
{
var typeA = new MyTypeA();
var typeB = new MyTypeB();
var serviceContainer = new ServicesContainerMutableT<object>(
new List<object> { typeA, typeB },
typeA.GetType().FullName);
serviceContainer.SetActive(typeB.GetType().FullName);
Assert.That(
serviceContainer.Active,
Is.EqualTo(typeB));
}
[Test]
public void TestSetActiveNotExists()
{
var typeA = new MyTypeA();
var typeB = new MyTypeB();
var serviceContainer = new ServicesContainerMutableT<object>(
new List<object> { typeA, typeB },
typeA.GetType().FullName);
Assert.That(
() => serviceContainer.SetActive(new MyTypeC().GetType().FullName),
Throws.TypeOf<ArgumentException>());
}
private class MyTypeA { }
private class MyTypeB { }
private class MyTypeC { }
[Test]
public void TestCtor2()
{
var container = new ServicesContainerMutableT<object>(new List<object> { new MyTypeA(), new MyTypeB() }, typeof(MyTypeB).FullName);
Assert.That(container.Active.GetType().FullName, Is.EqualTo("SharedBusinessLogic.Tests.Services.TestServicesContainerMutable+MyTypeB"));
}
[Test]
public void TestCtorExceptionDupes()
{
Assert.That(() => new ServicesContainerMutableT<object>(new List<object> { new MyTypeA(), new MyTypeB(), new MyTypeA() }, typeof(MyTypeB).FullName), Throws.InstanceOf<Exception>());
}
[Test]
public void TestCtorExceptionActiveNotFound()
{
Assert.That(() => new ServicesContainerMutableT<object>(new List<object> { new MyTypeA(), new MyTypeB() }, "MyTypeF"), Throws.InstanceOf<ArgumentException>());
}
[Test]
public void TestSetActive2()
{
var container = new ServicesContainerMutableT<object>(new List<object> { new MyTypeA(), new MyTypeB() }, typeof(MyTypeB).FullName);
container.SetActive(typeof(MyTypeA).FullName);
Assert.That(container.Active.GetType().FullName, Is.EqualTo("SharedBusinessLogic.Tests.Services.TestServicesContainerMutable+MyTypeA"));
}
}
}