public async Task create_return_ok_if_valid() { var command = new TossCreateCommand() { Content = "lorem ipsum lorem ipsum lorem ipsum lorem ipsum" }; var res = await _sut.Create(command); Assert.IsType <OkResult>(res); }
public async Task create_calls_mediator_with_command() { var command = new TossCreateCommand() { Content = "lorem ipsum lorem ipsum lorem ipsum lorem ipsum" }; var res = await _sut.Create(command); _m.Mediator.Verify(r => r.Send(command, It.IsAny <CancellationToken>())); }
public async Task create_setup_username_to_current_user() { var command = new TossCreateCommand() { Content = "lorem ipsum lorem ipsum lorem ipsum lorem ipsum" }; var res = await _sut.Handle(command, new System.Threading.CancellationToken()); var toss = await(await tossTemplate.CreateDocumentQuery()).GetFirstOrDefault(); Assert.Equal(_m.ApplicationUser.UserName, toss.UserName); }
public void can_send_toss_with_new_line() { var res = new List <ValidationResult>(); var sut = new TossCreateCommand() { Content = @"lorem ipsum lrorem peozeproizeri zerizeporizop eir zerzerezr #toto" }; bool isValid = ValidationHelper.IsValid(res, sut); Assert.True(isValid); }
public async Task create_insert_item_in_cosmos() { var command = new TossCreateCommand() { Content = "lorem ipsum" }; await _sut.Handle(command, new System.Threading.CancellationToken()); var toss = await(await tossTemplate.CreateDocumentQuery()).GetFirstOrDefault(); Assert.NotNull(toss); Assert.Equal("lorem ipsum", toss.Content); }
public async Task create_setup_date_of_post_to_today() { var command = new TossCreateCommand() { Content = "lorem ipsum lorem ipsum lorem ipsum lorem ipsum" }; var now = DateTimeOffset.Now.AddMinutes(-1); var res = await _sut.Handle(command, new System.Threading.CancellationToken()); var now2 = DateTimeOffset.Now.AddMinutes(1); var toss = await(await tossTemplate.CreateDocumentQuery()).GetFirstOrDefault(); Assert.True(toss.CreatedOn >= now && toss.CreatedOn <= now2); }
public void invalid_if_length_over_32000() { var res = new List <ValidationResult>(); var sut = new TossCreateCommand() { Content = string.Join("", Enumerable.Range(0, 3201).Select(i => "lorem #psu")) }; Assert.Equal(32010, sut.Content.Length); bool isValid = ValidationHelper.IsValid(res, sut); Assert.False(isValid); Assert.Contains(res, r => r.MemberNames.Contains("Content")); }
public async Task returns_details_of_single_toss() { TossCreateCommand request = new TossCreateCommand() { Content = "lalalaalalalam z emlazek amzk mlekmzalkazmel zaml azme #test" }; await _mediator.Send(request); var lastToss = await _mediator.Send(new TossLastQuery("test")); var res = await _mediator.Send(new TossDetailQuery(lastToss.First().Id)); Assert.Equal(request.Content, res.Content); Assert.Equal(lastToss.First().CreatedOn, res.CreatedOn); Assert.Equal(lastToss.First().UserName, res.UserName); }
public async Task create_when_payment_fails_delete_toss_throw_error() { var command = new TossCreateCommand() { Content = "lorem ipsum", SponsoredDisplayedCount = 1000, StripeChargeToken = "AAA" }; _mockStripe.Setup(m => m.Charge(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(Task.FromResult(false)); await _sut.Handle(command, new System.Threading.CancellationToken()); var toss = await(await tossTemplate.CreateDocumentQuery()).GetFirstOrDefault(); Assert.Null(toss); }
public async Task create_when_sponsored_payment_succeed_return_ok() { var command = new TossCreateCommand() { Content = "lorem ipsum", SponsoredDisplayedCount = 1000, StripeChargeToken = "AAA" }; _mockStripe.Setup(m => m.Charge(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(Task.FromResult(true)); await _sut.Handle(command, new System.Threading.CancellationToken()); var toss = await(await tossTemplate.CreateDocumentQuery()).GetFirstOrDefault(); _mockStripe.Verify(m => m.Charge("AAA", command.SponsoredDisplayedCount.Value * TossCreateCommand.CtsCostPerDisplay, It.Is <string>(s => s.Contains(toss.Id)), _m.ApplicationUser.Email)); }
public async Task create_when_display_count_creates_SponsoredToss() { var command = new TossCreateCommand() { Content = "lorem ipsum", SponsoredDisplayedCount = 1000 }; _mockStripe.Setup(m => m.Charge(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(Task.FromResult(true)); await _sut.Handle(command, new System.Threading.CancellationToken()); var toss = await(await tossTemplate.CreateDocumentQuery()).GetFirstOrDefault(); Assert.NotNull(toss); var sponsored = Assert.IsAssignableFrom <SponsoredTossEntity>(toss); Assert.Equal(1000, sponsored.DisplayedCount); Assert.Equal(1000, sponsored.DisplayedCountBought); }
public void cannot_send_toss_without_hashtag() { var res = new List <ValidationResult>(); var sut = new TossCreateCommand() { Content = "lorem ipsum lrorem peozeproizeri zerizeporizop eir " }; bool isValid = ValidationHelper.IsValid(res, sut); Assert.False(isValid); sut = new TossCreateCommand() { Content = "lorem ipsum #lrorem peozeproizeri zerizeporizop eir " }; isValid = ValidationHelper.IsValid(res, sut); Assert.True(isValid); }
public async Task <IActionResult> Create([FromBody] TossCreateCommand createTossCommand) { await _mediator.Send(createTossCommand); return(Ok()); }