Пример #1
0
        public async Task ServerQueryHandler_Get_OnException_ShouldThrowTokenQueryException()
        {
            // arrange
            var mockClient = new Mock <IClient>();

            mockClient.Setup(c => c.GetJson <Server[]>(It.IsAny <string>(), It.IsAny <string>())).ThrowsAsync(new ClientException("some error"));

            var serverHandler = new ServerQueryHandler(mockClient.Object);

            // act
            var result = await serverHandler.Get(new ServerQuery { Payload = "token" });

            // assert ExpectedException
        }
Пример #2
0
        public async Task ServerQueryHandler_Get_QueryPayloadIsNull_ShouldThrowArgumentNullException()
        {
            // arrange
            var mockClient = new Mock <IClient>();

            mockClient.Setup(c => c.GetJson <Server[]>(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(new Server[] { new Server {
                                                                                                                                  Name = "Lietuva"
                                                                                                                              } });

            var tokenHandler = new ServerQueryHandler(mockClient.Object);

            // act
            var result = await tokenHandler.Get(new ServerQuery());

            // assert ExpectedException
        }
Пример #3
0
        public async Task ServerQueryHandler_Get_QueryIsNull_ShouldThrowArgumentNullException()
        {
            // arrange
            var mockClient = new Mock <IClient>();

            mockClient.Setup(c => c.PostJson <Credentials, TokenResponse>(It.IsAny <string>(), It.IsAny <Credentials>())).ReturnsAsync(new TokenResponse {
                Token = "token"
            });

            var serverHandler = new ServerQueryHandler(mockClient.Object);

            // act
            var result = await serverHandler.Get(null);

            // assert ExpectedException
        }
Пример #4
0
        public async Task ServerQueryHandler_Get_ShouldReturnValidResult()
        {
            // arrange
            var mockClient = new Mock <IClient>();

            mockClient.Setup(c => c.GetJson <Server[]>(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(new Server[] { new Server {
                                                                                                                                  Name = "Lietuva"
                                                                                                                              } });

            var serverHandler = new ServerQueryHandler(mockClient.Object);

            // act
            var result = await serverHandler.Get(new ServerQuery { Payload = "token" });

            // assert
            Assert.AreEqual(1, result.Length);
            Assert.AreEqual("Lietuva", result[0].Name);
        }