public void TestNestedObject() { // Arrange var targetObject = new SimpleObjectWithNestedObject() { NestedObject = new NestedObject() { StringProperty = "B" } }; var testNested = new NestedObject() { StringProperty = "B" }; var patchDocument = new JsonPatchDocument <SimpleObjectWithNestedObject>(); patchDocument.Test(o => o.NestedObject, testNested); // Act patchDocument.ApplyTo(targetObject); // Assert Assert.Equal("B", targetObject.NestedObject.StringProperty); }
private void UpdateOnChanged(NestedObject obj) { if (Changed != null) { Changed(obj); } }
private void WorkshopRemoved(NestedObject nestedObject) { string oldProductionChainName = nestedObject.Parameters[CurProductionChainParamName].Value; // unlock all inventories at input if there is something left UnlockInventoryAtInput(ParentNestedObject, GetProductionChainByName(oldProductionChainName)); }
public void NestedObjectSearch() { var obj = new NestedObject() { Prop1 = new Holder <string>() { Value = "A B" } }; var obj2 = new NestedObject() { Prop1 = new Holder <string>() { Value = "B C" } }; var list = new List <NestedObject> { obj, obj2 }; var result = ObjectTextSearcher.FindMatches(list, "a"); result.Should().HaveCount(1); var result2 = ObjectTextSearcher.FindMatches(list, "b"); result2.Should().HaveCount(2); var result3 = ObjectTextSearcher.FindMatches(list, "d"); result3.Should().HaveCount(0); }
public void DeregisterSinkOrSource(NestedObject provider) { if (sinksAndSources.ContainsKey(provider)) { sinksAndSources.Remove(provider); } }
public void ShouldNotBeAbleToAdd_ToNonExistingProperty_ThatIsNotTheRoot() { //Adding to a Nonexistent Target // // An example target JSON document: // { "foo": "bar" } // A JSON Patch document: // [ // { "op": "add", "path": "/baz/bat", "value": "qux" } // ] // This JSON Patch document, applied to the target JSON document above, // would result in an error (therefore, it would not be applied), // because the "add" operation's target location that references neither // the root of the document, nor a member of an existing object, nor a // member of an existing array. // Arrange var nestedObject = new NestedObject() { DynamicProperty = new DynamicTestObject() }; var patchDocument = new JsonPatchDocument(); patchDocument.Add("DynamicProperty/OtherProperty/IntProperty", 1); // Act var exception = Assert.Throws <JsonPatchException>(() => { patchDocument.ApplyTo(nestedObject); }); // Assert Assert.Equal("The target location specified by path segment 'OtherProperty' was not found.", exception.Message); }
public SimpleObjectWithNestedObject() { NestedObject = new NestedObject(); SimpleObject = new SimpleObject(); InheritedObject = new InheritedObject(); SimpleObjectList = new List <SimpleObject>(); }
private static IEnumerable <ReportableData> GenerateReportableData() { var toReturn = new List <ReportableData>(); for (int i = 0; i <= 10; i++) { var reportableData = new ReportableData(); reportableData.ClientId = "Test Client"; reportableData.PortfolioId = "000111000"; reportableData.ReturnPct = i; reportableData.AsOfDate = "Some Date"; reportableData.LossResultId = 101; var twrSeries = new List <TwrSeriesReportableData>(); for (int j = 0; j <= 10; j++) { var twr = GenerateTwrSeriesReportableData(); twr.AccPeriodBasTwrAtMarketPrice = j; twrSeries.Add(twr); } reportableData.TwrSeries = twrSeries; var nestedObj = new NestedObject(); nestedObj.NestedObjectDesc = "Some Desc"; nestedObj.NestedObjectValue = 8850; reportableData.NestedObject = nestedObj; toReturn.Add(reportableData); } return(toReturn); }
private void ShowWorkSpotSpriteAtTile(string nestedObjectType, Tile tile) { NestedObject proto = PrototypeManager.NestedObject.Get(nestedObjectType); // if the workspot is inside the NestedObject, there's no reason to show it separately if (proto.Jobs.WorkSpotOffset.x >= 0 && proto.Jobs.WorkSpotOffset.x < proto.Width && proto.Jobs.WorkSpotOffset.y >= 0 && proto.Jobs.WorkSpotOffset.y < proto.Height) { return; } GameObject go = new GameObject(); go.transform.SetParent(nestedObjectParent.transform, true); dragPreviewGameObjects.Add(go); SpriteRenderer sr = go.AddComponent <SpriteRenderer>(); sr.sortingLayerName = "Jobs"; sr.sprite = SpriteManager.GetSprite("UI", "WorkSpotIndicator"); if (World.Current.NestedObjectManager.IsPlacementValid(nestedObjectType, tile) && World.Current.NestedObjectManager.IsWorkSpotClear(nestedObjectType, tile) && bmc.DoesBuildJobOverlapExistingBuildJob(tile, nestedObjectType) == false) { sr.color = new Color(0.5f, 1f, 0.5f, 0.25f); } else { sr.color = new Color(1f, 0.5f, 0.5f, 0.25f); } go.transform.position = new Vector3(tile.X + proto.Jobs.WorkSpotOffset.x, tile.Y + proto.Jobs.WorkSpotOffset.y, WorldController.Instance.cameraController.CurrentLayer); }
public void GivenValidNestedStructure_WhenValidateRecursively_ThenCorrectValidationResults() { RecursiveValidator validator = new RecursiveValidator(null); List <ValidationResult> results = validator.ValidateObjectRecursively(NestedObject.Valid()); Assert.Empty(results); }
public void ReplaceNestedObject_WithSerialization() { // Arrange var targetObject = new SimpleObjectWithNestedObject() { IntegerValue = 1 }; var newNested = new NestedObject() { StringProperty = "B" }; var patchDocument = new JsonPatchDocument <SimpleObjectWithNestedObject>(); patchDocument.Replace(o => o.NestedObject, newNested); var serialized = JsonConvert.SerializeObject(patchDocument); var deserialized = JsonConvert.DeserializeObject <JsonPatchDocument <SimpleObjectWithNestedObject> >(serialized); // Act deserialized.ApplyTo(targetObject); // Assert Assert.Equal("B", targetObject.NestedObject.StringProperty); }
private void ChangeCurrentProductionChain(NestedObject nestedObject, string newProductionChainName) { string oldProductionChainName = nestedObject.Parameters[CurProductionChainParamName].Value; bool isProcessing = nestedObject.Parameters[CurProcessedInvParamName].ToInt() > 0; // if selected production really changes and nothing is being processed now if (isProcessing || newProductionChainName.Equals(oldProductionChainName)) { return; } nestedObject.Jobs.CancelAll(); nestedObject.Parameters[CurProductionChainParamName].SetValue(newProductionChainName); // unlock all inventories at input if there is something left ProductionChain oldProdChain = GetProductionChainByName(oldProductionChainName); if (oldProdChain != null) { UnlockInventoryAtInput(nestedObject, oldProdChain); } else { Debug.ULogWarningChannel(ComponentLogChannel, "Workshop old production chain is null for some reason."); } }
private void ShowPreviews(DragParameters dragParams) { for (int x = dragParams.StartX; x <= dragParams.EndX; x++) { for (int y = dragParams.StartY; y <= dragParams.EndY; y++) { Tile t = WorldController.Instance.World.GetTileAt(x, y, WorldController.Instance.cameraController.CurrentLayer); if (t != null) { // Display the building hint on top of this tile position. if (bmc.buildMode == BuildMode.NESTEDOBJECT) { NestedObject proto = PrototypeManager.NestedObject.Get(bmc.buildModeType); if (IsPartOfDrag(t, dragParams, proto.DragType)) { ShowNestedObjectSpriteAtTile(bmc.buildModeType, t); ShowWorkSpotSpriteAtTile(bmc.buildModeType, t); } } else if (bmc.buildMode == BuildMode.UTILITY) { Utility proto = PrototypeManager.Utility.Get(bmc.buildModeType); if (IsPartOfDrag(t, dragParams, proto.DragType)) { ShowUtilitySpriteAtTile(bmc.buildModeType, t); } } else { ShowGenericVisuals(x, y); } } } } }
public void RegisterSinkOrSource(NestedObject provider) { // TODO: This need to be implemented. sinksAndSources[provider] = (float deltaTime) => { provider.EventActions.Trigger("OnUpdateTemperature", provider, deltaTime); }; }
/// <summary> /// Berths the ship at this berth. Cahgnes state of ship. Ship berthing should always be handled /// through this function to make sure the states are properly updated on both sides. /// </summary> /// <param name="berth">The berth NestedObject object.</param> /// <param name="ship">The ship to berth.</param> public void BerthShip(NestedObject berth, Ship ship) { ship.UnwrapAtBerth(); ship.State = ShipState.UNWRAPPED; berthShipMap[berth] = ship; berth.EventActions.Trigger("OnBerth", berth); }
private void EvaluateTraderVisit(ScheduledEvent scheduledEvent) { NestedObject landingPad = FindRandomLandingPadWithouTrader(); if (landingPad != null) { CallTradeShipTest(landingPad); } }
public void NoChange() { var source = new NestedObject(); var patched = new NestedObject(); var diff = DiffBuilder.Build(source, patched); Assert.Null(diff); }
private void OnIsOperatingChanged(NestedObject nestedObject) { Action <NestedObject> handler = IsOperatingChanged; if (handler != null) { handler(nestedObject); } }
public void GivenInvalidChild_WhenValidateRecursively_ThenCorrectValidationResults() { RecursiveValidator validator = new RecursiveValidator(null); List <ValidationResult> results = validator.ValidateObjectRecursively(NestedObject.WithInvalidChild()); Assert.Equal(3, results.Count); ValidationResultUtility.AssertValidationResultEquals(results[0], "The RequiredString field is required.", "Child.RequiredString"); ValidationResultUtility.AssertValidationResultEquals(results[1], "The RequiredLong field is required.", "Child.RequiredLong"); ValidationResultUtility.AssertValidationResultEquals(results[2], "The RequiredUnsignedLong field is required.", "Child.RequiredUnsignedLong"); }
/// <summary> /// Copy Constructor -- don't call this directly, unless we never /// do ANY sub-classing. Instead use Clone(), which is more virtual. /// </summary> private NestedObject(NestedObject other) { Type = other.Type; Name = other.Name; typeTags = new HashSet <string>(other.typeTags); description = other.description; MovementCost = other.MovementCost; PathfindingModifier = other.PathfindingModifier; PathfindingWeight = other.PathfindingWeight; RoomEnclosure = other.RoomEnclosure; Width = other.Width; Height = other.Height; CanRotate = other.CanRotate; Rotation = other.Rotation; Tint = other.Tint; LinksToNeighbour = other.LinksToNeighbour; deconstructInventory = other.deconstructInventory; InternalInventory = other.InternalInventory; Parameters = new Parameter(other.Parameters); Jobs = new BuildableJobs(this, other.Jobs); // don't need to clone here, as all are prototype things (not changing) components = new HashSet <BuildableComponent>(other.components); if (other.Animation != null) { Animation = other.Animation.Clone(); } if (other.EventActions != null) { EventActions = other.EventActions.Clone(); } if (other.contextMenuLuaActions != null) { contextMenuLuaActions = new List <ContextMenuLuaAction>(other.contextMenuLuaActions); } isEnterableAction = other.isEnterableAction; getSpriteNameAction = other.getSpriteNameAction; getProgressInfoNameAction = other.getProgressInfoNameAction; if (other.PowerConnection != null) { PowerConnection = other.PowerConnection.Clone() as Connection; PowerConnection.NewThresholdReached += OnNewThresholdReached; } tileTypeBuildPermissions = new HashSet <string>(other.tileTypeBuildPermissions); //LocalizationCode = other.LocalizationCode; //UnlocalizedDescription = other.UnlocalizedDescription; }
/// <summary> /// Sets the destination to a berth. Should not be called with null value. /// If cancelling intention to berth, use `ship.Berth = null` directly. /// </summary> /// <param name="goalBerth">Goal berth.</param> public void SetDestination(NestedObject goalBerth) { if (goalBerth == null) { Debug.ULogError("Ships", "Destination berth should not be set to null this way. Use Berth property or SetDestination(x,y) instead."); return; } Berth = goalBerth; Destination = new Vector2(goalBerth.Tile.X, goalBerth.Tile.Y); }
public void WhenValidateRecursively_ThenNamingPolicyIsReflectedInPath() { IServiceProvider services = new ServiceCollection().AddRecursiveValidator(options => { options.ValidationNamingPolicy = new NaiveCamelCasingPolicy(); }).BuildServiceProvider(); IRecursiveValidator validator = services.GetRequiredService <IRecursiveValidator>(); List <ValidationResult> results = validator.ValidateObjectRecursively(NestedObject.WithInvalidChild()); Assert.Equal(3, results.Count); ValidationResultUtility.AssertValidationResultEquals(results[0], "The RequiredString field is required.", "child.requiredString"); ValidationResultUtility.AssertValidationResultEquals(results[1], "The RequiredLong field is required.", "child.requiredLong"); ValidationResultUtility.AssertValidationResultEquals(results[2], "The RequiredUnsignedLong field is required.", "child.requiredUnsignedLong"); }
public void ReturningToPlanet(NestedObject parentObject) { DroneReturnEvent = new ScheduledEvent( "EvaluateReturnToPlanet", EvaluateReturnToPlanet, (int)TimeSpan.FromMinutes(0.5).TotalSeconds, false, parentObject); Scheduler.Scheduler.Current.RegisterEvent(DroneReturnEvent); }
public static bool CanBePickedUp(Inventory inventory, bool canTakeFromStockpile) { // You can't pick up stuff that isn't on a tile or if it's locked if (inventory == null || inventory.Tile == null || inventory.Locked) { return(false); } NestedObject nestedObject = inventory.Tile.NestedObject; return(nestedObject == null || canTakeFromStockpile == true || nestedObject.HasTypeTag("Storage") == false); }
public void OnNestedObjectCreated(NestedObject nestedObject) { // FIXME if (soundCooldown > 0) { return; } AudioClip ac = AudioManager.GetAudio("Sound", nestedObject.Type + "_OnCreated"); AudioSource.PlayClipAtPoint(ac, Camera.main.transform.position); soundCooldown = 0.1f; }
public void NullToObject() { var source = new NestedObject(); source.Object = null; var patched = new NestedObject(); var diff = DiffBuilder.Build(source, patched); Assert.True(JObject.DeepEquals( JObject.Parse($"{{Object:{JsonConvert.SerializeObject(patched.Object)}}}"), diff)); }
public void ObjectToNull() { var source = new NestedObject(); var patched = new NestedObject(); patched.Object = null; var diff = DiffBuilder.Build(source, patched); Assert.True(JObject.DeepEquals( JObject.Parse("{Object:null}"), diff)); }
public void Deep() { var source = new NestedObject(); var patched = new NestedObject(); patched.Object.Integer2 = 19; var diff = DiffBuilder.Build(source, patched); Assert.True(JObject.DeepEquals( JObject.Parse("{Object:{Integer2: 19}}"), diff)); }
/// <summary> /// Unreserves the NestedObject's work spot, allowing it to be built on. /// </summary> /// <param name="NestedObject">The NestedObject whose workspot will be unreserved.</param> /// <param name="tile">The tile on which the NestedObject is located, for NestedObject which don't have a tile, such as prototypes.</param> public void UnreserveTileAsWorkSpot(NestedObject nestedObject, Tile tile = null) { if (tile == null) { tile = nestedObject.Tile; } World.Current.GetTileAt( tile.X + (int)nestedObject.Jobs.WorkSpotOffset.x, tile.Y + (int)nestedObject.Jobs.WorkSpotOffset.y, tile.Z) .ReservedAsWorkSpotBy.Remove(nestedObject); }
public void MiningComplete(NestedObject parentObject) { parentObject.Parameters["mine_complete"].SetValue("true"); DroneVisitEvent = new ScheduledEvent( "EvaluateMiningDroneVisit", EvaluateMiningDroneVisit, (int)TimeSpan.FromMinutes(0.5).TotalSeconds, false, parentObject); Scheduler.Scheduler.Current.RegisterEvent(DroneVisitEvent); }
private static bool ParseNestedObject( List<AnnotationToken> tokenList, ref int nextToken, ref NestedObject result, ref int fareastError) { int currentToken = nextToken; string tokenStr = null; if (ReadToken(tokenList, AnnotationTokenType.LeftBrace, ref currentToken, ref tokenStr, ref fareastError)) { string fieldName = null; NestedObject fieldValue = null; CollectionObject collectionObj = new CollectionObject() { Collection = new Dictionary<string, NestedObject>() }; // Field Name can be a NameToken or a DoubleQuotedString if ((ReadToken(tokenList, AnnotationTokenType.DoubleQuotedString, ref currentToken, ref fieldName, ref fareastError) || ReadToken(tokenList, AnnotationTokenType.NameToken, ref currentToken, ref fieldName, ref fareastError)) && ReadToken(tokenList, AnnotationTokenType.Colon, ref currentToken, ref tokenStr, ref fareastError) && ParseNestedObject(tokenList, ref currentToken, ref fieldValue, ref fareastError)) { collectionObj.Collection[fieldName.ToLower()] = fieldValue; } else { return false; } while (ReadToken(tokenList, AnnotationTokenType.Comma, ref currentToken, ref tokenStr, ref fareastError) && (ReadToken(tokenList, AnnotationTokenType.DoubleQuotedString, ref currentToken, ref fieldName, ref fareastError) || ReadToken(tokenList, AnnotationTokenType.NameToken, ref currentToken, ref fieldName, ref fareastError)) && ReadToken(tokenList, AnnotationTokenType.Colon, ref currentToken, ref tokenStr, ref fareastError) && ParseNestedObject(tokenList, ref currentToken, ref fieldValue, ref fareastError)) { collectionObj.Collection[fieldName.ToLower()] = fieldValue; } if (!ReadToken(tokenList, AnnotationTokenType.RightBrace, ref currentToken, ref tokenStr, ref fareastError)) { return false; } result = collectionObj; nextToken = currentToken; return true; } else if (ReadToken(tokenList, AnnotationTokenType.DoubleQuotedString, ref currentToken, ref tokenStr, ref fareastError)) { StringObject stringObj = new StringObject() { Value = tokenStr }; result = stringObj; nextToken = currentToken; return true; } else { return false; } }