コード例 #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);
        }
コード例 #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" }));
        }
コード例 #3
0
        public async Task <IActionResult> Delete(int id)
        {
            var command = new DeleteNotificationCommand(id);
            var result  = await _mediatr.Send(command);

            return(Ok(result));
        }
コード例 #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>()));
        }
コード例 #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>()));
        }
コード例 #6
0
 public void Handle(ICommandContext context, DeleteNotificationCommand command)
 {
     context.Get <Notification>(command.AggregateRootId).Delete();
 }
コード例 #7
0
        public async Task <IActionResult> Delete(DeleteNotificationCommand command)
        {
            await this.Mediator.Send(command);

            return(this.Ok());
        }