public void GetOffice_WhenPassedNonExistentOfficeId_ReturnNull() { var mocks = new OfficeMocks(); _api = new OfficeApiService(mocks.MockRepo.Object, mocks.MockMap.Object); var id = 199; mocks.MockRepo.Setup(x => x.FindOffice(It.IsAny <int>())).Returns(() => null); mocks.MockMap.Setup(x => x.Map <OfficeResourceDto, Office>(It.IsAny <OfficeResourceDto>())).Returns(() => null); var getAsyncReturn = _api.GetAsync(id, mocks.MockContext.Object, new CancellationToken()); var returnValue = getAsyncReturn.Result; Assert.IsNull(returnValue); }
public void GetOffice_WhenPassedExistingOfficeId_ReturnOffice() { var mocks = new OfficeMocks(); _api = new OfficeApiService(mocks.MockRepo.Object, mocks.MockMap.Object); var id = 1; var name = "Vancouver"; var officeResDto = new OfficeResourceDto { Id = id, Name = name }; var office = new Office { Id = id, Name = name }; mocks.MockRepo.Setup(x => x.FindOffice(It.IsAny <int>())).Returns(() => officeResDto); mocks.MockMap.Setup(x => x.Map <OfficeResourceDto, Office>(It.IsAny <OfficeResourceDto>())).Returns(() => office); var getAsyncReturn = _api.GetAsync(id, mocks.MockContext.Object, new CancellationToken()); var returnValue = getAsyncReturn.Result; Assert.AreEqual(id, returnValue.Id); Assert.AreEqual(name, returnValue.Name); }