From f1a902efd49bb753b6d1f6e249924b188ce88cc6 Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Wed, 22 Mar 2023 08:53:42 +0300 Subject: [PATCH] Adds planner assignment model --- .../Extensions/PlannerAssignment.cs | 85 +++++++++++++++++++ .../Models/ModelSerializationTests.cs | 28 +++++- 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/Microsoft.Graph/Extensions/PlannerAssignment.cs diff --git a/src/Microsoft.Graph/Extensions/PlannerAssignment.cs b/src/Microsoft.Graph/Extensions/PlannerAssignment.cs new file mode 100644 index 00000000000..964f8be4984 --- /dev/null +++ b/src/Microsoft.Graph/Extensions/PlannerAssignment.cs @@ -0,0 +1,85 @@ +// ------------------------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. +// ------------------------------------------------------------------------------ + +using Microsoft.Kiota.Abstractions.Serialization; +using Microsoft.Kiota.Abstractions.Store; +using System; +using System.Collections.Generic; + +namespace Microsoft.Graph.Beta.Models; + +public class PlannerAssignment: IAdditionalDataHolder, IBackedModel, IParsable +{ + /// Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well. + public IDictionary AdditionalData { + get { return BackingStore?.Get>("additionalData"); } + set { BackingStore?.Set("additionalData", value); } + } + /// Stores model information. + public IBackingStore BackingStore { get; private set; } + /// The OdataType property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? OdataType { + get { return BackingStore?.Get("@odata.type"); } + set { BackingStore?.Set("@odata.type", value); } + } +#nullable restore +#else + public string OdataType { + get { return BackingStore?.Get("@odata.type"); } + set { BackingStore?.Set("@odata.type", value); } + } +#endif + /// The OdataType property +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER +#nullable enable + public string? OrderHint { + get { return BackingStore?.Get("orderHint"); } + set { BackingStore?.Set("orderHint", value); } + } +#nullable restore +#else + public string OrderHint { + get { return BackingStore?.Get("orderHint"); } + set { BackingStore?.Set("orderHint", value); } + } +#endif + /// + /// Instantiates a new auditActivityInitiator and sets the default values. + /// + public PlannerAssignment() { + BackingStore = BackingStoreFactorySingleton.Instance.CreateBackingStore(); + AdditionalData = new Dictionary(); + OdataType = "#microsoft.graph.plannerAssignment"; + OrderHint = "!"; + } + /// + /// Creates a new instance of the appropriate class based on discriminator value + /// + /// The parse node to use to read the discriminator value and create the object + public static PlannerAssignment CreateFromDiscriminatorValue(IParseNode parseNode) { + _ = parseNode ?? throw new ArgumentNullException(nameof(parseNode)); + return new PlannerAssignment(); + } + /// + /// The deserialization information for the current model + /// + public IDictionary> GetFieldDeserializers() { + return new Dictionary> { + {"@odata.type", n => { OdataType = n.GetStringValue(); } }, + {"orderHint", n => { OrderHint = n.GetStringValue(); } }, + }; + } + /// + /// Serializes information the current object + /// + /// Serialization writer to use to serialize this model + public void Serialize(ISerializationWriter writer) { + _ = writer ?? throw new ArgumentNullException(nameof(writer)); + writer.WriteStringValue("@odata.type", OdataType); + writer.WriteStringValue("orderHint", OrderHint); + writer.WriteAdditionalData(AdditionalData); + } +} diff --git a/tests/Microsoft.Graph.DotnetCore.Test/Models/ModelSerializationTests.cs b/tests/Microsoft.Graph.DotnetCore.Test/Models/ModelSerializationTests.cs index a064003d619..0b6edc37e3e 100644 --- a/tests/Microsoft.Graph.DotnetCore.Test/Models/ModelSerializationTests.cs +++ b/tests/Microsoft.Graph.DotnetCore.Test/Models/ModelSerializationTests.cs @@ -9,6 +9,7 @@ namespace Microsoft.Graph.DotnetCore.Test.Models using Microsoft.Graph.Beta.Models; using Microsoft.Kiota.Abstractions; using Microsoft.Kiota.Serialization.Json; + using System.Collections.Generic; using System.IO; using System.Text; @@ -159,7 +160,6 @@ public void SerializeAndDeserializeKnownEnumValue() Assert.Null(itemBody.AdditionalData); } - [Fact(Skip = "TODO fix pending odata.type bug")] public void SerializeDateValue() { var now = DateTimeOffset.UtcNow; @@ -198,5 +198,31 @@ public void TestEtagHelper() Assert.Equal(userId, user.Id); //Assert.Equal(testEtag, user.GetEtag()); } + [Fact] + public void TestPlannerAssigmentSerialization() + { + var planTask = new PlannerTask + { + PlanId = "PLAN_ID", + BucketId = "BUCKET_ID", + Title = "My Planner Task", + Assignments = new PlannerAssignments + { + AdditionalData = new Dictionary + { + {"USER_ID", new PlannerAssignment()} + } + } + }; + + string expectedSerializedString = "{\"assignments\":{\"USER_ID\":{\"@odata.type\":\"#microsoft.graph.plannerAssignment\",\"orderHint\":\"!\"}},\"bucketId\":\"BUCKET_ID\",\"planId\":\"PLAN_ID\",\"title\":\"My Planner Task\"}"; + using var jsonSerializerWriter = new JsonSerializationWriter(); + jsonSerializerWriter.WriteObjectValue(string.Empty, planTask); + var serializedStream = jsonSerializerWriter.GetSerializedContent(); + + // Assert + var streamReader = new StreamReader(serializedStream); + Assert.Equal(expectedSerializedString, streamReader.ReadToEnd()); + } } }