[Fact] public void GetUserIdByEmailAddress_ShouldReturnUserIdForFirstUserFound() { const string emailAddress = "*****@*****.**"; var users = new List <IUser> { new IncomingUser { EmailAddress = emailAddress, UserId = Guid.NewGuid() }, new IncomingUser { EmailAddress = emailAddress, UserId = Guid.NewGuid() }, new IncomingUser { EmailAddress = emailAddress, UserId = Guid.NewGuid() }, }; _unitOfWork .Setup(u => u.Users.Find(It.IsAny <Expression <Func <IUser, bool> > >())) .Returns(Task.FromResult <IEnumerable <IUser> >(users)); Silo.CreateGrain <UserRepositoryGrain>(0) .GetUserIdByEmailAddress(emailAddress) .GetAwaiter().GetResult() .Should().Be(users[0].UserId); }
[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 Update_ShouldCommitUnitOfWork() { var stored = new IncomingUser { UserId = Guid.NewGuid(), DisplayName = "Joe Bloggs" }; _unitOfWork.Setup(u => u.Users.Get(stored.UserId)) .Returns(() => Task.FromResult <IUser>(stored)); _unitOfWork.Setup(u => u.Commit()).Returns(() => Task.CompletedTask); var update = new User { UserId = stored.UserId, DisplayName = "Joey" }; Silo.CreateGrain <UserGrain>(stored.UserId) .Update(update).GetAwaiter().GetResult(); stored.DisplayName.Should().Be(update.DisplayName); _unitOfWork.Verify(u => u.Commit(), Times.Once(), "because we need to commit our changes"); }
public void MissingProbe() { IPing grain = Silo.CreateGrain <PingGrain>(1); //There should not be an exception, since we are using loose grain generation grain.Invoking(p => p.Ping()).ShouldNotThrow(); }
public async Task OnGameCreation_Fen_Should_BeInit() { var game = Silo.CreateGrain <Game> (Guid.NewGuid()); const string expected = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"; var state = await game.GetBoardState(); state.Fen.Should().Be(expected); }
public void XUnitLog() { const string greeting = "Bonjour"; IHello grain = Silo.CreateGrain <HelloGrain>(2); grain.Invoking(g => g.SayHello(greeting)).ShouldNotThrow(); }
public void GrainIsSubscribed() { var stream = Silo.AddStreamProbe <ChatMessage>(Guid.Empty, null); Silo.CreateGrain <Listener>(1); stream.Subscribed.Should().Be(1); }
public void LazyStreamProvider() { var chatty = Silo.CreateGrain <Chatty>(4); const string msg = "Hello Chat"; //Send a message without creating a stream probe chatty.Invoking(p => p.SendChat(msg).Wait()).ShouldNotThrow(); }
public void GrainDeactivation() { var grain = Silo.CreateGrain <LifecycleGrain>(new Random().Next()); grain.IsDeactivated.Should().BeFalse(); Silo.Deactivate(grain); grain.IsDeactivated.Should().BeTrue(); }
public async Task SetupProbe() { var grain = Silo.CreateGrain <PingGrain>(1); var pong = Silo.AddProbe <IPong>(22); await grain.Ping(); pong.Verify(p => p.Pong(), Times.Once); }
public async Task IntegerKeyGrain() { const int id = int.MaxValue; var grain = Silo.CreateGrain <IntegerKeyGrain>(id); var key = await grain.GetKey(); key.Should().Be(id); }
public async Task StatefulStringKeyGrain() { const string id = "TestId"; var grain = Silo.CreateGrain <StatefulStringKeyGrain>(id); var key = await grain.GetKey(); key.Should().Be(id); }
public void GrainDeactivation() { var grain = Silo.CreateGrain <LifecycleGrain>(new Random().Next()); grain.DeactivateCount.Should().Be(0); Silo.Deactivate(grain); grain.DeactivateCount.Should().Be(1); }
public async Task GrainReceives() { var stream = Silo.AddStreamProbe <ChatMessage>(Guid.Empty, null); var grain = Silo.CreateGrain <Listener>(1); await stream.OnNextAsync(new ChatMessage("Ding")); (await grain.ReceivedCount()).Should().Be(1); }
public async Task GuidKeyGrain() { var id = Guid.NewGuid(); var grain = Silo.CreateGrain <GuidKeyGrain>(id); var key = await grain.GetKey(); key.Should().Be(id); }
public void IncorrectProbeNamespace() { var chatty = Silo.CreateGrain <Chatty>(4); Silo.AddStreamProbe <ChatMessage>(Guid.Empty, "Wrong"); const string msg = "Hello Chat"; chatty.Invoking(p => p.SendChat(msg).Wait()).ShouldNotThrow(); }
public void IncorrectProbeId() { var chatty = Silo.CreateGrain <Chatty>(4); Silo.AddStreamProbe <ChatMessage>(Guid.NewGuid(), null); const string msg = "Hello Chat"; chatty.Invoking(p => p.SendChat(msg).Wait()).ShouldNotThrow(); }
public async Task InvalidProbeType() { IPing grain = Silo.CreateGrain <PingGrain>(1); //This uses the correct id, but the wrong grain type var pong = Silo.AddProbe <IPong2>(22); grain.Invoking(p => p.Ping()).ShouldThrowExactly <Exception>(); pong.Verify(p => p.Pong2(), Times.Never); }
public async Task OnGameCreation_Should_AllowPlayerII() { var gameId = Guid.NewGuid(); var sut = BuildSut(gameId); var playerIISeat = Silo.CreateGrain <SeatII> (gameId); var playerId = Guid.NewGuid(); var result = await playerIISeat.JoinGame(playerId); result.WasSuccessful.Should().BeTrue(); }
public void LazyStreamProviderStrict() { Silo.Options.StrictStreamProbes = true; var chatty = Silo.CreateGrain <Chatty>(4); const string msg = "Hello Chat"; //This should throw an exception since the provider was not created chatty.Invoking(p => p.SendChat(msg).Wait()).ShouldThrow <Exception>(); }
public async Task ShouldCallDeactivateOnIdle() { // Arrange var grain = Silo.CreateGrain <DeactivationGrain>(0); // Act await grain.DeactivateOnIdle(); // Assert Silo.VerifyRuntime(i => i.DeactivateOnIdle(grain), Times.Once); }
public async Task InvalidProbe() { IPing grain = Silo.CreateGrain <PingGrain>(1); //This uses the wrong id for the IPong since this is hard coded within PingGrain var pong = Silo.AddProbe <IPong>(0); grain.Invoking(p => p.Ping()).ShouldThrowExactly <Exception>(); pong.Verify(p => p.Pong(), Times.Never); }
public void InvalidProbeType() { IPing grain = Silo.CreateGrain <PingGrain>(1); //This correct id, but a different grain type var pong = Silo.AddProbe <IPong2>(22); grain.Invoking(p => p.Ping()).ShouldNotThrow(); pong.Verify(p => p.Pong2(), Times.Never); }
public async Task ShouldCallDelayDeactivation() { // Arrange var grain = Silo.CreateGrain <DeactivationGrain>(0); var timeSpan = TimeSpan.FromSeconds(5); // Act await grain.DelayDeactivation(timeSpan); // Assert Silo.VerifyRuntime(i => i.DelayDeactivation(grain, timeSpan), Times.Once); }
public async Task IncorrectVerifyMessage() { var chatty = Silo.CreateGrain <Chatty>(4); var stream = Silo.AddStreamProbe <ChatMessage>(Guid.Empty, null); const string msg = "Hello Chat"; await chatty.SendChat(msg); stream.Invoking(s => s.VerifySend(m => m.Msg == "This is not right")).ShouldThrow <Exception>(); }
public async Task IntegerCompoundKeyGrain() { const int id = int.MaxValue; var ext = "Thing"; var grain = Silo.CreateGrain <IntegerCompoundKeyGrain>(id, ext); var key = await grain.GetKey(); key.Item1.Should().Be(id); key.Item2.Should().Be(ext); }
public async Task ShouldActivateWithValidState() { // Arrange // Act var grain = Silo.CreateGrain <StatefulActivationGrain>(0); var value = await grain.GetActivationValue(); // Assert value.Should().Be(123); }
public async Task GuidCompoundKeyGrain() { var id = Guid.NewGuid(); var ext = "Thing"; var grain = Silo.CreateGrain <GuidCompoundKeyGrain>(id, ext); var key = await grain.GetKey(); key.Item1.Should().Be(id); key.Item2.Should().Be(ext); }
public void SetupGrainService() { var mockSvc = new Mock <IDIService>(); mockSvc.Setup(x => x.GetValue()).Returns(true); Silo.ServiceProvider.AddServiceProbe(mockSvc); var grain = Silo.CreateGrain <DIGrain>(Guid.NewGuid()); grain.GetServiceValue().Should().BeTrue(); mockSvc.Verify(x => x.GetValue(), Times.Once); }
public async Task SiloSayHelloTest() { long id = new Random().Next(); const string greeting = "Bonjour"; IHello grain = Silo.CreateGrain <HelloGrain>(id); // This will create and call a Hello grain with specified 'id' in one of the test silos. string reply = await grain.SayHello(greeting); Assert.NotNull(reply); Assert.Equal($"You said: '{greeting}', I say: Hello!", reply); }