Exemple #1
0
            public async void Stores()
            {
                const string userId                     = "user";
                const string channel1Id                 = "channel1";
                const string deviceId                   = "devId";
                var          deviceSyncStoreMock        = new Mock <IDeviceSyncStore>(MockBehavior.Strict);
                var          digitPushServiceClientMock = new Mock <IDigitPushServiceClient>(MockBehavior.Strict);
                var          calendarServiceMock        = new Mock <ICalendarServiceClient>(MockBehavior.Strict);
                var          travelServiceMock          = new Mock <ITravelServiceClient>(MockBehavior.Strict);
                var          focusStoreMock             = new Mock <IFocusStore>(MockBehavior.Strict);

                deviceSyncStoreMock.Setup(v => v.CreateAsync(userId, deviceId))
                .Returns(Task.CompletedTask);
                deviceSyncStoreMock.Setup(v => v.DeviceClaimedByAsync(It.IsAny <string>())).Returns(Task.FromResult <string>(null));
                digitPushServiceClientMock.Setup(v => v[userId].PushChannels.GetAllAsync()).Returns(Task.FromResult(new[] {
                    new PushChannelConfiguration()
                    {
                        Id      = channel1Id,
                        Options = new PushChannelOptions()
                    }
                }));
                digitPushServiceClientMock.Setup(v => v[userId].PushChannels[channel1Id].Options.PutAsync(It.IsAny <PushChannelOptions>()))
                .Returns(Task.CompletedTask)
                .Verifiable();

                var deviceSync = new DeviceSyncService(digitPushServiceClientMock.Object, deviceSyncStoreMock.Object);

                await deviceSync.RequestSynchronizationAsync(userId, deviceId, new DeviceSyncRequest()
                {
                    PushChannelId = channel1Id
                });

                digitPushServiceClientMock.Verify(v => v[userId].PushChannels[channel1Id].Options.PutAsync(It.Is <PushChannelOptions>(d => d.ContainsKey($"digit.sync.{deviceId}"))), Times.Once);
                deviceSyncStoreMock.Verify(v => v.CreateAsync(userId, deviceId));
            }
Exemple #2
0
            public async void ChannelNotFound_Exception()
            {
                const string userId                     = "user";
                const string deviceId                   = "devId";
                var          deviceSyncStoreMock        = new Mock <IDeviceSyncStore>(MockBehavior.Strict);
                var          digitPushServiceClientMock = new Mock <IDigitPushServiceClient>(MockBehavior.Strict);
                var          calendarServiceMock        = new Mock <ICalendarServiceClient>(MockBehavior.Strict);
                var          travelServiceMock          = new Mock <ITravelServiceClient>(MockBehavior.Strict);
                var          focusStoreMock             = new Mock <IFocusStore>(MockBehavior.Strict);

                deviceSyncStoreMock.Setup(v => v.DeviceClaimedByAsync(deviceId)).Returns(Task.FromResult <string>(null));
                digitPushServiceClientMock.Setup(v => v[userId].PushChannels.GetAllAsync())
                .Returns(Task.FromResult(new PushChannelConfiguration[0]));
                var deviceSync = new DeviceSyncService(digitPushServiceClientMock.Object, deviceSyncStoreMock.Object);
                var ex         = await Assert.ThrowsAsync <PushChannelNotFoundException>(async() => await deviceSync.RequestSynchronizationAsync(userId, deviceId, new DeviceSyncRequest()
                {
                    PushChannelId = "channel"
                }));
            }
Exemple #3
0
            public async void StoredForOtherUser_Exeception()
            {
                const string userId                     = "user";
                const string deviceId                   = "devId";
                var          deviceSyncStoreMock        = new Mock <IDeviceSyncStore>(MockBehavior.Strict);
                var          digitPushServiceClientMock = new Mock <IDigitPushServiceClient>(MockBehavior.Strict);
                var          calendarServiceMock        = new Mock <ICalendarServiceClient>(MockBehavior.Strict);
                var          travelServiceMock          = new Mock <ITravelServiceClient>(MockBehavior.Strict);
                var          focusStoreMock             = new Mock <IFocusStore>(MockBehavior.Strict);

                deviceSyncStoreMock.Setup(v => v.CreateAsync(userId, deviceId))
                .Returns(Task.CompletedTask);
                deviceSyncStoreMock.Setup(v => v.DeviceClaimedByAsync(It.IsAny <string>())).Returns(Task.FromResult("user2"));
                digitPushServiceClientMock.Setup(v => v[userId].PushChannels.GetAllAsync())
                .Returns(Task.FromResult(new[] { new PushChannelConfiguration()
                                                 {
                                                     Id = "channel"
                                                 } }));
                var deviceSync = new DeviceSyncService(digitPushServiceClientMock.Object, deviceSyncStoreMock.Object);
                var ex         = await Assert.ThrowsAsync <DeviceClaimedException>(async() => await deviceSync.RequestSynchronizationAsync(userId, deviceId, new DeviceSyncRequest()
                {
                    PushChannelId = "channel"
                }));
            }