public async Task When_UserHasEnoughSmsLimit_SmsEventIsPushed() { using var testServer = await CreateWithUserAsync(); var user = await testServer.GetCurrentUserInSession(); var client = testServer.CreateClient(); var addSmsCreditsCommand = new AddSmsCreditsCommand(Guid.NewGuid(), user.Id, 2, false); await client.PostAsync($"{ApiPath}/add-credits", addSmsCreditsCommand.ToJsonContent()); var messages = new List <SmsMessageModel>(); for (var i = 0; i < 2; i++) { messages.Add(new SmsMessageModel("5544567788", "TEST", "TEST")); } var command = new SendSmsCommand(Guid.NewGuid(), messages); var response = await client.PostAsync(ApiPath, command.ToJsonContent()); response.EnsureSuccessStatusCode(); var @event = Consumer.Instance.GetFirst <ISendSmsRequestReceived>(); @event.UserId.Should().NotBe(default);
public async Task ShouldAddCredits() { var testServer = await GetTestServer(); var client = testServer.CreateClient(); var model = await CreateUserAsync(client); var additionAmount = RandomGen.Next(1000); var response = await client.GetAsync($"api/v1/users/{model.Email}"); var user = await response.ReadAsync <Domain.Model.UserModel.User>(); var command = new AddSmsCreditsCommand(Guid.NewGuid(), (int)user.Id, additionAmount, true); response = await client.PostAsync($"{ApiPath}", command.ToJsonContent()); response.EnsureSuccessStatusCode(); response = await client.GetAsync($"api/v1/users/{model.Email}"); user = await response.ReadAsync <Domain.Model.UserModel.User>(); user.SmsBalance.Should().Be(additionAmount); Consumer.Instance.GetAll <ISmsCreditAdded>() .Should().Contain(x => x.Amount == command.Amount && x.Email == user.Email && x.Phone == user.Phone); }
public async Task ShouldAddCredits() { using (var testServer = await CreateAsync()) { var client = testServer.CreateClient(); var model = await CreateUserAsync(client, testServer.Host.Services); var additionAmount = RandomGen.Next(1000); var response = await client.GetAsync($"api/v1/users/{model.Email}"); var user = await response.ReadAsync <Domain.Model.UserModel.User>(); var command = new AddSmsCreditsCommand(Guid.NewGuid(), (int)user.Id, additionAmount); response = await client.PostAsync($"{ApiPath}", command.ToJsonContent()); response.EnsureSuccessStatusCode(); response = await client.GetAsync($"api/v1/users/{model.Email}"); user = await response.ReadAsync <Domain.Model.UserModel.User>(); user.SmsBalance.Should().Be(additionAmount); } }
public async Task <IActionResult> AddSmsCreditsAsync([FromBody, Required] AddSmsCreditsCommand command) { await _commandProcessor.SendAsync(command); return(Ok()); }