public User(LoginCredentials loginCredentials, ElectionDbContext context, WebserviceRawCommunication webservice) { _loginCredentials = loginCredentials; FirstName = loginCredentials.FirstName; LastName = loginCredentials.LastName; Pesel = loginCredentials.Pesel; _context = context; _webservice = webservice; _checkUserAlreadyVotedService = new CheckUserAlreadyVotedFromDbService(loginCredentials, context); _checkUserIsDisallowdToVoteService = new CheckUserIsDisallowedToVoteService(webservice); _loginValidatorService = new LoginValidatorService(loginCredentials.FirstName, loginCredentials.LastName, Pesel, _checkUserIsDisallowdToVoteService, _checkUserAlreadyVotedService); }
public DatabaseAndWebserviceFixture() { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json"); Configuration = builder.Build(); Context = new ElectionDbContext(Configuration.GetConnectionString("FpElectionDatabase")); Webservice = new WebserviceRawCommunication(); // Try to create database (if not exists) and populate with candidates data var dbInitializer = new DatabaseInitializer(Context, new GetJsonCandidateListFromWsService(Webservice)); dbInitializer.DeleteTablesInDatabase(); dbInitializer.InitializeDbWithCandidatesAndParties(); }
static void Main(string[] args) { ConsoleProlog(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("- Reading application settings - please wait..."); var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json"); Configuration = builder.Build(); Console.WriteLine("- Connecting to database - please wait..."); // Preparing services var context = new ElectionDbContext(Configuration.GetConnectionString("FpElectionDatabase")); using (context) { Console.WriteLine("- Initializing webservice - please wait..."); var webservice = new WebserviceRawCommunication(); Console.WriteLine("- Initializing database - please wait..."); // Try to create database (if not exists) and populate with candidates data var dbInitializer = new DatabaseInitializer(context, new GetJsonCandidateListFromWsService(webservice)); //dbInitializer.DeleteTablesInDatabase(); dbInitializer.InitializeDbWithCandidatesAndParties(); KeyOption key; do { key = ReadKeyOption(); switch (key) { case KeyOption.Login: LoginUserMethod(context, webservice); break; case KeyOption.VoteStatistics: VoteStatistics(context); break; case KeyOption.Quit: break; } } while (key != KeyOption.Quit); } }
public WebserviceRawCommunicationCandidatesTests(ITestOutputHelper output) { _output = output; _webservice = new WebserviceRawCommunication(); }
public WebserviceRawCommunicationDisallowedTests(ITestOutputHelper output) { _output = output; _webservice = new WebserviceRawCommunication(); }
private static void LoginUserMethod(ElectionDbContext context, WebserviceRawCommunication webservice) { Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("----- Login to system -------------------------------------------------------"); LoginCredentials loginCredentials = GetCredentialsFromConsole(); User user = new Domain.Models.User(loginCredentials, context, webservice); LoginValidation loginValidation = user.Login(); if (loginValidation.Error) { Console.ForegroundColor = ConsoleColor.Red; foreach (var error in loginValidation.LoginErrors) { Console.WriteLine($"- Error: {LoginErrorDescription.GetDescription(error)}"); } } if (loginValidation.Warning) { Console.ForegroundColor = ConsoleColor.DarkYellow; foreach (var warning in loginValidation.LoginWarnings) { Console.WriteLine($"- Warning: {LoginWarningDescription.GetDescription(warning)}"); } } if (!loginValidation.Error) { if (user.Logged) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine($"- User logged : {user.FirstName} / {user.LastName} / {user.Pesel}"); if (!loginValidation.LoginWarnings.Contains(LoginWarning.UserAlreadyVoted) && !loginValidation.LoginWarnings.Contains(LoginWarning.UserIsDisallowedToVote)) { IList <Candidate> candidates = context.Candidates.ToList(); IList <Party> parties = context.Parties.ToList(); Console.ForegroundColor = ConsoleColor.Magenta; for (int i = 0; i < candidates.Count; i++) { Console.WriteLine( $"{i + 1}] {candidates[i].Name} / {parties.Single(x => x.PartyId == candidates[i].PartyId).Name}"); } int[] parsedChoice; do { Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("Please enter you candidate (or candidates) no [eg. \"1,5,10\"]: "); Console.ForegroundColor = ConsoleColor.White; string candidatesRead = Console.ReadLine(); parsedChoice = ChoiceParser.Parse(candidatesRead, candidates.Count); if (parsedChoice == null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"- Error: Illegal characters in your response"); } } while (parsedChoice == null); Console.ForegroundColor = ConsoleColor.Yellow; for (int i = candidates.Count; i > 0; i--) { if (!parsedChoice.Any(x => x == i)) { candidates.RemoveAt(i - 1); } } Console.ForegroundColor = ConsoleColor.DarkGray; if (candidates.Count == 0) { Console.WriteLine($"You voted to nobody"); } foreach (var c in candidates) { Console.WriteLine( $"You voted to {c.Name} / {parties.Single(x => x.PartyId == c.PartyId).Name}"); } user.Vote(candidates); } // Get Vote statistics VoteStatistics(context); user.Logout(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("- User logout"); } } }