public void AllReactionsInMappingAreTriggeredOnMatchingPropertyUpdates() { // Arrange const string propertyName1 = "PropertyName1"; const string propertyName2 = "PropertyName2"; var updateReactionMock1 = new Mock <IUpdateReaction>(); var updateReactionMock2 = new Mock <IUpdateReaction>(); updateReactionMock1.Setup(u => u.UpdateCollection( It.IsAny <ICollectionView>(), It.IsAny <IUserPreferences>())); updateReactionMock2.Setup(u => u.UpdateCollection( It.IsAny <ICollectionView>(), It.IsAny <IUserPreferences>())); var mappingTable = new Dictionary <string, IEnumerable <IUpdateReaction> > { [propertyName1] = new[] { updateReactionMock1.Object }, [propertyName2] = new[] { updateReactionMock2.Object } }; var mapping = new TestingUpdateReactionMapping(mappingTable); var userPreferencesMock = new Mock <IUserPreferences>(); var collectionView = Mock.Of <ICollectionView>(); var manager = new UpdateReactionManager(mapping, userPreferencesMock.Object); manager.Initialize(collectionView); // Calling Initialize will invoke IUpdateReaction.UpdateCollection // Reset calls so that it is possible to verify the number of times // it is called as a result of raising PropertyChanged updateReactionMock1.ResetCalls(); updateReactionMock2.ResetCalls(); // Act userPreferencesMock.Raise(u => u.PropertyChanged += null, new PropertyChangedEventArgs(propertyName1)); userPreferencesMock.Raise(u => u.PropertyChanged += null, new PropertyChangedEventArgs(propertyName2)); // Assert updateReactionMock1.Verify(u => u.UpdateCollection( It.IsAny <ICollectionView>(), It.IsAny <IUserPreferences>()), Times.Exactly(1)); updateReactionMock2.Verify(u => u.UpdateCollection( It.IsAny <ICollectionView>(), It.IsAny <IUserPreferences>()), Times.Exactly(1)); }
public void ActivateAssignsUsageOrder() { // Arrange const string documentName = "DocumentName"; IList metadataCollection = null; var documentMockList = new List <Document> { CreateDocument(documentName) }; var documents = CreateDocuments(documentMockList); var collectionViewMock = new Mock <ICollectionView> { DefaultValue = DefaultValue.Mock }; var generatorMock = new Mock <ICollectionViewGenerator>(); generatorMock .Setup(c => c.CreateView(It.IsAny <IList>())) .Callback <IList>(mc => metadataCollection = mc) .Returns(collectionViewMock.Object); var mappingTable = new Dictionary <string, IEnumerable <IUpdateReaction> >(); var mapping = new TestingUpdateReactionMapping(mappingTable); var builder = new DocumentMetadataManagerBuilder { CollectionViewGenerator = generatorMock.Object, UpdateReactionMapping = mapping }; var manager = builder.CreateDocumentMetadataManager(); manager.Synchronize(documents, false); // Act manager.Activate(documentName); // Assert Assert.That(metadataCollection, Is.Not.Null); builder.NormalizedUsageOrderServiceMock .Verify(n => n.SetUsageOrder( (IList <DocumentMetadata>)metadataCollection, It.IsAny <IUserPreferences>())); }
public void ActivateRefreshesDocumentMetadataView() { // Arrange const string documentName = "DocumentName"; var documentMockList = new List <Document> { CreateDocument(documentName) }; var documents = CreateDocuments(documentMockList); var collectionViewMock = new Mock <ICollectionView> { DefaultValue = DefaultValue.Mock }; var generatorMock = new Mock <ICollectionViewGenerator>(); generatorMock .Setup(c => c.CreateView(It.IsAny <IList>())) .Returns(collectionViewMock.Object); var mappingTable = new Dictionary <string, IEnumerable <IUpdateReaction> >(); var mapping = new TestingUpdateReactionMapping(mappingTable); var builder = new DocumentMetadataManagerBuilder { CollectionViewGenerator = generatorMock.Object, UpdateReactionMapping = mapping }; var manager = builder.CreateDocumentMetadataManager(); manager.Synchronize(documents, false); // Act manager.Activate(documentName); // Assert collectionViewMock.Verify(c => c.Refresh()); }
public void ReactionIsNotTriggeredIfCollectionViewIsNull() { // Arrange const string propertyName = "PropertyName"; var updateReactionMock = new Mock <IUpdateReaction>(); updateReactionMock .Setup(u => u.UpdateCollection( It.IsAny <ICollectionView>(), It.IsAny <IUserPreferences>())); var mappingTable = new Dictionary <string, IEnumerable <IUpdateReaction> > { [propertyName] = new[] { updateReactionMock.Object } }; var mapping = new TestingUpdateReactionMapping(mappingTable); var userPreferencesMock = new Mock <IUserPreferences>(); var manager = new UpdateReactionManager(mapping, userPreferencesMock.Object); manager.Initialize(null); // Calling Initialize will invoke IUpdateReaction.UpdateCollection // Reset calls so that it is possible to verify the number of times // it is called as a result of raising PropertyChanged updateReactionMock.ResetCalls(); // Act userPreferencesMock.Raise(u => u.PropertyChanged += null, new PropertyChangedEventArgs(propertyName)); // Assert updateReactionMock.Verify(u => u.UpdateCollection( It.IsAny <ICollectionView>(), It.IsAny <IUserPreferences>()), Times.Never); }
public void ReactionInMappingIsNotTriggeredOnNonMatchingPropertyUpdate() { // Arrange var updateReactionMock = new Mock <IUpdateReaction>(); updateReactionMock .Setup(u => u.UpdateCollection( It.IsAny <ICollectionView>(), It.IsAny <IUserPreferences>())); var mappingTable = new Dictionary <string, IEnumerable <IUpdateReaction> > { ["MappedProperty"] = new[] { updateReactionMock.Object } }; var mapping = new TestingUpdateReactionMapping(mappingTable); var userPreferencesMock = new Mock <IUserPreferences>(); var collectionView = Mock.Of <ICollectionView>(); var manager = new UpdateReactionManager(mapping, userPreferencesMock.Object); manager.Initialize(collectionView); // Calling Initialize will invoke IUpdateReaction.UpdateCollection // Reset calls so that it is possible to verify the number of times // it is called as a result of raising PropertyChanged updateReactionMock.Invocations.Clear(); // Act userPreferencesMock.Raise(u => u.PropertyChanged += null, new PropertyChangedEventArgs("UnmappedPropertyName")); // Assert updateReactionMock.Verify(u => u.UpdateCollection( It.IsAny <ICollectionView>(), It.IsAny <IUserPreferences>()), Times.Never); }