Esempio n. 1
0
        // TODO: test with errors / loading / conflicts
        private CalculatedRepositoryStateEnum CalculateState(params IModelRepositoryMod[] mods)
        {
            var repo = new Mock <IModelRepository>(MockBehavior.Strict);

            repo.Setup(r => r.State).Returns(LoadingState.Loaded);
            repo.Setup(r => r.GetMods()).Returns(mods.ToList());
            return(CoreCalculation.GetRepositoryState(repo.Object, mods.ToList()));
        }
Esempio n. 2
0
        private ModActionEnum DoCheck(int repoHash, int repoVersion, int?storageHash, int?storageVersion, StorageModStateEnum state, bool canWrite = true)
        {
            // TODO: restructure a bit for less parameter passing all over the place
            var repoMod    = new MockModelRepositoryMod(repoHash, repoVersion);
            var storageMod = new MockModelStorageMod(storageHash, storageVersion, state)
            {
                CanWrite = canWrite
            };

            return(CoreCalculation.GetModAction(repoMod, storageMod));
        }
Esempio n. 3
0
 internal static ModAction Create(ModSelection selection, IModelRepositoryMod parent)
 {
     return(selection switch
     {
         ModSelectionNone => new SelectNone(),
         ModSelectionLoading => new SelectLoading(),
         ModSelectionDisabled => new SelectDisabled(),
         ModSelectionDownload download => new SelectStorage(download.DownloadStorage),
         ModSelectionStorageMod actionStorageMod => new SelectMod(actionStorageMod.StorageMod,
                                                                  CoreCalculation.GetModAction(parent, actionStorageMod.StorageMod)),
         _ => throw new ArgumentException()
     });
Esempio n. 4
0
        internal static IModelStorageMod FromAction(ModActionEnum actionType, bool canWrite = true)
        {
            var storageMod = actionType switch
            {
                ModActionEnum.Update => new MockModelStorageMod(1, 2, StorageModStateEnum.Created),
                ModActionEnum.ContinueUpdate => new MockModelStorageMod(1, 1, StorageModStateEnum.CreatedWithUpdateTarget),
                ModActionEnum.Await => new MockModelStorageMod(1, 1, StorageModStateEnum.Updating),
                ModActionEnum.Use => new MockModelStorageMod(1, 1, StorageModStateEnum.Created),
                ModActionEnum.AbortAndUpdate => new MockModelStorageMod(1, 2, StorageModStateEnum.CreatedWithUpdateTarget),
                ModActionEnum.AbortActiveAndUpdate => new MockModelStorageMod(1, 2, StorageModStateEnum.Updating),
                ModActionEnum.Unusable => new MockModelStorageMod(2, 2, StorageModStateEnum.Created),
                _ => throw new ArgumentOutOfRangeException(nameof(actionType), actionType, null)
            };

            storageMod.CanWrite = canWrite;

            // just checking that we got the setup right
            var testRepoMod = new MockModelRepositoryMod(1, 1);

            Assert.Equal(actionType, CoreCalculation.GetModAction(testRepoMod, storageMod));

            return(storageMod);
        }
 public CalculatedRepositoryStateEnum GetStateFor(IModelRepository repository)
 {
     _model ??= _serviceProvider.Get <IModel>();
     return(CoreCalculation.GetRepositoryState(repository, _model.GetRepositoryMods()));
 }
Esempio n. 6
0
 private IModelStorageMod?AutoSelect(IModelRepositoryMod repoMod, IEnumerable <IModelRepositoryMod>?allRepoMods = null,
                                     params IModelStorageMod[] storageMods)
 {
     return(CoreCalculation.AutoSelect(repoMod, storageMods.ToList(), allRepoMods?.ToList() ?? new List <IModelRepositoryMod>()));
 }