Пример #1
0
        public static IQueryable <TestAgentDto> CreateMany(TestAgentStatus status)
        {
            var fixture = new Fixture();

            fixture.Register(() => status);
            var result = fixture.CreateMany <TestAgentDto>().AsQueryable();

            return(result);
        }
Пример #2
0
        public static IQueryable <TestAgentDto> CreateWithoutCurrentMachineName(TestAgentStatus status, int count, int testAgentId)
        {
            var fixture = new Fixture();

            fixture.Register(() => status);
            fixture.Customize <TestAgentDto>(ta => ta.With(x => x.TestAgentId, testAgentId));

            var result = fixture.CreateMany <TestAgentDto>(count).AsQueryable();

            return(result);
        }
Пример #3
0
        public static IQueryable <TestAgentDto> CreateMany(string agentTag, TestAgentStatus status)
        {
            var fixture = new Fixture();

            fixture.Register(() => status);
            fixture.Customize <TestAgentDto>(ta => ta.With(x => x.AgentTag, agentTag));

            var result = fixture.CreateMany <TestAgentDto>().AsQueryable();

            return(result);
        }
Пример #4
0
        public static IQueryable <TestAgentDto> CreateWithCurrentMachineName(TestAgentStatus status, int count)
        {
            var    fixture  = new Fixture();
            string agentTag = fixture.Create <string>();

            fixture.Register(() => status);
            fixture.Customize <TestAgentDto>(ta => ta.With(x => x.MachineName, Environment.MachineName).With(x => x.AgentTag, agentTag));

            var result = fixture.CreateMany <TestAgentDto>(count).AsQueryable();

            return(result);
        }
        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 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 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);
        }
Пример #8
0
        public static IQueryable <TestAgentDto> CreateManyOnlyOneWithCurrentMachineName(TestAgentStatus status)
        {
            var fixture = new Fixture();

            fixture.Register(() => status);
            var withoutCurrentMachineTestAgents = fixture.CreateMany <TestAgentDto>().AsQueryable();

            fixture.Customize <TestAgentDto>(ta => ta.With(x => x.MachineName, Environment.MachineName));
            var currentMachineTestAgent = fixture.CreateMany <TestAgentDto>(1).AsQueryable();

            return(currentMachineTestAgent.Union(withoutCurrentMachineTestAgents));
        }