/// <summary> /// Creates and seeds a new part. /// </summary> /// <param name="item">The item this part should belong to.</param> /// <param name="roleId">The optional part role ID.</param> /// <param name="factory">The part seeder factory. This is used /// for layer parts, which need to seed a set of fragments.</param> /// <returns>A new part.</returns> /// <exception cref="ArgumentNullException">item or factory</exception> public override IPart GetPart(IItem item, string roleId, PartSeederFactory factory) { if (item == null) { throw new ArgumentNullException(nameof(item)); } MsPlacesPart part = new MsPlacesPart(); SetPartMetadata(part, roleId, item); for (int n = 1; n <= Randomizer.Seed.Next(1, 3 + 1); n++) { part.Places.Add(new Faker <MsPlace>() .RuleFor(p => p.Area, f => f.PickRandom("France", "Germany", "Italy")) .RuleFor(p => p.Address, f => $"{f.Lorem.Word()}, {f.Lorem.Word()}") .RuleFor(p => p.City, f => f.Address.City()) .RuleFor(p => p.Site, f => f.PickRandom("A library", "A monastery")) .RuleFor(p => p.Rank, (short)n) .RuleFor(p => p.Sources, SeedHelper.GetDocReferences(1, 3)) .Generate()); } return(part); }
public void GetDataPins_NoEntries_Ok() { MsPlacesPart part = GetPart(); part.Places.Clear(); List <DataPin> pins = part.GetDataPins(null).ToList(); Assert.Single(pins); DataPin pin = pins[0]; Assert.Equal("tot-count", pin.Name); TestHelper.AssertPinIds(part, pin); Assert.Equal("0", pin.Value); }
public void Part_Is_Serializable() { MsPlacesPart part = GetPart(); string json = TestHelper.SerializePart(part); MsPlacesPart part2 = TestHelper.DeserializePart <MsPlacesPart>(json); Assert.Equal(part.Id, part2.Id); Assert.Equal(part.TypeId, part2.TypeId); Assert.Equal(part.ItemId, part2.ItemId); Assert.Equal(part.RoleId, part2.RoleId); Assert.Equal(part.CreatorId, part2.CreatorId); Assert.Equal(part.UserId, part2.UserId); Assert.Equal(part.Places.Count, part2.Places.Count); }
public void Seed_Ok() { MsPlacesPartSeeder seeder = new MsPlacesPartSeeder(); seeder.SetSeedOptions(_seedOptions); IPart part = seeder.GetPart(_item, null, _factory); Assert.NotNull(part); MsPlacesPart p = part as MsPlacesPart; Assert.NotNull(p); TestHelper.AssertPartMetadata(p); Assert.NotEmpty(p.Places); }
public void GetDataPins_Entries_Ok() { MsPlacesPart part = GetEmptyPart(); for (int n = 1; n <= 3; n++) { bool even = n % 2 == 0; part.Places.Add(new MsPlace { Area = even? "even" : "odd", City = even? "Paris" : "Rome", Address = even? "ea, eb" : "oa, ob" }); } List <DataPin> pins = part.GetDataPins(null).ToList(); Assert.Equal(11, pins.Count); DataPin pin = pins.Find(p => p.Name == "tot-count"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); Assert.Equal("3", pin.Value); // area pin = pins.Find(p => p.Name == "area" && p.Value == "even"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); pin = pins.Find(p => p.Name == "area" && p.Value == "odd"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); pin = pins.Find(p => p.Name == "city" && p.Value == "rome"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); pin = pins.Find(p => p.Name == "city" && p.Value == "paris"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); pin = pins.Find(p => p.Name == "address" && p.Value == "ea, eb"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); pin = pins.Find(p => p.Name == "address" && p.Value == "oa, ob"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); pin = pins.Find(p => p.Name == "address-1" && p.Value == "ea"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); pin = pins.Find(p => p.Name == "address-2" && p.Value == "eb"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); pin = pins.Find(p => p.Name == "address-1" && p.Value == "oa"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); pin = pins.Find(p => p.Name == "address-2" && p.Value == "ob"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); }