public void Can_update_wallet_template() { var walletViewModel = new WalletTemplateViewModel { BrandId = _brandId, MainWallet = new WalletViewModel { Name = "Main wallet", IsMain = true, ProductIds = new Guid[0] } }; _brandCommands.CreateWalletStructureForBrand(walletViewModel); Assert.True(_brandQueries.GetWalletTemplates(_brandId).Any()); var wallets = _brandQueries.GetWalletTemplates(_brandId); walletViewModel.MainWallet.Id = wallets.First(x => x.IsMain).Id; walletViewModel.MainWallet.Name = "NewName"; _brandCommands.UpdateWalletStructureForBrand(walletViewModel); var updatedWallet = _brandQueries.GetWalletTemplates(_brandId).First(x => x.IsMain); Assert.AreEqual(updatedWallet.Name, "NewName"); Assert.AreEqual(updatedWallet.UpdatedBy, _actorInfoProvider.Actor.Id); }
public void Can_not_create_wallets_with_empty_names() { var walletViewModel = new WalletTemplateViewModel { BrandId = _brandId, MainWallet = new WalletViewModel { Name = "", IsMain = true, ProductIds = new Guid[0] }, ProductWallets = new List <WalletViewModel> { new WalletViewModel { Name = "", IsMain = false, ProductIds = new[] { _fakeGameRepository.GameProviders.First().Id } } } }; Assert.Throws <RegoValidationException>( () => _brandCommands.CreateWalletStructureForBrand(walletViewModel)); var wallets = _brandQueries.GetWalletTemplates(_brandId); Assert.IsNotNull(wallets); Assert.IsEmpty(wallets); }
public void Can_create_product_wallets() { var walletViewModel = new WalletTemplateViewModel { BrandId = _brandId, MainWallet = new WalletViewModel { Name = "Main wallet", IsMain = true, ProductIds = new Guid[0] }, ProductWallets = new List <WalletViewModel> { new WalletViewModel { Name = "Product wallet", IsMain = false, ProductIds = new[] { _fakeGameRepository.GameProviders.First().Id } } } }; _brandCommands.CreateWalletStructureForBrand(walletViewModel); var wallets = _brandQueries.GetWalletTemplates(_brandId).ToList(); Assert.IsNotNull(wallets); Assert.IsNotEmpty(wallets); Assert.IsTrue(wallets.Count(x => x.IsMain) == 1); Assert.IsTrue(wallets.Count(x => !x.IsMain) == 1); Assert.IsTrue(wallets.First(x => !x.IsMain).WalletTemplateProducts.Count == 1); }
public ActionResult Wallet(WalletTemplateViewModel model) { // In R1.0 we will not have wallets return(this.Failed(new NotImplementedException("In R1.0 we will not have wallets"))); /* * try * { * var message = String.Empty; * if (model.MainWallet.Id == null || model.MainWallet.Id == Guid.Empty) * { * _brandCommands.CreateWalletStructureForBrand(model); * message = "app:wallet.common.created"; * } * else * { * _brandCommands.UpdateWalletStructureForBrand(model); * message = "app:wallet.common.updated"; * } * return this.Success(message); * } * catch (ValidationError e) * { * return this.Failed(e); * } * catch(Exception e) * { * return this.Failed(e); * } */ }
public void UpdateWalletStructureForBrand(WalletTemplateViewModel viewModel) { TransformToOneWalletModel(viewModel); var validationResult = new EditWalletValidator().Validate(viewModel); if (!validationResult.IsValid) { throw new RegoValidationException(validationResult); } var brand = _repository.Brands.Single(x => x.Id == viewModel.BrandId); var existingWallets = _repository .WalletTemplates .Include(x => x.Brand) .Where(x => x.Brand.Id == viewModel.BrandId && !x.IsMain) .ToArray(); var walletTemplatesToDelete = existingWallets.Where(x => viewModel.ProductWallets.All(y => y.Id != x.Id)).ToArray(); walletTemplatesToDelete.ForEach(x => _repository.WalletTemplates.Remove(x)); var remainedWallets = viewModel.ProductWallets.Where(x => x.Id != null && x.Id != Guid.Empty).ToArray(); remainedWallets = remainedWallets.Concat(new[] { viewModel.MainWallet }).ToArray(); remainedWallets.ForEach(rw => UpdateWalletTemplate(viewModel.BrandId, rw)); var newWallets = viewModel.ProductWallets.Where(x => x.Id == null || x.Id == Guid.Empty).ToArray(); newWallets.ForEach(x => { var walleTemplate = CreateWalletTemplate(viewModel.BrandId, x.Name, x.ProductIds, false); x.Id = walleTemplate.Id; }); _repository.SaveChanges(); _eventBus.Publish(new WalletTemplateUpdated { BrandId = viewModel.BrandId, RemovedWalletTemplateIds = walletTemplatesToDelete.Select(x => x.Id).ToArray(), RemainedWalletTemplates = remainedWallets.Select(x => new WalletTemplateDto { Id = x.Id.Value, IsMain = x.IsMain, Name = x.Name, ProductIds = x.ProductIds.ToArray() }).ToArray(), NewWalletTemplates = newWallets.Select(x => new WalletTemplateDto { Id = x.Id.Value, IsMain = x.IsMain, Name = x.Name, ProductIds = x.ProductIds.ToArray() }).ToArray(), EventCreated = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId), }); }
// AZ / UGS-INTEGRATION / AFTREGO-4132 // Working with multiple wallets are not supported in first release. // This operations are required until UGS will not implement multi-wallets functionality // It assign all products to main wallet and clears product wallets preventing its creation private void TransformToOneWalletModel(WalletTemplateViewModel model) { if (model.ProductWallets == null) { return; } model.MainWallet.ProductIds = model.ProductWallets.SelectMany(x => x.ProductIds) .Union(model.MainWallet.ProductIds) .Distinct() .ToList(); model.ProductWallets.Clear(); }
public void CreateWalletStructureForBrand(WalletTemplateViewModel viewModel) { TransformToOneWalletModel(viewModel); var validationResult = new AddWalletValidator() .Validate(viewModel); if (!validationResult.IsValid) { throw new RegoValidationException(validationResult); } var brand = _repository.Brands.Single(x => x.Id == viewModel.BrandId); using (var scope = CustomTransactionScope.GetTransactionScope()) { var wallets = new List <WalletTemplate>(); wallets.Add(CreateWalletTemplate( viewModel.BrandId, viewModel.MainWallet.Name, viewModel.MainWallet.ProductIds, true)); foreach (var walletViewModel in viewModel.ProductWallets) { wallets.Add(CreateWalletTemplate( viewModel.BrandId, walletViewModel.Name, walletViewModel.ProductIds, false)); } _repository.SaveChanges(); _eventBus.Publish(new WalletTemplateCreated { BrandId = viewModel.BrandId, WalletTemplates = wallets.Select(x => new WalletTemplateDto { Id = x.Id, IsMain = x.IsMain, Name = x.Name, ProductIds = x.WalletTemplateProducts.Select(wt => wt.ProductId).ToArray() }).ToArray(), EventCreated = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId), }); scope.Complete(); } }
public void Can_create_wallet_template() { var walletViewModel = new WalletTemplateViewModel { BrandId = _brandId, MainWallet = new WalletViewModel { Name = "Main wallet", IsMain = true, ProductIds = new Guid[0] } }; _brandCommands.CreateWalletStructureForBrand(walletViewModel); Assert.True(_brandQueries.GetWalletTemplates(_brandId).Any()); }
public void Can_create_wallet_template_with_main_wallet_products() { var walletViewModel = new WalletTemplateViewModel { BrandId = _brandId, MainWallet = new WalletViewModel { Name = "Main wallet", IsMain = true, ProductIds = new[] { _fakeGameRepository.GameProviders.First().Id } } }; _brandCommands.CreateWalletStructureForBrand(walletViewModel); var walletTemplate = _brandQueries.GetWalletTemplates(_brandId).First(x => x.IsMain); Assert.IsNotNull(walletTemplate.WalletTemplateProducts); Assert.IsNotEmpty(walletTemplate.WalletTemplateProducts); Assert.AreEqual(walletTemplate.WalletTemplateProducts.Count(), 1); Assert.AreEqual(walletTemplate.WalletTemplateProducts.First().ProductId, _fakeGameRepository.GameProviders.First().Id); }