context: using GrizzenServer;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using Xunit;
  
  namespace XUnitTests
  {
      public class DataTests
      {
          public DataTests()
          {
              BaseDataSQLite.ResetDatabase();
          }
  
          [Fact]
          public void DeleteBody_DeletesBody()
          {
              using (var db = new DataSQLite())
              {
                  var monster = db.CreateBody("body-monster");
                  Assert.NotEmpty(db.Bodies());
  
                  db.DeleteBody(monster.Id);
                  Assert.Empty(db.Bodies());
  
                  var guard = db.CreateBody("body-guard");
                  Assert.NotEmpty(db.Bodies());
  
                  db.DeleteBody(guard.Id);
                  Assert.Empty(db.Bodies());
              }
          }
  
          [Fact]
          public void DeleteItem_DeletesItem()
          {
              using (var db = new DataSQLite())
              {
                  var weapon = db.CreateItem("item-weapon");
                  Assert.NotEmpty(db.Items());
  
                  db.DeleteItem(weapon.Id);
                  Assert.Empty(db.Items());
              }
          }
  
          [Fact]
          public void CreateBody_WithEmptyTemplateString_ReturnsNull()
          {
              using (var db = new DataSQLite())
              {
                  {
                      var body = db.CreateBody(null);
                      Assert.Null(body);
                      Assert.Empty(db.Bodies());
                  }
                  {
                      var body = db.CreateBody("");
                      Assert.Null(body);
                      Assert.Empty(db.Bodies());
                  }
                  {
                      var body = db.CreateBody(" \t");
                      Assert.Null(body);
                      Assert.Empty(db.Bodies());
                  }
              }
          }
  
          [Fact]
          public void CreateBody_WithInvalidTemplateString_ReturnsNull()
          {
              using (var db = new DataSQLite())
              {
                  var body = db.CreateBody("invalid template string");
                  Assert.Null(body);
                  Assert.Empty(db.Bodies());
              }
          }
  
          [Fact]
          public void CreateItem_WithEmptyTemplateString_ReturnsNull()
          {
              using (var db = new DataSQLite())
              {
                  {
                      var item = db.CreateItem(null);
                      Assert.Null(item);
                      Assert.Empty(db.Items());
                  }
                  {
                      var item = db.CreateItem("");
                      Assert.Null(item);
                      Assert.Empty(db.Items());
                  }
                  {
                      var item = db.CreateItem(" \t");
                      Assert.Null(item);
                      Assert.Empty(db.Items());
                  }
              }
          }
  
          [Fact]
          public void CreateItem_WithInvalidTemplateString_ReturnsNull()
          {
              using (var db = new DataSQLite())
              {
                  var item = db.CreateItem("invalid template string");
                  Assert.Null(item);
                  Assert.Empty(db.Items());
              }
          }
  
          [Fact]
          public void DeleteBody_AlsoDeletesRoles()
          {
              using (var db = new DataSQLite())
              {
                  var body = db.CreateBody("body-player");
                  var bodyId = body.Id;
                  Assert.True(db.HasRole(bodyId, "player"));
  
                  db.DeleteBody(body.Id);
                  Assert.False(db.HasRole(bodyId, "player"));
                  Assert.Empty(db.RolesByEntity(bodyId));
  
                  Assert.Empty(db.Bodies());
              }
          }
  
          [Fact]
          public void DeleteItem_AlsoDeletesRoles()
          {
              using (var db = new DataSQLite())
              {
                  var item = db.CreateItem("item-chair");
                  var itemId = item.Id;
                  Assert.True(db.HasRole(itemId, "seat"));
  
                  db.DeleteItem(item.Id);
                  Assert.False(db.HasRole(itemId, "seat"));
                  Assert.Empty(db.RolesByEntity(itemId));
  
                  Assert.Empty(db.Items());
              }
          }
  
          [Fact]
          public void SetEntityName_InvalidEntity()
          {
              using (var db = new DataSQLite())
              {
                  db.SetName("invalid ID", "a name");
              }
          }
  
          [Fact]
          public void SetGender_InvalidBody()
          {
              using (var db = new DataSQLite())
              {
                  db.SetGender("invalid ID", Gender.Female);
              }
          }
  
          [Fact]
          public void GetAllBodySpawnsTest()
          {
              using (var db = new DataSQLite())
              {
                  var spawns = db.BodySpawns();
                  Assert.NotEmpty(spawns);
                  Assert.Contains(spawns, s => s.SceneId == "scene-1" && s.TemplateId == "body-healer" && s.MaxSpawns == 1);
              }
          }
  
          [Fact]
          public void GetAllItemSpawnsTest()
          {
              using (var db = new DataSQLite())
              {
                  var spawns = db.ItemSpawns();
                  Assert.NotEmpty(spawns);
                  Assert.Contains(spawns, s => s.SceneId == "scene-1" && s.TemplateId == "item-chair" && s.MaxSpawns == 1);
              }
          }
  
          [Fact]
          public void GetScene_EmptyId_ReturnsNull()
          {
              using (var db = new DataSQLite())
              {
                  {
                      var scene = db.Scene(null);
                      Assert.Null(scene);
                  }
                  {
                      var scene = db.Scene("");
                      Assert.Null(scene);
                  }
                  {
                      var scene = db.Scene(" ");
                      Assert.Null(scene);
                  }
              }
          }
  
          [Fact]
          public void GetScene_InvalidId_ReturnsNull()
          {
              using (var db = new DataSQLite())
              {
  
gt:                 var scene = db.Scene("invalid ID");