ContentMetaData.xml does not exist on purpose here, it is created automatically.
View code on GitHub
Inheritance Hierarchy
DeltaEngine.Content.Disk.Tests DiskContentLoaderTests
Namespace: DeltaEngine.Content.Disk.Tests
Assembly: DeltaEngine.Content.Disk.Tests (in DeltaEngine.Content.Disk.Tests.dll) Version: 1.1.1.0 (1.1.1)
Syntax
The DiskContentLoaderTests type exposes the following members.
Constructors
Name | Description | |
---|---|---|
DiskContentLoaderTests | Initializes a new instance of the DiskContentLoaderTests class |
Methods
Examples
[TestFixtureSetUp] public void Setup() { CreateContentMetaDataAndRealFiles(); ContentLoader.Use<DiskContentLoader>(); image = ContentLoader.Load<MockImage>("DeltaEngineLogo"); }
[TestFixtureTearDown] public void DisposeContentLoaderAndDeleteContentDirectory() { ContentLoader.DisposeIfInitialized(); DeleteDirectoryAndAllIncludingFiles(ContentProjectDirectoryName); }
[Test] public void LoadImageContent() { Assert.AreEqual("DeltaEngineLogo", image.Name); Assert.IsFalse(image.IsDisposed); Assert.AreEqual(new Size(128, 128), image.PixelSize); var smallImage = ContentLoader.Load<MockImage>("SmallImage"); Assert.AreEqual(new Size(32, 32), smallImage.PixelSize); }
[Test] public void LoadNonExistingImageFails() { if (Debugger.IsAttached) Assert.Throws<ContentLoader.ContentNotFound>( () => ContentLoader.Load<MockImage>("FailImage")); }
[Test] public void LoadingCachedContentOfTheWrongTypeThrowsException() { Assert.DoesNotThrow(() => ContentLoader.Load<MockImage>("DeltaEngineLogo")); Assert.Throws<ContentLoader.CachedResourceExistsButIsOfTheWrongType>( () => ContentLoader.Load<MockXmlContent>("DeltaEngineLogo")); }
[Test] public void LastTimeUpdatedShouldBeSet() { Assert.Greater(image.MetaData.LastTimeUpdated, DateTime.Now.AddSeconds(-2)); }
[Test] public void PlatformFileIdShouldBeSet() { Assert.Less(image.MetaData.PlatformFileId, 0); }
[Test] public void FileSizeShouldBeSet() { Assert.Greater(image.MetaData.FileSize, 150); }
[Test] public void ShouldCreateMetaDataFileIfNoneExists() { Directory.CreateDirectory(ExtraContentDirectoryName); var files = Directory.GetFiles(ContentProjectDirectoryName, "*.png"); File.Copy(files[0], Path.Combine(ExtraContentDirectoryName, Path.GetFileName(files[0]))); string metaDataFilePath = Path.Combine(ExtraContentDirectoryName, "ContentMetaData.xml"); var contentLoader = (DiskContentLoader)ContentLoader.current; contentLoader.LoadMetaData(metaDataFilePath); Assert.IsTrue(File.Exists(metaDataFilePath)); }
[Test] public void LoadingContentDataFromBinaryDataWillLoadItFromName() { var content = new ImageAnimation(new[] { ContentLoader.Load<Image>("DeltaEngineLogo") }, 1); var data = BinaryDataExtensions.SaveDataIntoMemoryStream(content); Assert.AreEqual(63, data.Length); var loadedContent = BinaryDataExtensions.LoadDataWithKnownTypeFromMemoryStream<ImageAnimation>(data); Assert.AreEqual(content.Name, loadedContent.Name); Assert.AreEqual(content.Frames.Length, loadedContent.Frames.Length); Assert.AreEqual(content.Frames[0], loadedContent.Frames[0]); }
[Test] public void CreateMetaDataViaFileCreator() { Directory.CreateDirectory(ExtraContentDirectoryName); foreach (var filePath in Directory.GetFiles(ContentProjectDirectoryName, "*.png")) File.Copy(filePath, Path.Combine(ExtraContentDirectoryName, Path.GetFileName(filePath))); string metaDataFilePath = Path.Combine(ExtraContentDirectoryName, "ContentMetaData.xml"); var xml = CreateMetaDataXmlFileAndCheckPixelSizes(null, metaDataFilePath); CreateMetaDataXmlFileAndCheckPixelSizes(xml, metaDataFilePath); }
See Also