public void Should_save_links_for_the_same_url_with_different_ids() { var saveLink = Substitute.For <ISaveLinks>(); var sut = new LinkController(Substitute.For <IRetrieveLinks>(), saveLink); var ids = new[] { sut.Create("http://example.com").CreatedLinkId(), sut.Create("http://example.com").CreatedLinkId() }; ids.Should().OnlyHaveUniqueItems(); }
public void Should_save_a_link_with_specified_url_and_the_returned_id() { var saveLink = Substitute.For <ISaveLinks>(); var sut = new LinkController(Substitute.For <IRetrieveLinks>(), saveLink); var id = sut.Create("http://example.com").CreatedLinkId(); saveLink.Received().WithIdAndUrl(id, new Uri("http://example.com")); }
public void Should_return_an_http_created_result() { var sut = new LinkController( Substitute.For <IRetrieveLinks>(), Substitute.For <ISaveLinks>()); var result = sut.Create("example", "http://example.com"); result.Should().BeOfType <CreatedAtRouteNegotiatedContentResult <string> >(); }
public void Should_return_an_http_bad_request_result_even_with_a_provided_id(string url) { var sut = new LinkController( Substitute.For <IRetrieveLinks>(), Substitute.For <ISaveLinks>()); var result = sut.Create(id: "example", url); result.Should().BeOfType <BadRequestObjectResult>(); }
public void Should_return_an_http_bad_request_result(string url) { var sut = new LinkController( Substitute.For <IRetrieveLinks>(), Substitute.For <ISaveLinks>()); var result = sut.Create(url); result.Should().BeOfType <BadRequestObjectResult>(); }
public void Should_return_an_http_created_result() { var sut = new LinkController( Substitute.For <IRetrieveLinks>(), Substitute.For <ISaveLinks>()); var result = sut.Create("http://example.com"); result.StatusCode().Should().Be(201); }
public void Should_return_the_id_of_the_created_link() { var sut = new LinkController( Substitute.For <IRetrieveLinks>(), Substitute.For <ISaveLinks>()); var result = sut.Create("example", "http://example.com"); result.Should().BeOfType <CreatedAtRouteNegotiatedContentResult <string> >() .Which.RouteValues.Should().ContainKey("id").And.ContainValue("example"); }
public void Should_return_the_route_name_for_the_created_link() { var sut = new LinkController( Substitute.For <IRetrieveLinks>(), Substitute.For <ISaveLinks>()); var result = sut.Create("example", "http://example.com"); result.Should().BeOfType <CreatedAtRouteNegotiatedContentResult <string> >() .Which.RouteName.Should().Be("Follow"); }
public void Should_return_the_url_of_the_created_link() { var sut = new LinkController( Substitute.For <IRetrieveLinks>(), Substitute.For <ISaveLinks>()); var result = sut.Create("http://example.com"); result.Should().BeOfType <CreatedAtRouteResult>() .Which.Value.Should().Be("http://example.com"); }
public void Should_return_the_generated_id_of_the_created_link() { var sut = new LinkController( Substitute.For <IRetrieveLinks>(), Substitute.For <ISaveLinks>()); var result = sut.Create("http://example.com"); result.Should().BeOfType <CreatedAtRouteResult>() .Which.RouteValues.Should().ContainKey("id").And.NotBeNull(); }
public void Should_save_a_link_with_the_specified_id_and_url() { var saveLink = Substitute.For <ISaveLinks>(); var sut = new LinkController( Substitute.For <IRetrieveLinks>(), saveLink); var result = sut.Create("id", "http://example.com"); saveLink.Received().WithIdAndUrl("id", new Uri("http://example.com")); }
public async void Create_Errors() { LinkControllerMockFacade mock = new LinkControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiLinkResponseModel> >(new FluentValidation.Results.ValidationResult()); var mockRecord = new ApiLinkResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiLinkRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiLinkResponseModel> >(mockResponse.Object)); LinkController controller = new LinkController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Create(new ApiLinkRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiLinkRequestModel>())); }
public async void Create_No_Errors() { LinkControllerMockFacade mock = new LinkControllerMockFacade(); var mockResponse = new CreateResponse <ApiLinkResponseModel>(new FluentValidation.Results.ValidationResult()); mockResponse.SetRecord(new ApiLinkResponseModel()); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiLinkRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiLinkResponseModel> >(mockResponse)); LinkController controller = new LinkController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Create(new ApiLinkRequestModel()); response.Should().BeOfType <CreatedResult>(); (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created); var createResponse = (response as CreatedResult).Value as CreateResponse <ApiLinkResponseModel>; createResponse.Record.Should().NotBeNull(); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiLinkRequestModel>())); }