public void EditValue_WithCurrentItemInAvailableItems_ReturnsCurrentItem() { // Setup var mockRepository = new MockRepository(); var provider = mockRepository.DynamicMock <IServiceProvider>(); var service = mockRepository.DynamicMock <IWindowsFormsEditorService>(); var context = mockRepository.DynamicMock <ITypeDescriptorContext>(); var hasStochasticSoilProfile = mockRepository.Stub <IHasStochasticSoilProfile>(); var stochasticSoilProfile = new PipingStochasticSoilProfile(1.0, PipingSoilProfileTestFactory.CreatePipingSoilProfile()); hasStochasticSoilProfile.Stub(hssp => hssp.StochasticSoilProfile).Return(stochasticSoilProfile); hasStochasticSoilProfile.Stub(hssp => hssp.GetAvailableStochasticSoilProfiles()).Return( new[] { stochasticSoilProfile }); var editor = new PipingInputContextStochasticSoilProfileSelectionEditor <IHasStochasticSoilProfile>(); var someValue = new object(); var propertyBag = new DynamicPropertyBag(hasStochasticSoilProfile); provider.Expect(p => p.GetService(null)).IgnoreArguments().Return(service); service.Expect(s => s.DropDownControl(null)).IgnoreArguments(); context.Expect(c => c.Instance).Return(propertyBag); mockRepository.ReplayAll(); // Call object result = editor.EditValue(context, provider, someValue); // Assert Assert.AreSame(stochasticSoilProfile, result); mockRepository.VerifyAll(); }
public void EditValue_WithCurrentItemInAvailableItems_ReturnsCurrentItem() { // Setup var selectedHydraulicBoundaryLocation = new HydraulicBoundaryLocation(23, "name", 0, 0); var properties = new ObjectPropertiesWithSelectableHydraulicBoundaryLocation( new SelectableHydraulicBoundaryLocation(selectedHydraulicBoundaryLocation, null), new[] { new SelectableHydraulicBoundaryLocation(selectedHydraulicBoundaryLocation, null) }); var propertyBag = new DynamicPropertyBag(properties); var editor = new HydraulicBoundaryLocationEditor(); var someValue = new object(); var serviceProvider = mockRepository.Stub <IServiceProvider>(); var service = mockRepository.Stub <IWindowsFormsEditorService>(); var descriptorContext = mockRepository.Stub <ITypeDescriptorContext>(); serviceProvider.Stub(p => p.GetService(null)).IgnoreArguments().Return(service); descriptorContext.Stub(c => c.Instance).Return(propertyBag); mockRepository.ReplayAll(); // Call object result = editor.EditValue(descriptorContext, serviceProvider, someValue); // Assert Assert.AreEqual(new SelectableHydraulicBoundaryLocation(selectedHydraulicBoundaryLocation, null), result); mockRepository.VerifyAll(); }
public void GetProperties_SomePropertiesWithOrderAttribute_ReturnElementsInDesiredOrdering() { // Setup var dynamicPropertyBag = new DynamicPropertyBag(new TestOrderedProperties()); // Call PropertyDescriptorCollection propertyDescriptorCollection = dynamicPropertyBag.GetProperties(); // Assert var index = 0; Assert.AreEqual("PropSix", propertyDescriptorCollection[index++].DisplayName); Assert.AreEqual("PropFour", propertyDescriptorCollection[index++].DisplayName); Assert.AreEqual("PropTwo", propertyDescriptorCollection[index++].DisplayName); Assert.AreEqual("PropOne", propertyDescriptorCollection[index++].DisplayName); Assert.AreEqual("Description", propertyDescriptorCollection[index++].DisplayName); Assert.AreEqual("PropFive", propertyDescriptorCollection[index++].DisplayName); Assert.AreEqual("Name", propertyDescriptorCollection[index++].DisplayName); PropertyDescriptor propThreeDescriptor = propertyDescriptorCollection.Find("PropThree", false); Assert.GreaterOrEqual(propertyDescriptorCollection.IndexOf(propThreeDescriptor), index, "PropThree is not decorated with PropertyOrderAttribute or DynamicPropertyOrderAttribute, therefore should come after those that are."); PropertyDescriptor propSevenDescriptor = propertyDescriptorCollection.Find("PropSeven", false); Assert.GreaterOrEqual(propertyDescriptorCollection.IndexOf(propSevenDescriptor), index, "PropSeven is not decorated with PropertyOrderAttribute or DynamicPropertyOrderAttribute, therefore should come after those that are."); }
public void EditValue_WithCurrentItemNotInAvailableItems_ReturnsOriginalValue() { // Setup var mockRepository = new MockRepository(); var provider = mockRepository.DynamicMock <IServiceProvider>(); var service = mockRepository.DynamicMock <IWindowsFormsEditorService>(); var context = mockRepository.DynamicMock <ITypeDescriptorContext>(); var hasSurfaceLineProperty = mockRepository.Stub <IHasSurfaceLineProperty>(); hasSurfaceLineProperty.Stub(hslp => hslp.SurfaceLine).Return(new PipingSurfaceLine("1")); hasSurfaceLineProperty.Stub(hslp => hslp.GetAvailableSurfaceLines()).Return(new[] { new PipingSurfaceLine("2") }); var editor = new PipingInputContextSurfaceLineSelectionEditor <IHasSurfaceLineProperty>(); var someValue = new object(); var propertyBag = new DynamicPropertyBag(hasSurfaceLineProperty); provider.Expect(p => p.GetService(null)).IgnoreArguments().Return(service); service.Expect(s => s.DropDownControl(null)).IgnoreArguments(); context.Expect(c => c.Instance).Return(propertyBag); mockRepository.ReplayAll(); // Call object result = editor.EditValue(context, provider, someValue); // Assert Assert.AreSame(someValue, result); mockRepository.VerifyAll(); }
public void EditValue_WithCurrentItemInAvailableItems_ReturnsCurrentItem() { // Setup var simpleStructure = new TestStructure(); var properties = new ObjectPropertiesWithStructure(simpleStructure, new[] { simpleStructure }); var propertyBag = new DynamicPropertyBag(properties); var editor = new StructureEditor <TestStructure>(); var someValue = new object(); var serviceProvider = mockRepository.Stub <IServiceProvider>(); var service = mockRepository.Stub <IWindowsFormsEditorService>(); var descriptorContext = mockRepository.Stub <ITypeDescriptorContext>(); serviceProvider.Stub(p => p.GetService(null)).IgnoreArguments().Return(service); descriptorContext.Stub(c => c.Instance).Return(propertyBag); mockRepository.ReplayAll(); // Call object result = editor.EditValue(descriptorContext, serviceProvider, someValue); // Assert Assert.AreSame(simpleStructure, result); mockRepository.VerifyAll(); }
public void EditValue_WithCurrentItemNotInAvailableItems_ReturnsOriginalValue() { // Setup var selectableTargetProbability = new SelectableTargetProbability( new AssessmentSectionStub(), Enumerable.Empty <HydraulicBoundaryLocationCalculation>(), WaveConditionsInputWaterLevelType.None, 0.1); var properties = new ObjectPropertiesWithSelectableTargetProbability( selectableTargetProbability, Enumerable.Empty <SelectableTargetProbability>()); var propertyBag = new DynamicPropertyBag(properties); var editor = new WaveConditionsInputContextTargetProbabilitySelectionEditor(); var someValue = new object(); var mocks = new MockRepository(); var serviceProvider = mocks.Stub <IServiceProvider>(); var service = mocks.Stub <IWindowsFormsEditorService>(); var descriptorContext = mocks.Stub <ITypeDescriptorContext>(); serviceProvider.Stub(p => p.GetService(null)).IgnoreArguments().Return(service); descriptorContext.Stub(c => c.Instance).Return(propertyBag); mocks.ReplayAll(); // Call object result = editor.EditValue(descriptorContext, serviceProvider, someValue); // Assert Assert.AreSame(someValue, result); mocks.VerifyAll(); }
/// <summary> /// Gets all visible property descriptors for a given 'object properties' object. /// </summary> /// <param name="propertiesObject">The properties object.</param> /// <returns>All visible property descriptors.</returns> public static PropertyDescriptorCollection GetAllVisiblePropertyDescriptors(object propertiesObject) { var dynamicPropertyBag = new DynamicPropertyBag(propertiesObject); return(dynamicPropertyBag.GetProperties(new Attribute[] { BrowsableAttribute.Yes })); }
public void EditValue_WithCurrentItemInAvailableItems_ReturnsCurrentItem() { // Setup var mockRepository = new MockRepository(); var provider = mockRepository.DynamicMock <IServiceProvider>(); var service = mockRepository.DynamicMock <IWindowsFormsEditorService>(); var context = mockRepository.DynamicMock <ITypeDescriptorContext>(); var assessmentSection = mockRepository.Stub <IAssessmentSection>(); var handler = mockRepository.Stub <IObservablePropertyChangeHandler>(); var surfaceLine = new MacroStabilityInwardsSurfaceLine(string.Empty); surfaceLine.SetGeometry(new[] { new Point3D(0.0, 0.0, 0.0), new Point3D(1.0, 0.0, 1.0) }); var calculation = new MacroStabilityInwardsCalculationScenario(); var failureMechanism = new MacroStabilityInwardsFailureMechanism(); var input = new MacroStabilityInwardsInput(new MacroStabilityInwardsInput.ConstructionProperties()) { SurfaceLine = surfaceLine }; var inputParametersContext = new MacroStabilityInwardsInputContext(input, calculation, new[] { surfaceLine }, Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(), failureMechanism, assessmentSection); var properties = new MacroStabilityInwardsInputContextProperties(inputParametersContext, AssessmentSectionTestHelper.GetTestAssessmentLevel, handler); var editor = new MacroStabilityInwardsInputContextSurfaceLineSelectionEditor(); var someValue = new object(); var propertyBag = new DynamicPropertyBag(properties); provider.Expect(p => p.GetService(null)).IgnoreArguments().Return(service); service.Expect(s => s.DropDownControl(null)).IgnoreArguments(); context.Expect(c => c.Instance).Return(propertyBag); mockRepository.ReplayAll(); // Call object result = editor.EditValue(context, provider, someValue); // Assert Assert.AreSame(surfaceLine, result); mockRepository.VerifyAll(); }
static void Main(string[] args) { dynamic bag = new DynamicPropertyBag(); bag.Contact = new Contact(); bag.Contact.Name = "Alex"; bag.Contact.LastName = "Kaplunov"; string message = bag.ToString(); Console.WriteLine(message); Console.ReadKey(); }
public void Constructor_ClassWith4Properties_CorrectNumberOfPropertiesCreated() { // Setup var propertyObject = new TestProperties(); // Call var dynamicPropertyBag = new DynamicPropertyBag(propertyObject); // Assert Assert.AreEqual(4, dynamicPropertyBag.Properties.Count(), "Expected property count wrong"); }
public void GetDefaultProperty_ObjectHasNotProperties_ReturnNull() { // Setup var dynamicPropertyBag = new DynamicPropertyBag(new object()); // Call PropertyDescriptor defaultProperty = dynamicPropertyBag.GetDefaultProperty(); // Assert Assert.IsNull(defaultProperty); }
public void ToString_ReturnToStringFromWrappedObject() { // Setup var target = new TestProperties(); var dynamicPropertyBag = new DynamicPropertyBag(target); // Call string text = dynamicPropertyBag.ToString(); // Assert Assert.AreEqual(target.ToString(), text); }
public void GetClassName_Always_ReturnDynamicPropertyBagClassName() { // Setup var target = new TestProperties(); var dynamicPropertyBag = new DynamicPropertyBag(target); // Call string className = dynamicPropertyBag.GetClassName(); // Assert Assert.AreEqual(dynamicPropertyBag.GetType().FullName, className); }
public void GetPropertyOwner_Always_ReturnWrappedObject() { // Setup var propertyObject = new TestProperties(); var dynamicPropertyBag = new DynamicPropertyBag(propertyObject); // Call object owner = dynamicPropertyBag.GetPropertyOwner(null); // Assert Assert.AreSame(propertyObject, owner); }
public void GetComponentName_Always_ReturnNull() { // Setup var target = new TestProperties(); var dynamicPropertyBag = new DynamicPropertyBag(target); // Call string componentName = dynamicPropertyBag.GetComponentName(); // Assert Assert.IsNull(componentName); }
public void GetProperties_ClassWithPropertiesWithoutPublicSetter_PropertiesDecoratedWithReadOnlyAttribute() { // Setup var dynamicPropertyBag = new DynamicPropertyBag(new TestWithoutSetterPropertyClassProperties()); // Call PropertyDescriptorCollection propertyDescriptorCollection = dynamicPropertyBag.GetProperties(); // Assert Assert.IsTrue(propertyDescriptorCollection[0].Attributes.Matches(ReadOnlyAttribute.Yes)); Assert.IsTrue(propertyDescriptorCollection[1].Attributes.Matches(ReadOnlyAttribute.Yes)); }
public void GetAttributes_Always_ReturnEmpty() { // Setup var target = new TestProperties(); var dynamicPropertyBag = new DynamicPropertyBag(target); // Call AttributeCollection attributes = dynamicPropertyBag.GetAttributes(); // Assert CollectionAssert.IsEmpty(attributes); }
public void GetConverter_Always_ReturnDefaultTypeConverter() { // Setup var target = new TestProperties(); var dynamicPropertyBag = new DynamicPropertyBag(target); // Call TypeConverter typeConverter = dynamicPropertyBag.GetConverter(); // Assert Assert.AreEqual(TypeDescriptor.GetConverter(dynamicPropertyBag, true), typeConverter); }
public void GetDefaultEvent_Always_ReturnNull() { // Setup var target = new TestProperties(); var dynamicPropertyBag = new DynamicPropertyBag(target); // Call EventDescriptor eventDescriptor = dynamicPropertyBag.GetDefaultEvent(); // Assert Assert.IsNull(eventDescriptor); }
public void GetEventsParametered_Always_ReturnEmpty() { // Setup var target = new TestProperties(); var dynamicPropertyBag = new DynamicPropertyBag(target); // Call EventDescriptorCollection events = dynamicPropertyBag.GetEvents(new Attribute[0]); // Assert CollectionAssert.IsEmpty(events); }
public void GetEditor_Always_ReturnNull() { // Setup var target = new TestProperties(); var dynamicPropertyBag = new DynamicPropertyBag(target); // Call object editor = dynamicPropertyBag.GetEditor(typeof(UITypeEditor)); // Assert Assert.IsNull(editor); }
public void ParameteredConstructor_ExpectedValues() { // Setup var propertyObject = new object(); // Call var dynamicPropertyBag = new DynamicPropertyBag(propertyObject); // Assert CollectionAssert.IsEmpty(dynamicPropertyBag.Properties, "Object has no properties, therefore bag should have none too."); Assert.AreSame(propertyObject, dynamicPropertyBag.WrappedObject); }
public void GetDefaultProperty_ObjectWithProperties_ReturnFirstFromProperties() { // Setup var target = new TestProperties(); var dynamicPropertyBag = new DynamicPropertyBag(target); // Call PropertyDescriptor defaultProperty = dynamicPropertyBag.GetDefaultProperty(); // Assert Assert.NotNull(defaultProperty); Assert.AreEqual(dynamicPropertyBag.Properties.First().Name, defaultProperty.Name); }
public void EditValue_WithCurrentItemInAvailableItems_ReturnsCurrentItem() { // Setup DikeProfile dikeProfile = DikeProfileTestFactory.CreateDikeProfile(); var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); failureMechanism.DikeProfiles.AddRange(new[] { dikeProfile }, "path"); var grassCoverErosionInwardsInput = new GrassCoverErosionInwardsInput { DikeProfile = dikeProfile }; var grassCoverErosionInwardsCalculation = new GrassCoverErosionInwardsCalculation(); var assessmentSection = mockRepository.Stub <IAssessmentSection>(); var inputContext = new GrassCoverErosionInwardsInputContext(grassCoverErosionInwardsInput, grassCoverErosionInwardsCalculation, failureMechanism, assessmentSection); var handler = mockRepository.Stub <IObservablePropertyChangeHandler>(); var properties = new GrassCoverErosionInwardsInputContextProperties(inputContext, handler); var editor = new GrassCoverErosionInwardsInputContextDikeProfileEditor(); var propertyBag = new DynamicPropertyBag(properties); var serviceProvider = mockRepository.StrictMock <IServiceProvider>(); var service = mockRepository.StrictMock <IWindowsFormsEditorService>(); var descriptorContext = mockRepository.StrictMock <ITypeDescriptorContext>(); serviceProvider.Expect(p => p.GetService(null)).IgnoreArguments().Return(service); service.Expect(s => s.DropDownControl(null)).IgnoreArguments(); service.Expect(s => s.CloseDropDown()).IgnoreArguments(); descriptorContext.Expect(c => c.Instance).Return(propertyBag).Repeat.Twice(); mockRepository.ReplayAll(); var someValue = new object(); // Call object result = editor.EditValue(descriptorContext, serviceProvider, someValue); // Assert Assert.AreSame(dikeProfile, result); mockRepository.VerifyAll(); }
public void GetProperties_RepeatedConstructionsForSameState_RetainSameElementOrderAndContents() { // Setup var propertyObject = new TestOrderedProperties(); PropertyDescriptorCollection originalProperties = new DynamicPropertyBag(propertyObject).GetProperties(); // Call for (var i = 0; i < 100; i++) { PropertyDescriptorCollection currentProperties = new DynamicPropertyBag(propertyObject).GetProperties(); // Assert CollectionAssert.AreEqual(originalProperties, currentProperties); } }
public void GivenPropertyDescriptorFromDynamicPropertyBag_WhenSettingProperty_ThenWrappedObjectUpdated() { // Given var testProperties = new TestProperties { Name = "name" }; var dynamicPropertyBag = new DynamicPropertyBag(testProperties); const string newName = "newName"; // When dynamicPropertyBag.GetProperties()["Name"].SetValue(testProperties, newName); // Then Assert.AreEqual(newName, testProperties.Name); }
public void Constructor_ClassWithAttributes_PropertySpecsHaveAttributesSet() { // Setup var propertyObject = new TestProperties(); // Call var dynamicPropertyBag = new DynamicPropertyBag(propertyObject); // Assert PropertySpec namePropertySpec = dynamicPropertyBag.Properties.First(ps => ps.Name == "Name"); CollectionAssert.Contains(namePropertySpec.Attributes, new CategoryAttribute("General"), "Should have initialized Attributes of the property spec with declared Category(\"General\")."); PropertySpec descriptionPropertySpec = dynamicPropertyBag.Properties.First(ps => ps.Name == "Description"); CollectionAssert.Contains(descriptionPropertySpec.Attributes, ReadOnlyAttribute.Yes, "Should have initialized Attributes of the property spec with declared ReadOnlyAttribute."); }
public void GivenObjectPropertiesWithDynamicVisibleProperties_WhenPropertyHidden_ThenPropertyNotPresentInBag() { // Setup var propertyObject = new TestProperties { Visible = false }; var dynamicPropertyBag = new DynamicPropertyBag(propertyObject); PropertyDescriptorCollection propertyDescriptorCollection = dynamicPropertyBag.GetProperties(new Attribute[] { new BrowsableAttribute(true) }); // Call const string dynamicallyVisiblePropertyName = nameof(TestProperties.Name); PropertyDescriptor namePropertyDescriptor = propertyDescriptorCollection.Find(dynamicallyVisiblePropertyName, false); // Assert Assert.IsNull(namePropertyDescriptor, $"{dynamicallyVisiblePropertyName} should not be visible anymore"); }
public void GetProperties_BrowsableTrueFilter_ReturnOnlyPropertiesThatAreBrowsable() { // Setup var propertyObject = new TestProperties { Visible = false }; var dynamicPropertyBag = new DynamicPropertyBag(propertyObject); // Call PropertyDescriptorCollection properties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(propertyObject); // Assert Assert.Less(properties.Count, dynamicPropertyBag.Properties.Count()); Assert.IsNull(properties.Find("Name", false), "Name is dynamically not browsable, therefore should not be returned."); Assert.IsNotNull(properties.Find("Description", false)); Assert.IsNotNull(properties.Find("IsNameReadOnly", false)); Assert.IsNull(properties.Find("Visible", false), "Visible is statically not browsable, therefore should not be returned."); }
public void GetProperties_PropertyIsDecoratedWithExpandableObjectConverter_WrapPropertyValueInDynamicPropertyBag() { // Setup var subProperties = new TestProperties { Name = "test" }; var testProperties = new TestWithNestedPropertiesClassProperties { SubProperties = subProperties }; var dynamicPropertyBag = new DynamicPropertyBag(testProperties); // Call PropertyDescriptorCollection propertiesCollection = dynamicPropertyBag.GetProperties(); // Assert var bag = propertiesCollection[0].GetValue(dynamicPropertyBag.WrappedObject) as DynamicPropertyBag; Assert.NotNull(bag); Assert.AreSame(subProperties, bag.WrappedObject); }
public void GivenObjectPropertiesWithDynamicVisibleProperties_WhenPropertyShown_ThenPropertyShouldBePresentInBag() { // Given var propertyObject = new TestProperties { Visible = true }; var dynamicPropertyBag = new DynamicPropertyBag(propertyObject); PropertyDescriptorCollection propertyDescriptorCollection = dynamicPropertyBag.GetProperties(new Attribute[] { new BrowsableAttribute(true) }); // When const string dynamicallyVisiblePropertyName = nameof(TestProperties.Name); PropertyDescriptor namePropertyDescriptor = propertyDescriptorCollection.Find(dynamicallyVisiblePropertyName, false); // Then Assert.IsTrue(namePropertyDescriptor.IsBrowsable, $"{dynamicallyVisiblePropertyName} should be visible"); }