1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-14 04:55:42 +00:00
X10D/X10D.Unity.Tests/Assets/Tests/ComponentTests.cs

32 lines
872 B
C#
Raw Normal View History

2022-05-08 12:09:30 +01:00
#nullable enable
using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using Object = UnityEngine.Object;
2022-05-08 12:09:30 +01:00
namespace X10D.Unity.Tests
2022-05-08 12:09:30 +01:00
{
public class ComponentTests
{
[Test]
public void GetComponentsInChildrenOnly_ShouldIgnoreParent()
2022-05-08 12:09:30 +01:00
{
var parent = new GameObject();
var rigidbody = parent.AddComponent<Rigidbody>();
var child = new GameObject();
child.transform.SetParent(parent.transform);
2022-05-08 12:09:30 +01:00
child.AddComponent<Rigidbody>();
Rigidbody[] components = rigidbody.GetComponentsInChildrenOnly<Rigidbody>();
Assert.That(components, Has.Length.EqualTo(1));
Assert.That(child, Is.EqualTo(components[0].gameObject));
2022-05-08 12:09:30 +01:00
Object.Destroy(parent);
Object.Destroy(child);
}
2022-05-08 12:09:30 +01:00
}
}