Exemplo n.º 1
0
        public async Task <AddSerialSlotResult> AddSerialSlot(AddSerialSlotRequest request)
        {
            var user = await database.UserRepository.FindById(httpContextReader.CurrentUserId) ??
                       throw new EntityNotFoundException("User not found");

            user.IncreaseSerialsLimit(request.Amount);

            using (var transaction = database.BeginTransaction().Transaction)
            {
                if (!await database.UserRepository.Update(user))
                {
                    throw new PremiumOperationException(
                              "Adding serial slot failed");
                }

                if (await purchaseService.CreatePurchase(PremiumConstants.AddSerialSlot,
                                                         httpContextReader.CurrentUserId, request.Amount * PremiumConstants.AddSerialSlotCost) == null)
                {
                    throw new PremiumOperationException(
                              "Adding serial slot failed");
                }

                transaction.Complete();
            }

            return(new AddSerialSlotResult(true, user.SerialsLimit));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddSerialSlot([FromForm] AddSerialSlotRequest request)
        {
            var response = await mediator.Send(request);

            Log.Information(
                $"User #{HttpContext.GetCurrentUserId()} added {request.Amount} serial slots to their account");

            return(this.CreateResponse(response));
        }
        public void SetUp()
        {
            request = new AddSerialSlotRequest();

            premiumAccountManager = new Mock <IPremiumAccountManager>();
            premiumCreditsDatabaseRestorePoint = new Mock <IPremiumCreditsDatabaseRestorePoint>();
            httpContextReader = new Mock <IHttpContextReader>();

            premiumAccountManager.Setup(p => p.AddSerialSlot(request)).ReturnsAsync(new AddSerialSlotResult(true, 2));
            premiumCreditsDatabaseRestorePoint.Setup(pcd =>
                                                     pcd.CreateRestoreParams(It.IsAny <IDatabaseRestoreParams>())
                                                     .EnqueueToConnectionDatabaseRestorePoints(It.IsAny <string>()))
            .Returns(premiumCreditsDatabaseRestorePoint.Object);

            addSerialSlotCommand = new AddSerialSlotCommand(premiumAccountManager.Object,
                                                            premiumCreditsDatabaseRestorePoint.Object, httpContextReader.Object);
        }
        public void SetUp()
        {
            estate = new Estate();
            var user = new User();

            sourceCharacter = new Character();
            targetCharacter = new Character();
            user.Characters.Add(new TestCharacter().SetEstate(estate));
            user.Characters.Add(sourceCharacter);
            user.Characters.Add(targetCharacter);

            file = new FormFile(new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")), 0, 0, "Data",
                                "dummy.txt");

            addObjectProtectionRequest = new AddObjectProtectionRequest
            {
                ProtectionType = ObjectProtectionType.Estate,
                ObjectId       = estate.Id,
                Amount         = 1
            };

            addSerialSlotRequest = new AddSerialSlotRequest
            {
                Amount = 1
            };

            var characters = new List <Character>
            {
                new TestCharacter().SetEstate(estate),
                new TestCharacter()
            };

            database                  = new Mock <IDatabase>();
            characterService          = new Mock <ICharacterService>();
            userService               = new Mock <IUserService>();
            purchaseService           = new Mock <IPurchaseService>();
            adminActionService        = new Mock <IAdminActionService>();
            emailSender               = new Mock <IEmailSender>();
            mtaManager                = new Mock <IMtaManager>();
            orderService              = new Mock <IOrderService>();
            premiumUserLibraryManager = new Mock <IPremiumUserLibraryManager>();
            tempDatabaseCleaner       = new Mock <ITempDatabaseCleaner>();
            filesManager              = new Mock <IFilesManager>();
            customInteriorManager     = new Mock <ICustomInteriorManager>();
            httpContextReader         = new Mock <IHttpContextReader>();

            database.Setup(d => d.CharacterRepository.GetAccountCharactersWithEstatesAndVehicles(It.IsAny <int>()))
            .ReturnsAsync(characters);
            database.Setup(d => d.BeginTransaction()).Returns(new DatabaseTransaction());
            database.Setup(d => d.EstateRepository.Update(It.IsNotNull <Estate>())).ReturnsAsync(true);
            database.Setup(d => d.UserRepository.FindById(It.IsAny <int>())).ReturnsAsync(user);
            database.Setup(d => d.UserRepository.Update(It.IsAny <User>())).ReturnsAsync(true);
            database.Setup(d => d.CharacterRepository.Find(It.IsAny <string>()))
            .ReturnsAsync(new Character());
            userService.Setup(us => us.GetUserWithCharacters(It.IsAny <int>())).ReturnsAsync(user);
            characterService.Setup(cs => cs.HasAnyCharacterEstate(It.IsAny <IEnumerable <Character> >(), It.IsAny <int>()))
            .ReturnsAsync(estate);
            purchaseService.Setup(ps => ps.CreatePurchase(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()))
            .ReturnsAsync(new Purchase());
            orderService.Setup(os => os.CreateOrder(It.IsAny <Order>())).ReturnsAsync(new Order());
            premiumUserLibraryManager.Setup(pm => pm.AddFileToLibrary(It.IsAny <IFormFile>(),
                                                                      It.IsAny <PremiumFileType>(), It.IsAny <string>(), It.IsAny <int?>()))
            .ReturnsAsync(new PremiumFile());
            SetUpDefaultExecuteTransferCharacter();

            premiumAccountManager = new PremiumAccountManager(database.Object, characterService.Object,
                                                              userService.Object, purchaseService.Object, adminActionService.Object, emailSender.Object,
                                                              mtaManager.Object, orderService.Object, premiumUserLibraryManager.Object, tempDatabaseCleaner.Object,
                                                              filesManager.Object, customInteriorManager.Object, httpContextReader.Object);
        }