-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added unit tests for core module WidgetInstanceService (#1077)
Co-authored-by: Hisham Bin Ateya <[email protected]>
- Loading branch information
1 parent
1cc3cfe
commit dae5acd
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
test/SimplCommerce.Module.Core.Tests/Services/WidgetInstanceServiceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using System.Linq; | ||
using Moq; | ||
using SimplCommerce.Infrastructure.Data; | ||
using SimplCommerce.Module.Core.Models; | ||
using SimplCommerce.Module.Core.Services; | ||
using Xunit; | ||
|
||
namespace SimplCommerce.Module.Core.Tests.Services | ||
{ | ||
public class WidgetInstanceServiceTests | ||
{ | ||
[Fact] | ||
public void GetPublished_ShouldReturnPublishedWidgetInstances() | ||
{ | ||
// Arrange | ||
var widgetInstances = new[] | ||
{ | ||
new WidgetInstance { PublishStart = DateTimeOffset.Now.AddDays(-1), PublishEnd = DateTimeOffset.Now.AddDays(1) }, | ||
new WidgetInstance { PublishStart = DateTimeOffset.Now.AddDays(-2), PublishEnd = DateTimeOffset.Now.AddDays(2) } | ||
}; | ||
|
||
var mockRepository = new Mock<IRepository<WidgetInstance>>(); | ||
mockRepository.Setup(x => x.Query()).Returns(widgetInstances.AsQueryable()); | ||
|
||
var widgetInstanceService = new WidgetInstanceService(mockRepository.Object); | ||
|
||
// Act | ||
var result = widgetInstanceService.GetPublished(); | ||
|
||
// Assert | ||
Assert.Equal(widgetInstances.Length, result.Count()); | ||
} | ||
|
||
[Fact] | ||
public void GetPublished_ShouldNotReturnUnpublishedWidgetInstances() | ||
{ | ||
// Arrange | ||
var widgetInstances = new[] | ||
{ | ||
new WidgetInstance { PublishStart = DateTimeOffset.Now.AddDays(1), PublishEnd = DateTimeOffset.Now.AddDays(2) }, | ||
new WidgetInstance { PublishStart = null, PublishEnd = DateTimeOffset.Now.AddDays(-1) }, | ||
}; | ||
|
||
var mockRepository = new Mock<IRepository<WidgetInstance>>(); | ||
mockRepository.Setup(x => x.Query()).Returns(widgetInstances.AsQueryable()); | ||
|
||
var widgetInstanceService = new WidgetInstanceService(mockRepository.Object); | ||
|
||
// Act | ||
var result = widgetInstanceService.GetPublished(); | ||
|
||
// Assert | ||
Assert.Empty(result); | ||
} | ||
} | ||
} |