public void TestGetAsync_DeleteSession() { var identity = Mock.Of <IProtocolgatewayDeviceIdentity>(i => i.Id == "deviceId"); var sessionProvider = new SessionStateStoragePersistenceProvider(Mock.Of <IEdgeHub>(), this.entityStore); Task task = sessionProvider.DeleteAsync(identity, It.IsAny <ISessionState>()); Assert.True(task.IsCompleted); }
public async Task TestGetAsync_DeleteSession_DeleteFromStore() { var identity = Mock.Of <IProtocolgatewayDeviceIdentity>(i => i.Id == "deviceId"); var sessionProvider = new SessionStateStoragePersistenceProvider(Mock.Of <IEdgeHub>(), this.entityStore); var sessionState = new SessionState(false); await sessionProvider.SetAsync(identity, sessionState); await sessionProvider.DeleteAsync(identity, It.IsAny <ISessionState>()); ISessionState storedSession = await sessionProvider.GetAsync(identity); Assert.Null(storedSession); }
public async Task TestSetAsync_AddedMethodSubscription_ShouldSaveToStore() { var edgeHub = new Mock <IEdgeHub>(); var identity = Mock.Of <IProtocolgatewayDeviceIdentity>(i => i.Id == "d1"); var sessionProvider = new SessionStateStoragePersistenceProvider(edgeHub.Object, this.entityStore); var sessionState = new SessionState(false); sessionState.AddOrUpdateSubscription(MethodPostTopicPrefix, QualityOfService.AtLeastOnce); await sessionProvider.SetAsync(identity, sessionState); ISessionState storedSession = await sessionProvider.GetAsync(identity); Assert.NotNull(storedSession); edgeHub.Verify(x => x.AddSubscription("d1", DeviceSubscription.Methods), Times.Once); // clean up await sessionProvider.DeleteAsync(identity, sessionState); }
public async Task TestSetAsync_RemovedSubscription_ShouldUpdateStore() { List <(DeviceSubscription, bool)> receivedSubscriptions = null; var edgeHub = new Mock <IEdgeHub>(); edgeHub.Setup(e => e.ProcessSubscriptions("d1", It.IsAny <IEnumerable <(DeviceSubscription, bool)> >())) .Callback <string, IEnumerable <(DeviceSubscription, bool)> >((d, s) => receivedSubscriptions = s.ToList()) .Returns(Task.CompletedTask); var identity = Mock.Of <IProtocolgatewayDeviceIdentity>(i => i.Id == "d1"); var sessionProvider = new SessionStateStoragePersistenceProvider(edgeHub.Object, this.entityStore); var sessionState = new SessionState(false); sessionState.AddOrUpdateSubscription(MethodPostTopicPrefix, QualityOfService.AtLeastOnce); await sessionProvider.SetAsync(identity, sessionState); Assert.NotNull(receivedSubscriptions); Assert.Single(receivedSubscriptions); Assert.True(receivedSubscriptions[0].Item2); Assert.Equal(DeviceSubscription.Methods, receivedSubscriptions[0].Item1); sessionState.RemoveSubscription(MethodPostTopicPrefix); await sessionProvider.SetAsync(identity, sessionState); ISessionState storedSession = await sessionProvider.GetAsync(identity); Assert.NotNull(storedSession); Assert.Null(storedSession.Subscriptions.SingleOrDefault(p => p.TopicFilter == MethodPostTopicPrefix)); Assert.NotNull(receivedSubscriptions); Assert.Single(receivedSubscriptions); Assert.False(receivedSubscriptions[0].Item2); Assert.Equal(DeviceSubscription.Methods, receivedSubscriptions[0].Item1); // clean up await sessionProvider.DeleteAsync(identity, sessionState); }