A game framework written with osu! in mind.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2// See the LICENCE file in the repository root for full licence text.
3
4using System;
5using System.Collections.Generic;
6using NUnit.Framework;
7using osu.Framework.Graphics;
8using osu.Framework.Graphics.Containers;
9using osu.Framework.Graphics.Shapes;
10
11namespace osu.Framework.Tests.Containers
12{
13 [TestFixture]
14 public class ContainerEnumerableTest
15 {
16 /// <summary>
17 /// Ensures that adding container as an enumerable of drawables to another container results in an exception.
18 /// Tests with a regular <see cref="Container{T}"/>, and an <see cref="AudioContainer{T}"/> which doesn't directly inherit from <see cref="Container{T}"/>.
19 /// </summary>
20 [TestCase(typeof(Container))]
21 [TestCase(typeof(Container<Drawable>))]
22 [TestCase(typeof(Container<Box>))]
23 [TestCase(typeof(AudioContainer))]
24 [TestCase(typeof(AudioContainer<Drawable>))]
25 [TestCase(typeof(AudioContainer<Box>))]
26 public void TestAddingContainerAsEnumerableRangeThrows(Type containerType)
27 {
28 Assert.Throws<InvalidOperationException>(() =>
29 {
30 var unused = new Container
31 {
32 Children = (IReadOnlyList<Drawable>)Activator.CreateInstance(containerType)
33 };
34 });
35
36 Assert.Throws<InvalidOperationException>(() =>
37 {
38 var unused = new Container();
39
40 unused.AddRange((IEnumerable<Drawable>)Activator.CreateInstance(containerType));
41 });
42
43 Assert.Throws<InvalidOperationException>(() =>
44 {
45 var unused = new AudioContainer
46 {
47 Children = (IReadOnlyList<Drawable>)Activator.CreateInstance(containerType)
48 };
49 });
50
51 Assert.Throws<InvalidOperationException>(() =>
52 {
53 var unused = new AudioContainer();
54
55 unused.AddRange((IEnumerable<Drawable>)Activator.CreateInstance(containerType));
56 });
57 }
58 }
59}