public async Task ReturnsOkWithExpectedApiHomeResponse() { var linksCreator = A.Fake <ILinksCreator <ApiHomeResponse> >(); A.CallTo(() => _apiHomeResponseLinksCreatorFactory.Create()) .Returns(linksCreator); var links = new[] { new Hyperlink <ApiHomeResponseHyperlinkType>(HttpMethod.Get, "https://dalion.eu/testing/api", ApiHomeResponseHyperlinkType.Self), new Hyperlink <ApiHomeResponseHyperlinkType>(HttpMethod.Get, "https://dalion.eu/testing/api/userinfo", ApiHomeResponseHyperlinkType.GetUserInfo) }; A.CallTo(() => linksCreator.CreateLinksFor(A <ApiHomeResponse> ._)) .Invokes(call => { var response = call.GetArgument <ApiHomeResponse>(0); response.Links = links; }); var actual = await _sut.GetDefault(); actual.Should().BeOfType <OkObjectResult>(); var expected = new ApiHomeResponse { ApplicationInfo = _applicationInfo, Links = links }; actual.As <OkObjectResult>().Value.Should().BeEquivalentTo(expected); }
public async Task <IActionResult> GetDefault() { var response = new ApiHomeResponse { ApplicationInfo = _applicationInfoProvider.Provide() }; await _apiHomeResponseLinksCreatorFactory.Create().CreateLinksFor(response); return(Ok(response)); }
public CreateLinksFor() { _apiHomeResponse = new ApiHomeResponse { ApplicationInfo = new ApplicationInfo { Version = "1.2.3", Company = "Dalion", Product = "WebAppTemplate unit tests", UrlInfo = new ApplicationInfo.ApplicationUrlInfo { SiteUrl = "https://www.dalion.eu/", AppUrl = "WebAppTemplate" } } }; A.CallTo(() => _hyperlinkFactory.Create(A <HttpMethod> ._, A <string> ._, A <ApiHomeResponseHyperlinkType> ._)) .ReturnsLazily(call => { var method = call.GetArgument <HttpMethod>(0); var relativeUrl = call.GetArgument <string>(1); var rel = call.GetArgument <ApiHomeResponseHyperlinkType>(2); return(new Hyperlink <ApiHomeResponseHyperlinkType>(method, $"https://dalion.eu/testing{relativeUrl}", rel)); }); }
public async Task AddsExpectedLinksToModel() { await _sut.CreateLinksFor(_apiHomeResponse); var expected = new ApiHomeResponse { ApplicationInfo = new ApplicationInfo { Version = "1.2.3", Company = "Dalion", Product = "WebAppTemplate unit tests", UrlInfo = new ApplicationInfo.ApplicationUrlInfo { SiteUrl = "https://www.dalion.eu/", AppUrl = "WebAppTemplate" } }, Links = new[] { new Hyperlink <ApiHomeResponseHyperlinkType>(HttpMethod.Get, "https://dalion.eu/testing/api", ApiHomeResponseHyperlinkType.Self), new Hyperlink <ApiHomeResponseHyperlinkType>(HttpMethod.Get, "https://dalion.eu/testing/api/userinfo", ApiHomeResponseHyperlinkType.GetUserInfo) } }; var differences = _apiHomeResponse.CompareTo(expected); differences.AreEqual.Should().BeTrue(because: differences.DifferencesString); }