public void Setup() { _p = new Player("Player 1"); List <Player> playerlist = new List <Player>(); playerlist.Add(_p); GameConfiguration config = testUtils.GetDefaultGameConfiguration(playerlist); config.MapConfiguration.OutpostsPerPlayer = 12; _game = new Game(config); _tm = _game.TimeMachine; _o1 = _tm.GetState().GetPlayerOutposts(_p)[0]; _o2 = _tm.GetState().GetPlayerOutposts(_p)[1]; _model1 = new GameEventModel() { EventData = new DrillMineEventData() { SourceId = _o1.GetComponent <IdentityManager>().GetId() }.ToByteString(), Id = Guid.NewGuid().ToString(), EventType = EventType.DrillMineEvent, OccursAtTick = 10 }; _model2 = new GameEventModel() { EventData = new DrillMineEventData() { SourceId = _o2.GetComponent <IdentityManager>().GetId() }.ToByteString(), Id = Guid.NewGuid().ToString(), EventType = EventType.DrillMineEvent, OccursAtTick = 20 }; }
public void TasksCompleteWhenInputsComplete() { var tardis = new TimeMachine(); var task1 = tardis.ScheduleSuccess(1, "t1"); var task2 = tardis.ScheduleSuccess(2, "t2"); var task3 = tardis.ScheduleSuccess(3, "t3"); var tasksOutOfOrder = new[] { task2, task3, task1 }; tardis.ExecuteInContext(advancer => { var inOrder = tasksOutOfOrder.InCompletionOrder().ToList(); Assert.AreEqual(TaskStatus.WaitingForActivation, inOrder[0].Status); Assert.AreEqual(TaskStatus.WaitingForActivation, inOrder[1].Status); Assert.AreEqual(TaskStatus.WaitingForActivation, inOrder[2].Status); advancer.Advance(); Assert.AreEqual(TaskStatus.RanToCompletion, inOrder[0].Status); Assert.AreEqual(TaskStatus.WaitingForActivation, inOrder[1].Status); Assert.AreEqual(TaskStatus.WaitingForActivation, inOrder[2].Status); advancer.Advance(); Assert.AreEqual(TaskStatus.RanToCompletion, inOrder[1].Status); Assert.AreEqual(TaskStatus.WaitingForActivation, inOrder[2].Status); advancer.Advance(); Assert.AreEqual(TaskStatus.RanToCompletion, inOrder[2].Status); }); }
public bool ForwardAction(TimeMachine timeMachine, GameState state) { this._combatant1Specialists = _combatant1.GetSpecialistManager().GetSpecialists(); this._combatant2Specialists = _combatant1.GetSpecialistManager().GetSpecialists(); List <Specialist> specialists = new List <Specialist>(); specialists.AddRange(_combatant1.GetSpecialistManager().GetSpecialists()); specialists.AddRange(_combatant2.GetSpecialistManager().GetSpecialists()); while (specialists.Count > 0) { Specialist topPriority = null; foreach (Specialist s in specialists) { // If any of the specialists are invalid, cancel the event. if (!Validator.ValidateSpecialist(s)) { this._eventSuccess = false; return(false); } if (topPriority == null || s.GetPriority() < topPriority.GetPriority()) { topPriority = s; } } // Apply the specialist effect to the enemey. ICombatable enemy = _combatant1.GetOwner() == topPriority.GetOwner() ? _combatant2 : _combatant1; ICombatable friendly = _combatant1.GetOwner() == topPriority.GetOwner() ? _combatant1 : _combatant2; topPriority.ApplyEffect(friendly, enemy); } return(true); }
public void CanCopyPublishedMessageToAuditQueue() { // arrange var fakeTime = DateTime.UtcNow; TimeMachine.FixTo(fakeTime); // act adapter.Bus.Publish("yo!"); // assert var message = GetMessageFromAuditQueue(); message.ShouldNotBe(null); var logicalMessages = message.Messages; var headers = message.Headers; logicalMessages.Length.ShouldBe(1); logicalMessages[0].ShouldBe("yo!"); headers.ShouldContainKeyAndValue(Headers.AuditReason, Headers.AuditReasons.Published); headers.ShouldContainKeyAndValue(Headers.AuditMessageCopyTime, fakeTime.ToString("u")); headers.ShouldContainKeyAndValue(Headers.AuditSourceQueue, InputQueueAddress); }
public void SetUp() { TimeMachine.Reset(); FakeMessageContext.Reset(); RebusLoggerFactory.Reset(); DoSetUp(); }
/// <summary> /// Creates a new game using the provided GameConfiguration. Calling this constructor will trigger /// map generation and generate the map based on the GameConfiguration that was passed into the game. /// </summary> /// <param name="gameConfiguration">Settings that determine how the game should be configured during generation.</param> public Game(GameConfiguration gameConfiguration) { // Creates a new game state and makes a time machine to reference the state GameState state = new GameState(gameConfiguration); TimeMachine = new TimeMachine(state); // Creates the map generator with a random seed MapGenerator mapGenerator = new MapGenerator(gameConfiguration); // Generate the map List <Outpost> outpostsToGenerate = mapGenerator.GenerateMap(); // Add factory driller production events to the time machine. // TODO: Make this better. foreach (Outpost o in outpostsToGenerate) { if (o.GetOutpostType() == OutpostType.Factory) { TimeMachine.AddEvent(new FactoryProduceDrillersEvent(o, state.GetCurrentTick().Advance(36))); } } // Add the outposts to the map state.GetOutposts().AddRange(outpostsToGenerate); }
public void CanRemoveMultipleTimeoutsAtOnce() { var justSomeUtcTimeStamp = new DateTime(2010, 3, 10, 12, 30, 15, DateTimeKind.Utc); storage.Add(new Timeout.Timeout { CorrelationId = "first", ReplyTo = "somebody", TimeToReturn = justSomeUtcTimeStamp, CustomData = null, }); storage.Add(new Timeout.Timeout { CorrelationId = "second", ReplyTo = "somebody", TimeToReturn = justSomeUtcTimeStamp, CustomData = null, }); TimeMachine.FixTo(justSomeUtcTimeStamp.AddSeconds(1)); var dueTimeoutsAfterFirstTimeout = storage.RemoveDueTimeouts(); dueTimeoutsAfterFirstTimeout.Count().ShouldBe(2); }
public void InCompletionOrder_HandlesCanceledTasks() { var timeMachine = new TimeMachine(); var task1 = timeMachine.AddCancelTask<int>(2); var task2 = timeMachine.AddCancelTask<int>(1); var tasks = new List<Task<int>> { task1, task2 }; foreach (var task in tasks.InCompletionOrder()) { task.IsCompleted.Should().BeFalse("the task hasn't completed yet"); } // step 1 timeMachine.AdvanceTo(1); task2.IsCompleted.Should().BeTrue("because the task has completed"); task2.IsCanceled.Should().BeTrue("because the task was canceled"); // step 2 timeMachine.AdvanceTo(2); task1.IsCompleted.Should().BeTrue("because the task has completed"); task1.IsCanceled.Should().BeTrue("because the task was canceled"); }
public void Can_Find_Time_Interval_Where_Martys_Meet_Each_Other() { // Arrange var time1 = DateTime.Parse("1985-10-21T10:05:00Z"); var time2 = DateTime.Parse("1985-10-21T10:10:00Z"); var time3 = DateTime.Parse("1985-10-21T10:09:00Z"); var time4 = DateTime.Parse("1985-10-21T10:17:00Z"); var expectedInterval = new TimePeriod(time3, time2); var events = (new List <DateTime>(4) { time1, time3, time2, time4 }) //.OrderBy(dateTime => dateTime) .Select(dateTime => new TimeEvent(dateTime)); GroupOfMarty gom = new GroupOfMarty(); var marty1 = new Marty("MartyTimeline1", new List <(DateTime, DateTime)> { (time1, time2) }); var marty2 = new Marty("MartyTimeline2", new List <(DateTime, DateTime)> { (time3, time4) }); gom.AddMarty(marty1); gom.AddMarty(marty2); var deloreane = new TimeMachine(); //Act MartysMeetEachOther mmeo = deloreane.PlayWithTime(gom, events); // Assert Assert.Single(mmeo.TimePeriods); Assert.Equal(mmeo.TimePeriods[0], expectedInterval); }
/// <summary> /// Creates a new game using the provided GameConfiguration. Calling this constructor will trigger /// map generation and generate the map based on the GameConfiguration that was passed into the game. /// </summary> /// <param name="gameConfiguration">Settings that determine how the game should be configured during generation.</param> public Game(GameConfiguration gameConfiguration) { SeededRandom = new SeededRandom(gameConfiguration.MapConfiguration.Seed); // Creates a new game state and makes a time machine to reference the state GameState.GameState state = new GameState.GameState(gameConfiguration); TimeMachine = new TimeMachine(state); // Creates the map generator with a random seed MapGenerator mapGenerator = new MapGenerator(gameConfiguration.MapConfiguration, state.GetPlayers()); // Generate the map List <Outpost> generatedOutposts = mapGenerator.GenerateMap(); // Add the outposts to the map state.GetOutposts().AddRange(generatedOutposts); // Populate the specialist pool SpecialistPool = new SpecialistPool(SeededRandom, gameConfiguration.GameSettings.AllowedSpecialists.ToList()); // All owned factories should start producing drillers foreach (Outpost o in generatedOutposts) { if (o is Factory && o.GetComponent <DrillerCarrier>().GetOwner() != null) { Factory f = (Factory)o; TimeMachine.AddEvent(new FactoryProduction(f, f.GetTicksToFirstProduction())); } } }
public void Sync_command() { settings.LastSync = DateTime.MinValue; var stock = new Stock { Product = "Папаверин", Status = StockStatus.Available, Address = address, Quantity = 5, ReservedQuantity = 0, SupplyQuantity = 5 }; User User = session?.Query <User>()?.FirstOrDefault() ?? new User { SupportHours = "будни: с 07:00 до 19:00", SupportPhone = "тел.: 473-260-60-00", }; localSession.Save(stock); var doc = new InventoryDoc(address, User); doc.Lines.Add(new InventoryLine(doc, stock, 1, localSession)); doc.UpdateStat(); doc.Post(); localSession.Save(doc); Run(new SyncCommand()); TimeMachine.ToFuture(TimeSpan.FromMinutes(10)); doc.UnPost(); doc.Post(); Run(new SyncCommand()); }
public bool BackwardAction(TimeMachine timeMachine, GameState.GameState state) { if (!_eventSuccess) { return(false); } List <Specialist> specialists = new List <Specialist>(); specialists.AddRange(_combatant1Specialists); specialists.AddRange(_combatant2Specialists); while (specialists.Count > 0) { Specialist lowPriority = null; foreach (Specialist s in specialists) { if (lowPriority == null || s.GetPriority() >= lowPriority.GetPriority()) { lowPriority = s; } } // Apply the specialist effect to the enemey. Entity enemy = lowPriority != null && _combatant1.GetComponent <DrillerCarrier>().GetOwner() == lowPriority.GetOwner() ? _combatant2 : _combatant1; Entity friendly = lowPriority != null && _combatant1.GetComponent <DrillerCarrier>().GetOwner() == lowPriority.GetOwner() ? _combatant1 : _combatant2; if (lowPriority != null) { lowPriority.UndoEffect(state, friendly, enemy); } } return(true); }
public void PublishedMessageIsCopiedOnlyOnceRegardlessOfNumberOfSubscribers() { // arrange var fakeTime = DateTime.UtcNow; TimeMachine.FixTo(fakeTime); SetUpSubscriberThatDoesNotAuditMessages("test.audit.subscriber1"); SetUpSubscriberThatDoesNotAuditMessages("test.audit.subscriber2"); SetUpSubscriberThatDoesNotAuditMessages("test.audit.subscriber3"); // act adapter.Bus.Publish("yo!"); // assert var messages = MsmqTestHelper.GetMessagesFrom(AuditQueueName).ToList(); Console.WriteLine(string.Join(Environment.NewLine, messages)); messages.Count.ShouldBe(4); var stringMessages = messages.Where(m => m.Messages[0] is string).ToList(); Assert.That(stringMessages.Count, Is.EqualTo(1), "We should have only one single copy of the published messages!"); }
public async void Should_unblock_one_or_more_delays() { var task = Task.Run(() => { TimeMachine.UnblockOneOrMoreDelays(); }); await TimeMachine.Delay(10000000); }
private static ThrottlerService CreateThrottleService(TimeMachine timeMachine) { var store = new TestCounterStore(); var throttlerService = new ThrottlerService(store, timeMachine); return(throttlerService); }
public void DoesNotActuallyRemoveTimeoutUntilItIsMarkedAsProcessed() { // arrange const string someRecognizablePieceOfCustomData = "this custom dizzle can be recognizzle!!"; var actualTimeWhenIWroteThis = new DateTime(2012, 11, 30, 22, 13, 00, DateTimeKind.Utc); storage.Add(new Rebus.Timeout.Timeout("someone", "wham!", actualTimeWhenIWroteThis.AddSeconds(20), Guid.Empty, someRecognizablePieceOfCustomData)); TimeMachine.FixTo(actualTimeWhenIWroteThis.AddSeconds(25)); // act List <DueTimeout> dueTimeoutsFromFirstCall; using (var dueTimeoutsResult = storage.GetDueTimeouts()) { dueTimeoutsFromFirstCall = dueTimeoutsResult.DueTimeouts.ToList(); } // this is where we'd have marked the due timeout as processed - instead, we pretend that didn't happen // (perhaps because the timeout service was interrupted) ... List <DueTimeout> dueTimeoutsFromSecondCall; using (var nextDueTimeoutsResult = storage.GetDueTimeouts()) { dueTimeoutsFromSecondCall = nextDueTimeoutsResult.DueTimeouts.ToList(); } // assert dueTimeoutsFromFirstCall.Count.ShouldBe(1); dueTimeoutsFromFirstCall.Single().CustomData.ShouldBe(someRecognizablePieceOfCustomData); dueTimeoutsFromSecondCall.Count().ShouldBe(1); dueTimeoutsFromSecondCall.Single().CustomData.ShouldBe(someRecognizablePieceOfCustomData); }
public override bool ForwardAction(TimeMachine timeMachine, GameState state) { if (!Validator.ValidateICombatable(state, _combatant1) || !Validator.ValidateICombatable(state, _combatant2)) { this.EventSuccess = false; return(false); } // Determine additional events that should be triggered for this particular combat. if (_combatant1.GetOwner() == _combatant2.GetOwner()) { this._actions.Add(new FriendlySubArrive(_combatant1, _combatant2)); } else { this._actions.Add(new SpecialistCombat(_combatant1, _combatant2)); this._actions.Add(new DrillerCombat(_combatant1, _combatant2)); this._actions.Add(new CombatCleanup(_combatant1, _combatant2)); } foreach (IReversible action in this._actions) { action.ForwardAction(timeMachine, state); } this.EventSuccess = true; return(true); }
public override bool ForwardAction(TimeMachine timeMachine, GameState.GameState state) { Entity drillLocation = state.GetEntity(GetEventData().SourceId); if (drillLocation != null && drillLocation is Outpost && !(drillLocation is Mine) && !((Outpost)drillLocation).GetComponent <DrillerCarrier>().IsDestroyed()) { _original = (Outpost)drillLocation; var drillerCarrier = drillLocation.GetComponent <DrillerCarrier>(); if (state.GetOutposts().Contains(_original) && !drillerCarrier.GetOwner().IsEliminated() && drillerCarrier.GetDrillerCount() >= drillerCarrier.GetOwner().GetRequiredDrillersToMine()) { _drilledMine = new Mine(_original); if (state.ReplaceOutpost(_original, _drilledMine)) { drillerCarrier.RemoveDrillers(drillerCarrier.GetOwner().GetRequiredDrillersToMine()); drillerCarrier.GetOwner().AlterMinesDrilled(1); timeMachine.AddEvent(new NeptuniumProductionEvent(_drilledMine, GetOccursAt().Advance(Mine.TICKS_PER_PRODUCTION_PER_MINE / state.GetPlayerOutposts(drillerCarrier.GetOwner()).Count))); EventSuccess = true; } } } else { EventSuccess = false; } return(EventSuccess); }
public void Shoul_replace_now() { var fixedDate = new DateTime(2015, 1, 1); TimeMachine.OverrideNowWith(() => fixedDate); Assert.Equal(fixedDate, TimeMachine.Now); }
public void CanCopySuccessfullyHandledMessageToAuditQueue() { // arrange var fakeTime = DateTime.UtcNow; TimeMachine.FixTo(fakeTime); var resetEvent = new ManualResetEvent(false); adapter.Handle<string>(str => resetEvent.Set()); // act adapter.Bus.SendLocal("yo!"); // assert var message = GetMessageFromAuditQueue(); message.ShouldNotBe(null); var logicalMessages = message.Messages; var headers = message.Headers; logicalMessages.Length.ShouldBe(1); logicalMessages[0].ShouldBe("yo!"); headers.ShouldContainKeyAndValue(Headers.AuditReason, Headers.AuditReasons.Handled); headers.ShouldContainKeyAndValue(Headers.AuditMessageCopyTime, fakeTime.ToString("u")); headers.ShouldContainKeyAndValue(Headers.AuditSourceQueue, InputQueueAddress); }
public void BasicDispatchOfSomeEvents() { var allPotatoesView = new MongoDbViewManager <AllPotatoesView>(_mongoDatabase); var potatoTimeToBeConsumedView = new MongoDbViewManager <PotatoTimeToBeConsumedView>(_mongoDatabase); _dispatcher.AddViewManager(allPotatoesView); _dispatcher.AddViewManager(potatoTimeToBeConsumedView); // act var firstPointInTime = new DateTime(1979, 3, 1, 12, 0, 0, DateTimeKind.Utc); TimeMachine.FixCurrentTimeTo(firstPointInTime); _commandProcessor.ProcessCommand(new BitePotato("potato1", 0.5m)); _commandProcessor.ProcessCommand(new BitePotato("potato2", 0.3m)); _commandProcessor.ProcessCommand(new BitePotato("potato2", 0.3m)); _commandProcessor.ProcessCommand(new BitePotato("potato3", 0.3m)); var nextPointInTime = new DateTime(1981, 6, 9, 12, 0, 0, DateTimeKind.Utc); TimeMachine.FixCurrentTimeTo(nextPointInTime); _commandProcessor.ProcessCommand(new BitePotato("potato1", 0.5m)); _commandProcessor.ProcessCommand(new BitePotato("potato2", 0.5m)); var lastPointInTime = new DateTime(1981, 6, 9, 12, 0, 0, DateTimeKind.Utc); _commandProcessor.ProcessCommand(new BitePotato("potato3", 0.8m)); Thread.Sleep(1000); // assert var allPotatoes = allPotatoesView.Load(GlobalInstanceLocator.GetViewInstanceId()); Assert.That(allPotatoes, Is.Not.Null); var potato1View = potatoTimeToBeConsumedView.Load(InstancePerAggregateRootLocator.GetViewIdFromAggregateRootId("potato1")); var potato2View = potatoTimeToBeConsumedView.Load(InstancePerAggregateRootLocator.GetViewIdFromAggregateRootId("potato2")); var potato3View = potatoTimeToBeConsumedView.Load(InstancePerAggregateRootLocator.GetViewIdFromAggregateRootId("potato3")); Assert.That(potato1View, Is.Not.Null); Assert.That(potato2View, Is.Not.Null); Assert.That(potato3View, Is.Not.Null); Assert.That(allPotatoes.NamesOfPotatoes.Count, Is.EqualTo(3)); Assert.That(allPotatoes.NamesOfPotatoes["potato1"], Is.EqualTo("Jeff")); Assert.That(allPotatoes.NamesOfPotatoes["potato2"], Is.EqualTo("Bunny")); Assert.That(allPotatoes.NamesOfPotatoes["potato3"], Is.EqualTo("Walter")); Assert.That(potato1View.Name, Is.EqualTo("Jeff")); Assert.That(potato1View.TimeOfCreation.ToUniversalTime(), Is.EqualTo(firstPointInTime)); Assert.That(potato1View.TimeToBeEaten, Is.EqualTo(nextPointInTime - firstPointInTime)); Assert.That(potato2View.Name, Is.EqualTo("Bunny")); Assert.That(potato2View.TimeOfCreation.ToUniversalTime(), Is.EqualTo(firstPointInTime)); Assert.That(potato2View.TimeToBeEaten, Is.EqualTo(nextPointInTime - firstPointInTime)); Assert.That(potato3View.Name, Is.EqualTo("Walter")); Assert.That(potato3View.TimeOfCreation.ToUniversalTime(), Is.EqualTo(firstPointInTime)); Assert.That(potato3View.TimeToBeEaten, Is.EqualTo(lastPointInTime - firstPointInTime)); }
public void Replan_job() { job.Plan(PlanPeriod.Month, 1.Day()); Assert.That(job.Run(), Is.True); job.Plan(PlanPeriod.Month, 10.Day()); TimeMachine.ToFuture(9.Days()); Assert.That(job.Run(), Is.True); }
public override bool BackwardAction(TimeMachine timeMachine, GameState.GameState state) { if (EventSuccess) { _mine.GetComponent <DrillerCarrier>().GetOwner().AlterNeptunium(-1); } return(EventSuccess); }
public void Setup() { timeService = new TimeMachine(); IWebServerConfiguration configuration = MockRepository.GenerateStub <IWebServerConfiguration>(); configuration.Stub(x => x.WebServerDevelopmentMode).Return(false); context = new FakeWebContext(null, null, null, timeService, configuration); }
public override string GetInteractionName(Sim actor, TimeMachine target, InteractionObjectPair iop) { if (GameUtils.IsFutureWorld()) { return(TimePortal.LocalizeString("TravelHome", new object[0x0])); } return(TimePortal.LocalizeString("Travel", new object[0x0])); }
public void SetUp() { TimeMachine.Reset(); toDispose = new List <IDisposable>(); DoSetUp(); }
public DynamicTests() { eventJournal = Substitute.For <IEventJournal>(); var timeMachine = new TimeMachine <TestEntity>(eventJournal); entity = new TestEntity(11, "John Doe"); wrapper = timeMachine.Wrap(entity); }
public void CanStoreAndRemoveTimeouts() { var someUtcTimeStamp = new DateTime(2010, 3, 10, 12, 30, 15, DateTimeKind.Utc); var anotherUtcTimeStamp = someUtcTimeStamp.AddHours(2); var thirtytwoKilobytesOfDollarSigns = new string('$', 32768); storage.Add(new Rebus.Timeout.Timeout("somebody", "first", someUtcTimeStamp, new Guid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"), null)); storage.Add(new Rebus.Timeout.Timeout("somebody", "second", anotherUtcTimeStamp, new Guid("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"), thirtytwoKilobytesOfDollarSigns)); TimeMachine.FixTo(someUtcTimeStamp.AddSeconds(-1)); var dueTimeoutsBeforeTimeout = GetTimeouts(); dueTimeoutsBeforeTimeout.Count().ShouldBe(0); TimeMachine.FixTo(someUtcTimeStamp.AddSeconds(1)); using (var firstTimeoutsResult = storage.GetDueTimeouts()) { var dueTimeoutsAfterFirstTimeout = firstTimeoutsResult.DueTimeouts; var firstTimeout = dueTimeoutsAfterFirstTimeout.SingleOrDefault(); firstTimeout.ShouldNotBe(null); firstTimeout.SagaId.ShouldBe(new Guid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa")); firstTimeout.CorrelationId.ShouldBe("first"); firstTimeout.ReplyTo.ShouldBe("somebody"); firstTimeout.TimeToReturn.ShouldBe(someUtcTimeStamp); firstTimeout.MarkAsProcessed(); } var dueTimeoutsAfterHavingMarkingTheFirstTimeoutAsProcessed = GetTimeouts(); dueTimeoutsAfterHavingMarkingTheFirstTimeoutAsProcessed.Count().ShouldBe(0); TimeMachine.FixTo(anotherUtcTimeStamp.AddSeconds(1)); using (var secondTimeoutsResult = storage.GetDueTimeouts()) { var dueTimeoutsAfterSecondTimeout = secondTimeoutsResult.DueTimeouts; var secondTimeout = dueTimeoutsAfterSecondTimeout.SingleOrDefault(); secondTimeout.ShouldNotBe(null); secondTimeout.SagaId.ShouldBe(new Guid("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb")); secondTimeout.CorrelationId.ShouldBe("second"); secondTimeout.ReplyTo.ShouldBe("somebody"); secondTimeout.TimeToReturn.ShouldBe(anotherUtcTimeStamp); secondTimeout.CustomData.ShouldBe(thirtytwoKilobytesOfDollarSigns); secondTimeout.MarkAsProcessed(); } GetTimeouts().Count().ShouldBe(0); }
public override bool BackwardAction(TimeMachine timeMachine, GameState.GameState state) { if (EventSuccess) { _producingFactory.GetComponent <DrillerCarrier>().RemoveDrillers(_productionAmount); return(true); } return(false); }
protected override bool Satisfies(Sim actor, Sim target, TimeMachine obj, bool isAutonomous, ref GreyedOutTooltipCallback callback) { if (!base.Satisfies(actor, target, obj, isAutonomous, ref callback)) { return(false); } return(CommonPregnancy.SatisfiesTryForBaby(actor, target, "TimeMachineTryForBaby", isAutonomous, true, ref callback)); }
public bool TestUse(TimeMachine obj) { if (!TestRepaired(obj)) { return(false); } return(obj.UseCount == 0 && obj.InWorld); }
public ThrottlerMiddleware CreateMiddleware(ThrottleOptions throttleOptions, TimeMachine timeMachine, RequestDelegate next) { var options = Options.Create(throttleOptions); var throttlerService = CreateThrottleService(timeMachine); var throttlePolicyProvider = new DefaultThrottlePolicyProvider(options); var middleware = new ThrottlerMiddleware(next, throttlerService, throttlePolicyProvider, options, timeMachine, NullLogger <ThrottlerMiddleware> .Instance); return(middleware); }
public void InCompletionOrder_ReturnsSuccessfulTasksInOrder() { var timeMachine = new TimeMachine(); var task1 = timeMachine.AddSuccessTask(3, 'a'); var task2 = timeMachine.AddSuccessTask(1, 'b'); var task3 = timeMachine.AddSuccessTask(2, 'c'); var tasks = new List<Task<char>> { task1, task2, task3 }; foreach (var task in tasks) { task.IsCompleted.Should().BeFalse("the task hasn't completed yet"); } var inorder = tasks.InCompletionOrder(); // step 1 timeMachine.AdvanceTo(1); task2.IsCompleted.Should().BeTrue("because the task has completed"); // step 2 timeMachine.AdvanceTo(2); task3.IsCompleted.Should().BeTrue("because the task has completed"); // step 3 timeMachine.AdvanceTo(3); task1.IsCompleted.Should().BeTrue("because the task has completed"); // check order using (var enumerator = inorder.GetEnumerator()) { enumerator.MoveNext(); enumerator.Current.Result.Should().Be('b', "because task2 completed first"); enumerator.MoveNext(); enumerator.Current.Result.Should().Be('c', "because task3 completed second"); enumerator.MoveNext(); enumerator.Current.Result.Should().Be('a', "because task1 completed last"); } }
public void TasksCompleteInOrder() { var tardis = new TimeMachine(); var task1 = tardis.ScheduleSuccess(1, "t1"); var task2 = tardis.ScheduleSuccess(2, "t2"); var task3 = tardis.ScheduleSuccess(3, "t3"); var tasksOutOfOrder = new[] { task2, task3, task1 }; tardis.ExecuteInContext(advancer => { var inOrder = tasksOutOfOrder.InCompletionOrder().ToList(); advancer.AdvanceTo(3); // Could use CollectionAssert here, but this is simpler... Assert.AreEqual("t1", inOrder[0].Result); Assert.AreEqual("t2", inOrder[1].Result); Assert.AreEqual("t3", inOrder[2].Result); }); }
public void MixedResults() { string message = "message"; var tardis = new TimeMachine(); var task1 = tardis.ScheduleSuccess(1, "t1"); var task2 = tardis.ScheduleFault<string>(2, new Exception(message)); var task3 = tardis.ScheduleCancellation<string>(3); var tasksOutOfOrder = new[] { task2, task3, task1 }; tardis.ExecuteInContext(advancer => { var inOrder = tasksOutOfOrder.InCompletionOrder().ToList(); advancer.AdvanceTo(3); // Could use CollectionAssert here, but this is simpler... Assert.AreEqual(TaskStatus.RanToCompletion, inOrder[0].Status); Assert.AreEqual(TaskStatus.Faulted, inOrder[1].Status); Assert.AreEqual(message, inOrder[1].Exception.InnerExceptions[0].Message); Assert.AreEqual(TaskStatus.Canceled, inOrder[2].Status); }); }
public override string GetInteractionName(Sim actor, TimeMachine target, InteractionObjectPair iop) { if (GameUtils.IsFutureWorld()) { return TimePortal.LocalizeString("TravelHome", new object[0x0]); } return (TimePortal.LocalizeString("TravelWith", new object[0x0]) + Localization.Ellipsis); }
public override void AddInteractions(InteractionObjectPair iop, Sim actor, TimeMachine target, List<InteractionObjectPair> results) { // Override base class if (iop.CheckIfInteractionValid()) { results.Add(iop); } }
public override bool Test(Sim actor, TimeMachine target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback) { if (!GameUtils.IsInstalled(ProductVersion.EP11)) { greyedOutTooltipCallback = Common.DebugTooltip("Pack Fail"); return false; } if (actor.BuffManager.HasElement(BuffNames.TimeTraveled)) { greyedOutTooltipCallback = InteractionInstance.CreateTooltipCallback(TimeMachine.LocalizeString("TimeTravelGreyedOutTooltip", new object[] { actor })); return false; } return TimePortalTravelWithEx.Definition.PublicTest(actor, target, isAutonomous, ref greyedOutTooltipCallback); }
public void InCompletionOrder_HandlesFaultedTasks() { var timeMachine = new TimeMachine(); var task1 = timeMachine.AddFaultingTask<int>(2, new Exception("oops")); var task2 = timeMachine.AddFaultingTask<int>(1, new Exception("whoa")); var tasks = new List<Task<int>> { task1, task2 }; foreach (var task in tasks.InCompletionOrder()) { task.IsCompleted.Should().BeFalse("the task hasn't completed yet"); } // step 1 timeMachine.AdvanceBy(1); task2.IsCompleted.Should().BeTrue("because the task has completed"); task2.IsFaulted.Should().BeTrue("because the task was canceled"); // step 2 timeMachine.AdvanceBy(2); task1.IsCompleted.Should().BeTrue("because the task has completed"); task1.IsFaulted.Should().BeTrue("because the task was canceled"); }