public void SetSeedThrowsWhenCharacterSetIsEmptyOrNull() { var seed = string.Empty; Action action = () => { ShortId.SetCharacters(seed); }; action.Should().Throw <ArgumentException>() .WithMessage("The replacement characters must not be null or empty."); }
public void SetSeedThrowsWhenCharacterSetIsLessThan20Characters() { const string seed = "783ujrcuei039kj4"; Action action = () => { ShortId.SetCharacters(seed); }; action.Should().Throw <InvalidOperationException>() .WithMessage( "The replacement characters must be at least 20 letters in length and without whitespace."); }
public void SetSeedWorksWithValidCharSet() { const string seed = "ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ①②③④⑤⑥⑦⑧⑨⑩⑪⑫"; var action = () => { ShortId.SetCharacters(seed); }; action .Should() .NotThrow <InvalidOperationException>(); }
public virtual async Task <IActionResult> CreateBooking(CreateBookingDTO booking) { var result = new JsonResult <string>(); try { ShortId.SetCharacters(CHARACTERS); var pendingBooking = await _service.GetPendingBookingByClientIdAsync(booking.PendingBookingId); var entity = new Booking { Id = ShortId.Generate(true, false, 8).ToUpper(), Date = DateTime.Now, Email = booking.Email, Name = booking.Name, Phone = booking.Phone, ScheduleId = pendingBooking.EvenScheduleId }; entity.BookingPositions = pendingBooking .PendingBookingPositions .Select(x => new BookingPosition { BookingId = entity.Id, ServicePlacePositionId = x.ServicePlacePositionId }) .ToList(); entity = await _service.CreateBookingAsync(entity); await _hubContext.Clients.All.RecieveNewBooking(_mapper.Map <Booking, BookingDTO>(entity)); result.Success = true; result.Result = entity.Id; SmtpMail oMail = new SmtpMail("TryIt"); SmtpClient oSmtp = new SmtpClient(); oMail.From = "*****@*****.**"; oMail.To = booking.Email; oMail.Subject = "Sikeres foglalás"; oMail.TextBody = $"Köszönjük a foglalásod. Az azonosító: {entity.Id}."; SmtpServer oServer = new SmtpServer("smtp.gmail.com"); oServer.Port = 587; oServer.ConnectType = SmtpConnectType.ConnectSSLAuto; oServer.User = "******"; oServer.Password = ""; oSmtp.SendMail(oServer, oMail); } catch (BookingException) { result.Message = "Valaki más már tett foglalást a kiválasztott hely(ek)re."; } catch { // TODO log result.Message = "A foglalási kérelmet nem lehet elindítani váratlan hiba miatt."; } return(Ok(result)); }
public UniqueIdGenerator() { ShortId.SetCharacters(@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseResponseCompression(); //app.UseCors(builder => // builder // .WithOrigins("https://localhost:44384", "http://localhost:4200").AllowAnyOrigin()); app.UseCors(builder => { builder.AllowAnyOrigin(); builder.AllowAnyMethod(); builder.AllowAnyMethod(); }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSpaStaticFiles(); app.UseWebSockets(); app.UseSignalR(routes => { routes.MapHub <NotificationHub>("/notification-hub"); routes.MapHub <KanbanHub>("/kanban-hub"); routes.MapHub <ChatHub>("/chat-hub"); routes.MapHub <ReadOnlyProjectHub>("/project-read-only"); }); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action=Index}/{id?}"); }); app.UseAuthentication(); app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); } }); // Configure id generator ShortId.SetCharacters("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"); ShortId.SetSeed(1939048828); }