public void UpdateNotConfirmedUser() { var mocker = new RouteServiceMocker(); RouteInfoEntity entity = new RouteInfoEntity(); mocker.RepoMock.Setup(r => r.Update(It.IsAny <RouteInfoEntity>())).Callback(() => Console.WriteLine("Unit test update")); mocker.RepoMock.Setup(r => r.GetSingle(It.IsAny <int>())).Returns(() => new RouteInfoEntity() { ID = 1, Name = "test", UserId = 2 }); mocker.RepoMock.Setup(r => r.Commit()).Throws(new Exception("testexception")); mocker.UserResolverMock.Setup(r => r.GetUser()) .Returns(() => Task.FromResult <UserModel>(new UserModel() { Email = "*****@*****.**", Id = 2, Name = "testowy" })); mocker.UserResolverMock.Setup(r => r.IsConfirmed()).Returns(() => Task.FromResult <bool>(false)); IRouteBLService service = mocker.GetService(); var result = service.Update(0, new RouteUpdateModel()); Assert.Equal(ErrorStatus.Forbidden, result.Result.Error.Status); Assert.Equal("User is not confirmed", result.Result.Error.Message); }
public async Task <IActionResult> Update([FromQuery] int id, [FromBody] RouteUpdateModel model) { if (!ModelState.IsValid) { return(WrapResponse(new Result <RouteUpdateModel>(WrapModelStateErrors(ModelState)))); } var result = await _routeService.Update(id, model); return(WrapResponse(result, HttpStatusCode.NoContent)); }
public void UpdateWrongId() { var mocker = new RouteServiceMocker(); RouteInfoEntity entity = new RouteInfoEntity(); mocker.RepoMock.Setup(r => r.Update(It.IsAny <RouteInfoEntity>())).Callback(() => Console.WriteLine("Unit test delete")); mocker.RepoMock.Setup(r => r.GetSingle(It.IsAny <int>())).Returns(() => null); IRouteBLService service = mocker.GetService(); var result = service.Update(0, new RouteUpdateModel()); Assert.Equal("Id", result.Result.Error.Errors.First().Field); Assert.Equal(ErrorStatus.ObjectNotFound, result.Result.Error.Status); }