コード例 #1
0
        public async Task GivenOneAgentswithNoTargets_WhenGetAssignments_NoTargetsReturn()
        {
            // Arrange
            IWatcherRepository watcherRepository = new CosmosWatcherRepository(_watcherOption, _loggerFactory);
            await watcherRepository.Database.Delete(_databaseName);

            await watcherRepository.InitializeContainers();

            IAgentController agentController = new AgentController(_watcherOption, watcherRepository, _loggerFactory.CreateLogger <AgentController>());

            agentController.Should().NotBeNull();
            AgentRecord agentRecord = await agentController.CreateTestAgent(1);

            IRecordContainer <TargetRecord> targetContainer = await watcherRepository.Container.Create <TargetRecord>();

            targetContainer.Should().NotBeNull();


            // Act
            await agentController.LoadBalanceAssignments();

            IReadOnlyList <TargetRecord> targetRecords = await targetContainer.GetAssignments(agentRecord.Id, _loggerFactory.CreateLogger <TargetRecord>());

            // Assert
            targetRecords.Should().NotBeNull();
            targetRecords.Count.Should().Be(0);

            // Clean up
            await watcherRepository.Database.Delete(_databaseName);
        }
コード例 #2
0
        public async Task GiveOneAgentsAddingTargets_WhenGetAssignments_CorrectTargetsShouldBeReturned()
        {
            // Arrange
            IWatcherRepository watcherRepository = new CosmosWatcherRepository(_watcherOption, _loggerFactory);
            await watcherRepository.Database.Delete(_databaseName, CancellationToken.None);

            await watcherRepository.InitializeContainers();

            IRecordContainer <TargetRecord> targetContainer = await watcherRepository.Container.Create <TargetRecord>();

            targetContainer.Should().NotBeNull();

            IAgentController agentController = new AgentController(_watcherOption, watcherRepository, _loggerFactory.CreateLogger <AgentController>());

            // Act
            const int   max         = 10;
            AgentRecord agentRecord = await agentController.CreateTestAgent(1);

            foreach (int targetCount in Enumerable.Range(1, max))
            {
                await targetContainer.CreateTestTarget(targetCount);

                await agentController.LoadBalanceAssignments();

                IReadOnlyList <TargetRecord> assignments = await targetContainer.GetAssignments(agentRecord.Id, _loggerFactory.CreateLogger <TargetRecord>());

                assignments.Count.Should().BeGreaterThan(targetCount);
            }

            // Clean up
            await watcherRepository.Database.Delete(_databaseName, CancellationToken.None);
        }