public void Should_return_valid_node_calling_GetRootNode() { // arrange var rootNodeTarget = new HierarchyNode { Id = 0, LeftId = 1, RightId = 2 }; var mockHierarchyDataProvider = new Mock <IHierarchyDataProvider>(); mockHierarchyDataProvider .Setup(p => p.GetRootNode(It.IsAny <HierarchyEntry>())) .Returns(rootNodeTarget); var mockHierarchyEntryRepository = new Mock <IHierarchyEntryRepository>(); var mockTargetEntryRepository = new Mock <ITargetEntryRepository>(); var mockTargetRepository = new Mock <ITargetRepository>(); var mockTargetTypes = new List <Type>(); var service = new HierarchyService(mockHierarchyDataProvider.Object, mockHierarchyEntryRepository.Object, mockTargetEntryRepository.Object, mockTargetRepository.Object, mockTargetTypes); // act var rootHierarchyNode = service.GetRootNode(hierarchyEntry); // assert Assert.That(rootHierarchyNode, Is.Not.Null); Assert.That(rootHierarchyNode.LeftId, Is.EqualTo(1)); Assert.That(rootHierarchyNode.RightId, Is.EqualTo(2)); Assert.That(rootHierarchyNode.Id, Is.EqualTo(0)); mockHierarchyDataProvider.Verify(p => p.GetRootNode(It.IsAny <HierarchyEntry>())); }
public void Should_return_valid_Root_Node_calling_Initializehierarchy() { // arrange var rootNodeTarget = new TestTarget { Id = 0, Data = new TestTargetData { TestString = "Profile Root" } }; var mockHierarchyDataProvider = new Mock <IHierarchyDataProvider>(); mockHierarchyDataProvider.Setup(p => p.Add(It.IsAny <HierarchyEntry>(), It.IsAny <HierarchyNode>())); var mockHierarchyEntryRepository = new Mock <IHierarchyEntryRepository>(); var mockTargetEntryRepository = new Mock <ITargetEntryRepository>(); var mockTargetRepository = new Mock <ITargetRepository>(); var mockTargetTypes = new List <Type>(); var service = new HierarchyService(mockHierarchyDataProvider.Object, mockHierarchyEntryRepository.Object, mockTargetEntryRepository.Object, mockTargetRepository.Object, mockTargetTypes); // act var rootHierarchyNode = service.InitializeHierarchy(hierarchyEntry, rootNodeTarget); // assert Assert.That(rootHierarchyNode, Is.Not.Null); Assert.That(rootHierarchyNode.LeftId, Is.EqualTo(1)); Assert.That(rootHierarchyNode.RightId, Is.EqualTo(2)); Assert.That(rootHierarchyNode.Id, Is.EqualTo(0)); mockHierarchyDataProvider .Verify(p => p.Add(It.IsAny <HierarchyEntry>(), It.IsAny <HierarchyNode>())); }
public void Should_return_children_calling_GetChildren() { // arrange var testTarget = new TestTarget { Id = 345, Data = new TestTargetData { TestString = "Its a target!" } }; var parentNode = new HierarchyNode { Id = 23, LeftId = 1, RightId = 6, TargetId = testTarget.Id }; var child1 = new HierarchyNode { Id = 45, LeftId = 2, RightId = 3, TargetId = testTarget.Id }; var child2 = new HierarchyNode { Id = 46, LeftId = 4, RightId = 5, TargetId = testTarget.Id }; var mockHierarchyDataProvider = new Mock <IHierarchyDataProvider>(); mockHierarchyDataProvider.Setup(p => p.GetChildren(It.IsAny <HierarchyEntry>(), It.IsAny <HierarchyNode>())) .Returns(new List <HierarchyNode> { child1, child2 }); var mockHierarchyEntryRepository = new Mock <IHierarchyEntryRepository>(); var mockTargetEntryRepository = new Mock <ITargetEntryRepository>(); var mockTargetRepository = new Mock <ITargetRepository>(); var mockTargetTypes = new List <Type>(); var service = new HierarchyService(mockHierarchyDataProvider.Object, mockHierarchyEntryRepository.Object, mockTargetEntryRepository.Object, mockTargetRepository.Object, mockTargetTypes); // act var resultNode = service.GetChildren(hierarchyEntry, parentNode); // assert Assert.That(resultNode, Is.Not.Null); Assert.That(resultNode.Count, Is.EqualTo(2)); Assert.That(resultNode[0].Id, Is.EqualTo(child1.Id)); Assert.That(resultNode[0].LeftId, Is.EqualTo(child1.LeftId)); Assert.That(resultNode[0].RightId, Is.EqualTo(child1.RightId)); Assert.That(resultNode[0].TargetId, Is.EqualTo(child1.TargetId)); mockHierarchyDataProvider.Verify(p => p.GetChildren(It.IsAny <HierarchyEntry>(), It.IsAny <HierarchyNode>())); }
public void Should_return_parent_calling_GetParent() { // arrange var testTarget = new TestTarget { Id = 345, Data = new TestTargetData { TestString = "Its a target!" } }; var childNode = new HierarchyNode { Id = 34, LeftId = 2, RightId = 3, TargetId = testTarget.Id }; var parentNode = new HierarchyNode { Id = 22, LeftId = 1, RightId = 6, TargetId = testTarget.Id }; var mockHierarchyDataProvider = new Mock <IHierarchyDataProvider>(); mockHierarchyDataProvider.Setup(p => p.GetParent(It.IsAny <HierarchyEntry>(), It.IsAny <HierarchyNode>())) .Returns(parentNode); var mockHierarchyEntryRepository = new Mock <IHierarchyEntryRepository>(); var mockTargetEntryRepository = new Mock <ITargetEntryRepository>(); var mockTargetRepository = new Mock <ITargetRepository>(); var mockTargetTypes = new List <Type>(); var service = new HierarchyService(mockHierarchyDataProvider.Object, mockHierarchyEntryRepository.Object, mockTargetEntryRepository.Object, mockTargetRepository.Object, mockTargetTypes); // act var resultNode = service.GetParent(hierarchyEntry, childNode); // assert Assert.That(resultNode, Is.Not.Null); Assert.That(resultNode.Id, Is.EqualTo(parentNode.Id)); Assert.That(resultNode.LeftId, Is.EqualTo(parentNode.LeftId)); Assert.That(resultNode.RightId, Is.EqualTo(parentNode.RightId)); Assert.That(resultNode.TargetId, Is.EqualTo(parentNode.TargetId)); mockHierarchyDataProvider.Verify(p => p.GetParent(It.IsAny <HierarchyEntry>(), It.IsAny <HierarchyNode>())); }
Task <bool> IRequestHandler <UpdateHierarchyRequest, bool> .Handle(UpdateHierarchyRequest request, CancellationToken cancellationToken) { var existingHierarchy = HierarchyService.Get(request.Hierarchy.Id); if (existingHierarchy == null) { throw new ApplicationException($"UpdateHierarchyHandler: Hierarchy with Id {request.Hierarchy.Id} does not exist."); } //AutoMapper to Map the fields Mapper.Map(request.Hierarchy, existingHierarchy); using (var ts = new TransactionScope()) { var updatedHierarchy = HierarchyService.Update(existingHierarchy); ts.Complete(); } return(Task.FromResult(true)); }
public void Should_return_valid_node_calling_InsertNode() { // arrange var parentNode = new HierarchyNode { Id = 0, LeftId = 1, RightId = 2 }; var childTarget = new TestTarget { Id = 345, Data = new TestTargetData { TestString = "Its a boy!" } }; var mockHierarchyDataProvider = new Mock <IHierarchyDataProvider>(); mockHierarchyDataProvider.Setup(p => p.PrepareForInsertNode(It.IsAny <HierarchyEntry>(), It.IsAny <HierarchyNode>())); mockHierarchyDataProvider.Setup(p => p.Add(It.IsAny <HierarchyEntry>(), It.IsAny <HierarchyNode>())); var mockHierarchyEntryRepository = new Mock <IHierarchyEntryRepository>(); var mockTargetEntryRepository = new Mock <ITargetEntryRepository>(); var mockTargetRepository = new Mock <ITargetRepository>(); var mockTargetTypes = new List <Type>(); var service = new HierarchyService(mockHierarchyDataProvider.Object, mockHierarchyEntryRepository.Object, mockTargetEntryRepository.Object, mockTargetRepository.Object, mockTargetTypes); // act var newHierarchyNode = service.InsertNode(hierarchyEntry, parentNode, childTarget); // assert Assert.That(newHierarchyNode, Is.Not.Null); Assert.That(newHierarchyNode.LeftId, Is.EqualTo(parentNode.RightId)); Assert.That(newHierarchyNode.RightId, Is.EqualTo(parentNode.RightId + 1)); Assert.That(newHierarchyNode.Id, Is.EqualTo(0)); mockHierarchyDataProvider.Verify(p => p.PrepareForInsertNode(It.IsAny <HierarchyEntry>(), It.IsAny <HierarchyNode>())); mockHierarchyDataProvider.Verify(p => p.Add(It.IsAny <HierarchyEntry>(), It.IsAny <HierarchyNode>())); }
public static void Initialize() { // verify tables var dataProvider = new MssqlDataProvider(); var hierarchyDataProvider = new MssqlHierarchyDataProvider(dataProvider); var hierarchyEntryRepository = new HierarchyEntryRepository(dataProvider); var targetEntryRepository = new TargetEntryRepository(dataProvider); var targetRepository = new TargetRepository(dataProvider); var assembly = Assembly.GetCallingAssembly(); var targetTypes = assembly.GetTypesOfType <ITarget>(); var hierarchyService = new HierarchyService(hierarchyDataProvider, hierarchyEntryRepository, targetEntryRepository, targetRepository, targetTypes); // build missing tables // register structureMap }
public void Should_verify_calling_DeleteNode() { // arrange var deleteNode = new HierarchyNode { Id = 1, LeftId = 2, RightId = 3 }; var mockHierarchyDataProvider = new Mock <IHierarchyDataProvider>(); mockHierarchyDataProvider.Setup(p => p.Delete(It.IsAny <HierarchyEntry>(), It.IsAny <HierarchyNode>())); var mockHierarchyEntryRepository = new Mock <IHierarchyEntryRepository>(); var mockTargetEntryRepository = new Mock <ITargetEntryRepository>(); var mockTargetRepository = new Mock <ITargetRepository>(); var mockTargetTypes = new List <Type>(); var service = new HierarchyService(mockHierarchyDataProvider.Object, mockHierarchyEntryRepository.Object, mockTargetEntryRepository.Object, mockTargetRepository.Object, mockTargetTypes); // act service.DeleteNode(hierarchyEntry, deleteNode); // assert mockHierarchyDataProvider.Verify(p => p.Delete(It.IsAny <HierarchyEntry>(), It.IsAny <HierarchyNode>())); }
public void Should_return_ancestors_calling_GetAncestors() { // arrange var testTarget = new TestTarget { Id = 345, Data = new TestTargetData { TestString = "Its a target!" } }; var node = new HierarchyNode { Id = 34, LeftId = 2, RightId = 3, TargetId = testTarget.Id }; var ancestor1 = new HierarchyNode { Id = 22, LeftId = 1, RightId = 6, TargetId = testTarget.Id }; var ancestor2 = new HierarchyNode { Id = 11, LeftId = 1, RightId = 13, TargetId = testTarget.Id }; var mockHierarchyDataProvider = new Mock <IHierarchyDataProvider>(); mockHierarchyDataProvider.Setup(p => p.GetAncestors(It.IsAny <HierarchyEntry>(), It.IsAny <HierarchyNode>(), true, true)) .Returns(new List <HierarchyNode> { ancestor2, ancestor1, node }); var mockHierarchyEntryRepository = new Mock <IHierarchyEntryRepository>(); var mockTargetEntryRepository = new Mock <ITargetEntryRepository>(); var mockTargetRepository = new Mock <ITargetRepository>(); var mockTargetTypes = new List <Type>(); var service = new HierarchyService(mockHierarchyDataProvider.Object, mockHierarchyEntryRepository.Object, mockTargetEntryRepository.Object, mockTargetRepository.Object, mockTargetTypes); // act var resultNode = service.GetAncestors(hierarchyEntry, node, true, true); // assert Assert.That(resultNode, Is.Not.Null); Assert.That(resultNode.Count, Is.EqualTo(3)); Assert.That(resultNode[0].Id, Is.EqualTo(ancestor2.Id)); Assert.That(resultNode[0].LeftId, Is.EqualTo(ancestor2.LeftId)); Assert.That(resultNode[0].RightId, Is.EqualTo(ancestor2.RightId)); Assert.That(resultNode[0].TargetId, Is.EqualTo(ancestor2.TargetId)); Assert.That(resultNode[1].Id, Is.EqualTo(ancestor1.Id)); Assert.That(resultNode[1].LeftId, Is.EqualTo(ancestor1.LeftId)); Assert.That(resultNode[1].RightId, Is.EqualTo(ancestor1.RightId)); Assert.That(resultNode[1].TargetId, Is.EqualTo(ancestor1.TargetId)); Assert.That(resultNode[2].Id, Is.EqualTo(node.Id)); Assert.That(resultNode[2].LeftId, Is.EqualTo(node.LeftId)); Assert.That(resultNode[2].RightId, Is.EqualTo(node.RightId)); Assert.That(resultNode[2].TargetId, Is.EqualTo(node.TargetId)); mockHierarchyDataProvider.Verify(p => p.GetAncestors(It.IsAny <HierarchyEntry>(), It.IsAny <HierarchyNode>(), true, true)); }
public override void SetUp() { base.SetUp(); hierarchy = new UIHierarchy(Host, CreateDefaultConfiguration()); HierarchyService.AddHierarchy(hierarchy); }
public static void EverythingWorks() { var jsonOutput = new HierarchyService(new ReportingService()).GetCompanyHierarchy(); Assert.NotNull(jsonOutput); }
public static void Main(string[] args) { var jsonOutput = new HierarchyService(new ReportingService()).GetCompanyHierarchy(); Console.WriteLine(jsonOutput); }