mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-10-01 16:47:26 +00:00
* Pass 1. * i'm FREE * Prevent hangups. * okay fine here's an attribute for settings, will polish later and prolly remove the overridable thing. * sigh. * fix singular trigger bug so LatheTest doesn't flake. * Remove SystemAttribute usage. * Poke * I used the shotgun. You know why? Cause the shot gun doesn’t miss, and unlike the shitty hybrid taser it stops a criminal in their tracks in two hits. Bang, bang, and they’re fucking done. I use four shots just to make damn sure. Because, once again, I’m not there to coddle a buncha criminal scum sucking f------, I’m there to 1) Survive the fucking round. 2) Guard the armory. So you can absolutely get fucked. If I get unbanned, which I won’t, you can guarantee I will continue to use the shotgun to apprehend criminals. Because it’s quick, clean and effective as fuck. Why in the seven hells would I fuck around with the disabler shots, which take half a clip just to bring someone down, or with the tazer bolts which are slow as balls, impossible to aim and do about next to jack shit, fuck all. The shotgun is the superior law enforcement weapon. Because it stops crime. And it stops crime by reducing the number of criminals roaming the fucking halls. * Change the faulty store test into two tests, one of which is ignored for failing.
200 lines
7.7 KiB
C#
200 lines
7.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using Content.IntegrationTests.Fixtures;
|
|
using Content.Server.Database;
|
|
using Content.Server.Preferences.Managers;
|
|
using Content.Shared.Body;
|
|
using Content.Shared.Humanoid;
|
|
using Content.Shared.Humanoid.Markings;
|
|
using Content.Shared.Humanoid.Prototypes;
|
|
using Content.Shared.Preferences;
|
|
using Microsoft.Data.Sqlite;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Log;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Serialization.Manager;
|
|
using Robust.UnitTesting;
|
|
|
|
namespace Content.IntegrationTests.Tests.Preferences
|
|
{
|
|
[TestFixture]
|
|
public sealed class ServerDbSqliteTests : GameTest
|
|
{
|
|
[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()
|
|
{
|
|
Name = "Charlie Charlieson",
|
|
FlavorText = "The biggest boy around.",
|
|
Species = "Human",
|
|
Age = 21,
|
|
Appearance = new(
|
|
Color.Azure,
|
|
Color.Beige,
|
|
new ())
|
|
};
|
|
}
|
|
|
|
private static ServerDbSqlite GetDb(RobustIntegrationTest.ServerIntegrationInstance server)
|
|
{
|
|
var cfg = server.ResolveDependency<IConfigurationManager>();
|
|
var serialization = server.ResolveDependency<ISerializationManager>();
|
|
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, serialization);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestUserDoesNotExist()
|
|
{
|
|
var pair = Pair;
|
|
var db = GetDb(pair.Server);
|
|
// Database should be empty so a new GUID should do it.
|
|
Assert.That(await db.GetPlayerPreferencesAsync(NewUserId()), Is.Null);
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestAppearanceValidationAndSave()
|
|
{
|
|
var pair = await PoolManager.GetServerClient();
|
|
var db = GetDb(pair.Server);
|
|
var username = new NetUserId(new Guid("640bd619-fc8d-4fe2-bf3c-4a5fb17d6ddd"));
|
|
|
|
var profile = CharlieCharlieson();
|
|
profile.Appearance.Markings["Head"] = new Dictionary<HumanoidVisualLayers, List<Marking>>
|
|
{
|
|
[HumanoidVisualLayers.Hair] = [],
|
|
[HumanoidVisualLayers.FacialHair] = [],
|
|
};
|
|
profile.Appearance.Markings["OrganFake"] = new Dictionary<HumanoidVisualLayers, List<Marking>>();
|
|
|
|
await pair.Server.WaitAssertion(() =>
|
|
{
|
|
var updated = HumanoidCharacterAppearance.EnsureValid(profile.Appearance, profile.Species, profile.Sex);
|
|
Assert.That(updated.Markings["Head"], Is.Empty);
|
|
Assert.That(updated.Markings.ContainsKey("OrganFake"), Is.False);
|
|
profile.Appearance = updated;
|
|
});
|
|
|
|
Assert.DoesNotThrowAsync(async () => await db.InitPrefsAsync(username, profile));
|
|
|
|
var preferences = (ServerPreferencesManager)pair.Server.ResolveDependency<IServerPreferencesManager>();
|
|
var prefs = await db.GetPlayerPreferencesAsync(username);
|
|
var fetchedProfile = preferences.ConvertProfiles(prefs!.Profiles.Find(p => p.Slot == 0));
|
|
Assert.That(fetchedProfile.MemberwiseEquals(profile));
|
|
|
|
await pair.CleanReturnAsync();
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestInitPrefs()
|
|
{
|
|
var pair = Pair;
|
|
var db = GetDb(pair.Server);
|
|
var preferences = (ServerPreferencesManager)pair.Server.ResolveDependency<IServerPreferencesManager>();
|
|
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);
|
|
var profile = preferences.ConvertProfiles(prefs!.Profiles.Find(p => p.Slot == slot));
|
|
Assert.That(profile.MemberwiseEquals(originalProfile));
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestDeleteCharacter()
|
|
{
|
|
var pair = Pair;
|
|
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!.Profiles, Has.Count.EqualTo(1));
|
|
}
|
|
|
|
[Test]
|
|
public async Task TestNoPendingDatabaseChanges()
|
|
{
|
|
var pair = Pair;
|
|
var server = pair.Server;
|
|
var db = GetDb(server);
|
|
Assert.That(async () => await db.HasPendingModelChanges(), Is.False,
|
|
"The database has pending model changes. Add a new migration to apply them. See https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations");
|
|
}
|
|
|
|
private static NetUserId NewUserId()
|
|
{
|
|
return new(Guid.NewGuid());
|
|
}
|
|
|
|
private const string InvalidSpecies = "WingusDingus";
|
|
|
|
private static bool[] _trueFalse = [true, false];
|
|
|
|
[Test]
|
|
[TestCaseSource(nameof(_trueFalse))]
|
|
public async Task InvalidSpeciesConversion(bool legacy)
|
|
{
|
|
var pair = Pair;
|
|
var server = pair.Server;
|
|
var db = GetDb(pair.Server);
|
|
var preferences = (ServerPreferencesManager)pair.Server.ResolveDependency<IServerPreferencesManager>();
|
|
|
|
var proto = server.ResolveDependency<IPrototypeManager>();
|
|
Assert.That(!proto.HasIndex<SpeciesPrototype>(InvalidSpecies), "You should not have added a species called WingusDingus, but change it in this test to something else I guess");
|
|
|
|
var bogus = new HumanoidCharacterProfile()
|
|
{
|
|
Species = InvalidSpecies,
|
|
};
|
|
|
|
var username = new NetUserId(new Guid("640bd619-fc8d-4fe2-bf3c-4a5fb17d6ddd"));
|
|
await db.InitPrefsAsync(username, new HumanoidCharacterProfile());
|
|
await db.SaveCharacterSlotAsync(username, bogus, 0);
|
|
await db.SaveSelectedCharacterIndexAsync(username, 0);
|
|
|
|
if (legacy)
|
|
await db.MakeCharacterSlotLegacyAsync(username, 0);
|
|
|
|
var prefs = await db.GetPlayerPreferencesAsync(username, CancellationToken.None);
|
|
|
|
Assert.That(prefs, Is.Not.Null);
|
|
await server.WaitAssertion(() =>
|
|
{
|
|
var converted = preferences.ConvertPreferences(prefs);
|
|
|
|
Assert.That(converted.Characters, Has.Count.EqualTo(1));
|
|
Assert.That(converted.Characters[0].Species, Is.Not.EqualTo(InvalidSpecies));
|
|
Assert.That(converted.Characters[0].Species, Is.EqualTo(HumanoidCharacterProfile.DefaultSpecies));
|
|
});
|
|
}
|
|
}
|
|
}
|