Ejemplo n.º 1
0
        public static async Task SeedRoleAsync(IChannelService channelService, Channel channel)
        {
            var channelExists = channelService.Exists(channel.Name);

            if (!channelExists)
            {
                await channelService.CreateAsync(channel);
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CreateAsync([FromBody] Channel channelEntry)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var channel = await _channelService.CreateAsync(channelEntry);

            return(CreatedAtAction(nameof(GetByIdAsync), new { id = channel.Id }, null));
        }
        internal async Task GivenCreateAsyncWhenExpectedExceptionIsThrownThenHandlesGracefully()
        {
            // Arrange

            // Act
            var exception = await Assert.ThrowsAsync <NotImplementedException>(
                () => channelService.CreateAsync(It.IsAny <Channel>()));

            // Assert
            exception.Should().NotBeNull().And.BeOfType <NotImplementedException>();
        }
Ejemplo n.º 4
0
        public void GivenCreateAsyncWhenExpectedExceptionIsThrownThenHandlesGracefully()
        {
            // Arrange

            // Act
            var exception = Assert.ThrowsAsync <NotImplementedException>(
                () => channelService.CreateAsync(It.IsAny <Channel>()));

            // Assert
            exception.ShouldNotBeNull();
            exception.ShouldBeOfType <NotImplementedException>();
        }
        public void GivenCreateAsyncWhenExpectedExceptionIsThrownThenHandlesGracefully()
        {
            // Arrange

            // Act
            var exception = Assert.ThrowsAsync <NotImplementedException>(
                () => channelService.CreateAsync(It.IsAny <Channel>()));

            // Assert
            Assert.That(exception, Is.Not.Null);
            Assert.That(exception, Is.TypeOf <NotImplementedException>());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> CreateAsync([FromBody] Channel channel)
        {
            try
            {
                await channelService.CreateAsync(channel);

                return(Created($"api/v1/channels/{ channel?.Id }", channel));
            }
            catch
            {
                return(BadRequest());
            }
        }
Ejemplo n.º 7
0
 public UnifyResponseDto CreateAsync([FromBody] CreateUpdateChannelDto createChannel)
 {
     _channelService.CreateAsync(createChannel);
     return(UnifyResponseDto.Success("新建技术频道成功"));
 }