public void Returns_all_definitions() { DISetup.SetupContainer(); var defs = new List <IDefinition>(); for (int i = 0; i < 10; i++) { defs.Add(new Definition() { Code = i.ToString(), ContentSHA = i.ToString(), Dependencies = new List <string> { i.ToString() }, File = i.ToString(), Id = i.ToString(), ModName = i.ToString(), Type = i.ToString() }); } var service = new IndexedDefinitions(); service.InitMap(defs); var results = service.GetAll(); results.Count().Should().Be(defs.Count); int match = 0; foreach (var item in defs) { if (results.Contains(item)) { match++; } } match.Should().Be(defs.Count); }
public void Returns_by_type() { DISetup.SetupContainer(); var defs = new List <IDefinition>(); for (int i = 0; i < 10; i++) { defs.Add(new Definition() { Code = i.ToString(), ContentSHA = i.ToString(), Dependencies = new List <string> { i.ToString() }, File = i < 3 ? "file" : i.ToString(), Id = i.ToString(), ModName = i.ToString(), Type = i > 3 && i < 6 ? "type" : i.ToString() }); } var service = new IndexedDefinitions(); service.InitMap(defs); var results = service.GetByType("type"); results.Count().Should().Be(defs.Where(s => s.Type == "type").Count()); int match = 0; foreach (var item in defs.Where(s => s.Type == "type")) { if (results.Contains(item)) { match++; } } match.Should().Be(defs.Where(s => s.Type == "type").Count()); }
public void Should_filter_out_duplicates() { DISetup.SetupContainer(); var registry = new LocalizationRegistry(new Cache()); registry.RegisterTranslation("en", LocalizationResources.FilterCommands.Achievements, "en-ach"); registry.RegisterTranslation("fr", LocalizationResources.FilterCommands.Achievements, "fr-ach"); registry.RegisterTranslation("en", LocalizationResources.FilterCommands.Selected, "en-sel"); registry.RegisterTranslation("fr", LocalizationResources.FilterCommands.Selected, "fr-sel"); registry.RegisterTranslation("en", LocalizationResources.FilterCommands.Yes, "yes"); registry.RegisterTranslation("fr", LocalizationResources.FilterCommands.Yes, "fr-yes"); registry.RegisterTranslation("en", LocalizationResources.FilterCommands.True, "true"); registry.RegisterTranslation("fr", LocalizationResources.FilterCommands.True, "fr-true"); registry.RegisterTranslation("en", LocalizationResources.FilterCommands.No, "no"); registry.RegisterTranslation("fr", LocalizationResources.FilterCommands.No, "fr-no"); registry.RegisterTranslation("en", LocalizationResources.FilterCommands.False, "false"); registry.RegisterTranslation("fr", LocalizationResources.FilterCommands.False, "fr-false"); registry.RegisterTranslation("en", LocalizationResources.FilterCommands.Version, "en-ver"); registry.RegisterTranslation("fr", LocalizationResources.FilterCommands.Version, "fr-ver"); registry.RegisterTranslation("en", LocalizationResources.FilterCommands.Source, "en-src"); registry.RegisterTranslation("fr", LocalizationResources.FilterCommands.Source, "fr-src"); registry.RegisterTranslation("en", LocalizationResources.FilterCommands.Paradox, "pdx"); registry.RegisterTranslation("fr", LocalizationResources.FilterCommands.Paradox, "fr-pdx"); registry.RegisterTranslation("en", LocalizationResources.FilterCommands.Steam, "steam"); registry.RegisterTranslation("fr", LocalizationResources.FilterCommands.Steam, "fr-steam"); registry.RegisterTranslation("en", LocalizationResources.FilterCommands.Local, "local"); registry.RegisterTranslation("fr", LocalizationResources.FilterCommands.Local, "fr-local"); var parser = new Mod.Search.Parser(new Logger(), new List <ITypeConverter <object> > { new VersionConverter(registry), new BoolConverter(registry), new SourceTypeConverter(registry) }); var line = "en-ach:yes && en-ach:no"; var result = parser.Parse("en", line); result.Should().NotBeNull(); result.AchievementCompatible.Result.GetValueOrDefault().Should().BeTrue(); }
/// <summary> /// Setups the mock case. /// </summary> /// <param name="preferencesService">The preferences service.</param> /// <param name="storageProvider">The storage provider.</param> private static void SetupMockCase(Mock <IPreferencesService> preferencesService, Mock <IStorageProvider> storageProvider) { DISetup.SetupContainer(); preferencesService.Setup(p => p.Get()).Returns(() => { return(new Preferences() { Theme = "MaterialDeepPurple" }); }); preferencesService.Setup(p => p.Save(It.IsAny <IPreferences>())).Returns(true); var themes = new List <IThemeType> { new ThemeType() { Name = "Dark", IsDefault = false }, new ThemeType() { Name = "MaterialDark", IsDefault = false }, new ThemeType() { Name = "MaterialLightGreen", IsDefault = false }, new ThemeType() { Name = "MaterialDeepPurple", IsDefault = false }, new ThemeType() { Name = "Light", IsDefault = true } }; storageProvider.Setup(p => p.GetThemes()).Returns(themes); }
public async Task Mod_directory_should_purge() { DISetup.SetupContainer(); 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>(); gameService.Setup(p => p.GetSelected()).Returns(new Game() { Type = "Mod_directory_should_purge", UserDirectory = "C:\\Users\\Fake", WorkshopDirectory = "C:\\workshop" }); modWriter.Setup(p => p.PurgeModDirectoryAsync(It.IsAny <ModWriterParameters>(), It.IsAny <bool>())).Returns(Task.FromResult(true)); var service = GetService(storageProvider, modParser, reader, mapper, modWriter, gameService); var result = await service.PurgeModDirectoryAsync("test"); result.Should().BeTrue(); }
public void Should_not_resolve_user_control() { DISetup.SetupContainer(); var resolver = new Mock <IViewResolver>(); resolver.Setup(p => p.FormatUserControlName(It.IsAny <object>())).Returns(string.Empty); resolver.Setup(p => p.IsControl(It.IsAny <string>())).Returns(true); resolver.Setup(p => p.ResolveUserControl(It.IsAny <object>())).Returns(() => { throw new Exception("Fake"); }); DISetup.Container.RegisterInstance(resolver.Object); var logger = new Mock <ILogger>(); logger.Setup(p => p.Info(It.IsAny <string>())); logger.Setup(p => p.Error(It.IsAny <Exception>(), It.IsAny <string>())); DISetup.Container.RegisterInstance(logger.Object); var locator = new ViewLocator(); var result = locator.Build(new FakeVM()); result.GetType().Should().Be(typeof(TextBlock)); ((TextBlock)result).Text.Should().Contain("Not Found"); }
public void Should_not_refresh_property() { DISetup.SetupContainer(); DISetup.Container.Register <FakeModel>(); var model = DISetup.Container.GetInstance <FakeModel>(); model.Dummy3 = new List <FakeLocalizableModelWithoutAttribute>() { new FakeLocalizableModelWithoutAttribute() { FakeProp = "1" } }; var changedEvents = new List <string>(); var changingEvents = new List <string>(); model.Dummy3.First().PropertyChanged += (s, e) => { changedEvents.Add(e.PropertyName); }; model.Dummy3.First().PropertyChanging += (s, e) => { changingEvents.Add(e.PropertyName); }; var invocation = new Mock <Castle.DynamicProxy.IInvocation>(); invocation.Setup(p => p.InvocationTarget).Returns(model); invocation.Setup(p => p.Proxy).Returns(model.Dummy3); var prop = model.GetType().GetProperty("Dummy3"); var args = new LocalizationRefreshArgs(invocation.Object, prop); var handler = new LocalizationCollectionRefreshHandler(); handler.Refresh(args); changedEvents.Count.Should().Be(0); changingEvents.Count.Should().Be(0); }
public async Task Should_not_import_paradox_launcher_mod() { var storageProvider = new Mock <IStorageProvider>(); var mapper = new Mock <IMapper>(); var gameService = new Mock <IGameService>(); var modExport = new Mock <IModCollectionExporter>(); DISetup.SetupContainer(); gameService.Setup(s => s.GetSelected()).Returns(new Game() { Type = "no-items", UserDirectory = "C:\\fake" }); modExport.Setup(p => p.ImportParadoxLauncherAsync(It.IsAny <ModCollectionExporterParams>())).Returns((ModCollectionExporterParams p) => { p.Mod.Name = "fake"; return(Task.FromResult(false)); }); var service = new ModCollectionService(null, null, new Cache(), null, null, null, null, gameService.Object, modExport.Object, storageProvider.Object, mapper.Object); var result = await service.ImportParadoxLauncherAsync(); result.Should().BeNull(); }
public async Task Should_return_mod_collection_details() { var storageProvider = new Mock <IStorageProvider>(); var mapper = new Mock <IMapper>(); var gameService = new Mock <IGameService>(); var modExport = new Mock <IModCollectionExporter>(); DISetup.SetupContainer(); gameService.Setup(s => s.GetSelected()).Returns(new Game() { Type = "no-items", UserDirectory = "C:\\fake" }); modExport.Setup(p => p.ImportAsync(It.IsAny <ModCollectionExporterParams>())).Returns((ModCollectionExporterParams p) => { p.Mod.Name = "fake"; return(Task.FromResult(true)); }); var service = new ModCollectionService(null, null, new Cache(), null, null, null, null, gameService.Object, modExport.Object, storageProvider.Object, mapper.Object); var result = await service.GetImportedCollectionDetailsAsync("file"); result.Should().NotBeNull(); }
public async Task Should_delete_descriptors() { DISetup.SetupContainer(); 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>(); gameService.Setup(p => p.GetSelected()).Returns(new Game() { Type = "Should_delete_descriptors", UserDirectory = "C:\\Users\\Fake", WorkshopDirectory = "C:\\workshop" }); modWriter.Setup(p => p.DeleteDescriptorAsync(It.IsAny <ModWriterParameters>())).Returns(Task.FromResult(true)); var service = GetService(storageProvider, modParser, reader, mapper, modWriter, gameService); var result = await service.DeleteDescriptorsAsync(new List <IMod>() { new Mod() }); result.Should().BeTrue(); }
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}"); }
public void Parse_should_yield_results() { DISetup.SetupContainer(); var sb = new StringBuilder(); sb.AppendLine(@"NCamera = {FOV = 35 # Field-of-View"); sb.AppendLine(@" # Used for all ships"); sb.AppendLine(@" ENTITY_SPRITE_DESIGN_ENTRY_CAM_DIR = { -1.0 -0.6 0.3 }"); sb.AppendLine(@"}"); sb.AppendLine(@"NGraphics = {"); sb.AppendLine(@" CAMERA_DISTANCE_TO_ZOOM = 10.0"); sb.AppendLine(@"}"); var sb2 = new StringBuilder(); sb2.AppendLine(@"NCamera = {"); sb2.AppendLine(@" FOV = 35"); sb2.Append('}'); var sb3 = new System.Text.StringBuilder(); sb3.AppendLine(@"NCamera = {"); sb3.AppendLine(@" ENTITY_SPRITE_DESIGN_ENTRY_CAM_DIR = {"); sb3.AppendLine(@" -1"); sb3.AppendLine(@" -0.6"); sb3.AppendLine(@" 0.3"); sb3.AppendLine(@" }"); sb3.Append('}'); var sb4 = new StringBuilder(); sb4.AppendLine(@"NGraphics = {"); sb4.AppendLine(@" CAMERA_DISTANCE_TO_ZOOM = 10"); sb4.Append('}'); var args = new ParserArgs() { ContentSHA = "sha", ModDependencies = new List <string> { "1" }, File = "common\\defines\\t.txt", Lines = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries), ModName = "fake" }; var parser = new Generic.DefinesParser(new CodeParser(new Logger()), null); var result = parser.Parse(args).ToList(); result.Should().NotBeNullOrEmpty(); result.Count.Should().Be(3); for (int i = 0; i < 3; i++) { result[i].ContentSHA.Should().Be("sha"); result[i].Dependencies.First().Should().Be("1"); result[i].File.Should().Be("common\\defines\\t.txt"); switch (i) { case 0: result[i].Code.Trim().Should().Be(sb2.ToString().Trim()); result[i].Id.Should().Be("FOV"); result[i].ValueType.Should().Be(ValueType.SpecialVariable); result[i].Type.Should().Be("common\\defines\\NCamera-txt"); break; case 1: result[i].Code.Trim().Should().Be(sb3.ToString().Trim()); result[i].Id.Should().Be("ENTITY_SPRITE_DESIGN_ENTRY_CAM_DIR"); result[i].ValueType.Should().Be(ValueType.SpecialVariable); result[i].Type.Should().Be("common\\defines\\NCamera-txt"); break; case 2: result[i].Code.Trim().Should().Be(sb4.ToString().Trim()); result[i].Id.Should().Be("CAMERA_DISTANCE_TO_ZOOM"); result[i].ValueType.Should().Be(ValueType.SpecialVariable); result[i].Type.Should().Be("common\\defines\\NGraphics-txt"); break; default: break; } result[i].ModName.Should().Be("fake"); } }
public void Parse_gfx_variable_should_yield_results() { DISetup.SetupContainer(); var sb = new StringBuilder(); sb.AppendLine(@"@test1 = 0"); sb.AppendLine(@"spriteTypes = {"); sb.AppendLine(@" @test2 = 1"); sb.AppendLine(@" spriteType = {"); sb.AppendLine(@" @test3 = 1"); sb.AppendLine(@" name = ""GFX_dmm_mod_1"""); sb.AppendLine(@" }"); sb.AppendLine(@"}"); var args = new ParserArgs() { ContentSHA = "sha", ModDependencies = new List <string> { "1" }, File = "gfx\\gfx.gfx", Lines = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries), ModName = "fake" }; var parser = new GraphicsParser(new CodeParser(new Logger()), null); var result = parser.Parse(args).ToList(); result.Should().NotBeNullOrEmpty(); result.Count.Should().Be(4); for (int i = 0; i < 4; i++) { result[i].ContentSHA.Should().Be("sha"); result[i].Dependencies.First().Should().Be("1"); result[i].File.Should().Be("gfx\\gfx.gfx"); switch (i) { case 0: result[i].Id.Should().Be("@test1"); result[i].CodeTag.Should().BeNullOrWhiteSpace(); result[i].ValueType.Should().Be(ValueType.Variable); break; case 1: result[i].Id.Should().Be("@test2"); result[i].CodeTag.Should().Be("spriteTypes"); result[i].ValueType.Should().Be(ValueType.Variable); break; case 2: result[i].Id.Should().Be("GFX_dmm_mod_1"); result[i].ValueType.Should().Be(ValueType.Object); break; case 3: result[i].Id.Should().Be("@test3"); result[i].CodeTag.Should().Be("spriteTypes"); result[i].ValueType.Should().Be(ValueType.Variable); break; default: break; } result[i].ModName.Should().Be("fake"); result[i].Type.Should().Be("gfx\\gfx"); } }
public void Parse_gfx_bitmap_type_override_should_yield_results() { DISetup.SetupContainer(); var sb = new StringBuilder(); sb.AppendLine(@"bitmapfonts = {"); sb.AppendLine(@" bitmapfont_override = {"); sb.AppendLine(@" name = ""large_title_font"""); sb.AppendLine(@" ttf_font = ""Easter_bigger"""); sb.AppendLine(@" ttf_size = ""30"""); sb.AppendLine(@" languages = { ""l_russian"" ""l_polish"" }"); sb.AppendLine(@" } "); sb.AppendLine(@" bitmapfont_override = {"); sb.AppendLine(@" name = ""large_title_font"""); sb.AppendLine(@" ttf_font = ""Easter_bigger"""); sb.AppendLine(@" ttf_size = ""30"""); sb.AppendLine(@" languages = { ""l_russian"" ""l_polish"" }"); sb.AppendLine(@" } "); sb.AppendLine(@"}"); var sb2 = new StringBuilder(); sb2.AppendLine(@"bitmapfonts = {"); sb2.AppendLine(@" bitmapfont_override = {"); sb2.AppendLine(@" name = ""large_title_font"""); sb2.AppendLine(@" ttf_font = ""Easter_bigger"""); sb2.AppendLine(@" ttf_size = ""30"""); sb2.AppendLine(@" languages = {"); sb2.AppendLine(@" ""l_russian"""); sb2.AppendLine(@" ""l_polish"""); sb2.AppendLine(@" }"); sb2.AppendLine(@" }"); sb2.AppendLine(@"}"); var args = new ParserArgs() { ContentSHA = "sha", ModDependencies = new List <string> { "1" }, File = "gfx\\gfx.gfx", Lines = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries), ModName = "fake" }; var parser = new GraphicsParser(new CodeParser(new Logger()), null); var result = parser.Parse(args).ToList(); result.Should().NotBeNullOrEmpty(); result.Count.Should().Be(2); for (int i = 0; i < 2; i++) { result[i].ContentSHA.Should().Be("sha"); result[i].Dependencies.First().Should().Be("1"); result[i].File.Should().Be("gfx\\gfx.gfx"); switch (i) { case 0: result[i].Id.Should().Be("l_polish-l_russian-large_title_font"); result[i].Code.Should().Be(sb2.ToString().Trim().ReplaceTabs()); result[i].ValueType.Should().Be(ValueType.Object); break; case 1: result[i].Id.Should().Be("l_polish-l_russian-large_title_font"); result[i].Code.Should().Be(sb2.ToString().Trim().ReplaceTabs()); result[i].ValueType.Should().Be(ValueType.Object); break; default: break; } result[i].ModName.Should().Be("fake"); result[i].Type.Should().Be("gfx\\gfx"); } }
public void Parse_levels_should_yield_results() { DISetup.SetupContainer(); var sb = new StringBuilder(); sb.AppendLine(@"leader_attack_skills = {"); sb.AppendLine(@""); sb.AppendLine(@" ### NAVY ###"); sb.AppendLine(@" 1 = {"); sb.AppendLine(@" cost = 100"); sb.AppendLine(@" type = navy"); sb.AppendLine(@" modifier = {"); sb.AppendLine(@" naval_damage_factor = 0.05"); sb.AppendLine(@" }"); sb.AppendLine(@" }"); sb.AppendLine(@""); sb.AppendLine(@" 2 = {"); sb.AppendLine(@" cost = 200"); sb.AppendLine(@" type = navy"); sb.AppendLine(@" modifier = {"); sb.AppendLine(@" naval_damage_factor = 0.10"); sb.AppendLine(@" }"); sb.AppendLine(@" }"); sb.AppendLine(@"}"); var args = new ParserArgs() { ContentSHA = "sha", ModDependencies = new List <string> { "1" }, File = "common\\unit_leader\\fake.txt", Lines = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries), ModName = "fake" }; var parser = new Games.HOI4.InnerLayerParser(new CodeParser(new Logger()), null); var result = parser.Parse(args).ToList(); result.Should().NotBeNullOrEmpty(); result.Count.Should().Be(1); for (int i = 0; i < 1; i++) { result[i].ContentSHA.Should().Be("sha"); result[i].Dependencies.First().Should().Be("1"); result[i].File.Should().Be("common\\unit_leader\\fake.txt"); switch (i) { case 0: result[i].Id.Should().Be("leader_attack_skills"); result[i].ValueType.Should().Be(ValueType.Object); break; default: break; } result[i].ModName.Should().Be("fake"); result[i].Type.Should().Be("common\\unit_leader\\txt"); } }
public ProductQueryBuilderTest(ITestOutputHelper output) { _output = output; _builder = DISetup.GetAutofacContainerBuilder(); _context = null; }
public void Parse_complex_type_edge_case_should_yield_results() { DISetup.SetupContainer(); var sb = new StringBuilder(); sb.AppendLine(@" NInterface = { TOPBAR_BUTTONS_SHORTCUTS = {"); sb.AppendLine(@" ""contacts"" ""F1"""); sb.AppendLine(@" ""situation"" ""F2"""); sb.AppendLine(@" ""technology"" ""F3"""); sb.AppendLine(@" ""empire"" ""F4"""); sb.AppendLine(@" ""leaders"" ""F5"""); sb.AppendLine(@" ""species"" ""F6"""); sb.AppendLine(@" ""ship_designer"" ""F7"""); sb.AppendLine(@" ""fleet_manager"" ""F8"""); sb.AppendLine(@" ""edicts"" ""F9"""); sb.AppendLine(@" ""policies"" ""F10"""); sb.AppendLine(@" }}"); var sb2 = new StringBuilder(); sb2.AppendLine(@"NInterface = {"); sb2.AppendLine(@" TOPBAR_BUTTONS_SHORTCUTS = {"); sb2.AppendLine(@" ""contacts"""); sb2.AppendLine(@" ""F1"""); sb2.AppendLine(@" ""situation"""); sb2.AppendLine(@" ""F2"""); sb2.AppendLine(@" ""technology"""); sb2.AppendLine(@" ""F3"""); sb2.AppendLine(@" ""empire"""); sb2.AppendLine(@" ""F4"""); sb2.AppendLine(@" ""leaders"""); sb2.AppendLine(@" ""F5"""); sb2.AppendLine(@" ""species"""); sb2.AppendLine(@" ""F6"""); sb2.AppendLine(@" ""ship_designer"""); sb2.AppendLine(@" ""F7"""); sb2.AppendLine(@" ""fleet_manager"""); sb2.AppendLine(@" ""F8"""); sb2.AppendLine(@" ""edicts"""); sb2.AppendLine(@" ""F9"""); sb2.AppendLine(@" ""policies"""); sb2.AppendLine(@" ""F10"""); sb2.AppendLine(@" }"); sb2.Append('}'); var args = new ParserArgs() { ContentSHA = "sha", ModDependencies = new List <string> { "1" }, File = "common\\defines\\t.txt", Lines = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries), ModName = "fake" }; var parser = new Generic.DefinesParser(new CodeParser(new Logger()), null); var result = parser.Parse(args).ToList(); result.Should().NotBeNullOrEmpty(); result.Count.Should().Be(1); for (int i = 0; i < 1; i++) { result[i].ContentSHA.Should().Be("sha"); result[i].Dependencies.First().Should().Be("1"); result[i].File.Should().Be("common\\defines\\t.txt"); switch (i) { case 0: result[i].Id.Should().Be("TOPBAR_BUTTONS_SHORTCUTS"); result[i].ValueType.Should().Be(ValueType.SpecialVariable); result[i].Code.Should().Be(sb2.ToString().ReplaceTabs()); result[i].Type.Should().Be("common\\defines\\NInterface-txt"); break; default: break; } result[i].ModName.Should().Be("fake"); } }
public async Task Should_export_hash_report() { var storageProvider = new Mock <IStorageProvider>(); var mapper = new Mock <IMapper>(); var gameService = new Mock <IGameService>(); gameService.Setup(s => s.GetSelected()).Returns(new Game() { Type = "no-items", UserDirectory = "C:\\fake", GameFolders = new List <string>() { "test" } }); var collections = new List <IModCollection>() { new ModCollection() { IsSelected = true, Mods = new List <string>() { "mod/fakemod.mod" }, Name = "test", Game = "no-items" } }; storageProvider.Setup(s => s.GetModCollections()).Returns(() => { return(collections); }); var modExport = new Mock <IModCollectionExporter>(); var hashExport = new Mock <IReportExportService>(); hashExport.Setup(p => p.ExportAsync(It.IsAny <IEnumerable <IHashReport> >(), It.IsAny <string>())).ReturnsAsync((IEnumerable <IHashReport> report, string path) => { if (report.Count() == 1 && report.FirstOrDefault().Reports.Count == 1 && report.FirstOrDefault().Reports.FirstOrDefault().File == "test\\test" && report.FirstOrDefault().Reports.FirstOrDefault().Hash == "2") { return(true); } return(false); }); var messageBus = new Mock <IMessageBus>(); messageBus.Setup(p => p.PublishAsync(It.IsAny <IMessageBusEvent>())); messageBus.Setup(p => p.Publish(It.IsAny <IMessageBusEvent>())); var reader = new Mock <IReader>(); reader.Setup(p => p.GetFileInfo(It.IsAny <string>(), It.IsAny <string>())).Returns(new FileInfo() { ContentSHA = "2" }); var modWriter = new Mock <IModWriter>(); modWriter.Setup(p => p.ModDirectoryExistsAsync(It.IsAny <ModWriterParameters>())).Returns((ModWriterParameters p) => { return(Task.FromResult(false)); }); DISetup.SetupContainer(); var service = new ModCollectionService(messageBus.Object, hashExport.Object, new Cache(), null, reader.Object, modWriter.Object, null, gameService.Object, modExport.Object, storageProvider.Object, mapper.Object); var result = await service.ExportHashReportAsync(new List <IMod>() { new Mod() { Name = "test", Files = new List <string>() { "test\\test" } } }, "test"); result.Should().BeTrue(); }
public async Task Should_import_hash() { var storageProvider = new Mock <IStorageProvider>(); var mapper = new Mock <IMapper>(); var gameService = new Mock <IGameService>(); gameService.Setup(s => s.GetSelected()).Returns(new Game() { Type = "no-items", UserDirectory = "C:\\fake", GameFolders = new List <string>() { "test" } }); var collections = new List <IModCollection>() { new ModCollection() { IsSelected = true, Mods = new List <string>() { "mod/fakemod.mod" }, Name = "test", Game = "no-items" } }; storageProvider.Setup(s => s.GetModCollections()).Returns(() => { return(collections); }); var modExport = new Mock <IModCollectionExporter>(); var innerReports = new List <IHashFileReport>() { new HashFileReport() { File = "test\\1", Hash = "2" } }; var outerReports = new List <IHashReport>() { new HashReport() { Name = "testreport", Reports = innerReports } }; var hashExport = new Mock <IReportExportService>(); hashExport.Setup(p => p.GetCollectionReports(It.IsAny <IReadOnlyCollection <IHashReport> >())).Returns((IReadOnlyCollection <IHashReport> hashReports) => { if (hashReports != null) { return(hashReports.Where(p => p.ReportType == HashReportType.Collection).ToList()); } return(null); }); hashExport.Setup(p => p.CompareReports(It.IsAny <IReadOnlyCollection <IHashReport> >(), It.IsAny <IReadOnlyCollection <IHashReport> >())).Returns((IReadOnlyCollection <IHashReport> first, IReadOnlyCollection <IHashReport> second) => { return(outerReports); }); var messageBus = new Mock <IMessageBus>(); messageBus.Setup(p => p.PublishAsync(It.IsAny <IMessageBusEvent>())); messageBus.Setup(p => p.Publish(It.IsAny <IMessageBusEvent>())); var reader = new Mock <IReader>(); reader.Setup(p => p.GetFileInfo(It.IsAny <string>(), It.IsAny <string>())).Returns(new FileInfo() { FileName = "2", ContentSHA = "3" }); var modWriter = new Mock <IModWriter>(); modWriter.Setup(p => p.ModDirectoryExistsAsync(It.IsAny <ModWriterParameters>())).Returns((ModWriterParameters p) => { return(Task.FromResult(false)); }); DISetup.SetupContainer(); var service = new ModCollectionService(messageBus.Object, hashExport.Object, new Cache(), null, reader.Object, modWriter.Object, null, gameService.Object, modExport.Object, storageProvider.Object, mapper.Object); var result = await service.ImportHashReportAsync(new List <IMod>() { new Mod() { Name = "testreport", Files = new List <string>() { "test\\test" } } }, outerReports); result.Should().NotBeNull(); result.Count().Should().Be(1); result.FirstOrDefault().Reports.Count.Should().Be(1); }
public void Parse_should_yield_results() { DISetup.SetupContainer(); var sb = new StringBuilder(); sb.AppendLine(@"@test = 1"); sb.AppendLine(@""); sb.AppendLine(@"namespace = dmm_mod"); sb.AppendLine(@""); sb.AppendLine(@"country_event = {"); sb.AppendLine(@" id = dmm_mod.1"); sb.AppendLine(@" hide_window = yes"); sb.AppendLine(@" is_triggered_only = yes"); sb.AppendLine(@""); sb.AppendLine(@" trigger = {"); sb.AppendLine(@" has_global_flag = dmm_mod_1"); sb.AppendLine(@" }"); sb.AppendLine(@""); sb.AppendLine(@" after = {"); sb.AppendLine(@" remove_global_flag = dmm_mod_1_opened"); sb.AppendLine(@" }"); sb.AppendLine(@""); sb.AppendLine(@" immediate = {"); sb.AppendLine(@" country_event = {"); sb.AppendLine(@" id = asl_options.1"); sb.AppendLine(@" }"); sb.AppendLine(@" }"); sb.AppendLine(@"}"); var sb2 = new StringBuilder(); sb2.AppendLine(@"country_event = {"); sb2.AppendLine(@" id = dmm_mod.1"); sb2.AppendLine(@" hide_window = yes"); sb2.AppendLine(@" is_triggered_only = yes"); sb2.AppendLine(@" trigger = {"); sb2.AppendLine(@" has_global_flag = dmm_mod_1"); sb2.AppendLine(@" }"); sb2.AppendLine(@" after = {"); sb2.AppendLine(@" remove_global_flag = dmm_mod_1_opened"); sb2.AppendLine(@" }"); sb2.AppendLine(@" immediate = {"); sb2.AppendLine(@" country_event = {"); sb2.AppendLine(@" id = asl_options.1"); sb2.AppendLine(@" }"); sb2.AppendLine(@" }"); sb2.AppendLine(@"}"); var args = new ParserArgs() { ContentSHA = "sha", ModDependencies = new List <string> { "1" }, File = "events\\fake.txt", Lines = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries), ModName = "fake" }; var parser = new KeyParser(new CodeParser(new Logger()), null); var result = parser.Parse(args).ToList(); result.Should().NotBeNullOrEmpty(); result.Count().Should().Be(3); for (int i = 0; i < 3; i++) { result[i].ContentSHA.Should().Be("sha"); result[i].Dependencies.First().Should().Be("1"); result[i].File.Should().Be("events\\fake.txt"); switch (i) { case 0: result[i].Code.Trim().Should().Be("@test = 1"); result[i].Id.Should().Be("@test"); result[i].ValueType.Should().Be(Common.ValueType.Variable); break; case 1: result[i].Id.Should().Be("fake-namespace"); result[i].ValueType.Should().Be(Common.ValueType.Namespace); break; case 2: result[i].Id.Should().Be("dmm_mod.1"); result[i].Code.Should().Be(sb2.ToString().Trim().ReplaceTabs()); result[i].ValueType.Should().Be(Common.ValueType.Object); break; default: break; } result[i].ModName.Should().Be("fake"); result[i].Type.Should().Be("events\\txt"); } }
public async Task Should_import_hash() { var storageProvider = new Mock <IStorageProvider>(); var mapper = new Mock <IMapper>(); var hashExport = new Mock <IReportExportService>(); var preferencesService = new Mock <IPreferencesService>(); var innerReports = new List <IHashFileReport>() { new HashFileReport() { File = "test\\1", Hash = "2" } }; var outerReports = new List <IHashReport>() { new HashReport() { Name = "test", Reports = innerReports, ReportType = HashReportType.Game } }; hashExport.Setup(p => p.GetGameReports(It.IsAny <IReadOnlyCollection <IHashReport> >())).Returns((IReadOnlyCollection <IHashReport> hashReports) => { if (hashReports != null) { return(hashReports.Where(p => p.ReportType == HashReportType.Game).ToList()); } return(null); }); hashExport.Setup(p => p.CompareReports(It.IsAny <IReadOnlyCollection <IHashReport> >(), It.IsAny <IReadOnlyCollection <IHashReport> >())).Returns((IReadOnlyCollection <IHashReport> first, IReadOnlyCollection <IHashReport> second) => { return(outerReports); }); var messageBus = new Mock <IMessageBus>(); messageBus.Setup(p => p.PublishAsync(It.IsAny <IMessageBusEvent>())); messageBus.Setup(p => p.Publish(It.IsAny <IMessageBusEvent>())); var reader = new Mock <IReader>(); reader.Setup(p => p.GetFileInfo(It.IsAny <string>(), It.IsAny <string>())).Returns(new IO.FileInfo() { FileName = "2", ContentSHA = "3" }); reader.Setup(p => p.GetFiles(It.IsAny <string>())).Returns(new List <string>() { "test\\test" }); DISetup.SetupContainer(); var service = new GameService(messageBus.Object, hashExport.Object, reader.Object, storageProvider.Object, preferencesService.Object, new Mock <IMapper>().Object); var result = await service.ImportHashReportAsync(new Game() { GameFolders = new List <string>() { "test" } }, outerReports); result.Should().NotBeNull(); result.Count().Should().Be(1); result.FirstOrDefault().Reports.Count.Should().Be(1); }
public void Should_add_new_game() { DISetup.SetupContainer(); var dbMock = GetDbMock(); var key = "test2"; var storage = new Storage(dbMock, new Mock <IMapper>().Object); var game = new GameType() { Name = key, SteamAppId = 1, ChecksumFolders = new List <string>() { "test" }, GameFolders = new List <string>() { "testgame" }, LogLocation = "test.log", UserDirectory = "user_directory", WorkshopDirectory = new List <string>() { "workshop1" }, BaseSteamGameDirectory = "base", ExecutablePath = "exe", ExecutableArgs = "args", LauncherSettingsFileName = "settings", LauncherSettingsPrefix = "prefix", AdvancedFeatures = GameAdvancedFeatures.ReadOnly, RemoteSteamUserDirectory = new List <string>() { "remotesave" }, Abrv = "abrv", ParadoxGameId = "pdxId", DLCContainer = "container", GameIndexCacheVersion = 2 }; storage.RegisterGame(game); dbMock.Games.Count.Should().Be(2); dbMock.Games.FirstOrDefault(p => p.Name == key).Should().NotBeNull(); dbMock.Games.FirstOrDefault(p => p.Name == key).UserDirectory.Should().Be("user_directory"); dbMock.Games.FirstOrDefault(p => p.Name == key).SteamAppId.Should().Be(1); dbMock.Games.FirstOrDefault(p => p.Name == key).WorkshopDirectory.FirstOrDefault().Should().Be("workshop1"); dbMock.Games.FirstOrDefault(p => p.Name == key).LogLocation.Should().Be("test.log"); dbMock.Games.FirstOrDefault(p => p.Name == key).ChecksumFolders.FirstOrDefault().Should().Be("test"); dbMock.Games.FirstOrDefault(p => p.Name == key).GameFolders.FirstOrDefault().Should().Be("testgame"); dbMock.Games.FirstOrDefault(p => p.Name == key).BaseSteamGameDirectory.Should().Be("base"); dbMock.Games.FirstOrDefault(p => p.Name == key).ExecutablePath.Should().Be("exe"); dbMock.Games.FirstOrDefault(p => p.Name == key).ExecutableArgs.Should().Be("args"); dbMock.Games.FirstOrDefault(p => p.Name == key).LauncherSettingsFileName.Should().Be("settings"); dbMock.Games.FirstOrDefault(p => p.Name == key).LauncherSettingsPrefix.Should().Be("prefix"); dbMock.Games.FirstOrDefault(p => p.Name == key).RemoteSteamUserDirectory.FirstOrDefault().Should().Be("remotesave"); dbMock.Games.FirstOrDefault(p => p.Name == key).AdvancedFeatures.Should().Be(GameAdvancedFeatures.ReadOnly); dbMock.Games.FirstOrDefault(p => p.Name == key).Abrv.Should().Be("abrv"); dbMock.Games.FirstOrDefault(p => p.Name == key).ParadoxGameId.Should().Be("pdxId"); dbMock.Games.FirstOrDefault(p => p.Name == key).DLCContainer.Should().Be("container"); dbMock.Games.FirstOrDefault(p => p.Name == key).GameIndexCacheVersion.Should().Be(2); }
public void Parse_gfx_should_yield_results() { DISetup.SetupContainer(); var sb = new StringBuilder(); sb.AppendLine(@"bitmapfonts = {"); sb.AppendLine(@""); sb.AppendLine(@" ### ship size icons ###"); sb.AppendLine(@""); sb.AppendLine(@" bitmapfont = {"); sb.AppendLine(@" name = ""GFX_text_military_size_1"""); sb.AppendLine(@" texturefile = ""gfx/interface/icons/text_icons/icon_text_military_size_1.dds"""); sb.AppendLine(@" }"); sb.AppendLine(@" "); sb.AppendLine(@" bitmapfont = {"); sb.AppendLine(@" name = ""GFX_text_military_size_2"""); sb.AppendLine(@" texturefile = ""gfx/interface/icons/text_icons/icon_text_military_size_2.dds"""); sb.AppendLine(@" }"); sb.AppendLine(@"}"); var sb2 = new StringBuilder(); sb2.AppendLine(@"bitmapfonts = {"); sb2.AppendLine(@" bitmapfont = {"); sb2.AppendLine(@" name = ""GFX_text_military_size_1"""); sb2.AppendLine(@" texturefile = ""gfx/interface/icons/text_icons/icon_text_military_size_1.dds"""); sb2.AppendLine(@" }"); sb2.AppendLine(@"}"); var sb3 = new System.Text.StringBuilder(); sb3.AppendLine(@"bitmapfonts = {"); sb3.AppendLine(@" bitmapfont = {"); sb3.AppendLine(@" name = ""GFX_text_military_size_2"""); sb3.AppendLine(@" texturefile = ""gfx/interface/icons/text_icons/icon_text_military_size_2.dds"""); sb3.AppendLine(@" }"); sb3.AppendLine(@"}"); var args = new ParserArgs() { ContentSHA = "sha", ModDependencies = new List <string> { "1" }, File = "gfx\\gfx.gfx", Lines = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries), ModName = "fake" }; var parser = new GraphicsParser(new CodeParser(new Logger()), null); var result = parser.Parse(args).ToList(); result.Should().NotBeNullOrEmpty(); result.Count.Should().Be(2); for (int i = 0; i < 2; i++) { result[i].ContentSHA.Should().Be("sha"); result[i].Dependencies.First().Should().Be("1"); result[i].File.Should().Be("gfx\\gfx.gfx"); switch (i) { case 0: result[i].Id.Should().Be("GFX_text_military_size_1"); result[i].Code.Should().Be(sb2.ToString().Trim().ReplaceTabs()); result[i].ValueType.Should().Be(ValueType.Object); break; case 1: result[i].Id.Should().Be("GFX_text_military_size_2"); result[i].Code.Should().Be(sb3.ToString().Trim().ReplaceTabs()); result[i].ValueType.Should().Be(ValueType.Object); break; default: break; } result[i].ModName.Should().Be("fake"); result[i].Type.Should().Be("gfx\\gfx"); } }
public void Should_add_and_return_added_game() { DISetup.SetupContainer(); var dbMock = GetDbMock(); var key = "test2"; var mapper = new Mock <IMapper>(); mapper.Setup(p => p.Map <List <IGameType> >(It.IsAny <IEnumerable <IGameType> >())).Returns(() => { return(dbMock.Games.ToList()); }); var storage = new Storage(dbMock, mapper.Object); var game = new GameType() { Name = key, SteamAppId = 1, ChecksumFolders = new List <string>() { "test" }, GameFolders = new List <string>() { "testgame" }, LogLocation = "test.log", UserDirectory = "user_directory", WorkshopDirectory = new List <string>() { "workshop1" }, BaseSteamGameDirectory = "base", ExecutablePath = "exe", ExecutableArgs = "args", LauncherSettingsFileName = "settings", LauncherSettingsPrefix = "prefix", AdvancedFeaturesSupported = true, RemoteSteamUserDirectory = new List <string>() { "remotesave" }, Abrv = "abrv" }; storage.RegisterGame(game); var result = storage.GetGames(); result.Count().Should().Be(2); result.FirstOrDefault(p => p.Name == key).Should().NotBeNull(); result.FirstOrDefault(p => p.Name == key).UserDirectory.Should().Be("user_directory"); result.FirstOrDefault(p => p.Name == key).SteamAppId.Should().Be(1); result.FirstOrDefault(p => p.Name == key).WorkshopDirectory.FirstOrDefault().Should().Be("workshop1"); result.FirstOrDefault(p => p.Name == key).LogLocation.Should().Be("test.log"); result.FirstOrDefault(p => p.Name == key).ChecksumFolders.FirstOrDefault().Should().Be("test"); result.FirstOrDefault(p => p.Name == key).GameFolders.FirstOrDefault().Should().Be("testgame"); result.FirstOrDefault(p => p.Name == key).BaseSteamGameDirectory.Should().Be("base"); result.FirstOrDefault(p => p.Name == key).ExecutablePath.Should().Be("exe"); result.FirstOrDefault(p => p.Name == key).ExecutableArgs.Should().Be("args"); result.FirstOrDefault(p => p.Name == key).LauncherSettingsFileName.Should().Be("settings"); result.FirstOrDefault(p => p.Name == key).LauncherSettingsPrefix.Should().Be("prefix"); result.FirstOrDefault(p => p.Name == key).RemoteSteamUserDirectory.FirstOrDefault().Should().Be("remotesave"); result.FirstOrDefault(p => p.Name == key).AdvancedFeaturesSupported.Should().BeTrue(); result.FirstOrDefault(p => p.Name == key).Abrv.Should().Be("abrv"); }
public void Parse_gui_edge_case_should_yield_results() { DISetup.SetupContainer(); var sb = new StringBuilder(); sb.AppendLine(@"guiTypes = { "); sb.AppendLine(@" containerWindowType = { "); sb.AppendLine(@" name = ""test"""); sb.AppendLine(@" } "); sb.AppendLine(@"}"); sb.AppendLine(@"guiTypes = { "); sb.AppendLine(@" containerWindowType = { "); sb.AppendLine(@" name = ""test2"""); sb.AppendLine(@" } "); sb.AppendLine(@"}"); var sb2 = new StringBuilder(); sb2.AppendLine(@"guiTypes = {"); sb2.AppendLine(@" containerWindowType = {"); sb2.AppendLine(@" name = ""test"""); sb2.AppendLine(@" }"); sb2.AppendLine(@"}"); var sb3 = new StringBuilder(); sb3.AppendLine(@"guiTypes = {"); sb3.AppendLine(@" containerWindowType = {"); sb3.AppendLine(@" name = ""test2"""); sb3.AppendLine(@" }"); sb3.AppendLine(@"}"); var args = new ParserArgs() { ContentSHA = "sha", ModDependencies = new List <string> { "1" }, File = "gui\\gui.gui", Lines = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries), ModName = "fake" }; var parser = new GraphicsParser(new CodeParser(new Logger()), null); var result = parser.Parse(args).ToList(); result.Should().NotBeNullOrEmpty(); result.Count.Should().Be(2); for (int i = 0; i < 2; i++) { result[i].ContentSHA.Should().Be("sha"); result[i].Dependencies.First().Should().Be("1"); result[i].File.Should().Be("gui\\gui.gui"); switch (i) { case 0: result[i].Id.Should().Be("test"); result[i].Code.Should().Be(sb2.ToString().Trim().ReplaceTabs()); result[i].ValueType.Should().Be(ValueType.Object); break; case 1: result[i].Id.Should().Be("test2"); result[i].Code.Should().Be(sb3.ToString().Trim().ReplaceTabs()); result[i].ValueType.Should().Be(ValueType.Object); break; } result[i].ModName.Should().Be("fake"); result[i].Type.Should().Be("gui\\gui"); } }
public void Parse_lua_multiple_complex_object_should_yield_results() { DISetup.SetupContainer(); var sb = new StringBuilder(); sb.AppendLine(@"NDefines_Graphics = {"); sb.AppendLine(@" NInterface = {"); sb.AppendLine(@" NO_COMBATS_COLOR = { 0.0, 0.0, 0.8 }, -- Color for icons if all combats are successful"); sb.AppendLine(@" MAP_MODE_IDEOLOGY_COLOR_TRANSPARENCY = 1"); sb.AppendLine(@" },"); sb.AppendLine(@" NInterface2 = {"); sb.AppendLine(@" NO_COMBATS_COLOR = { 0.0, 0.0, 0.8 }, -- Color for icons if all combats are successful"); sb.AppendLine(@" MAP_MODE_IDEOLOGY_COLOR_TRANSPARENCY = 1"); sb.AppendLine(@" }"); sb.AppendLine(@"}"); var args = new ParserArgs() { ContentSHA = "sha", ModDependencies = new List <string> { "1" }, File = "common\\defines\\t.lua", Lines = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries), ModName = "fake" }; var parser = new Generic.DefinesParser(new CodeParser(new Logger()), null); var result = parser.Parse(args).ToList(); result.Should().NotBeNullOrEmpty(); result.Count.Should().Be(4); for (int i = 0; i < 4; i++) { result[i].ContentSHA.Should().Be("sha"); result[i].Dependencies.First().Should().Be("1"); result[i].File.Should().Be("common\\defines\\t.lua"); switch (i) { case 0: result[i].Id.Should().Be("NO_COMBATS_COLOR"); result[i].ValueType.Should().Be(ValueType.SpecialVariable); result[i].Type.Should().Be("common\\defines\\NDefines_Graphics.NInterface-txt"); result[i].Code.Should().Be("NDefines_Graphics.NInterface.NO_COMBATS_COLOR = {\r\n 0,\r\n 0,\r\n 0.8\r\n}"); break; case 1: result[i].Id.Should().Be("MAP_MODE_IDEOLOGY_COLOR_TRANSPARENCY"); result[i].ValueType.Should().Be(ValueType.SpecialVariable); result[i].Type.Should().Be("common\\defines\\NDefines_Graphics.NInterface-txt"); result[i].Code.Should().Be("NDefines_Graphics.NInterface.MAP_MODE_IDEOLOGY_COLOR_TRANSPARENCY = 1"); break; case 2: result[i].Id.Should().Be("NO_COMBATS_COLOR"); result[i].ValueType.Should().Be(ValueType.SpecialVariable); result[i].Type.Should().Be("common\\defines\\NDefines_Graphics.NInterface2-txt"); result[i].Code.Should().Be("NDefines_Graphics.NInterface2.NO_COMBATS_COLOR = {\r\n 0,\r\n 0,\r\n 0.8\r\n}"); break; case 3: result[i].Id.Should().Be("MAP_MODE_IDEOLOGY_COLOR_TRANSPARENCY"); result[i].ValueType.Should().Be(ValueType.SpecialVariable); result[i].Type.Should().Be("common\\defines\\NDefines_Graphics.NInterface2-txt"); result[i].Code.Should().Be("NDefines_Graphics.NInterface2.MAP_MODE_IDEOLOGY_COLOR_TRANSPARENCY = 1"); break; default: break; } result[i].ModName.Should().Be("fake"); } }
public void Parse_gui_variable_should_yield_results() { DISetup.SetupContainer(); var sb = new StringBuilder(); sb.AppendLine(@"@sort_button_height = 80"); sb.AppendLine(@"guiTypes = {"); sb.AppendLine(@" @entry_info_height = 17"); sb.AppendLine(@" # Button in the lower right of the main view, opening the Alliance View."); sb.AppendLine(@" containerWindowType = {"); sb.AppendLine(@" @why_am_i_here = 17"); sb.AppendLine(@" name = ""alliance_button_window"""); sb.AppendLine(@" position = { x = -458 y = 43 }"); sb.AppendLine(@" }"); sb.AppendLine(@"}"); var args = new ParserArgs() { ContentSHA = "sha", ModDependencies = new List <string> { "1" }, File = "gui\\gui.gui", Lines = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries), ModName = "fake" }; var parser = new GraphicsParser(new CodeParser(new Logger()), null); var result = parser.Parse(args).ToList(); result.Should().NotBeNullOrEmpty(); result.Count.Should().Be(4); for (int i = 0; i < 4; i++) { result[i].ContentSHA.Should().Be("sha"); result[i].Dependencies.First().Should().Be("1"); result[i].File.Should().Be("gui\\gui.gui"); switch (i) { case 0: result[i].Id.Should().Be("@sort_button_height"); result[i].CodeTag.Should().BeNullOrWhiteSpace(); result[i].ValueType.Should().Be(ValueType.Variable); break; case 1: result[i].Id.Should().Be("@entry_info_height"); result[i].CodeTag.Should().Be("guiTypes"); result[i].ValueType.Should().Be(ValueType.Variable); break; case 2: result[i].Id.Should().Be("alliance_button_window"); result[i].ValueType.Should().Be(ValueType.Object); break; case 3: result[i].Id.Should().Be("@why_am_i_here"); result[i].CodeTag.Should().Be("guiTypes"); result[i].ValueType.Should().Be(ValueType.Variable); break; default: break; } result[i].ModName.Should().Be("fake"); result[i].Type.Should().Be("gui\\gui"); } }
public void Parse_multiple_types_should_yield_results() { DISetup.SetupContainer(); var sb = new StringBuilder(); sb.AppendLine(@"NArmy = {"); sb.AppendLine(@" ARMY_MILITARY_POWER_EXPONENT = 0.5 # 0.65"); sb.AppendLine(@"}"); sb.AppendLine(@""); sb.AppendLine(@"NGameplay = {"); sb.AppendLine(@" ASCENSION_PERKS_SLOTS = 12"); sb.AppendLine(@" JUMP_DRIVE_COOLDOWN = 0"); sb.AppendLine(@"}"); var args = new ParserArgs() { ContentSHA = "sha", ModDependencies = new List <string> { "1" }, File = "common\\defines\\t.txt", Lines = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries), ModName = "fake" }; var parser = new Generic.DefinesParser(new CodeParser(new Logger()), null); var result = parser.Parse(args).ToList(); result.Should().NotBeNullOrEmpty(); result.Count.Should().Be(3); for (int i = 0; i < 1; i++) { result[i].ContentSHA.Should().Be("sha"); result[i].Dependencies.First().Should().Be("1"); result[i].File.Should().Be("common\\defines\\t.txt"); switch (i) { case 0: result[i].Id.Should().Be("ARMY_MILITARY_POWER_EXPONENT"); result[i].ValueType.Should().Be(ValueType.SpecialVariable); result[i].Type.Should().Be("common\\defines\\NArmy-txt"); result[i].Code.Should().Be("NArmy = {\r\n ARMY_MILITARY_POWER_EXPONENT = 0.5\r\n}"); break; case 1: result[i].Id.Should().Be("ASCENSION_PERKS_SLOTS"); result[i].ValueType.Should().Be(ValueType.SpecialVariable); result[i].Type.Should().Be("common\\defines\\NGameplay-txt"); result[i].Code.Should().Be("NGameplay = {\r\n ASCENSION_PERKS_SLOTS = 12\r\n}"); break; case 2: result[i].Id.Should().Be("JUMP_DRIVE_COOLDOWN"); result[i].ValueType.Should().Be(ValueType.SpecialVariable); result[i].Type.Should().Be("common\\defines\\NGameplay-txt"); result[i].Code.Should().Be("NGameplay = {\r\n JUMP_DRIVE_COOLDOWN = 0\r\n}"); break; default: break; } result[i].ModName.Should().Be("fake"); } }
public void Parse_should_yield_results() { DISetup.SetupContainer(); var sb = new StringBuilder(); sb.AppendLine(@"@test = 1"); sb.AppendLine(@""); sb.AppendLine(@"asl_mode_options_1 = {"); sb.AppendLine(@" potential = {"); sb.AppendLine(@" NOT = {"); sb.AppendLine(@" has_country_flag = asl_modify_3"); sb.AppendLine(@" has_country_flag = asl_modify_5"); sb.AppendLine(@" }"); sb.AppendLine(@" }"); sb.AppendLine(@" allow = {"); sb.AppendLine(@" always = yes"); sb.AppendLine(@" }"); sb.AppendLine(@" effect = {"); sb.AppendLine(@" }"); sb.AppendLine(@"}"); sb.AppendLine(@""); sb.AppendLine(@"asl_mode_options_3 = {"); sb.AppendLine(@" potential = {"); sb.AppendLine(@" has_country_flag = asl_modify_3"); sb.AppendLine(@" }"); sb.AppendLine(@" allow = {"); sb.AppendLine(@" always = yes"); sb.AppendLine(@" }"); sb.AppendLine(@" effect = {"); sb.AppendLine(@" }"); sb.AppendLine(@"}"); sb.AppendLine(@""); sb.AppendLine(@"asl_mode_options_5 = {"); sb.AppendLine(@" potential = {"); sb.AppendLine(@" has_country_flag = asl_modify_5"); sb.AppendLine(@" }"); sb.AppendLine(@" allow = {"); sb.AppendLine(@" always = yes"); sb.AppendLine(@" }"); sb.AppendLine(@" effect = {"); sb.AppendLine(@" }"); sb.AppendLine(@"}"); sb.AppendLine(@""); sb.AppendLine(@"### END TEMPLATE:effects ###"); var sb2 = new StringBuilder(); sb2.AppendLine(@"asl_mode_options_1 = {"); sb2.AppendLine(@" potential = {"); sb2.AppendLine(@" NOT = {"); sb2.AppendLine(@" has_country_flag = asl_modify_3"); sb2.AppendLine(@" has_country_flag = asl_modify_5"); sb2.AppendLine(@" }"); sb2.AppendLine(@" }"); sb2.AppendLine(@" allow = {"); sb2.AppendLine(@" always = yes"); sb2.AppendLine(@" }"); sb2.AppendLine(@" effect = {"); sb2.AppendLine(@" }"); sb2.AppendLine(@"}"); var args = new ParserArgs() { ContentSHA = "sha", ModDependencies = new List <string> { "1" }, File = "common\\fake\\fake.txt", Lines = sb.ToString().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries), ModName = "fake" }; var parser = new OverWrittenObjectWithPreserveFileNameParser(new CodeParser(new Logger()), null); var result = parser.Parse(args).ToList(); result.Should().NotBeNullOrEmpty(); result.Count.Should().Be(4); for (int i = 0; i < 4; i++) { result[i].ContentSHA.Should().Be("sha"); result[i].Dependencies.First().Should().Be("1"); result[i].File.Should().Be("common\\fake\\fake.txt"); switch (i) { case 0: result[i].Code.Trim().Should().Be("@test = 1"); result[i].Id.Should().Be("@test"); result[i].ValueType.Should().Be(ValueType.Variable); break; case 1: result[i].Id.Should().Be("asl_mode_options_1"); result[i].Code.Should().Be(sb2.ToString().Trim().ReplaceTabs()); result[i].ValueType.Should().Be(ValueType.OverWrittenObjectWithPreserveFileName); break; case 2: result[i].Id.Should().Be("asl_mode_options_3"); result[i].ValueType.Should().Be(ValueType.OverWrittenObjectWithPreserveFileName); break; case 3: result[i].Id.Should().Be("asl_mode_options_5"); result[i].ValueType.Should().Be(ValueType.OverWrittenObjectWithPreserveFileName); break; default: break; } result[i].ModName.Should().Be("fake"); result[i].Type.Should().Be("common\\fake\\txt"); } }
public async Task Should_install_lockable_mods() { DISetup.SetupContainer(); 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>(); bool lockSet = false; var service = GetService(storageProvider, modParser, reader, mapper, modWriter, gameService); SetupMockCase(reader, modParser); gameService.Setup(p => p.GetSelected()).Returns(new Game() { Type = "Should_install_mods", UserDirectory = AppDomain.CurrentDomain.BaseDirectory, WorkshopDirectory = "C:\\workshop" }); mapper.Setup(s => s.Map <IMod>(It.IsAny <IModObject>())).Returns((IModObject o) => { return(new Mod() { FileName = o.FileName }); }); modWriter.Setup(p => p.WriteDescriptorAsync(It.IsAny <ModWriterParameters>(), It.IsAny <bool>())).Returns((ModWriterParameters mwp, bool wdf) => { if (mwp.LockDescriptor) { lockSet = true; } return(Task.FromResult(true)); }); reader.Setup(p => p.GetFileInfo(It.IsAny <string>(), It.IsAny <string>())).Returns((string root, string path) => { var sb = new System.Text.StringBuilder(115); sb.AppendLine(@"path=""c:/fake"""); sb.AppendLine(@"name=""Fake"""); sb.AppendLine(@"picture=""thumbnail.png"""); sb.AppendLine(@"tags={"); sb.AppendLine(@" ""Gameplay"""); sb.AppendLine(@" ""Fixes"""); sb.AppendLine(@"}"); sb.AppendLine(@"supported_version=""2.6.*"""); return(new FileInfo() { Content = sb.ToString().SplitOnNewLine(), ContentSHA = "test", FileName = "fake.mod", IsBinary = false }); }); var result = await service.InstallModsAsync(new List <IMod> { new Mod() { DescriptorFile = "mod/fake.mod", IsLocked = true } });; result.Should().BeTrue(); lockSet.Should().BeTrue(); }