public void ANoteIsCreated() { int createdNoteId = 0; UnProcessableEntityException couldNotCreateNoteException = null; try { var userId = _fixture.LandmarkContext.Users.First().Id; var command = new CreateNoteCommand { UserId = userId, Text = "a sample note", Latitude = 50, Longitude = 50 }; createdNoteId = new CreateNoteCommandHandler(_fixture.LandmarkContext, new FakeDatetimeProvider()).Handle(command, CancellationToken.None).GetAwaiter().GetResult(); } catch (UnProcessableEntityException ex) { couldNotCreateNoteException = ex; } couldNotCreateNoteException.ShouldBeNull(); createdNoteId.ShouldBeGreaterThan(0); }
public void ExceptionIsThrownWithCorrectDetaisl() { int createdNoteId = 0; UnProcessableEntityException couldNotCreateNoteException = null; try { var userId = _fixture.LandmarkContext.Users.First().Id; var command = new CreateNoteCommand { UserId = userId, Text = "a sample note", Latitude = 150, Longitude = 50 }; createdNoteId = new CreateNoteCommandHandler(_fixture.LandmarkContext, new FakeDatetimeProvider()).Handle(command, CancellationToken.None).GetAwaiter().GetResult(); } catch (UnProcessableEntityException ex) { couldNotCreateNoteException = ex; } couldNotCreateNoteException.ShouldNotBeNull(); couldNotCreateNoteException.ModelStateErrors.Count().ShouldBe(1); var modelStateError = couldNotCreateNoteException.ModelStateErrors.First(); modelStateError.PropertyName.ShouldBe(nameof(CreateNoteCommand.Latitude)); }
public void Setup() => _handler = new CreateNoteCommandHandler(_mapper, _wolkDbContext);