public async Task ドキュメント作成のイベントが登録される() { var document = DocumentUtils.Create("path1/content1.txt", "testdata"); var ev = document.DomainEvents.First(); await sut.Handle(new DomainEventNotification <DocumentCreatedEvent>(ev as DocumentCreatedEvent)); Assert.AreEqual(1, await ctx.DocumentHistories.Where(f => f.Path == "path1/content1.txt" && f.Discriminator == DocumentHistoryDiscriminator.DocumentCreated).CountAsync()); }
public async Task ドメインイベントから読み取りモデルのファイルを追加する() { var document = DocumentUtils.Create("path1/content1.txt", "Hello"); var ev = document.DomainEvents.First(); await sut.Handle(new DomainEventNotification <DocumentCreatedEvent>(ev as DocumentCreatedEvent)); Assert.IsTrue(await ctx.Blobs.AnyAsync(f => f.Path == "path1/content1.txt")); Assert.IsTrue(await ctx.BlobContainers.AnyAsync(f => f.Path == "path1")); }
public async Task ルート直下のサブディレクトリをディレクトリとして認識すること() { var ctx = new MockDocmsContext("DocumentsRepositoryTests"); var sut = new DocumentRepository(ctx); await sut.AddAsync(DocumentUtils.Create("dir1/test.txt", "Hello, world")); await sut.UnitOfWork.SaveEntitiesAsync(); Assert.IsTrue(await sut.IsContainerPath("dir1")); }
public async Task コマンドを発行してドキュメントが削除されること() { await repository.AddAsync(DocumentUtils.Create("test1/document1.txt", "Hello, World")); await sut.Handle(new DeleteDocumentCommand() { Path = new FilePath("test1/document1.txt"), }); Assert.IsNull(await repository.GetAsync("test1/document1.txt")); }
public async Task DocumentがPathで取得できること() { var ctx = new MockDocmsContext("DocumentsRepositoryTests"); var sut = new DocumentRepository(ctx); await sut.AddAsync(DocumentUtils.Create("dir1/test.txt", "Hello, world")); await sut.UnitOfWork.SaveEntitiesAsync(); var document = await sut.GetAsync("dir1/test.txt"); Assert.AreEqual("dir1/test.txt", document.Path); }
public async Task すでに存在するディレクトリのパスに対して読み取りモデルのファイルを追加する() { var document1 = DocumentUtils.Create("path1/subpath1/content1.txt", "path1/subpath1/content1.txt"); var ev1 = document1.DomainEvents.First(); await sut.Handle(new DomainEventNotification <DocumentCreatedEvent>(ev1 as DocumentCreatedEvent)); var document2 = DocumentUtils.Create("path1/subpath1/content2.txt", "path1/subpath1/content2.txt"); var ev2 = document2.DomainEvents.First(); await sut.Handle(new DomainEventNotification <DocumentCreatedEvent>(ev2 as DocumentCreatedEvent)); Assert.IsTrue(await ctx.Blobs.AnyAsync(f => f.Path == "path1/subpath1/content2.txt")); }
public async Task コマンドを発行してファイルが移動すること() { await repository.AddAsync(DocumentUtils.Create("test1/document1.txt", "Hello, world")); await sut.Handle(new MoveDocumentCommand() { OriginalPath = new FilePath("test1/document1.txt"), DestinationPath = new FilePath("test2/document2.txt"), }); Assert.AreEqual("test2/document2.txt", repository.Entities.First().Path); }
public async Task 親Containerに1件のみファイルが存在するパスを削除してDocumentとContainerが削除される() { var document1 = DocumentUtils.Create("path1/subpath1/content1.txt", "path1/subpath1/content1.txt"); var ev1 = document1.DomainEvents.First(); await sut.Handle(new DomainEventNotification <DocumentCreatedEvent>(ev1 as DocumentCreatedEvent)); document1.ClearDomainEvents(); document1.Delete(); var ev2 = document1.DomainEvents.First(); await sut.Handle(new DomainEventNotification <DocumentDeletedEvent>(ev2 as DocumentDeletedEvent)); Assert.IsFalse(await ctx.Blobs.AnyAsync(f => f.Path == "path1/subpath1/document1.txt")); Assert.IsFalse(await ctx.BlobContainers.AnyAsync(f => f.Path == "path1/subpath1")); }
public async Task ドキュメント更新のイベントが登録される() { var document1 = DocumentUtils.Create("path1/subpath1/content1.txt", "Hello, World"); var ev1 = document1.DomainEvents.First(); await sut.Handle(new DomainEventNotification <DocumentCreatedEvent>(ev1 as DocumentCreatedEvent)); document1.ClearDomainEvents(); document1.Update("application/json", InMemoryData.Create("storagekey2", Encoding.UTF8.GetBytes("Hello, New World"))); var ev2 = document1.DomainEvents.First(); await sut.Handle(new DomainEventNotification <DocumentUpdatedEvent>(ev2 as DocumentUpdatedEvent)); Assert.AreEqual(1, await ctx.DocumentHistories.Where(f => f.Path == "path1/subpath1/content1.txt" && f.Discriminator == DocumentHistoryDiscriminator.DocumentCreated).CountAsync()); Assert.AreEqual(1, await ctx.DocumentHistories.Where(f => f.Path == "path1/subpath1/content1.txt" && f.Discriminator == DocumentHistoryDiscriminator.DocumentUpdated).CountAsync()); }
public async Task ドキュメント削除のイベントが登録される() { var document1 = DocumentUtils.Create("path1/subpath1/document1.txt", "Hello, World"); var ev1 = document1.DomainEvents.First(); await sut.Handle(new DomainEventNotification <DocumentCreatedEvent>(ev1 as DocumentCreatedEvent)); document1.ClearDomainEvents(); document1.Delete(); var ev2 = document1.DomainEvents.First(); await sut.Handle(new DomainEventNotification <DocumentDeletedEvent>(ev2 as DocumentDeletedEvent)); Assert.AreEqual(1, await ctx.DocumentHistories.Where(f => f.Path == "path1/subpath1/document1.txt" && f.Discriminator == DocumentHistoryDiscriminator.DocumentCreated).CountAsync()); Assert.AreEqual(1, await ctx.DocumentHistories.Where(f => f.Path == "path1/subpath1/document1.txt" && f.Discriminator == DocumentHistoryDiscriminator.DocumentDeleted).CountAsync()); }
public async Task ファイルが更新された場合正しく更新されること() { var document1 = DocumentUtils.Create("path1/subpath1/content1.txt", "path1/subpath1/content1.txt"); var ev1 = document1.DomainEvents.First(); await sut.Handle(new DomainEventNotification <DocumentCreatedEvent>(ev1 as DocumentCreatedEvent)); var bytes2 = Encoding.UTF8.GetBytes("path1/subpath1/content1.txt updated"); document1.ClearDomainEvents(); document1.Update("application/json", InMemoryData.Create("storagekey2", bytes2)); var ev2 = document1.DomainEvents.First(); await sut.Handle(new DomainEventNotification <DocumentUpdatedEvent>(ev2 as DocumentUpdatedEvent)); Assert.AreEqual("application/json", (await ctx.Blobs.FirstAsync(f => f.Path == "path1/subpath1/content1.txt")).ContentType); }
public async Task コマンドを発行してドキュメントが更新されること() { await repository.AddAsync(DocumentUtils.Create("test1/document1.txt", "Hello, world")); await sut.Handle(new CreateOrUpdateDocumentCommand() { Path = new FilePath("test1/document1.txt"), Data = await dataStore.CreateAsync(Encoding.UTF8.GetBytes("Hello, new world")).ConfigureAwait(false) }); var document = repository.Entities.Single(); Assert.AreEqual("test1/document1.txt", document.Path.ToString()); Assert.AreEqual("Hello, new world", await ReadTextAsync(document.StorageKey)); }
public async Task ドキュメントが移動した場合移動元のパスにドキュメントはなくなり移動先のパスにドキュメントが生成される() { var document1 = DocumentUtils.Create("path1/subpath1/content1.txt", "path1/subpath1/content1.txt"); var ev1 = document1.DomainEvents.First(); await sut.Handle(new DomainEventNotification <DocumentCreatedEvent>(ev1 as DocumentCreatedEvent)); document1.ClearDomainEvents(); document1.MoveTo(new DocumentPath("path2/subpath1/document1.txt")); var ev2 = document1.DomainEvents.First(); await sut.Handle(new DomainEventNotification <DocumentMovedEvent>(ev2 as DocumentMovedEvent)); Assert.IsFalse(await ctx.Blobs.AnyAsync(f => f.Path == "path1/subpath1/content1.txt")); Assert.IsFalse(await ctx.BlobContainers.AnyAsync(f => f.Path == "path1/subpath1")); Assert.IsFalse(await ctx.BlobContainers.AnyAsync(f => f.Path == "path1")); Assert.IsTrue(await ctx.Blobs.AnyAsync(f => f.Path == "path2/subpath1/document1.txt")); Assert.IsTrue(await ctx.BlobContainers.AnyAsync(f => f.Path == "path2/subpath1")); Assert.IsTrue(await ctx.BlobContainers.AnyAsync(f => f.Path == "path2")); }
public async Task 削除済みのファイルが存在する場合でもコマンドを発行してドキュメントが作成されること() { var document = DocumentUtils.Create("test1/document1.txt", "Hello, world"); document.Delete(); await repository.AddAsync(document); await sut.Handle(new CreateOrUpdateDocumentCommand() { Path = new FilePath("test1/document1.txt"), Data = await dataStore.CreateAsync(Encoding.UTF8.GetBytes("Hello, new world")).ConfigureAwait(false), }); var doc1 = repository.Entities.FirstOrDefault(e => e.Path == null); var doc2 = repository.Entities.FirstOrDefault(e => e.Path == "test1/document1.txt"); Assert.IsNotNull(doc1); Assert.IsNotNull(doc2); Assert.AreEqual("Hello, new world", await ReadTextAsync(doc2.StorageKey)); }