/// <summary> /// Initializes a new instance of the <see cref="FluentMessage"/> class. /// </summary> /// <param name="message"> /// The main message. /// </param> /// <remarks> /// You can use {x} as place holders for standard wordings: /// - {0}. /// </remarks> private FluentMessage(string message) { this.message = message; this.EntityDescription = null; this.checkedNamer = new EntityNamer(); this.expectedNamer = new EntityNamer(); this.checkedLabel = GenericLabelBlock.BuildCheckedBlock(this.checkedNamer); this.expectedLabel = GenericLabelBlock.BuildExpectedBlock(this.expectedNamer); }
/// <summary> /// Initializes a new instance of the <see cref="MessageBlock"/> class. /// </summary> /// <param name="message"> /// The message. /// </param> /// <param name="test"> /// The tested object. /// </param> /// <param name="block"> /// The block attribute. /// </param> /// <param name="index">The index for enumerable types</param> internal MessageBlock(FluentMessage message, object test, GenericLabelBlock block, int index = 0) : this(message, test.GetTypeWithoutThrowingException(), block) { if (!(test is string) && (test is IEnumerable)) { this.value = new EnumerationBlock((IEnumerable) test, index); } else { this.value = new ValueBlock(test); } }
public void BlockTest() { var message = FluentMessage.BuildMessage("test"); const int x = 4; var block = new MessageBlock(message, x, GenericLabelBlock.BuildCheckedBlock(new EntityNamer())); Assert.AreEqual("The checked value:" + NewLine + "\t[4]", block.GetMessage()); block.WithHashCode().WithType(); Assert.AreEqual("The checked value:" + NewLine + "\t[4] of type: [int] with HashCode: [4]", block.GetMessage()); }
/// <summary> /// Initializes a new instance of the <see cref="MessageBlock"/> class. /// </summary> /// <param name="message"> /// The message. /// </param> /// <param name="type"> /// The tested type. /// </param> /// <param name="label"> /// The block label. /// </param> internal MessageBlock(FluentMessage message, Type type, GenericLabelBlock label) { if (message == null) { throw new ArgumentNullException(nameof(message)); } this.value = new InstanceBlock(type); this.message = message; this.block = label; }
public void ShouldCreateExpectedLabel() { var label = GenericLabelBlock.BuildExpectedBlock(new EntityNamer()); Assert.AreEqual("The expected value:", label.CustomMessage(null)); }
public void ShouldCreateActualLabel() { var label = GenericLabelBlock.BuildActualBlock(null); Assert.AreEqual("The actual value:", label.CustomMessage(null)); }
/// <summary> /// Adds a message block to describe the given value (usually used as an /// alternative to the Expected block). /// </summary> /// <param name="givenValue">The given value.</param> /// <returns>The created MessageBlock.</returns> public MessageBlock WithGivenValue(object givenValue) { this.expectedLabel = GenericLabelBlock.BuildGivenBlock(this.checkedNamer); this.expectedBlock = new MessageBlock(this, givenValue, this.expectedLabel); return this.expectedBlock; }
/// <summary> /// Adds a message block to describe the expected values. /// </summary> /// <param name="expectedValues">The expected values.</param> /// <returns>The created MessageBlock.</returns> public MessageBlock ExpectedValues(object expectedValues) { var customNamer = new EntityNamer { EntityName = "value(s)" }; this.expectedLabel = GenericLabelBlock.BuildExpectedBlock(customNamer); this.expectedBlock = new MessageBlock(this, expectedValues, this.expectedLabel); this.referenceType = this.referenceType ?? expectedValues.GetTypeWithoutThrowingException(); return this.expectedBlock; }