@@ -11,6 +11,27 @@ import 'helpers/mock_cache_info_repository.dart';
1111import 'helpers/test_configuration.dart' ;
1212
1313void main () {
14+ late int fileId;
15+ late String fileName;
16+ late String fileUrl;
17+ late DateTime validTill;
18+
19+ late CacheObject cacheObject;
20+
21+ setUp (() {
22+ fileId = 666 ;
23+ fileName = 'testimage.png' ;
24+ fileUrl = 'baseflow.com/test.png' ;
25+ validTill = DateTime (2017 , 9 , 7 , 17 , 30 );
26+
27+ cacheObject = CacheObject (
28+ fileUrl,
29+ relativePath: fileName,
30+ id: fileId,
31+ validTill: validTill,
32+ );
33+ });
34+
1435 group ('Retrieving files from store' , () {
1536 test ('Store should return null when file not cached' , () async {
1637 var repo = MockCacheInfoRepository ();
@@ -21,9 +42,6 @@ void main() {
2142 });
2243
2344 test ('Store should return FileInfo when file is cached' , () async {
24- var fileName = 'testimage.png' ;
25- var fileUrl = 'baseflow.com/test.png' ;
26-
2745 var config = createTestConfig ();
2846 await config.returnsFile (fileName);
2947 config.returnsCacheObject (fileUrl, fileName, DateTime .now ());
@@ -36,6 +54,28 @@ void main() {
3654 expect (await store.getFile ('baseflow.com/test.png' ), isNotNull);
3755 });
3856
57+ test ('Store should return null if file is not cached' , () async {
58+ var config = createTestConfig ();
59+ await config.returnsFile (fileName);
60+ config.returnsCacheObject (fileUrl, fileName, validTill,
61+ id: fileId, key: fileUrl);
62+
63+ var tempDir = createDir ();
64+ await (await tempDir).childFile ('testimage.png' ).create ();
65+
66+ final store = CacheStore (config);
67+
68+ final results = Future .wait ([
69+ store.removeCachedFile (cacheObject),
70+ store.removeCachedFile (cacheObject),
71+ ]);
72+
73+ expect (
74+ () => results,
75+ returnsNormally,
76+ );
77+ });
78+
3979 test ('Store should return null when file is no longer cached' , () async {
4080 var repo = MockCacheInfoRepository ();
4181
@@ -59,9 +99,6 @@ void main() {
5999 });
60100
61101 test ('Store should return CacheInfo when file is cached' , () async {
62- var fileName = 'testimage.png' ;
63- var fileUrl = 'baseflow.com/test.png' ;
64-
65102 var config = createTestConfig ();
66103 await config.returnsFile (fileName);
67104 config.returnsCacheObject (fileUrl, fileName, DateTime .now (), id: 1 );
@@ -74,8 +111,6 @@ void main() {
74111
75112 test ('Store should return CacheInfo from memory when asked twice' ,
76113 () async {
77- var fileName = 'testimage.png' ;
78- var fileUrl = 'baseflow.com/test.png' ;
79114 var validTill = DateTime .now ();
80115 var config = createTestConfig ();
81116
@@ -96,8 +131,6 @@ void main() {
96131 test (
97132 'Store should return File from memcache only when file is retrieved before' ,
98133 () async {
99- var fileName = 'testimage.png' ;
100- var fileUrl = 'baseflow.com/test.png' ;
101134 var validTill = DateTime .now ();
102135 var config = createTestConfig ();
103136
@@ -172,8 +205,6 @@ void main() {
172205
173206 group ('Removing files in store' , () {
174207 test ('Store should remove fileinfo from repo on delete' , () async {
175- var fileName = 'testimage.png' ;
176- var fileUrl = 'baseflow.com/test.png' ;
177208 var validTill = DateTime .now ();
178209 var config = createTestConfig ();
179210
0 commit comments