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

69 lines
1.4 KiB
C#
Raw Normal View History

2022-08-30 15:42:25 +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 { }
}
2021-05-13 20:09:46 +02:00
}