public void BuildBadUrl() { var controller = new Mock <IJwtTokenSource>(MockBehavior.Strict).Object; var serializer = new Mock <IContentSerializer>(MockBehavior.Strict).Object; var builder = new HttpRequestBuilder(controller, serializer); Assert.ThrowsAsync <ArgumentException>( async() => await builder.BuildAsync(HttpMethod.Get, "") ); }
public void BuildWithContentNullItem() { var controller = new Mock <IJwtTokenSource>(MockBehavior.Strict).Object; var serializer = new Mock <IContentSerializer>(MockBehavior.Strict).Object; var builder = new HttpRequestBuilder(controller, serializer); Assert.ThrowsAsync <ArgumentNullException>( async() => await builder.BuildAsync <Uom>(HttpMethod.Get, "http://localhost", null) ); }
public async Task BuildValid() { var controller = new Mock <IJwtTokenSource>(MockBehavior.Strict); var serializer = new Mock <IContentSerializer>(MockBehavior.Strict).Object; controller .Setup(c => c.GetTokenAsync()) .Returns(Task.FromResult("TheToken")); var builder = new HttpRequestBuilder(controller.Object, serializer); var message = await builder.BuildAsync(HttpMethod.Get, "http://localhost"); Assert.NotNull(message); Assert.AreEqual(HttpMethod.Get, message.Method); Assert.AreEqual("http://localhost/", message.RequestUri.ToString()); Assert.AreEqual("Bearer TheToken", message.Headers.Single(h => h.Key == "Authorization").Value?.FirstOrDefault()); }
public async Task BuildWithContentValid() { var expectedItem = new Uom(0, "TheUom", "TheDescription"); var controller = new Mock <IJwtTokenSource>(MockBehavior.Strict); var serializer = new Mock <IContentSerializer>(MockBehavior.Strict); controller .Setup(c => c.GetTokenAsync()) .Returns(Task.FromResult("TheToken")); serializer .Setup(s => s.Serialize(It.IsAny <HttpRequestMessage>(), expectedItem)); var builder = new HttpRequestBuilder(controller.Object, serializer.Object); var message = await builder.BuildAsync(HttpMethod.Post, "http://localhost", expectedItem); Assert.NotNull(message); Assert.AreEqual(HttpMethod.Post, message.Method); Assert.AreEqual("http://localhost/", message.RequestUri.ToString()); Assert.AreEqual("Bearer TheToken", message.Headers.Single(h => h.Key == "Authorization").Value?.FirstOrDefault()); }