Hi there,
I'm new to JustMock and I'm looking into writing unit tests. Below i have copied the code i'm trying to test and will also copy what i have so far for unit testing. Looking at the test covarage within Visual Studio i aren't testing the catch exceptions and i don't know how to do this. Most my tests are structured this way and any help to get me moving again will be appreciated.
Thanks again,
Tommy
I'm new to JustMock and I'm looking into writing unit tests. Below i have copied the code i'm trying to test and will also copy what i have so far for unit testing. Looking at the test covarage within Visual Studio i aren't testing the catch exceptions and i don't know how to do this. Most my tests are structured this way and any help to get me moving again will be appreciated.
[HttpGet] [Route("api/DealBuilder/GetSession")] public IHttpActionResult NewVersion(string sessionId) { try { if (!String.IsNullOrEmpty(sessionId)) { try { return Ok(dealbuilderRepository.GetTemplateAndXml(new Guid(sessionId))); } catch (Exception ex) { return InternalServerError(ex); } } else { return BadRequest("No Session ID was passed."); } } catch (Exception ex) { // TODO: logger.Error(ex.Message, ex); return InternalServerError(ex); } }
This is what i have so far for tests on my code above.
[TestMethod] public void NewVersion() { var repo = Mock.Create<IDealBuilderRepository>(); var controller = new DealBuilderController(repo); Mock.Arrange(() => repo.Equals(Arg.IsAny<String>())); var result = controller.NewVersion(Arg.IsAny<String>()); Mock.Assert(repo); } [TestMethod] public void GetNewVersionFail() { var repo = Mock.Create<IDealBuilderRepository>(); var controller = new DealBuilderController(repo); Mock.Arrange(() => repo.Equals(Arg.IsAny<Guid>())); // .Returns(null); var result = controller.NewVersion(new Guid().ToString()) as InternalServerErrorResult ; Mock.Assert(typeof(InternalServerErrorResult)); }Thanks again,
Tommy