public void Initialize()
 {
     this.requesterSecurity = new Mock <IRequesterSecurity>();
     this.requesterSecurity.SetupFor(Requester);
     this.userManager       = new Mock <IUserManager>(MockBehavior.Strict);
     this.connectionFactory = new Mock <IFifthweekDbConnectionFactory>(MockBehavior.Strict);
     this.target            = new UpdateCreatorAccountSettingsCommandHandler(this.requesterSecurity.Object, this.userManager.Object);
 }
        public async Task ItShouldBeIdempotent()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new UpdateCreatorAccountSettingsCommandHandler(this.requesterSecurity.Object, this.userManager.Object);
                this.requesterSecurity.Setup(v => v.IsInRoleAsync(Requester, FifthweekRole.Creator)).ReturnsAsync(true);

                await this.CreateUserAsync(testDatabase);
                await this.target.HandleAsync(Command);
                await testDatabase.TakeSnapshotAsync();
                await this.target.HandleAsync(Command);

                return(ExpectedSideEffects.None);
            });
        }
        public async Task WhenUserIsNotACreator_ItShouldUpdateSettingsAddTheUserToCreatorRole()
        {
            await this.DatabaseTestAsync(async testDatabase =>
            {
                this.target = new UpdateCreatorAccountSettingsCommandHandler(this.requesterSecurity.Object, this.userManager.Object);

                var expectedUser = await this.CreateUserAsync(testDatabase);
                await testDatabase.TakeSnapshotAsync();

                this.requesterSecurity.Setup(v => v.IsInRoleAsync(Requester, FifthweekRole.Creator)).ReturnsAsync(false);
                this.userManager.Setup(_ => _.AddToRoleAsync(UserId.Value, FifthweekRole.Creator)).ReturnsAsync(new IdentityResult()).Verifiable();

                await this.target.HandleAsync(Command);

                this.userManager.Verify();

                return(ExpectedSideEffects.None);
            });
        }