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 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 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 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(); } }