示例#1
0
        public void SecretSanta_Generate_WithBanned_ReturnsASet()
        {
            var result = SecretSantaGenerator.Generate(_participants, _banned);

            CheckForValidSantaList(result);
            CheckResultHasNoBannedPair(result);
        }
示例#2
0
        private static void CreateSantasList(string[] args)
        {
            IList <string> participants = ReadFile(args[0]);

            IDictionary <string, string> bannedPairs = new Dictionary <string, string>();
            string outputFile;

            switch (args.Length)
            {
            case 2:
                outputFile = args[1];
                break;

            case 3:
                bannedPairs = ReadDictFile(args[1]);
                outputFile  = args[2];
                break;

            default:
                throw new ArgumentException("Invalid number of arguments passed");
            }

            var santasList = SecretSantaGenerator.Generate(participants, bannedPairs);

            WriteDictFile(outputFile, santasList);
        }
示例#3
0
        public async Task SendAsync()
        {
            if (string.IsNullOrEmpty(_configuration["SANTA_PARTICIPANT_PATH"]))
            {
                throw new ArgumentException("You must provide path to participants file as first argument");
            }

            var participantsPath = _configuration["SANTA_PARTICIPANT_PATH"];

            if (!File.Exists(participantsPath))
            {
                throw new ArgumentException($"File {participantsPath} doesn't exists");
            }

            _logger.LogInformation("Load participants list");
            var json         = File.ReadAllText(participantsPath);
            var participants = JsonConvert.DeserializeObject <List <Participant> >(json);

            _logger.LogInformation("Participants: {count}", participants.Count);
            var santasList =
                SecretSantaGenerator.Generate(participants, new Dictionary <Participant, Participant>());

            _logger.LogInformation("List generated");
            try
            {
                await _mailSender.SendMail(santasList, "Secret Santa 2019", "~/Views/Mail/Notification.cshtml");
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex, ex.ToString());
            }
        }
示例#4
0
        public void SecretSanta_Generate_ReturnsASet()
        {
            var result = SecretSantaGenerator.Generate(_participants);

            CheckForValidSantaList(result);
        }