1
0

ComponentStateNullTest.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using NUnit.Framework;
  5. using Robust.Shared.ContentPack;
  6. using Robust.Shared.GameObjects;
  7. using Robust.Shared.Reflection;
  8. namespace Content.Tests.Shared.Gamestates
  9. {
  10. [TestFixture]
  11. public sealed class ComponentStateNullTest
  12. {
  13. [Test]
  14. public void HandleComponentState_NullStates_NotThrow()
  15. {
  16. var reflection = ReflectionManagerFactory();
  17. var comps = reflection.GetAllChildren<Component>();
  18. foreach (var compType in comps)
  19. {
  20. // Any component should be able to be instantiated without DI injection.
  21. _ = (IComponent) Activator.CreateInstance(compType);
  22. }
  23. }
  24. private static IReflectionManager ReflectionManagerFactory()
  25. {
  26. AppDomain.CurrentDomain.Load("Robust.Client");
  27. AppDomain.CurrentDomain.Load("Content.Client");
  28. AppDomain.CurrentDomain.Load("Robust.Server");
  29. AppDomain.CurrentDomain.Load("Content.Server");
  30. AppDomain.CurrentDomain.Load("Robust.Shared");
  31. AppDomain.CurrentDomain.Load("Content.Shared");
  32. var assemblies = new List<Assembly>(7);
  33. assemblies.Add(AppDomain.CurrentDomain.GetAssemblyByName("Robust.Client"));
  34. assemblies.Add(AppDomain.CurrentDomain.GetAssemblyByName("Content.Client"));
  35. assemblies.Add(AppDomain.CurrentDomain.GetAssemblyByName("Robust.Server"));
  36. assemblies.Add(AppDomain.CurrentDomain.GetAssemblyByName("Content.Server"));
  37. assemblies.Add(AppDomain.CurrentDomain.GetAssemblyByName("Robust.Shared"));
  38. assemblies.Add(AppDomain.CurrentDomain.GetAssemblyByName("Content.Shared"));
  39. assemblies.Add(Assembly.GetExecutingAssembly());
  40. var reflection = new FullReflectionManager();
  41. reflection.LoadAssemblies(assemblies);
  42. return reflection;
  43. }
  44. private sealed class FullReflectionManager : ReflectionManager
  45. {
  46. protected override IEnumerable<string> TypePrefixes => Prefixes;
  47. private static readonly string[] Prefixes = {
  48. "",
  49. "Robust.Client.",
  50. "Content.Client.",
  51. "Robust.Shared.",
  52. "Content.Shared.",
  53. "Robust.Server.",
  54. "Content.Server.",
  55. };
  56. }
  57. }
  58. }