PageRenderTime 59ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/test/NRopes.Tests/RopeTestsBase.cs

https://github.com/mingdayfly/NRopes
C# | 47 lines | 40 code | 7 blank | 0 comment | 1 complexity | 5f2a37f5e8084bd3e92e4066e1028cce MD5 | raw file
  1. namespace NRopes.Tests {
  2. using System;
  3. using System.Collections.Generic;
  4. using FluentAssertions;
  5. using Xunit;
  6. public abstract class RopeTestsBase {
  7. protected abstract IEnumerable<Rope> TargetRopes { get; }
  8. [Fact]
  9. public void SubstringShouldThrowExceptionsForInvalidParameters() {
  10. foreach (var rope in TargetRopes) {
  11. rope.Invoking(r => r.Substring(-1))
  12. .ShouldThrow<ArgumentOutOfRangeException>().And
  13. .ParamName.Should().Be("startIndex");
  14. rope.Invoking(r => r.Substring(r.Length + 1))
  15. .ShouldThrow<ArgumentOutOfRangeException>().And
  16. .ParamName.Should().Be("startIndex");
  17. rope.Invoking(r => r.Substring(0, -1))
  18. .ShouldThrow<ArgumentOutOfRangeException>().And
  19. .ParamName.Should().Be("length");
  20. rope.Invoking(r => r.Substring(0, r.Length + 1))
  21. .ShouldThrow<ArgumentOutOfRangeException>().And
  22. .ParamName.Should().Be("length");
  23. }
  24. }
  25. [Fact]
  26. public void SubstringShouldReturnSelfForZeroStartIndexAndFullLength() {
  27. foreach (var rope in TargetRopes) {
  28. if (rope.Length > 0) {
  29. rope.Substring(0, rope.Length).Should().BeSameAs(rope);
  30. }
  31. }
  32. }
  33. [Fact]
  34. public void SubstringShouldReturnEmptyForZeroLength() {
  35. foreach (var rope in TargetRopes) {
  36. rope.Substring(rope.Length, 0).Should().BeSameAs(Rope.Empty);
  37. }
  38. }
  39. }
  40. }