Esempio n. 1
0
        public ActionResult <bool> Delete([FromBody] DeleteEventDTO request)
        {
            var command = new DeleteEventCommand(_mapper.Map <Event>(request));
            var handler = _commandHandler.Build(command);

            return(Ok(handler.Execute()));
        }
Esempio n. 2
0
        public async Task <IActionResult> DeleteEvent(int eventId)
        {
            var deleteEventCommand = new DeleteEventCommand(eventId);
            var result             = await mediator.Send(deleteEventCommand);

            return(StatusCode((int)result.Code, result.Value));
        }
Esempio n. 3
0
        public async Task <IActionResult> DeleteConfirmed(int?id, int Id, string returnUrl)
        {
            if (id == null || id != Id)
            {
                return(NotFound());
            }
            var command = new DeleteEventCommand {
                Id = Id
            };

            try
            {
                await _mediator.Send(command);

                if (!string.IsNullOrEmpty(returnUrl))
                {
                    return(Redirect(returnUrl));
                }
                else
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (ValidationException ex)
            {
                ViewData["exception"] = ex.Message;
                ErrorViewModel vm = new ErrorViewModel();
                return(RedirectToAction("Error", "Home"));
            }
        }
        public async Task <ActionResult> Delete(int id)
        {
            DeleteEventCommand command = new DeleteEventCommand(id);

            await _mediator.Send(command);

            return(RedirectToAction("List"));
        }
        public async Task <ActionResult> Delete(Guid Id)
        {
            var deleteCommand = new DeleteEventCommand {
                EventId = Id
            };
            await _mediator.Send(deleteCommand);

            return(NoContent());
        }
Esempio n. 6
0
        public void EventDoesNotExist()
        {
            var command = new DeleteEventCommand {
                EventId = 0
            };
            var handler = new DeleteEventCommandHandler(Context);

            handler.Handle(command);
            //TODO: this test needs to be completed to actually test something
        }
Esempio n. 7
0
        public IActionResult Delete([FromQuery] DeleteEventCommand command)
        {
            var commandResult = _mediator.Send(command);

            if (commandResult.IsFaulted)
            {
                return(BadRequest(commandResult.Exception.InnerException.Message));
            }

            return(Ok(new { message = "Event deleted" }));
        }
        public async Task Handle_Given_InvalidId_Throws_NotFoundException()
        {
            // Arrange
            var invalidId = 0;
            var command   = new DeleteEventCommand {
                Id = invalidId
            };

            // Act/Assert
            await Assert.ThrowsAsync <NotFoundException>(() => _sut.Handle(command, CancellationToken.None));
        }
Esempio n. 9
0
        public void ShouldRequireValidEventId()
        {
            //arrange
            var command = new DeleteEventCommand {
                Id = Guid.NewGuid()
            };

            //assert
            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().Throw <NotFoundException>();
        }
Esempio n. 10
0
        public void EventDoesNotExist()
        {
            var context = ServiceProvider.GetService <AllReadyContext>();
            var command = new DeleteEventCommand {
                EventId = 0
            };
            var handler = new DeleteEventCommandHandler(context);

            handler.Handle(command);
            //TODO: this test needs to be completed to actually test something
        }
        public async Task ExistingEvent()
        {
            var command = new DeleteEventCommand {
                EventId = 1
            };
            var handler = new DeleteEventCommandHandler(Context);
            await handler.Handle(command);

            var data = Context.Events.Count(_ => _.Id == 1);

            Assert.Equal(0, data);
        }
Esempio n. 12
0
        public void ShouldNotCallHandleIfEventNotExist()
        {
            dbSetEvent.Setup(x => x.FindAsync(id)).Returns(null);
            context.Setup(x => x.Events).Returns(dbSetEvent.Object);

            DeleteEventCommandHandler deleteEventCommandHandler = new DeleteEventCommandHandler(context.Object, stringLocalizer.Object);
            DeleteEventCommand        deleteEventCommand        = new DeleteEventCommand(id);

            Func <Task> act = async() => await deleteEventCommandHandler.Handle(deleteEventCommand, new CancellationToken());

            act.Should().Throw <NotFoundException>();
        }
        public async Task <ActionResult <DeleteEventResponse> > DeleteAsync(int id)
        {
            var command = new DeleteEventCommand();
            var request = new DeleteEventRequest()
            {
                EventID = id
            };

            command.Data = request;
            var response = await Go(command);

            return(Ok(response));
        }
Esempio n. 14
0
        public void ExistingEvent()
        {
            var context = ServiceProvider.GetService <AllReadyContext>();
            var command = new DeleteEventCommand {
                EventId = 1
            };
            var handler = new DeleteEventCommandHandler(context);

            handler.Handle(command);

            var data = context.Events.Count(_ => _.Id == 1);

            Assert.Equal(0, data);
        }
        public async Task Handle_Given_ValidId_Deletes_Event()
        {
            // Arrange
            var validId = 1;
            var command = new DeleteEventCommand {
                Id = validId
            };

            // Act
            await _sut.Handle(command, CancellationToken.None);

            // Assert
            Assert.Null(_context.Events.Find(validId));
        }
Esempio n. 16
0
        public void ShouldNotCallHandleIfNotSavedChanges()
        {
            dbSetEvent.Setup(x => x.FindAsync(id)).Returns(new ValueTask <Event>(Task.FromResult(new Event {
                Id = id
            })));
            context.Setup(x => x.Events).Returns(dbSetEvent.Object);
            context.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(0));

            DeleteEventCommandHandler deleteEventCommandHandler = new DeleteEventCommandHandler(context.Object, stringLocalizer.Object);
            DeleteEventCommand        deleteEventCommand        = new DeleteEventCommand(id);

            Func <Task> act = async() => await deleteEventCommandHandler.Handle(deleteEventCommand, new CancellationToken());

            act.Should().Throw <RestException>();
        }
