public async Task Test_RetrieveEntriesByMapId_Doesnt_Return_Entries_With_Different_MapId(int mapId) { int unavailableMapId = 5; if (mapId == unavailableMapId) { Assert.Inconclusive($"Cannot use {nameof(mapId)}: {unavailableMapId}"); return; } //arrange INpcEntryRepository entryRepo = BuildEmptyRepository(); //act await entryRepo.TryCreateAsync(new NPCEntryModel(1, new Vector3 <float>(5, 6, 7), 55, mapId, NpcMovementType.Stationary, 1)); await entryRepo.TryCreateAsync(new NPCEntryModel(2, new Vector3 <float>(5, 6, 7), 55, mapId, NpcMovementType.Stationary, 1)); await entryRepo.TryCreateAsync(new NPCEntryModel(3, new Vector3 <float>(5, 6, 7), 55, mapId, NpcMovementType.Stationary, 1)); await entryRepo.TryCreateAsync(new NPCEntryModel(3, new Vector3 <float>(5, 6, 7), 55, unavailableMapId, NpcMovementType.Stationary, 1)); await entryRepo.TryCreateAsync(new NPCEntryModel(3, new Vector3 <float>(5, 6, 7), 55, unavailableMapId, NpcMovementType.Stationary, 1)); IReadOnlyCollection <NPCEntryModel> entryModels = await entryRepo.RetrieveAllWithMapIdAsync(mapId); //assert Assert.AreEqual(3, entryModels.Count); Assert.False(entryModels.Any(e => e.MapId != mapId)); }
public async Task Test_RetrieveEntriesByMapId_Returns_All_Entries_With_MapId(int mapId) { //arrange INpcEntryRepository entryRepo = BuildEmptyRepository(); //act await entryRepo.TryCreateAsync(new NPCEntryModel(1, new Vector3 <float>(5, 6, 7), 55, mapId, NpcMovementType.Stationary, 1)); await entryRepo.TryCreateAsync(new NPCEntryModel(2, new Vector3 <float>(5, 6, 7), 55, mapId, NpcMovementType.Stationary, 1)); await entryRepo.TryCreateAsync(new NPCEntryModel(3, new Vector3 <float>(5, 6, 7), 55, mapId, NpcMovementType.Stationary, 1)); IReadOnlyCollection <NPCEntryModel> entryModels = await entryRepo.RetrieveAllWithMapIdAsync(mapId); //assert Assert.AreEqual(3, entryModels.Count); Assert.False(entryModels.Any(e => e.MapId != mapId)); }
public async Task <IActionResult> GetNpcsOnMap([FromRoute(Name = "id")] int mapId, [FromServices] INpcEntryRepository entryRepository) { if (entryRepository == null) { throw new ArgumentNullException(nameof(entryRepository)); } IReadOnlyCollection <NPCEntryModel> entryModels = await entryRepository.RetrieveAllWithMapIdAsync(mapId) .ConfigureAwait(false); //TODO: Should this be an OK? if (entryModels.Count == 0) { return(Ok(new ZoneServerNPCEntryCollectionResponse(NpcEntryCollectionResponseCode.NoneFound))); } return(base.Ok(new ZoneServerNPCEntryCollectionResponse(entryModels.Select(npc => BuildDatabaseNPCEntryToTransportNPC(npc)).ToArray()))); }