public void WillFlushAllKeysWhenPassedGuidIsEmpty()
            {
                var testable   = new TestableLocalDiskStore();
                var urlBuilder = new UriBuilder(testable.Mock <IRRConfiguration>().Object);

                testable.Inject(urlBuilder);
                var guid1 = Guid.NewGuid();
                var guid2 = Guid.NewGuid();

                testable.Mock <IRRConfiguration>().Setup(x => x.ResourceVirtualPath).Returns("/dir");
                testable.Mock <IRRConfiguration>().Setup(x => x.ResourcePhysicalPath).Returns("c:\\web\\dir");
                testable.Inject <IUriBuilder>(urlBuilder);
                var file1 = new DatedFileEntry(urlBuilder.BuildResourceUrl <CssResource>(guid1, new byte[] { 1 }).Replace("/dir", "c:\\dir").Replace('/', '\\'), DateTime.Now);
                var file2 = new DatedFileEntry(urlBuilder.BuildResourceUrl <CssResource>(guid2, new byte[] { 1 }).Replace("/dir", "c:\\dir").Replace('/', '\\'), DateTime.Now);

                testable.Mock <IFileWrapper>().Setup(x => x.GetDatedFiles("c:\\web\\dir", "*RequestReduce*")).Returns(new List <DatedFileEntry> {
                    file1, file2
                });
                testable.Mock <IFileWrapper>().Setup(x => x.GetFiles("c:\\web\\dir")).Returns(new string[] { file1.FileName, file2.FileName });

                testable.ClassUnderTest.Flush(Guid.Empty);

                testable.Mock <IFileWrapper>().Verify(x => x.RenameFile(file1.FileName, file1.FileName.Replace(guid1.RemoveDashes(), guid1.RemoveDashes() + "-Expired")));
                testable.Mock <IFileWrapper>().Verify(x => x.RenameFile(file2.FileName, file2.FileName.Replace(guid2.RemoveDashes(), guid2.RemoveDashes() + "-Expired")));
            }
Exemple #2
0
            public void WillNotReturnExpiredKeys()
            {
                var testable = new TestableRepository();
                var builder  = new RequestReduce.Utilities.UriBuilder(testable.Mock <IRRConfiguration>().Object);
                var id       = Guid.NewGuid();
                var id2      = Guid.NewGuid();
                var file     = new RequestReduceFile()
                {
                    Content             = new byte[] { 1 },
                    FileName            = builder.BuildResourceUrl <CssResource>(id, new byte[] { 1 }),
                    Key                 = id,
                    LastUpdated         = DateTime.Now,
                    OriginalName        = "originalName",
                    RequestReduceFileId = Hasher.Hash(new byte[] { 1 }),
                    IsExpired           = true
                };
                var file2 = new RequestReduceFile()
                {
                    Content             = new byte[] { 1 },
                    FileName            = builder.BuildResourceUrl <CssResource>(id2, new byte[] { 2 }),
                    Key                 = id2,
                    LastUpdated         = DateTime.Now,
                    OriginalName        = "originalName2",
                    RequestReduceFileId = Hasher.Hash(new byte[] { 2 })
                };

                testable.ClassUnderTest.Save(file);
                testable.ClassUnderTest.Save(file2);

                var result = testable.ClassUnderTest.GetActiveFiles();

                Assert.Equal(1, result.Count());
                Assert.Equal(file2.FileName, result.First());
                Assert.True(result.Contains(file2.FileName));
            }
            public void WillExpireFile()
            {
                var testable   = new TestableLocalDiskStore();
                var key        = Guid.NewGuid();
                var urlBuilder = new UriBuilder(testable.Mock <IRRConfiguration>().Object);

                testable.Mock <IRRConfiguration>().Setup(x => x.ResourceVirtualPath).Returns("/RRContent");
                testable.Mock <IRRConfiguration>().Setup(x => x.ResourcePhysicalPath).Returns("c:\\RRContent");
                testable.Inject <IUriBuilder>(urlBuilder);
                var file1 = urlBuilder.BuildResourceUrl <CssResource>(key, new byte[] { 1 }).Replace("/RRContent", "c:\\RRContent").Replace('/', '\\');
                var file2 = urlBuilder.BuildSpriteUrl(key, new byte[] { 1 }).Replace("/RRContent", "c:\\RRContent").Replace('/', '\\');

                testable.Mock <IFileWrapper>().Setup(x => x.GetFiles("c:\\RRContent")).Returns(new string[]
                                                                                               { file1, file2 });

                testable.ClassUnderTest.Flush(key);

                testable.Mock <IFileWrapper>().Verify(x => x.RenameFile(file1, file1.Replace(key.RemoveDashes(), key.RemoveDashes() + "-Expired")));
                testable.Mock <IFileWrapper>().Verify(x => x.RenameFile(file2, file2.Replace(key.RemoveDashes(), key.RemoveDashes() + "-Expired")));
            }
