Example #1
0
        public async Task ScrobbleTest()
        {
            // given: CacheScrobbleViewModel and mocks
            var scrobbles = TestHelper.CreateGenericScrobbles(3);

            Mock <IUserScrobbler> scrobblerMock = new Mock <IUserScrobbler>(MockBehavior.Strict);

            scrobblerMock.Setup(u => u.GetCachedAsync()).Returns(Task.Run(() => scrobbles.AsEnumerable()));
            scrobblerMock.Setup(u => u.SendCachedScrobblesAsync()).Returns(Task.Run(() => new ScrobbleResponse()));
            scrobblerMock.Setup(u => u.IsAuthenticated).Returns(true);

            Mock <IExtendedWindowManager> windowManagerMock = new Mock <IExtendedWindowManager>(MockBehavior.Strict);

            CacheScrobblerViewModel vm = new CacheScrobblerViewModel(windowManagerMock.Object)
            {
                Scrobbler = scrobblerMock.Object
            };

            await vm.GetCachedScrobbles();

            // when: scrobbling the cached tracks
            await vm.Scrobble();

            // then: send has been called
            Assert.That(() => scrobblerMock.Verify(u => u.SendCachedScrobblesAsync(), Times.Once), Throws.Nothing);
        }
Example #2
0
        public async Task GetCachedScrobblesTest()
        {
            // given: CacheScrobbleViewModel and mocks
            var expected = TestHelper.CreateGenericScrobbles(3);

            Mock <IUserScrobbler> scrobblerMock = new Mock <IUserScrobbler>(MockBehavior.Strict);

            scrobblerMock.Setup(u => u.GetCachedAsync()).Returns(Task.Run(() => expected.AsEnumerable()));

            Mock <IExtendedWindowManager> windowManagerMock = new Mock <IExtendedWindowManager>(MockBehavior.Strict);

            CacheScrobblerViewModel vm = new CacheScrobblerViewModel(windowManagerMock.Object)
            {
                Scrobbler = scrobblerMock.Object
            };

            // when: getting the cached scrobbles
            await vm.GetCachedScrobbles();

            // then: scrobbles are the expected ones
            Assert.That(vm.Scrobbles.IsEqualScrobble(expected));
        }