public async Task GetDiffDataShouldReturnInternalServerErrorResultWhenExceptionIsThrownInAnalysis() { // Arrange var repositoryMock = new Mock <IDiffRepositoryManager>(); repositoryMock .Setup(r => r.GetById(It.IsAny <int>())) .ReturnsAsync(new DiffData()); var diffAnalyserMock = new Mock <IDiffAnalyser>(); diffAnalyserMock .Setup(d => d.Analyse(It.IsAny <byte[]>(), It.IsAny <byte[]>())) .Throws <Exception>(); var someValidId = int.MaxValue; var diffController = new DiffController(repositoryMock.Object, diffAnalyserMock.Object, _defaultMapperMock.Object); // Act IHttpActionResult result = await diffController.GetDiffData(someValidId); // Assert Assert.IsInstanceOfType(result, typeof(InternalServerErrorResult)); }
public async Task GetDiffDataShouldReturnDiffResultWhenAnalysisIsSuccessful() { // Arrange var repositoryMock = new Mock <IDiffRepositoryManager>(); repositoryMock .Setup(r => r.GetById(It.IsAny <int>())) .ReturnsAsync(new DiffData()); var diffAnalyserMock = new Mock <IDiffAnalyser>(); diffAnalyserMock .Setup(d => d.Analyse(It.IsAny <byte[]>(), It.IsAny <byte[]>())) .Returns(default(Domain.DiffResult)); var someValidId = int.MaxValue; var diffController = new DiffController(repositoryMock.Object, diffAnalyserMock.Object, _defaultMapperMock.Object); // Act IHttpActionResult result = await diffController.GetDiffData(someValidId); // Assert Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <Models.Diff.DiffResult>)); }
public async Task GetDiffDataShouldReturnBlocksAreNotOfSameSizeWhenProvidedBlocksAreDifferents() { // Arrange var someValidId = int.MaxValue; var leftBlock = new byte[] { 1, 2, 3, 4, 5 }; var leftBlockBase64String = Convert.ToBase64String(leftBlock); var rightBlock = new byte[] { 1, 2, 3, 4 }; var rightBlockBase64String = Convert.ToBase64String(rightBlock); // Act IHttpActionResult insertLeftResponse = await _diffController.PostLeftDiffData(someValidId, leftBlockBase64String); IHttpActionResult insertRightResponse = await _diffController.PostRightDiffData(someValidId, rightBlockBase64String); IHttpActionResult getDataResponse = await _diffController.GetDiffData(someValidId); // Assert Assert.IsInstanceOfType(insertLeftResponse, typeof(OkResult)); Assert.IsInstanceOfType(insertRightResponse, typeof(OkResult)); Assert.IsInstanceOfType(getDataResponse, typeof(OkNegotiatedContentResult <Models.Diff.DiffResult>)); var diffResult = ((OkNegotiatedContentResult <Models.Diff.DiffResult>)getDataResponse).Content; Assert.AreEqual("BlocksAreNotOfSameSize", diffResult.Status); }
public async Task GetDiffDataShouldReturnNotFoundWhenIdDoesNotExists() { // Arrange var repositoryMock = new Mock <IDiffRepositoryManager>(); repositoryMock .Setup(r => r.GetById(It.IsAny <int>())) .ReturnsAsync(default(DiffData)); var someValidId = int.MaxValue; var diffController = new DiffController(repositoryMock.Object, _defaultDiffAnalyserMock.Object, _defaultMapperMock.Object); // Act IHttpActionResult result = await diffController.GetDiffData(someValidId); // Assert Assert.IsInstanceOfType(result, typeof(NotFoundResult)); }