public void Sync_CheckInput_Socket()
        {
            var sync = new FakeISynchronize(new List <FileIndexItem>
            {
                new FileIndexItem("/test")
                {
                    Status = FileIndexItem.ExifStatus.Ok
                }
            });
            var websockets           = new FakeIWebSocketConnectionsService();
            var appSettings          = new AppSettings();
            var syncWatcherPreflight = new SyncWatcherConnector(new AppSettings(),
                                                                sync, websockets, new FakeIQuery(), new FakeIWebLogger(), new TelemetryClient(new TelemetryConfiguration()));

            syncWatcherPreflight.Sync(
                new Tuple <string, string, WatcherChangeTypes>(
                    Path.Combine(appSettings.StorageFolder, "test"), null, WatcherChangeTypes.Changed));

            Assert.AreEqual(1, websockets.FakeSendToAllAsync.Count(p => !p.StartsWith("[system]")));
            var value = websockets.FakeSendToAllAsync.FirstOrDefault(p =>
                                                                     !p.StartsWith("[system]"));

            Assert.IsTrue(value.Contains("filePath\":\"/test\""));
            Assert.AreEqual("/test", sync.Inputs[0].Item1);
        }
Example #2
0
        public async Task ThumbnailGenerationTest_CheckIfGenerated_Socket_Success()
        {
            var storage = new FakeIStorage(new List <string> {
                "/"
            }, new List <string> {
                "/test.jpg"
            },
                                           new List <byte[]> {
                CreateAnImage.Bytes
            });

            var thumbStorage = new FakeIStorage();

            var socket          = new FakeIWebSocketConnectionsService();
            var selectorStorage = new FakeSelectorStorage(storage);
            var controller      = new ThumbnailGenerationController(selectorStorage, new FakeIQuery(
                                                                        new List <FileIndexItem> {
                new FileIndexItem("/test.jpg")
            }
                                                                        ), new FakeIWebLogger(), socket);

            await controller.WorkItem("/", storage, thumbStorage);

            Assert.AreEqual(1, socket.FakeSendToAllAsync.Count(p => !p.StartsWith("[system]")));
        }
Example #3
0
        public async Task SyncControllerTest_Mkdir_Good_SocketUpdate()
        {
            InsertSearchData();
            var context = new ControllerContext
            {
                HttpContext = new DefaultHttpContext()
            };

            var socket      = new FakeIWebSocketConnectionsService();
            var fakeStorage = new FakeIStorage(new List <string> {
                "/"
            },
                                               new List <string> {
                _createAnImage.DbPath
            });
            var storageSelector = new FakeSelectorStorage(fakeStorage);

            var controller =
                new DiskController(_query, storageSelector,
                                   socket, new FakeINotificationQuery())
            {
                ControllerContext = context
            };

            await controller.Mkdir("/test_dir");

            var value = socket.FakeSendToAllAsync.FirstOrDefault(p =>
                                                                 !p.StartsWith("[system]"));

            Assert.IsNotNull(value);
            Assert.IsTrue(value.Contains("/test_dir"));
        }
Example #4
0
        public async Task SyncControllerTest_Rename_Good_SocketUpdate()
        {
            InsertSearchData();

            var context = new ControllerContext
            {
                HttpContext = new DefaultHttpContext()
            };
            var socket = new FakeIWebSocketConnectionsService();

            var fakeStorage = new FakeIStorage(new List <string> {
                "/"
            },
                                               new List <string> {
                _createAnImage.DbPath
            });
            var storageSelector = new FakeSelectorStorage(fakeStorage);

            var controller =
                new DiskController(_query, storageSelector,
                                   socket, new FakeINotificationQuery())
            {
                ControllerContext = context
            };

            await controller.Rename(_createAnImage.DbPath, "/test.jpg");

            Assert.AreEqual(1, socket.FakeSendToAllAsync.Count(p => !p.Contains("[system]")));
            Assert.IsTrue(socket.FakeSendToAllAsync[0].Contains("/test.jpg"));

            await _query.RemoveItemAsync(await _query.GetObjectByFilePathAsync("/test.jpg"));
        }
        public void RealtimeConnectionsService_ShouldPassThough()
        {
            var fakeIWebSocketConnectionsService = new FakeIWebSocketConnectionsService();
            var fakeINotificationQuery           = new FakeINotificationQuery();
            var service = new RealtimeConnectionsService(fakeIWebSocketConnectionsService, fakeINotificationQuery, new FakeIWebLogger());

            service.NotificationToAllAsync(
                new ApiNotificationResponseModel <string>(), CancellationToken.None);

            Assert.AreEqual(1, fakeIWebSocketConnectionsService.FakeSendToAllAsync.Count);
            Assert.AreEqual(1, fakeINotificationQuery.FakeContent.Count);
        }
Example #6
0
        public async Task StartAsync_CancelBeforeStart()
        {
            var connectionService = new FakeIWebSocketConnectionsService();
            var service           = new HeartbeatService(connectionService);

            CancellationTokenSource source = new CancellationTokenSource();
            CancellationToken       token  = source.Token;

            source.Cancel();
            await service.StartAsync(token);

            Assert.AreEqual(0, connectionService.FakeSendToAllAsync.Count);
        }
        public void CleanOldMessagesAsync_Exception_Handle_Test()
        {
            var fakeIWebSocketConnectionsService = new FakeIWebSocketConnectionsService();
            var fakeINotificationQuery           = new FakeINotificationQuery(new Exception("t"));
            var service = new RealtimeConnectionsService(fakeIWebSocketConnectionsService, fakeINotificationQuery, new FakeIWebLogger());

            service.NotificationToAllAsync(
                new ApiNotificationResponseModel <string>(),
                CancellationToken.None);

            service.CleanOldMessagesAsync();
            // service has thrown an exception so the remove is ignored
            Assert.AreEqual(1, fakeINotificationQuery.FakeContent.Count);
        }
