public void GetDataPins_NoEntries_Ok() { MsUnitsPart part = GetPart(); part.Units.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() { MsUnitsPart part = GetPart(); string json = TestHelper.SerializePart(part); MsUnitsPart part2 = TestHelper.DeserializePart <MsUnitsPart>(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.Units.Count, part2.Units.Count); }
public void Seed_Ok() { MsUnitsPartSeeder seeder = new MsUnitsPartSeeder(); seeder.SetSeedOptions(_seedOptions); IPart part = seeder.GetPart(_item, null, _factory); Assert.NotNull(part); MsUnitsPart p = part as MsUnitsPart; Assert.NotNull(p); TestHelper.AssertPartMetadata(p); Assert.NotEmpty(p.Units); }
public void GetDataPins_Entries_Ok() { MsUnitsPart part = new MsUnitsPart { ItemId = Guid.NewGuid().ToString(), RoleId = "some-role", CreatorId = "zeus", UserId = "another" }; for (int n = 1; n <= 3; n++) { bool even = n % 2 == 0; part.Units.Add(new MsUnit { Material = even ? "paper" : "parchment", Palimpsests = even ? new List <MsPalimpsest>(new[] { new MsPalimpsest() }) : null, SheetCount = n * 2, GuardSheetCount = n }); } List <DataPin> pins = part.GetDataPins(null).ToList(); Assert.Equal(10, pins.Count); DataPin pin = pins.Find(p => p.Name == "tot-count"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); Assert.Equal("3", pin.Value); // material pin = pins.Find(p => p.Name == "material" && p.Value == "parchment"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); pin = pins.Find(p => p.Name == "material" && p.Value == "paper"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); // palimpsest pin = pins.Find(p => p.Name == "palimpsest" && p.Value == "1"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); // sheets for (int n = 1; n <= 3; n++) { // sheet-count pin = pins.Find(p => p.Name == "sheet-count" && p.Value == $"{n * 2}"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); // guard-sheet-count pin = pins.Find(p => p.Name == "guard-sheet-count" && p.Value == $"{n}"); Assert.NotNull(pin); TestHelper.AssertPinIds(part, pin); } }
/// <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</exception> public override IPart GetPart(IItem item, string roleId, PartSeederFactory factory) { if (item == null) { throw new ArgumentNullException(nameof(item)); } MsUnitsPart part = new MsUnitsPart(); SetPartMetadata(part, roleId, item); int count = Randomizer.Seed.Next(1, 5 + 1); for (int n = 1; n <= count; n++) { bool even = n % 2 == 0; int guardCount = Randomizer.Seed.Next(0, 3); part.Units.Add(new Faker <MsUnit>() .RuleFor(u => u.Start, f => new MsLocation { N = n, S = even ? "v" : "r", L = f.Random.Number(1, 40) }) .RuleFor(u => u.End, f => new MsLocation { N = n + 3, S = even ? "v" : "r", L = f.Random.Number(1, 40) }) .RuleFor(u => u.Palimpsests, f => GetPalimpsests(f.Random.Number(0, 2))) .RuleFor(u => u.Material, f => f.PickRandom("paper", "parchment")) .RuleFor(u => u.GuardSheetMaterial, f => f.PickRandom("paper", "parchment")) .RuleFor(u => u.SheetCount, f => f.Random.Number(1, 3)) .RuleFor(u => u.GuardSheetCount, guardCount) .RuleFor(u => u.BackGuardSheetCount, guardCount) .RuleFor(u => u.GuardSheets, GetGuardSheets(guardCount)) .RuleFor(u => u.Quires, f => f.Lorem.Sentence()) .RuleFor(u => u.SheetNumbering, f => f.Lorem.Sentence()) .RuleFor(u => u.QuireNumbering, f => f.Lorem.Sentence()) .RuleFor(u => u.LeafSizes, SeedHelper.GetSizes(1, 2)) .RuleFor(u => u.LeafSizeSamples, new List <MsLocation>(new[] { new MsLocation { N = n, S = even? "v" : "r" } })) .RuleFor(u => u.WrittenAreaSizes, SeedHelper.GetSizes(1, 2)) .RuleFor(u => u.WrittenAreaSizeSamples, new List <MsLocation>(new[] { new MsLocation { N = n, S = even? "v" : "r" } })) .RuleFor(u => u.Rulings, f => GetRulings(f.Random.Number(1, 2))) .RuleFor(u => u.Watermarks, f => GetWatermarks(f.Random.Number(0, 3))) .RuleFor(u => u.State, f => f.Lorem.Sentence()) .RuleFor(u => u.Binding, f => f.Lorem.Sentence()) .Generate()); } return(part); }