RecorderControllerTests.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using NUnit.Framework;
  3. using UnityEditor.Recorder;
  4. namespace UnityEngine.Recorder.Tests
  5. {
  6. class RecorderControllerTests
  7. {
  8. [Test]
  9. public void PrepareRecording_WithNullSettings_ThrowsException()
  10. {
  11. var recorderController = new RecorderController(null);
  12. var ex = Assert.Throws<NullReferenceException>(() => recorderController.PrepareRecording());
  13. Assert.IsTrue(ex.Message.Contains("Can start recording without prefs"));
  14. }
  15. [Test]
  16. public void StartRecording_WithEmptySettings_ShouldNotStartRecording()
  17. {
  18. var settings = ScriptableObject.CreateInstance<RecorderControllerSettings>();
  19. var recorderController = new RecorderController(settings);
  20. recorderController.PrepareRecording();
  21. Assert.IsFalse(recorderController.StartRecording());
  22. Assert.IsFalse(recorderController.IsRecording());
  23. Object.DestroyImmediate(settings);
  24. }
  25. [Test]
  26. public void StartAndStopRecording_WithValidSettings_ShouldStartThenStopRecording()
  27. {
  28. var settings = ScriptableObject.CreateInstance<RecorderControllerSettings>();
  29. var imageRecorder = ScriptableObject.CreateInstance<ImageRecorderSettings>();
  30. settings.AddRecorderSettings(imageRecorder);
  31. var recorderController = new RecorderController(settings);
  32. recorderController.PrepareRecording();
  33. Assert.IsTrue(recorderController.StartRecording());
  34. Assert.IsTrue(recorderController.IsRecording());
  35. recorderController.StopRecording();
  36. Assert.IsFalse(recorderController.IsRecording());
  37. Object.DestroyImmediate(imageRecorder);
  38. Object.DestroyImmediate(settings);
  39. }
  40. }
  41. }