Example #8
0
        public async Task StartAsyncStop()
        {
            var connectionService = new FakeIWebSocketConnectionsService();
            var service           = new HeartbeatService(connectionService);

            CancellationTokenSource source = new CancellationTokenSource();
            CancellationToken       token  = source.Token;

            await service.StartAsync(token);

            await service.StopAsync(token);

            Assert.IsTrue(connectionService.FakeSendToAllAsync.LastOrDefault()?.Contains("dateTime"));
        }
Example #9
0
        public async Task PushToSockets_ContainsValue()
        {
            var socket = new FakeIWebSocketConnectionsService();

            await new ManualBackgroundSyncService(
                new FakeISynchronize(new List <FileIndexItem>()),
                new FakeIQuery(),
                socket,
                new FakeMemoryCache(
                    new Dictionary <string, object>()),
                new FakeIWebLogger(), new FakeIUpdateBackgroundTaskQueue(), GetScope())
            .PushToSockets(new List <FileIndexItem> {
                new FileIndexItem("/test.jpg")
            });

            Assert.IsTrue(socket.FakeSendToAllAsync[0].Contains("/test.jpg"));
        }
Example #10
0
        public void Sync_CheckInput_CheckIfCacheIsUpdated_ButIgnoreNotInIndexFile()
        {
            var sync = new FakeISynchronize(new List <FileIndexItem>
            {
                //    = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = > source is missing
                new FileIndexItem("/test.jpg")
                {
                    Status = FileIndexItem.ExifStatus.NotFoundSourceMissing
                }
            });
            var websockets  = new FakeIWebSocketConnectionsService();
            var appSettings = new AppSettings();

            var provider = new ServiceCollection()
                           .AddMemoryCache()
                           .BuildServiceProvider();
            var memoryCache = provider.GetService <IMemoryCache>();

            var builderDb = new DbContextOptionsBuilder <ApplicationDbContext>();

            builderDb.UseInMemoryDatabase(nameof(DownloadPhotoControllerTest));
            var options = builderDb.Options;
            var context = new ApplicationDbContext(options);

            var query = new Query(context, null, null, null, memoryCache);

            query.AddCacheParentItem("/",
                                     new List <FileIndexItem> {
                new FileIndexItem("/test.jpg")
                {
                    IsDirectory     = false,
                    Tags            = "This should not be the tags",
                    ParentDirectory = "/"
                }
            });

            var syncWatcherConnector = new SyncWatcherConnector(appSettings,
                                                                sync, websockets, query, new FakeIWebLogger(), new TelemetryClient(new TelemetryConfiguration()));

            syncWatcherConnector.Sync(
                new Tuple <string, string, WatcherChangeTypes>(
                    Path.Combine(appSettings.StorageFolder, "test.jpg"), null, WatcherChangeTypes.Changed));

            Assert.AreEqual(0, query.DisplayFileFolders().Count());
        }
        public void Replace_ShouldTriggerBackgroundService_Fail()
        {
            var fakeFakeIWebSocketConnectionsService =
                new FakeIWebSocketConnectionsService();

            var metaReplaceService = new FakeIMetaReplaceService(new List <FileIndexItem>
            {
                new FileIndexItem("/test09.jpg")
                {
                    Status = FileIndexItem.ExifStatus.OperationNotSupported
                }
            });
            var controller = new MetaReplaceController(metaReplaceService, _bgTaskQueue,
                                                       new FakeIRealtimeConnectionsService(), new FakeIWebLogger(), NewScopeFactory());

            controller.Replace("/test09.jpg", "tags", "test", "");

            Assert.AreEqual(0, fakeFakeIWebSocketConnectionsService.FakeSendToAllAsync.Count);
        }
Example #12
0
        public void Sync_CheckInput_Socket_Ignore()
        {
            var sync = new FakeISynchronize(new List <FileIndexItem>
            {
                new FileIndexItem("/test")
                {
                    Status = FileIndexItem.ExifStatus.OperationNotSupported
                }
            });
            var websockets           = new FakeIWebSocketConnectionsService();
            var appSettings          = new AppSettings();
            var syncWatcherConnector = new SyncWatcherConnector(appSettings,
                                                                sync, websockets, new FakeIQuery(), new FakeIWebLogger(), new TelemetryClient(new TelemetryConfiguration()));

            syncWatcherConnector.Sync(
                new Tuple <string, string, WatcherChangeTypes>(
                    Path.Combine(appSettings.StorageFolder, "test"), null, WatcherChangeTypes.Changed));

            Assert.AreEqual(0, websockets.FakeSendToAllAsync.Count);
            Assert.AreEqual("/test", sync.Inputs[0].Item1);
        }
Example #13
0
        public async Task ThumbnailGenerationTest_CheckIfGenerated_Socket_NoResultsInDatabase()
        {
            var storage = new FakeIStorage(new List <string> {
                "/"
            }, new List <string> {
                "/test.jpg"
            },
                                           new List <byte[]> {
                CreateAnImage.Bytes
            });

            var thumbStorage = new FakeIStorage();

            var socket          = new FakeIWebSocketConnectionsService();
            var selectorStorage = new FakeSelectorStorage(storage);
            var controller      = new ThumbnailGenerationController(selectorStorage, new FakeIQuery(
                                                                        new List <FileIndexItem>()), new FakeIWebLogger(), socket);

            await controller.WorkItem("/", storage, thumbStorage);

            Assert.AreEqual(0, socket.FakeSendToAllAsync.Count);
        }