Skip to content

Commit

Permalink
increase coverage unit tests, fix grammar naming
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxymGorn committed Oct 22, 2023
1 parent 8e937a0 commit 694c479
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 101 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ And then use it in Razor file ([for example](https://github.com/CropperBlazor/Cr
IsErrorLoadImage="@IsErrorLoadImage"
OnErrorLoadImageEvent="OnErrorLoadImageEvent"
Options="Options"
IsAvaibleInitCropper="IsAvaibleInitCropper">
IsAvailableInitCropper="IsAvailableInitCropper">
</CropperComponent>
```

Expand Down
2 changes: 1 addition & 1 deletion src/Cropper.Blazor/Client/Pages/CropperDemo.razor
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
IsErrorLoadImage="@IsErrorLoadImage"
OnErrorLoadImageEvent="OnErrorLoadImageEvent"
Options="Options"
IsAvaibleInitCropper="IsAvaibleInitCropper" />
IsAvailableInitCropper="IsAvailableInitCropper" />
</div>
</MudPaper>
</MudItem>
Expand Down
14 changes: 7 additions & 7 deletions src/Cropper.Blazor/Client/Pages/CropperDemo.razor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Cropper.Blazor.Client.Components;
using System.Reflection;
using System.Text.Json;
using Cropper.Blazor.Client.Components;
using Cropper.Blazor.Client.Enums;
using Cropper.Blazor.Components;
using Cropper.Blazor.Events;
Expand All @@ -14,8 +16,6 @@
using Microsoft.JSInterop;
using MudBlazor;
using MudBlazor.Services;
using System.Reflection;
using System.Text.Json;
using ErrorEventArgs = Microsoft.AspNetCore.Components.Web.ErrorEventArgs;

namespace Cropper.Blazor.Client.Pages
Expand All @@ -38,7 +38,7 @@ public partial class CropperDemo : IDisposable

private string Src = "https://fengyuanchen.github.io/cropperjs/v2/picture.jpg";
private bool IsErrorLoadImage { get; set; } = false;
private bool IsAvaibleInitCropper { get; set; } = true;
private bool IsAvailableInitCropper { get; set; } = true;
private readonly string _errorLoadImageSrc = "not-found-image.jpg";
private Breakpoint Start;
private Guid SubscriptionId;
Expand Down Expand Up @@ -392,7 +392,7 @@ public async Task InputFileChangeAsync(InputFileChangeEventArgs inputFileChangeE

Src = await CropperComponent!.GetImageUsingStreamingAsync(imageFile, imageFile.Size);

IsAvaibleInitCropper = true;
IsAvailableInitCropper = true;
IsErrorLoadImage = false;

CropperComponent?.Destroy();
Expand All @@ -411,12 +411,12 @@ public async Task ReplaceImageAsync(InputFileChangeEventArgs inputFileChangeEven

if (IsErrorLoadImage)
{
IsAvaibleInitCropper = true;
IsAvailableInitCropper = true;
IsErrorLoadImage = false;
}
else
{
IsAvaibleInitCropper = false;
IsAvailableInitCropper = false;
}

CropperComponent?.ReplaceAsync(src);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ public async Task Should_Render_CropperComponent_SuccessfulAsync()
ComponentParameter isErrorLoadImageParameter = ComponentParameter.CreateParameter(
nameof(CropperComponent.IsErrorLoadImage),
false);
ComponentParameter isAvaibleInitCropperParameter = ComponentParameter.CreateParameter(
nameof(CropperComponent.IsAvaibleInitCropper),
ComponentParameter isAvailableInitCropperParameter = ComponentParameter.CreateParameter(
nameof(CropperComponent.IsAvailableInitCropper),
true);
ComponentParameter onLoadImageParameter = ComponentParameter.CreateParameter(
nameof(CropperComponent.OnLoadImageEvent),
Expand Down Expand Up @@ -347,7 +347,7 @@ public async Task Should_Render_CropperComponent_SuccessfulAsync()
loadingParameter,
errorLoadImageSrcParameter,
isErrorLoadImageParameter,
isAvaibleInitCropperParameter,
isAvailableInitCropperParameter,
srcParameter,
imageClassParameter,
onLoadImageParameter,
Expand Down Expand Up @@ -597,8 +597,8 @@ public void Should_Not_Render_CropperComponent_With_IsNotAvaibleInitCropper_Para
ComponentParameter isErrorLoadImage = ComponentParameter.CreateParameter(
nameof(CropperComponent.IsErrorLoadImage),
true);
ComponentParameter isAvaibleInitCropperParameter = ComponentParameter.CreateParameter(
nameof(CropperComponent.IsAvaibleInitCropper),
ComponentParameter isAvailableInitCropperParameter = ComponentParameter.CreateParameter(
nameof(CropperComponent.IsAvailableInitCropper),
false);

// act
Expand All @@ -608,7 +608,7 @@ public void Should_Not_Render_CropperComponent_With_IsNotAvaibleInitCropper_Para
loadingParameter,
errorLoadImageSrcParameter,
isErrorLoadImage,
isAvaibleInitCropperParameter);
isAvailableInitCropperParameter);

// assert
IElement expectedElement = cropperComponent.Find($"img.{errorLoadImageClass}");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bogus;
using System.Collections.Generic;
using Bogus;
using Microsoft.JSInterop;
using Moq;
using Xunit;
Expand All @@ -8,24 +9,37 @@ namespace Cropper.Blazor.UnitTests.Events.CropEndEvent
{
public class CropEndEvent_Should
{
private readonly Mock<IJSObjectReference> _mockIJSObjectReference;
private readonly Event _event;
private static Mock<IJSObjectReference> _mockIJSObjectReference = null!;

public CropEndEvent_Should()
[Theory, MemberData(nameof(TestData_Verify_Dispose))]
public void Verify_Dispose(IJSObjectReference? jSObjectReference, Times times)
{
_mockIJSObjectReference = new Mock<IJSObjectReference>();
_event = new Faker<Event>()
.RuleFor(x => x.OriginalEvent, _mockIJSObjectReference.Object);
}
// arrange
Event @event = new Faker<Event>()
.RuleFor(x => x.OriginalEvent, jSObjectReference);

[Fact]
public void Verify_Dispose()
{
// act
_event.Dispose();
@event.Dispose();

// assert
_mockIJSObjectReference.Verify(c => c.DisposeAsync(), Times.Once());
_mockIJSObjectReference.Verify(c => c.DisposeAsync(), times);
}

public static IEnumerable<object[]> TestData_Verify_Dispose()
{
yield return WrapArgs(null, Times.Never());

_mockIJSObjectReference = new Mock<IJSObjectReference>();
yield return WrapArgs(_mockIJSObjectReference.Object, Times.Once());

static object[] WrapArgs(
IJSObjectReference? jSObjectReference,
Times times)
=> new object[]
{
jSObjectReference,
times
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bogus;
using System.Collections.Generic;
using Bogus;
using Microsoft.JSInterop;
using Moq;
using Xunit;
Expand All @@ -8,24 +9,37 @@ namespace Cropper.Blazor.UnitTests.Events.CropMoveEvent
{
public class CropMoveEvent_Should
{
private readonly Mock<IJSObjectReference> _mockIJSObjectReference;
private readonly Event _event;
private static Mock<IJSObjectReference> _mockIJSObjectReference = null!;

public CropMoveEvent_Should()
[Theory, MemberData(nameof(TestData_Verify_Dispose))]
public void Verify_Dispose(IJSObjectReference? jSObjectReference, Times times)
{
_mockIJSObjectReference = new Mock<IJSObjectReference>();
_event = new Faker<Event>()
.RuleFor(x => x.OriginalEvent, _mockIJSObjectReference.Object);
}
// arrange
Event @event = new Faker<Event>()
.RuleFor(x => x.OriginalEvent, jSObjectReference);

[Fact]
public void Verify_Dispose()
{
// act
_event.Dispose();
@event.Dispose();

// assert
_mockIJSObjectReference.Verify(c => c.DisposeAsync(), Times.Once());
_mockIJSObjectReference.Verify(c => c.DisposeAsync(), times);
}

public static IEnumerable<object[]> TestData_Verify_Dispose()
{
yield return WrapArgs(null, Times.Never());

_mockIJSObjectReference = new Mock<IJSObjectReference>();
yield return WrapArgs(_mockIJSObjectReference.Object, Times.Once());

static object[] WrapArgs(
IJSObjectReference? jSObjectReference,
Times times)
=> new object[]
{
jSObjectReference,
times
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bogus;
using System.Collections.Generic;
using Bogus;
using Microsoft.JSInterop;
using Moq;
using Xunit;
Expand All @@ -8,24 +9,37 @@ namespace Cropper.Blazor.UnitTests.Events.CropStartEvent
{
public class CropStartEvent_Should
{
private readonly Mock<IJSObjectReference> _mockIJSObjectReference;
private readonly Event _event;
private static Mock<IJSObjectReference> _mockIJSObjectReference = null!;

public CropStartEvent_Should()
[Theory, MemberData(nameof(TestData_Verify_Dispose))]
public void Verify_Dispose(IJSObjectReference? jSObjectReference, Times times)
{
_mockIJSObjectReference = new Mock<IJSObjectReference>();
_event = new Faker<Event>()
.RuleFor(x => x.OriginalEvent, _mockIJSObjectReference.Object);
}
// arrange
Event @event = new Faker<Event>()
.RuleFor(x => x.OriginalEvent, jSObjectReference);

[Fact]
public void Verify_Dispose()
{
// act
_event.Dispose();
@event.Dispose();

// assert
_mockIJSObjectReference.Verify(c => c.DisposeAsync(), Times.Once());
_mockIJSObjectReference.Verify(c => c.DisposeAsync(), times);
}

public static IEnumerable<object[]> TestData_Verify_Dispose()
{
yield return WrapArgs(null, Times.Never());

_mockIJSObjectReference = new Mock<IJSObjectReference>();
yield return WrapArgs(_mockIJSObjectReference.Object, Times.Once());

static object[] WrapArgs(
IJSObjectReference? jSObjectReference,
Times times)
=> new object[]
{
jSObjectReference,
times
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bogus;
using System.Collections.Generic;
using Bogus;
using Microsoft.JSInterop;
using Moq;
using Xunit;
Expand All @@ -8,24 +9,37 @@ namespace Cropper.Blazor.UnitTests.Events.ZoomEvent
{
public class ZoomEvent_Should
{
private readonly Mock<IJSObjectReference> _mockIJSObjectReference;
private readonly Event _event;
private static Mock<IJSObjectReference> _mockIJSObjectReference = null!;

public ZoomEvent_Should()
[Theory, MemberData(nameof(TestData_Verify_Dispose))]
public void Verify_Dispose(IJSObjectReference? jSObjectReference, Times times)
{
_mockIJSObjectReference = new Mock<IJSObjectReference>();
_event = new Faker<Event>()
.RuleFor(x => x.OriginalEvent, _mockIJSObjectReference.Object);
}
// arrange
Event @event = new Faker<Event>()
.RuleFor(x => x.OriginalEvent, jSObjectReference);

[Fact]
public void Verify_Dispose()
{
// act
_event.Dispose();
@event.Dispose();

// assert
_mockIJSObjectReference.Verify(c => c.DisposeAsync(), Times.Once());
_mockIJSObjectReference.Verify(c => c.DisposeAsync(), times);
}

public static IEnumerable<object[]> TestData_Verify_Dispose()
{
yield return WrapArgs(null, Times.Never());

_mockIJSObjectReference = new Mock<IJSObjectReference>();
yield return WrapArgs(_mockIJSObjectReference.Object, Times.Once());

static object[] WrapArgs(
IJSObjectReference? jSObjectReference,
Times times)
=> new object[]
{
jSObjectReference,
times
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bogus;
using System.Collections.Generic;
using Bogus;
using Cropper.Blazor.Models;
using Microsoft.JSInterop;
using Moq;
Expand All @@ -8,24 +9,37 @@ namespace Cropper.Blazor.UnitTests.Models
{
public class CroppedCanvas_Should
{
private readonly Mock<IJSObjectReference> _mockIJSObjectReference;
private readonly CroppedCanvas _croppedCanvas;
private static Mock<IJSObjectReference> _mockIJSObjectReference = null!;

public CroppedCanvas_Should()
[Theory, MemberData(nameof(TestData_Verify_Dispose))]
public void Verify_Dispose(IJSObjectReference? jSObjectReference, Times times)
{
_mockIJSObjectReference = new Mock<IJSObjectReference>();
_croppedCanvas = new Faker<CroppedCanvas>()
.CustomInstantiator(f => new CroppedCanvas(_mockIJSObjectReference.Object));
}
// arrange
CroppedCanvas croppedCanvas = new Faker<CroppedCanvas>()
.CustomInstantiator(f => new CroppedCanvas(jSObjectReference));

[Fact]
public void Verify_Dispose()
{
// act
_croppedCanvas.Dispose();
croppedCanvas.Dispose();

// assert
_mockIJSObjectReference.Verify(c => c.DisposeAsync(), Times.Once());
_mockIJSObjectReference.Verify(c => c.DisposeAsync(), times);
}

public static IEnumerable<object[]> TestData_Verify_Dispose()
{
yield return WrapArgs(null, Times.Never());

_mockIJSObjectReference = new Mock<IJSObjectReference>();
yield return WrapArgs(_mockIJSObjectReference.Object, Times.Once());

static object[] WrapArgs(
IJSObjectReference? jSObjectReference,
Times times)
=> new object[]
{
jSObjectReference,
times
};
}
}
}
Loading

0 comments on commit 694c479

Please sign in to comment.