Exemple #1
0
        public SqlServerStoreFacts()
        {
            var dataDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName +
                          "\\RequestReduce.SampleWeb\\App_Data";

            if (Directory.Exists(dataDir))
            {
                File.Delete(dataDir + "\\RequestReduce.sdf");
            }
            else
            {
                Directory.CreateDirectory(dataDir);
            }

            RequestReduceDB.DefaultProviderName = "System.Data.SQLite";
            var mockConfig = new Mock <IRRConfiguration>();

            mockConfig.Setup(x => x.ConnectionStringName).Returns("data source=" + dataDir + "\\RequestReduce.sdf;Version=3;");
            config = mockConfig.Object;
            repo   = new FileRepository(config);
            IntegrationFactHelper.RecyclePool();
            repo.GetDatabase().Execute(SqliteHelper.GetSqlLightSafeSql());
            rrFolder   = IntegrationFactHelper.ResetPhysicalContentDirectoryAndConfigureStore(Configuration.Store.SqlServerStore, 3000);
            uriBuilder = new UriBuilder(config);
        }
        public void WillUseSameReductionAfterAppPoolRecycle()
        {
            var urlPattern = new Regex(@"(href|src)=""?(?<url>[^"" ]+)""?[^ />]+[ />]", RegexOptions.IgnoreCase);

            new WebClient().DownloadString("http://localhost:8877/Local.html");
            WaitToCreateResources();
            var response   = new WebClient().DownloadString("http://localhost:8877/Local.html");
            var css        = new CssResource().ResourceRegex.Match(response).ToString();
            var js         = new JavaScriptResource().ResourceRegex.Match(response).ToString();
            var urls       = new string[] { urlPattern.Match(css).Groups["url"].Value, urlPattern.Match(js).Groups["url"].Value };
            var files      = new string [] { urls[0].Replace("/RRContent", rrFolder).Replace("/", "\\"), urls[1].Replace("/RRContent", rrFolder).Replace("/", "\\") };
            var createTime = new DateTime[] { new FileInfo(files[0]).LastWriteTime, new FileInfo(files[1]).LastWriteTime };

            IntegrationFactHelper.RecyclePool();
            new WebClient().DownloadString("http://localhost:8877/Local.html");
            WaitToCreateResources();

            Assert.Equal(createTime[0], new FileInfo(files[0]).LastWriteTime);
            Assert.Equal(createTime[1], new FileInfo(files[1]).LastWriteTime);
        }
        public SqlServerStoreFacts()
        {
            var dataDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName +
                          "\\RequestReduce.SampleWeb\\App_Data";

            if (!Directory.Exists(dataDir))
            {
                Directory.CreateDirectory(dataDir);
            }
            Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
            var mockConfig = new Mock <IRRConfiguration>();

            mockConfig.Setup(x => x.ConnectionStringName).Returns("data source=" + dataDir + "\\RequestReduce.sdf");
            config = mockConfig.Object;
            repo   = new FileRepository(config);
            IntegrationFactHelper.RecyclePool();
            repo.Context.Database.Delete();
            repo.Context.Database.Create();
            rrFolder   = IntegrationFactHelper.ResetPhysicalContentDirectoryAndConfigureStore(Configuration.Store.SqlServerStore, 3000);
            uriBuilder = new UriBuilder(config);
        }
Exemple #4
0
        public void WillReReduceAfterFileIsRemovedFromDb()
        {
            var cssPattern = new Regex(@"<link[^>]+type=""?text/css""?[^>]+>", RegexOptions.IgnoreCase);
            var urlPattern = new Regex(@"href=""?(?<url>[^"" ]+)""?[^ />]+[ />]", RegexOptions.IgnoreCase);

            new WebClient().DownloadString("http://localhost:8877/Local.html");
            WaitToCreateResources();
            var response   = new WebClient().DownloadString("http://localhost:8877/Local.html");
            var css        = cssPattern.Match(response).ToString();
            var url        = urlPattern.Match(css).Groups["url"].Value;
            var id         = Hasher.Hash(uriBuilder.ParseFileName(url));
            var createTime = repo.SingleOrDefault <RequestReduceFile>(id).LastUpdated;

            repo.Delete <RequestReduceFile>(id);
            IntegrationFactHelper.RecyclePool();
            new WebClient().DownloadString("http://localhost:8877/Local.html");
            WaitToCreateResources();
            new WebClient().DownloadString("http://localhost:8877/Local.html");

            Assert.True(createTime < repo.SingleOrDefault <RequestReduceFile>(id).LastUpdated);
        }