public async Task ResetColor_WithDefaultState_DoesNotClearState() { // Arrange var state = new ColorGrainState(); var mockState = new Mock <IPersistentState <ColorGrainState> >(); mockState.SetupGet(o => o.State).Returns(state); mockState.Setup(o => o.ClearStateAsync()); var mockMapper = new Mock <IAttributeToFactoryMapper <PersistentStateAttribute> >(); mockMapper.Setup(o => o.GetFactory(It.IsAny <ParameterInfo>(), It.IsAny <PersistentStateAttribute>())).Returns(context => mockState.Object); Silo.AddService(mockMapper.Object); var grain = await Silo.CreateGrainAsync <ColorGrain>(GrainId); // Act await grain.ResetColor(); // Assert state.Color.Should().Be(Color.Unknown); state.Id.Should().Be(Guid.Empty); // Note that the following assert ties this test to the _implementation_ details. Generally, one should try // to avoid tying the test to the implementation details. It can lead to more brittle tests. However, one may // choose to accept this as a trade-off when the implementation detail represents an important behavior. mockState.Verify(o => o.ClearStateAsync(), Times.Never); }
public async Task GetColor_WithState_ReturnsColor() { // Arrange var state = new ColorGrainState { Color = Color.Red, Id = GrainId, }; var mockState = new Mock <IPersistentState <ColorGrainState> >(); mockState.SetupGet(o => o.State).Returns(state); var mockMapper = new Mock <IAttributeToFactoryMapper <PersistentStateAttribute> >(); mockMapper.Setup(o => o.GetFactory(It.IsAny <ParameterInfo>(), It.IsAny <PersistentStateAttribute>())).Returns(context => mockState.Object); Silo.AddService(mockMapper.Object); var grain = await Silo.CreateGrainAsync <ColorGrain>(GrainId); // Act var color = await grain.GetColor(); // Assert color.Should().Be(Color.Red); }
public async Task SetColor_WithDefaultState_SetsState() { // Arrange var state = new ColorGrainState(); var mockState = new Mock <IPersistentState <ColorGrainState> >(); mockState.SetupGet(o => o.State).Returns(state); mockState.Setup(o => o.WriteStateAsync()); var mockMapper = new Mock <IAttributeToFactoryMapper <PersistentStateAttribute> >(); mockMapper.Setup(o => o.GetFactory(It.IsAny <ParameterInfo>(), It.IsAny <PersistentStateAttribute>())).Returns(context => mockState.Object); Silo.AddService(mockMapper.Object); var grain = await Silo.CreateGrainAsync <ColorGrain>(GrainId); // Act await grain.SetColor(Color.Blue); // Assert state.Color.Should().Be(Color.Blue); state.Id.Should().Be(GrainId); }
public void Init() { var clientFactory = new Mock <IHttpClientFactory>(); var httpClient = CreateMockedHttpClient(HttpStatusCode.OK, HttpResultValue); clientFactory.Setup(s => s.CreateClient(It.IsAny <string>())) .Returns(httpClient); Silo.AddService(clientFactory.Object); }
protected PlatformexTestKit() { var loggerFactory = new LoggerFactory(); Silo.AddService <ILoggerFactory>(loggerFactory); Platform = new TestPlatform(); Builder = new PlatformBuilder(Platform); Silo.AddService <IPlatform>(Platform); }
public PersistantStreamNotWithinGrainStateTests() { _stateWithoutHandle = new PersistentListenerStateWithoutHandle(); _persistentState = new Mock <IPersistentState <PersistentListenerStateWithoutHandle> >(); _persistentState.SetupGet(o => o.State).Returns(_stateWithoutHandle); var mockMapper = new Mock <IAttributeToFactoryMapper <PersistentStateAttribute> >(); mockMapper.Setup(o => o.GetFactory(It.IsAny <ParameterInfo>(), It.IsAny <PersistentStateAttribute>())) .Returns(context => _persistentState.Object); Silo.AddService(mockMapper.Object); _stream = Silo.AddStreamProbe <ChatMessage>(Guid.Empty, null, "Default"); }
public async Task SetColor_WithMutatedState_ThrowsInconsistentStateException() { // Arrange var state = new ColorGrainState(); var mockState = new Mock <IPersistentState <ColorGrainState> >(); mockState.SetupGet(o => o.State).Returns(state); mockState.Setup(o => o.WriteStateAsync()).Throws <InconsistentStateException>(); var mockMapper = new Mock <IAttributeToFactoryMapper <PersistentStateAttribute> >(); mockMapper.Setup(o => o.GetFactory(It.IsAny <ParameterInfo>(), It.IsAny <PersistentStateAttribute>())).Returns(context => mockState.Object); Silo.AddService(mockMapper.Object); var grain = await Silo.CreateGrainAsync <ColorGrain>(GrainId); Action action = () => grain.SetColor(Color.Green); // Act+Assert action.Should().Throw <InconsistentStateException>(); }
public async Task SayHelloTestShouldPrintDateWhenServiceProvided() { // Arrange const string greeting = "Bonjour"; var date = DateTime.UtcNow.Date; var dateServiceMock = new Mock <IDateTimeService>(); dateServiceMock.Setup(i => i.GetCurrentDate()) .ReturnsAsync(() => date); Silo.AddService(dateServiceMock.Object); var grain = Silo.CreateGrain <HelloGrainWithServiceDependency>(10); // Act var reply = await grain.SayHello(greeting); // Assert Assert.NotNull(reply); Assert.Equal($"[{date}]: You said: '{greeting}', I say: Hello!", reply); dateServiceMock.Verify(i => i.GetCurrentDate(), Times.Once); }
public UnitTest1() { Silo.AddService <IMemoState>(new MemoState(new InMemoryDbProvider <MemoModel>())); }
public UserRepositoryGrainTests() { _unitOfWork = new Mock <IUnitOfWork>(); Silo.AddService(_unitOfWork.Object); }
public BlogPostGrainTests() { _unitOfWork = new Mock <IUnitOfWork>(); Silo.AddService(_unitOfWork.Object); }
public AggregateTests() { Silo.AddService <ITestAggregateState>(new TestAggregateState()); }