public static async Task SeedRoleAsync(IChannelService channelService, Channel channel) { var channelExists = channelService.Exists(channel.Name); if (!channelExists) { await channelService.CreateAsync(channel); } }
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>(); }
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>()); }
public async Task <IActionResult> CreateAsync([FromBody] Channel channel) { try { await channelService.CreateAsync(channel); return(Created($"api/v1/channels/{ channel?.Id }", channel)); } catch { return(BadRequest()); } }
public UnifyResponseDto CreateAsync([FromBody] CreateUpdateChannelDto createChannel) { _channelService.CreateAsync(createChannel); return(UnifyResponseDto.Success("新建技术频道成功")); }