/// <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)); } if (factory == null) { throw new ArgumentNullException(nameof(factory)); } MsCatchwordsPart part = new MsCatchwordsPart(); int count = Randomizer.Seed.Next(1, 3 + 1); for (int n = 1; n <= count; n++) { part.Catchwords.Add(new Faker <MsCatchword>() .RuleFor(c => c.Position, f => f.PickRandom("bottom", "right")) .RuleFor(c => c.IsVertical, f => f.Random.Bool(0.5f)) .RuleFor(c => c.Decoration, f => f.Lorem.Sentence()) .RuleFor(c => c.Register, f => f.Lorem.Sentence()) .RuleFor(c => c.Note, f => f.PickRandom(null, f.Lorem.Sentence())) .Generate()); } SetPartMetadata(part, roleId, item); return(part); }
public void GetDataPins_Recalls_Ok() { MsCatchwordsPart part = GetPart(3); List <DataPin> pins = part.GetDataPins(null).ToList(); Assert.Equal(5, pins.Count); TestHelper.AssertValidDataPinNames(pins); DataPin pin = pins.Find(p => p.Name == "tot-count"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); Assert.Equal("3", pin.Value); pin = pins.Find(p => p.Name == "pos-bottom-count"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); Assert.Equal("2", pin.Value); pin = pins.Find(p => p.Name == "pos-right-count"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); Assert.Equal("1", pin.Value); pin = pins.Find(p => p.Name == "vrt-0-count"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); Assert.Equal("2", pin.Value); pin = pins.Find(p => p.Name == "vrt-1-count"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); Assert.Equal("1", pin.Value); }
public void GetDataPins_NoRecalls_Ok() { MsCatchwordsPart part = GetPart(0); 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() { MsCatchwordsPart part = GetPart(2); string json = TestHelper.SerializePart(part); MsCatchwordsPart part2 = TestHelper.DeserializePart <MsCatchwordsPart>(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(2, part.Catchwords.Count); // TODO: details }
private static MsCatchwordsPart GetPart(int count) { MsCatchwordsPart part = new MsCatchwordsPart { ItemId = Guid.NewGuid().ToString(), RoleId = "some-role", CreatorId = "zeus", UserId = "another", }; for (int n = 1; n <= count; n++) { part.Catchwords.Add(new MsCatchword { Position = n % 2 == 0? "right" : "bottom", IsVertical = n % 2 == 0, Decoration = "Decoration", Register = "Register" }); } return(part); }
public void Seed_Ok() { MsCatchwordsPartSeeder seeder = new MsCatchwordsPartSeeder(); seeder.SetSeedOptions(_seedOptions); IPart part = seeder.GetPart(_item, null, _factory); Assert.NotNull(part); MsCatchwordsPart cp = part as MsCatchwordsPart; Assert.NotNull(cp); TestHelper.AssertPartMetadata(cp); Assert.NotEmpty(cp.Catchwords); foreach (MsCatchword catchword in cp.Catchwords) { Assert.NotNull(catchword.Position); Assert.NotNull(catchword.Decoration); Assert.NotNull(catchword.Register); } }