/// <summary>
 /// Creates a <see cref="TreeNodeInfo"/> object for a calculation context of the type <typeparamref name="TCalculationContext"/>.
 /// </summary>
 /// <typeparam name="TCalculationContext">The type of calculation context to create a <see cref="TreeNodeInfo"/> object for.</typeparam>
 /// <param name="childNodeObjects">The function for obtaining the child node objects.</param>
 /// <param name="contextMenuStrip">The function for obtaining the context menu strip.</param>
 /// <param name="onNodeRemoved">The action to perform on removing a node.</param>
 /// <param name="calculationType">The type of the calculation.</param>
 /// <returns>A <see cref="TreeNodeInfo"/> object.</returns>
 public static TreeNodeInfo <TCalculationContext> CreateCalculationContextTreeNodeInfo <TCalculationContext>(
     Func <TCalculationContext, object[]> childNodeObjects,
     Func <TCalculationContext, object, TreeViewControl, ContextMenuStrip> contextMenuStrip,
     Action <TCalculationContext, object> onNodeRemoved,
     CalculationType calculationType)
     where TCalculationContext : ICalculationContext <ICalculation, ICalculatableFailureMechanism>
 {
     return(new TreeNodeInfo <TCalculationContext>
     {
         Text = context => context.WrappedData.Name,
         Image = context => CalculationTypeHelper.GetCalculationTypeImage(calculationType),
         EnsureVisibleOnCreate = (context, parent) => true,
         ChildNodeObjects = childNodeObjects,
         ContextMenuStrip = contextMenuStrip,
         CanRename = (context, parent) => true,
         OnNodeRenamed = (context, newName) =>
         {
             context.WrappedData.Name = newName;
             context.WrappedData.NotifyObservers();
         },
         CanRemove = (context, parentData) => CalculationContextCanRemove(context, parentData),
         OnNodeRemoved = onNodeRemoved,
         CanDrag = (context, parentData) => true
     });
 }
        public void GetCalculationTypeImage_ValidCalculationType_ReturnsImage(CalculationType calculationType, Bitmap expectedImage)
        {
            // Call
            Bitmap image = CalculationTypeHelper.GetCalculationTypeImage(calculationType);

            // Assert
            TestHelper.AssertImagesAreEqual(expectedImage, image);
        }
Esempio n. 3
0
 /// <summary>
 /// Creates a <see cref="StrictContextMenuItem"/> which is bound to the action of adding new calculations.
 /// </summary>
 /// <typeparam name="TCalculationContext">The type of the calculation group context.</typeparam>
 /// <param name="calculationGroupContext">The calculation group context belonging to the calculation group.</param>
 /// <param name="addCalculationAction">The action for adding a calculation to the calculation group.</param>
 /// <param name="calculationType">The type of the calculation to add.</param>
 /// <returns>The created <see cref="StrictContextMenuItem"/>.</returns>
 public static StrictContextMenuItem CreateAddCalculationItem <TCalculationContext>(
     TCalculationContext calculationGroupContext,
     Action <TCalculationContext> addCalculationAction,
     CalculationType calculationType)
     where TCalculationContext : ICalculationContext <CalculationGroup, ICalculatableFailureMechanism>
 {
     return(new StrictContextMenuItem(
                Resources.CalculationGroup_Add_Calculation,
                Resources.CalculationGroup_Add_Calculation_Tooltip,
                CalculationTypeHelper.GetCalculationTypeImage(calculationType),
                (o, args) => addCalculationAction(calculationGroupContext)));
 }
        public void GetCalculationTypeImage_InvalidCalculationType_ThrowsInvalidEnumArgumentException()
        {
            // Setup
            const CalculationType calculationType = (CalculationType)99;

            // Call
            void Call() => CalculationTypeHelper.GetCalculationTypeImage(calculationType);

            // Assert
            var expectedMessage = $"The value of argument 'calculationType' ({calculationType}) is invalid for Enum type '{nameof(CalculationType)}'.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <InvalidEnumArgumentException>(Call, expectedMessage);
        }