Ejemplo n.º 1
0
        public void GivenPropertyGridViewWithNewDataSet_WhenRefreshRequiredEventRaisedOnPreviouslySetData_ThenRefreshNotTriggered()
        {
            // Given
            var dataObject1 = new object();
            var dataObject2 = new object();

            var mockRepository    = new MockRepository();
            var objectProperties1 = mockRepository.Stub <IObjectProperties>();
            var objectProperties2 = mockRepository.Stub <IObjectProperties>();
            var propertyResolver  = mockRepository.StrictMock <IPropertyResolver>();

            propertyResolver.Expect(prs => prs.GetObjectProperties(dataObject1)).Return(new DynamicPropertyBag(objectProperties1));
            propertyResolver.Expect(prs => prs.GetObjectProperties(dataObject2)).Return(new DynamicPropertyBag(objectProperties2));
            mockRepository.ReplayAll();

            using (var propertyGridView = new TestGuiPropertyGridView(propertyResolver)
            {
                Data = dataObject1
            })
            {
                propertyGridView.Data = dataObject2;

                // When
                objectProperties1.Raise(p => p.RefreshRequired += null,
                                        objectProperties1,
                                        EventArgs.Empty);

                // Then
                Assert.AreEqual(0, propertyGridView.RefreshCalled);
            }

            mockRepository.VerifyAll();
        }
Ejemplo n.º 2
0
        public void GivenDisposedPropertyGridViewWithDataSet_WhenRefreshRequiredEventRaised_ThenRefreshNotTriggered()
        {
            // Given
            var dataObject = new object();

            var mockRepository   = new MockRepository();
            var objectProperties = mockRepository.Stub <IObjectProperties>();
            var propertyResolver = mockRepository.StrictMock <IPropertyResolver>();

            propertyResolver.Expect(prs => prs.GetObjectProperties(dataObject)).Return(new DynamicPropertyBag(objectProperties));
            mockRepository.ReplayAll();

            var propertyGridView = new TestGuiPropertyGridView(propertyResolver)
            {
                Data = dataObject
            };

            propertyGridView.Dispose();

            // When
            objectProperties.Raise(p => p.RefreshRequired += null,
                                   objectProperties,
                                   EventArgs.Empty);

            // Then
            Assert.AreEqual(0, propertyGridView.RefreshCalled);
            mockRepository.VerifyAll();
        }
Ejemplo n.º 3
0
        public void GivenPropertyGridViewWithObservableDataSet_WhenNewDataObjectSet_ThenPreviousDataObserverDetached()
        {
            // Given
            var mockRepository       = new MockRepository();
            var observableDataObject = mockRepository.StrictMock <IObservable>();

            observableDataObject.Expect(d => d.Attach(null)).IgnoreArguments();
            observableDataObject.Expect(d => d.Detach(null)).IgnoreArguments();
            var dataObjectProperties = mockRepository.Stub <IObjectProperties>();

            dataObjectProperties.Data = observableDataObject;

            var newDataObject    = new object();
            var propertyResolver = mockRepository.StrictMock <IPropertyResolver>();

            propertyResolver.Expect(prs => prs.GetObjectProperties(observableDataObject)).Return(new DynamicPropertyBag(dataObjectProperties));
            propertyResolver.Expect(prs => prs.GetObjectProperties(newDataObject)).Return(null);
            mockRepository.ReplayAll();

            using (var propertyGridView = new TestGuiPropertyGridView(propertyResolver))
            {
                propertyGridView.Data = observableDataObject;

                // When
                propertyGridView.Data = newDataObject;
            }

            // Then
            mockRepository.VerifyAll();
        }
Ejemplo n.º 4
0
        public void GivenPropertyGridViewWithDisposableDataSet_WhenDisposing_ThenObjectPropertiesCorrectlyDisposed()
        {
            // Given
            var    mockRepository       = new MockRepository();
            var    dataObject           = new object();
            object dataObjectProperties = mockRepository.StrictMultiMock(typeof(IDisposable), typeof(IObjectProperties));

            dataObjectProperties.Expect(d => ((IDisposable)d).Dispose());
            dataObjectProperties.Expect(d => ((IObjectProperties)d).RefreshRequired += null).IgnoreArguments();
            dataObjectProperties.Expect(d => ((IObjectProperties)d).RefreshRequired -= null).IgnoreArguments();
            dataObjectProperties.Stub(d => ((IObjectProperties)d).Data).Return(dataObject);

            var propertyResolver = mockRepository.StrictMock <IPropertyResolver>();

            propertyResolver.Expect(prs => prs.GetObjectProperties(dataObject)).Return(new DynamicPropertyBag(dataObjectProperties));
            mockRepository.ReplayAll();

            var propertyGridView = new TestGuiPropertyGridView(propertyResolver)
            {
                Data = dataObject
            };

            // When
            propertyGridView.Dispose();

            // Then
            mockRepository.VerifyAll();
        }
Ejemplo n.º 5
0
        public void Data_SetSameDataObject_NoRedundantViewUpdate()
        {
            // Setup
            var dataObject = new object();

            var mockRepository   = new MockRepository();
            var propertyResolver = mockRepository.StrictMock <IPropertyResolver>();

            propertyResolver.Expect(prs => prs.GetObjectProperties(dataObject)).Return(null);
            mockRepository.ReplayAll();

            using (var propertyGridView = new TestGuiPropertyGridView(propertyResolver))
            {
                propertyGridView.Data = dataObject;

                object selectedObject = propertyGridView.SelectedObject;

                // Call
                propertyGridView.Data = dataObject;

                // Assert
                Assert.AreSame(selectedObject, propertyGridView.SelectedObject);
                Assert.AreEqual(0, propertyGridView.RefreshCalled);
            }

            mockRepository.VerifyAll();
        }