public void ShouldReturnAListOfDashboardItemsToView()
        {
            var expectedItems = new List <DashBoardItem> {
                new DashBoardItem()
            };
            var uow = new Mock <IUnitOfWork>();

            uow.Setup(m => m.DashBoardRepository.Get()).Returns(expectedItems);
            var controller = new DashboardController(uow.Object);

            var items = controller.GetDashboard();

            Assert.AreEqual(expectedItems.Count, ((IList)items).Count);
        }
Exemple #2
0
        public async Task GetDashboard()
        {
            Random random             = new Random();
            Guid   grantParentScopeId = random.NextGuid();
            Guid   parentScopeId      = random.NextGuid();
            Guid   childScopeId       = random.NextGuid();

            DHCPv6RootScope rootScope = GetDHCPv6RootScope();

            rootScope.Load(new List <DomainEvent>
            {
                new DHCPv6ScopeEvents.DHCPv6ScopeAddedEvent(
                    new DHCPv6ScopeCreateInstruction
                {
                    Name = "grant parent",
                    Id   = grantParentScopeId,
                }),
                new DHCPv6ScopeEvents.DHCPv6ScopeAddedEvent(
                    new DHCPv6ScopeCreateInstruction
                {
                    Name     = "parent",
                    Id       = parentScopeId,
                    ParentId = grantParentScopeId
                }),
                new DHCPv6ScopeEvents.DHCPv6ScopeAddedEvent(
                    new DHCPv6ScopeCreateInstruction
                {
                    Name     = "child",
                    Id       = childScopeId,
                    ParentId = parentScopeId
                }),
            });

            DHCPv4RootScope dhcpv4RootScope = GetDHCPv4RootScope();

            dhcpv4RootScope.Load(new List <DomainEvent>
            {
                new DHCPv4ScopeEvents.DHCPv4ScopeAddedEvent(
                    new DHCPv4ScopeCreateInstruction
                {
                    Name = "grant parent",
                    Id   = grantParentScopeId,
                }),
                new DHCPv4ScopeEvents.DHCPv4ScopeAddedEvent(
                    new DHCPv4ScopeCreateInstruction
                {
                    Name     = "parent",
                    Id       = parentScopeId,
                    ParentId = grantParentScopeId
                }),
                new DHCPv4ScopeEvents.DHCPv4ScopeAddedEvent(
                    new DHCPv4ScopeCreateInstruction
                {
                    Name     = "child",
                    Id       = childScopeId,
                    ParentId = parentScopeId
                }),
            });

            DashboardResponse response = new DashboardResponse
            {
                DHCPv6 = new DHCPOverview <DHCPv6LeaseEntry, DHCPv6PacketHandledEntry>
                {
                    ActiveInterfaces = random.Next(3, 10),
                },
                DHCPv4 = new DHCPOverview <DHCPv4LeaseEntry, DHCPv4PacketHandledEntry>
                {
                    ActiveInterfaces = random.Next(3, 10),
                },
            };

            Int32 expectedPipelineAmount = random.Next(3, 10);

            Mock <IDHCPv6ReadStore> readStoreMock = new Mock <IDHCPv6ReadStore>(MockBehavior.Strict);

            readStoreMock.Setup(x => x.GetDashboardOverview()).ReturnsAsync(response).Verifiable();

            Mock <INotificationEngine> notificationEngineMock = new Mock <INotificationEngine>(MockBehavior.Strict);

            notificationEngineMock.Setup(x => x.GetPipelineAmount()).Returns(expectedPipelineAmount).Verifiable();

            var controller   = new DashboardController(rootScope, dhcpv4RootScope, readStoreMock.Object, notificationEngineMock.Object);
            var actionResult = await controller.GetDashboard();

            var result = actionResult.EnsureOkObjectResult <DashboardResponse>(true);

            Assert.NotNull(result);
            Assert.NotNull(result.DHCPv6);
            Assert.NotNull(result.DHCPv4);

            Assert.Equal(3, result.DHCPv6.ScopeAmount);
            Assert.Equal(response.DHCPv6.ActiveInterfaces, result.DHCPv6.ActiveInterfaces);
            Assert.Equal(expectedPipelineAmount, result.AmountOfPipelines);

            Assert.Equal(3, result.DHCPv4.ScopeAmount);
            Assert.Equal(response.DHCPv4.ActiveInterfaces, result.DHCPv4.ActiveInterfaces);

            readStoreMock.Verify();
        }