Ejemplo n.º 1
0
        [Fact] public void Update_ShouldCommitUnitOfWork()
        {
            var stored = new IncomingBlogPost {
                BlogPostId = Guid.NewGuid(),
                Title      = "Hello, world!"
            };

            _unitOfWork.Setup(u => u.Posts.Get(stored.BlogPostId))
            .Returns(() => Task.FromResult <IBlogPost>(stored));

            _unitOfWork.Setup(u => u.Commit()).Returns(() => Task.CompletedTask);

            var update = new BlogPost {
                BlogPostId = stored.BlogPostId,
                Title      = "Hello, xUnit!"
            };

            Silo.CreateGrain <BlogPostGrain>(stored.BlogPostId)
            .Update(update).GetAwaiter().GetResult();

            stored.Title.Should().Be(update.Title);

            _unitOfWork.Verify(u => u.Posts.Get(stored.BlogPostId), Times.AtMostOnce(),
                               "because need for fetch it 0 or 1 times");

            _unitOfWork.Verify(u => u.Commit(), Times.Once(),
                               "because we need to commit our changes");

            _unitOfWork.VerifyNoOtherCalls();
        }
        public void ToDataModel_ShouldTransferAllFields()
        {
            var original    = new BlogPost();
            var expectation = new IncomingBlogPost();

            original.BlogPostId = expectation.BlogPostId = Guid.NewGuid();
            original.Title      = expectation.Title = "Hello, world!";
            original.Content    = expectation.Content = "This is a blog post";
            expectation.Created = original.Created = DateTime.UtcNow;
            original.AuthorId   = expectation.AuthorId = Guid.NewGuid();

            original.ToDataModel().Should().BeEquivalentTo(expectation,
                                                           "because we need to be able to rely on having all fields transferred");
        }
Ejemplo n.º 3
0
        [Fact] public void Find_ShouldReturnGrainModel()
        {
            var stored = new IncomingBlogPost {
                BlogPostId = Guid.NewGuid()
            };

            _unitOfWork.Setup(u => u.Posts.Get(stored.BlogPostId))
            .Returns(() => Task.FromResult <IBlogPost>(stored));

            var grain = Silo.CreateGrain <BlogPostGrain>(stored.BlogPostId);

            grain.Find().GetAwaiter().GetResult().Should().BeEquivalentTo(stored.ToGrainModel(),
                                                                          "becuase that's what the UnitOfWork provided");

            _unitOfWork.Verify(u => u.Posts.Get(stored.BlogPostId), Times.Once(),
                               "because we need to call it just once");

            _unitOfWork.VerifyNoOtherCalls();
        }