public void CreateShouldAssembleFileTileWithCorrectPath() { var lib = new TagLib(); lib.Register(new Tags.Tiles()); lib.Register(new Sharp()); var locatorFactory = new FileLocatorFactory().CloneForTagLib(lib) as FileLocatorFactory; var factory = new TilesFactory(new MockConfiguration("x", DateTime.Now) { Factory = locatorFactory }); var entry = new MockTileEntry { Name = "name", Path = "a.htm", Extends = null }; var tile = new TemplateTileCreator().Create(entry, factory); Assert.That(tile, Is.Not.Null); Assert.That(tile.GetType(), Is.EqualTo(typeof(TemplateTile))); Assert.That(tile.Name, Is.EqualTo("name")); var templateTile = (TemplateTile)tile; var fileTemplate = (FileTemplate)templateTile.Template; Assert.That(fileTemplate.Path.EndsWith("a.htm")); }
public void SetUp() { _lib = new TagLib(); _lib.Register(new Tags.Tiles()); _lib.Register(new Sharp()); _factory = new FileLocatorFactory().CloneForTagLib(_lib) as FileLocatorFactory; new TilesSet(); _map = new TilesMap(); _data = new Hashtable(); _model = new TagModel(_data); _nestedAttributes = new AttributeSet( "nested", new TileAttribute("aAttribute", new StringTile("aAttributeValue")) ); _map.AddTile(new TemplateTile("fileWithAttributes", _factory.Handle("filewithtileattributes.htm", true), _nestedAttributes)); _attributes = new AttributeSet( "main", new TileAttribute("simple", new StringTile("simpleValue")), new TileAttribute("file", new TemplateTile(null, _factory.Handle("a.htm", true), null)), new TileAttribute("fileWithVars", new TemplateTile(null, _factory.Handle("b.htm", true), null)), new TileAttribute("fileWithTilesAttributes", new TileReference("fileWithAttributes", _map)) ); _model.Decorate().With(_attributes); _data["simpleAsProperty"] = "simple"; _data["some"] = new Hashtable { { "a", "AA" } }; }
public void SetUp() { _lib = new TagLib(); _lib.Register(new Tags.Tiles()); _lib.Register(new Sharp()); _factory = new FileLocatorFactory().CloneForTagLib(_lib) as FileLocatorFactory; }
public void ErrorFileShouldSaveParseContext() { var lib = new TagLib(); lib.Register(new Tags.Tiles()); lib.Register(new Sharp()); var factory = new FileLocatorFactory().CloneForTagLib(lib) as FileLocatorFactory; try { new TilesSet(); var tile = new TemplateTile( "test", factory.Handle("errorinfile.htm", true), null ); } catch (TemplateExceptionWithContext TEWC) { Assert.That(TEWC.Context, Is.Not.Null); Assert.That(TEWC.Context.LineNumber, Is.EqualTo(2)); string fullPath = Path.GetFullPath("errorinfile.htm"); TagException tagException = TagException.UnbalancedCloseingTag(new ForEach() { Group = new Core() }, new If() { Group = new Core() }).Decorate(TEWC.Context); Assert.That(TEWC.Message, Is.EqualTo(TemplateExceptionWithContext.ErrorInTemplate(fullPath, tagException).Message)); } }
public void SetUp() { _lib = new TagLib(); _lib.Register(new Tags.Tiles()); _lib.Register(new Sharp()); _locatorFactory = new FileLocatorFactory().CloneForTagLib(_lib) as FileLocatorFactory; var config = new MockConfiguration() { Factory = _locatorFactory }; _factory = new TilesFactory(config); }
private static ICollection <string> GetTexturesExist(string optName, OptFile opt, List <string> distinctSkins) { var texturesExist = new SortedSet <string>(); foreach (string skin in distinctSkins) { string path = GetSkinDirectoryLocatorPath(optName, skin); if (path == null) { continue; } SortedSet <string> filesSet; using (IFileLocator locator = FileLocatorFactory.Create(path)) { if (locator == null) { continue; } var filesEnum = locator.EnumerateFiles() .Select(t => Path.GetFileName(t)); filesSet = new SortedSet <string>(filesEnum, StringComparer.OrdinalIgnoreCase); } foreach (string textureName in opt.Textures.Keys) { if (TextureExists(filesSet, textureName, skin) != null) { texturesExist.Add(textureName); } } } return(texturesExist); }
public void GetView_Should_Update_Locator_Correct() { //Given var lib = new TagLib(); lib.Register(new Html()); lib.Register(new Tiles.Tags.Tiles()); var factory = new FileLocatorFactory("Views").CloneForTagLib(lib); var cache = new NstlCache { Factory = factory }; var view = cache.GetView("Home/Index.htm"); Assert.That(view, Is.Not.Null); var model = new TagModel(new Dictionary <string, string> { { "Message", "Test" } }); Assert.That(view.Render(model).Contains("VIEWS")); //Then }
public void CreateShouldAssembleFileTileWithCorrectExtendsAndPath() { var lib = new TagLib(); lib.Register(new Tags.Tiles()); lib.Register(new Sharp()); var locatorFactory = new FileLocatorFactory().CloneForTagLib(lib) as FileLocatorFactory; var factory = new TilesFactory(new MockConfiguration("a", DateTime.Now) { Factory = locatorFactory }); var entry = new MockTileEntry { Name = "name", Path = "b.htm", Extends = "definition" }; ITile tile = new TemplateOverridingDefinitionTileCreator().Create(entry, factory); Assert.That(tile, Is.Not.Null); Assert.That(tile.GetType(), Is.EqualTo(typeof(TemplateOveridingDefinitionTile))); Assert.That(tile.Name, Is.EqualTo("name")); var definition = (TemplateOveridingDefinitionTile)tile; var tileTemplate = (FileTemplate)definition.Template; Assert.That(tileTemplate.Path.EndsWith("b.htm")); Assert.That(definition.Extends, Is.Not.Null); Assert.That(definition.Extends.GetType(), Is.EqualTo(typeof(TileReference))); var reference = (TileReference)definition.Extends; Assert.That(reference.Name, Is.EqualTo("definition")); }
public void Test1() { var temp = Path.GetTempFileName(); try { for (int pass = 0; pass < 2; pass++) { using (var zip = WritableFileLocatorFactory.CreateArchive(temp, ArchiveType.Zip, CompressionType.LZMA)) { zip.Create(Path.Combine("a", Path.GetRandomFileName())); } } using (var reader = FileLocatorFactory.Create(temp)) { Assert.Equal(2, reader.EnumerateFiles().Count()); } } finally { File.Delete(temp); } }
private static void UpdateSkins(string optName, OptFile opt, List <string> distinctSkins, List <List <string> > fgSkins) { var locatorsPath = new Dictionary <string, string>(distinctSkins.Count, StringComparer.OrdinalIgnoreCase); var filesSets = new Dictionary <string, SortedSet <string> >(distinctSkins.Count, StringComparer.OrdinalIgnoreCase); foreach (string skin in distinctSkins) { string path = GetSkinDirectoryLocatorPath(optName, skin); locatorsPath.Add(skin, path); SortedSet <string> filesSet = null; if (path != null) { using (IFileLocator locator = FileLocatorFactory.Create(path)) { if (locator != null) { var filesEnum = locator.EnumerateFiles() .Select(t => Path.GetFileName(t)); filesSet = new SortedSet <string>(filesEnum, StringComparer.OrdinalIgnoreCase); } } } filesSets.Add(skin, filesSet ?? new SortedSet <string>()); } opt.Textures.AsParallel().ForAll(texture => { int position = texture.Key.IndexOf("_fg_"); if (position == -1) { return; } string textureName = texture.Key.Substring(0, position); int fgIndex = int.Parse(texture.Key.Substring(position + 4, texture.Key.IndexOf('_', position + 4) - position - 4), CultureInfo.InvariantCulture); foreach (string skin in fgSkins[fgIndex]) { string path = locatorsPath[skin]; if (path == null) { continue; } string filename = TextureExists(filesSets[skin], textureName, skin); if (filename == null) { continue; } using (IFileLocator locator = FileLocatorFactory.Create(path)) { if (locator == null) { continue; } CombineTextures(texture.Value, locator, filename); } } texture.Value.GenerateMipmaps(); }); }