dotnet / dotnet/orleans

Microsoft Orleans, Mock and IGrainObserver

Open
#8,620 1 comment 0 reactions 1 assignee View on GitHub

@ReubenBond is already working on this.

Since Sep 1, 2023.

question
Dominant language
C#
Stars
10.9k
Forks
2.1k
Avg merge
13h 56m
Merged PRs (30d)
351

Description

I am trying to run this test but I get an error.

[Fact]
public async Task Subscribe()
{
    var cluster = new ClusterFixture().Cluster;
    var grain = cluster.GrainFactory.GetGrain<INewsGrain>(String.Empty);
    
    var observer = new Mock<INewsObserver>();
    observer.Setup(x => x.NewsItemAdded(It.IsAny<NewsItem>()));
    
    var observerRef = cluster.GrainFactory.CreateObjectReference<INewsObserver>(observer.Object);
    await grain.Subscribe(observerRef);
    
    var newsItem = new NewsItem
    {
        NewsId = Guid.NewGuid(),
        Title = "Title",
        Content = "Content",
        AuthorId = Guid.NewGuid(),
        PublishedDate = DateTime.Now,
        Tags = ImmutableArray.Create("asd", "qwe")
    };
    
    await grain.AddNewsItem(newsItem);
    observer.Verify(x => x.NewsItemAdded(It.IsAny<NewsItem>()), Times.Once);
}

Expected invocation on the mock once, but was 0 times: x => x.NewsItemAdded(It.IsAny())

await grain.AddNewsItem(newsItem); code works fine

Can you tell me what the problem might be?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.