Exemple #1
0
        public async Task Should_not_create_merge_mod()
        {
            var messageBus = new Mock <IMessageBus>();

            messageBus.Setup(p => p.PublishAsync(It.IsAny <IMessageBusEvent>()));
            messageBus.Setup(p => p.Publish(It.IsAny <IMessageBusEvent>()));
            var storageProvider  = new Mock <IStorageProvider>();
            var modParser        = new Mock <IModParser>();
            var reader           = new Mock <IReader>();
            var modWriter        = new Mock <IModWriter>();
            var gameService      = new Mock <IGameService>();
            var mapper           = new Mock <IMapper>();
            var modPatchExporter = new Mock <IModPatchExporter>();
            var modMergeExporter = new Mock <IModMergeExporter>();
            var infoProvider     = new Mock <IDefinitionInfoProvider>();
            var parserManager    = new Mock <IParserManager>();

            infoProvider.Setup(p => p.DefinitionUsesFIOSRules(It.IsAny <IDefinition>())).Returns(true);
            infoProvider.Setup(p => p.CanProcess(It.IsAny <string>())).Returns(true);
            gameService.Setup(p => p.GetSelected()).Returns((IGame)null);

            var service = new ModMergeService(null, parserManager.Object, new Cache(), messageBus.Object, modPatchExporter.Object, modMergeExporter.Object,
                                              new List <IDefinitionInfoProvider>()
            {
                infoProvider.Object
            }, reader.Object, modWriter.Object,
                                              modParser.Object, gameService.Object, storageProvider.Object, mapper.Object);

            var indexed = new IndexedDefinitions();

            indexed.InitMap(new List <IDefinition>()
            {
                new Definition()
                {
                    Code = "test = {test}",
                    File = "fake.txt"
                }
            });
            var empty = new IndexedDefinitions();

            empty.InitMap(new List <IDefinition>());

            var result = await service.MergeCollectionByDefinitionsAsync(new ConflictResult()
            {
                AllConflicts         = indexed,
                Conflicts            = empty,
                OverwrittenConflicts = empty,
                ResolvedConflicts    = empty
            }, new List <string>(), "fake copy");

            result.Should().BeNull();
        }
        public async Task Should_select_overwritten_conflict_for_merge()
        {
            DISetup.SetupContainer();

            var messageBus = new Mock <IMessageBus>();

            messageBus.Setup(p => p.PublishAsync(It.IsAny <IMessageBusEvent>()));
            messageBus.Setup(p => p.Publish(It.IsAny <IMessageBusEvent>()));
            var storageProvider  = new Mock <IStorageProvider>();
            var modParser        = new Mock <IModParser>();
            var reader           = new Mock <IReader>();
            var modWriter        = new Mock <IModWriter>();
            var gameService      = new Mock <IGameService>();
            var mapper           = new Mock <IMapper>();
            var modPatchExporter = new Mock <IModPatchExporter>();

            modPatchExporter.Setup(p => p.GetPatchStateAsync(It.IsAny <ModPatchExporterParameters>(), It.IsAny <bool>())).Returns(Task.FromResult((IPatchState) new PatchState()
            {
                ConflictHistory = new List <IDefinition>()
            }));
            IDefinition definition       = null;
            var         modMergeExporter = new Mock <IModMergeExporter>();

            modMergeExporter.Setup(p => p.ExportDefinitionsAsync(It.IsAny <ModMergeDefinitionExporterParameters>())).Returns((ModMergeDefinitionExporterParameters p) =>
            {
                definition = p.PatchDefinitions.FirstOrDefault();
                return(Task.FromResult(true));
            });
            var infoProvider = new Mock <IDefinitionInfoProvider>();

            infoProvider.Setup(p => p.DefinitionUsesFIOSRules(It.IsAny <IDefinition>())).Returns(true);
            infoProvider.Setup(p => p.CanProcess(It.IsAny <string>())).Returns(true);
            gameService.Setup(p => p.GetSelected()).Returns(new Game()
            {
                Type              = "Should_select_overwritten_conflict_for_merge",
                UserDirectory     = "C:\\Users\\Fake",
                WorkshopDirectory = "C:\\Fake"
            });
            var collections = new List <IModCollection>()
            {
                new ModCollection()
                {
                    IsSelected = true,
                    Mods       = new List <string>()
                    {
                        "mod/fakemod.mod"
                    },
                    Name = "test",
                    Game = "Should_select_overwritten_conflict_for_merge"
                }
            };

            storageProvider.Setup(s => s.GetModCollections()).Returns(() =>
            {
                return(collections);
            });
            var fileInfos = new List <IFileInfo>()
            {
                new FileInfo()
                {
                    Content = new List <string>()
                    {
                        "a"
                    },
                    FileName = "fakemod.mod",
                    IsBinary = false
                }
            };

            reader.Setup(s => s.Read(It.IsAny <string>(), It.IsAny <IEnumerable <string> >())).Returns(fileInfos);
            modParser.Setup(s => s.Parse(It.IsAny <IEnumerable <string> >())).Returns((IEnumerable <string> values) =>
            {
                return(new ModObject()
                {
                    FileName = values.First(),
                    Name = values.First()
                });
            });
            mapper.Setup(s => s.Map <IMod>(It.IsAny <IModObject>())).Returns((IModObject o) =>
            {
                return(new Mod()
                {
                    FileName = o.FileName,
                    Name = o.Name
                });
            });

            var service = new ModMergeService(new Cache(), messageBus.Object, modPatchExporter.Object, modMergeExporter.Object,
                                              new List <IDefinitionInfoProvider>()
            {
                infoProvider.Object
            }, reader.Object, modWriter.Object,
                                              modParser.Object, gameService.Object, storageProvider.Object, mapper.Object);

            var indexed = new IndexedDefinitions();

            indexed.InitMap(new List <IDefinition>()
            {
                new Definition()
                {
                    Code    = "test = {test}",
                    File    = "events\\fake.txt",
                    ModName = "a",
                    Id      = "test1"
                }
            });

            var overwritten = new IndexedDefinitions();

            overwritten.InitMap(new List <IDefinition>()
            {
                new Definition()
                {
                    Code    = "test = {testfakeoverwritten}",
                    File    = "events\\fake.txt",
                    ModName = "a",
                    Id      = "test1"
                }
            });

            var empty = new IndexedDefinitions();

            empty.InitMap(new List <IDefinition>());

            var result = await service.MergeCollectionByDefinitionsAsync(new ConflictResult()
            {
                AllConflicts         = indexed,
                Conflicts            = empty,
                OverwrittenConflicts = overwritten,
                ResolvedConflicts    = empty
            }, new List <string>() { "a" }, "fake copy");

            result.Should().NotBeNull();
            definition.Code.Should().Be("test = {testfakeoverwritten}");
        }