private async void DoneCommandRecieverAsync() { try { Address address = new Address() { Line1 = Line1, Line2 = Line2, Line3 = Line3, City = City, State = State, PostalCode = PostalCode, Country = Country }; if (AddressTitle.Contains("Shipping")) { IsShipping = true; } else { IsShipping = false; } await _navigationService.GoBackAsync(new NavigationParameters { { "EditAddress", address }, { "IsShipping", IsShipping } }, animated : false); CleanupData(); } catch (Exception ex) { Crashes.TrackError(ex); } }
public virtual async Task Can_manipulate_embedded_collections() { var options = Fixture.CreateOptions(seed: false); Address existingAddress1Person2; Address existingAddress1Person3; Address existingAddress2Person3; Address addedAddress1; Address addedAddress2; Address addedAddress3; using (var context = new EmbeddedTransportationContext(options)) { context.Add(new Person { Id = 1 }); var note1 = new Note { Content = "First note" }; var note2 = new Note { Content = "Second note" }; existingAddress1Person2 = new Address { Street = "Second", City = "Village", Notes = new List <Note> { note1, note2 } }; context.Add(new Person { Id = 2, Addresses = new List <Address> { existingAddress1Person2 } }); existingAddress1Person3 = new Address { Street = "First", City = "City", AddressTitle = new AddressTitle { Title = "P3 Shipping" } }; existingAddress2Person3 = new Address { Street = "Second", City = "City", AddressTitle = new AddressTitle { Title = "P3 Billing" } }; context.Add(new Person { Id = 3, Addresses = new List <Address> { existingAddress1Person3, existingAddress2Person3 } }); await context.SaveChangesAsync(); var people = await context.Set <Person>().ToListAsync(); Assert.Empty(people[0].Addresses); Assert.Equal(1, people[1].Addresses.Count); Assert.Same(existingAddress1Person2, people[1].Addresses.First()); Assert.Equal(2, existingAddress1Person2.Notes.Count); Assert.Same(existingAddress1Person3, people[2].Addresses.First()); Assert.Same(existingAddress2Person3, people[2].Addresses.Last()); Assert.Equal(2, people[2].Addresses.Count); Assert.Same(existingAddress1Person3, people[2].Addresses.First()); Assert.Same(existingAddress2Person3, people[2].Addresses.Last()); } using (var context = new EmbeddedTransportationContext(options)) { var people = await context.Set <Person>().ToListAsync(); addedAddress1 = new Address { Street = "First", City = "Town", AddressTitle = new AddressTitle { Title = "P1" } }; people[0].Addresses.Add(addedAddress1); addedAddress2 = new Address { Street = "Another", City = "Village", AddressTitle = new AddressTitle { Title = "P2" }, Notes = existingAddress1Person2.Notes }; people[1].Addresses.Clear(); people[1].Addresses.Add(addedAddress2); addedAddress3 = new Address { Street = "Another", City = "City", AddressTitle = new AddressTitle { Title = "P3 Alternative" }, Notes = new List <Note> { new() { Content = "Another note" } } }; var existingFirstAddressEntry = context.Entry(people[2].Addresses.First()); var addressJson = existingFirstAddressEntry.Property <JObject>("__jObject").CurrentValue; Assert.Equal("First", addressJson[nameof(Address.Street)]); addressJson["unmappedId"] = 2; existingFirstAddressEntry.Property <JObject>("__jObject").IsModified = true; var existingLastAddress = people[2].Addresses.Last(); people[2].Addresses.Remove(existingLastAddress); people[2].Addresses.Add(addedAddress3); people[2].Addresses.Add(existingLastAddress); existingLastAddress.Notes.Add(new Note { Content = "City note" }); await context.SaveChangesAsync(); await AssertState(context); } using (var context = new EmbeddedTransportationContext(options)) { await AssertState(context); } async Task AssertState(EmbeddedTransportationContext context) { var people = await context.Set <Person>().OrderBy(o => o.Id).ToListAsync(); var firstAddress = people[0].Addresses.Single(); Assert.Equal("First", firstAddress.Street); Assert.Equal("Town", firstAddress.City); Assert.Equal("P1", firstAddress.AddressTitle.Title); Assert.Empty(firstAddress.Notes); var addresses = people[1].Addresses.ToList(); Assert.Single(addresses); Assert.Equal("Another", addresses[0].Street); Assert.Equal("Village", addresses[0].City); Assert.Equal("P2", addresses[0].AddressTitle.Title); var notes = addresses[0].Notes; Assert.Equal(2, notes.Count); Assert.Equal("First note", notes.First().Content); Assert.Equal("Second note", notes.Last().Content); addresses = people[2].Addresses.ToList(); Assert.Equal(3, addresses.Count); Assert.Equal("First", addresses[0].Street); Assert.Equal("City", addresses[0].City); Assert.Equal("P3 Shipping", addresses[0].AddressTitle.Title); var existingAddressEntry = context.Entry(addresses[0]); var addressJson = existingAddressEntry.Property <JObject>("__jObject").CurrentValue; Assert.Equal("First", addressJson[nameof(Address.Street)]); Assert.Equal(5, addressJson.Count); Assert.Equal(2, addressJson["unmappedId"]); Assert.Equal("Another", addresses[1].Street); Assert.Equal("City", addresses[1].City); Assert.Equal("P3 Alternative", addresses[1].AddressTitle.Title); Assert.Equal(1, addresses[1].Notes.Count); Assert.Equal("Another note", addresses[1].Notes.First().Content); Assert.Equal("Second", addresses[2].Street); Assert.Equal("City", addresses[2].City); Assert.Equal("P3 Billing", addresses[2].AddressTitle.Title); Assert.Equal(1, addresses[2].Notes.Count); Assert.Equal("City note", addresses[2].Notes.First().Content); } }