public async Task SaveLinks_Converts_VanityUrl_To_LowerCase(string vanityUrl) { // Arrange ILogger fakeLogger = A.Fake <ILogger>(); LinkBundle bundle = Fixture.Create <LinkBundle>(); bundle.VanityUrl = vanityUrl; HttpRequest req = this.AuthenticatedRequest; req.Body = this.GetHttpRequestBodyStream(JsonConvert.SerializeObject(bundle)); IAsyncCollector <LinkBundle> collector = A.Fake <IAsyncCollector <LinkBundle> >(); // Act IActionResult result = await LinkOperations.SaveLinks(req, collector, fakeLogger); // Assert Assert.IsType <CreatedResult>(result); CreatedResult createdResult = result as CreatedResult; LinkBundle createdBundle = createdResult.Value as LinkBundle; Assert.Equal(vanityUrl.ToLower(), createdBundle.VanityUrl); A.CallTo(() => collector.AddAsync(A <LinkBundle> .That.Matches(b => b.VanityUrl == vanityUrl.ToLower()), default)).MustHaveHappened(); }
public async Task SaveLinks_Valid_Payload_Returns_CreatRequest() { // Arrange ILogger fakeLogger = A.Fake <ILogger>(); LinkBundle bundle = Fixture.Create <LinkBundle>(); HttpRequest req = this.AuthenticatedRequest; req.Body = this.GetHttpRequestBodyStream(JsonConvert.SerializeObject(bundle)); IAsyncCollector <LinkBundle> collector = A.Fake <IAsyncCollector <LinkBundle> >(); // Act IActionResult result = await LinkOperations.SaveLinks(req, collector, fakeLogger); // Assert Assert.IsType <CreatedResult>(result); CreatedResult createdResult = result as CreatedResult; LinkBundle createdBundle = createdResult.Value as LinkBundle; Assert.Equal("userid", createdBundle.UserId); A.CallTo(() => collector.AddAsync(A <LinkBundle> .That.Matches(b => b.UserId == "userid"), default)).MustHaveHappened(); }
public async Task SaveLinks_Empty_Payload_Returns_BadRequest() { // Arrange ILogger fakeLogger = A.Fake <ILogger>(); HttpRequest req = this.DefaultRequest; req.Body = this.GetHttpRequestBodyStream(""); IAsyncCollector <LinkBundle> collector = A.Fake <IAsyncCollector <LinkBundle> >(); // Act IActionResult result = await LinkOperations.SaveLinks(req, collector, fakeLogger); // Assert Assert.IsType <BadRequestObjectResult>(result); A.CallTo(() => collector.AddAsync(A <LinkBundle> .Ignored, CancellationToken.None)).MustNotHaveHappened(); }
public async Task SaveLinks_Returns_BadRequest_If_Vanity_Url_Fails_Regex(string vanityUrl) { // Arrange ILogger fakeLogger = A.Fake <ILogger>(); HttpRequest req = this.DefaultRequest; LinkBundle payload = this.Fixture.Create <LinkBundle>(); payload.VanityUrl = vanityUrl; req.Body = this.GetHttpRequestBodyStream(JsonConvert.SerializeObject(payload)); IAsyncCollector <LinkBundle> collector = A.Fake <IAsyncCollector <LinkBundle> >(); // Act IActionResult result = await LinkOperations.SaveLinks(req, collector, fakeLogger); // Assert Assert.IsType <BadRequestResult>(result); A.CallTo(() => collector.AddAsync(A <LinkBundle> .Ignored, CancellationToken.None)).MustNotHaveHappened(); }