Files
OldThink/Content.IntegrationTests/Tests/Preferences/ServerDbSqliteTests.cs
Remuchi 3515e87f74 [Feat] Тонкие спрайты снова в строю (#102)
* Revert "Hair Overhaul (#19298)"

This reverts commit 9491f322de.

# Conflicts:
#	Resources/Textures/Mobs/Customization/human_hair.rsi/a.png
#	Resources/Textures/Mobs/Customization/human_hair.rsi/afro.png
#	Resources/Textures/Mobs/Customization/human_hair.rsi/afro2.png
#	Resources/Textures/Mobs/Customization/human_hair.rsi/bigafro.png
#	Resources/Textures/Mobs/Customization/human_hair.rsi/cornrows2.png
#	Resources/Textures/Mobs/Customization/human_hair.rsi/emofringe.png
#	Resources/Textures/Mobs/Customization/human_hair.rsi/keanu.png
#	Resources/Textures/Mobs/Customization/human_hair.rsi/long.png
#	Resources/Textures/Mobs/Customization/human_hair.rsi/long2.png
#	Resources/Textures/Mobs/Customization/human_hair.rsi/long3.png
#	Resources/Textures/Mobs/Customization/human_hair.rsi/meta.json
#	Resources/Textures/Mobs/Customization/human_hair.rsi/modern.png
#	Resources/Textures/Mobs/Customization/human_hair.rsi/quiff.png

* add: возврат системы тонкоспрайтов

* fix: небольшие фиксы после реверта причесок

* add: старые текстуры для slim бодитайпа

* fix: фикс причесок после апстрима
2024-02-24 10:06:32 +00:00

132 lines
4.4 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Content.Server.Database;
using Content.Shared.GameTicking;
using Content.Shared.Humanoid;
using Content.Shared.Preferences;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Robust.Shared.Configuration;
using Robust.Shared.Enums;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Network;
using Robust.UnitTesting;
namespace Content.IntegrationTests.Tests.Preferences
{
[TestFixture]
public sealed class ServerDbSqliteTests
{
[TestPrototypes]
private const string Prototypes = @"
- type: dataset
id: sqlite_test_names_first_male
values:
- Aaden
- type: dataset
id: sqlite_test_names_first_female
values:
- Aaliyah
- type: dataset
id: sqlite_test_names_last
values:
- Ackerley";
private static HumanoidCharacterProfile CharlieCharlieson()
{
return new(
"Charlie Charlieson",
"HONK",
"Quiet",
"Silicon",
"The biggest boy around.",
"Human",
"Eugene",
21,
Sex.Male,
Gender.Epicene,
"Normal",
new HumanoidCharacterAppearance(
"Afro",
Color.Aqua,
"Shaved",
Color.Aquamarine,
Color.Azure,
Color.Beige,
new ()
),
ClothingPreference.Jumpskirt,
BackpackPreference.Backpack,
SpawnPriorityPreference.None,
new Dictionary<string, JobPriority>
{
{SharedGameTicker.FallbackOverflowJob, JobPriority.High}
},
PreferenceUnavailableMode.StayInLobby,
new List<string> (),
new List<string>()
);
}
private static ServerDbSqlite GetDb(RobustIntegrationTest.ServerIntegrationInstance server)
{
var cfg = server.ResolveDependency<IConfigurationManager>();
var opsLog = server.ResolveDependency<ILogManager>().GetSawmill("db.ops");
var builder = new DbContextOptionsBuilder<SqliteServerDbContext>();
var conn = new SqliteConnection("Data Source=:memory:");
conn.Open();
builder.UseSqlite(conn);
return new ServerDbSqlite(() => builder.Options, true, cfg, true, opsLog);
}
[Test]
public async Task TestUserDoesNotExist()
{
var pair = await PoolManager.GetServerClient();
var db = GetDb(pair.Server);
// Database should be empty so a new GUID should do it.
Assert.That(await db.GetPlayerPreferencesAsync(NewUserId()), Is.Null);
await pair.CleanReturnAsync();
}
[Test]
public async Task TestInitPrefs()
{
var pair = await PoolManager.GetServerClient();
var db = GetDb(pair.Server);
var username = new NetUserId(new Guid("640bd619-fc8d-4fe2-bf3c-4a5fb17d6ddd"));
const int slot = 0;
var originalProfile = CharlieCharlieson();
await db.InitPrefsAsync(username, originalProfile);
var prefs = await db.GetPlayerPreferencesAsync(username);
Assert.That(prefs.Characters.Single(p => p.Key == slot).Value.MemberwiseEquals(originalProfile));
await pair.CleanReturnAsync();
}
[Test]
public async Task TestDeleteCharacter()
{
var pair = await PoolManager.GetServerClient();
var server = pair.Server;
var db = GetDb(server);
var username = new NetUserId(new Guid("640bd619-fc8d-4fe2-bf3c-4a5fb17d6ddd"));
await db.InitPrefsAsync(username, new HumanoidCharacterProfile());
await db.SaveCharacterSlotAsync(username, CharlieCharlieson(), 1);
await db.SaveSelectedCharacterIndexAsync(username, 1);
await db.SaveCharacterSlotAsync(username, null, 1);
var prefs = await db.GetPlayerPreferencesAsync(username);
Assert.That(!prefs.Characters.Any(p => p.Key != 0));
await pair.CleanReturnAsync();
}
private static NetUserId NewUserId()
{
return new(Guid.NewGuid());
}
}
}