public void BuildsComplexAccountDocument() { var createdAt = new DateTime(2020, 5, 10); var a = new ComplexAccount { AccountId = "ABC1", Balance = 12.0M, IsActive = true, CreatedAt = createdAt, AccountHolder = new User { Id = 1, Name = "Han Solo" }, Transactions = new List <Transaction> { new Transaction { Id = 123, Amount = 3.0M }, new Transaction { Id = 234, Amount = 21.0M } } }; var builder = new IonConverter.IonDocumentConverter(); var doc = builder.ConvertFrom <ComplexAccount>(a); Console.WriteLine("Constructed Document:"); Console.Write(doc.ToPrettyString()); Assert.Equal(a.AccountId, doc.GetField("AccountId").StringValue); Assert.Equal(a.Balance, doc.GetField("Balance").DecimalValue); Assert.Equal(a.IsActive, doc.GetField("IsActive").BoolValue); Assert.Equal(2, doc.GetField("Transactions").Count); Assert.Equal(createdAt, doc.GetField("CreatedAt").TimestampValue.DateTimeValue); }
private IIonValue CreateComplexDoc(ComplexAccount model) { var factory = new ValueFactory(); var doc = factory.NewEmptyStruct(); doc.SetField("AccountId", factory.NewString(model.AccountId)); doc.SetField("Balance", factory.NewDecimal(model.Balance)); doc.SetField("IsActive", factory.NewBool(model.IsActive)); doc.SetField("CreatedAt", factory.NewTimestamp(new Timestamp(model.CreatedAt))); var list = factory.NewEmptyList(); model.Transactions.ForEach(t => { var it = CreateTransaction(t, factory); list.Add(it); }); doc.SetField("Transactions", list); return(doc); }
public void BuildsComplexAccountDocument() { var account = new ComplexAccount { AccountId = "ABC1", Balance = 12.0M, IsActive = true, Transactions = new List <Transaction> { new Transaction { Id = 1, Amount = 10.0M }, new Transaction { Id = 2, Amount = 21.0M }, } }; var doc = CreateComplexDoc(account); var converter = new IonConverter.IonDocumentConverter(); var convertedAccount = converter.ConvertTo <ComplexAccount>(doc); Assert.Equal(12.0M, convertedAccount.Balance); Assert.Equal(true, convertedAccount.IsActive); Assert.Equal(2, convertedAccount.Transactions.Count); Assert.Equal(21.0M, convertedAccount.Transactions[1].Amount); }