public void GetADealViewModelReturnsNotFound() { ///////////////////Arrange/////////////////// var mockGenRepository = new Mock <IGenericRepository>(); var mockDealRepository = new Mock <IDealRepository>(); mockDealRepository.Setup(x => x.getDealViewModel(7)).Returns(new DealViewModel { Deal = new Deal { Id = 7 } }); var controller = new DealsController(mockGenRepository.Object, mockDealRepository.Object); ///////////////////Act/////////////////// //Should Pass Test IHttpActionResult actionResult = controller.GetADealOwned(10); //Should Fail Test //IHttpActionResult actionResult = controller.GetADealViewModel(7); var contentResult = actionResult as OkNegotiatedContentResult <Deal>; ///////////////////Assert/////////////////// Assert.IsInstanceOfType(actionResult, typeof(UnauthorizedResult)); }
public void GetADealViewModelReturnsDealWithSameId() { ///////////////////Arrange/////////////////// var mockGenRepository = new Mock <IGenericRepository>(); var mockDealRepository = new Mock <IDealRepository>(); mockDealRepository.Setup(x => x.getDealViewModel(7)).Returns(new DealViewModel { Deal = new Deal { Id = 7, DealName = "Test Deal", Amount = 500000m, Stage = "Qualified to Buy", CloseDate = new DateTime(2015, 4, 27), isArchived = false } }); var controller = new DealsController(mockGenRepository.Object, mockDealRepository.Object); ///////////////////Act/////////////////// //Should Pass Test IHttpActionResult actionResult = controller.GetADealOwned(7); //Should Fail Test //IHttpActionResult actionResult = controller.GetADealViewModel(10); var contentResult = actionResult as OkNegotiatedContentResult <Deal>; ///////////////////Assert/////////////////// Assert.IsInstanceOfType(actionResult, typeof(UnauthorizedResult)); //Assert.IsNotNull(contentResult); //Assert.IsNotNull(contentResult.Content); //Assert.AreEqual(7, contentResult.Content.Id); }