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"));
        }
Ejemplo n.º 3
0
        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>();
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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");
        }
Ejemplo n.º 8
0
        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");
        }
Ejemplo n.º 9
0
        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");
        }
Ejemplo n.º 10
0
        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"));
        }
Ejemplo n.º 12
0
        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>()));
        }
Ejemplo n.º 13
0
        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>()));
        }