Esempio n. 1
0
            public void WillReturnListOfCssFiles()
            {
                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 })
                };
                var file2 = new RequestReduceFile()
                {
                    Content             = new byte[] { 1 },
                    FileName            = builder.BuildSpriteUrl(id, new byte[] { 2 }),
                    Key                 = id,
                    LastUpdated         = DateTime.Now,
                    RequestReduceFileId = Hasher.Hash(new byte[] { 2 })
                };
                var file3 = new RequestReduceFile()
                {
                    Content             = new byte[] { 1 },
                    FileName            = builder.BuildResourceUrl <CssResource>(id2, new byte[] { 3 }),
                    Key                 = id2,
                    LastUpdated         = DateTime.Now,
                    OriginalName        = "originalName2",
                    RequestReduceFileId = Hasher.Hash(new byte[] { 3 })
                };

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

                var result = testable.ClassUnderTest.GetActiveFiles();

                Assert.Equal(2, result.Count());
                Assert.True(result.Contains(file.FileName));
                Assert.True(result.Contains(file3.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")));
            }