public async void Delete_ReturnsAsyncOk() { var serviceMock = new Mock <IHistoricalCrudService <Guid, TestEntity> >(); var controller = new HistoricalCrudControllerBase <Guid, TestEntity>(null, serviceMock.Object); var actionResult = await controller.Delete(_entity.Id); Assert.IsType <OkObjectResult>(actionResult.Result); serviceMock.Verify(_ => _.DeleteAsync(It.IsAny <Guid>()), Times.Once); }
public async void MarkOneAsUnread_ReturnsOk() { var serviceMock = new Mock <IHistoricalCrudService <Guid, TestEntity> >(); var controller = new HistoricalCrudControllerBase <Guid, TestEntity>(null, serviceMock.Object); var actionResult = await controller.MarkOneAsUnread(_entity.Id); Assert.IsType <NoContentResult>(actionResult); serviceMock.Verify(_ => _.MarkOneAsUnread(It.IsAny <Guid>()), Times.Once); }
public async void Update_ReturnsAsyncModifiedEntity() { var serviceMock = new Mock <IHistoricalCrudService <Guid, TestEntity> >(); var controller = new HistoricalCrudControllerBase <Guid, TestEntity>(null, serviceMock.Object); var actionResult = await controller.Update(_entity.Id, _entity); Assert.IsType <NoContentResult>(actionResult); serviceMock.Verify(_ => _.UpdateAsync(It.IsAny <Guid>(), It.IsAny <TestEntity>()), Times.Once); }
public async void Head_Calls_CrudController_Definition() { var controllerMock = new Mock <ICrudController <Guid, TestEntity> >(); controllerMock.Setup(_ => _.HeadById(It.IsAny <Guid>())).ReturnsAsync(new OkResult()); var controller = new HistoricalCrudControllerBase <Guid, TestEntity>(controllerMock.Object, null); await controller.HeadById(_entity.Id); controllerMock.Verify(_ => _.HeadById(It.IsAny <Guid>()), Times.Once); }
public async void GetAll_Calls_CrudController_Definition() { var controllerMock = new Mock <ICrudController <Guid, TestEntity> >(); controllerMock.Setup(_ => _.GetAll()).ReturnsAsync(new OkObjectResult(_entities)); var controller = new HistoricalCrudControllerBase <Guid, TestEntity>(controllerMock.Object, null); var result = await controller.GetAll(); Assert.IsType <ActionResult <IEnumerable <TestEntity> > >(result); controllerMock.Verify(_ => _.GetAll(), Times.Once); }
public async void GetHistory_ThrowsEntityNotFoundException() { var serviceMock = new Mock <IHistoricalCrudService <Guid, TestEntity> >(); serviceMock.Setup(_ => _.GetHistoryAsync(It.IsAny <Guid>())).ThrowsAsync(new EntityNotFoundException()); var controller = new HistoricalCrudControllerBase <Guid, TestEntity>(null, serviceMock.Object); var result = await controller.GetHistory(_entity.Id); Assert.IsType <NotFoundResult>(result); serviceMock.Verify(_ => _.GetHistoryAsync(It.IsAny <Guid>()), Times.Once); }
public async void GetHistory_ReturnsOk() { var serviceMock = new Mock <IHistoricalCrudService <Guid, TestEntity> >(); serviceMock.Setup(_ => _.GetHistoryAsync(It.IsAny <Guid>())).ReturnsAsync(_events); var controller = new HistoricalCrudControllerBase <Guid, TestEntity>(null, serviceMock.Object); var result = await controller.GetHistory(_entity.Id); Assert.IsType <OkObjectResult>(result); serviceMock.Verify(_ => _.GetHistoryAsync(It.IsAny <Guid>()), Times.Once); }
public async void Delta_ReturnsNotFound() { var serviceMock = new Mock <IHistoricalCrudService <Guid, TestEntity> >(); serviceMock.Setup(_ => _.Delta(It.IsAny <Guid>(), It.IsAny <DeltaRequest>())).ThrowsAsync(new EntityNotFoundException()); var controller = new HistoricalCrudControllerBase <Guid, TestEntity>(null, serviceMock.Object); var actionResult = await controller.Delta(_entity.Id, new DeltaRequest()); Assert.IsType <NotFoundResult>(actionResult); serviceMock.Verify(_ => _.Delta(It.IsAny <Guid>(), It.IsAny <DeltaRequest>()), Times.Once); }
public async void RestoreFromChangeset_ReturnsNoContent() { var serviceMock = new Mock <IHistoricalCrudService <Guid, TestEntity> >(); serviceMock.Setup(_ => _.RestoreFromChangeset(It.IsAny <Guid>(), It.IsAny <Guid>())).ReturnsAsync(_entity); var controller = new HistoricalCrudControllerBase <Guid, TestEntity>(null, serviceMock.Object); var actionResult = await controller.RestoreFromChangeset(_entity.Id, new Guid()); Assert.IsType <NoContentResult>(actionResult.Result); serviceMock.Verify(_ => _.RestoreFromChangeset(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Once); }
public async void RestoreFromChangeset_ReturnsBadRequest_For_UnmanageableException() { var serviceMock = new Mock <IHistoricalCrudService <Guid, TestEntity> >(); serviceMock.Setup(_ => _.RestoreFromChangeset(It.IsAny <Guid>(), It.IsAny <Guid>())).ThrowsAsync(new Exception()); var controller = new HistoricalCrudControllerBase <Guid, TestEntity>(null, serviceMock.Object); var actionResult = await controller.RestoreFromChangeset(_entity.Id, new Guid()); Assert.IsType <BadRequestObjectResult>(actionResult.Result); serviceMock.Verify(_ => _.RestoreFromChangeset(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Once); }
public async void CopyFromChangeset_ReturnsNotFound_For_ChangesetNotFoundException() { var serviceMock = new Mock <IHistoricalCrudService <Guid, TestEntity> >(); serviceMock.Setup(_ => _.CopyFromChangeset(It.IsAny <Guid>(), It.IsAny <Guid>())).ThrowsAsync(new ChangesetNotFoundException()); var controller = new HistoricalCrudControllerBase <Guid, TestEntity>(null, serviceMock.Object); var actionResult = await controller.CopyFromChangeset(_entity.Id, new Guid()); Assert.IsType <NotFoundObjectResult>(actionResult.Result); serviceMock.Verify(_ => _.CopyFromChangeset(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Once); }
public async void Copy_ReturnsOk() { var serviceMock = new Mock <IHistoricalCrudService <Guid, TestEntity> >(); serviceMock.Setup(_ => _.CopyAsync(It.IsAny <Guid>())).ReturnsAsync(_entity); var controller = new HistoricalCrudControllerBase <Guid, TestEntity>(null, serviceMock.Object); var actionResult = await controller.Copy(_entity.Id); Assert.IsType <CreatedAtActionResult>(actionResult.Result); serviceMock.Verify(_ => _.CopyAsync(It.IsAny <Guid>()), Times.Once); }
public async void GetReadStatusByIdAsync_ReturnsAsyncOk() { var serviceMock = new Mock <IHistoricalCrudService <Guid, TestEntity> >(); serviceMock.Setup(_ => _.GetReadStatusByIdAsync(It.IsAny <Guid>())).ReturnsAsync(_status); var controller = new HistoricalCrudControllerBase <Guid, TestEntity>(null, serviceMock.Object); var actionResult = await controller.GetReadStatusById(_entity.Id); Assert.IsType <ActionResult <ReadeableStatus <TestEntity> > >(actionResult); serviceMock.Verify(_ => _.GetReadStatusByIdAsync(It.IsAny <Guid>()), Times.Once); }