Пример #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 Handle_GivenNullRequest_ShouldThrowArgumentNullException()
        {
            // Arrange
            var sut = new DeleteNotificationCommandHandler(It.IsAny <IDeletableEntityRepository <Notification> >(), It.IsAny <IUserAccessor>());

            // Act & Assert
            await Should.ThrowAsync <ArgumentNullException>(sut.Handle(null, It.IsAny <CancellationToken>()));
        }
Пример #3
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>()));
        }
Пример #4
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>()));
        }