Exemple #4
0
            public void WillReturnMostRecentActiveEntryPerKey()
            {
                var testable = new TestableRepository();
                var builder  = new RequestReduce.Utilities.UriBuilder(testable.Mock <IRRConfiguration>().Object);
                var id       = Guid.NewGuid();
                var id2      = Guid.NewGuid();
                var file     = new RequestReduceFile()
                {
                    Content             = new byte[] { 1 },
                    FileName            = builder.BuildResourceUrl <CssResource>(id, new byte[] { 1 }),
                    Key                 = id,
                    LastUpdated         = DateTime.Now,
                    OriginalName        = "originalName",
                    RequestReduceFileId = Hasher.Hash(new byte[] { 1 }),
                    IsExpired           = true
                };
                var file2 = new RequestReduceFile()
                {
                    Content             = new byte[] { 1 },
                    FileName            = builder.BuildResourceUrl <CssResource>(id, new byte[] { 2 }),
                    Key                 = id,
                    LastUpdated         = DateTime.Now.Subtract(new TimeSpan(0, 0, 2)),
                    OriginalName        = "originalName2",
                    RequestReduceFileId = Hasher.Hash(new byte[] { 2 })
                };
                var file3 = new RequestReduceFile()
                {
                    Content             = new byte[] { 1 },
                    FileName            = builder.BuildResourceUrl <CssResource>(id, new byte[] { 3 }),
                    Key                 = id,
                    LastUpdated         = DateTime.Now.Subtract(new TimeSpan(0, 0, 3)),
                    OriginalName        = "originalName2",
                    RequestReduceFileId = Hasher.Hash(new byte[] { 3 })
                };
                var file4 = new RequestReduceFile()
                {
                    Content             = new byte[] { 1 },
                    FileName            = builder.BuildResourceUrl <CssResource>(id2, new byte[] { 4 }),
                    Key                 = id2,
                    LastUpdated         = DateTime.Now.Subtract(new TimeSpan(0, 0, 3)),
                    OriginalName        = "originalName2",
                    RequestReduceFileId = Hasher.Hash(new byte[] { 4 })
                };
                var file5 = new RequestReduceFile()
                {
                    Content             = new byte[] { 1 },
                    FileName            = "file.png",
                    Key                 = id2,
                    LastUpdated         = DateTime.Now,
                    OriginalName        = "originalName2",
                    RequestReduceFileId = Hasher.Hash(new byte[] { 5 })
                };

                testable.ClassUnderTest.Save(file);
                testable.ClassUnderTest.Save(file2);
                testable.ClassUnderTest.Save(file3);
                testable.ClassUnderTest.Save(file4);
                testable.ClassUnderTest.Save(file5);

                var result = testable.ClassUnderTest.GetActiveFiles();

                Assert.Equal(2, result.Count());
                Assert.True(result.Contains(file2.FileName));
                Assert.True(result.Contains(file4.FileName));
            }