public void GetPhysicalFile()
        {
            Mock<IRemoteFileTempFolderProvider> remoteFileTempFolderProviderMock = new Mock<IRemoteFileTempFolderProvider>();
            
            const string content = "JavaScript1.js";
            string remoteFileAddress = "{0}/{1}".FormatWith(BASE_ADDRESS, content);
            string tempFile = Path.Combine(GetContentsFolder(), "JavaScript1.temp.js");
            remoteFileTempFolderProviderMock.Setup(x => x.GetTempFilePath(remoteFileAddress)).Returns(tempFile);

            HttpResourceReader httpResourceReader = new HttpResourceReader(remoteFileTempFolderProviderMock.Object, null);
            string fileName;
            string fileContent;
            httpResourceReader.GetPhysicalFile(remoteFileAddress, out fileName, out fileContent);

            Assert.IsTrue(File.Exists(fileName));
            Assert.AreEqual(tempFile, fileName);
            Assert.AreEqual(File.ReadAllText(Path.Combine(GetContentsFolder(), content)), fileContent);
            Assert.AreEqual(File.ReadAllText(tempFile), fileContent);
        }
        public void ReadResource()
        {
            Mock<IRemoteFileTempFolderProvider> remoteFileTempFolderProviderMock = new Mock<IRemoteFileTempFolderProvider>();

            const string content = "JavaScript1.js";
            string remoteFileAddress = "{0}/{1}".FormatWith(BASE_ADDRESS, content);
            string contentPath = Path.Combine(GetContentsFolder(), content);
            string tempFile = Path.Combine(GetContentsFolder(), "JavaScript2.temp.js");
            remoteFileTempFolderProviderMock.Setup(x => x.GetTempFilePath(remoteFileAddress)).Returns(tempFile);

            HttpResourceReader httpResourceReader = new HttpResourceReader(remoteFileTempFolderProviderMock.Object, null);
            ResourceInfo resourceInfo = httpResourceReader.ReadResource(remoteFileAddress);

            Assert.IsTrue(File.Exists(resourceInfo.DependentFile));
            Assert.AreEqual(tempFile, resourceInfo.DependentFile);
            Assert.AreEqual(File.ReadAllText(contentPath), resourceInfo.Content);
            Assert.AreEqual(File.ReadAllText(tempFile), resourceInfo.Content);
            AssertLastWriteTime(File.GetLastWriteTime(contentPath), resourceInfo.ModifyDate);
        }
 public void GetPhysicalFile_ThrowsExceptionWhenNotFoundRemoteFile()
 {
     const string content = "JavaScript2.js";
     string remoteFileAddress = "{0}/{1}".FormatWith(BASE_ADDRESS, content);
     HttpResourceReader httpResourceReader = new HttpResourceReader(null, null);
     string fileName;
     string fileContent;
     Assert.Throws<HttpResourceReaderException>(() => httpResourceReader.GetPhysicalFile(remoteFileAddress, out fileName, out fileContent));
 }
        public void GetAbsoluteUrl(string relativeUrl, string currentUrl, string expectedUrl)
        {
            Mock<HttpContextBase> mock = new Mock<HttpContextBase>();
            mock.Setup(x => x.Request.Url).Returns(new Uri(currentUrl));
            Utility.HttpContextWrapper.Context = mock.Object;

            Mock<IVirtualPathProvider> mockVirtualPathProvider = new Mock<IVirtualPathProvider>();
            string absoluteUrl = relativeUrl.Replace("~", string.Empty);
            if (!absoluteUrl.StartsWith("/"))
            {
                absoluteUrl = absoluteUrl.Insert(0, "/");
            }
            mockVirtualPathProvider.Setup(x => x.ToAbsoluteUrl(It.IsAny<string>())).Returns(absoluteUrl);

            HttpResourceReader httpResourceReader = new HttpResourceReader(null, mockVirtualPathProvider.Object);
            Assert.AreEqual(expectedUrl, httpResourceReader.GetAbsoluteUrl(relativeUrl));
        }
 public void GetPhysicalFile_ThrowsExceptionWhenPathIsNull()
 {
     HttpResourceReader httpResourceReader = new HttpResourceReader(null, null);
     string fileName;
     string fileContent;
     Assert.Throws<ArgumentNullException>(() => httpResourceReader.GetPhysicalFile(null, out fileName, out fileContent));
 }