Esempio n. 1
0
 private async Task InitializeTarget(IFifthweekDbConnectionFactory testDatabase)
 {
     this.target = new CreateBlogCommandHandler(
         this.blogSecurity.Object,
         this.requesterSecurity.Object,
         testDatabase,
         this.requestSnapshotService);
 }
Esempio n. 2
0
        public async Task WhenUnauthenticated_ItShouldThrowUnauthorizedException()
        {
            // Give side-effecting components strict mock behaviour.
            var connectionFactory = new Mock <IFifthweekDbConnectionFactory>(MockBehavior.Strict);

            this.target = new CreateBlogCommandHandler(this.blogSecurity.Object, this.requesterSecurity.Object, connectionFactory.Object, this.requestSnapshotService);

            await this.target.HandleAsync(new CreateBlogCommand(Requester.Unauthenticated, BlogId, FirstChannelId, BlogName, BasePrice));
        }
Esempio n. 3
0
        public async Task WhenReRun_ItShouldHaveNoEffect()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new CreateBlogCommandHandler(this.blogSecurity.Object, this.requesterSecurity.Object, testDatabase, this.requestSnapshotService);
                await this.CreateUserAsync(UserId, testDatabase);
                await this.target.HandleAsync(Command);
                await testDatabase.TakeSnapshotAsync();

                await this.target.HandleAsync(Command);

                return(ExpectedSideEffects.None);
            });
        }
Esempio n. 4
0
        public async Task WhenNotAllowedToCreate_ItShouldReportAnError()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.blogSecurity.Setup(_ => _.AssertCreationAllowedAsync(Requester)).Throws <UnauthorizedException>();
                this.target = new CreateBlogCommandHandler(this.blogSecurity.Object, this.requesterSecurity.Object, testDatabase, this.requestSnapshotService);
                await testDatabase.TakeSnapshotAsync();

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

                await badMethodCall.AssertExceptionAsync <UnauthorizedException>();

                return(ExpectedSideEffects.None);
            });
        }
Esempio n. 5
0
        public void Should_call_validate_command_when_create_new_blog()
        {
            var blog    = Domain.Blog.Blog.CreateNew("Title");
            var command = new CreateBlogCommand(blog.Title);

            var blogRepository = new Mock <IBlogRepository>();

            var validator = new Mock <IValidator <CreateBlogCommand> >();

            validator.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            var createBlogCommandHandler = new CreateBlogCommandHandler(blogRepository.Object, validator.Object);

            createBlogCommandHandler.Handle(command);

            validator.Verify(x => x.Validate(command));
        }