public UnitOfWork(AppDbContext context) { _context = context; Worlds = new WorldRepository(_context); Books = new BookRepository(_context); Chapters = new ChapterRepository(_context); }
void LoadEntities(string worldId) { IBiomeRepository biomeRepository = new BiomeRepository(Path.Combine(ApplicationPaths.WorldsDirectory, worldId, "biomes.xml")); IBorderRepository borderRepository = new BorderRepository(Path.Combine(ApplicationPaths.WorldsDirectory, worldId, "borders.xml")); ICultureRepository cultureRepository = new CultureRepository(Path.Combine(ApplicationPaths.WorldsDirectory, worldId, "cultures.xml")); IFactionRepository factionRepository = new FactionRepository(Path.Combine(ApplicationPaths.WorldsDirectory, worldId, "factions.xml")); IFlagRepository flagRepository = new FlagRepository(Path.Combine(ApplicationPaths.WorldsDirectory, worldId, "flags.xml")); IHoldingRepository holdingRepository = new HoldingRepository(Path.Combine(ApplicationPaths.WorldsDirectory, worldId, "holdings.xml")); IProvinceRepository provinceRepository = new ProvinceRepository(Path.Combine(ApplicationPaths.WorldsDirectory, worldId, "provinces.xml")); IResourceRepository resourceRepository = new ResourceRepository(Path.Combine(ApplicationPaths.WorldsDirectory, worldId, "resources.xml")); IUnitRepository unitRepository = new UnitRepository(Path.Combine(ApplicationPaths.WorldsDirectory, worldId, "units.xml")); IWorldRepository worldRepository = new WorldRepository(ApplicationPaths.WorldsDirectory); IEnumerable <Biome> biomeList = biomeRepository.GetAll().ToDomainModels(); IEnumerable <Border> borderList = borderRepository.GetAll().ToDomainModels(); IEnumerable <Culture> cultureList = cultureRepository.GetAll().ToDomainModels(); IEnumerable <Faction> factionList = factionRepository.GetAll().ToDomainModels(); IEnumerable <Flag> flagList = flagRepository.GetAll().ToDomainModels(); IEnumerable <Province> provinceList = provinceRepository.GetAll().ToDomainModels(); IEnumerable <Resource> resourceList = resourceRepository.GetAll().ToDomainModels(); IEnumerable <Unit> unitList = unitRepository.GetAll().ToDomainModels(); armies = new ConcurrentDictionary <Tuple <string, string>, Army>(); biomes = new ConcurrentDictionary <string, Biome>(biomeList.ToDictionary(biome => biome.Id, biome => biome)); borders = new ConcurrentDictionary <Tuple <string, string>, Border>(borderList.ToDictionary(border => new Tuple <string, string>(border.SourceProvinceId, border.TargetProvinceId), border => border)); cultures = new ConcurrentDictionary <string, Culture>(cultureList.ToDictionary(culture => culture.Id, culture => culture)); factions = new ConcurrentDictionary <string, Faction>(factionList.ToDictionary(faction => faction.Id, faction => faction)); flags = new ConcurrentDictionary <string, Flag>(flagList.ToDictionary(flag => flag.Id, flag => flag)); holdings = new ConcurrentDictionary <string, Holding>(); provinces = new ConcurrentDictionary <string, Province>(provinceList.ToDictionary(province => province.Id, province => province)); relations = new ConcurrentDictionary <Tuple <string, string>, Relation>(); resources = new ConcurrentDictionary <string, Resource>(resourceList.ToDictionary(resource => resource.Id, resource => resource)); units = new ConcurrentDictionary <string, Unit>(unitList.ToDictionary(unit => unit.Id, unit => unit)); world = worldRepository.Get(worldId).ToDomainModel(); }
public void ReturnAWorld() { var repo = new WorldRepository(); var world = repo.GetWorld(); Assert.IsType <World>(world); }
public void WorldShouldHaveChunks() { var repo = new WorldRepository(); var world = repo.GetWorld(); Assert.NotEmpty(world.Chunks); }
public void WorldShouldHaveASeed() { var repo = new WorldRepository(); var world = repo.GetWorld(); Assert.NotNull(world.Seed); }
/// <summary>Creates an instance for the given language.</summary> /// <param name="culture">The culture.</param> /// <returns>A repository.</returns> public IWorldRepository ForCulture(CultureInfo culture) { Contract.Ensures(Contract.Result<IWorldRepository>() != null); IWorldRepository repository = new WorldRepository(this.serviceClient); repository.Culture = culture; return repository; }
/// <summary> /// Destroys the chunk at the given world position. /// </summary> /// <param name="position">The world position of the chunk.</param> public void DestroyChunk(WorldPosition position) { var chunk = default(Chunk); if (this.Chunks.TryGetValue(position, out chunk)) { WorldRepository.SaveChunk(chunk); UnityEngine.Object.Destroy(chunk.gameObject); this.Chunks.Remove(position); } }
public async Task IntegrationTestAddCombatResults() { // Arrange WorldRepository repository = new WorldRepository(DevelopmentStorageAccountConnectionString); Guid SessionId = new Guid("2CDE3217-B8F2-4FDA-8E7A-3B6B6FA4C747"); Guid combatId = new Guid("4B0286E6-6DBE-4F86-A87C-1CF776F41437"); Guid attackingRegionId = new Guid("4CD8D6E1-8FFE-48E1-8FE0-B89BCDD0AA96"); Guid defendingRegionId = new Guid("E0FE9A73-4125-4DA1-A113-25ED927EA7B4"); CombatTableEntry combat = new CombatTableEntry(SessionId, 1, combatId, CombatType.Invasion); combat.SetCombatArmy(new List <ICombatArmy> { new CombatArmy(attackingRegionId, "AttackingUser", Core.CombatArmyMode.Attacking, 3), new CombatArmy(defendingRegionId, "DefendingUser", Core.CombatArmyMode.Defending, 2) }); CombatResultTableEntry tableEntry = new CombatResultTableEntry(SessionId, combatId, new List <ICombatRoundResult> { new CombatRoundResult( new List <ICombatArmyRoundResult> { new CombatArmyRoundResult(attackingRegionId, "AttackingUser", new List <UInt32> { 2, 3, 4 }, 1), new CombatArmyRoundResult(defendingRegionId, "DefendingUser", new List <UInt32> { 1, 1 }, 2), } ) }); CloudTable testTable = SessionRepository.GetTableForSessionData(TableClient, SessionId); testTable.CreateIfNotExists(); // Act await repository.AddCombatResults(SessionId, 1, new List <ICombatResult> { tableEntry }); // Assert TableOperation operation = TableOperation.Retrieve <CombatResultTableEntry>(SessionId.ToString(), "Result_" + combatId.ToString()); TableResult result = await testTable.ExecuteAsync(operation); Assert.IsNotNull(result.Result); Assert.IsInstanceOfType(result.Result, typeof(CombatResultTableEntry)); CombatResultTableEntry resultStronglyTyped = result.Result as CombatResultTableEntry; AssertCombat.IsResultValid(1, combat, resultStronglyTyped); AssertCombat.IsArmyResult(attackingRegionId, 1, 1, resultStronglyTyped); AssertCombat.IsArmyResult(defendingRegionId, 1, 2, resultStronglyTyped); }
/// <summary>Creates an instance for the given language.</summary> /// <param name="culture">The culture.</param> /// <returns>A repository.</returns> public IWorldRepository ForCulture(CultureInfo culture) { if (culture == null) { throw new ArgumentNullException("culture"); } IWorldRepository repository = new WorldRepository(this.serviceClient, new CollectionConverter <WorldDTO, World>(new WorldConverter())); repository.Culture = culture; return(repository); }
/// <summary>Creates an instance for the given language.</summary> /// <param name="culture">The culture.</param> /// <returns>A repository.</returns> public override IWorldRepository ForCulture(CultureInfo culture) { var worldConverter = new WorldConverter(); var identifiersResponseConverter = new CollectionResponseConverter <int, int>(new ConverterAdapter <int>()); var responseConverter = new ResponseConverter <WorldDTO, World>(worldConverter); var bulkResponseConverter = new DictionaryRangeResponseConverter <WorldDTO, int, World>(worldConverter, value => value.WorldId); var pageResponseConverter = new CollectionPageResponseConverter <WorldDTO, World>(worldConverter); IWorldRepository repository = new WorldRepository(this.serviceClient, identifiersResponseConverter, responseConverter, bulkResponseConverter, pageResponseConverter); repository.Culture = culture; return(repository); }
public async Task <IEnumerable <ICombat> > GetCombat(Guid sessionId) { ISession session = await SessionRepository.GetSessionOrThrow(sessionId) .IsUserIdJoinedOrThrow(NationRepository, User.Identity.GetUserId()); IEnumerable <ICombat> combatData = await WorldRepository.GetCombat(session.GameId, session.Round); return(from combat in combatData where IsStillValid(session, combat) orderby combat.ResolutionType ascending select new Combat(combat)); }
public async Task IntegrationTestGetCombatByType() { // Arrange WorldRepository repository = new WorldRepository(DevelopmentStorageAccountConnectionString); Guid combatId = new Guid("B75CFB8A-727A-46C1-A952-BF2B1AFF9AD8"); Guid secondCombatId = new Guid("2F366A82-A99C-4A83-BF0E-FFF8D87D94A6"); Guid attackingRegionId = new Guid("5EA3D204-63EA-4683-913E-C5C3609BD893"); Guid defendingRegionId = new Guid("6DC3039A-CC79-4CAC-B7CE-37E1B1565A6C"); CombatTableEntry tableEntry = new CombatTableEntry(SessionId, 1, combatId, CombatType.Invasion); tableEntry.SetCombatArmy(new List <ICombatArmy> { new CombatArmy(attackingRegionId, "AttackingUser", Core.CombatArmyMode.Attacking, 5), new CombatArmy(defendingRegionId, "DefendingUser", Core.CombatArmyMode.Defending, 4) }); CombatTableEntry secondTableEntry = new CombatTableEntry(SessionId, 1, secondCombatId, CombatType.SpoilsOfWar); secondTableEntry.SetCombatArmy(new List <ICombatArmy> { new CombatArmy(attackingRegionId, "AttackingUser", Core.CombatArmyMode.Attacking, 5), new CombatArmy(defendingRegionId, "DefendingUser", Core.CombatArmyMode.Defending, 4) }); CloudTable testTable = SessionRepository.GetTableForSessionData(TableClient, SessionId); testTable.CreateIfNotExists(); TableOperation insertOperation = TableOperation.Insert(tableEntry); await testTable.ExecuteAsync(insertOperation); insertOperation = TableOperation.Insert(secondTableEntry); await testTable.ExecuteAsync(insertOperation); CombatTableEntry thirdTableEntry = new CombatTableEntry(SessionId, 2, Guid.NewGuid(), CombatType.SpoilsOfWar); insertOperation = TableOperation.Insert(thirdTableEntry); await testTable.ExecuteAsync(insertOperation); // Act var results = await repository.GetCombat(SessionId, 1, CombatType.SpoilsOfWar); // Assert Assert.IsNotNull(results); Assert.AreEqual(1, results.Count()); ICombat result = results.Where(combat => combat.CombatId == combatId).FirstOrDefault(); Assert.IsNull(result); result = results.Where(combat => combat.CombatId == secondCombatId).FirstOrDefault(); Assert.IsNotNull(result); Assert.AreEqual(CombatType.SpoilsOfWar, result.ResolutionType); }
public async Task IntegrationTestAddArmyToCombat() { // Arrange WorldRepository repository = new WorldRepository(DevelopmentStorageAccountConnectionString); Guid combatId = new Guid("0DAAF6DD-E1D6-42BA-B3ED-749BB7652C8E"); Guid attackingRegionId = new Guid("5EA3D204-63EA-4683-913E-C5C3609BD893"); Guid attacking2RegionId = new Guid("E0675161-4192-4C33-B8BB-3B6D763725E2"); Guid attacking3RegionId = new Guid("CA563328-5743-4EC0-AA39-D7978DE44872"); Guid defendingRegionId = new Guid("6DC3039A-CC79-4CAC-B7CE-37E1B1565A6C"); CombatTableEntry tableEntry = new CombatTableEntry(SessionId, 1, combatId, CombatType.MassInvasion); tableEntry.SetCombatArmy(new List <ICombatArmy> { new CombatArmy(attackingRegionId, "AttackingUser", Core.CombatArmyMode.Attacking, 5), new CombatArmy(defendingRegionId, "DefendingUser", Core.CombatArmyMode.Defending, 4) }); CloudTable testTable = SessionRepository.GetTableForSessionData(TableClient, SessionId); testTable.CreateIfNotExists(); TableOperation insertOperation = TableOperation.Insert(tableEntry); await testTable.ExecuteAsync(insertOperation); // Act using (BatchOperationHandle batchOperation = new BatchOperationHandle(testTable)) { repository.AddArmyToCombat(batchOperation, tableEntry, new List <ICombatArmy> { new CombatArmy(attacking2RegionId, "AttackingUser", Core.CombatArmyMode.Attacking, 6), new CombatArmy(attacking3RegionId, "AttackingUser2", Core.CombatArmyMode.Attacking, 3) }); } // Assert TableOperation operation = TableOperation.Retrieve <CombatTableEntry>(SessionId.ToString(), "Combat_" + combatId.ToString()); TableResult result = await testTable.ExecuteAsync(operation); Assert.IsNotNull(result.Result); Assert.IsInstanceOfType(result.Result, typeof(CombatTableEntry)); CombatTableEntry resultStronglyTyped = result.Result as CombatTableEntry; Assert.AreEqual(SessionId, resultStronglyTyped.SessionId); Assert.AreEqual(combatId, resultStronglyTyped.CombatId); Assert.AreEqual(1, resultStronglyTyped.Round); Assert.AreEqual(CombatType.MassInvasion, resultStronglyTyped.ResolutionType); Assert.AreEqual(4, resultStronglyTyped.InvolvedArmies.Count()); AssertCombat.IsAttacking(attackingRegionId, 5, "AttackingUser", resultStronglyTyped); AssertCombat.IsAttacking(attacking2RegionId, 6, "AttackingUser", resultStronglyTyped); AssertCombat.IsAttacking(attacking3RegionId, 3, "AttackingUser2", resultStronglyTyped); AssertCombat.IsDefending(defendingRegionId, 4, "DefendingUser", resultStronglyTyped); }
public ControllerAzure(String developmentStorageAccountConnectionString, String worldDefinitionPath, String userId) { OwnerId = userId; UserRepository = new DummyUserRepository(); AzureCommandQueue = new CommandQueue(developmentStorageAccountConnectionString); AzureNationRepository = new NationRepository(developmentStorageAccountConnectionString); AzureRegionRepository = new RegionRepository(developmentStorageAccountConnectionString, worldDefinitionPath); AzureSessionRepository = new SessionRepository(developmentStorageAccountConnectionString); AzureWorldRepository = new WorldRepository(developmentStorageAccountConnectionString); CreateControllers(); }
/// <summary> /// Loads the specified world. /// </summary> /// <param name="id">World identifier.</param> public void LoadWorld(string id) { WorldRepository worldRepository = new WorldRepository(ApplicationPaths.WorldsDirectory); WorldEntity worldEntity = worldRepository.Get(id); currentWorld = worldEntity.ToDomainModel(); mapMarkers = new List <MapMarker>(); terrainMap = new Terrain[currentWorld.Width, currentWorld.Height]; worldObjectMap = new WorldObject[currentWorld.Width, currentWorld.Height]; ProcessTileProperties(); ProcessMapMarkers(); }
/// <summary> /// Creates a chunk at the given position. /// </summary> /// <param name="position">The world coordinates.</param> public void CreateChunk(WorldPosition position) { var newChunkObject = UnityEngine.Object.Instantiate( World.chunkPrefab, new Vector3(position.X, position.Y, position.Z), Quaternion.Euler(Vector3.zero)) as GameObject; var newChunk = newChunkObject.GetComponent <Chunk>(); newChunk.Position = position; newChunk.World = this; this.Chunks.Add(position, newChunk); var terrainGenerator = new ChunkGenerator(); terrainGenerator.GenerateChunk(newChunk); newChunk.SetBlocksUnmodified(); WorldRepository.LoadChunk(newChunk); }
public void IntegrationTestGetRandomNumberGenerator() { // Arrange WorldRepository repository = new WorldRepository(DevelopmentStorageAccountConnectionString); // Act var randomNumbers = repository.GetRandomNumberGenerator(Guid.Empty, 1, 6).Take(100000); // Assert Assert.AreEqual(0, randomNumbers.Count(number => number < 1)); Assert.IsTrue(5000 > randomNumbers.Count(number => number == 1)); Assert.IsTrue(5000 > randomNumbers.Count(number => number == 2)); Assert.IsTrue(5000 > randomNumbers.Count(number => number == 3)); Assert.IsTrue(5000 > randomNumbers.Count(number => number == 4)); Assert.IsTrue(5000 > randomNumbers.Count(number => number == 5)); Assert.IsTrue(5000 > randomNumbers.Count(number => number == 6)); Assert.AreEqual(0, randomNumbers.Count(number => number > 6)); }
public async Task IntegrationTestGetCombatWithMultipleRounds() { // Arrange WorldRepository repository = new WorldRepository(DevelopmentStorageAccountConnectionString); Guid combatId = new Guid("3233BE80-37BA-4FBD-B07B-BB18F6E47FEE"); Guid attackingRegionId = new Guid("5EA3D204-63EA-4683-913E-C5C3609BD893"); Guid defendingRegionId = new Guid("6DC3039A-CC79-4CAC-B7CE-37E1B1565A6C"); CombatTableEntry tableEntry = new CombatTableEntry(SessionId, 5, combatId, CombatType.Invasion); tableEntry.SetCombatArmy(new List <ICombatArmy> { new CombatArmy(attackingRegionId, "AttackingUser", Core.CombatArmyMode.Attacking, 5), new CombatArmy(defendingRegionId, "DefendingUser", Core.CombatArmyMode.Defending, 4) }); CloudTable testTable = SessionRepository.GetTableForSessionData(TableClient, SessionId); testTable.CreateIfNotExists(); TableOperation insertOperation = TableOperation.Insert(tableEntry); await testTable.ExecuteAsync(insertOperation); CombatTableEntry otherRoundTableEntry = new CombatTableEntry(SessionId, 2, Guid.NewGuid(), CombatType.Invasion); insertOperation = TableOperation.Insert(otherRoundTableEntry); await testTable.ExecuteAsync(insertOperation); // Act var results = await repository.GetCombat(SessionId, 5); // Assert Assert.IsNotNull(results); Assert.AreEqual(1, results.Count()); ICombat result = results.Where(combat => combat.CombatId == combatId).FirstOrDefault(); Assert.IsNotNull(result); Assert.AreEqual(combatId, result.CombatId); Assert.AreEqual(CombatType.Invasion, result.ResolutionType); Assert.AreEqual(2, result.InvolvedArmies.Count()); AssertCombat.IsAttacking(attackingRegionId, 5, "AttackingUser", result); AssertCombat.IsDefending(defendingRegionId, 4, "DefendingUser", result); }
public async Task IntegrationTestAddCombat() { // Arrange WorldRepository repository = new WorldRepository(DevelopmentStorageAccountConnectionString); Guid attackingRegionId = new Guid("4CD8D6E1-8FFE-48E1-8FE0-B89BCDD0AA96"); Guid defendingRegionId = new Guid("E0FE9A73-4125-4DA1-A113-25ED927EA7B4"); CloudTable testTable = SessionRepository.GetTableForSessionData(TableClient, SessionId); testTable.CreateIfNotExists(); // Act using (IBatchOperationHandle batchOperation = new BatchOperationHandle(testTable)) { repository.AddCombat(batchOperation, SessionId, 2, new List <Tuple <CombatType, IEnumerable <ICombatArmy> > > { Tuple.Create <CombatType, IEnumerable <ICombatArmy> >(CombatType.MassInvasion, new List <ICombatArmy> { new CombatArmy(attackingRegionId, "AttackingUser", Core.CombatArmyMode.Attacking, 5), new CombatArmy(defendingRegionId, "DefendingUser", Core.CombatArmyMode.Defending, 4) }) }); } // Assert IEnumerable <ICombat> combatList = await repository.GetCombat(SessionId, 2); Assert.IsNotNull(combatList); Assert.AreEqual(1, combatList.Count()); ICombat combat = combatList.First(); Assert.IsInstanceOfType(combat, typeof(CombatTableEntry)); CombatTableEntry resultStronglyTyped = combat as CombatTableEntry; Assert.AreEqual(SessionId, resultStronglyTyped.SessionId); Assert.IsNotNull(resultStronglyTyped.CombatId); Assert.AreEqual(CombatType.MassInvasion, resultStronglyTyped.ResolutionType); Assert.AreEqual(2, resultStronglyTyped.InvolvedArmies.Count()); AssertCombat.IsAttacking(attackingRegionId, 5, "AttackingUser", resultStronglyTyped); AssertCombat.IsDefending(defendingRegionId, 4, "DefendingUser", resultStronglyTyped); }
/// <summary> /// Loads the content. /// </summary> public override void LoadContent() { base.LoadContent(); // TODO: Identify and retrieve the items properly worldSelector = ListSelectors.FirstOrDefault(x => x.Text == "World"); factionSelector = ListSelectors.FirstOrDefault(x => x.Text == "Faction"); startLink = Links.FirstOrDefault(x => x.Text == "Start"); worldSelector.SelectedIndexChanged += OnWorldSelectorSelectedIndexChanged; factionSelector.SelectedIndexChanged += OnFactionSelectorSelectedIndexChanged; // TODO: Do not access the repository directly from here WorldRepository worldRepository = new WorldRepository(ApplicationPaths.WorldsDirectory); // TODO: Don't load everything unnecessarily worlds = worldRepository.GetAll().ToDomainModels().ToList(); worldSelector.Values.AddRange(worlds.Select(f => f.Name)); worldSelector.SelectedIndex = 0; }
/// <summary>Creates an instance for the given language.</summary> /// <param name="culture">The culture.</param> /// <returns>A repository.</returns> public IWorldRepository ForCulture(CultureInfo culture) { if (culture == null) { throw new ArgumentNullException("culture"); } IWorldRepository repository = new WorldRepository(this.serviceClient, new CollectionConverter<WorldDTO, World>(new WorldConverter())); repository.Culture = culture; return repository; }
public WorldController() { this.worldRepository = new WorldRepository(); }
public HomeController(IConfiguration configuration) { worldRepository = new WorldRepository(configuration); }