Exemple #1
0
        public async Task TestGetProject_WhenStatusIsSucceededButProjectIsAbsent_ReturnsNull()
        {
            var connection = Substitute.For <ITfsConnection>();

            connection.GetProjects().Returns(Enumerable.Empty <ITfProject>());
            _connectionFactory.Create(_testUri).Returns(connection);
            var systemUnderTest = new TfProjectCollection(_testUri, _connectionFactory, _logger);

            await systemUnderTest.RetrieveProjects();

            Assert.That(systemUnderTest.GetProject(Guid.NewGuid()), Is.Null);
        }
Exemple #2
0
        public async Task TestRetrieveProjects_WhenGettingProjectsFailsForUnknownReason_SetsStatusToFailedReasonUnknown(Exception exception)
        {
            var tfsConnection = Substitute.For <ITfsConnection>();

            _connectionFactory.Create(_testUri).Returns(tfsConnection);
            var systemUnderTest = new TfProjectCollection(_testUri, _connectionFactory, _logger);

            tfsConnection.GetProjects().Throws(callInfo => exception);

            await systemUnderTest.RetrieveProjects();

            Assert.That(systemUnderTest.ProjectRetrievalStatus, Is.EqualTo(RetrievalStatus.FailedReasonUnknown));
        }
Exemple #3
0
        public async Task TestRetrieveProjects_WhenStatusIsUnstarted_SetsStatusToRetrieving()
        {
            var tfsConnection = Substitute.For <ITfsConnection>();

            _connectionFactory.Create(_testUri).Returns(tfsConnection);
            var systemUnderTest = new TfProjectCollection(_testUri, _connectionFactory, _logger);

            tfsConnection.GetProjects().Returns(info =>
            {
                Assert.That(systemUnderTest.ProjectRetrievalStatus, Is.EqualTo(RetrievalStatus.Ongoing));
                return(Enumerable.Empty <ITfProject>());
            });

            await systemUnderTest.RetrieveProjects();
        }
Exemple #4
0
        public async Task TestRetrieveProjects_WhenGettingProjectsSucceeds_SetsStatusToSucceeded()
        {
            var tfsConnection = Substitute.For <ITfsConnection>();

            _connectionFactory.Create(_testUri).Returns(tfsConnection);
            var systemUnderTest = new TfProjectCollection(_testUri, _connectionFactory, _logger);
            var firstProject    = Substitute.For <ITfProject>();

            firstProject.Id.Returns(Guid.NewGuid());
            var projects = new[] { firstProject };

            tfsConnection.GetProjects().Returns(projects);

            await systemUnderTest.RetrieveProjects();

            Assert.That(systemUnderTest.ProjectRetrievalStatus, Is.EqualTo(RetrievalStatus.Suceeded));
        }
Exemple #5
0
        public async Task TestGetProject_WhenStatusIsSucceededAndProjectIsPresent_ReturnsProject()
        {
            var connection      = Substitute.For <ITfsConnection>();
            var expectedProject = Substitute.For <ITfProject>();
            var projectId       = Guid.NewGuid();

            expectedProject.Id.Returns(projectId);
            var projects = new [] { expectedProject };

            connection.GetProjects().Returns(projects);
            _connectionFactory.Create(_testUri).Returns(connection);
            var systemUnderTest = new TfProjectCollection(_testUri, _connectionFactory, _logger);
            await systemUnderTest.RetrieveProjects();

            var actualProject = systemUnderTest.GetProject(projectId);

            Assert.That(actualProject, Is.EqualTo(expectedProject));
        }
Exemple #6
0
        public async Task TestRetrieveProjects_WhenStatusIsUnstarted_GetsProjectsFromConnection()
        {
            var tfsConnection = Substitute.For <ITfsConnection>();

            _connectionFactory.Create(_testUri).Returns(tfsConnection);
            var systemUnderTest = new TfProjectCollection(_testUri, _connectionFactory, _logger);
            var firstProject    = Substitute.For <ITfProject>();

            firstProject.Id.Returns(Guid.NewGuid());
            var secondProject = Substitute.For <ITfProject>();

            secondProject.Id.Returns(Guid.NewGuid());
            var projects = new[] { firstProject, secondProject };

            tfsConnection.GetProjects().Returns(projects);

            await systemUnderTest.RetrieveProjects();

            foreach (var tfProject in projects)
            {
                Assert.That(systemUnderTest.Projects, Contains.Item(tfProject));
            }
        }
Exemple #7
0
        public void TestProjects_ImmediatelyAfterConstruction_IsNotNull()
        {
            var systemUnderTest = new TfProjectCollection(_testUri, _connectionFactory, _logger);

            Assert.That(systemUnderTest.Projects, Is.Not.Null);
        }
Exemple #8
0
        public void TestConstructor_SetsRetrievalStatusToUnstarted()
        {
            var systemUnderTest = new TfProjectCollection(_testUri, _connectionFactory, _logger);

            Assert.That(systemUnderTest.ProjectRetrievalStatus, Is.EqualTo(RetrievalStatus.Unstarted));
        }
Exemple #9
0
        public void TestGetProject_WhenStatusIsUnstarted_ThrowsInvalidOperation()
        {
            var systemUnderTest = new TfProjectCollection(_testUri, _connectionFactory, _logger);

            Assert.That(() => systemUnderTest.GetProject(Arg.Any <Guid>()), Throws.InvalidOperationException);
        }