Provides localizable files reader, reads the files from data folder
Наследование: IFileReader
Пример #1
0
		public void Initialize()
		{
			_languageManagerProvider = new Mock<ILanguageManagerProvider>();
			_languageManager = new Mock<ILanguageManager>();

			_languageManagerProvider.Setup(x => x.Get()).Returns(_languageManager.Object);
			_languageManager.SetupGet(x => x.Language).Returns("ru");

			_fs = new Mock<IFileSystem>();

			_fs.Setup(x => x.File.ReadAllText(It.Is<string>(d => d == "C:/WebSites/FooSite/App_Data/Foo.en.xml")))
				.Returns("<?xml version=\"1.0\" encoding=\"utf-8\" ?><items><item name=\"SiteTitle\" value=\"Title\" /></items>");

			// ReSharper disable once StringLiteralTypo
			_fs.Setup(x => x.File.ReadAllText(It.Is<string>(d => d == "C:/WebSites/FooSite/App_Data/Foo.ru.xml")))
				.Returns("<?xml version=\"1.0\" encoding=\"utf-8\" ?><items><item name=\"SiteTitle\" value=\"Заголовок\" /></items>");

			_fs.Setup(x => x.File.ReadAllText(It.Is<string>(d => d == "C:/WebSites/FooSite/App_Data/Foo.en.txt")))
				.Returns("Dummy");

			// ReSharper disable once StringLiteralTypo
			_fs.Setup(x => x.File.ReadAllText(It.Is<string>(d => d == "C:/WebSites/FooSite/App_Data/Foo.ru.txt")))
				.Returns("Тест");

			_fs.Setup(x => x.File.Exists(It.Is<string>(d => d == "C:/WebSites/FooSite/App_Data/Foo.en.xml")))
				.Returns(true);

			_fs.Setup(x => x.File.Exists(It.Is<string>(d => d == "C:/WebSites/FooSite/App_Data/Foo.ru.xml")))
				.Returns(true);

			_fs.Setup(x => x.File.Exists(It.Is<string>(d => d == "C:/WebSites/FooSite/App_Data/Foo.en.txt")))
				.Returns(true);

			_fs.Setup(x => x.File.Exists(It.Is<string>(d => d == "C:/WebSites/FooSite/App_Data/Foo.ru.txt")))
				.Returns(true);

			FileReader.FileSystem = _fs.Object;

			_fileReader = new FileReader(DataPath, "en", _languageManagerProvider.Object);
			_fileReader.Setup();
		}
Пример #2
0
		public void LoadTextDocument_CacheEnabledDefaultFile_DefaultFileFromCache()
		{
			// Assign
			FileReader.ClearCache();
			_fs.Setup(x => x.File.Exists(It.Is<string>(d => d == "C:/WebSites/FooSite/App_Data/Foo.ru.txt"))).Returns(false);

			// Act

			_fileReader.LoadTextDocument("Foo.txt", true);

			_fileReader = new FileReader(DataPath, "en", _languageManagerProvider.Object);
			_fileReader.Setup();

			var result = _fileReader.LoadTextDocument("Foo.txt", true);

			// Assert

			_fs.Verify(x => x.File.ReadAllText(It.IsAny<string>()), Times.Once);
			Assert.AreEqual("Dummy", result);
		}
Пример #3
0
		public void LoadXDocument_CacheEnabledDefaultFile_DefaultFileFromCache()
		{
			// Assign
			FileReader.ClearCache();
			_fs.Setup(x => x.File.Exists(It.Is<string>(d => d == "C:/WebSites/FooSite/App_Data/Foo.ru.xml"))).Returns(false);

			// Act

			_fileReader.LoadXDocument("Foo.xml", true);

			_fileReader = new FileReader(DataPath, "en", _languageManagerProvider.Object);
			_fileReader.Setup();

			var result = _fileReader.LoadXDocument("Foo.xml", true);

			// Assert

			_fs.Verify(x => x.File.ReadAllText(It.IsAny<string>()), Times.Once);
			Assert.AreEqual(XDocument.Parse(
					"<?xml version=\"1.0\" encoding=\"utf-8\" ?><items><item name=\"SiteTitle\" value=\"Title\" /></items>")
					.Root.OuterXml(), result.Root.OuterXml());
		}
Пример #4
0
		public void LoadTextDocument_CacheEnabled_SecondTimeFromCache()
		{
			// Assign
			FileReader.ClearCache();

			// Act

			_fileReader.LoadTextDocument("Foo.txt", true);

			_fileReader = new FileReader(DataPath, "en", _languageManagerProvider.Object);
			_fileReader.Setup();

			var result = _fileReader.LoadTextDocument("Foo.txt", true);

			// Assert

			_fs.Verify(x => x.File.ReadAllText(It.IsAny<string>()), Times.Once);

			// ReSharper disable once StringLiteralTypo
			Assert.AreEqual("Тест", result);
		}
Пример #5
0
		public void LoadXDocument_CacheEnabled_SecondTimeFromCache()
		{
			// Assign
			FileReader.ClearCache();

			// Act

			_fileReader.LoadXDocument("Foo.xml", true);

			_fileReader = new FileReader(DataPath, "en", _languageManagerProvider.Object);
			_fileReader.Setup();

			var result = _fileReader.LoadXDocument("Foo.xml", true);

			// Assert

			_fs.Verify(x => x.File.ReadAllText(It.IsAny<string>()), Times.Once);
			Assert.AreEqual(XDocument.Parse(
					"<?xml version=\"1.0\" encoding=\"utf-8\" ?><items><item name=\"SiteTitle\" value=\"Заголовок\" /></items>")
					.Root.OuterXml(), result.Root.OuterXml());
		}