コード例 #1
0
        public void AddShouldAddNewLinkToDbAndReturnShortUrl()
        {
            // Arrange
            var linkService = A.Fake <IDataLinkService>();

            A.CallTo(() => linkService.Add(A <Link> .Ignored))
            .ReturnsLazily((Link link) => link);

            var linkBuilder = A.Fake <IShortLinkBuilder>();

            A.CallTo(() => linkBuilder.Build(A <ActionContext> .Ignored, A <long> .Ignored))
            .ReturnsLazily((ActionContext context, long id) => $"coded short url");

            var controller = new LinkController(linkService, linkBuilder, CreateTokenServiceMock());

            // Act
            var result = controller.Add("some url").Value as AddViewModel;

            // Assert
            Assert.That(result.ShortUrl, Is.EqualTo("coded short url"));
        }