public override Empty CreateNativeToken(CreateNativeTokenInput input) { Assert(string.IsNullOrEmpty(State.NativeTokenSymbol.Value), "Native token already created."); State.NativeTokenSymbol.Value = input.Symbol; State.BasicContractZero.Value = Context.GetZeroSmartContractAddress(); var whiteList = new List <Address>(); foreach (var systemContractName in input.LockWhiteSystemContractNameList) { var address = State.BasicContractZero.GetContractAddressByName.Call(systemContractName); whiteList.Add(address); } var createInput = new CreateInput { Symbol = input.Symbol, TokenName = input.TokenName, TotalSupply = input.TotalSupply, Issuer = input.Issuer, Decimals = input.Decimals, IsBurnable = true, LockWhiteList = { whiteList } }; return(Create(createInput)); }
public void ProductDoesNotExist_ShouldThrowExpectedException() { // Arrange _customerRepository .Setup(repository => repository.GetById(It.IsAny <Guid>())) .Returns(new Customer()); _productRepository .Setup(repository => repository.Exists(It.IsAny <Guid>())) .Returns(false); var sut = GetSut(); var productId = Guid.NewGuid(); var productIdQuantityDictionary = new Dictionary <Guid, int> { { productId, 1 } }; var input = new CreateInput(Guid.NewGuid(), productIdQuantityDictionary); // Act Action action = () => sut.Execute(input); // Assert action .Should() .Throw <ProductNotFoundException>() .WithMessage($"{typeof(CreateUseCase)}: Product with id: {productId}, does not exist."); }
public CreateOutput <GameTaskTypeDto, long> Create(CreateInput <GameTaskTypeDto, long> input) { throw new NotSupportedException("This method is implemented but it is not safely to use it."); GameTaskType newGameTaskTypeEntity = input.Entity.MapTo <GameTaskType>(); newGameTaskTypeEntity.IsDefault = false; newGameTaskTypeEntity.IsActive = true; if (!GameTaskTypePolicy.CanCreateEntity(newGameTaskTypeEntity)) { throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionCreateDenied, "\"GameTaskType\""); } GameTaskTypeRepository.Includes.Add(r => r.LastModifierUser); GameTaskTypeRepository.Includes.Add(r => r.CreatorUser); GameTaskTypeDto newGameTaskTypeDto = (GameTaskTypeRepository.Insert(newGameTaskTypeEntity)).MapTo <GameTaskTypeDto>(); GameTaskTypeRepository.Includes.Clear(); return(new CreateOutput <GameTaskTypeDto, long>() { CreatedEntity = newGameTaskTypeDto }); }
public async Task <Hash> Create_Proposal() { _organizationAddress = await Create_Organization(); _createInput = new CreateInput() { Symbol = "NEW", Decimals = 2, TotalSupply = 10_0000, TokenName = "new token", Issuer = _organizationAddress, IsBurnable = true }; _createProposalInput = new CreateProposalInput { ContractMethodName = nameof(TokenContract.Create), ToAddress = TokenContractAddress, Params = _createInput.ToByteString(), ExpiredTime = BlockTimeProvider.GetBlockTime().AddDays(2).ToTimestamp(), OrganizationAddress = _organizationAddress }; var proposal = await ReferendumAuthContractStub.CreateProposal.SendAsync(_createProposalInput); proposal.TransactionResult.Status.ShouldBe(TransactionResultStatus.Mined); return(proposal.Output); }
public override Empty CrossChainCreateToken(CrossChainCreateTokenInput input) { var parentChainId = GetValidCrossChainContractReferenceState().GetParentChainId.Call(new Empty()).Value; var tokenContractAddress = State.CrossChainTransferWhiteList[parentChainId]; Assert(tokenContractAddress != null, "Token contract address of parent chain not found."); var originalTransaction = Transaction.Parser.ParseFrom(input.TransactionBytes); AssertCrossChainTransaction(originalTransaction, tokenContractAddress, nameof(Create)); var originalTransactionId = originalTransaction.GetHash(); CrossChainVerify(originalTransactionId, input.ParentChainHeight, input.FromChainId, input.MerklePath); CreateInput creationInput = CreateInput.Parser.ParseFrom(originalTransaction.Params); RegisterTokenInfo(new TokenInfo { Symbol = creationInput.Symbol, TokenName = creationInput.TokenName, TotalSupply = creationInput.TotalSupply, Decimals = creationInput.Decimals, Issuer = creationInput.Issuer, IsBurnable = creationInput.IsBurnable, IssueChainId = parentChainId }); return(new Empty()); }
public void ValidInput_ShouldCreateTheOrder() { // Arrange _customerRepository .Setup(repository => repository.GetById(It.IsAny <Guid>())) .Returns(new Customer()); _productRepository .Setup(repository => repository.Exists(It.IsAny <Guid>())) .Returns(true); var sut = GetSut(); var productId = Guid.NewGuid(); var productIdQuantityDictionary = new Dictionary <Guid, int> { { productId, 1 } }; var input = new CreateInput(Guid.NewGuid(), productIdQuantityDictionary); // Act Action action = () => sut.Execute(input); // Assert action .Should() .NotThrow(); }
public CreateOutput <DivisionDto, long> Create(CreateInput <DivisionDto, long> input) { Division newDivisionEntity = input.Entity.MapTo <Division>(); newDivisionEntity.IsDefault = false; newDivisionEntity.IsActive = true; if (!DivisionPolicy.CanCreateEntity(newDivisionEntity)) { throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionCreateDenied, "\"Division\""); } DivisionRepository.Includes.Add(r => r.LastModifierUser); DivisionRepository.Includes.Add(r => r.CreatorUser); DivisionRepository.Includes.Add(r => r.Teams); DivisionDto newDivisionDto = (DivisionRepository.Insert(newDivisionEntity)).MapTo <DivisionDto>(); DivisionRepository.Includes.Clear(); return(new CreateOutput <DivisionDto, long>() { CreatedEntity = newDivisionDto }); }
/// <summary> /// Register the TokenInfo into TokenContract add initial TokenContractState.LockWhiteLists; /// </summary> /// <param name="input"></param> /// <returns></returns> public override Empty Create(CreateInput input) { RegisterTokenInfo(new TokenInfo { Symbol = input.Symbol, TokenName = input.TokenName, TotalSupply = input.TotalSupply, Decimals = input.Decimals, Issuer = input.Issuer, IsBurnable = input.IsBurnable, IsTransferDisabled = input.IsTransferDisabled, IssueChainId = input.IssueChainId == 0 ? Context.ChainId : input.IssueChainId }); if (string.IsNullOrEmpty(State.NativeTokenSymbol.Value)) { State.NativeTokenSymbol.Value = input.Symbol; } var systemContractAddresses = Context.GetSystemContractNameToAddressMapping().Select(m => m.Value); var isSystemContractAddress = input.LockWhiteList.All(l => systemContractAddresses.Contains(l)); Assert(isSystemContractAddress, "Addresses in lock white list should be system contract addresses"); foreach (var address in input.LockWhiteList) { State.LockWhiteLists[input.Symbol][address] = true; } Context.LogDebug(() => $"Token created: {input.Symbol}"); return(new Empty()); }
public void ProductExists_ShouldUpdateTheProduct() { // Arrange var repository = GetEmptyProductRepository(); var sut = new UpdateUseCase(repository); var createUseCase = new CreateUseCase(repository); var getByIdUseCase = new GetByIdUseCase(repository); var id = Guid.NewGuid(); var createInput = new CreateInput { Id = id, Name = "Name", Description = "Description" }; var UpdateInput = new UpdateInput { Id = id, Name = "Name", Description = "Description" }; createUseCase.Execute(createInput); // Act sut.Execute(UpdateInput); var actual = getByIdUseCase.Execute(id); // Assert actual.Id .Should() .Be(id); }
public int CreateAsync(CreateInput input) { //get current active financial year; var currentYr = financialYearRepository.FirstOrDefault(c => c.IsActive == true); var obj = new Applicant { Type = input.Type, Name = input.Name, Adress = input.Adress, Phone = input.Phone, Email = input.Email, TIN = input.TIN, IsTanzanian = input.IsTanzanian, IDtype = input.IDtype, IDNumber = input.IDNumber, IDIssuePlace = input.IDIssuePlace, IDExpiryDate = input.IDExpiryDate, FinancialYearId = currentYr.Id }; var objExist = this.reporitaryApplicant.FirstOrDefault(a => a.Name == input.Name); if (objExist == null) { return(this.reporitaryApplicant.InsertAndGetId(obj)); } else { throw new UserFriendlyException("Item Alredy Exist"); } }
public void Create(CreateInput input) { var fault = new Fault() { Name = input.Name }; _faultRepository.Insert(fault); }
private void AssertValidCreateInput(CreateInput input) { var isValid = input.TokenName.Length <= TokenContractConstants.TokenNameLength && input.Symbol.Length > 0 && input.Symbol.Length <= TokenContractConstants.SymbolMaxLength && input.Decimals >= 0 && input.Decimals <= TokenContractConstants.MaxDecimals; Assert(isValid, "Invalid input."); }
public Guid Execute(CreateInput input) { ValidateCustomerIdAndThrow(input.CustomerId); ValidateOrderItemsAndThrow(input.ProductIdQuantityDictionary); var order = ToDomainEntity(input); _repository.Create(order); return(order.Id); }
public IActionResult Create(Dictionary <Guid, int> request) { var user = _userService.GetUser(_httpContextAccessor.HttpContext); var customerId = user.CustomerId; var input = new CreateInput(customerId, request); var orderId = _createUseCase.Execute(input); return(Ok(orderId)); }
public void Create(CreateInput input) { var accessory = new Accessory() { Number = input.Number, Unit = input.Unit, Model = input.Model, Name = input.Name }; _accessoryRepository.Insert(accessory); }
// [Authorize] public IActionResult Create(CreateProductRequest request) { var input = new CreateInput { Id = request.Id, Name = request.Name, Description = request.Description }; var productId = _createUseCase.Execute(input); return(Ok(productId)); }
private Order ToDomainEntity(CreateInput input) { var orderItems = new OrderItems(); foreach (var item in input.ProductIdQuantityDictionary) { orderItems.Add(item.Key, item.Value); } var order = new Order(input.CustomerId, orderItems); return(order); }
public async Task <BlogResponse> CreateAsync(CreateInput input) { var response = new BlogResponse(); if (!input.Content.Any()) { response.IsFailed("The content list is null."); return(response); } await _sayings.InsertManyAsync(input.Content.Select(x => new Saying { Content = x.Trim() })); return(response); }
/// <summary> /// Register the TokenInfo into TokenContract add initial TokenContractState.LockWhiteLists; /// </summary> /// <param name="input"></param> /// <returns></returns> public override Empty Create(CreateInput input) { Assert(State.SideChainCreator.Value == null, "Failed to create token if side chain creator already set."); AssertValidCreateInput(input); RegisterTokenInfo(new TokenInfo { Symbol = input.Symbol, TokenName = input.TokenName, TotalSupply = input.TotalSupply, Decimals = input.Decimals, Issuer = input.Issuer, IsBurnable = input.IsBurnable, IsProfitable = input.IsProfitable, IssueChainId = input.IssueChainId == 0 ? Context.ChainId : input.IssueChainId }); if (string.IsNullOrEmpty(State.NativeTokenSymbol.Value)) { Assert(Context.Variables.NativeSymbol == input.Symbol, "Invalid native token input."); State.NativeTokenSymbol.Value = input.Symbol; } var systemContractAddresses = Context.GetSystemContractNameToAddressMapping().Select(m => m.Value); var isSystemContractAddress = input.LockWhiteList.All(l => systemContractAddresses.Contains(l)); Assert(isSystemContractAddress, "Addresses in lock white list should be system contract addresses"); foreach (var address in input.LockWhiteList) { State.LockWhiteLists[input.Symbol][address] = true; } Context.LogDebug(() => $"Token created: {input.Symbol}"); Context.Fire(new TokenCreated { Symbol = input.Symbol, TokenName = input.TokenName, TotalSupply = input.TotalSupply, Decimals = input.Decimals, Issuer = input.Issuer, IsBurnable = input.IsBurnable, IsProfitable = input.IsProfitable, IssueChainId = input.IssueChainId == 0 ? Context.ChainId : input.IssueChainId }); return(new Empty()); }
public void ValidInput_ShouldCreateTheProduct() { // Arrange var repository = new InMemoryProductRepository(); var sut = new CreateUseCase(repository); var input = new CreateInput { Name = "Name", Description = "Description" }; // Act Action action = () => sut.Execute(input); // Assert action .Should() .NotThrow(); }
public void ProductAlreadyExists_ShouldThrowException() { // Arrange var repository = GetProductRepository(); var sut = new CreateUseCase(repository); var input = new CreateInput { Name = "Name", Description = "Description" }; // Act Action action = () => sut.Execute(input); // Assert action .Should() .Throw <ProductAlreadyExistsException>(); }
public Guid Execute(CreateInput input) { var product = _repository.GetById(input.Id); if (product != null) { return(product.Id); } product = new Product( input.Id, input.Name, input.Description); _repository.Create(product); return(product.Id); }
public CreateOutput <LocationDto, long> Create(CreateInput <LocationDto, long> input) { Location newLocationEntity = input.Entity.MapTo <Location>(); if (!LocationPolicy.CanCreateEntity(newLocationEntity)) { throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionCreateDenied, "\"Location\""); } LocationRepository.Includes.Add(r => r.LastModifierUser); LocationRepository.Includes.Add(r => r.CreatorUser); LocationDto newLocationDto = (LocationRepository.Insert(newLocationEntity)).MapTo <LocationDto>(); LocationRepository.Includes.Clear(); return(new CreateOutput <LocationDto, long>() { CreatedEntity = newLocationDto }); }
public override Empty Create(CreateInput input) { var existing = State.TokenInfos[input.Symbol]; Assert(existing == null || existing == new TokenInfo(), "Token already exists."); RegisterTokenInfo(new TokenInfo { Symbol = input.Symbol, TokenName = input.TokenName, TotalSupply = input.TotalSupply, Decimals = input.Decimals, Issuer = input.Issuer, IsBurnable = input.IsBurnable }); foreach (var address in input.LockWhiteList) { State.LockWhiteLists[input.Symbol][address] = true; } return(new Empty()); }
public CreateOutput <TipDto, long> Create(CreateInput <TipDto, long> input) { throw new NotSupportedException("This method is implemented but it is not safely to use it."); Tip newTipEntity = input.Entity.MapTo <Tip>(); if (!TipPolicy.CanCreateEntity(newTipEntity)) { throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionCreateDenied, "\"Tip\""); } TipRepository.Includes.Add(r => r.LastModifierUser); TipRepository.Includes.Add(r => r.CreatorUser); TipDto newTipDto = (TipRepository.Insert(newTipEntity)).MapTo <TipDto>(); TipRepository.Includes.Clear(); return(new CreateOutput <TipDto, long>() { CreatedEntity = newTipDto }); }
public ActionResult Account(CreateInput input) { int applicantId = _applicantService.CreateAsync(input); if (applicantId > 0) { // TODO: Add insert logic here return(RedirectToAction("AddUser", new { Id = applicantId })); } else { var applicationTypes = _applicationTypeService.GetRefApplicationTypes().Select(c => new SelectListItem { Value = c.Id.ToString(), Text = c.Name }); var IdTypes = _refIdentityService.GetItemList().Select(c => new SelectListItem { Value = c.Name.ToString(), Text = c.Name }); ViewBag.Type = applicationTypes; ViewBag.IDtype = IdTypes; return(View(input)); } }
public CreateOutput <UserDto, long> Create(CreateInput <UserDto, long> input) { User existingUser = UserRepository.FirstOrDefault(r => r.UserName == input.Entity.UserName); if (existingUser != null) { throw new UserFriendlyException("Wrong username!", String.Format( "There is already a user with username: \"{0}\"! Please, select another user name.", input.Entity.UserName)); } User newUserEntity = new User() { EmailAddress = input.Entity.EmailAddress, IsEmailConfirmed = true, Name = input.Entity.Name, Password = input.Entity.Password, PhoneNumber = input.Entity.PhoneNumber, Roles = new List <UserRole>(), Surname = input.Entity.Surname, UserName = input.Entity.UserName }; newUserEntity.Password = new PasswordHasher().HashPassword(newUserEntity.Password); #region Creating UserRole Role defaultRole = RoleRepository.FirstOrDefault(r => r.IsDefault); if (defaultRole == null) { throw new UserFriendlyException("Error during the action!", "Can not get default role! Please, contact your system administrator or system support."); } newUserEntity.Roles.Clear(); newUserEntity.Roles.Add(new UserRole() { Role = defaultRole, RoleId = defaultRole.Id, User = newUserEntity }); #endregion #region Creating PlayerCareer try { long defaultTeamId = TeamRepository.Single(r => r.IsDefault == true).Id; PlayerCareer newPlayerCareer = new PlayerCareer() { CareerDateStart = DateTime.Now, IsActive = true, IsCaptain = false, TeamId = defaultTeamId, User = newUserEntity, }; newUserEntity.PlayerCareers.Add(newPlayerCareer); } catch { throw new UserFriendlyException("User creating fault!", "User creating fault! Please contact system administrator or support."); } #endregion UserDto newUserDto = (UserRepository.Insert(newUserEntity)).MapTo <UserDto>(); return(new CreateOutput <UserDto, long>() { CreatedEntity = newUserDto }); }
private CreateItemsOutput[] createECNItems(ItemIdsAndInitialRevisionIds[] itemIds, string itemType) // throws ServiceException { // Get the service stub DataManagementService dmService = DataManagementService.getService(Session.getConnection()); // Populate form type GetItemCreationRelatedInfoResponse relatedResponse = dmService.GetItemCreationRelatedInfo(itemType, null); String[] formTypes = new String[0]; if (relatedResponse.ServiceData.sizeOfPartialErrors() > 0) { throw new ServiceException("DataManagementService.getItemCretionRelatedInfo returned a partial error."); } formTypes = new String[relatedResponse.FormAttrs.Length]; for (int i = 0; i < relatedResponse.FormAttrs.Length; i++) { FormAttributesInfo attrInfo = relatedResponse.FormAttrs[i]; formTypes[i] = attrInfo.FormType; } ItemProperties[] itemProps = new ItemProperties[itemIds.Length]; for (int i = 0; i < itemIds.Length; i++) { CreateIn itemInput = new CreateIn(); itemInput.Data.BoName = "A9_AutoCN"; VecStruct PropValueVec1 = new VecStruct(); PropValueVec1.StringVec = new String[] { "Synopsis_name" }; itemInput.Data.StringProps.Add("object_name", PropValueVec1); CreateInput itemRevisionInput = new CreateInput(); itemRevisionInput.BoName = "A9_AutoCNRevision"; VecStruct PropValueVec2 = new VecStruct(); PropValueVec2.StringVec = new String[] { "test revision desc" }; itemRevisionInput.StringProps.Add("object_desc", PropValueVec2); DateTime currentdate = DateTime.Now; DateTime SyncStartdate = new DateTime(currentdate.Year, currentdate.Month, currentdate.Day, currentdate.Hour, currentdate.Minute, currentdate.Second); String SyncStartdateStr = SyncStartdate.ToString("yyyyMMMddHHmmsssss"); VecStruct PropValueVec4 = new VecStruct(); PropValueVec4.StringVec = new String[] { SyncStartdateStr }; itemRevisionInput.DateProps.Add("a9_EstImpDate", PropValueVec4); itemInput.Data.CompoundCreateInput.Add("revision", itemRevisionInput); CreateIn[] itemInputarray = new CreateIn[1]; itemInputarray[0] = itemInput; CreateResponse cresponse = dmService.CreateObjects(itemInputarray); if (cresponse.ServiceData.sizeOfPartialErrors() > 0) { throw new ServiceException("DataManagementService.CreateObjects returned a partial error." + cresponse.ServiceData.GetPartialError(0)); } //--------------------------------------------------------------------------------- //// Create form in cache for form property population //ModelObject[] forms = createForms(itemIds[i].NewItemId, formTypes[0], // itemIds[i].NewRevId, formTypes[1], // null, false); //ItemProperties itemProperty = new ItemProperties(); //itemProperty.ClientId = "AppX-Test"; //itemProperty.ItemId = itemIds[i].NewItemId; //itemProperty.RevId = itemIds[i].NewRevId; //itemProperty.Name = "AppX-Test"; //itemProperty.Type = itemType; //itemProperty.Description = "Test Item for the SOA AppX sample application."; //itemProperty.Uom = ""; //// Retrieve one of form attribute value from Item master form. //ServiceData serviceData = dmService.GetProperties(forms, new String[] { "project_id" }); //if (serviceData.sizeOfPartialErrors() > 0) // throw new ServiceException("DataManagementService.getProperties returned a partial error."); //Property property = null; //try //{ // property = forms[0].GetProperty("project_id"); //} //catch (NotLoadedException /*ex*/) { } //// Only if value is null, we set new value //if (property == null || property.StringValue == null || property.StringValue.Length == 0) //{ // itemProperty.ExtendedAttributes = new ExtendedAttributes[1]; // ExtendedAttributes theExtendedAttr = new ExtendedAttributes(); // theExtendedAttr.Attributes = new Hashtable(); // theExtendedAttr.ObjectType = formTypes[0]; // theExtendedAttr.Attributes["project_id"] = "project_id"; // itemProperty.ExtendedAttributes[0] = theExtendedAttr; //} //itemProps[i] = itemProperty; } //// ***************************** //// Execute the service operation //// ***************************** //CreateItemsResponse response = dmService.CreateItems(itemProps, null, ""); //// before control is returned the ChangedHandler will be called with //// newly created Item and ItemRevisions //// The AppXPartialErrorListener is logging the partial errors returned //// In this simple example if any partial errors occur we will throw a //// ServiceException //if (response.ServiceData.sizeOfPartialErrors() > 0) // throw new ServiceException("DataManagementService.createItems returned a partial error."); CreateItemsResponse response = null; return(response.Output); }