public void CreateBatch_ShouldReturnSuccessTest() { #region Data int mrmUserId = 25; List <int> channelist = new List <int>() { 1, 2, 3 }; List <int> budgettypelist = new List <int>() { 1, 2 }; SqlParameter userChannels = new SqlParameter("@ChannelIds", SqlDbType.NVarChar); userChannels.Value = channelist; SqlParameter userBudgetTypes = new SqlParameter("@BudgetTypeID", SqlDbType.NVarChar); userBudgetTypes.Value = budgettypelist; SqlParameter userId = new SqlParameter("@UserID", SqlDbType.Int); userId.Value = mrmUserId; SqlParameter invoiceHeaderId = new SqlParameter("@InvoiceHeaderId", SqlDbType.Int); invoiceHeaderId.Value = 119; List <SqlParameter> result = new List <SqlParameter>(); result.Add(userChannels); result.Add(userBudgetTypes); result.Add(userId); result.Add(invoiceHeaderId); ApUploadUserChoiceModel apUploadUserChoiceModel = new ApUploadUserChoiceModel() { UserId = mrmUserId, UserSelectedChannelList = channelist, UserSelectedBudgetTypeList = budgettypelist }; UserMessageModel usermodel = new UserMessageModel(); MRM.DANG.Model.UserMessageModel userMessage_SuccessCase = new Model.UserMessageModel { StatusNumber = 0, IsSuccess = true, Message = "Batch Created Succesfuly" }; #endregion #region Mock mockApInvoiceBatchRepository.Setup(x => x.CreateBatch(It.IsAny <ApUploadUserChoiceModel>())) .Returns(userMessage_SuccessCase); #endregion #region Service var financeService = new FinanceServiceMock( apInvoiceBatchRepository: mockApInvoiceBatchRepository.Object); UserMessageModel userMessage = financeService.CreateBatch(apUploadUserChoiceModel); #endregion #region Assertions Assert.IsFalse(userMessage.Message == "No approved invoices exist for the for selected channels and budget type."); Assert.IsTrue(userMessage.Message == "Batch Created successfully."); Assert.IsTrue(userMessage.StatusNumber == 0); Assert.IsTrue(userMessage.IsSuccess == true); #endregion }
public void CreateBatch_ShouldReturnErrorTest() { #region Data int mrmUserId = 25; List <int> channelist = new List <int>() { 1, 2, 3 }; List <int> budgettypelist = new List <int>() { 1, 2 }; SqlParameter userChannels = new SqlParameter("@ChannelIds", SqlDbType.NVarChar); userChannels.Value = channelist; SqlParameter userBudgetTypes = new SqlParameter("@BudgetTypeID", SqlDbType.NVarChar); userBudgetTypes.Value = budgettypelist; SqlParameter userId = new SqlParameter("@UserID", SqlDbType.Int); userId.Value = mrmUserId; SqlParameter invoiceHeaderId = new SqlParameter("@InvoiceHeaderId", SqlDbType.Int); invoiceHeaderId.Value = 119; List <SqlParameter> result = new List <SqlParameter>(); result.Add(userChannels); result.Add(userBudgetTypes); result.Add(userId); result.Add(invoiceHeaderId); ApUploadUserChoiceModel apUploadUserChoiceModel = new ApUploadUserChoiceModel() { UserId = mrmUserId, }; MRM.DANG.Model.UserMessageModel userMessage_Error = new Model.UserMessageModel { IsSuccess = false, IsWarning = false }; bool exceptionCaught = false; UserMessageModel userMessage = new UserMessageModel(); #endregion #region Mock mockApInvoiceBatchRepository.Setup(x => x.CreateBatch(It.IsAny <ApUploadUserChoiceModel>())) .Returns(userMessage_Error); #endregion #region Service var financeService = new FinanceServiceMock( apInvoiceBatchRepository: mockApInvoiceBatchRepository.Object); try { userMessage = financeService.CreateBatch(It.IsAny <ApUploadUserChoiceModel>()); } catch (Exception ex) { exceptionCaught = true; } #endregion #region Assertions Assert.IsFalse(userMessage.IsSuccess == true); Assert.IsTrue(userMessage.IsWarning == false); Assert.IsTrue(exceptionCaught == true); #endregion }