public void DevOpsAccess_ListDuplicateTestCases_EmptyDuplicateTestCases()
        {
            // Arrange
            var testManagementHttpClient   = new Mock <TestManagementHttpClient>(new Uri("http://dummy.url"), new VssCredentials());
            var workItemTrackingHttpClient = new Mock <WorkItemTrackingHttpClient>(new Uri("http://dummy.url"), new VssCredentials());

            var outputAccess = new Mock <IOutputAccess>();
            var messages     = new Messages();

            var fixture   = new Fixture();
            var testCases = fixture.Create <TestCase[]>();

            var options = new InputOptions()
            {
                ValidationOnly = true,
                VerboseLogging = true
            };
            var counter = new Counter();

            var azureDevOpsHttpClients = new AzureDevOpsHttpClients()
            {
                TestManagementHttpClient   = testManagementHttpClient.Object,
                WorkItemTrackingHttpClient = workItemTrackingHttpClient.Object
            };

            var target = new DevOpsAccessFactory(azureDevOpsHttpClients, messages, outputAccess.Object, options, counter).Create();

            // Act
            var actual = target.ListDuplicateTestCases(testCases);

            // Assert
            actual.Count.Should().Be(0);
        }
        public void DevOpsAccess_GetTestCasesId_EmptyArrayTestCasesId()
        {
            // Arrange
            var testManagementHttpClient   = new Mock <TestManagementHttpClient>(new Uri("http://dummy.url"), new VssCredentials());
            var workItemTrackingHttpClient = new Mock <WorkItemTrackingHttpClient>(new Uri("http://dummy.url"), new VssCredentials());

            var outputAccess = new Mock <IOutputAccess>();
            var messages     = new Messages();

            var options = new InputOptions()
            {
                ValidationOnly = true,
                VerboseLogging = true
            };
            var counter = new Counter();

            var azureDevOpsHttpClients = new AzureDevOpsHttpClients()
            {
                TestManagementHttpClient   = testManagementHttpClient.Object,
                WorkItemTrackingHttpClient = workItemTrackingHttpClient.Object
            };

            var target = new DevOpsAccessFactory(azureDevOpsHttpClients, messages, outputAccess.Object, options, counter).Create();

            testManagementHttpClient
            .Setup(x => x.GetPointsAsync(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), null, null, null, null, null, null, null, null, default))
            .ReturnsAsync(new List <TestPoint>());

            // Act
            var actual = target.GetTestCasesId();

            // Assert
            actual.Length.Should().Be(0);
        }
        public void DevOpsAccess_Associate_OperationSuccessIsFalse()
        {
            // Arrange
            var testManagementHttpClient   = new Mock <TestManagementHttpClient>(new Uri("http://dummy.url"), new VssCredentials());
            var workItemTrackingHttpClient = new Mock <WorkItemTrackingHttpClient>(new Uri("http://dummy.url"), new VssCredentials());

            var outputAccess = new Mock <IOutputAccess>();

            var fixture     = new Fixture();
            var messages    = new Messages();
            var testMethods = fixture.Create <TestMethod[]>();
            var testCases   = testMethods.Select(x => new TestCase(fixture.Create <int>(), x.Name, NotAutomatedName, string.Empty)).ToArray();

            var methodName      = fixture.Create <string>();
            var assemblyName    = fixture.Create <string>();
            var automatedTestId = fixture.Create <string>();
            var result          = new Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem
            {
                Fields = new Dictionary <string, object>()
                {
                    { AutomationStatusName, AutomatedName },
                    { AutomatedTestIdName, automatedTestId },
                    { AutomatedTestStorageName, assemblyName },
                    { AutomatedTestName, methodName }
                }
            };

            workItemTrackingHttpClient
            .Setup(x => x.UpdateWorkItemAsync(It.IsAny <JsonPatchDocument>(), It.IsAny <int>(), It.IsAny <bool?>(), null, null, null, null, default))
            .ReturnsAsync(result);

            var options = new InputOptions()
            {
                ValidationOnly = true,
                VerboseLogging = true
            };
            var counter = new Counter();

            var azureDevOpsHttpClients = new AzureDevOpsHttpClients()
            {
                TestManagementHttpClient   = testManagementHttpClient.Object,
                WorkItemTrackingHttpClient = workItemTrackingHttpClient.Object
            };

            var target = new DevOpsAccessFactory(azureDevOpsHttpClients, messages, outputAccess.Object, options, counter).Create();

            // Act
            var errorCount = target.Associate(testMethods, testCases.ToDictionary(v => v.Title, t => t));

            // Assert
            errorCount.Should().Be(testMethods.Length);
            counter.Total.Should().Be(0);
            counter.Success.FixedReference.Should().Be(0);
            counter.Error.TestCaseNotFound.Should().Be(0);
            counter.Error.OperationFailed.Should().Be(testMethods.Length);
            outputAccess.Verify(x => x.WriteToConsole(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Exactly(testMethods.Length));
        }
        public void DevOpsAccess_GetTestCasesId_NotEmptyArrayTestCasesId()
        {
            // Arrange
            var testManagementHttpClient   = new Mock <TestManagementHttpClient>(new Uri("http://dummy.url"), new VssCredentials());
            var workItemTrackingHttpClient = new Mock <WorkItemTrackingHttpClient>(new Uri("http://dummy.url"), new VssCredentials());

            var outputAccess = new Mock <IOutputAccess>();
            var messages     = new Messages();

            var fixture    = new Fixture();
            var testPoints = new List <TestPoint>()
            {
                fixture.Build <TestPoint>()
                .Without(x => x.LastUpdatedBy)
                .Without(x => x.AssignedTo)
                .Without(x => x.LastResultDetails)
                .With(x => x.TestCase, fixture.Build <WorkItemReference>().With(y => y.Id, fixture.Create <int>().ToString()).Create())
                .Create(),
                fixture.Build <TestPoint>()
                .Without(x => x.LastUpdatedBy)
                .Without(x => x.AssignedTo)
                .Without(x => x.LastResultDetails)
                .With(x => x.TestCase, fixture.Build <WorkItemReference>().With(y => y.Id, fixture.Create <int>().ToString()).Create())
                .Create(),
                fixture.Build <TestPoint>()
                .Without(x => x.LastUpdatedBy)
                .Without(x => x.AssignedTo)
                .Without(x => x.LastResultDetails)
                .With(x => x.TestCase, fixture.Build <WorkItemReference>().With(y => y.Id, fixture.Create <int>().ToString()).Create())
                .Create()
            };

            var options = new InputOptions()
            {
                ValidationOnly = true,
                VerboseLogging = true
            };
            var counter = new Counter();

            var azureDevOpsHttpClients = new AzureDevOpsHttpClients()
            {
                TestManagementHttpClient   = testManagementHttpClient.Object,
                WorkItemTrackingHttpClient = workItemTrackingHttpClient.Object
            };

            var target = new DevOpsAccessFactory(azureDevOpsHttpClients, messages, outputAccess.Object, options, counter).Create();

            testManagementHttpClient
            .Setup(x => x.GetPointsAsync(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), null, null, null, null, null, null, null, null, default))
            .ReturnsAsync(testPoints);

            // Act
            var actual = target.GetTestCasesId();

            // Assert
            actual.Length.Should().Be(testPoints.Count);
        }
        public void DevOpsAccess_Associate_TestCaseIsNull()
        {
            // Arrange
            var testManagementHttpClient   = new Mock <TestManagementHttpClient>(new Uri("http://dummy.url"), new VssCredentials());
            var workItemTrackingHttpClient = new Mock <WorkItemTrackingHttpClient>(new Uri("http://dummy.url"), new VssCredentials());

            var outputAccess = new Mock <IOutputAccess>();

            var fixture     = new Fixture();
            var messages    = new Messages();
            var testCases   = fixture.Create <TestCase[]>();
            var testMethods = fixture.Create <TestMethod[]>();

            var options = new InputOptions()
            {
                ValidationOnly = true,
                VerboseLogging = true
            };
            var counter = new Counter();

            var azureDevOpsHttpClients = new AzureDevOpsHttpClients()
            {
                TestManagementHttpClient   = testManagementHttpClient.Object,
                WorkItemTrackingHttpClient = workItemTrackingHttpClient.Object
            };

            var target = new DevOpsAccessFactory(azureDevOpsHttpClients, messages, outputAccess.Object, options, counter).Create();

            // Act
            var errorCount = target.Associate(testMethods, testCases.ToDictionary(v => v.Title, t => t));

            // Assert
            errorCount.Should().Be(testMethods.Length);
            counter.Error.Total.Should().Be(testMethods.Length);
            counter.Error.TestCaseNotFound.Should().Be(testMethods.Length);
            outputAccess.Verify(x => x.WriteToConsole(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Exactly(testMethods.Length));
        }
        public void DevOpsAccess_ListTestCasesWithNotAvailableTestMethods_EmptyListTestCasesWithNotAvailableTestMethodsWhereAutomationStatusIsNotEqualToAutomatedName()
        {
            // Arrange
            var testManagementHttpClient   = new Mock <TestManagementHttpClient>(new Uri("http://dummy.url"), new VssCredentials());
            var workItemTrackingHttpClient = new Mock <WorkItemTrackingHttpClient>(new Uri("http://dummy.url"), new VssCredentials());

            var outputAccess = new Mock <IOutputAccess>();

            var fixture  = new Fixture();
            var messages = new Messages();

            fixture.Customize <TestCase>(c => c.With(x => x.AutomationStatus, NotAutomatedName));
            var testCases   = fixture.Create <TestCase[]>();
            var testMethods = fixture.Create <TestMethod[]>();

            var options = new InputOptions()
            {
                ValidationOnly = true,
                VerboseLogging = true
            };
            var counter = new Counter();

            var azureDevOpsHttpClients = new AzureDevOpsHttpClients()
            {
                TestManagementHttpClient   = testManagementHttpClient.Object,
                WorkItemTrackingHttpClient = workItemTrackingHttpClient.Object
            };

            var target = new DevOpsAccessFactory(azureDevOpsHttpClients, messages, outputAccess.Object, options, counter).Create();

            // Act
            var actual = target.ListTestCasesWithNotAvailableTestMethods(testMethods, testCases);

            // Assert
            actual.Count.Should().Be(0);
        }