PageRenderTime 22ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/Extensions/src/Ncqrs.EventBus.Tests/CursorPositionCalculatorSpecification.cs

http://github.com/ncqrs/ncqrs
C# | 63 lines | 52 code | 11 blank | 0 comment | 0 complexity | e2bd8946f58953da57ec036d3129903d MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, Apache-2.0
  1. using System;
  2. using NUnit.Framework;
  3. using FluentAssertions;
  4. namespace Ncqrs.EventBus.Tests
  5. {
  6. [TestFixture]
  7. public class CursorPositionCalculatorSpecification
  8. {
  9. [Test]
  10. public void When_event_does_not_lengthen_the_sequence()
  11. {
  12. var sut = new CursorPositionCalculator(0);
  13. sut.Append(CreateProcessingEvent(2));
  14. sut.Count.Should().Be(1);
  15. sut.SequenceLength.Should().Be(0);
  16. }
  17. [Test]
  18. public void When_event_lengthens_the_sequence()
  19. {
  20. var sut = new CursorPositionCalculator(0);
  21. sut.Append(CreateProcessingEvent(1));
  22. sut.Count.Should().Be(1);
  23. sut.SequenceLength.Should().Be(1);
  24. }
  25. [Test]
  26. public void When_event_fills_gap_in_sequence_sequence_length_is_incremented_by_gap_size()
  27. {
  28. var sut = new CursorPositionCalculator(0);
  29. sut.Append(CreateProcessingEvent(2));
  30. sut.Append(CreateProcessingEvent(3));
  31. sut.Append(CreateProcessingEvent(5));
  32. sut.Append(CreateProcessingEvent(1));
  33. sut.Count.Should().Be(4);
  34. sut.SequenceLength.Should().Be(3);
  35. }
  36. [Test]
  37. public void When_clearing_sequence()
  38. {
  39. var sut = new CursorPositionCalculator(0);
  40. sut.Append(CreateProcessingEvent(1));
  41. sut.Append(CreateProcessingEvent(2));
  42. sut.Append(CreateProcessingEvent(4));
  43. sut.ClearSequence();
  44. sut.Count.Should().Be(1);
  45. sut.SequenceLength.Should().Be(0);
  46. }
  47. private static IProcessingElement CreateProcessingEvent(int sequence)
  48. {
  49. return new FakeProcessingElement {SequenceNumber = sequence};
  50. }
  51. }
  52. }