Browse Source

Added unit test for AddPhone.

pull/96/head
Halil İbrahim Kalkan 9 years ago
parent
commit
36f52a616f
  1. 9
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConvention.cs
  2. 36
      test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs
  3. 1
      test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPersonAppService.cs

9
src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConvention.cs

@ -249,14 +249,7 @@ namespace Volo.Abp.AspNetCore.Mvc
private static AttributeRouteModel CreateAbpServiceAttributeRouteModel(string moduleName, string controllerName, ActionModel action, string verb)
{
//TODO: Implement via interfaces!
var url = $"api/services/{moduleName}/{controllerName}";
if (!verb.IsIn("POST"))
{
url += $"/{action.ActionName}";
}
var url = $"api/services/{moduleName}/{controllerName}/{action.ActionName}";
return new AttributeRouteModel(new RouteAttribute(url));
}

36
test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/PersonAppService_Tests.cs

@ -69,11 +69,10 @@ namespace Volo.Abp.AspNetCore.Mvc
//Ideally should be [POST] /api/app/person
var response = await Client.PostAsync(
"/api/services/app/person",
"/api/services/app/person/Create",
new StringContent(postData, Encoding.UTF8, "application/json")
);
response.IsSuccessStatusCode.ShouldBeTrue();
response.StatusCode.ShouldBe(HttpStatusCode.OK);
var resultAsString = await response.Content.ReadAsStringAsync();
PersonDto resultDto = _jsonSerializer.Deserialize<PersonDto>(resultAsString);
@ -107,7 +106,6 @@ namespace Volo.Abp.AspNetCore.Mvc
new StringContent(putData, Encoding.UTF8, "application/json")
);
response.IsSuccessStatusCode.ShouldBeTrue();
response.StatusCode.ShouldBe(HttpStatusCode.OK);
var resultAsString = await response.Content.ReadAsStringAsync();
PersonDto resultDto = _jsonSerializer.Deserialize<PersonDto>(resultAsString);
@ -123,5 +121,37 @@ namespace Volo.Abp.AspNetCore.Mvc
personInDb.Name.ShouldBe(firstPerson.Name);
personInDb.Age.ShouldBe(firstPersonAge + 1);
}
[Fact]
public async Task AddPhone_Test()
{
//Arrange
var personToAddNewPhone = _personRepository.GetList().First();
var phoneNumberToAdd = RandomHelper.GetRandom(1000000, 9000000).ToString();
//Act
var postData = _jsonSerializer.Serialize(new PhoneDto { Type = PhoneType.Mobile, Number = phoneNumberToAdd });
//Ideally should be [POST] /api/people/{id}/phones
var response = await Client.PostAsync(
"/api/services/app/person/AddPhone?id=" + personToAddNewPhone.Id,
new StringContent(postData, Encoding.UTF8, "application/json")
);
response.StatusCode.ShouldBe(HttpStatusCode.OK);
var resultAsString = await response.Content.ReadAsStringAsync();
var resultDto = _jsonSerializer.Deserialize<PhoneDto>(resultAsString);
//Assert
resultDto.Type.ShouldBe(PhoneType.Mobile);
resultDto.Number.ShouldBe(phoneNumberToAdd);
var personInDb = await _personRepository.FindAsync(personToAddNewPhone.Id);
personInDb.ShouldNotBeNull();
personInDb.Phones.Any(p => p.Number == phoneNumberToAdd).ShouldBeTrue();
}
}
}

1
test/Volo.Abp.TestApp/Volo/Abp/TestApp/Application/IPersonAppService.cs

@ -10,7 +10,6 @@ namespace Volo.Abp.TestApp.Application
//URL: [GET] /api/people/{id}?type=office
Task<ListResultDto<PhoneDto>> GetPhones(Guid id, GetPersonPhonesFilter filter);
//URL: [POST] /api/people/{id}/phones
Task<PhoneDto> AddPhone(Guid id, PhoneDto phoneDto);
//URL: [DELETE] /api/people/{id}/phones/{phoneId}

Loading…
Cancel
Save