protected override string CreateMessage(Type dtoType) { try { var requestObj = AutoMappingUtils.PopulateWith(Activator.CreateInstance(dtoType)); using (var ms = new MemoryStream()) { HostContext.ContentTypes.SerializeToStream( new BasicRequest { ContentType = this.ContentType }, requestObj, ms); return(Encoding.UTF8.GetString(ms.ToArray())); } } catch (Exception ex) { var error = string.Format("Error serializing type '{0}' with custom format '{1}'", dtoType.GetOperationName(), this.ContentFormat); Log.Error(error, ex); return(string.Format("{{Unable to show example output for type '{0}' using the custom '{1}' filter}}" + ex.Message, dtoType.GetOperationName(), this.ContentFormat)); } }
public void Can_create_DTO_with_Stream() { var o = typeof(RawRequest).CreateInstance(); var requestObj = AutoMappingUtils.PopulateWith(o); Assert.That(requestObj, Is.Not.Null); }
public void Can_PopulateObjectWithStringArray() { var obj = (DtoWithStringArray)AutoMappingUtils.PopulateWith(new DtoWithStringArray()); Assert.IsNotNull(obj.Data); Assert.Greater(obj.Data.Length, 0); Assert.IsNotNull(obj.Data[0]); }
public void Can_PopulateRecursiveDto() { var obj = (RecursiveDto)AutoMappingUtils.PopulateWith(new RecursiveDto()); Assert.IsNotNullOrEmpty(obj.Name); Assert.IsNotNull(obj.Child); Assert.IsNotNullOrEmpty(obj.Child.Name); }
public void Can_PopulateObjectWithNonZeroEnumArray() { var obj = (DtoWithEnumArray)AutoMappingUtils.PopulateWith(new DtoWithEnumArray()); Assert.IsNotNull(obj.Data); Assert.Greater(obj.Data.Length, 0); Assert.That(Enum.IsDefined(typeof(TestClassType), obj.Data[0]), "Values in created array should be valid for the enum"); }
public void Can_PopulateRecursiveDto() { var obj = (RecursiveDto)AutoMappingUtils.PopulateWith(new RecursiveDto()); Assert.That(obj.Name, Is.Not.Null); Assert.IsNotNull(obj.Child); Assert.That(obj.Child.Name, Is.Not.Null); }
public void Can_PopulateRecursiveArrayDto() { var obj = (RecursiveArrayDto)AutoMappingUtils.PopulateWith(new RecursiveArrayDto()); Assert.That(obj.Name, Is.Not.Null); Assert.IsNotNull(obj.Nodes[0]); Assert.That(obj.Nodes[0].Name, Is.Not.Null); Assert.IsNotNull(obj.Nodes[0].Nodes); Assert.That(obj.Nodes[0].Nodes[0].Name, Is.Not.Null); }
public void Can_PopulateTheVortex() { var obj = (MindTwister)AutoMappingUtils.PopulateWith(new MindTwister()); Console.WriteLine("Mindtwister = " + ServiceStack.Text.XmlSerializer.SerializeToString(obj)); // TypeSerializer and JsonSerializer blow up on this structure with a Null Reference Exception! Assert.IsNotNull(obj); Assert.IsNotNull(obj.Name); Assert.IsNotNull(obj.Arrays); Assert.IsNotNull(obj.Vortex); }
public void Populate_Different_Objects_with_different_property_types() { var toObj = ModelWithFieldsOfDifferentTypes.Create(1); var fromObj = ModelWithOnlyStringFields.Create("2"); var obj3 = AutoMappingUtils.PopulateWith(toObj, fromObj); Assert.IsTrue(obj3 == toObj); Assert.That(obj3.Id, Is.EqualTo(2)); Assert.That(obj3.Name, Is.EqualTo(fromObj.Name)); }
public void Can_PopulateArrayOfRecursiveDto() { var obj = (DtoWithRecursiveArray)AutoMappingUtils.PopulateWith(new DtoWithRecursiveArray()); Assert.IsNotNull(obj.Paths); Assert.Greater(obj.Paths.Length, 0); Assert.IsNotNull(obj.Paths[0]); Assert.That(obj.Paths[0].Name, Is.Not.Null); Assert.IsNotNull(obj.Paths[0].Child); Assert.That(obj.Paths[0].Child.Name, Is.Not.Null); }
protected override string CreateMessage(Type dtoType) { var requestObj = AutoMappingUtils.PopulateWith(Activator.CreateInstance(dtoType)); var xml = DataContractSerializer.Instance.Parse(requestObj, true); var soapEnvelope = string.Format(@"<?xml version=""1.0"" encoding=""utf-8""?> <soap12:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap12=""http://www.w3.org/2003/05/soap-envelope""> <soap12:Body> {0} </soap12:Body> </soap12:Envelope>", xml); return(soapEnvelope); }
public void Populate_Same_Objects() { var toObj = ModelWithFieldsOfDifferentTypes.Create(1); var fromObj = ModelWithFieldsOfDifferentTypes.Create(2); var obj3 = AutoMappingUtils.PopulateWith(toObj, fromObj); Assert.IsTrue(obj3 == toObj); Assert.That(obj3.Bool, Is.EqualTo(fromObj.Bool)); Assert.That(obj3.DateTime, Is.EqualTo(fromObj.DateTime)); Assert.That(obj3.Double, Is.EqualTo(fromObj.Double)); Assert.That(obj3.Guid, Is.EqualTo(fromObj.Guid)); Assert.That(obj3.Id, Is.EqualTo(fromObj.Id)); Assert.That(obj3.LongId, Is.EqualTo(fromObj.LongId)); Assert.That(obj3.Name, Is.EqualTo(fromObj.Name)); }
protected override string CreateMessage(Type dtoType) { try { var requestObj = AutoMappingUtils.PopulateWith(Activator.CreateInstance(dtoType)); using var ms = MemoryStreamFactory.GetStream(); HostContext.ContentTypes.SerializeToStreamAsync( new BasicRequest { ContentType = this.ContentType }, requestObj, ms).Wait(); return(ms.ReadToEnd()); } catch (Exception ex) { var error = $"Error serializing type '{dtoType.GetOperationName()}' with custom format '{this.ContentFormat}'"; Log.Error(error, ex); return($"{{Unable to show example output for type '{dtoType.GetOperationName()}' using the custom '{this.ContentFormat}' filter}}{ex.Message}"); } }
protected override string CreateMessage(Type dtoType) { var requestObj = AutoMappingUtils.PopulateWith(Activator.CreateInstance(dtoType)); return(requestObj.SerializeAndFormat()); }
protected override string CreateMessage(Type dtoType) { var requestObj = AutoMappingUtils.PopulateWith(dtoType.CreateInstance()); return(JsonDataContractSerializer.Instance.SerializeToString(requestObj)); }
public void PopulateObject_UsesDefinedEnum() { var requestObj = (TestClass2)AutoMappingUtils.PopulateWith(Activator.CreateInstance(typeof(TestClass2))); Assert.True(Enum.IsDefined(typeof(TestClassType), requestObj.Type)); }
public string Parse(Type type) { return(Parse(AutoMappingUtils.PopulateWith(type.CreateInstance()), true)); }