/// <summary> /// Assembly exception constructor for a single error message /// </summary> /// <param name="entityId">The id of the entity on which the error occurred</param> /// <param name="error">The code of the error which occurred</param> public AssemblyException(string entityId, EAssemblyErrors error) { Errors = new List <AssemblyErrorMessage> { new AssemblyErrorMessage(entityId, error) }; }
private static void CheckException(AssemblyException e, EAssemblyErrors expectedError) { Assert.NotNull(e.Errors); var message = e.Errors.FirstOrDefault(); Assert.NotNull(message); Assert.AreEqual(expectedError, message.ErrorCode); Assert.Pass(); }
public void ConstructorPassesArguments() { string id = "TestID"; EAssemblyErrors error = EAssemblyErrors.FailureProbabilityOutOfRange; var message = new AssemblyErrorMessage(id, error); Assert.AreEqual(id, message.EntityId); Assert.AreEqual(error, message.ErrorCode); }
/// <summary> /// Creates an <see cref="AssemblyErrorMessage"/>. /// </summary> /// <param name="entityId">The id of the entity on which the error occurred.</param> /// <param name="errorCode">The code of the error.</param> /// <returns>The created <see cref="AssemblyErrorMessage"/>.</returns> public static AssemblyErrorMessage Create(string entityId, EAssemblyErrors errorCode) { const BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance; return((AssemblyErrorMessage)Activator.CreateInstance( typeof(AssemblyErrorMessage), flags, null, new object[] { entityId, errorCode }, null)); }
/// <summary> /// Throws an exception when either <paramref name="throwExceptionOnCalculate"/> /// or <paramref name="throwAssemblyExceptionOnCalculate"/> is <c>true</c>. /// </summary> /// <param name="throwExceptionOnCalculate">Indicator whether an /// <see cref="Exception"/> should be thrown.</param> /// <param name="throwAssemblyExceptionOnCalculate">Indicator whether an /// <see cref="AssemblyException"/> should be thrown.</param> /// <param name="assemblyError">The error to use in the <see cref="AssemblyException"/>.</param> /// <exception cref="Exception">Thrown when <paramref name="throwExceptionOnCalculate"/> is <c>true</c>.</exception> /// <exception cref="AssemblyException">Thrown when <paramref name="throwAssemblyExceptionOnCalculate"/> /// is <c>true</c>.</exception> public static void ThrowException(bool throwExceptionOnCalculate, bool throwAssemblyExceptionOnCalculate, EAssemblyErrors assemblyError) { if (throwExceptionOnCalculate) { throw new Exception("Message", new Exception()); } if (throwAssemblyExceptionOnCalculate) { const BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance; throw (AssemblyException)Activator.CreateInstance( typeof(AssemblyException), flags, null, new object[] { "entity", assemblyError }, null); } }
public void FindGreatestCommonDenominatorSectionsWbi3A1ThrowsOnInvalidAssessmentLength(double assessmentLength, EAssemblyErrors expectedError) { var list1 = new FailureMechanismSectionList(new[] { new FailureMechanismSection(0.0, 10.0), new FailureMechanismSection(10.0, 20.0), new FailureMechanismSection(20.0, 30.0) }); try { var commonSections = assembler.FindGreatestCommonDenominatorSectionsWbi3A1(new[] { list1 }, assessmentLength); } catch (AssemblyException exception) { Assert.IsNotNull(exception.Errors); Assert.AreEqual(1, exception.Errors.Count()); Assert.AreEqual(expectedError, exception.Errors.First().ErrorCode); Assert.Pass(); } Assert.Fail("Expected exception did not occur"); }
/// <summary> /// Error message. /// </summary> /// <param name="entityId">The id of the entity on which the error occurred</param> /// <param name="errorCode">The code of the error which occurred</param> public AssemblyErrorMessage(string entityId, EAssemblyErrors errorCode) { EntityId = entityId; ErrorCode = errorCode; }
public void CreateErrorMessage_SingleAssemblyError_ReturnsExpectedErrorMessage(EAssemblyErrors assemblyError, string expectedErrorMessage) { // Call string errorMessage = AssemblyErrorMessageCreator.CreateErrorMessage(new[] { AssemblyErrorMessageTestHelper.Create(string.Empty, assemblyError) }); // Assert Assert.AreEqual(expectedErrorMessage, errorMessage); }
/// <summary> /// Gets the localized error message that belongs to the given <see cref="EAssemblyErrors"/>. /// </summary> /// <param name="assemblyError">The <see cref="EAssemblyErrors"/> to localize.</param> /// <returns>A localized string.</returns> /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="assemblyError"/> /// is an invalid value of <see cref="EAssemblyErrors"/>.</exception> /// <exception cref="NotSupportedException">Thrown when <paramref name="assemblyError"/> is a valid value, /// but unsupported.</exception> private static string GetErrorMessage(EAssemblyErrors assemblyError) { if (!Enum.IsDefined(typeof(EAssemblyErrors), assemblyError)) { throw new InvalidEnumArgumentException(nameof(assemblyError), (int)assemblyError, typeof(EAssemblyErrors)); } switch (assemblyError) { case EAssemblyErrors.LengthEffectFactorOutOfRange: return(Resources.AssemblyErrorMessageCreator_LengthEffectFactorOutOfRange); case EAssemblyErrors.SectionLengthOutOfRange: return(Resources.AssemblyErrorMessageCreator_SectionLengthOutOfRange); case EAssemblyErrors.SignalFloodingProbabilityAboveMaximumAllowableFloodingProbability: return(Resources.AssemblyErrorMessageCreator_SignalFloodingProbabilityAboveMaximumAllowableFloodingProbability); case EAssemblyErrors.LowerLimitIsAboveUpperLimit: return(Resources.AssemblyErrorMessageCreator_LowerLimitIsAboveUpperLimit); case EAssemblyErrors.ValueMayNotBeNull: case EAssemblyErrors.NonMatchingProbabilityValues: case EAssemblyErrors.UndefinedProbability: case EAssemblyErrors.ProbabilitiesNotBothDefinedOrUndefined: return(Resources.AssemblyErrorMessageCreator_InvalidInput); case EAssemblyErrors.FailureMechanismSectionLengthInvalid: return(Resources.AssemblyErrorMessageCreator_FailureMechanismSectionLengthInvalid); case EAssemblyErrors.FailureMechanismSectionSectionStartEndInvalid: return(Resources.AssemblyErrorMessageCreator_FailureMechanismSectionSectionStartEndInvalid); case EAssemblyErrors.FailureProbabilityOutOfRange: return(Resources.AssemblyErrorMessageCreator_FailureProbabilityOutOfRange); case EAssemblyErrors.InputNotTheSameType: return(Resources.AssemblyErrorMessageCreator_InputNotTheSameType); case EAssemblyErrors.CommonFailureMechanismSectionsInvalid: return(Resources.AssemblyErrorMessageCreator_CommonFailureMechanismSectionsInvalid); case EAssemblyErrors.CommonFailureMechanismSectionsNotConsecutive: return(Resources.AssemblyErrorMessageCreator_CommonFailureMechanismSectionsNotConsecutive); case EAssemblyErrors.RequestedPointOutOfRange: return(Resources.AssemblyErrorMessageCreator_RequestedPointOutOfRange); case EAssemblyErrors.SectionsWithoutCategory: return(Resources.AssemblyErrorMessageCreator_SectionsWithoutCategory); case EAssemblyErrors.InvalidCategoryLimits: return(Resources.AssemblyErrorMessageCreator_GetErrorMessage_InvalidCategoryLimits); case EAssemblyErrors.EmptyResultsList: return(Resources.AssemblyErrorMessageCreator_EmptyResultsList); case EAssemblyErrors.ProfileProbabilityGreaterThanSectionProbability: return(Resources.AssemblyErrorMessageCreator_ProfileProbabilityGreaterThanSectionProbability); case EAssemblyErrors.EncounteredOneOrMoreSectionsWithoutResult: return(Resources.AssemblyErrorMessageCreator_All_sections_must_have_a_result); case EAssemblyErrors.ErrorConstructingErrorMessage: case EAssemblyErrors.CommonFailureMechanismSectionsDoNotHaveEqualSections: case EAssemblyErrors.InvalidCategoryValue: case EAssemblyErrors.InvalidEnumValue: case EAssemblyErrors.UnequalCommonFailureMechanismSectionLists: case EAssemblyErrors.CommonSectionsWithoutCategoryValues: case EAssemblyErrors.InvalidArgumentType: return(Resources.AssemblyErrorMessageCreator_ErrorConstructingErrorMessage); default: throw new NotSupportedException(); } }