public async Task ShouldGetMessageResult() { Guid sessionId = Guid.NewGuid(); ISessionRepository repository = Substitute.For <ISessionRepository>(); MessageBuilder leftMessageBuilder = new MessageBuilder().WithData(ApplicationConstants.DefaultData); MessageBuilder rightMessageBuilder = new MessageBuilder().WithData(ApplicationConstants.SameSizeDifferentData); repository.Get(sessionId.ToString()) .Returns(new SessionBuilder(sessionId.ToString()) .WithLeftSideMessage(leftMessageBuilder) .WithRightSideMessage(rightMessageBuilder) .Build()); DiffController controller = new DiffController(repository); ActionResult result = await controller.Get(sessionId); result.ShouldBeAssignableTo <OkObjectResult>(); ((OkObjectResult)result).Value.ToString().ShouldContain("Differences found starting at 3 ending at 5"); ((OkObjectResult)result).Value.ToString().ShouldContain("Differences found starting at 66 ending at 68"); }
public void GetWhenBase64DataAreEqualReturnsMessage() { // Arrange testSetUp(); // Act var diffRepository = DiffRepository.GetInstance(); diffRepository.SaveLeft("1", "TestSame"); diffRepository.SaveRight("1", "TestSame"); var result = controller.Get("1"); // Assert Assert.IsNotNull(result); Assert.AreEqual(result.StatusCode, HttpStatusCode.OK); }
public void Diff_ValidInputDifferentJson_ReturnOkButNotEqual() { //Arrange var obj1 = new { prop1 = "val1", prop2 = "val2", prop3 = new { nested1 = "n1", nested2 = new { nested3 = "n3" } } }; var json1 = JsonConvert.SerializeObject(obj1); var obj2 = new { prop1 = "val2", prop2 = "val2", prop3 = new { nested1 = "n2", nested2 = new { nested3 = "n3" } } }; var json2 = JsonConvert.SerializeObject(obj2); _sessionPersistenceServiceMock.Setup(x => x.Get("LeftData")).Returns(json1); _sessionPersistenceServiceMock.Setup(x => x.Get("RightData")).Returns(json2); //Act var response = _diffController.Get() as ObjectResult; var responseValue = response.Value as DiffResult; //Assert Assert.Equal((int)HttpStatusCode.OK, response.StatusCode); Assert.False(responseValue.AreEqual); }
public async Task ReturnsCorrectResult(int id, DiffResponse response, Type expectedType) { // arrange _diffServiceMock.Setup(x => x.GetDiffAsync(id)).Returns(Task.FromResult(response)); // act var result = await _target.Get(id); // assert Assert.Equal(expectedType.FullName, result.GetType().FullName); }
public async Task GetReturnsNoContentResultWhenReadinessNotReady() { var service = Substitute.For <IDifferenceService>(); service.FindDiffAsync(10).Returns( Task.FromResult(((DifferenceContent)null, DifferenceReadiness.NotReady))); var controller = new DiffController(service); var result = await controller.Get(10); result.Should().BeOfType <NoContentResult>(); }
public void Get_non_existent_id_must_return_notfound() { //Arrange var expectedResult = new List <string> { "Offset: 2, length: 2" }; var service = A.Fake <IDifferentiationService>(); A.CallTo(() => service.Get(1)).Returns(null); var controller = new DiffController(service); //Act var result = controller.Get(1); //Assert Assert.IsType <NotFoundResult>(result); }
public void Get_existent_id_must_return_differentiation() { //Arrange var expectedResult = new List <string> { "Offset: 2, length: 2" }; var service = A.Fake <IDifferentiationService>(); A.CallTo(() => service.Get(1)).Returns(new Differentiation(1, "dGVjZSAy", "dGVzdCAy")); var controller = new DiffController(service); //Act var result = controller.Get(1); //Assert Assert.Equal(expectedResult, ((ObjectResult)result).Value); }
public void GetEmpty() { try { var response = controller.Get(1); Assert.Fail("Get should fail with empty data"); } catch (HttpResponseException ex) { Assert.AreEqual(ex.Response.StatusCode, HttpStatusCode.NotFound); } }
public async Task GetReturnsOkObjectResultWithDifferenceContentWhenReadinessReady() { var content = new DifferenceContent { Type = DifferenceType.SizeDiffers }; var service = Substitute.For <IDifferenceService>(); service.FindDiffAsync(10).Returns( Task.FromResult((content, DifferenceReadiness.Ready))); var controller = new DiffController(service); var result = await controller.Get(10); result.Should() .BeOfType <OkObjectResult>() .Which.Value.Should().Be(content); }
public async Task ShouldGetSameContentMessageResult() { Guid sessionId = Guid.NewGuid(); ISessionRepository repository = Substitute.For <ISessionRepository>(); MessageBuilder messageBuilder = new MessageBuilder().WithData(ApplicationConstants.DefaultData); repository.Get(sessionId.ToString()) .Returns(new SessionBuilder(sessionId.ToString()) .WithLeftSideMessage(messageBuilder) .WithRightSideMessage(messageBuilder) .Build()); DiffController controller = new DiffController(repository); ActionResult result = await controller.Get(sessionId); result.ShouldBeAssignableTo <OkObjectResult>(); ((OkObjectResult)result).Value.ShouldBe("Content is the same"); }