Пример #1
0
        public async Task HasTimeout_ReturnsFalse_WhenTimeoutRecordDoesNotExist()
        {
            const string PlayerId = "TestPlayer";
            const string Source   = "CosmosEventWriterUnitTests";

            var mockTimerClient = new Mock <ICosmosTimerClient>();

            mockTimerClient.Setup(timerClient =>
                                  timerClient.GetPlayerTimeoutRecord(It.Is <string>(s => s == Source), It.Is <string>(s => s == PlayerId)))
            .Returns(Task.FromResult(new ResponseMessage(HttpStatusCode.NotFound)))
            .Verifiable();

            var structureUnderTest = new CosmosTimer(mockTimerClient.Object);
            var result             = await structureUnderTest.HasTimeout(PlayerId, Source);

            mockTimerClient.Verify(
                timerClient =>
                timerClient.GetPlayerTimeoutRecord(It.Is <string>(s => s == Source),
                                                   It.Is <string>(s => s == PlayerId)), Times.Once);

            Assert.IsFalse(result);
        }
Пример #2
0
        public async Task Timeout_DoesNotCallCreateItemAsync_OnCosmosContainerWhenTimeoutRecordExists()
        {
            const string PlayerId = "TestPlayer";
            const string Source   = "CosmosEventWriterUnitTests";

            var mockTimerClient = new Mock <ICosmosTimerClient>();

            mockTimerClient.Setup(timerClient =>
                                  timerClient.GetPlayerTimeoutRecord(It.Is <string>(s => s == Source), It.Is <string>(s => s == PlayerId)))
            .Returns(Task.FromResult(new ResponseMessage(HttpStatusCode.OK)))
            .Verifiable();

            var structureUnderTest = new CosmosTimer(mockTimerClient.Object);
            await structureUnderTest.Timeout(PlayerId, Source);

            mockTimerClient.Verify(
                timerClient =>
                timerClient.GetPlayerTimeoutRecord(It.Is <string>(s => s == Source),
                                                   It.Is <string>(s => s == PlayerId)), Times.Once);

            mockTimerClient.Verify(timerClient => timerClient.CreatePlayerTimeoutRecord(It.Is <string>(s => s == Source),
                                                                                        It.Is <string>(s => s == PlayerId)), Times.Never);
        }