PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/Framework/src/Ncqrs.Tests/Eventing/Storage/NoDB/SnapshotStoreTests/when_saving_a_new_snapshot.cs

http://github.com/ncqrs/ncqrs
C# | 55 lines | 47 code | 7 blank | 1 comment | 0 complexity | 34795910e6011bb556ac045b080d140e MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, Apache-2.0
  1. using System;
  2. using System.IO;
  3. using FluentAssertions;
  4. using Ncqrs.Eventing.Sourcing.Snapshotting;
  5. using Ncqrs.Eventing.Storage.NoDB.Tests.Fakes;
  6. using Newtonsoft.Json;
  7. using Xunit;
  8. namespace Ncqrs.Eventing.Storage.NoDB.Tests.SnapshotStoreTests
  9. {
  10. //[Ignore("")]
  11. public class when_saving_a_new_snapshot : IClassFixture<when_saving_a_new_snapshotFixture>
  12. {
  13. private when_saving_a_new_snapshotFixture _fixture;
  14. public when_saving_a_new_snapshot(when_saving_a_new_snapshotFixture fixture)
  15. {
  16. _fixture = fixture;
  17. }
  18. [Fact]
  19. public void it_should_create_the_snapshot_file()
  20. {
  21. Assert.True(File.Exists(Path.Combine(_fixture.FolderName, _fixture.FileName)));
  22. }
  23. [Fact]
  24. public void it_should_write_the_snapshot_to_the_snapshot_file()
  25. {
  26. using (var reader = new StreamReader(File.Open(Path.Combine(_fixture.FolderName, _fixture.FileName), FileMode.Open)))
  27. {
  28. reader.ReadLine(); //Throw out type line
  29. var jsonSerializer = JsonSerializer.Create(null);
  30. var snapshot = jsonSerializer.Deserialize<Snapshot>(new JsonTextReader(reader));
  31. snapshot.EventSourceId.Should().Be(_fixture.Snapshot.EventSourceId);
  32. snapshot.Version.Should().Be(_fixture.Snapshot.Version);
  33. }
  34. }
  35. }
  36. public class when_saving_a_new_snapshotFixture : NoDBSnapshotStoreTestFixture
  37. {
  38. public string FolderName;
  39. public string FileName;
  40. public when_saving_a_new_snapshotFixture(): base()
  41. {
  42. Snapshot = new Snapshot(Guid.NewGuid(), 1, new TestSnapshot { Name = "TestName" });
  43. FolderName = Snapshot.EventSourceId.ToString().Substring(0, 2);
  44. FileName = Snapshot.EventSourceId.ToString().Substring(2) + ".ss";
  45. SnapshotStore.SaveSnapshot(Snapshot);
  46. }
  47. }
  48. }