public void DeleteTroopObject_WhenTroopObjectCreated_AddsUnitsBackToOriginalTroop( [Frozen] ITroopStub stub, [Frozen] ISimpleStub unitsToRetreat, StationedPartialTroopObjectInitializer troopInitializer) { unitsToRetreat.TotalCount.Returns <ushort>(1); stub.State.Returns(TroopState.Stationed); stub.RemoveFromFormation(FormationType.Defense, Arg.Any <ISimpleStub>()).Returns(true); stub.City.Troops.Remove(Arg.Any <ushort>()).Returns(true); var newStub = Substitute.For <ITroopStub>(); stub.City.CreateTroopStub().Returns(newStub); ITroopObject troopObject = Substitute.For <ITroopObject>(); troopObject.Stub.Returns(newStub); stub.City.CreateTroopObject(newStub, Arg.Any <uint>(), Arg.Any <uint>()).Returns(troopObject); troopInitializer.GetTroopObject(out troopObject); troopInitializer.DeleteTroopObject(); stub.Received(1).BeginUpdate(); stub.Received(1).AddAllToFormation(FormationType.Defense, newStub); stub.Received(1).EndUpdate(); }
public void GetTroopObject_WhenCannotRemoveFromExistingTroop_ReturnsError( [Frozen] ITroopStub stub, [Frozen] ISimpleStub unitsToRetreat, StationedPartialTroopObjectInitializer troopInitializer) { unitsToRetreat.TotalCount.Returns <ushort>(1); stub.State.Returns(TroopState.Stationed); stub.RemoveFromFormation(FormationType.Defense, unitsToRetreat).Returns(false); ITroopObject troopObject; troopInitializer.GetTroopObject(out troopObject).Should().Be(Error.TroopChanged); troopObject.Should().BeNull(); }
public void GetTroopObject_WhenAbleToRetreat_AddsNewTroopObjectToWorld( [Frozen] ITroopStub stub, [Frozen] IWorld world, [Frozen] ISimpleStub unitsToRetreat, StationedPartialTroopObjectInitializer troopInitializer) { unitsToRetreat.TotalCount.Returns <ushort>(1); stub.State.Returns(TroopState.Stationed); stub.RemoveFromFormation(FormationType.Defense, Arg.Any <ISimpleStub>()).Returns(true); ITroopObject troopObject; troopInitializer.GetTroopObject(out troopObject).Should().Be(Error.Ok); world.Regions.Received(1).Add(troopObject); }
public void DeleteTroopObject_WhenTroopObjectCreated_ScheduleRemovesTheTroopObject( [Frozen] ITroopStub stub, [Frozen] ISimpleStub unitsToRetreat, StationedPartialTroopObjectInitializer troopInitializer) { unitsToRetreat.TotalCount.Returns <ushort>(1); stub.State.Returns(TroopState.Stationed); stub.RemoveFromFormation(FormationType.Defense, Arg.Any <ISimpleStub>()).Returns(true); stub.City.Troops.Remove(Arg.Any <ushort>()).Returns(true); ITroopObject troopObject; troopInitializer.GetTroopObject(out troopObject); troopInitializer.DeleteTroopObject(); stub.City.Received(1).ScheduleRemove(troopObject, false); }
public Error GetTroopObject(out ITroopObject troopObject) { if (newTroopObject != null) { troopObject = newTroopObject; return(Error.Ok); } if (unitsToRetreat.TotalCount == 0) { troopObject = null; return(Error.TroopEmpty); } if (stub.State != TroopState.Stationed) { troopObject = null; return(Error.TroopNotStationed); } if (!stub.RemoveFromFormation(FormationType.Defense, unitsToRetreat)) { troopObject = null; return(Error.TroopChanged); } var newTroopStub = stub.City.CreateTroopStub(); newTroopStub.BeginUpdate(); newTroopStub.Add(unitsToRetreat); newTroopStub.EndUpdate(); newTroopObject = stub.City.CreateTroopObject(newTroopStub, stub.Station.PrimaryPosition.X, stub.Station.PrimaryPosition.Y + 1); newTroopObject.BeginUpdate(); newTroopObject.Stats = new TroopStats(formula.GetTroopRadius(stub, null), formula.GetTroopSpeed(stub)); world.Regions.Add(newTroopObject); newTroopObject.EndUpdate(); troopObject = newTroopObject; return(Error.Ok); }
public void GetTroopObject_WhenCalledTwice_ReturnsSameInstance( [Frozen] ITroopStub stub, [Frozen] ISimpleStub unitsToRetreat, StationedPartialTroopObjectInitializer troopInitializer) { unitsToRetreat.TotalCount.Returns <ushort>(1); stub.State.Returns(TroopState.Stationed); stub.RemoveFromFormation(FormationType.Defense, Arg.Any <ISimpleStub>()).Returns(true); ITroopObject troopObject; troopInitializer.GetTroopObject(out troopObject).Should().Be(Error.Ok); ITroopObject troopObject2; troopInitializer.GetTroopObject(out troopObject2).Should().Be(Error.Ok); troopObject.Should().BeSameAs(troopObject2); }
public void GetTroopObject_WhenAbleToRetreat_AddsUnitsToNewStub( [Frozen] ITroopStub stub, [Frozen] ISimpleStub unitsToRetreat, StationedPartialTroopObjectInitializer troopInitializer) { unitsToRetreat.TotalCount.Returns <ushort>(1); stub.State.Returns(TroopState.Stationed); stub.RemoveFromFormation(FormationType.Defense, unitsToRetreat).Returns(true); var newStub = Substitute.For <ITroopStub>(); stub.City.CreateTroopStub().Returns(newStub); ITroopObject troopObject; troopInitializer.GetTroopObject(out troopObject).Should().Be(Error.Ok); newStub.Received(1).BeginUpdate(); newStub.Received(1).Add(unitsToRetreat); newStub.Received(1).EndUpdate(); }
public void GetTroopObject_WhenAbleToRetreat_AddsNewTroopObjectToCity( [Frozen] ITroopStub stub, [Frozen] ISimpleStub unitsToRetreat, StationedPartialTroopObjectInitializer troopInitializer) { unitsToRetreat.TotalCount.Returns <ushort>(1); stub.State.Returns(TroopState.Stationed); stub.RemoveFromFormation(FormationType.Defense, Arg.Any <ISimpleStub>()).Returns(true); stub.Station.PrimaryPosition.Returns(new Position(10, 20)); var newStub = Substitute.For <ITroopStub>(); stub.City.CreateTroopStub().Returns(newStub); ITroopObject troopObject; troopInitializer.GetTroopObject(out troopObject).Should().Be(Error.Ok); stub.City.Received(1).CreateTroopObject(newStub, 10, 21); }
public void GetTroopObject_WhenAbleToRetreat_LoadsStats( [Frozen] ITroopStub stub, [Frozen] ISimpleStub unitsToRetreat, [FrozenMock] Formula formula, ITroopObject newTroopObject, StationedPartialTroopObjectInitializer troopInitializer) { unitsToRetreat.TotalCount.Returns <ushort>(1); formula.GetTroopRadius(stub, null).Returns <byte>(34); formula.GetTroopSpeed(stub).Returns(44); stub.State.Returns(TroopState.Stationed); stub.RemoveFromFormation(FormationType.Defense, Arg.Any <ISimpleStub>()).Returns(true); ITroopObject troopObject; troopInitializer.GetTroopObject(out troopObject).Should().Be(Error.Ok); troopObject.Stats.Speed.Should().Be(44); troopObject.Stats.AttackRadius.Should().Be(34); }
public void DeleteTroopObject_WhenTroopObjectFailsToRemoveFromCity_DoesNotAddUnitsBackToStub( [Frozen] ITroopStub stub, [Frozen] ISimpleStub unitsToRetreat, StationedPartialTroopObjectInitializer troopInitializer) { unitsToRetreat.TotalCount.Returns <ushort>(1); stub.State.Returns(TroopState.Stationed); stub.RemoveFromFormation(FormationType.Defense, Arg.Any <ISimpleStub>()).Returns(true); var newStub = Substitute.For <ITroopStub>(); newStub.TroopId.Returns <ushort>(5); stub.City.CreateTroopStub().Returns(newStub); stub.City.Troops.Remove(newStub.TroopId).Returns(false); ITroopObject troopObject; troopInitializer.GetTroopObject(out troopObject); troopInitializer.DeleteTroopObject(); stub.DidNotReceiveWithAnyArgs().AddAllToFormation(FormationType.Defense, null); }