public void GetDateDifferenceTestForSameDate() { // Mock Manager layer and stub the business method var mockManager = new Mock <IDateManager>(); mockManager.Setup(x => x.CalculateDateDifference(It.IsAny <DateRequestModel>())).Returns((0)); // Arrange var requestModel = new DateRequestModel() { FromDate = new Date() { Day = 2, Month = 6, Year = 1983 }, ToDate = new Date() { Day = 2, Month = 6, Year = 1983 } }; // Create controller instance var api = new DateController(mockManager.Object) { Request = new HttpRequestMessage() { Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } } } }; // Act var responseObj = api.GetDateDifference(requestModel); var responseModel = responseObj?.Content?.ReadAsAsync <int>()?.Result; // Assert Assert.AreEqual(responseModel, 0); }
public void GetDateDifferenceTestForNullRequestModel() { // Mock Manager layer and stub the business method var mockManager = new Mock <IDateManager>(); // Arrange DateRequestModel requestModel = null; // Create controller instance var api = new DateController(mockManager.Object) { Request = new HttpRequestMessage() { Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } } } }; // Act var responseObj = api.GetDateDifference(requestModel); var statusCode = responseObj?.StatusCode; // Assert Assert.AreEqual(statusCode, HttpStatusCode.BadRequest); }