using AcDream.Content;
using AcDream.Core.Content;
using DatReaderWriter.Lib.IO;
using DatReaderWriter.Options;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
namespace AcDream.App.Tests;
///
/// Test-only raw DatCollection which can be passed through the same bounded
/// abstraction as production without changing DAT fixture setup code.
///
public sealed class BoundedTestDatCollection : DatReaderWriter.DatCollection, IDatReaderWriter
{
private readonly DatCollectionAdapter _bounded;
public BoundedTestDatCollection(
string datDirectory,
DatAccessType datAccessType = DatAccessType.Read)
: base(new DatCollectionOptions
{
DatDirectory = datDirectory,
AccessType = datAccessType,
IndexCachingStrategy = IndexCachingStrategy.OnDemand,
FileCachingStrategy = FileCachingStrategy.Never,
})
{
_bounded = new DatCollectionAdapter(this);
}
public BoundedTestDatCollection(DatCollectionOptions options)
: base(options)
{
_bounded = new DatCollectionAdapter(this);
}
string IDatReaderWriter.SourceDirectory => _bounded.SourceDirectory;
IDatDatabase IDatReaderWriter.Portal => _bounded.Portal;
IDatDatabase IDatReaderWriter.Cell => _bounded.Cell;
ReadOnlyDictionary IDatReaderWriter.CellRegions => _bounded.CellRegions;
IDatDatabase IDatReaderWriter.HighRes => _bounded.HighRes;
IDatDatabase IDatReaderWriter.Language => _bounded.Language;
IDatDatabase IDatReaderWriter.Local => _bounded.Local;
ReadOnlyDictionary IDatReaderWriter.RegionFileMap => _bounded.RegionFileMap;
int IDatReaderWriter.PortalIteration => _bounded.PortalIteration;
int IDatReaderWriter.CellIteration => _bounded.CellIteration;
int IDatReaderWriter.HighResIteration => _bounded.HighResIteration;
int IDatReaderWriter.LanguageIteration => _bounded.LanguageIteration;
[return: MaybeNull]
T IDatObjectSource.Get(uint fileId) =>
_bounded.Get(fileId);
bool IDatObjectSource.TryGet(uint fileId, [MaybeNullWhen(false)] out T value)
=> _bounded.TryGet(fileId, out value);
IEnumerable IDatReaderWriter.GetAllIdsOfType() =>
_bounded.GetAllIdsOfType();
bool IDatReaderWriter.TryGetFileBytes(
uint regionId,
uint fileId,
ref byte[] bytes,
out int bytesRead) =>
_bounded.TryGetFileBytes(regionId, fileId, ref bytes, out bytesRead);
IEnumerable IDatReaderWriter.ResolveId(uint id) =>
_bounded.ResolveId(id);
bool IDatReaderWriter.TrySave(T obj, int iteration) =>
_bounded.TrySave(obj, iteration);
bool IDatReaderWriter.TrySave(uint regionId, T obj, int iteration) =>
_bounded.TrySave(regionId, obj, iteration);
}