public async Task DtoReturned_PutRightFile_Created() { // Arrange const int id = 1; var mockDiffService = new Mock <IDiffService>(); var mockRetrieveService = new Mock <IRetrieveService>(); var mockUploadService = new Mock <IUploadService>(); var leftFile = Convert.FromBase64String(TestConstants.File1Base64Content); var rightFile = Convert.FromBase64String(TestConstants.File1Base64Content); mockUploadService.Setup(u => u.UploadLeftAsync(id, leftFile)) .Returns(Task.FromResult(new FileComparisonDTO() { Id = id, Left = leftFile, Right = rightFile })); var controller = new FileDiffController(mockDiffService.Object, mockRetrieveService.Object, mockUploadService.Object); // Act var result = await controller.PutRightFileAsync(id, new FileContentDTO() { Data = TestConstants.File1Base64Content }); // Assert Assert.IsNotNull(result, "The action result should not be null!"); Assert.IsInstanceOfType(result, typeof(CreatedFileActionResult), "The action result should be 201-Created!"); }
public async Task FilesSame_GetDiff_Diff() { // Arrange const int id = 1; var mockDiffService = new Mock <IDiffService>(); var mockRetrieveService = new Mock <IRetrieveService>(); var mockUploadService = new Mock <IUploadService>(); mockDiffService.Setup(d => d.GetDiffAsync(id)) .Returns(Task.FromResult(new DiffResultDTO() { DiffResultType = ComparisonResult.Equals.ToString() })); mockRetrieveService.Setup(r => r.LeftFileExistsAsync(id)) .Returns(Task.FromResult(true)); mockRetrieveService.Setup(r => r.RightFileExistsAsync(id)) .Returns(Task.FromResult(true)); var controller = new FileDiffController(mockDiffService.Object, mockRetrieveService.Object, mockUploadService.Object); // Act var actionResult = await controller.GetDiffAsync(id); var contentResult = actionResult as OkNegotiatedContentResult <DiffResultDTO>; // Assert Assert.IsNotNull(contentResult, "The action result should not be null!"); Assert.IsNotNull(contentResult.Content, "The content of the action result should not be null!"); Assert.AreEqual(ComparisonResult.Equals.ToString(), contentResult.Content.DiffResultType, "The diff result should be Equals!"); Assert.IsNull(contentResult.Content.Diffs, "The list of diffs should not exist in the results!"); }
public async Task FilesSameSizeDifferentContent_GetDiff_Diff() { // Arrange const int id = 1; var mockDiffService = new Mock <IDiffService>(); var mockRetrieveService = new Mock <IRetrieveService>(); var mockUploadService = new Mock <IUploadService>(); var diffs = new List <DifferenceDTO>() { new DifferenceDTO() { Offset = 0, Length = 1 }, new DifferenceDTO() { Offset = 2, Length = 2 } }; mockDiffService.Setup(d => d.GetDiffAsync(id)) .Returns(Task.FromResult(new DiffResultDTO() { DiffResultType = ComparisonResult.ContentDoNotMatch.ToString(), Diffs = diffs })); mockRetrieveService.Setup(r => r.LeftFileExistsAsync(id)) .Returns(Task.FromResult(true)); mockRetrieveService.Setup(r => r.RightFileExistsAsync(id)) .Returns(Task.FromResult(true)); var controller = new FileDiffController(mockDiffService.Object, mockRetrieveService.Object, mockUploadService.Object); // Act var actionResult = await controller.GetDiffAsync(id); var contentResult = actionResult as OkNegotiatedContentResult <DiffResultDTO>; // Assert Assert.IsNotNull(contentResult, "The action result should not be null!"); Assert.IsNotNull(contentResult.Content, "The content of the action result should not be null!"); Assert.AreEqual( ComparisonResult.ContentDoNotMatch.ToString(), contentResult.Content.DiffResultType, "The diff result should be ContentDoNotMatch!"); Assert.IsNotNull(contentResult.Content.Diffs, "The list of diffs should exist in the results!"); CollectionAssert.AreEqual( diffs, contentResult.Content.Diffs, new DifferenceDTOComparer(), "The list of diffs is not matching with the expected result!"); }
public async Task EmptyFile_PutRightFile_BadRequest() { // Arrange const int id = 1; var mockDiffService = new Mock <IDiffService>(); var mockRetrieveService = new Mock <IRetrieveService>(); var mockUploadService = new Mock <IUploadService>(); var rightFile = new FileContentDTO() { Data = string.Empty }; var controller = new FileDiffController(mockDiffService.Object, mockRetrieveService.Object, mockUploadService.Object); // Act var result = await controller.PutRightFileAsync(id, rightFile); // Assert Assert.IsNotNull(result, "The action result should not be null!"); Assert.IsInstanceOfType(result, typeof(BadRequestResult), "The action result should be 400-BadRequest!"); }
public async Task RightFileNull_GetDiff_NotFound() { // Arrange const int id = 1; var mockDiffService = new Mock <IDiffService>(); var mockRetrieveService = new Mock <IRetrieveService>(); var mockUploadService = new Mock <IUploadService>(); mockRetrieveService.Setup(r => r.LeftFileExistsAsync(id)) .Returns(Task.FromResult(true)); mockRetrieveService.Setup(r => r.RightFileExistsAsync(id)) .Returns(Task.FromResult(false)); var controller = new FileDiffController(mockDiffService.Object, mockRetrieveService.Object, mockUploadService.Object); // Act var result = await controller.GetDiffAsync(id); // Assert Assert.IsNotNull(result, "The action result should not be null!"); Assert.IsInstanceOfType(result, typeof(NotFoundResult), "The action result should be 404-NotFound!"); }