public void Compare_ExceptionDuringGetResult_SwallowsException()
        {
            var valueA      = TypeWithAllDataTypes.Create();
            var valueThrows = TypeWithAllDataTypes.Create();

            var resultA = MockRepository.GenerateStub <IBusinessObjectPropertyPathResult>();

            resultA.Stub(_ => _.GetValue()).Return(new object());

            var propertyPathStub = MockRepository.GenerateStub <IBusinessObjectPropertyPath>();

            propertyPathStub
            .Stub(
                _ =>
                _.GetResult(
                    (IBusinessObject)valueA,
                    BusinessObjectPropertyPath.UnreachableValueBehavior.ReturnNullForUnreachableValue,
                    BusinessObjectPropertyPath.ListValueBehavior.GetResultForFirstListEntry))
            .Return(resultA);

            propertyPathStub
            .Stub(
                _ =>
                _.GetResult(
                    (IBusinessObject)valueThrows,
                    BusinessObjectPropertyPath.UnreachableValueBehavior.ReturnNullForUnreachableValue,
                    BusinessObjectPropertyPath.ListValueBehavior.GetResultForFirstListEntry))
            .Throw(new Exception());

            var comparer = new BusinessObjectPropertyPathBasedComparer(propertyPathStub);

            CompareEqualValues(comparer, (IBusinessObject)valueThrows, (IBusinessObject)valueThrows);
            CompareAscendingValues(comparer, (IBusinessObject)valueThrows, (IBusinessObject)valueA);
            CompareDescendingValues(comparer, (IBusinessObject)valueA, (IBusinessObject)valueThrows);
        }
        protected void CheckValues(IBusinessObject value, string stringValue, int int32Value)
        {
            TypeWithAllDataTypes typeWithAllDataTypes = ArgumentUtility.CheckNotNullAndType <TypeWithAllDataTypes> ("value", value);

            Assert.That(typeWithAllDataTypes.String, Is.EqualTo(stringValue));
            Assert.That(typeWithAllDataTypes.Int32, Is.EqualTo(int32Value));
        }
