/// <summary> /// Creates a new <see cref="DesignVariableProperties{TDistribution}"/>. /// </summary> /// <param name="readOnlyProperties">Indicates which properties, if any, should be marked as read-only.</param> /// <param name="designVariable">The data of the <see cref="TDistribution"/> to create the properties for.</param> /// <param name="handler">The handler responsible for handling effects of a property change.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="designVariable"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when any number of properties in this class is editable and the /// <paramref name="handler"/> is <c>null</c>.</exception> protected DesignVariableProperties(DistributionReadOnlyProperties readOnlyProperties, DesignVariable <TDistribution> designVariable, IObservablePropertyChangeHandler handler) : base(readOnlyProperties, GetDistribution(designVariable), handler) { DesignVariable = designVariable; }
/// <summary> /// Creates a new instance of <see cref="NormalDistributionProperties"/>. /// </summary> /// <param name="readOnlyProperties">Indicates which properties, if any, should be /// marked as read-only.</param> /// <param name="distribution">The <see cref="NormalDistribution"/> to create the properties for.</param> /// <param name="handler">Optional handler that is used to handle property changes.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="distribution"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when any number of properties in this class is editable and the /// <paramref name="handler"/> is <c>null</c>.</exception> public NormalDistributionProperties( DistributionReadOnlyProperties readOnlyProperties, NormalDistribution distribution, IObservablePropertyChangeHandler handler) : base(readOnlyProperties, distribution, handler) { }
/// <summary> /// Creates a new <see cref="LogNormalDistributionDesignVariableProperties"/>. /// </summary> /// <param name="readOnlyProperties">Indicates which properties, if any, should be marked as read-only.</param> /// <param name="designVariable">The <see cref="DesignVariable{T}"/> to create the properties for.</param> /// <param name="handler">The handler responsible for handling effects of a property change.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="designVariable"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when any number of properties in this class is editable and the /// <paramref name="handler"/> is <c>null</c>.</exception> public LogNormalDistributionDesignVariableProperties(DistributionReadOnlyProperties readOnlyProperties, DesignVariable <LogNormalDistribution> designVariable, IObservablePropertyChangeHandler handler) : base(readOnlyProperties, designVariable, handler) { }
public void Constructor_NoDistributionSetWhileChangesPossible_ThrowArgumentException( DistributionReadOnlyProperties flags) { // Call TestDelegate call = () => new SimpleDistributionProperties(flags, null, null); // Assert string paramName = Assert.Throws <ArgumentNullException>(call).ParamName; Assert.AreEqual("distribution", paramName); }
public void Constructor_Always_PropertiesHaveExpectedAttributesValues(DistributionReadOnlyProperties readOnlyProperties, bool expectMeanReadOnly, bool expectStandardDeviationReadOnly) { // Setup var mocks = new MockRepository(); var distribution = mocks.Stub <IDistribution>(); var handler = mocks.Stub <IObservablePropertyChangeHandler>(); mocks.ReplayAll(); // Call var properties = new SimpleDistributionProperties(readOnlyProperties, distribution, handler); // Assert AssertPropertiesInState(properties, expectMeanReadOnly, expectStandardDeviationReadOnly); mocks.VerifyAll(); }
public void Constructor_NoHandlerSetWhileChangesPossible_ThrowArgumentException( DistributionReadOnlyProperties flags) { // Setup var mocks = new MockRepository(); var distribution = mocks.Stub <IDistribution>(); mocks.ReplayAll(); // Call TestDelegate call = () => new SimpleDistributionProperties(flags, distribution, null); // Assert const string message = "Change handler required if changes are possible."; var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(call, message); Assert.AreEqual("handler", exception.ParamName); mocks.VerifyAll(); }
/// <summary> /// Creates a new instance of <see cref="DistributionPropertiesBase{TDistribution}"/>. /// </summary> /// <param name="readOnlyProperties">Indicates which properties, if any, should be marked as read-only.</param> /// <param name="distribution">The <see cref="TDistribution"/> to create the properties for.</param> /// <param name="handler">The handler responsible for handling effects of a property change.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="distribution"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when any number of properties in this class is editable and the /// <paramref name="handler"/> is <c>null</c>.</exception> protected DistributionPropertiesBase(DistributionReadOnlyProperties readOnlyProperties, TDistribution distribution, IObservablePropertyChangeHandler handler) { if (distribution == null) { throw new ArgumentNullException(nameof(distribution)); } if (!readOnlyProperties.HasFlag(DistributionReadOnlyProperties.All) && handler == null) { throw new ArgumentException(@"Change handler required if changes are possible.", nameof(handler)); } Data = distribution; isMeanReadOnly = readOnlyProperties.HasFlag(DistributionReadOnlyProperties.Mean); isStandardDeviationReadOnly = readOnlyProperties.HasFlag(DistributionReadOnlyProperties.StandardDeviation); changeHandler = handler; }
public void StandardDeviation_ReadOnlyWithoutObserverable_ThrowsArgumentException(DistributionReadOnlyProperties readOnlyProperties) { // Setup var mocks = new MockRepository(); var distribution = mocks.Stub <IDistribution>(); var handler = mocks.Stub <IObservablePropertyChangeHandler>(); mocks.ReplayAll(); var properties = new SimpleDistributionProperties( readOnlyProperties, distribution, handler); // Call TestDelegate test = () => properties.StandardDeviation = new RoundedDouble(2, 20); // Assert const string expectedMessage = "StandardDeviation is set to be read-only."; string actualMessage = Assert.Throws <InvalidOperationException>(test).Message; Assert.AreEqual(expectedMessage, actualMessage); mocks.VerifyAll(); }
public void DynamicReadOnlyValidationMethod_VariousReadOnlySet_ExpectedValues(DistributionReadOnlyProperties readOnlyProperties, bool expectMeanReadOnly, bool expectStandardDeviationReadOnly) { // Setup var mocks = new MockRepository(); var distribution = mocks.Stub <IDistribution>(); var handler = mocks.Stub <IObservablePropertyChangeHandler>(); mocks.ReplayAll(); var properties = new SimpleDistributionProperties(readOnlyProperties, distribution, handler); // Call bool meanIsReadOnly = properties.DynamicReadOnlyValidationMethod("Mean"); bool standardDeviationIsReadOnly = properties.DynamicReadOnlyValidationMethod("StandardDeviation"); bool doesNotExist = properties.DynamicReadOnlyValidationMethod("DoesNotExist"); // Assert Assert.AreEqual(expectStandardDeviationReadOnly, standardDeviationIsReadOnly); Assert.AreEqual(expectMeanReadOnly, meanIsReadOnly); Assert.IsFalse(doesNotExist); mocks.VerifyAll(); }