Ejemplo n.º 1
0
            public async Task DeleteIssueAsync_Where_SaveChangesAsync_Fails_Should__return_a_IssueNotCreatedException_Test()
            {
                // Arrange

                var expectedLog = $"Delete Issue: {IssueToDeleteDto.Id} Failed!";

                RepositoryWrapperMock
                .Setup(x => x.Issue.GetIssueByIdAsync(IssueToDeleteDto.Id))
                .ReturnsAsync(Issues[0]).Verifiable();

                RepositoryWrapperMock
                .Setup(x => x.SaveAsync())
                .Throws(new Exception("Save Changes Failed")).Verifiable();

                // Act

                await Assert.ThrowsAsync <IssueNotDeletedException>(() => ServiceUnderTest.DeleteIssueAsync(IssueToDeleteDto));

                // Assert

                LoggerMock.VerifyLog(LogLevel.Error, expectedLog);
                RepositoryWrapperMock.Verify(x => x.SaveAsync(), Times.Once);
                RepositoryWrapperMock
                .Verify(x => x.Issue.GetIssueByIdAsync(IssueToDeleteDto.Id), Times.Once);
            }
Ejemplo n.º 2
0
            public async Task UpdateIssueAsync_Should_Update_and_return_the_specified_Issue_Test()
            {
                // Arrange

                const int id = 1;
                var       issueToUpdateDto = new IssueForUpdateDto()
                {
                    Id = 1, IssueDescription = "Test 1 updated", DateAdded = DateTimeOffset.Now
                };

                RepositoryWrapperMock
                .Setup(x => x.Issue.GetIssueByIdAsync(id))
                .ReturnsAsync(Issues[0]).Verifiable();

                RepositoryWrapperMock
                .Setup(x => x.SaveAsync())
                .Returns(() => Task.Run(() => { return(1); })).Verifiable();

                // Act

                var result = await ServiceUnderTest.UpdateIssueAsync(issueToUpdateDto);

                // Assert

                result.Should().BeTrue();
                RepositoryWrapperMock.Verify(x => x.SaveAsync(), Times.Once);
                RepositoryWrapperMock
                .Verify(x => x.Issue.GetIssueByIdAsync(id), Times.Once);
            }
Ejemplo n.º 3
0
            public async Task CreateIssueAsync_Should_create_and_return_the_specified_Issue_Test()
            {
                // Arrange

                const int id          = 5;
                var       newIssueDto = new IssueForCreationDto
                {
                    Id = 5, IssueDescription = "Test 5", DateAdded = DateTimeOffset.Now
                };

                RepositoryWrapperMock
                .Setup(x => x.Issue.GetIssueByIdAsync(It.IsAny <int>()))
                .ReturnsAsync(default(Issue)).Verifiable();

                RepositoryWrapperMock
                .Setup(x => x.SaveAsync())
                .Returns(() => Task.Run(() => { return(1); })).Verifiable();

                // Act

                var result = await ServiceUnderTest.CreateIssueAsync(newIssueDto);

                // Assert

                result.Should().NotBeNull();
                result.Should().BeOfType <IssueDto>();
                result.Id.Should().Be(id);
                result.IssueDescription.Should().Be(newIssueDto.IssueDescription);
                RepositoryWrapperMock.Verify(x => x.SaveAsync(), Times.Once);
            }
Ejemplo n.º 4
0
            public async Task UpdateIssueAsync_Where_SaveChangesAsync_Fails_Should__return_a_IssueNotCreatedException_Test()
            {
                // Arrange

                const int id               = 1;
                var       expectedLog      = $"Updating Issue: {id} Failed!";
                var       issueToUpdateDto = new IssueForUpdateDto
                {
                    Id = 1, IssueDescription = "Test 1 updated", DateAdded = DateTimeOffset.Now
                };

                RepositoryWrapperMock
                .Setup(x => x.Issue.GetIssueByIdAsync(id))
                .ReturnsAsync(Issues[0]).Verifiable();

                RepositoryWrapperMock
                .Setup(x => x.SaveAsync())
                .Throws(new Exception("Save Changes Failed")).Verifiable();

                // Act

                await Assert.ThrowsAsync <IssueNotUpdatedException>(() => ServiceUnderTest.UpdateIssueAsync(issueToUpdateDto));

                // Assert

                LoggerMock.VerifyLog(LogLevel.Error, expectedLog);
                RepositoryWrapperMock.Verify(x => x.SaveAsync(), Times.Once);
                RepositoryWrapperMock
                .Verify(x => x.Issue.GetIssueByIdAsync(id), Times.Once);
            }
Ejemplo n.º 5
0
            public async Task GetIssueByIdAsync_With_Invalid_Id_Should_Return_Null_If_The_Issue_Does_Not_Exist_Test()
            {
                // Arrange

                var id = -1;

                RepositoryWrapperMock
                .Setup(x => x.Issue.GetIssueByIdAsync(id))
                .ReturnsAsync(default(Issue));

                // Act, Assert

                await Assert.ThrowsAsync <IssueNotFoundException>(() => ServiceUnderTest.GetIssueByIdAsync(id));
            }
Ejemplo n.º 6
0
            public async Task DeleteIssueAsync_With_A_NonExisting_Issue_Should_Return_IssueNotFoundException_Test()
            {
                // Arrange

                RepositoryWrapperMock
                .Setup(x => x.Issue.GetIssueByIdAsync(IssueToDeleteDto.Id))
                .ReturnsAsync(default(Issue)).Verifiable();

                // Act

                await Assert.ThrowsAsync <IssueNotFoundException>(() => ServiceUnderTest.DeleteIssueAsync(IssueToDeleteDto));

                // Assert

                RepositoryWrapperMock
                .Verify(x => x.Issue.GetIssueByIdAsync(IssueToDeleteDto.Id), Times.Once);
            }
