public void HierarchyGeneratorConstructor_SourceListNotBigEnough_Complains() { // Formula is (maxCategories^0 + maxCategories^1 + maxCategories^2) * numRoots // = (5^0 + 5^1 + 5^2) * 4 // = (1 + 5 + 25) * 4 // = 31 * 4 // = 124 const int requiredSizeOfList = 124; using (mocks.Record()) { sourceList.Expect(x => x.Count).Return(requiredSizeOfList - 1); } using (mocks.Playback()) { // TODO FIX #if !SILVERLIGHT Assert.Throws <ArgumentException>( () => hierarchyGenerator = new HierarchyGenerator <MyHierarchicalClass>(sourceList, null, numberOfRoots, depth, minCategories, maxCategories, randomGenerator, namingMethod, null) ); #endif } }
public MainWindow() { try { this.dropNetClient = new DropNetClient(API_KEY, APP_SECRET); this.dropNetClient.UseSandbox = true; this.employees = HierarchyGenerator.GenerateEmployees(); InitializeComponent(); this.importDataBtn.Click += (sender, eventArgs) => { var reportsPage = new ReportsPage(employees); this.pagesFrame.Navigate(reportsPage); this.currentPage = reportsPage; }; this.exportToDropBoxBtn.Click += ExportToDropBoxAccount; this.exportToWordBtn.Click += (sender, e) => { try { ExportToWordFile(sender, e); } catch (Exception ex) { ShowError(ex); } }; this.aboutBtn.Click += ShowAboutBox; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void ShouldAddChildren() { sourceList.Count.Returns(categoryCount); randomGenerator.Next(minCategories, maxCategories).Returns(1); sourceList[0].Returns(new MyHierarchicalClass()); sourceList.RemoveAt(0); hierarchyGenerator = new HierarchyGenerator <MyHierarchicalClass>(sourceList, (x, y) => x.AddChild(y), numberOfRoots, depth, minCategories, maxCategories, randomGenerator, namingMethod, null); hierarchyGenerator.Generate(); }
public void ShouldGenerateTheCorrectNumberOfRoots() { sourceList.Count.Returns(categoryCount); sourceList[0].Returns(new MyHierarchicalClass()); hierarchyGenerator = new HierarchyGenerator <MyHierarchicalClass>(sourceList, (x, y) => x.AddChild(y), numberOfRoots, depth, minCategories, maxCategories, randomGenerator, namingMethod, null); IList <MyHierarchicalClass> hierarchy = hierarchyGenerator.Generate(); hierarchy.Count.ShouldBe(numberOfRoots); }
public static IList <T> BuildHierarchy <T>(this IListBuilder <T> listBuilder, IHierarchySpec <T> hierarchySpec) { var list = listBuilder.Build(); var hierarchy = new HierarchyGenerator <T>(list, hierarchySpec.AddMethod, hierarchySpec.NumberOfRoots, hierarchySpec.Depth, hierarchySpec.MinimumChildren, hierarchySpec.MaximumChildren, new RandomGenerator(), hierarchySpec.NamingMethod, null).Generate(); return(hierarchy); }
public static IList <T> PersistHierarchy <T>(this IListBuilder <T> listBuilder, IHierarchySpec <T> hierarchySpec) { // 1. Create var list = listBuilder.Build(); // 2. Reorganise var hierarchy = new HierarchyGenerator <T>(list, hierarchySpec.AddMethod, hierarchySpec.NumberOfRoots, hierarchySpec.Depth, hierarchySpec.MinimumChildren, hierarchySpec.MaximumChildren, new RandomGenerator(), hierarchySpec.NamingMethod, listBuilder.BuilderSetup.GetPersistenceService()).Generate(); return(hierarchy); }
public void ShouldGenerateTheCorrectNumberOfRoots() { using (mocks.Record()) { sourceList.Expect(x => x.Count).Return(categoryCount).Repeat.Any(); sourceList.Expect(x => x[0]).Return(new MyHierarchicalClass()).Repeat.Times(numberOfRoots); } hierarchyGenerator = new HierarchyGenerator <MyHierarchicalClass>(sourceList, (x, y) => x.AddChild(y), numberOfRoots, depth, minCategories, maxCategories, randomGenerator, namingMethod, null); IList <MyHierarchicalClass> hierarchy = hierarchyGenerator.Generate(); Assert.That(hierarchy.Count, Is.EqualTo(numberOfRoots)); }
public void ShouldGenerateTheCorrectNumberOfRoots() { using (mocks.Record()) { sourceList.Expect(x => x.Count).Return(categoryCount).Repeat.Any(); sourceList.Expect(x => x[0]).Return(new MyHierarchicalClass()).Repeat.Times(numberOfRoots); } hierarchyGenerator = new HierarchyGenerator<MyHierarchicalClass>(sourceList, (x, y) => x.AddChild(y), numberOfRoots, depth, minCategories, maxCategories, randomGenerator, namingMethod, null); IList<MyHierarchicalClass> hierarchy = hierarchyGenerator.Generate(); Assert.That(hierarchy.Count, Is.EqualTo(numberOfRoots)); }
public void ShouldTryToPersistIfPersistenceServiceSupplied() { IPersistenceService persistenceService = Substitute.For <IPersistenceService>(); sourceList.Count.Returns(categoryCount); randomGenerator.Next(minCategories, maxCategories).Returns(1); sourceList[0].Returns(new MyHierarchicalClass()); sourceList.RemoveAt(0); persistenceService.Create(Arg.Any <MyHierarchicalClass>()); persistenceService.Update(Arg.Any <IList <MyHierarchicalClass> >()); hierarchyGenerator = new HierarchyGenerator <MyHierarchicalClass>(sourceList, (x, y) => x.AddChild(y), numberOfRoots, depth, minCategories, maxCategories, randomGenerator, namingMethod, persistenceService); hierarchyGenerator.Generate(); }
public void ShouldAddChildren() { using (mocks.Record()) { sourceList.Expect(x => x.Count).Return(categoryCount).Repeat.Any(); randomGenerator.Expect(x => x.Next(minCategories, maxCategories)).Return(1).Repeat.Times(12); sourceList.Expect(x => x[0]).Return(new MyHierarchicalClass()).Repeat.Any(); sourceList.Expect(x => x.RemoveAt(0)).Repeat.Any(); } using (mocks.Playback()) { hierarchyGenerator = new HierarchyGenerator <MyHierarchicalClass>(sourceList, (x, y) => x.AddChild(y), numberOfRoots, depth, minCategories, maxCategories, randomGenerator, namingMethod, null); hierarchyGenerator.Generate(); } }
public void ShouldAddChildren() { using (mocks.Record()) { sourceList.Expect(x => x.Count).Return(categoryCount).Repeat.Any(); randomGenerator.Expect(x => x.Next(minCategories, maxCategories)).Return(1).Repeat.Times(12); sourceList.Expect(x => x[0]).Return(new MyHierarchicalClass()).Repeat.Any(); sourceList.Expect(x => x.RemoveAt(0)).Repeat.Any(); } using (mocks.Playback()) { hierarchyGenerator = new HierarchyGenerator<MyHierarchicalClass>(sourceList, (x, y) => x.AddChild(y), numberOfRoots, depth, minCategories, maxCategories, randomGenerator, namingMethod, null); hierarchyGenerator.Generate(); } }
public void HierarchyGeneratorConstructor_SourceListNotBigEnough_Complains() { // Formula is (maxCategories^0 + maxCategories^1 + maxCategories^2) * numRoots // = (5^0 + 5^1 + 5^2) * 4 // = (1 + 5 + 25) * 4 // = 31 * 4 // = 124 const int requiredSizeOfList = 124; sourceList.Count.Returns(requiredSizeOfList - 1); Should.Throw <ArgumentException>( () => hierarchyGenerator = new HierarchyGenerator <MyHierarchicalClass>(sourceList, null, numberOfRoots, depth, minCategories, maxCategories, randomGenerator, namingMethod, null) ); }
public void ShouldTryToPersistIfPersistenceServiceSupplied() { IPersistenceService persistenceService = mocks.DynamicMock <IPersistenceService>(); using (mocks.Record()) { sourceList.Expect(x => x.Count).Return(categoryCount).Repeat.Any(); randomGenerator.Expect(x => x.Next(minCategories, maxCategories)).Return(1).Repeat.Times(12); sourceList.Expect(x => x[0]).Return(new MyHierarchicalClass()).Repeat.Any(); sourceList.Expect(x => x.RemoveAt(0)).Repeat.Any(); persistenceService.Expect(x => x.Create(Arg <MyHierarchicalClass> .Is.TypeOf)).Repeat.Times(12); persistenceService.Expect(x => x.Update(Arg <IList <MyHierarchicalClass> > .Is.TypeOf)).Repeat.Times(1); } using (mocks.Playback()) { hierarchyGenerator = new HierarchyGenerator <MyHierarchicalClass>(sourceList, (x, y) => x.AddChild(y), numberOfRoots, depth, minCategories, maxCategories, randomGenerator, namingMethod, persistenceService); hierarchyGenerator.Generate(); } }
static void Main() { var hg = new HierarchyGenerator(); Console.WriteLine(hg.Current); // 1 hg.DownOneLevel(); Console.WriteLine(hg.Current); // 1.1 hg.DownOneLevel(); Console.WriteLine(hg.Current); // 1.1.1 hg.MoveNext(); Console.WriteLine(hg.Current); // 1.1.2 hg.MoveNext(); Console.WriteLine(hg.Current); // 1.1.3 hg.UpLevels(1); Console.WriteLine(hg.Current); // 1.2 hg.MoveNext(); Console.WriteLine(hg.Current); // 1.3 hg.UpLevels(1); Console.WriteLine(hg.Current); // 2 hg.DownOneLevel(); Console.WriteLine(hg.Current); // 2.1 }
public void ShouldTryToPersistIfPersistenceServiceSupplied() { IPersistenceService persistenceService = mocks.DynamicMock<IPersistenceService>(); using (mocks.Record()) { sourceList.Expect(x => x.Count).Return(categoryCount).Repeat.Any(); randomGenerator.Expect(x => x.Next(minCategories, maxCategories)).Return(1).Repeat.Times(12); sourceList.Expect(x => x[0]).Return(new MyHierarchicalClass()).Repeat.Any(); sourceList.Expect(x => x.RemoveAt(0)).Repeat.Any(); persistenceService.Expect(x => x.Create(Arg<MyHierarchicalClass>.Is.TypeOf)).Repeat.Times(12); persistenceService.Expect(x => x.Update(Arg<IList<MyHierarchicalClass>>.Is.TypeOf)).Repeat.Times(1); } using (mocks.Playback()) { hierarchyGenerator = new HierarchyGenerator<MyHierarchicalClass>(sourceList, (x, y) => x.AddChild(y), numberOfRoots, depth, minCategories, maxCategories, randomGenerator, namingMethod, persistenceService); hierarchyGenerator.Generate(); } }
public void HierarchyGeneratorConstructor_SourceListNotBigEnough_Complains() { // Formula is (maxCategories^0 + maxCategories^1 + maxCategories^2) * numRoots // = (5^0 + 5^1 + 5^2) * 4 // = (1 + 5 + 25) * 4 // = 31 * 4 // = 124 const int requiredSizeOfList = 124; using (mocks.Record()) { sourceList.Expect(x => x.Count).Return(requiredSizeOfList - 1); } using (mocks.Playback()) { // TODO FIX #if !SILVERLIGHT Assert.Throws<ArgumentException>( () => hierarchyGenerator = new HierarchyGenerator<MyHierarchicalClass>(sourceList, null, numberOfRoots, depth, minCategories, maxCategories, randomGenerator, namingMethod, null) ); #endif } }