public async Task CreateCompanyTagAsync_TwoCompanyTagsWithSameName_ShouldStoreBothCompanyTags() { // Arrange await this.fixture.ClearFactroInstanceAsync(); var companyApi = this.fixture.GetService <ICompanyApi>(); var name = $"{BaseTestFixture.TestPrefix}{Guid.NewGuid().ToString()}"; var createCompanyTagRequest = new CreateCompanyTagRequest(name); var firstCreatedCompanyTag = await companyApi.CreateCompanyTagAsync(createCompanyTagRequest); var secondCreatedCompanyTag = default(CreateCompanyTagResponse); // Act Func <Task> act = async() => secondCreatedCompanyTag = await companyApi.CreateCompanyTagAsync(createCompanyTagRequest); // Assert await act.Should().NotThrowAsync(); using (new AssertionScope()) { secondCreatedCompanyTag.Should().NotBeNull(); var companyTags = await this.fixture.GetCompanyTagsAsync(companyApi); companyTags.Should() .Contain(x => x.Id == firstCreatedCompanyTag.Id).And .Contain(x => x.Id == secondCreatedCompanyTag.Id); } await this.fixture.ClearFactroInstanceAsync(); }
public async Task CreateCompanyTagAsync_ValidCompanyTag_ShouldCreateCompanyTag() { // Arrange await this.fixture.ClearFactroInstanceAsync(); var companyApi = this.fixture.GetService <ICompanyApi>(); var name = $"{BaseTestFixture.TestPrefix}{Guid.NewGuid().ToString()}"; var createCompanyTagRequest = new CreateCompanyTagRequest(name); var createCompanyTagResponse = default(CreateCompanyTagResponse); // Act Func <Task> act = async() => createCompanyTagResponse = await companyApi.CreateCompanyTagAsync(createCompanyTagRequest); // Assert await act.Should().NotThrowAsync(); var companyTags = await this.fixture.GetCompanyTagsAsync(companyApi); companyTags.Should().ContainEquivalentOf(createCompanyTagResponse); await this.fixture.ClearFactroInstanceAsync(); }
public async Task CreateCompanyTagAsync_ValidRequest_ShouldReturnExpectedCompany() { // Arrange var createCompanyTagRequest = new CreateCompanyTagRequest(Guid.NewGuid().ToString()); var expectedCompany = new CreateCompanyTagResponse { Name = createCompanyTagRequest.Name, }; var expectedResponseContent = new StringContent(JsonConvert.SerializeObject(expectedCompany, this.fixture.JsonSerializerSettings)); var expectedResponse = new HttpResponseMessage { Content = expectedResponseContent, }; var companyApi = this.fixture.GetCompanyApi(expectedResponse); var createCompanyTagResponse = default(CreateCompanyTagResponse); // Act Func <Task> act = async() => createCompanyTagResponse = await companyApi.CreateCompanyTagAsync(createCompanyTagRequest); // Assert await act.Should().NotThrowAsync(); createCompanyTagResponse.Should().BeEquivalentTo(expectedCompany); }
public async Task <CreateCompanyTagResponse> CreateTestCompanyTagAsync(ICompanyApi companyApi) { var name = $"{TestPrefix}{Guid.NewGuid().ToString()}"; var createCompanyTagRequest = new CreateCompanyTagRequest(name); var createCompanyTagResponse = await companyApi.CreateCompanyTagAsync(createCompanyTagRequest); return(createCompanyTagResponse); }
public async Task CreateCompanyTagAsync_NullRequestModelName_ShouldThrowArgumentNullException() { // Arrange var createCompanyTagRequest = new CreateCompanyTagRequest(name: null); var companyApi = this.fixture.GetCompanyApi(); // Act Func <Task> act = async() => await companyApi.CreateCompanyTagAsync(createCompanyTagRequest); // Assert await act.Should().ThrowAsync <ArgumentNullException>(); }
public async Task CreateCompanyTagAsync_UnsuccessfulRequest_ShouldThrowCompanyApiException() { // Arrange var createCompanyTagRequest = new CreateCompanyTagRequest(Guid.NewGuid().ToString()); var response = new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, RequestMessage = new HttpRequestMessage { RequestUri = new Uri("http://www.mock-web-address.com"), }, }; var companyApi = this.fixture.GetCompanyApi(response); // Act Func <Task> act = async() => await companyApi.CreateCompanyTagAsync(createCompanyTagRequest); // Assert await act.Should().ThrowAsync <FactroApiException>(); }
public async Task <CreateCompanyTagResponse> CreateCompanyTagAsync(CreateCompanyTagRequest createCompanyTagRequest) { if (createCompanyTagRequest == null) { throw new ArgumentNullException(nameof(createCompanyTagRequest), $"{nameof(createCompanyTagRequest)} can not be null."); } if (createCompanyTagRequest.Name == null) { throw new ArgumentNullException(nameof(createCompanyTagRequest), $"{nameof(createCompanyTagRequest.Name)} can not be null."); } var requestRoute = CompanyApiEndpoints.Tag.Create(); var requestString = JsonConvert.SerializeObject(createCompanyTagRequest, this.jsonSerializerSettings); var requestContent = ApiHelpers.GetStringContent(requestString); var response = await this.httpClient.PostAsync(requestRoute, requestContent); if (!response.IsSuccessStatusCode) { throw new FactroApiException( "Could not create company tag.", response.RequestMessage.RequestUri.ToString(), response.StatusCode, response.Content == null ? null : await response.Content.ReadAsStringAsync()); } var responseContentString = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject <CreateCompanyTagResponse>( responseContentString, this.jsonSerializerSettings); return(result); }