using System.Linq;
using VCommon.VEntityFrameworkCore.Tests.Efc;
using VCommon.VEntityFrameworkCore.Tests.Entities;
using Xunit;
using Xunit.Abstractions;

namespace VCommon.VEntityFrameworkCore.Tests
{
    public class DbContextTests
    {
        private readonly ITestOutputHelper _output;

        public DbContextTests(ITestOutputHelper output)
        {
            _output = output;
        }

        [Fact]
        public void CreateAuditTest()
        {
            var ctx = new TestDbContext(_output);
            var ne = new TestEntity
            {
                Name = "I am a new entity"
            };

            ctx.TestEntities.Add(ne);
            ctx.SaveChanges();
        }

        [Fact]
        public void UpdateAuditTest()
        {
            var ctx = new TestDbContext(_output);
            var ee = ctx.TestEntities.First();
            ee.Name = "The name was changed";
            ctx.SaveChanges();
        }

        [Fact]
        public void DeleteAuditTest()
        {
            var ctx = new TestDbContext(_output);
            var ee = ctx.TestEntities.First();
            ctx.TestEntities.Remove(ee);
            ctx.SaveChanges();
        }
    }
}
