public void ConsumerChangeToken_IsNotRefreshed_AfterDisposal() { var endpoint1 = CreateEndpoint("/a"); var dataSource1 = new DynamicEndpointDataSource(endpoint1); var observableCollection = new ObservableCollection <EndpointDataSource> { dataSource1 }; var compositeDataSource = new CompositeEndpointDataSource(observableCollection); var changeToken1 = compositeDataSource.GetChangeToken(); var token = Assert.IsType <CancellationChangeToken>(changeToken1); Assert.False(token.HasChanged); var endpoint2 = CreateEndpoint("/b"); // Update DynamicEndpointDatasource dataSource1.AddEndpoint(endpoint2); Assert.True(changeToken1.HasChanged); var changeToken2 = compositeDataSource.GetChangeToken(); Assert.NotSame(changeToken2, changeToken1); token = Assert.IsType <CancellationChangeToken>(changeToken2); Assert.False(token.HasChanged); // Update ObservableCollection var endpoint3 = CreateEndpoint("/c"); var datasource2 = new DynamicEndpointDataSource(endpoint3); observableCollection.Add(datasource2); Assert.True(changeToken2.HasChanged); var changeToken3 = compositeDataSource.GetChangeToken(); Assert.NotSame(changeToken3, changeToken2); Assert.NotSame(changeToken3, changeToken1); token = Assert.IsType <CancellationChangeToken>(changeToken3); Assert.False(token.HasChanged); compositeDataSource.Dispose(); // Update DynamicEndpointDatasource and ObservableCollection after disposing CompositeEndpointDataSource. var endpoint4 = CreateEndpoint("/d"); dataSource1.AddEndpoint(endpoint4); var endpoint5 = CreateEndpoint("/d"); var datasource3 = new DynamicEndpointDataSource(endpoint5); observableCollection.Add(datasource3); // Token is not changed since the CompositeEndpointDataSource was disposed prior to the last endpoint being added. Assert.False(changeToken3.HasChanged); }
public void ConsumerChangeToken_IsRefreshed_WhenDataSourceCallbackFires() { // Arrange1 var endpoint1 = CreateEndpoint("/a"); var dataSource1 = new DynamicEndpointDataSource(endpoint1); var compositeDataSource = new CompositeEndpointDataSource(new[] { dataSource1 }); // Act1 var endpoints = compositeDataSource.Endpoints; // Assert1 var changeToken1 = compositeDataSource.GetChangeToken(); var token = Assert.IsType <CancellationChangeToken>(changeToken1); Assert.False(token.HasChanged); // initial state // Arrange2 var endpoint2 = CreateEndpoint("/b"); // Act2 dataSource1.AddEndpoint(endpoint2); // Assert2 Assert.True(changeToken1.HasChanged); // old token is expected to be changed var changeToken2 = compositeDataSource.GetChangeToken(); // new token is in a unchanged state Assert.NotSame(changeToken2, changeToken1); token = Assert.IsType <CancellationChangeToken>(changeToken2); Assert.False(token.HasChanged); // Arrange3 var endpoint3 = CreateEndpoint("/c"); // Act2 dataSource1.AddEndpoint(endpoint3); // Assert2 Assert.True(changeToken2.HasChanged); // old token is expected to be changed var changeToken3 = compositeDataSource.GetChangeToken(); // new token is in a unchanged state Assert.NotSame(changeToken3, changeToken2); Assert.NotSame(changeToken3, changeToken1); token = Assert.IsType <CancellationChangeToken>(changeToken3); Assert.False(token.HasChanged); }
public void ConsumerChangeToken_IsRefreshed_WhenNewDataSourceCallbackFires() { var endpoint1 = CreateEndpoint("/a"); var dataSource1 = new DynamicEndpointDataSource(endpoint1); var observableCollection = new ObservableCollection <EndpointDataSource> { dataSource1 }; var compositeDataSource = new CompositeEndpointDataSource(observableCollection); var changeToken1 = compositeDataSource.GetChangeToken(); var token = Assert.IsType <CancellationChangeToken>(changeToken1); Assert.False(token.HasChanged); var endpoint2 = CreateEndpoint("/b"); // Update ObservableCollection with a new DynamicEndpointDataSource var dataSource2 = new DynamicEndpointDataSource(endpoint2); observableCollection.Add(dataSource2); Assert.True(changeToken1.HasChanged); var changeToken2 = compositeDataSource.GetChangeToken(); Assert.NotSame(changeToken2, changeToken1); token = Assert.IsType <CancellationChangeToken>(changeToken2); Assert.False(token.HasChanged); // Update the newly added DynamicEndpointDataSource var endpoint3 = CreateEndpoint("/c"); dataSource2.AddEndpoint(endpoint3); Assert.True(changeToken2.HasChanged); var changeToken3 = compositeDataSource.GetChangeToken(); Assert.NotSame(changeToken3, changeToken2); Assert.NotSame(changeToken3, changeToken1); token = Assert.IsType <CancellationChangeToken>(changeToken3); Assert.False(token.HasChanged); }