Beispiel #1
0
        public async Task Handle_GivenValidRequest_ShouldReturnViewModel()
        {
            // Arrange
            var notification = new Notification {
                PlayerId = "Foo1", Content = "TestContent", Header = "TestHeader", Type = Domain.Entities.Enums.NotificationType.Info
            };

            this.dbContext.Add(notification);
            this.dbContext.SaveChanges();
            this.dbContext.ChangeTracker.Entries().ToList().ForEach(x => x.State = Microsoft.EntityFrameworkCore.EntityState.Detached);

            var userAccessorMock = new Mock <IUserAccessor>();

            userAccessorMock.Setup(x => x.UserId).Returns("Foo1");

            var command = new DeleteNotificationCommand {
                Id = notification.Id
            };
            var sut = new DeleteNotificationCommandHandler(this.deletableEntityRepository, userAccessorMock.Object);

            // Act
            var id = await sut.Handle(command, It.IsAny <CancellationToken>());

            // Assert
            id.ShouldNotBeEmpty();

            var notificationDeleted = dbContext.Notifications.SingleOrDefault();

            notificationDeleted.IsDeleted.ShouldBe(true);
        }
Beispiel #2
0
        public async Task <IActionResult> DeleteById(int id)
        {
            var notif  = new DeleteNotificationCommand(id);
            var result = await _mediatr.Send(notif);

            return(result != null ? (IActionResult)Ok(new { Message = "success" }) : NotFound(new { Message = "Notification not found" }));
        }
        public async Task <IActionResult> Delete(int id)
        {
            var command = new DeleteNotificationCommand(id);
            var result  = await _mediatr.Send(command);

            return(Ok(result));
        }
Beispiel #4
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowNotFoundException()
        {
            // Arrange
            var userAccessorMock = new Mock <IUserAccessor>();

            userAccessorMock.Setup(x => x.UserId).Returns("Foo1");

            var command = new DeleteNotificationCommand {
                Id = "InvalidId"
            };
            var sut = new DeleteNotificationCommandHandler(this.deletableEntityRepository, userAccessorMock.Object);

            // Act & Assert
            await Should.ThrowAsync <NotFoundException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
Beispiel #5
0
        public async Task Handle_GivenInvalidRequest_ShouldThrowDeleteFailureException()
        {
            // Arrange
            var notification = new Notification {
                PlayerId = "Foo1", Content = "TestContent", Header = "TestHeader", Type = Domain.Entities.Enums.NotificationType.Info
            };

            this.dbContext.Add(notification);
            this.dbContext.SaveChanges();

            var userAccessorMock = new Mock <IUserAccessor>();

            userAccessorMock.Setup(x => x.UserId).Returns("Foo2");

            var command = new DeleteNotificationCommand {
                Id = notification.Id
            };
            var sut = new DeleteNotificationCommandHandler(this.deletableEntityRepository, userAccessorMock.Object);

            // Act & Assert
            await Should.ThrowAsync <DeleteFailureException>(sut.Handle(command, It.IsAny <CancellationToken>()));
        }
 public void Handle(ICommandContext context, DeleteNotificationCommand command)
 {
     context.Get <Notification>(command.AggregateRootId).Delete();
 }
Beispiel #7
0
        public async Task <IActionResult> Delete(DeleteNotificationCommand command)
        {
            await this.Mediator.Send(command);

            return(this.Ok());
        }