예제 #1
0
        public async Task Handle_returns_toss_count()
        {
            for (int i = 0; i < 59; i++)
            {
                await _tossCosmosDB.Insert(new TossEntity("test", "test", DateTimeOffset.Now));
            }

            var res = await _mediator.Send(new Toss.Shared.Tosses.TossListAdminQuery(), new System.Threading.CancellationToken());

            Assert.Equal(59, res.Count);
        }
예제 #2
0
        public async Task <Unit> Handle(TossCreateCommand command, CancellationToken cancellationToken)
        {
            TossEntity toss;

            if (!command.SponsoredDisplayedCount.HasValue)
            {
                toss = new TossEntity(
                    command.Content,
                    _httpContextAccessor.HttpContext.User.Identity.Name,
                    DateTimeOffset.Now);
            }
            else
            {
                toss = new SponsoredTossEntity(
                    command.Content,
                    _httpContextAccessor.HttpContext.User.Identity.Name,
                    DateTimeOffset.Now,
                    command.SponsoredDisplayedCount.Value);
            }
            toss.Id = await _dbTemplate.Insert(toss);

            if (command.SponsoredDisplayedCount.HasValue)
            {
                ApplicationUser applicationUser = (await userManager.GetUserAsync(_httpContextAccessor.HttpContext.User));
                var             paymentResult   = await stripeClient.Charge(command.StripeChargeToken, command.SponsoredDisplayedCount.Value *TossCreateCommand.CtsCostPerDisplay, "Payment for sponsored Toss #" + toss.Id, applicationUser.Email);

                if (!paymentResult)
                {
                    await _dbTemplate.Delete(toss.Id);
                }
            }
            return(Unit.Value);
        }
        public async Task Handle_removes_toss()
        {
            await _cosmosDBTemplateEntity.Insert(new TossEntity("test content", "user test", DateTimeOffset.Now));

            await _cosmosDBTemplateEntity.Insert(new TossEntity("test content2", "user test", DateTimeOffset.Now));

            var allInsertedToss = (await _cosmosDBTemplateEntity.CreateDocumentQuery()).ToList();

            await _mediator.Send(new DeleteTossCommand(allInsertedToss.First().Id));


            var allRemaining = (await _cosmosDBTemplateEntity.CreateDocumentQuery()).ToList();

            Assert.Single(allRemaining);
            Assert.Null(allRemaining.FirstOrDefault(t => t.Id == allInsertedToss.First().Id));
        }
예제 #4
0
        public async Task last_returns_last_items_from_table_ordered_desc_by_createdon()
        {
            for (int i = 0; i < 60; i++)
            {
                await tossTemplate.Insert(new TossEntity()
                {
                    Content   = "lorem #ipsum",
                    CreatedOn = new DateTime(2017, 12, 31).AddDays(-i),
                    UserName  = "******"
                });
            }

            var res = await _sut.Handle(new Toss.Shared.Tosses.TossLastQuery("ipsum"), new System.Threading.CancellationToken());

            Assert.Equal(50, res.Count());
            Assert.Null(res.FirstOrDefault(r => r.CreatedOn < new DateTime(2017, 12, 31).AddDays(-50)));
        }
예제 #5
0
        public async Task <Unit> Handle(TossCreateCommand command, CancellationToken cancellationToken)
        {
            var toss = new TossEntity(
                command.Content,
                _httpContextAccessor.HttpContext.User.Identity.Name,
                DateTimeOffset.Now);

            await _dbTemplate.Insert(toss);

            return(Unit.Value);
        }
예제 #6
0
        public async Task <Unit> Handle(TossCreateCommand command, CancellationToken cancellationToken)
        {
            TossEntity toss;
            var        user = _httpContextAccessor.HttpContext.User;

            if (!command.SponsoredDisplayedCount.HasValue)
            {
                toss = new TossEntity(
                    command.Content,
                    user.UserId(),
                    DateTimeOffset.Now);
            }
            else
            {
                toss = new SponsoredTossEntity(
                    command.Content,
                    user.UserId(),
                    DateTimeOffset.Now,
                    command.SponsoredDisplayedCount.Value);
            }
            toss.UserName = user.Identity.Name;
            toss.Id       = await _dbTemplate.Insert(toss);

            if (command.SponsoredDisplayedCount.HasValue)
            {
                ApplicationUser applicationUser = (await userManager.GetUserAsync(user));
                var             paymentResult   = await stripeClient.Charge(command.StripeChargeToken, command.SponsoredDisplayedCount.Value *TossCreateCommand.CtsCostPerDisplay, "Payment for sponsored Toss #" + toss.Id, applicationUser.Email);

                if (!paymentResult)
                {
                    await _dbTemplate.Delete(toss.Id);

                    throw new InvalidOperationException("Payment error on sponsored Toss ");
                }
            }
            await mediator.Publish(new TossCreated(toss.Id));

            return(Unit.Value);
        }