예제 #1
0
        public void ドキュメントを新規に作成しドキュメントの作成イベントが発生する()
        {
            var sut = new Document(new DocumentPath("test.txt"), "text/plain", InMemoryData.Create("storagekey1", Stream("ABCD")));

            Assert.AreEqual(1, sut.DomainEvents.Count);
            Assert.IsTrue(sut.DomainEvents.First() is DocumentCreatedEvent);
        }
예제 #2
0
        public void ドキュメントを移動した場合ドキュメントの移動イベントが発生する()
        {
            var sut = new Document(new DocumentPath("test.txt"), "text/plain", InMemoryData.Create("storagekey1", Stream("ABCD")));

            sut.ClearDomainEvents();
            sut.MoveTo(new DocumentPath("test2.txt"));
            Assert.AreEqual(1, sut.DomainEvents.Count);
            Assert.IsTrue(sut.DomainEvents.First() is DocumentMovedEvent);
        }
예제 #3
0
        public static Document Create(string path, string textContent)
        {
            var now = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            return(new Document(new DocumentPath(path),
                                "text/plain",
                                InMemoryData.Create(path, Encoding.UTF8.GetBytes(textContent)),
                                now,
                                now));
        }
        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/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);
        }