public async void Post_WhenConflict() { // arrange var testLocation = TestLocationModel(); var errorCodeConverter = new ErrorCodeConverter(); var locationServiceMoq = new Mock <ILocationService>(); locationServiceMoq.Setup(x => x.Insert(It.IsAny <Location>())) .ReturnsAsync(() => new Result <Guid>(ResultCode.Conflict, TestLocation().Id)); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.Post(testLocation); var conflictResult = result as StatusCodeResult; // assert Assert.Equal(409, conflictResult.StatusCode); }
public async void Post_WhenNotValid() { // arrange var errorCodeConverter = new ErrorCodeConverter(); var locationServiceMoq = new Mock <ILocationService>(); locationServiceMoq.Setup(x => x.Insert(It.IsAny <Location>())) .ReturnsAsync(() => new Result <Guid>(ResultCode.BadRequest, TestLocation().Id)); var dataStructureConverterMoq = new Mock <IDataStructureConverter>(); var sut = new LocationsController(locationServiceMoq.Object, errorCodeConverter, dataStructureConverterMoq.Object) { ControllerContext = DefaultControllerContext() }; // act var result = await sut.Post(TestLocationModel()); var badRequestResult = result as BadRequestResult; // assert Assert.NotNull(badRequestResult); }