public async Task Create_WithValidInfo_ShouldReturnNewContact() { var contactRequest = new ContactRequestBuilder().Build(); var contactResponse = new ContactResponseBuilder().Build(); _mockLoggingService.Setup(l => l.LogInformation("Requesting create contact...", contactRequest)); _mockContactService.Setup(service => service.Create(contactRequest)).ReturnsAsync(contactResponse); _mockLoggingService.Setup(l => l.LogInformation("Contact with '{ID}' successfully created.", contactResponse.Id)); var actionResult = await _controller.Post(contactRequest); actionResult.Should().BeOfType <OkObjectResult>(); }
public async Task Create_WithInvalidInfo_ShouldReturnBadRequest() { var contactRequest = new ContactRequestBuilder().WithTelephone("invalid phone").WithEmail("invalid email").Build(); var server = new TestServer(new WebHostBuilder().UseStartup <Startup>()); var client = server.CreateClient(); var content = new StringContent(JsonConvert.SerializeObject(contactRequest), Encoding.UTF8, "application/json"); var result = await client.PostAsync("/api/Contact", content); result.StatusCode.Should().Be(HttpStatusCode.BadRequest); var respone = await result.Content.ReadAsStringAsync(); respone.Should().Contain("Email is not valid. Please enter a correct email format. E.g. [email protected]"); respone.Should().Contain("Phone number is not in correct format. The pattern is: +<InternationalDialingCode>.<TelephoneNumber>"); }