Ejemplo n.º 7
0
            public async Task IssueExistsAsync_Should_Return_False_If_The_Issue_Does_Not_Exist_Test()
            {
                // Arrange

                const int id = 0;

                RepositoryWrapperMock
                .Setup(x => x.Issue.GetIssueByIdAsync(id))
                .ReturnsAsync(default(Issue));

                // Act

                var result = await ServiceUnderTest.IssueExistsAsync(id);

                // Assert

                Assert.False(result);
            }
Ejemplo n.º 8
0
            public async Task IssueExistsAsync_Should_Return_True_If_The_Issue_Exists_Test()
            {
                // Arrange

                var id = 1;

                RepositoryWrapperMock
                .Setup(x => x.Issue.GetIssueByIdAsync(id))
                .ReturnsAsync(new Issue());

                // Act

                var result = await ServiceUnderTest.IssueExistsAsync(id);

                // Assert

                Assert.True(result);
            }
Ejemplo n.º 9
0
            public async Task EnforceUserExistanceAsync_Should_Return_UserNotFoundException_If_The_User_Does_Not_Exist_Test()
            {
                // Arrange

                const int id = 1;

                RepositoryWrapperMock
                .Setup(x => x.Issue.GetIssueByIdAsync(id))
                .ReturnsAsync(default(Issue));

                // Act

                await Assert.ThrowsAsync <IssueNotFoundException>(() =>
                                                                  ServiceUnderTest.EnforceIssueExistenceAsync(id));

                // Assert

                RepositoryWrapperMock
                .Verify(x => x.Issue.GetIssueByIdAsync(id), Times.Once);
            }
Ejemplo n.º 10
0
            public async Task EnforceUserExistanceAsync_Should_Return_User_If_The_User_Exists_Test()
            {
                // Arrange

                var issueId = Issues[0].Id;

                RepositoryWrapperMock
                .Setup(x => x.Issue.GetIssueByIdAsync(issueId))
                .ReturnsAsync(Issues[0]).Verifiable();

                // Act

                var result = await ServiceUnderTest.EnforceIssueExistenceAsync(issueId);

                // Assert

                result.Should().BeSameAs(Issues[0]);
                RepositoryWrapperMock
                .Verify(x => x.Issue.GetIssueByIdAsync(issueId), Times.Once);
            }
Ejemplo n.º 11
0
            public async Task GetIssueByIdAsync_With_Valid_Id_Should_Return_The_Expected_Issue_Test()
            {
                // Arrange

                const int id            = 1;
                var       expectedIssue = Issues[0];

                RepositoryWrapperMock
                .Setup(x => x.Issue.GetIssueByIdAsync(expectedIssue.Id))
                .ReturnsAsync(Issues[0]);

                // Act

                var result = await ServiceUnderTest.GetIssueByIdAsync(id);

                // Assert

                result.Should().BeOfType <IssueDto>();
                result.Id.Should().Be(expectedIssue.Id);
                result.IssueDescription.Should().Contain(expectedIssue.IssueDescription);
            }
Ejemplo n.º 12
0
            public async Task GetAllIssuesAsync_Should_Return_All_Issues_Test()
            {
                // Arrange
                var issuesToReturn = Issues.AsEnumerable();

                RepositoryWrapperMock
                .Setup(x => x.Issue.GetAllIssuesAsync())
                .ReturnsAsync(issuesToReturn);

                // Act

                var result = await ServiceUnderTest.GetAllIssuesAsync();

                // Assert

                var items = result.ToList();

                items.Count.Should().Be(3);
                items[0].IssueDescription.Should().Contain(IssueDtos[0].IssueDescription);
                items[1].IssueDescription.Should().Contain(IssueDtos[1].IssueDescription);
                items[2].IssueDescription.Should().Contain(IssueDtos[2].IssueDescription);
            }
Ejemplo n.º 13
0
            public async Task UpdateIssueAsync_With_A_NonExisting_Issue_Should_Return_IssueNotUpdatedException_Test()
            {
                // Arrange

                var issueToUpdateDto = new IssueForUpdateDto()
                {
                    Id = 1, IssueDescription = "Test 1 updated"
                };

                RepositoryWrapperMock
                .Setup(x => x.Issue.GetIssueByIdAsync(issueToUpdateDto.Id))
                .ReturnsAsync(default(Issue)).Verifiable();

                // Act

                await Assert.ThrowsAsync <IssueNotFoundException>(() => ServiceUnderTest.UpdateIssueAsync(issueToUpdateDto));

                // Assert

                RepositoryWrapperMock
                .Verify(x => x.Issue.GetIssueByIdAsync(issueToUpdateDto.Id), Times.Once);
            }
Ejemplo n.º 14
0
            public async Task DeleteIssueAsync_Should_Update_and_return_the_specified_Issue_Test()
            {
                // Arrange

                RepositoryWrapperMock
                .Setup(x => x.Issue.GetIssueByIdAsync(IssueToDeleteDto.Id))
                .ReturnsAsync(Issues[0]).Verifiable();

                RepositoryWrapperMock
                .Setup(x => x.SaveAsync())
                .Returns(() => Task.Run(() => { return(1); })).Verifiable();

                // Act

                var result = await ServiceUnderTest.DeleteIssueAsync(IssueToDeleteDto);

                // Assert

                result.Should().BeTrue();
                RepositoryWrapperMock.Verify(x => x.SaveAsync(), Times.Once);
                RepositoryWrapperMock
                .Verify(x => x.Issue.GetIssueByIdAsync(IssueToDeleteDto.Id), Times.Once);
            }