public void Constructor_InvalidType_ThrowsInvalidEnumArgumentException() { // Setup const MacroStabilityInwardsKernelMessageType type = (MacroStabilityInwardsKernelMessageType)99; // Call void Call() => new MacroStabilityInwardsKernelMessage(type, "test"); // Assert string expectedMessage = $"The value of argument 'type' ({type}) is invalid for Enum type '{nameof(MacroStabilityInwardsKernelMessageType)}'."; var exception = TestHelper.AssertThrowsArgumentExceptionAndTestMessage <InvalidEnumArgumentException>(Call, expectedMessage); Assert.AreEqual("type", exception.ParamName); }
/// <summary> /// Creates a new instance of <see cref="MacroStabilityInwardsKernelMessage"/>. /// </summary> /// <param name="type">The type of the message.</param> /// <param name="message">The text of the message.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="message"/> /// is <c>null</c>.</exception> /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="type"/> /// contains an invalid value for <see cref="MacroStabilityInwardsKernelMessageType"/>.</exception> public MacroStabilityInwardsKernelMessage(MacroStabilityInwardsKernelMessageType type, string message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } if (!Enum.IsDefined(typeof(MacroStabilityInwardsKernelMessageType), type)) { throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(MacroStabilityInwardsKernelMessageType)); } Type = type; Message = message; }
private static MacroStabilityInwardsKernelMessage CreateMessage(MacroStabilityInwardsKernelMessageType type, string message) { return(new MacroStabilityInwardsKernelMessage(type, message ?? Resources.MacroStabilityInwardsKernelMessagesCreator_Create_Unknown)); }