public async Task WhenNoHeaderImage_ItShouldUpdateBlog()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new UpdateBlogCommandHandler(this.blogSecurity.Object, this.fileSecurity.Object, this.requesterSecurity.Object, testDatabase);
                var blog    = await this.CreateBlogAsync(UserId, BlogId, testDatabase);
                await testDatabase.TakeSnapshotAsync();

                await this.target.HandleAsync(CommandWithoutHeaderImage);

                var expectedBlog = new Blog(
                    BlogId.Value,
                    UserId.Value,
                    null,
                    BlogName.Value,
                    Introduction.Value,
                    Description.Value,
                    Video.Value,
                    null,
                    null,
                    blog.CreationDate);

                return(new ExpectedSideEffects
                {
                    Update = expectedBlog
                });
            });
        }
        public async Task WhenReRun_ItShouldHaveNoEffect()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new UpdateBlogCommandHandler(this.blogSecurity.Object, this.fileSecurity.Object, this.requesterSecurity.Object, testDatabase);
                await this.CreateBlogAsync(UserId, BlogId, testDatabase);
                await this.target.HandleAsync(Command);
                await testDatabase.TakeSnapshotAsync();

                await this.target.HandleAsync(Command);

                return(ExpectedSideEffects.None);
            });
        }
        public async Task WhenNotAllowedToUseFile_ItShouldReportAnError()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.fileSecurity.Setup(_ => _.AssertReferenceAllowedAsync(UserId, HeaderImageFileId)).Throws <UnauthorizedException>();
                this.target = new UpdateBlogCommandHandler(this.blogSecurity.Object, this.fileSecurity.Object, this.requesterSecurity.Object, testDatabase);
                await testDatabase.TakeSnapshotAsync();

                Func <Task> badMethodCall = () => this.target.HandleAsync(Command);

                await badMethodCall.AssertExceptionAsync <UnauthorizedException>();

                return(ExpectedSideEffects.None);
            });
        }
        public async Task WhenUnauthenticated_ItShouldThrowUnauthorizedException()
        {
            // Give side-effecting components strict mock behaviour.
            var connectionFactory = new Mock <IFifthweekDbConnectionFactory>(MockBehavior.Strict);

            this.target = new UpdateBlogCommandHandler(this.blogSecurity.Object, this.fileSecurity.Object, this.requesterSecurity.Object, connectionFactory.Object);

            await this.target.HandleAsync(new UpdateBlogCommand(
                                              Requester.Unauthenticated,
                                              BlogId,
                                              BlogName,
                                              Introduction,
                                              Description,
                                              HeaderImageFileId,
                                              Video));
        }