public void VersionedStringBuilder_IsInitializedToSpecifiedString() { var builder = new VersionedStringBuilder("Hello, world!"); TheResultingValue(builder.Version).ShouldBe(0); TheResultingString(builder.ToString()).ShouldBe("Hello, world!"); }
public void VersionedStringSource_ExplicitlyConvertsToStringBuilder_WhenSourceIsStringBuilder() { var data = new VersionedStringBuilder("Hello, world!"); var source = new VersionedStringSource(data); TheResultingObject((VersionedStringBuilder)source) .ShouldSatisfyTheCondition(x => x.ToString() == "Hello, world!"); }
public void VersionedStringSource_CannotConvertToString_WhenSourceIsNotString() { var data = new VersionedStringBuilder("Hello, world!"); var source = new VersionedStringSource(data); Assert.That(() => TheResultingString((String)source).ShouldBe("Hello, world!"), Throws.TypeOf<InvalidCastException>()); }
public void VersionedStringSource_IsValid_WhenStringBuilderSourceIsSpecified() { var data = new VersionedStringBuilder("Hello, world!"); var source = new VersionedStringSource(data); TheResultingValue(source.IsValid).ShouldBe(true); TheResultingValue(source.IsSourcedFromString).ShouldBe(false); TheResultingValue(source.IsSourcedFromStringBuilder).ShouldBe(true); }
public void VersionedStringBuilder_VersionIsNotIncremented_WhenAppendStringBuilderIsCalled_AndValueIsNull() { var builder = new VersionedStringBuilder("Hello, world!"); builder.Append((StringBuilder)null); TheResultingValue(builder.Version).ShouldBe(0); TheResultingString(builder.ToString()).ShouldBe("Hello, world!"); }
public void VersionedStringBuilder_VersionIsIncremented_WhenClearIsCalled() { var builder = new VersionedStringBuilder("Hello, world!"); builder.Clear(); TheResultingValue(builder.Version).ShouldBe(1); TheResultingString(builder.ToString()).ShouldBe(String.Empty); }
public void VersionedStringBuilder_VersionIsIncremented_WhenAppendVersionedStringBuilderIsCalled() { var builder = new VersionedStringBuilder("Hello, world!"); var value = new VersionedStringBuilder(" Goodbye, world!"); builder.Append(value); TheResultingValue(builder.Version).ShouldBe(1); TheResultingString(builder.ToString()).ShouldBe("Hello, world! Goodbye, world!"); }
/// <summary> /// Appends the contents of the specified string builder at the end of the string builder. /// </summary> /// <param name="value">The value to append.</param> /// <returns>The current instance of <see cref="VersionedStringBuilder"/>.</returns> public VersionedStringBuilder Append(VersionedStringBuilder value) { if (value != null) { for (int i = 0; i < value.Length; i++) { stringBuilder.Append(value[i]); } version++; } return(this); }
/// <summary> /// Inserts the contents of the specified string builder at the specified index within the string builder. /// </summary> /// <param name="index">The index at which to insert the value.</param> /// <param name="value">The value to insert.</param> /// <returns>The current instance of <see cref="VersionedStringBuilder"/>.</returns> public VersionedStringBuilder Insert(Int32 index, VersionedStringBuilder value) { if (value != null) { for (int i = 0; i < value.Length; i++) { stringBuilder.Insert(index + i, value[i]); } version++; } else { if (index < 0 || index > stringBuilder.Length) { throw new ArgumentOutOfRangeException("index"); } } return(this); }
/// <summary> /// Initializes a new instance of the <see cref="VersionedStringSource"/> structure that wraps the specified <see cref="VersionedStringBuilder"/> instance. /// </summary> /// <param name="sourceStringBuilder">The <see cref="VersionedStringBuilder"/> instance which is wrapped by this buffer.</param> public VersionedStringSource(VersionedStringBuilder sourceStringBuilder) { this.sourceString = null; this.sourceStringBuilder = sourceStringBuilder; this.version = (sourceStringBuilder == null) ? 0 : sourceStringBuilder.Version; }
/// <summary> /// Inserts the contents of the specified string builder at the specified index within the string builder. /// </summary> /// <param name="index">The index at which to insert the value.</param> /// <param name="value">The value to insert.</param> /// <returns>The current instance of <see cref="VersionedStringBuilder"/>.</returns> public VersionedStringBuilder Insert(Int32 index, VersionedStringBuilder value) { if (value != null) { for (int i = 0; i < value.Length; i++) { stringBuilder.Insert(index + i, value[i]); } version++; } else { if (index < 0 || index > stringBuilder.Length) throw new ArgumentOutOfRangeException("index"); } return this; }
/// <summary> /// Appends the contents of the specified string builder at the end of the string builder. /// </summary> /// <param name="value">The value to append.</param> /// <returns>The current instance of <see cref="VersionedStringBuilder"/>.</returns> public VersionedStringBuilder Append(VersionedStringBuilder value) { if (value != null) { for (int i = 0; i < value.Length; i++) { stringBuilder.Append(value[i]); } version++; } return this; }
public void VersionedStringSource_ProducesCorrectString_WhenToStringIsCalled_AndSourceIsStringBuilder() { var data = new VersionedStringBuilder("Hello, world!"); var source = new VersionedStringSource(data); TheResultingString(source.ToString()).ShouldBe("Hello, world!"); }
public void VersionedStringBuilder_VersionIsIncremented_WhenInsertCharIsCalled() { var builder = new VersionedStringBuilder("Hello, world!"); var value = '!'; builder.Insert(12, value); TheResultingValue(builder.Version).ShouldBe(1); TheResultingString(builder.ToString()).ShouldBe("Hello, world!!"); }
public void VersionedStringBuilder_VersionIsNotIncremented_WhenInsertVersionedStringSourceIsCalled_WithInvalidSource() { var builder = new VersionedStringBuilder("Hello, world!"); var value = new VersionedStringSource(); builder.Insert(5, value); TheResultingValue(builder.Version).ShouldBe(0); TheResultingString(builder.ToString()).ShouldBe("Hello, world!"); }
public void VersionedStringBuilder_VersionIsIncremented_WhenInsertVersionedStringSourceIsCalled_WithValidStringBuilderSource() { var builder = new VersionedStringBuilder("Hello, world!"); var source = new VersionedStringBuilder(" and goodbye"); var value = new VersionedStringSource(source); builder.Insert(5, value); TheResultingValue(builder.Version).ShouldBe(1); TheResultingString(builder.ToString()).ShouldBe("Hello and goodbye, world!"); }
/// <summary> /// Performs a pass-through conversion for an instance of the <see cref="VersionedStringBuilder"/> class. /// </summary> /// <param name="value">The string to convert.</param> /// <param name="example">An example value which will cause the compiler to perform type inference.</param> /// <returns>The value that was created.</returns> protected VersionedStringBuilder __UPF_ConvertFromString(VersionedStringBuilder value, VersionedStringBuilder example) { return(value); }