예제 #3
0
        public override void SetUp()
        {
            base.SetUp();
            _bocTextValue    = new BocTextValueMock();
            _bocTextValue.ID = "BocTextValue";
            NamingContainer.Controls.Add(_bocTextValue);

            _businessObject = (IBusinessObject)TypeWithAllDataTypes.Create();

            _dataSource                = new BindableObjectDataSourceControl();
            _dataSource.Type           = typeof(TypeWithAllDataTypes);
            _dataSource.BusinessObject = _businessObject;

            _cultureScope = new CultureScope("");
        }
        public override void SetUp()
        {
            base.SetUp();

            _editModeHost                           = new FakeEditModeHost();
            _editModeHost.ID                        = "BocList";
            _editModeHost.RowIDProvider             = new FakeRowIDProvider();
            _editModeHost.EditModeControlFactory    = EditableRowControlFactory.CreateEditableRowControlFactory();
            _editModeHost.EditModeDataSourceFactory = new EditableRowDataSourceFactory();

            _editableRow    = new EditableRow(_editModeHost);
            _editableRow.ID = "Row";
            NamingContainer.Controls.Add(_editableRow);

            _value01 = (IBusinessObject)TypeWithAllDataTypes.Create("A", 1);

            _typeWithAllDataTypesClass = BindableObjectProviderTestHelper.GetBindableObjectClass(typeof(TypeWithAllDataTypes));

            _typeWithAllDataTypesStringValuePath = BusinessObjectPropertyPath.CreateStatic(_typeWithAllDataTypesClass, "String");
            _typeWithAllDataTypesInt32ValuePath  = BusinessObjectPropertyPath.CreateStatic(_typeWithAllDataTypesClass, "Int32");

            _typeWithAllDataTypesStringValueSimpleColumn = new BocSimpleColumnDefinition();
            _typeWithAllDataTypesStringValueSimpleColumn.SetPropertyPath(_typeWithAllDataTypesStringValuePath);

            _typeWithAllDataTypesStringValueSimpleColumnAsDynamic = new BocSimpleColumnDefinition();
            _typeWithAllDataTypesStringValueSimpleColumnAsDynamic.SetPropertyPath(BusinessObjectPropertyPath.CreateDynamic("StringValue"));
            _typeWithAllDataTypesStringValueSimpleColumnAsDynamic.IsDynamic = true;

            _typeWithAllDataTypesInt32ValueSimpleColumn = new BocSimpleColumnDefinition();
            _typeWithAllDataTypesInt32ValueSimpleColumn.SetPropertyPath(_typeWithAllDataTypesInt32ValuePath);

            _typeWithAllDataTypesStringValueFirstValueCompoundColumn = new BocCompoundColumnDefinition();
            _typeWithAllDataTypesStringValueFirstValueCompoundColumn.PropertyPathBindings.Add(
                new PropertyPathBinding(_typeWithAllDataTypesStringValuePath));
            _typeWithAllDataTypesStringValueFirstValueCompoundColumn.PropertyPathBindings.Add(
                new PropertyPathBinding(_typeWithAllDataTypesStringValuePath));
            _typeWithAllDataTypesStringValueFirstValueCompoundColumn.FormatString = "{0}, {1}";

            _typeWithAllDataTypesStringValueCustomColumn = new BocCustomColumnDefinition();
            _typeWithAllDataTypesStringValueCustomColumn.SetPropertyPath(_typeWithAllDataTypesStringValuePath);
            _typeWithAllDataTypesStringValueCustomColumn.IsSortable = true;

            _commandColumn      = new BocCommandColumnDefinition();
            _rowEditModeColumn  = new BocRowEditModeColumnDefinition();
            _dropDownMenuColumn = new BocDropDownMenuColumnDefinition();
        }
        public void Compare_StringValues()
        {
            var valueA = TypeWithAllDataTypes.Create();

            valueA.String = "A";

            var valueB = TypeWithAllDataTypes.Create();

            valueB.String = "B";

            var valueNull = TypeWithAllDataTypes.Create();

            valueNull.String = null;

            var bindableObjectClass = BindableObjectProviderTestHelper.GetBindableObjectClass(typeof(TypeWithAllDataTypes));

            var propertyPath = BusinessObjectPropertyPath.CreateStatic(bindableObjectClass, "String");
            var comparer     = new BusinessObjectPropertyPathBasedComparer(propertyPath);

            AssertCompare(comparer, valueA, valueB, valueNull);
        }
        public override void SetUp()
        {
            base.SetUp();

            _actualEvents = new StringCollection();

            _values    = new IBusinessObject[5];
            _values[0] = (IBusinessObject)TypeWithAllDataTypes.Create("A", 1);
            _values[1] = (IBusinessObject)TypeWithAllDataTypes.Create("B", 2);
            _values[2] = (IBusinessObject)TypeWithAllDataTypes.Create("C", 3);
            _values[3] = (IBusinessObject)TypeWithAllDataTypes.Create("D", 4);
            _values[4] = (IBusinessObject)TypeWithAllDataTypes.Create("E", 5);

            _newValues    = new IBusinessObject[2];
            _newValues[0] = (IBusinessObject)TypeWithAllDataTypes.Create("F", 6);
            _newValues[1] = (IBusinessObject)TypeWithAllDataTypes.Create("G", 7);

            _class = BindableObjectProviderTestHelper.GetBindableObjectClass(typeof(TypeWithAllDataTypes));

            _stringValuePath = BusinessObjectPropertyPath.CreateStatic(_class, "String");
            _int32ValuePath  = BusinessObjectPropertyPath.CreateStatic(_class, "Int32");

            _stringValueSimpleColumn = new BocSimpleColumnDefinition();
            _stringValueSimpleColumn.SetPropertyPath(_stringValuePath);

            _int32ValueSimpleColumn = new BocSimpleColumnDefinition();
            _int32ValueSimpleColumn.SetPropertyPath(_int32ValuePath);

            _columns    = new BocColumnDefinition[2];
            _columns[0] = _stringValueSimpleColumn;
            _columns[1] = _int32ValueSimpleColumn;

            _editModeHost    = new FakeEditModeHost();
            _editModeHost.ID = "BocList";

            _controller    = new EditModeController(_editModeHost);
            _controller.ID = "Controller";
            NamingContainer.Controls.Add(_controller);

            _controllerInvoker = new ControlInvoker(_controller);

            _editModeHost.NotifyOnEditableRowChangesCanceled  = (i, o) => _actualEvents.Add(FormatChangesCanceledEventMessage(i, o));
            _editModeHost.NotifyOnEditableRowChangesCanceling = (i, o) => _actualEvents.Add(FormatChangesCancelingEventMessage(i, o));
            _editModeHost.NotifyOnEditableRowChangesSaved     = (i, o) => _actualEvents.Add(FormatChangesSavedEventMessage(i, o));
            _editModeHost.NotifyOnEditableRowChangesSaving    = (i, o) => _actualEvents.Add(FormatChangesSavingEventMessage(i, o));
            _editModeHost.NotifyAddRows =
                objects =>
            {
                var oldLength = _editModeHost.Value.Count;
                _editModeHost.Value = ((IBusinessObject[])_editModeHost.Value).Concat(objects).ToArray();
                return(((IBusinessObject[])_editModeHost.Value).Select((o, i) => new BocListRow(i, o)).Skip(oldLength).ToArray());
            };
            _editModeHost.NotifyRemoveRows =
                objects =>
            {
                var removedRows = ((IBusinessObject[])_editModeHost.Value)
                                  .Select((o, i) => new BocListRow(i, o))
                                  .Where(r => objects.Contains(r.BusinessObject))
                                  .ToArray();
                _editModeHost.Value = ((IBusinessObject[])_editModeHost.Value).Except(objects).ToArray();
                return(removedRows);
            };
            _editModeHost.NotifyEndRowEditModeCleanUp  = i => _actualEvents.Add(FormatEndRowEditModeCleanUp(i));
            _editModeHost.NotifyEndListEditModeCleanUp = () => _actualEvents.Add(FormatEndListEditModeCleanUp());
            _editModeHost.NotifyValidateEditableRows   = () => _actualEvents.Add(FormatValidateEditableRows());
            _editModeHost.Value                     = _values;
            _editModeHost.RowIDProvider             = new FakeRowIDProvider();
            _editModeHost.EditModeControlFactory    = EditableRowControlFactory.CreateEditableRowControlFactory();
            _editModeHost.EditModeDataSourceFactory = new EditableRowDataSourceFactory();
            _editModeHost.EnableEditModeValidator   = true;
            _editModeHost.AreCustomCellsValid       = true;
        }