public async void Get_null_record() { var mock = new ServiceMockFacade <IMachineRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <Machine>(null)); var service = new MachineService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.MachineModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLMachineMapperMock, mock.DALMapperMockFactory.DALMachineMapperMock); ApiMachineResponseModel response = await service.Get(default(string)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <string>())); }
public async void Get_ShouldReturnNullBecauseRecordNotFound() { var mock = new ServiceMockFacade <IMachineService, IMachineRepository>(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Machine>(null)); var service = new MachineService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.MachineModelValidatorMock.Object, mock.DALMapperMockFactory.DALMachineMapperMock, mock.DALMapperMockFactory.DALLinkMapperMock); ApiMachineServerResponseModel response = await service.Get(default(int)); response.Should().BeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
// GET api/<controller> public HttpResponseMessage Get(string id) { try { LoggerUtils.WriteLog("MachinesController : GET BY ID - request received"); var machine = machineService.Get(id); if (machine != null) { return(Request.CreateResponse(HttpStatusCode.OK, machine)); } return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Machine not found for provided id.")); } catch (Exception ex) { LoggerUtils.WriteLog("ERROR : MachinesController : " + ex.Message + "\r" + "InnerException : " + ex.InnerException); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public async void Get() { var mock = new ServiceMockFacade <IMachineRepository>(); var record = new Machine(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record)); var service = new MachineService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.MachineModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLMachineMapperMock, mock.DALMapperMockFactory.DALMachineMapperMock, mock.BOLMapperMockFactory.BOLLinkMapperMock, mock.DALMapperMockFactory.DALLinkMapperMock, mock.BOLMapperMockFactory.BOLMachineRefTeamMapperMock, mock.DALMapperMockFactory.DALMachineRefTeamMapperMock); ApiMachineResponseModel response = await service.Get(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }