示例#1
0
 public async Task ThrowArgumentNullExceptionWhenRelayIdMissingWhenGetRelayIsCalledAsync()
 {
     // Arrange
     IRelayManagementService relayManagementService = A.Fake <IRelayManagementService>();
     ILogger logger      = A.Fake <ILogger>();
     var     sut         = new ShieldManagementApi(relayManagementService);
     var     httpContext = new DefaultHttpContext();
     var     httpRequest = new DefaultHttpRequest(httpContext);
     // Act & Assert
     await Assert.ThrowsAsync <ArgumentNullException>(() => sut.GetRelayInformationAsync(httpRequest, "", logger));
 }
示例#2
0
 public async Task PostRelayThrowInvalidOperationExceptionWhenHttpRequestContainsNoBodyAsync()
 {
     // Arrange
     IRelayManagementService relayManagementService = A.Fake <IRelayManagementService>();
     ILogger logger      = A.Fake <ILogger>();
     var     sut         = new ShieldManagementApi(relayManagementService);
     var     httpContext = new DefaultHttpContext();
     var     httpRequest = new DefaultHttpRequest(httpContext);
     // Act & Assert
     await Assert.ThrowsAsync <InvalidOperationException>(() => sut.PostRelayInformationAsync(httpRequest, logger));
 }
示例#3
0
        public async Task ThrowArgumentNullExceptionWhenGetListenerIsCalledWithoutRelayAsync()
        {
            // Arrange
            IRelayManagementService relayManagementService = A.Fake <IRelayManagementService>();
            ILogger logger      = A.Fake <ILogger>();
            var     sut         = new ShieldManagementApi(relayManagementService);
            var     httpContext = new DefaultHttpContext();
            var     httpRequest = new DefaultHttpRequest(httpContext);

            A.CallTo(() => relayManagementService.GetRelayAsync(TestHelper.TenantId.ToString())).WithAnyArguments().Returns(TestHelper.GetHybridConnectionDto());
            // Act
            await Assert.ThrowsAsync <ArgumentNullException>(() => sut.GetRelayListnerInformationAsync(httpRequest, "", logger));
        }
示例#4
0
        public async Task ReturnNotFoundResultWhenNoHybridConnectionIsReturnedWhenGetRelayIsCalledAsync()
        {
            // Arrange
            IRelayManagementService relayManagementService = A.Fake <IRelayManagementService>();
            ILogger logger      = A.Fake <ILogger>();
            var     sut         = new ShieldManagementApi(relayManagementService);
            var     httpContext = new DefaultHttpContext();
            var     httpRequest = new DefaultHttpRequest(httpContext);

            A.CallTo(() => relayManagementService.GetRelayAsync(TestHelper.TenantId.ToString())).WithAnyArguments().Returns <HybridConnectionDto>(null);
            // Act
            IActionResult actual = await sut.GetRelayInformationAsync(httpRequest, "relay", logger);

            // Assert
            Assert.Equal(HttpStatusCode.NotFound, (HttpStatusCode)((StatusCodeResult)actual).StatusCode);
        }
示例#5
0
        public async Task ReturnSuccessStatusCodeWhenGetRelayListnerIsCalledAsync()
        {
            // Arrange
            IRelayManagementService relayManagementService = A.Fake <IRelayManagementService>();
            ILogger logger      = A.Fake <ILogger>();
            var     sut         = new ShieldManagementApi(relayManagementService);
            var     httpContext = new DefaultHttpContext();
            var     httpRequest = new DefaultHttpRequest(httpContext);

            A.CallTo(() => relayManagementService.GetRelayAsync(TestHelper.TenantId.ToString())).WithAnyArguments().Returns(TestHelper.GetHybridConnectionDto());
            // Act
            IActionResult actual = await sut.GetRelayListnerInformationAsync(httpRequest, "relay", logger);

            // Assert
            Assert.IsType <ListenerDto>(((ObjectResult)actual).Value);
            Assert.Equal(HttpStatusCode.OK, (HttpStatusCode)((ObjectResult)actual).StatusCode);
        }
示例#6
0
        public async Task ReturnBadRequestStatusCodeWhenPostRelayIsCalledAndSomethingWentWrongAsync()
        {
            // Arrange
            IRelayManagementService relayManagementService = A.Fake <IRelayManagementService>();
            ILogger logger      = A.Fake <ILogger>();
            var     sut         = new ShieldManagementApi(relayManagementService);
            var     httpContext = new DefaultHttpContext();
            var     httpRequest = new DefaultHttpRequest(httpContext)
            {
                Body = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(TestHelper.GetCreateRelayStorageDto())))
            };

            A.CallTo(() => relayManagementService.StoreRelayAsync(TestHelper.GetCreateRelayStorageDto())).WithAnyArguments().Returns <HybridConnectionDto>(null);
            // Act
            IActionResult actual = await sut.PostRelayInformationAsync(httpRequest, logger);

            // Assert
            Assert.Equal(HttpStatusCode.BadRequest, (HttpStatusCode)((StatusCodeResult)actual).StatusCode);
        }