Ejemplo n.º 1
0
 /// <summary>
 /// Matches an actual entity instance of a person against.
 /// </summary>
 /// <param name="actualEntityInstance">The actual entity instance to verify.</param>
 /// <param name="expectedId">The expected id of the Person.</param>
 /// <param name="expectedName">The expected name of the Person.</param>
 /// <param name="expectedDateOfBirth">The expected date of birth of the person.</param>
 /// <param name="expectedETag">The expected ETag of the entity instance.</param>
 internal static void MatchEntityInstanceOfPerson(EntityInstance <Person> actualEntityInstance, string expectedId, string expectedName, string expectedDateOfBirth, string expectedETag)
 {
     Assert.AreEqual(expectedId, actualEntityInstance.Entity.Id);
     Assert.AreEqual(ValueUtilities.GetNullableString(expectedName), actualEntityInstance.Entity.Name);
     Assert.AreEqual(ValueUtilities.GetNullableDateTimeOffset(expectedDateOfBirth), actualEntityInstance.Entity.DateOfBirth);
     Assert.AreEqual(ValueUtilities.GetNullableString(expectedETag), actualEntityInstance.ETag);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an entity instance from a person and an etag.
        /// </summary>
        /// <param name="person">The person to create.</param>
        /// <param name="eTag">The etag for the instance.</param>
        /// <param name="context">The scenario context.</param>
        /// <param name="keyToSet">The key to set in the scenario context (or null if you do not wish to set the value into the context).</param>
        /// <returns>The resulting <see cref="EntityInstance{T}"/> for the person.</returns>
        internal static EntityInstance <Person> CreateEntityInstance(Person person, string eTag, ScenarioContext?context = null, string?keyToSet = null)
        {
            var entityInstance = new EntityInstance <Person>(person, ValueUtilities.GetNullableString(eTag));

            if (context != null && keyToSet != null)
            {
                context.Set(entityInstance, keyToSet);
            }

            return(entityInstance);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Serialize a person to a document.
        /// </summary>
        /// <param name="person">The person to serialize.</param>
        /// <param name="eTag">The etag for the document.</param>
        /// <param name="context">The scenario context (or null if you do not wish to set the value into the context).</param>
        /// <param name="keyToSet">The key to set in the scenario context (or null if you do not wish to set the value into the context).</param>
        /// <returns>The serialized <see cref="Person"/>.</returns>
        internal static string SerializePersonToDocument(Person person, string eTag, ScenarioContext?context = null, string?keyToSet = null)
        {
            string serializedPerson = JsonConvert.SerializeObject(person);
            var    jobject          = JObject.Parse(serializedPerson);

            jobject["_etag"] = ValueUtilities.GetNullableString(eTag);

            string serializedDocument = jobject.ToString();

            if (context != null && keyToSet != null)
            {
                context.Set(serializedDocument, keyToSet);
            }

            return(serializedDocument);
        }