Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

NewsServiceTests.cs

using FluentAssertions;
using Nop.Core.Domain.News;
using Nop.Services.News;
using NUnit.Framework;

namespace Nop.Tests.Nop.Services.Tests.News;

[TestFixture]
public class NewsServiceTests : ServiceTest
{
    private INewsService _newsService;

    [OneTimeSetUp]
    public void SetUp()
    {
        _newsService = GetService();
    }

    [Test]
    public void ShouldBeAvailableWhenStartDateIsNotSet()
    {
        var newsItem = new NewsItem
        {
            StartDateUtc = null
        };

        _newsService.IsNewsAvailable(newsItem, new DateTime(2010, 01, 03)).Should().BeTrue();
    }

    [Test]
    public void ShouldBeAvailableWhenStartDateIsLessThanSomeDate()
    {
        var newsItem = new NewsItem
        {
            StartDateUtc = new DateTime(2010, 01, 02)
        };

        _newsService.IsNewsAvailable(newsItem, new DateTime(2010, 01, 03)).Should().BeTrue();
    }

    [Test]
    public void ShouldNotBeAvailableWhenStartDateIsGreaterThanSomeDate()
    {
        var newsItem = new NewsItem
        {
            StartDateUtc = new DateTime(2010, 01, 02)
        };

        _newsService.IsNewsAvailable(newsItem, new DateTime(2010, 01, 01)).Should().BeFalse();
    }

    [Test]
    public void ShouldBeAvailableWhenEndDateIsNotSet()
    {
        var newsItem = new NewsItem
        {
            EndDateUtc = null
        };

        _newsService.IsNewsAvailable(newsItem, new DateTime(2010, 01, 03)).Should().BeTrue();
    }

    [Test]
    public void ShouldBeAvailableWhenEndDateIsGreaterThanSomeDate()
    {
        var newsItem = new NewsItem
        {
            EndDateUtc = new DateTime(2010, 01, 02)
        };

        _newsService.IsNewsAvailable(newsItem, new DateTime(2010, 01, 01)).Should().BeTrue();
    }

    [Test]
    public void ShouldNotBeAvailableWhenEndDateIsLessThanSomeDate()
    {
        var newsItem = new NewsItem
        {
            EndDateUtc = new DateTime(2010, 01, 02)
        };

        _newsService.IsNewsAvailable(newsItem, new DateTime(2010, 01, 03)).Should().BeFalse();
    }
}