public void UpdateState_adds_bomb() { const int entityCount = 1; const int bomb1Id = 0; const Owner2 bombOwner = Owner2.Own; const int bombOriginFactoryId = 0; const int bombDestinationFactoryId = 1; const int turnsUntilExplodes = 5; var previousState = new State(); _consoleMock .SetupSequence(c => c.ReadLine()) .Returns($"{entityCount}") .Returns($"{bomb1Id} " + $"{BombEntityType} " + $"{(int) bombOwner} " + $"{bombOriginFactoryId} " + $"{bombDestinationFactoryId} " + $"{turnsUntilExplodes}"); var state = _robot.UpdateState(previousState); var bomb = Assert.Single(state.Bombs); Assert.NotNull(bomb); Assert.Equal(bomb1Id, bomb.Id); Assert.Equal(bombOwner, bomb.Owner); Assert.Equal(bombOriginFactoryId, bomb.Origin); Assert.Equal(bombDestinationFactoryId, bomb.Destination); Assert.Equal(turnsUntilExplodes, bomb.TurnsUntilExplodes); }
public void UpdateState_adds_troop() { const int entityCount = 1; const int troop1Id = 0; const Owner2 troopOwner = Owner2.Own; const int originFactoryId = 0; const int destinationFactoryId = 1; const int numberOfCyborgs = 10; const int remainingTravelTime = 2; var previousState = new State(); _consoleMock .SetupSequence(c => c.ReadLine()) .Returns($"{entityCount}") .Returns($"{troop1Id} " + $"{TroopEntityType} " + $"{(int) troopOwner} " + $"{originFactoryId} " + $"{destinationFactoryId} " + $"{numberOfCyborgs} " + $"{remainingTravelTime}"); var state = _robot.UpdateState(previousState); var troop = Assert.Single(state.Troops); Assert.NotNull(troop); Assert.Equal(troop1Id, troop.Id); Assert.Equal(troopOwner, troop.Owner); Assert.Equal(originFactoryId, troop.Origin); Assert.Equal(destinationFactoryId, troop.Destination); Assert.Equal(numberOfCyborgs, troop.NumberOfCyborgs); Assert.Equal(remainingTravelTime, troop.RemainingTravelTime); }
public static void Main(string[] args) { var retained = Create <Retained>(7); var owner1 = new Owner1(retained[0], retained[1], retained[2], retained[5], retained[6]); var owner2 = new Owner2(retained[3], retained[4], retained[5], retained[6]); retained = null; ProfilingApi.GetSnapshot(); GC.KeepAlive(owner1); GC.KeepAlive(owner2); }
public void FindTargets_single_factory_no_link_returns_no_target(Owner2 owner) { var factory = new Factory2(Factory2Id) { Owner = owner, Production = 1, Distances = new Dictionary <int, int>() }; _state.Factories.Add(factory); var targets = _robot.FindTargets(_originFactory, _state); Assert.Empty(targets); }
public void UpdateState_updates_factory() { const int entityCount = 1; const int factory1Id = 0; const int factory2Id = 1; const int distance = 1; const Owner2 factoryOwner = Owner2.Own; const int numberOfCyborgs = 10; const int production = 1; const int turnsUntilProducing = 0; var previousFactory = new Factory2(factory1Id) { Distances = new Dictionary <int, int>() { { factory2Id, distance } } }; var previousState = new State { Factories = new List <Factory2> { previousFactory } }; _consoleMock .SetupSequence(c => c.ReadLine()) .Returns($"{entityCount}") .Returns($"{factory1Id} " + $"{FactoryEntityType} " + $"{(int) factoryOwner} " + $"{numberOfCyborgs} " + $"{production} " + $"{turnsUntilProducing}"); var state = _robot.UpdateState(previousState); var factory1 = state.Factories[factory1Id]; Assert.Equal(factory1Id, factory1.Id); Assert.Equal(factoryOwner, factory1.Owner); Assert.Equal(numberOfCyborgs, factory1.NumberOfCyborgs); Assert.Equal(previousFactory.Distances, factory1.Distances); Assert.Equal(production, factory1.Production); Assert.Equal(turnsUntilProducing, factory1.TurnsUntilProducing); }
public void UpdateState_unknown_entity_type_throws() { const int entityCount = 1; const int entityId = 1; const string unknownEntityType = "UNKNOWN"; const Owner2 entityOwner = Owner2.Own; var previousState = new State(); _consoleMock .SetupSequence(c => c.ReadLine()) .Returns($"{entityCount}") .Returns($"{entityId} " + $"{unknownEntityType} " + $"{(int) entityOwner}"); Assert.Throws <ArgumentOutOfRangeException>(() => _robot.UpdateState(previousState)); }
public void FindTargets_single_factory_link_returns_target(Owner2 owner) { var factory = new Factory2(Factory2Id) { Owner = owner, Production = 1, Distances = new Dictionary <int, int> { { Factory1Id, 1 } } }; _state.Factories.Add(factory); var targets = _robot.FindTargets(_originFactory, _state); var target = Assert.Single(targets); Assert.Equal(factory, target); }
public void UpdateVersionWithManyRootsTest() { Key owner1Key; VersionInfo owner1Version; Key owner2Key; VersionInfo owner2Version; Key itemKey; VersionInfo itemVersion; using (var session = Domain.OpenSession()) { using (var transactionScope = session.OpenTransaction()) { var owner1 = new Owner1(); var owner2 = new Owner2(); var item = new Item { Value = "Value" }; owner1Key = owner1.Key; owner2Key = owner2.Key; owner1Version = owner1.VersionInfo; owner2Version = owner2.VersionInfo; itemKey = item.Key; itemVersion = item.VersionInfo; transactionScope.Complete(); } } using (var session = Domain.OpenSession()) { using (var transactionScope = session.OpenTransaction()) { var owner1 = session.Query.Single <Owner1>(owner1Key); var owner2 = session.Query.Single <Owner2>(owner2Key); var item = session.Query.Single <Item>(itemKey); Assert.IsTrue(owner1Version == owner1.VersionInfo); Assert.IsTrue(owner2Version == owner2.VersionInfo); Assert.IsTrue(itemVersion == item.VersionInfo); item.Value = "New Value"; Assert.IsFalse(owner1Version == owner1.VersionInfo); Assert.IsFalse(owner2Version == owner2.VersionInfo); Assert.IsFalse(itemVersion == item.VersionInfo); transactionScope.Complete(); } } }
public void SerializeVersionInfoTest() { VersionInfo itemVersion; using (var session = Domain.OpenSession()) { using (var transactionScope = session.OpenTransaction()) { var owner1 = new Owner1(); var owner2 = new Owner2(); var item = new Item { Value = "Value" }; itemVersion = item.VersionInfo; transactionScope.Complete(); } } Assert.IsFalse(itemVersion.IsVoid); var clone = Cloner.Clone(itemVersion); Assert.IsFalse(clone.IsVoid); Assert.IsTrue(itemVersion == clone); }