diff --git a/Testing/VelaptorTests/OpenGL/Shaders/LineShaderTests.cs b/Testing/VelaptorTests/OpenGL/Shaders/LineShaderTests.cs index 1ba9fb1bb..3094e0713 100644 --- a/Testing/VelaptorTests/OpenGL/Shaders/LineShaderTests.cs +++ b/Testing/VelaptorTests/OpenGL/Shaders/LineShaderTests.cs @@ -10,7 +10,7 @@ namespace VelaptorTests.OpenGL.Shaders; using Carbonate.NonDirectional; using Carbonate.OneWay; using FluentAssertions; -using Moq; +using NSubstitute; using Velaptor; using Velaptor.Factories; using Velaptor.NativeInterop.OpenGL; @@ -23,12 +23,12 @@ namespace VelaptorTests.OpenGL.Shaders; public class LineShaderTests { - private readonly Mock mockGL; - private readonly Mock mockGLService; - private readonly Mock mockShaderLoader; - private readonly Mock mockReactableFactory; - private readonly Mock> mockBatchSizeReactable; - private readonly Mock batchSizeUnsubscriber; + private readonly IGLInvoker mockGL; + private readonly IOpenGLService mockGLService; + private readonly IShaderLoaderService mockShaderLoader; + private readonly IReactableFactory mockReactableFactory; + private readonly IPushReactable mockBatchSizeReactable; + private readonly IDisposable batchSizeUnsubscriber; private IReceiveSubscription? batchSizeReactor; /// @@ -36,28 +36,30 @@ public class LineShaderTests /// public LineShaderTests() { - this.mockGL = new Mock(); - this.mockGLService = new Mock(); - this.mockShaderLoader = new Mock(); + this.mockGL = Substitute.For(); + this.mockGLService = Substitute.For(); + this.mockShaderLoader = Substitute.For(); - this.batchSizeUnsubscriber = new Mock(); + this.batchSizeUnsubscriber = Substitute.For(); - var mockPushReactable = new Mock(); - mockPushReactable.Setup(m => m.Subscribe(It.IsAny())) - .Returns(_ => new Mock().Object); + var mockPushReactable = Substitute.For(); + mockPushReactable.Subscribe(Arg.Any()) + .Returns(_ => Substitute.For()); - this.mockBatchSizeReactable = new Mock>(); - this.mockBatchSizeReactable.Setup(m => m.Subscribe(It.IsAny>())) - .Returns(() => this.batchSizeUnsubscriber.Object) - .Callback>(reactor => + this.mockBatchSizeReactable = Substitute.For>(); + this.mockBatchSizeReactable.Subscribe(Arg.Any>()) + .Returns(_ => this.batchSizeUnsubscriber); + this.mockBatchSizeReactable.When(x => x.Subscribe(Arg.Any>())) + .Do(callInfo => { + var reactor = callInfo.Arg>(); reactor.Should().NotBeNull("It is required for unit testing."); this.batchSizeReactor = reactor; }); - this.mockReactableFactory = new Mock(); - this.mockReactableFactory.Setup(m => m.CreateNoDataPushReactable()).Returns(mockPushReactable.Object); - this.mockReactableFactory.Setup(m => m.CreateBatchSizeReactable()).Returns(this.mockBatchSizeReactable.Object); + this.mockReactableFactory = Substitute.For(); + this.mockReactableFactory.CreateNoDataPushReactable().Returns(mockPushReactable); + this.mockReactableFactory.CreateBatchSizeReactable().Returns(this.mockBatchSizeReactable); } #region Constructor Tests @@ -68,9 +70,9 @@ public void Ctor_WithNullReactableFactoryParam_ThrowsException() var act = () => { _ = new LineShader( - new Mock().Object, - new Mock().Object, - new Mock().Object, + Substitute.For(), + Substitute.For(), + Substitute.For(), null); }; @@ -119,9 +121,10 @@ public void BatchSizeReactable_WhenReceivingBatchSizeNotification_SetsBatchSize( public void BatchSizeReactable_WhenCreatingSubscription_CreatesSubscriptionCorrectly() { // Arrange & Act & Assert - this.mockBatchSizeReactable.Setup(m => m.Subscribe(It.IsAny>())) - .Callback>(reactor => + this.mockBatchSizeReactable.When(x => x.Subscribe(Arg.Any>())) + .Do(callInfo => { + var reactor = callInfo.Arg>(); reactor.Should().NotBeNull("It is required for unit testing."); this.batchSizeReactor = reactor; reactor.Name.Should().Be($"LineShader.ctor() - {PushNotifications.BatchSizeChangedId}"); @@ -140,7 +143,7 @@ public void BatchSizeReactable_WhenUnsubscribingGlInit_Unsubscribes() this.batchSizeReactor.OnUnsubscribe(); // Assert - this.batchSizeUnsubscriber.Verify(m => m.Dispose(), Times.Once); + this.batchSizeUnsubscriber.Received(1).Dispose(); } #endregion @@ -149,8 +152,8 @@ public void BatchSizeReactable_WhenUnsubscribingGlInit_Unsubscribes() /// /// The instance to test. private LineShader CreateSystemUnderTest() - => new (this.mockGL.Object, - this.mockGLService.Object, - this.mockShaderLoader.Object, - this.mockReactableFactory.Object); + => new (this.mockGL, + this.mockGLService, + this.mockShaderLoader, + this.mockReactableFactory); }