1
0

Added customized AppendLine() for StringBuilder

This commit is contained in:
2022-05-06 19:29:55 +02:00
parent e38864b32b
commit d9ba209402
6 changed files with 36 additions and 2 deletions

View File

@@ -95,6 +95,7 @@ namespace AMWD.Common.AspNetCore.BasicAuthentication
if (!string.IsNullOrWhiteSpace(Realm)) if (!string.IsNullOrWhiteSpace(Realm))
context.HttpContext.Response.Headers["WWW-Authenticate"] += $" realm=\"{Realm.Replace("\"", "")}\""; context.HttpContext.Response.Headers["WWW-Authenticate"] += $" realm=\"{Realm.Replace("\"", "")}\"";
context.HttpContext.Response.StatusCode = 401;
context.Result = new UnauthorizedResult(); context.Result = new UnauthorizedResult();
} }
} }

View File

@@ -7,6 +7,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace AMWD.Common.Tests.Extensions namespace AMWD.Common.Tests.Extensions
{ {
[TestClass] [TestClass]
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public class StreamExtensionsTests public class StreamExtensionsTests
{ {
[TestMethod] [TestMethod]

View File

@@ -333,5 +333,21 @@ namespace AMWD.Common.Tests.Extensions
Assert.IsNull(hexDecodeNull); Assert.IsNull(hexDecodeNull);
Assert.AreEqual("", hexDecodeEmpty); Assert.AreEqual("", hexDecodeEmpty);
} }
[TestMethod]
public void ShouldAddCustomLineTermination()
{
// arrange
string value = "abc";
var sb = new StringBuilder();
// act
sb.AppendLine(value, "\r");
sb.AppendLine(value, "\r");
// assert
Assert.AreEqual($"{value}\r{value}\r", sb.ToString());
Assert.IsFalse(sb.ToString().Contains('\n'));
}
} }
} }

View File

@@ -203,5 +203,16 @@ namespace System
return false; return false;
} }
} }
/// <summary>
/// Appends a copy of the specified string followed by the specified line terminator
/// to the end of the current <see cref="StringBuilder"/> object.
/// </summary>
/// <param name="sb">The <see cref="StringBuilder"/> object.</param>
/// <param name="value">The string to append.</param>
/// <param name="newLine">The line terminator.</param>
/// <returns></returns>
public static StringBuilder AppendLine(this StringBuilder sb, string value, string newLine)
=> sb.Append(value).Append(newLine);
} }
} }

View File

@@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
_nothing changed yet_ _nothing changed yet_
## [v1.4.2](https://git.am-wd.de/AM.WD/common/compare/v1.4.1...v1.4.2) - 2022-05-06
### Added
- New extension for `StringBuilder` `AppendLine(value: string, newLine: string)` to add a line with a explicit defined new line character.
## [v1.4.1](https://git.am-wd.de/AM.WD/common/compare/v1.4.0...v1.4.1) - 2022-03-23 ## [v1.4.1](https://git.am-wd.de/AM.WD/common/compare/v1.4.0...v1.4.1) - 2022-03-23
### Added ### Added
- `IntegrityHashTagHelper` can be used with `asp-integrity="true|false"` and `asp-integrity-strength="256|384|512"` - `IntegrityHashTagHelper` can be used with `asp-integrity="true|false"` and `asp-integrity-strength="256|384|512"`

View File

@@ -1,6 +1,6 @@
The MIT License The MIT License
Copyright (c) 2020-2021 Andreas Müller Copyright (c) 2020-2022 Andreas Müller
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal