예제 #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "list/{id}")] HttpRequest req, string id)
        {
            try
            {
                var command = new DeleteListCommand {
                    Id = id
                };
                var handler = Container.GetInstance <ICommandHander <DeleteListCommand> >();

                await handler.Execute(command);

                return(new NoContentResult());
            }
            catch (ResourceNotFoundException ex)
            {
                Container.GetInstance <TelemetryClient>().TrackException(ex);

                return(new NotFoundResult());
            }
            catch (Exception ex)
            {
                Container.GetInstance <TelemetryClient>().TrackException(ex);

                return(new InternalServerErrorResult());
            }
        }
예제 #2
0
        private async Task <bool> HandleAsync(DeleteListCommand command)
        {
            var list = await this.context.Lists.FindAsync(command.Id);

            this.context.Lists.Remove(list);
            var count = await this.context.SaveChangesAsync();

            return(count >= 0);
        }
예제 #3
0
        public async Task <IActionResult> Delete([FromBody] Guid id)
        {
            var user = await _userManagerWrapper.FindByNameAsync(User.Identity.Name);

            var deletelistCommand = new DeleteListCommand {
                Id = id, UserId = user.Id
            };
            await _endpointInstance.Send("LifeManager.Lists", deletelistCommand).ConfigureAwait(false);

            return(Ok());
        }
예제 #4
0
        public void Execute_ReturnsCompletedTaskOnSuccess()
        {
            var repo    = new Mock <IListRepository>();
            var id      = Guid.NewGuid().ToString();
            var command = new DeleteListCommand {
                Id = id
            };
            var handler = new DeleteListCommandHandler(repo.Object);

            repo.Setup(r => r.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);

            var result = handler.Execute(command);

            Assert.AreEqual(Task.CompletedTask, result);
        }
예제 #5
0
        public async Task HandleDeleteCommand_ShouldCallListServiceDelete()
        {
            // Data
            var deleteListCommand = new DeleteListCommand {
                Id = Guid.NewGuid(), UserId = "username"
            };


            // Setup
            _mockListService.Setup(x => x.DeleteList(deleteListCommand.Id, deleteListCommand.UserId)).Returns(Task.CompletedTask).Verifiable();

            // Test
            var handler = new ListsEventHandler(_mockListService.Object);
            await handler.Handle(deleteListCommand, _mockMessageContext.Object);

            // Analysis
            _mockListService.Verify();
        }
예제 #6
0
 public async Task Handle(DeleteListCommand message, IMessageHandlerContext context)
 {
     await _listService.DeleteList(message.Id, message.UserId);
 }
예제 #7
0
 public async Task <bool> DeleteList([FromBody] DeleteListCommand command)
 {
     return(await commandProcessor.ProcessAsync(command));
 }