using Tiobon.Core.IServices;
using Tiobon.Core.Model.Models;
using Xunit;
using System;
using System.Linq;
using Autofac;

namespace Tiobon.Core.Tests
{
    public class TiobonArticleService_Should
    {

        private ITiobonArticleServices TiobonArticleServices;
        DI_Test dI_Test = new DI_Test();


        public TiobonArticleService_Should()
        {
            //mockTiobonRep.Setup(r => r.Query());

            var container = dI_Test.DICollections();

            TiobonArticleServices = container.Resolve<ITiobonArticleServices>();

        }


        [Fact]
        public void TiobonArticleServices_Test()
        {
            Assert.NotNull(TiobonArticleServices);
        }


        [Fact]
        public async void Get_Tiobons_Test()
        {
            var data = await TiobonArticleServices.GetTiobons();

            Assert.True(data.Any());
        }

        [Fact]
        public async void Add_Tiobon_Test()
        {
            TiobonArticle TiobonArticle = new TiobonArticle()
            {
                bCreateTime = DateTime.Now,
                bUpdateTime = DateTime.Now,
                btitle = "xuint test title",
                bcontent = "xuint test content",
                bsubmitter = "xuint test submitter",
            };

            var BId = await TiobonArticleServices.Add(TiobonArticle);

            Assert.True(BId > 0);
        }

        [Fact]
        public async void Delete_Tiobon_Test()
        {
            Add_Tiobon_Test();

            var deleteModel = (await TiobonArticleServices.Query(d => d.btitle == "xuint test title")).FirstOrDefault();

            Assert.NotNull(deleteModel);

            var IsDel = await TiobonArticleServices.Delete(deleteModel);

            Assert.True(IsDel);
        }
    }
}
