void Start()
        {
            _myModules      = new ModuleContainer(); // will be used in the future
            _myAgentFactory = _myModules.AgentFactory;
            _myWorldGrid    = _myModules.WorldGrid;
            for (int i = 0; i < 20; i++)
            {
                _myAgentFactory.CreateAgent(_myWorldGrid);
            }
            _myWorldGrid.Started = true;

            /*
             * float actualTestX = (float)3.3;
             * float actualTestY = (float)6.7;
             *
             * Debug.Log(_myWorldGrid.GetClosestDistance(3, 6, actualTestX, actualTestY, 2, 5));
             * Debug.Log(_myWorldGrid.GetClosestDistance(3, 6, actualTestX, actualTestY, 2, 6));
             * Debug.Log(_myWorldGrid.GetClosestDistance(3, 6, actualTestX, actualTestY, 2, 7));
             * Debug.Log(_myWorldGrid.GetClosestDistance(3, 6, actualTestX, actualTestY, 3, 5));
             * Debug.Log(_myWorldGrid.GetClosestDistance(3, 6, actualTestX, actualTestY, 3, 7));
             * Debug.Log(_myWorldGrid.GetClosestDistance(3, 6, actualTestX, actualTestY, 4, 5));
             * Debug.Log(_myWorldGrid.GetClosestDistance(3, 6, actualTestX, actualTestY, 4, 6));
             * Debug.Log(_myWorldGrid.GetClosestDistance(3, 6, actualTestX, actualTestY, 4, 7));
             */
        }
        public async Task NotUpdateTestAgentStatus_When_TestAgentForCurrentMachineIsNotExistingInDatabaseSecondTime()
        {
            // Arrange
            var testAgents = TestAgentFactory.CreateWithCurrentMachineName(TestAgentStatus.Active, 1);

            _testAgentRepositoryMock.SetupSequence(x => x.GetAllAsync()).Returns(Task.FromResult(testAgents)).Returns(Task.FromResult(TestAgentFactory.CreateEmpty()));

            // Act
            await _testAgentStateSwitcher.SetTestAgentAsInactiveAsync(testAgents.First().AgentTag);

            // Assert
            _testAgentRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny <int>(), It.IsAny <TestAgentDto>()), Times.Never);
        }
        public void ThrowException_When_MoreThanOneTestAgentExistsForCurrentMachineInStatus(TestAgentStatus status)
        {
            // Arrange
            var testAgents = TestAgentFactory.CreateWithCurrentMachineName(status, 2);

            _testAgentRepositoryMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(testAgents));

            // Act
            var action = new TestDelegate(() => _testAgentStateSwitcher.SetTestAgentAsInactiveAsync(testAgents.First().AgentTag));

            // Assert
            Assert.That(action, Throws.Exception.TypeOf <InvalidOperationException>());
        }
        public async Task NotUpdateTestAgentStatus_When_NoTestAgentsExists()
        {
            // Arrange
            var testAgents = TestAgentFactory.CreateEmpty();

            _testAgentRepositoryMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(testAgents));

            // Act
            _testAgentStateSwitcher.SetTestAgentAsActiveAsync(FixtureFactory.Create().Create <string>());

            // Assert
            _testAgentRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny <int>(), It.IsAny <TestAgentDto>()), Times.Never);
        }
        public async Task NotUpdateTestAgentStatus_When_TestAgentForCurrentMachineIsNotExistingFirstTime()
        {
            // Arrange
            var testAgents = TestAgentFactory.CreateMany();

            _testAgentRepositoryMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(new List <TestAgentDto>().AsQueryable()));

            // Act
            _testAgentStateSwitcher.SetTestAgentAsActiveAsync(testAgents.First().AgentTag);

            // Assert
            _testAgentRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny <int>(), It.IsAny <TestAgentDto>()), Times.Never);
        }
        public async Task ReturnCorrectTestAgent_When_OnlyOneTestAgentExistsWithProvidedTag()
        {
            // Arrange
            var testAgent = TestAgentFactory.CreateSingle(_agentTag);

            _testAgentRepositoryMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(testAgent));

            // Act
            var actualTestAgents = await _testAgentsService.GetAllActiveTestAgentsByTagAsync(_agentTag);

            // Assert
            Assert.That(actualTestAgents, Has.Exactly(1).EqualTo(testAgent.First()));
        }
        public void ThrowArgumentNullException_When_TheProvidedTagIsNull()
        {
            // Arrange
            var testAgents = TestAgentFactory.CreateMany();

            _testAgentRepositoryMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(testAgents));

            // Act
            var action = new TestDelegate(() => _testAgentsService.GetAllActiveTestAgentsByTagAsync(null));

            // Assert
            Assert.That(action, Throws.Exception.TypeOf <ArgumentNullException>());
        }
        public async Task ReturnNoTestAgents_When_NoTestAgentsExistsForTheProvidedTag()
        {
            // Arrange
            var testAgents = TestAgentFactory.CreateMany();

            _testAgentRepositoryMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(testAgents));

            // Act
            var actualTestAgents = await _testAgentsService.GetAllActiveTestAgentsByTagAsync(_agentTag);

            // Assert
            Assert.That(actualTestAgents, Is.Empty);
        }
        public async Task ReturnCorrectTestAgents_When_ManyTestAgentExistsWithProvidedTag()
        {
            // Arrange
            var testAgents = TestAgentFactory.CreateMany(_agentTag, Model.TestAgentStatus.Active);

            _testAgentRepositoryMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(testAgents));

            // Act
            var actualTestAgents = await _testAgentsService.GetAllActiveTestAgentsByTagAsync(_agentTag);

            // Assert
            Assert.That(actualTestAgents, Is.EquivalentTo(testAgents.ToList()));
        }
        public async Task NotUpdateTestAgentStatus_When_TestAgentForCurrentMachineIsInRunningTestsStatus()
        {
            // Arrange
            var testAgents  = TestAgentFactory.CreateWithCurrentMachineName(TestAgentStatus.RunningTests, 1);
            int testAgentId = testAgents.FirstOrDefault().TestAgentId;

            _testAgentRepositoryMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(testAgents));

            // Act
            await _testAgentStateSwitcher.SetTestAgentAsRunningTestsAsync(testAgents.First().AgentTag);

            // Assert
            _testAgentRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny <int>(), It.Is <TestAgentDto>(i => i.TestAgentId == testAgentId && i.Status == TestAgentStatus.Inactive)), Times.Never);
        }
        public async Task ReturnCorrectTestAgent_When_OneTestAgentExistsWithProvidedTag_AndTestAgentsWithDifferentTagsExists()
        {
            // Arrange
            var currentTagTestAgent     = TestAgentFactory.CreateSingle(_agentTag);
            var differentTagsTestAgents = TestAgentFactory.CreateMany();

            _testAgentRepositoryMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(currentTagTestAgent.Union(differentTagsTestAgents)));

            // Act
            var actualTestAgents = await _testAgentsService.GetAllActiveTestAgentsByTagAsync(_agentTag);

            // Assert
            Assert.That(actualTestAgents, Has.Exactly(1).EqualTo(currentTagTestAgent.First()));
        }
        public async Task UpdateTestAgentStatusToInactive_When_CurrentTestAgentStatusIs(TestAgentStatus status)
        {
            // Arrange
            var testAgents  = TestAgentFactory.CreateWithCurrentMachineName(status, 1);
            int testAgentId = testAgents.FirstOrDefault().TestAgentId;

            _testAgentRepositoryMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(testAgents));

            // Act
            await _testAgentStateSwitcher.SetTestAgentAsInactiveAsync(testAgents.First().AgentTag);

            // Assert
            _testAgentRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny <int>(), It.Is <TestAgentDto>(i => i.TestAgentId == testAgentId && i.Status == TestAgentStatus.Inactive)), Times.Once);
            _testAgentRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny <int>(), It.IsAny <TestAgentDto>()), Times.Once());
        }
        public async Task UpdateTestAgentStatusToActive_When_TestAgentsForDifferentMachineNamesExist_AndCurrentTestAgentStatusIs(TestAgentStatus status)
        {
            // Arrange
            var testAgentsWithCurrentMachine    = TestAgentFactory.CreateWithCurrentMachineName(status, 1);
            var testAgentsWithoutCurrentMachine = TestAgentFactory.CreateWithoutCurrentMachineName(status);
            var testAgentId = testAgentsWithCurrentMachine.FirstOrDefault().TestAgentId;
            var testAgents  = testAgentsWithCurrentMachine.Union(testAgentsWithoutCurrentMachine);

            _testAgentRepositoryMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(testAgents));

            // Act
            _testAgentStateSwitcher.SetTestAgentAsActiveAsync(testAgentsWithCurrentMachine.First().AgentTag);

            // Assert
            _testAgentRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny <int>(), It.Is <TestAgentDto>(i => i.TestAgentId == testAgentId && i.Status == TestAgentStatus.Active)), Times.Once);
            _testAgentRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny <int>(), It.IsAny <TestAgentDto>()), Times.Once);
        }
        public async Task InsertCurrentTestAgent_When_NoTestAgentsAreExistingInDatabase()
        {
            // Arrange
            var testAgents        = TestAgentFactory.CreateEmpty();
            var insertedTestAgent = default(Task <TestAgentDto>);

            _testAgentRepositoryMock.Setup(x => x.GetAllAsync()).Returns(Task.FromResult(testAgents));
            _testAgentRepositoryMock.Setup(x => x.CreateAsync(It.IsAny <TestAgentDto>())).Returns((Task <TestAgentDto> a) => insertedTestAgent = a);
            var testAgentTag = FixtureFactory.Create().Create <string>();

            // Act
            _testAgentStateSwitcher.SetTestAgentAsActiveAsync(testAgentTag);

            // Assert
            _testAgentRepositoryMock.Verify(x => x.GetAllAsync(), Times.Once());
            _testAgentRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny <int>(), It.IsAny <TestAgentDto>()), Times.Never);
            Assert.That(insertedTestAgent.Result.TestAgentId, Is.Not.Null);
            Assert.That(insertedTestAgent.Result.AgentTag, Is.EqualTo(testAgentTag));
            Assert.That(insertedTestAgent.Result.MachineName, Is.EqualTo(Environment.MachineName));
            Assert.That(insertedTestAgent.Status, Is.EqualTo(TestAgentStatus.Active));
        }