Esempio n. 17
0
        public async Task ShouldCallHandle()
        {
            dbSetEvent.Setup(x => x.FindAsync(id)).Returns(new ValueTask <Event>(Task.FromResult(new Event {
                Id = id
            })));
            context.Setup(x => x.Events).Returns(dbSetEvent.Object);
            context.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(1));

            DeleteEventCommandHandler deleteEventCommandHandler = new DeleteEventCommandHandler(context.Object, stringLocalizer.Object);
            DeleteEventCommand        deleteEventCommand        = new DeleteEventCommand(id);

            var result = await deleteEventCommandHandler.Handle(deleteEventCommand, new CancellationToken());

            result.Should().Be(Unit.Value);
        }
        public string DispatchCommand(string[] commandParameters)
        {
            string commandName = commandParameters[0];

            commandParameters = commandParameters.Skip(1).ToArray();
            string result = string.Empty;

            EventService eventService = new EventService();

            switch (commandName)
            {
            case "CreateEvent":
                CreateEventCommand createEvent = new CreateEventCommand(eventService);
                result = createEvent.Execute(commandParameters);
                break;

            case "DeleteEvent":
                DeleteEventCommand deleteEvent = new DeleteEventCommand(eventService);
                result = deleteEvent.Execute(commandParameters);
                break;

            case "EditEvent":
                EditEventCommand editEvent = new EditEventCommand(eventService);
                result = editEvent.Execute(commandParameters);
                break;

            case "ListEvents":
                ListEventsCommand listEvents = new ListEventsCommand(eventService);
                result = listEvents.Execute(commandParameters);
                break;

            case "Help":
                HelpCommand help = new HelpCommand();
                result = help.Execute(commandParameters);
                break;

            case "Exit":
                ExitCommand exit = new ExitCommand(eventService);
                result = exit.Execute(commandParameters);
                break;

            default:
                result = $@"Command {commandName} does not exist. Type ""Help"" to check the available commands.";
                break;
            }

            return(result);
        }
Esempio n. 19
0
        public void DeleteEvent_UserExist(
            [Frozen] IEventRepository eventRepository,
            Event @event,
            DeleteEventCommand message,
            DeleteEventCommandHandler deleteEventCommandHandler)
        {
            //Information
            A.CallTo(() => eventRepository.GetById(message.EventId)).Returns(@event);

            //Act
            deleteEventCommandHandler.ExecuteAsync(message);

            //Test
            A.CallTo(() => eventRepository.Remove(@event))
            .MustHaveHappened();
        }
Esempio n. 20
0
        public void DeleteEvent_UserDoesNotExist(
            [Frozen] IEventRepository eventRepository,
            Event @event,
            DeleteEventCommand message,
            DeleteEventCommandHandler deleteEventCommandHandler)
        {
            //Information

            //Act
            deleteEventCommandHandler.ExecuteAsync(message);

            //Test
            A.CallTo(() => eventRepository.GetById(message.EventId)).Throws(new ArgumentNullException());
            A.CallTo(() => eventRepository.Remove(@event))
            .MustNotHaveHappened();
        }
Esempio n. 21
0
        public void DeleteEvent_EventIsRemoved(
            [Frozen] IEventRepository eventRepository,
            Event @event,
            DeleteEventCommand message,
            DeleteEventCommandHandler deleteEventCommandHandler)
        {
            //Information
            @event.EventID = message.EventId;
            eventRepository.Add(@event);
            var actual = eventRepository.GetById(message.EventId);

            //Act
            deleteEventCommandHandler.ExecuteAsync(message);

            //Test
            var expected = eventRepository.GetById(@event.EventID);

            Assert.AreNotEqual(expected, actual);
        }
 public ICommandHandler <DeleteEventCommand, bool> Build(DeleteEventCommand command)
 {
     return(new DeleteEventCommandHandler(_service, command));
 }
Esempio n. 23
0
 public async Task <IActionResult> DeleteEvent(DeleteEventCommand request)
 {
     return(Ok(await _mediator.Send(request)));
 }
 public Task <bool> Handle(DeleteEventCommand request, CancellationToken cancellationToken)
 {
     _eventRepository.Remove(request.EventId);
     _unitOfWork.Commit();
     return(Task.FromResult(true));
 }