Esempio n. 1
0
        public async Task Integration_BasicItemSync()
        {
            Library client1 = new Library("machine1", SQLiteHelpers.CreateInMemoryDb(), _serverCaller, Logger.None);
            Library client2 = new Library("machine2", SQLiteHelpers.CreateInMemoryDb(), _serverCaller, Logger.None);

            // create item on server, pull to 1
            await _serverCaller.CreateNewLibraryItemAsync("foo/bar.mp3");

            await client1.PullFromServer();

            // modify item to generate a bunch of events
            LibraryItem item = client1.Items.Single();

            item.IncrementPlayCount();
            item.IncrementPlayCount();
            item.Name     = "GIMIX set";
            item.FilePath = "bar.mp3";
            item.Artist   = "The Avalanches";
            item.Album    = "Mixes";
            item.AddBookmark(TimeSpan.FromSeconds(30));
            item.AddBookmark(TimeSpan.FromSeconds(40));

            // sync from 1 to 2
            await client1.PushToServer();

            await client2.PullFromServer();

            AssertLibrariesHaveSameItems(client1, client2);

            // Delete a bookmark
            client2.Items.Single().Bookmarks.Count.Should().Be(2);
            client2.Items.Single().DeleteBookmark(item.Bookmarks.First().ID);
            client2.Items.Single().Bookmarks.Count.Should().Be(1);

            // Set bookmark emoji
            LibraryItem client2Item       = client2.Items.Single();
            Bookmark    remainingBookmark = client2Item.Bookmarks.Single();

            client2.Items.Single().SetBookmarkEmoji(remainingBookmark.ID, "🎶");
            client2.Items.Single().Bookmarks.Single().Emoji.Should().Be("🎶");

            client2.Items.Single().IncrementPlayCount();

            await client2.PushToServer();

            await client1.PullFromServer();

            AssertLibrariesHaveSameItems(client1, client2);

            // delete and make sure the delete propagates
            client1.Delete(client1.Items.Single());

            client1.Items.Count.Should().Be(0);

            await client1.PushToServer();

            await client2.PullFromServer();

            AssertLibrariesHaveSameItems(client1, client2);
        }
Esempio n. 2
0
        public async Task Integration_BasicItemSync()
        {
            NeverIncreasingClock clock = new NeverIncreasingClock();
            Library client1            = new Library("machine1", SQLiteHelpers.CreateInMemoryDb(), _serverCaller, Logger.None, clock);
            Library client2            = new Library("machine2", SQLiteHelpers.CreateInMemoryDb(), _serverCaller, Logger.None, clock);

            // create item on server, pull to 1
            await _serverCaller.CreateNewLibraryItemAsync("foo/bar.mp3");

            await client1.PullFromServer();

            // modify item to generate a bunch of events with the same time but increasing ID
            LibraryItem item = client1.Items.Single();

            item.IncrementPlayCount();
            item.IncrementPlayCount();
            item.Name = "foo";
            item.Name = "foo";
            item.Name = "foo";
            item.Name = "foo";
            item.Name = "bar";

            // sync from 1 to 2
            await client1.PushToServer();

            await client2.PullFromServer();

            AssertLibrariesHaveSameItems(client1, client2);
        }
Esempio n. 3
0
        public IntegrationTests_NormalClock()
        {
            _factory = new WebApplicationFactory <Startup>().WithWebHostBuilder(builder => {
                builder.ConfigureTestServices(services => {
                    services.AddSingleton <ISerializedEventRepository, SQLiteEventRepository>(
                        _ => new SQLiteEventRepository(SQLiteHelpers.CreateInMemoryDb()));
                });
            });

            ServiceCollection services = new ServiceCollection();

            services.AddSingleton <HttpClient>((_) => _factory.CreateClient());
            services.AddSingleton <ILogger>((_) => Logger.None);
            services.AddSingleton <ServerCaller>();

            _serviceProvider = services.BuildServiceProvider();

            _serverCaller = _serviceProvider.GetService <ServerCaller>();
        }
Esempio n. 4
0
 public SqliteTests()
 {
     _conn = SQLiteHelpers.CreateInMemoryDb();
     _conn.CreateEventsTableIfNotExists();
 }