public IncidentAddVm GetIncident(string state) { IncidentAddVm incident = new IncidentAddVm(); incident.AccountId = state == "AccountContact" ? null : (Guid?)Guid.Parse(TestData4.AccountId); incident.ContactId = state == "AccountContact" ? null : (Guid?)Guid.Parse(TestData4.ContactId); if (state == "ParliamentBoss") { incident.RequestType = 1; // رییس مجلس } else if (state == "Agent") { incident.RequestType = 2;// نماینده مجلس } else if (state == "RequestType") { incident.RequestType = null; } else { incident.RequestType = 1; } incident.UserId = state == "User" ? null : (Guid?)Guid.Parse(TestData4.UserId); incident.Description = FakeData.RandomString(10); incident.IncidentTitle = FakeData.RandomString(10); incident.RequestGroupId = state == "RequestGroup" ? null : (Guid?)Guid.Parse(TestData4.RequestGroupId); incident.RequestSubGroupId = state == "RequestSubGroup" ? null : (Guid?)Guid.Parse(TestData4.RequestSubGroupId); return(incident); }
public async void AddIncident() { var httpClient = new HttpClient(); IncidentAddVm incidentAddVm = GetIncident("FullData"); var jsonString = JsonConvert.SerializeObject(incidentAddVm); var httpContent = new StringContent(jsonString, Encoding.UTF8, "application/json"); HttpResponseMessage httpResponseMessage = await httpClient.PostAsync($"{EndPoints.BaseUrl}/{EndPoints.Incidents}", httpContent); Assert.Equal(HttpStatusCode.OK, httpResponseMessage.StatusCode); }
public async void GetIncidentById_ExpectedFound() { var httpClient = new HttpClient(); var json = await httpClient.GetAsync($"{EndPoints.BaseUrl}/{EndPoints.Incidents}/byaccount/{TestData4.AccountId}"); var strJson = await json.Content.ReadAsStringAsync(); IncidentAddVm incidentAddVm = JsonConvert.DeserializeObject <IncidentAddVm>(strJson); Assert.IsType <IncidentAddVm>(incidentAddVm); Assert.NotNull(incidentAddVm); }
public async void AddIncidentNegativeRequestTypeExpectedBadRequest() { var httpClient = new HttpClient(); IncidentAddVm incidentAddVm = GetIncident("FullData"); incidentAddVm.RequestType = -1; await Assert.ThrowsAsync <HttpRequestException>(async() => { var jsonString = JsonConvert.SerializeObject(incidentAddVm); var httpContent = new StringContent(jsonString, Encoding.UTF8, "application/json"); HttpResponseMessage httpResponseMessage = await httpClient.PostAsync($"{EndPoints.BaseUrl}/{EndPoints.Incidents}", httpContent); if (httpResponseMessage.StatusCode == HttpStatusCode.BadRequest) { throw new HttpRequestException(); } }); }
public async void AddIncidentNullAccountContactExpectedBadRequest() { var httpClient = new HttpClient(); IncidentAddVm incidentAddVm = GetIncident("AccountContact"); var accountId = incidentAddVm.AccountId; var contactId = incidentAddVm.ContactId; Assert.Null(accountId); Assert.Null(contactId); await Assert.ThrowsAsync <HttpRequestException>(async() => { var jsonString = JsonConvert.SerializeObject(incidentAddVm); var httpContent = new StringContent(jsonString, Encoding.UTF8, "application/json"); HttpResponseMessage httpResponseMessage = await httpClient.PostAsync($"{EndPoints.BaseUrl}{EndPoints.Incidents}", httpContent); if (httpResponseMessage.StatusCode == HttpStatusCode.BadRequest) { throw new HttpRequestException(); } }); }