public async Task GeneratePairings() { using (var context = new ApplicationDbContext(Options)) { var pairingService = new PairingService(context); List <Pairing> pairings = await pairingService.GeneratePairings(1); List <int> santaIds = new List <int>(); foreach (Pairing pairing in pairings) { if (!santaIds.Contains(pairing.SantaId)) { santaIds.Add(pairing.SantaId); } } foreach (var pairing in pairings) { Assert.AreNotEqual <int>(pairing.SantaId, pairing.RecipientId); } Assert.IsNotNull(pairings); Assert.IsTrue(pairings.Count == 5); Assert.AreEqual(pairings.Count, santaIds.Count); } }
public async Task GeneratePairings_CreatesPairings() { using (var context = new ApplicationDbContext(Options)) { var pairingService = new PairingService(context); List <Pairing> pairings = await pairingService.GeneratePairings(1); Assert.IsNotNull(pairings); Assert.IsTrue(pairings.Count == 4); } }
public async Task GeneratePairings_NoRecipientIsTheirOwnSanta() { using (var context = new ApplicationDbContext(Options)) { var pairingService = new PairingService(context); List <Pairing> pairings = await pairingService.GeneratePairings(1); foreach (var pairing in pairings) { Assert.AreNotEqual <int>(pairing.SantaId, pairing.RecipientId); } } }
public async Task <IActionResult> GeneratePairings(int groupId) { if (groupId < 1) { return(BadRequest("A group id must be specified")); } List <Pairing> result = await PairingService.GeneratePairings(groupId); if (result.Count == 0) { return(BadRequest()); } return(Created($"/pairing/{groupId}", result.Select(p => Mapper.Map <PairingViewModel>(p)).ToList())); }
public async Task <IActionResult> GeneratePairings(int groupId) { if (groupId < 1) { return(BadRequest("No ID given.")); } List <Pairing> pairings = await PairingService.GeneratePairings(groupId); if (pairings.Count < 1 || pairings == null) { return(BadRequest("Issue generating pairings.")); } return(Created($"/Pairing/{groupId}", pairings.Select(p => Mapper.Map <PairingViewModel>(p)).ToList())); }
public async Task GeneratePairings_SantasAreUnique() { using (var context = new ApplicationDbContext(Options)) { var pairingService = new PairingService(context); List <Pairing> pairings = await pairingService.GeneratePairings(1); List <int> santaIds = new List <int>(); // List of uniquely found santaIds foreach (Pairing pairing in pairings) { if (!santaIds.Contains(pairing.SantaId)) { santaIds.Add(pairing.SantaId); } } Assert.AreEqual(pairings.Count, santaIds.Count); } }