public async Task Should_have_notification_when_create_user_returns_failure() { fakeAccountRepository.Setup(x => x.CreateAsync(It.IsAny <Account>(), It.IsAny <string>())) .Returns(Task.FromResult(identityResultFailure)); var handler = new RegisterAccountHandler(fakeAccountRepository.Object); var result = await handler.Handle(command, CancellationToken.None); Assert.True(result.Invalid); Assert.Equal("Erro ao cadastrar o usuário.", result.Message); Assert.NotEmpty(result.Notifications); Assert.IsType <ErrorCommandResponse>(result); }
public async Task should_send_activation_email() { var repos = Substitute.For <IAccountRepository>(); var cmdBus = Substitute.For <ICommandBus>(); var eventBus = Substitute.For <IEventBus>(); var cmd = new RegisterAccount("rne", "yo", "someEmal"); repos.When(x => x.CreateAsync(Arg.Any <Account>())) .Do(x => x.Arg <Account>().SetId(3)); var sut = new RegisterAccountHandler(repos, cmdBus, eventBus); await sut.ExecuteAsync(cmd); await cmdBus.Received().ExecuteAsync(Arg.Any <SendEmail>()); }
public async Task Should_send_activation_email() { var configStore = new TestStore(); var repos = Substitute.For <IAccountRepository>(); var context = Substitute.For <IMessageContext>(); var cmd = new RegisterAccount("rne", "yo", "*****@*****.**"); repos.When(x => x.CreateAsync(Arg.Any <Account>())) .Do(x => x.Arg <Account>().SetId(3)); var sut = new RegisterAccountHandler(repos, configStore); await sut.HandleAsync(context, cmd); await context.Received().SendAsync(Arg.Any <SendEmail>()); }
public async Task Should_not_have_notifications() { fakeAccountRepository.Setup(x => x.CreateAsync(It.IsAny <Account>(), It.IsAny <string>())) .Returns(Task.FromResult(identityResultSuccess)); fakeAccountRepository.Setup(x => x.AddToRoleAsync(It.IsAny <Account>(), It.IsAny <string>())) .Returns(Task.FromResult(identityResultSuccess)); fakeAccountRepository.Setup(x => x.RequireConfirmedAccount()) .Returns(false); var handler = new RegisterAccountHandler(fakeAccountRepository.Object); var result = await handler.Handle(command, CancellationToken.None); Assert.True(result.Valid); Assert.Empty(result.Notifications); Assert.Equal("Usuário cadastrado com sucesso.", result.Message); Assert.IsType <SuccessCommandResponse>(result); }
public async Task Should_create_a_new_account() { ConfigurationStore.Instance = new TestStore(); var repos = Substitute.For <IAccountRepository>(); var cmdBus = Substitute.For <ICommandBus>(); var eventBus = Substitute.For <IEventBus>(); var cmd = new RegisterAccount("rne", "yo", "*****@*****.**"); repos.When(x => x.CreateAsync(Arg.Any <Account>())) .Do(x => x.Arg <Account>().SetId(3)); var sut = new RegisterAccountHandler(repos, cmdBus, eventBus); await sut.ExecuteAsync(cmd); await repos.Received().CreateAsync(Arg.Any <Account>()); }
public async Task should_inform_the_rest_of_the_system_about_the_new_account() { var repos = Substitute.For <IAccountRepository>(); var cmdBus = Substitute.For <ICommandBus>(); var eventBus = Substitute.For <IEventBus>(); var cmd = new RegisterAccount("rne", "yo", "someEmal"); repos.When(x => x.CreateAsync(Arg.Any <Account>())) .Do(x => x.Arg <Account>().SetId(3)); var sut = new RegisterAccountHandler(repos, cmdBus, eventBus); await sut.ExecuteAsync(cmd); await eventBus.Received().PublishAsync(Arg.Any <AccountRegistered>()); eventBus.Method("PublishAsync").Arg <AccountRegistered>().AccountId.Should().Be(3); }
public async Task Should_inform_the_rest_of_the_system_about_the_new_account() { var configStore = new TestStore(); var repos = Substitute.For <IAccountRepository>(); var context = Substitute.For <IMessageContext>(); var cmd = new RegisterAccount("rne", "yo", "*****@*****.**"); repos.When(x => x.CreateAsync(Arg.Any <Account>())) .Do(x => x.Arg <Account>().SetId(3)); var sut = new RegisterAccountHandler(repos, configStore); await sut.HandleAsync(context, cmd); await context.Received().SendAsync(Arg.Any <AccountRegistered>()); context.Method("SendAsync").Arg <AccountRegistered>().AccountId.Should().Be(3); }
public async Task Should_inform_the_rest_of_the_system_about_the_new_account() { ConfigurationStore.Instance = new TestStore(); var repos = Substitute.For <IAccountRepository>(); var cmdBus = Substitute.For <ICommandBus>(); var eventBus = Substitute.For <IEventBus>(); var cmd = new RegisterAccount("rne", "yo", "*****@*****.**"); repos.When(x => x.CreateAsync(Arg.Any <Account>())) .Do(x => x.Arg <Account>().SetId(3)); var sut = new RegisterAccountHandler(repos, cmdBus, eventBus); await sut.ExecuteAsync(cmd); await eventBus.Received().PublishAsync(Arg.Any <AccountRegistered>()); AssertionExtensions.Should((int)eventBus.Method("PublishAsync").Arg <AccountRegistered>().AccountId).Be(3); }