Exemplo n.º 1
0
        public void ValueChangeUpdatesTargetProperty()
        {
            const string updatedValue = "Updated";

            var target = new EditableStruct {
                Text = "Initial"
            };
            var editorComponent = new EditorComponentVM <string>();
            var propertyAdapter = EditableStructMetadata.TextProperty;
            var sut             = new ScalarPropertyDataEditor <EditableStruct, string, EditorComponentVM <string> >(propertyAdapter,
                                                                                                                     editorComponent);

            // act
            sut.MonitorEvents();

            sut.EditableTarget = target;

            sut.Component.Value = updatedValue;

            // assert
            sut.ShouldRaise("TargetUpdated")
            .WithSender(sut);

            sut.Component.Value.Should().Be(updatedValue);
        }
Exemplo n.º 2
0
        public void ReadonlyStateIsAssignedToComponent()
        {
            var editorComponent = new EditorComponentVM <string>();
            var propertyAdapter = EditableStructMetadata.ReadonlyTextProperty;

            // act
            var sut = new ScalarPropertyDataEditor <EditableStruct, string, EditorComponentVM <string> >(propertyAdapter, editorComponent);

            // assert
            sut.Component.IsReadOnly.Should().Be(EditableStructMetadata.ReadonlyTextProperty.IsReadOnly);
        }
Exemplo n.º 3
0
        public void WhatWasSetIsWhatValueReturns()
        {
            var sut         = new EditorComponentVM <string>();
            var implicitSut = (IEditorComponent <string>)sut;

            const string sample = "sample";

            // act
            implicitSut.SetValue(sample);

            // assert
            sut.Value.Should().Be(sample);
        }
Exemplo n.º 4
0
        public void SetErrorRaisesPropertyChangeNotification()
        {
            var sut = new EditorComponentVM <string>();

            const string error = "error";

            // act
            sut.MonitorEvents();
            sut.SetError(error);

            // assert
            sut.ShouldRaisePropertyChangeFor(x => x.Value);
        }
Exemplo n.º 5
0
        public void WhatWasAssignedToValueIsWhatGetValueReturns()
        {
            var sut         = new EditorComponentVM <string>();
            var implicitSut = (IEditorComponent <string>)sut;

            const string sample = "sample";

            // act
            sut.Value = sample;

            // assert
            implicitSut.GetValue().Should().Be(sample);
        }
Exemplo n.º 6
0
        public void SetValueRaisesPropertyChangeNotification()
        {
            var sut         = new EditorComponentVM <string>();
            var implicitSut = (IEditorComponent <string>)sut;

            const string sample = "sample";

            // act
            sut.MonitorEvents();
            implicitSut.SetValue(sample);

            // assert
            sut.ShouldRaisePropertyChangeFor(x => x.Value);
        }
Exemplo n.º 7
0
        public void NonEmptyErrorMessageValueIsWhatErrorInterfaceReturns()
        {
            var sut         = new EditorComponentVM <string>();
            var implicitSut = (IDataErrorInfo)sut;

            const string error = "error";

            // act
            sut.SetError(error);

            // assert
            implicitSut.Error.Should().Be(error);
            implicitSut["Value"].Should().Be(error);
        }
Exemplo n.º 8
0
        public void NullEditableTargetIsTolerated()
        {
            var editorComponent = new EditorComponentVM <string>();
            var propertyAdapter = EditableClassMetadata.TextProperty;
            var sut             = new ScalarPropertyDataEditor <EditableClass, string, EditorComponentVM <string> >(propertyAdapter, editorComponent);

            // act
            sut.Component.MonitorEvents();

            sut.EditableTarget = null;

            // assert
            sut.Component.Value.Should().Be(default(string));
        }
Exemplo n.º 9
0
        public void EventIsRaisedWhenReadOnlyStateIsUpdated()
        {
            var sut         = new EditorComponentVM <string>();
            var implicitSut = (IEditorComponent <string>)sut;

            const bool isReadOnly = true;

            // act
            implicitSut.MonitorEvents();

            implicitSut.SetReadOnly(isReadOnly);

            // assert
            sut.ShouldRaisePropertyChangeFor(x => x.IsReadOnly);
            sut.IsReadOnly.Should().Be(isReadOnly);
        }
Exemplo n.º 10
0
        public void AssignedValueCausesEventToBeRaised()
        {
            var sut         = new EditorComponentVM <string>();
            var implicitSut = (IEditorComponent <string>)sut;

            const string sample = "sample";

            // act
            implicitSut.MonitorEvents();
            sut.Value = sample;

            // assert
            implicitSut.ShouldRaise("ValueUpdated")
            .WithSender(implicitSut)
            .WithArgs <EventArgs>(args => args == EventArgs.Empty);
        }
Exemplo n.º 11
0
        public void ValueUpdateChangeReportedOnTargetUpdate()
        {
            var target = new EditableClass {
                Text = "Initial"
            };
            var editorComponent = new EditorComponentVM <string>();
            var propertyAdapter = EditableClassMetadata.TextProperty;
            var sut             = new ScalarPropertyDataEditor <EditableClass, string, EditorComponentVM <string> >(propertyAdapter, editorComponent);

            // act
            sut.Component.MonitorEvents();

            sut.EditableTarget = target;

            // assert
            sut.Component.ShouldRaisePropertyChangeFor(x => x.Value);
            sut.Component.Value.Should().Be(target.Text);
        }