sharee.bike-App/TestShareeLib/Services/TestServicesContainerMutable.cs

99 lines
2.5 KiB
C#
Raw Normal View History

2023-04-05 15:02:10 +02:00
using System;
2021-05-13 20:09:46 +02:00
using System.Collections.Generic;
2022-08-30 15:42:25 +02:00
using NUnit.Framework;
2021-05-13 20:09:46 +02:00
using TINK.Services;
namespace TestShareeLib.Services
{
2022-09-06 16:08:19 +02:00
[TestFixture]
public class TestServicesContainerMutable
{
[Test]
public void TestCtor()
{
var typeA = new MyTypeA();
var typeB = new MyTypeB();
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
var serviceContainer = new ServicesContainerMutableT<object>(
new List<object> { typeA, typeB, typeB },
typeA.GetType().FullName);
2022-08-30 15:42:25 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
serviceContainer,
Is.EqualTo(new List<object> { typeA, typeB }).AsCollection);
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
serviceContainer.Active,
Is.EqualTo(typeA));
}
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestSetActive()
{
var typeA = new MyTypeA();
var typeB = new MyTypeB();
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
var serviceContainer = new ServicesContainerMutableT<object>(
new List<object> { typeA, typeB },
typeA.GetType().FullName);
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
serviceContainer.SetActive(typeB.GetType().FullName);
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
serviceContainer.Active,
Is.EqualTo(typeB));
}
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
[Test]
public void TestSetActiveNotExists()
{
var typeA = new MyTypeA();
var typeB = new MyTypeB();
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
var serviceContainer = new ServicesContainerMutableT<object>(
new List<object> { typeA, typeB },
typeA.GetType().FullName);
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
Assert.That(
() => serviceContainer.SetActive(new MyTypeC().GetType().FullName),
Throws.TypeOf<ArgumentException>());
}
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
private class MyTypeA { }
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
private class MyTypeB { }
2021-05-13 20:09:46 +02:00
2022-09-06 16:08:19 +02:00
private class MyTypeC { }
2023-04-05 15:02:10 +02:00
[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("TestShareeLib.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("TestShareeLib.Services.TestServicesContainerMutable+MyTypeA"));
}
2022-09-06 16:08:19 +02:00
}
2021-05-13 20:09:46 +02:00
}