public async Task <Unit> Handle(UpdateDeviceCommand request, CancellationToken cancellationToken) { var code = StringCleaner.CleanInput(request.Code).Trim(); var name = StringCleaner.CleanInput(request.Name).Trim(); if (String.IsNullOrEmpty(code) || String.IsNullOrEmpty(name)) { throw new NotFoundException("User input is bad.", request.Id); } // Retrieve the entity var entity = await _context.Devices.FindAsync(request.Id); if (entity == null) { throw new NotFoundException(nameof(Device), request.Id); } var lat = (entity.Latitude != null) ? StringCleaner.CleanInput(request.Latitude).Trim() : null; var lng = (entity.Longitude != null) ? StringCleaner.CleanInput(request.Longitude).Trim() : null; // Update the entity entity.Code = code; entity.Name = name; entity.Zone = request.Zone; entity.Latitude = (String.IsNullOrEmpty(lat)) ? null : lat; entity.Longitude = (String.IsNullOrEmpty(lng)) ? null : lng; await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public void RemoveInvalidFileNameCharacters_Test_ForwardSlashReplacedWithHyphen() { var testString = InsertCharRandomlyIntoString(sampleString, '/'); Assert.AreEqual(StringCleaner.RemoveInvalidDirectoryCharacters(testString), testString.Replace(':', '-')); }
public void RemoveInvalidFileNameCharacters_Test_SemiColonReplacedWithHyphen() { var testString = InsertCharRandomlyIntoString(sampleString, ':'); Assert.AreEqual(StringCleaner.RemoveInvalidFileNameCharacters(testString), testString.Replace(':', '-')); }
public async Task <Unit> Handle(UpdateTestCommand request, CancellationToken cancellationToken) { // Retrieve the entity var entity = await _context.Tests.FindAsync(request.Id); if (entity == null) { throw new NotFoundException(nameof(Test), request.Id); } var jiraNumber = StringCleaner.CleanInput(request.JiraTestNumber).Trim(); if (String.IsNullOrEmpty(jiraNumber)) { throw new NotFoundException("User input is bad.", request.Id); } var existingTest = await _context.Tests.FirstOrDefaultAsync(x => x.JiraTestNumber == jiraNumber); if (existingTest == null) { entity.JiraTestNumber = jiraNumber; } else { // TODO Fix the return statements throw new NotFoundException(nameof(Test), request.Id); } await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <int> Handle(CreateDeviceCommand request, CancellationToken cancellationToken) { var code = StringCleaner.CleanInput(request.Code).Trim(); var name = StringCleaner.CleanInput(request.Name).Trim(); if (String.IsNullOrEmpty(code) || String.IsNullOrEmpty(name)) { throw new NotFoundException("User input is bad.", request.Code); } var lat = (request.Latitude != null) ? StringCleaner.CleanInput(request.Latitude).Trim() : null; var lng = (request.Longitude != null) ? StringCleaner.CleanInput(request.Longitude).Trim() : null; //Map request to entity var entity = new Device { Code = code, Name = name, Zone = request.Zone, Latitude = (String.IsNullOrEmpty(lat)) ? null : lat, Longitude = (String.IsNullOrEmpty(lng)) ? null : lng }; _context.Devices.Add(entity); await _context.SaveChangesAsync(cancellationToken); return(entity.Id); }
public void Clean_NullText_ArgumentNullException() { Assert.Throws <ArgumentNullException>(() => StringCleaner.Clean(null)); // This was added // This was added2 // This was added3 }
public void Sc_ToActualTitleCase_Test_AllLowercaseInput() { var dirtyInput = "i want this to be correct title case."; var cleanOutput = "I Want This to Be Correct Title Case."; Assert.AreEqual(StringCleaner.ToActualTitleCase(dirtyInput), cleanOutput); }
/// <summary> /// Executes the View for Export /// </summary> public ActionResult BeerXml(int recipeId) { var recipe = this.RecipeService.GetRecipeById(recipeId); if (recipe == null) { return(this.Issue404()); } var xmlString = this.BeerXmlExporter.Export(recipe); var xmlBytes = Encoding.Default.GetBytes(xmlString); var disposition = new ContentDisposition { // for example foo.bak FileName = string.Format("{0}-brewgr.xml", StringCleaner.CleanForUrl(recipe.RecipeName)), // always prompt the user for downloading, set to true if you want // the browser to try to show the file inline Inline = false, }; Response.AppendHeader("Content-Disposition", disposition.ToString()); return(new FileStreamResult(new MemoryStream(xmlBytes), "text/xml")); }
/// <summary> /// Builds a Recipe Detail Url /// </summary> public string BuildBrewSessionDetailUrl(BrewSession brewSession) { var brewSessionNameForUrl = StringCleaner.CleanForUrl(brewSession.RecipeSummary.RecipeName); brewSessionNameForUrl += "-brew-session"; return(string.Format("/brew/{0}/{1}", brewSession.BrewSessionId, brewSessionNameForUrl)); }
public async Task <Unit> Handle(UpdatePassCommand request, CancellationToken cancellationToken) { var name = StringCleaner.CleanInput(request.Name).Trim(); if (String.IsNullOrEmpty(name)) { throw new NotFoundException("User input is bad.", request.Id); } // Retrieve the entity var entity = await _context.Passes.FindAsync(request.Id); if (entity == null) { throw new NotFoundException(nameof(Pass), request.Id); } var tapsToUpdate = await _context.Taps.Where(x => x.Pass == entity.Name).ToListAsync(); foreach (var tap in tapsToUpdate) { tap.Pass = name; } // Update the entity entity.Name = name; await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public CreateDeviceCommandValidator(IApplicationDbContext context) { _context = context; RuleFor(d => d.Code) .Transform(d => StringCleaner.CleanInput(d)) .NotEmpty().WithMessage("Code is required.") .MaximumLength(32).WithMessage("Code must not exceed 32 characters.") .MustAsync(BeUniqueCode).WithMessage("The specified Code already exists.") .Must(NotContainBadCharactersCode).WithMessage("Code can only contain a-zA-Z0-9_.$@-"); RuleFor(d => d.Name) .Transform(d => StringCleaner.CleanInput(d)) .NotEmpty().WithMessage("Name is required.") .MaximumLength(64).WithMessage("Code must not exceed 64 characters.") .Must(NotContainBadCharactersName).WithMessage("Name can only contain a-zA-Z0-9_.$@-"); RuleFor(d => d.Zone) .NotEmpty().WithMessage("Zone is required.") .ExclusiveBetween(0, 100).WithMessage("Zone must be between 0 and 100."); RuleFor(d => d.Latitude) .Transform(d => StringCleaner.CleanInput(d)) .MaximumLength(16).WithMessage("Latitude must not exceed 16 characters") .Must(NotContainBadCharactersLat).WithMessage("Latitude can only contain a-zA-Z0-9_.$@-"); RuleFor(d => d.Longitude) .Transform(d => StringCleaner.CleanInput(d)) .MaximumLength(16).WithMessage("Longitude must not exceed 16 characters") .Must(NotContainBadCharactersLng).WithMessage("Longitude can only contain a-zA-Z0-9_.$@-"); }
public async Task <int> Handle(CreateStageCommand request, CancellationToken cancellationToken) { var name = StringCleaner.CleanInput(request.Name).Trim(); if (String.IsNullOrEmpty(name)) { throw new NotFoundException("User input is bad.", request.Name); } //Map request to entity var entity = new Stage { Name = name, IsCurrent = request.IsCurrent }; if (request.IsCurrent) { var current = await _context.Stages.FirstOrDefaultAsync(x => x.IsCurrent == true); if (current != null) { current.IsCurrent = false; } } _context.Stages.Add(entity); await _context.SaveChangesAsync(cancellationToken); return(entity.Id); }
public async Task <Unit> Handle(UpdateStageCommand request, CancellationToken cancellationToken) { var name = StringCleaner.CleanInput(request.Name).Trim(); if (String.IsNullOrEmpty(name)) { throw new NotFoundException("User input is bad.", request.Name); } // Retrieve the entity var entity = await _context.Stages.FindAsync(request.Id); if (entity == null) { throw new NotFoundException(nameof(Stage), request.Id); } if (request.IsCurrent && entity.IsCurrent != true) { var current = await _context.Stages.FirstOrDefaultAsync(x => x.IsCurrent == true); if (current != null) { current.IsCurrent = false; } } // Update the entity entity.Name = name; entity.IsCurrent = request.IsCurrent; await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public void Sc_ToActualTitleCase_Test_FirstLetterOfEveryWordCapitalizedInInput() { var dirtyInput = "This Is Another Test For My Regex Stuff"; var cleanOutput = "This Is Another Test for My Regex Stuff"; Assert.AreEqual(StringCleaner.ToActualTitleCase(dirtyInput), cleanOutput); }
// GET: AttendeeModels public async Task <IActionResult> Index() { var _dbstring = Config.GetConnectionString("AttendeeContext"); ViewData["ConnectSource"] = "appsettings.json"; IConfigurationSection configurationSection = Config.GetSection("ConnectionStrings"); if (configurationSection != null) { if (configurationSection.GetValue <string>("AttendeeContext") != null) { ViewData["ConnectSource"] = "Config Server"; } } var cfe = new CFEnvironmentVariables(); var _connect = cfe.getConnectionStringForDbService("user-provided", "AttendeeContext"); if (!string.IsNullOrEmpty(_connect)) { ViewData["ConnectSource"] = "User Provided Service"; _dbstring = _connect; } ViewData["ConnectionString"] = StringCleaner.GetDisplayString("Password="******";", _dbstring, "*****"); return(View(await _context.AttendeeModel.ToListAsync())); }
public void IfUsingCleanUnicodeThenPlainTextRemains() { var stringCleaner = new StringCleaner(false, true, false, false); stringCleaner.Clean("this.\"has\".-punctuation()").ShouldBe("this.\"has\".-punctuation()"); stringCleaner.Clean("no punctuation in this one").ShouldBe("no punctuation in this one"); }
public CreateCardCommandValidator(IApplicationDbContext context) { _context = context; RuleFor(c => c.Number) .Transform(c => StringCleaner.CleanInput(c)) .NotEmpty().WithMessage("Number is required.") .MaximumLength(32).WithMessage("Number must not exceed 32 characters.") .MustAsync(BeUniqueNumber).WithMessage("The specified Number already exists.") .Must(NotContainBadCharactersNumber).WithMessage("Number can only contain a-zA-Z0-9_.$@-"); //When(c => c?.Alias != null, () => //{ // RuleFor(c => c.Alias) // .Transform(c => StringCleaner.CleanInput(c)) // .MaximumLength(32).WithMessage("Alias must not exceed 32 characters.") // .MustAsync(BeUniqueAlias).WithMessage("The specified Alias already exists.") // .Must(NotContainBadCharactersAlias).WithMessage("Can only contain a-zA-Z0-9_.$@-"); //}); RuleFor(c => c.Alias) .Transform(c => StringCleaner.CleanInput(c)) .MaximumLength(32).WithMessage("Alias must not exceed 32 characters.") .MustAsync(BeUniqueAlias).WithMessage("The specified Alias already exists.") .Must(NotContainBadCharactersAlias).WithMessage("Alias can only contain a-zA-Z0-9_.$@-"); RuleFor(c => c.SupplierId) .NotEmpty().WithMessage("Supplier must not be null.") .MustAsync(SupplierExist).WithMessage("Supplier does not exist."); RuleFor(c => c.PassId) .MustAsync(PassExist).WithMessage("Pass does not exist.").When(c => c.PassId != null); RuleFor(c => c.ProductId) .MustAsync(ProductExist).WithMessage("Product does not exist.").When(c => c.ProductId != null); }
public async Task <CustomerInfo> GetCustomerInfo(string contractId) { if (string.IsNullOrEmpty(Query)) { throw new InvalidOperationException("Query is not set"); } if (string.IsNullOrEmpty(contractId)) { throw new ArgumentNullException(); } using (var connection = new OracleConnection()) { connection.ConnectionString = GetConnectionString(); await connection.OpenAsync(); var customer = await GetCustomer(connection, new CommandDefinition(GetQuery(contractId))); //fill in input info if (customer == null) { return(null); //Cant find customer } //Return customer with stripped vietnamese accents return(StringCleaner.StripAccentsNSpecialChars(customer)); } }
/// <summary> /// Builds a Recipe Detail Url /// </summary> public string BuildBrewSessionDetailUrl(BrewSession brewSession) { var brewSessionNameForUrl = StringCleaner.CleanForUrl(brewSession.RecipeSummary.RecipeName); brewSessionNameForUrl += "-brew-session"; return(string.Format("{0}/brew/{1}/{2}", this.WebSettings.RootPath, brewSession.BrewSessionId, brewSessionNameForUrl)); }
/// <summary> /// Gets the products from a file an fill them into a list. /// Uses static class <see cref="StringCleaner"/> methods to clean for noise characters /// </summary> private void GetUsersFromFile() { IEnumerable <string[]> CleanUserInformation = _userFile.GetCellsInLinesOfFile(';') .Select(s => StringCleaner.RemoveCharacterFromStringArray(s, '"')).Skip(1); _listOfUsers = RegisterUsers(CleanUserInformation); }
public async Task <Unit> Handle(UpdateCardCommand request, CancellationToken cancellationToken) { var number = StringCleaner.CleanInput(request.Number).Trim(); if (String.IsNullOrEmpty(number)) { throw new NotFoundException("User input is bad.", request.Id); } // Retrieve the entity var entity = await _context.Cards.FindAsync(request.Id); if (entity == null) { throw new NotFoundException(nameof(Card), request.Id); } var supplierEntity = await _context.Suppliers.AsNoTracking().FirstOrDefaultAsync(s => s.Id == request.SupplierId); if (supplierEntity == null) { throw new NotFoundException(nameof(Product), request.ProductId); } Pass passEntity = null; if (request.PassId != null) { passEntity = await _context.Passes.AsNoTracking().FirstOrDefaultAsync(s => s.Id == request.PassId); if (passEntity == null) { throw new NotFoundException(nameof(Pass), request.PassId); } } Product productEntity = null; if (request.ProductId != null) { productEntity = await _context.Products.AsNoTracking().FirstOrDefaultAsync(s => s.Id == request.ProductId); if (productEntity == null) { throw new NotFoundException(nameof(Product), request.ProductId); } } var alias = (request.Alias != null) ? StringCleaner.CleanInput(request.Alias).Trim() : null; // Update the entity entity.Number = number; entity.Alias = (String.IsNullOrEmpty(request.Alias)) ? null : alias; entity.SupplierId = request.SupplierId; entity.ProductId = request.ProductId ?? null; entity.PassId = request.PassId ?? null; await _context.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <int> Handle(CreateCardCommand request, CancellationToken cancellationToken) { //var number2 = StringCleaner.HasBadCharacters(request.Number); var number = StringCleaner.CleanInput(request.Number).Trim(); if (String.IsNullOrEmpty(number)) { throw new NotFoundException("User input is bad.", request.Number); } var supplierEntity = await _context.Suppliers.AsNoTracking().FirstOrDefaultAsync(s => s.Id == request.SupplierId); if (supplierEntity == null) { throw new NotFoundException(nameof(Product), request.ProductId); } Pass passEntity = null; if (request.PassId != null) { passEntity = await _context.Passes.AsNoTracking().FirstOrDefaultAsync(s => s.Id == request.PassId); if (passEntity == null) { throw new NotFoundException(nameof(Pass), request.PassId); } } Product productEntity = null; if (request.ProductId != null) { productEntity = await _context.Products.AsNoTracking().FirstOrDefaultAsync(s => s.Id == request.ProductId); if (productEntity == null) { throw new NotFoundException(nameof(Product), request.ProductId); } } var alias = (request.Alias != null) ? StringCleaner.CleanInput(request.Alias).Trim() : null; //Map request to entity var entity = new Card { Number = number, Alias = String.IsNullOrEmpty(alias) ? null : alias, SupplierId = request.SupplierId, PassId = request.PassId ?? null, ProductId = request.ProductId ?? null }; _context.Cards.Add(entity); await _context.SaveChangesAsync(cancellationToken); return(entity.Id); }
// ---- Ubacivanje podataka u bazi ---- private void BtnSubmitData_Click(object sender, EventArgs e) { // ---- Provera ispravnosti podataka ---- if (String.IsNullOrWhiteSpace(TbPunoIme.Text)) { MessageBox.Show("Unesi Puno ime trenera!"); return; } else if (String.IsNullOrWhiteSpace(TbMestoRodjenja.Text)) { MessageBox.Show("Unesi mesto rodjenja trenera!"); return; } else if (String.IsNullOrWhiteSpace(TbTrenutniKlub.Text)) { MessageBox.Show("Unesi trenutni klub(reprezentaciju) koju trenira trener!"); return; } Trener forSave = new Trener(); forSave.PunoIme = StringCleaner.checkString(TbPunoIme.Text); forSave.MestoRodjenja = StringCleaner.checkString(TbMestoRodjenja.Text); forSave.TrenutniKlub = StringCleaner.checkString(TbTrenutniKlub.Text); forSave.TrenerskaKarijera = StringCleaner.checkString(RtbTrenerskaKarijera.Text); forSave.Uspesi = StringCleaner.checkString(RtbUspesi.Text); forSave.DatumRodjenja = StringCleaner.checkString(dateTimePicker1.Value.ToShortDateString()); var _client = new MongoClient(); var _database = _client.GetDatabase("test"); var collection = _database.GetCollection <BsonDocument>("treneri"); var filter = new BsonDocument() { { "PunoIme", TbPunoIme.Text } }; var filterForUniqueCheck = Builders <BsonDocument> .Filter.Eq("PunoIme", this.TbPunoIme.Text); var document = forSave.ToBsonDocument(); //test if exists var test = collection.Find(filterForUniqueCheck).Count(); if (test == 0) { collection.InsertOne(document); if (slikaTrenera != null) { AuxLib.AddImageToGridFS(slikaTrenera, forSave.PunoIme, format); } MessageBox.Show("Uspesno dodat novi trener!"); } else { //TO DO : URADITI UPDATE SLIKE (AuxLib treba da ima remove image i remove mp3 i da se izbaci slika i ubaci nova); collection.ReplaceOne(filter, document); MessageBox.Show("Uspesno azuriran trener!"); } }
public void IfUsingCleanUnicodeThenExtendedBecomePlain() { var stringCleaner = new StringCleaner(false, true, false, false); stringCleaner.Clean("this ùŠ").ShouldBe("this uS"); stringCleaner.Clean("Mötley Crüe").ShouldBe("Motley Crue"); stringCleaner.Clean("Mötley!.Crüe").ShouldBe("Motley!.Crue"); }
public void Clean_TextWithSpaces_SpacesRemoved(string text, string expectedResult) { // Act var actualResult = StringCleaner.Clean(text); // Assert Assert.AreEqual(expectedResult, actualResult); }
public void IfUsingCleanPunctuationThenPlainPunctuationRemains() { var stringCleaner = new StringCleaner(true, false, false, false); var str1 = "this.\"has\".-punctuation()"; stringCleaner.Clean(str1).ShouldBe(str1); stringCleaner.Clean("no punctuation in this one").ShouldBe("no punctuation in this one"); }
public void WhenStringStartsWithTheItIsRemoved() { var stringCleaner = new StringCleaner(false, false, false, false); stringCleaner.Clean("the who").ShouldBe("who"); stringCleaner.Clean("thewho").ShouldBe("thewho"); stringCleaner.Clean("The Who").ShouldBe("Who"); }
/// <summary> /// Gets the products from a file and fill them into a list /// Uses static class <see cref="StringCleaner"/> methods to clean the information for noise characters /// </summary> private void GetProductsFromFile() { IEnumerable <string[]> _cleanProductInformation = _productFile.GetCellsInLinesOfFile(';') .Select(s => StringCleaner.RemoveCharacterFromStringArray(s, '"')) .Select(s => StringCleaner.RemoveHtmlTagsFromStringArray(s)).Skip(1); _listOfProducts = MakeProductsFromInformation(_cleanProductInformation); }
public RegionalStringCleaner(Region region) { var repository = new StringCleanerRepository(); var regionalCharacterMappings = repository.GetCharacterMappingsForRegion(region); var regionalAcceptableCharacters = new Regex(repository.GetAcceptableStringPatternForRegion(region), RegexOptions.Compiled); _stringCleaner = new StringCleaner(regionalCharacterMappings, regionalAcceptableCharacters); }
public void WhenStrippingSongThenCaseChanges() { var stringCleaner = new StringCleaner(false, false, false, true); stringCleaner.MakeSongSortName("Testing").ShouldBe("testing"); stringCleaner.MakeSongSortName("test iNg").ShouldBe("testing"); stringCleaner.MakeSongSortName("!strip.this please").ShouldBe("stripthisplease"); }