public void WatchGameServer_Returns_OK() { var mockClient = new Mock <SDK.SDKClient>(); var mockResponseStream = new Moq.Mock <IAsyncStreamReader <GameServer> >(); var mockSdk = new AgonesSDK(); var expectedWatchReturn = new GameServer(); GameServer actualWatchReturn = null; var serverStream = TestCalls.AsyncServerStreamingCall <GameServer>(mockResponseStream.Object, Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }); mockClient.Setup(m => m.WatchGameServer(It.IsAny <Empty>(), It.IsAny <Metadata>(), It.IsAny <DateTime?>(), It.IsAny <CancellationToken>())).Returns(serverStream); mockResponseStream.Setup(m => m.Current).Returns(expectedWatchReturn); mockResponseStream.SetupSequence(m => m.MoveNext(It.IsAny <CancellationToken>())) .Returns(Task.FromResult(true)) .Returns(Task.FromResult(false)); mockSdk.client = mockClient.Object; mockSdk.WatchGameServer((gs) => { actualWatchReturn = gs; }); Assert.AreSame(expectedWatchReturn, actualWatchReturn); }
public void TestMethod1() { Mock <IDataReader> dataReader = new Moq.Mock <IDataReader>(); DatabaseWrapper._connectionString = string.Empty; dataReader.Setup(x => x[Column1]).Returns(ExpectedValue1); dataReader.Setup(x => x[Column2]).Returns(ExpectedValue2); dataReader.SetupSequence(m => m.Read()) .Returns(true) .Returns(false); RoleRequest roleRequest = new RoleRequest { UserId = 1, CompanyId = 6, Payload = new RoleRequest { AppType = Constants.WORKBOOK_DASHBOARD } }; RoleModel roleModel = new RoleModel { Role = "Shoba", RoleId = 1 }; List <RoleModel> roleModels = new List <RoleModel> { roleModel }; mockEmployeeRepository.Setup(m => m.ExecuteDataReader(It.IsAny <string>(), null)).Returns(dataReader.Object); mockEmployeeRepository.Setup(m => m.CloseConnection()); mockEmployeeRepository.CallBase = true; ReportBuilder.Models.Response.RoleResponse ActualResponse = mockEmployeeRepository.Object.GetRoles(roleRequest); Assert.AreEqual(null, ActualResponse.Error); Assert.AreEqual(roleModels, ActualResponse.Roles); }
public void GetBudgetCommitedDetailsWithoutInvoiceDates_Test() { #region Data Vendor vendor1 = new Vendor() { Id = 66, Name = "KMP" }; Vendor vendor2 = new Vendor() { Id = 99, Name = "SS" }; InvoiceStatus invoiceStatus = new InvoiceStatus() { Id = 1, Name = "In Process", Code = "INPCC" }; InvoiceHeader invoiceHeader1 = new InvoiceHeader() { Id = 200, InvoiceNumber = "111", InvoiceStatus = invoiceStatus, Comments = "UTC Test", Vendor = vendor1 }; InvoiceHeader invoiceHeader2 = new InvoiceHeader() { Id = 100, InvoiceNumber = "222", InvoiceStatus = invoiceStatus, Comments = "UTC Test 2", Vendor = vendor2 }; InvoiceLine invoiceLine1 = new InvoiceLine() { Id = 1, InvoiceHeaderId = 100, Amount = 99, LineDescription = "Invoice Line 1", GLAccountId = 22 }; InvoiceLine invoiceLine2 = new InvoiceLine() { Id = 2, InvoiceHeaderId = 200, Amount = 635, LineDescription = "Invoice Line 2", GLAccountId = 78 }; List <InvoiceLine> invoiceLineList = new List <InvoiceLine>(); invoiceLineList.Add(invoiceLine1); invoiceLineList.Add(invoiceLine2); #endregion #region Mock mockfinanceservice.Setup(x => x.GetInvoiceLinesByWBSId(It.IsAny <int>())) .Returns(invoiceLineList); mockfinanceservice.Setup(x => x.GetInvoiceLinesByDeliverableandWBS(It.IsAny <int>(), It.IsAny <int>())) .Returns(invoiceLineList); mockfinanceservice.SetupSequence(x => x.GetInvoiceById(It.IsAny <int>())) .Returns(invoiceHeader1) .Returns(invoiceHeader2); //Finance Controller Mock var FinanceController = new FinanceControllerMock(financeServicee: mockfinanceservice.Object); #endregion #region Service List <BudgetCommittedAmountDetailsViewModel> result = FinanceController.GetBudgetCommitedDetails(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()); #endregion #region Assertions Assert.IsFalse(result == null); Assert.IsTrue(result.ElementAt(0).Description == "Invoice Line 1"); Assert.IsTrue(result.ElementAt(1).Description == "Invoice Line 2"); Assert.IsTrue(result.ElementAt(0).HeaderComments == "UTC Test"); Assert.IsTrue(result.ElementAt(1).HeaderComments == "UTC Test 2"); Assert.IsTrue(result.ElementAt(0).Vendor == "KMP"); Assert.IsTrue(result.ElementAt(1).Vendor == "SS"); Assert.IsTrue(result.ElementAt(0).InlineAmount == 99); Assert.IsTrue(result.ElementAt(1).InlineAmount == 635); Assert.IsFalse(result.ElementAt(1).Status == "Approved"); #endregion }
public void GetCRVendors_Tests() { #region Variables var deliverableId = 101; #endregion #region Data SetUp #region MasterVendor var masterVendorsWithSAPNo = new List <MasterVendor1>() { new MasterVendor1 { Id = 1, SAPVendorId = 1 }, new MasterVendor1 { Id = 2, SAPVendorId = 2 }, new MasterVendor1 { Id = 3, SAPVendorId = 3 }, new MasterVendor1 { Id = 4, SAPVendorId = 4 }, new MasterVendor1 { Id = 5, SAPVendorId = 5 }, }; var masterVendorsWithoutSAPNo = new List <MasterVendor1>() { new MasterVendor1 { Id = 6, SAPVendorId = null, OtherName = "No SAP Number", PhoneNumber = "2154519099", Address = "1 North Front Street" } }; #endregion #region Deliverable MasterVendor var lstDeliverableMasterVendor = new List <Deliverable_MasterVendor>() { new Deliverable_MasterVendor { Id = 1, DeliverableId = 101, AwardedContractFlag = true, RespondedFlag = true, MasterVendorId = 2 }, new Deliverable_MasterVendor { Id = 2, DeliverableId = 101, AwardedContractFlag = true, RespondedFlag = true, MasterVendorId = 3 }, new Deliverable_MasterVendor { Id = 3, DeliverableId = 101, AwardedContractFlag = true, RespondedFlag = true, MasterVendorId = 5 } }; #endregion #region Vendor var lstVendor = new List <Vendor>() { new Vendor { Name = "Vendor 2", City = "Pasadena", FederalId = "VEN2", Id = 2, PhoneNumber = "9876543211", SAPVendorNumber = "SAPVen2" }, new Vendor { Name = "Vendor 3", City = "Pasadena", FederalId = "VEN3", Id = 3, PhoneNumber = "9876543212", SAPVendorNumber = "SAPVen3" }, new Vendor { Name = "Vendor 5", City = "Pasadena", FederalId = "VEN5", Id = 5, PhoneNumber = "9876543215", SAPVendorNumber = "SAPVen5" } }; #endregion #region Deliverable_UserTitle_MRMUser List <Deliverable_UserTitle_MRMUser> lstDeliverableUsertitleMrmuser = new List <Deliverable_UserTitle_MRMUser>(); lstDeliverableUsertitleMrmuser.Add(new Deliverable_UserTitle_MRMUser { Id = 1, IsPrimaryFlag = true, MRMUserId = 1, NotifyFlag = true }); lstDeliverableUsertitleMrmuser.Add(new Deliverable_UserTitle_MRMUser { Id = 2, IsPrimaryFlag = true, MRMUserId = 2, NotifyFlag = true }); lstDeliverableUsertitleMrmuser.Add(new Deliverable_UserTitle_MRMUser { Id = 3, IsPrimaryFlag = true, MRMUserId = 3, NotifyFlag = true }); #endregion #endregion #region Mock mockVendorViewRepository.SetupSequence(x => x.GetMany(It.IsAny <Expression <Func <MasterVendor1, bool> > >())) .Returns(masterVendorsWithSAPNo.AsEnumerable()) .Returns(masterVendorsWithoutSAPNo.AsEnumerable()); mockVendorViewRepository.Setup(x => x.GetSingle(It.IsAny <Expression <Func <MasterVendor1, bool> > >())).Returns(new MasterVendor1 { Id = 1, SAPVendorId = 1 }); mockDeliverableVendorRepository.Setup(x => x.GetMany(It.IsAny <Expression <Func <Deliverable_MasterVendor, bool> > >())).Returns(lstDeliverableMasterVendor); mockDeliverableUserTitleMrmUserRepository.Setup(x => x.GetMany(It.IsAny <Expression <Func <Deliverable_UserTitle_MRMUser, bool> > >())).Returns(lstDeliverableUsertitleMrmuser); mockVendorRepository.Setup(x => x.GetMany(It.IsAny <Expression <Func <Vendor, bool> > >())).Returns(lstVendor); #endregion #region Services var deliverableService2 = new DeliverableServiceV2Mock( masterVendorViewRepository: mockVendorViewRepository.Object, deliverable_VendorRepository: mockDeliverableVendorRepository.Object, deliverableUserTitleMrmUserRepository: mockDeliverableUserTitleMrmUserRepository.Object, vendorRepository: mockVendorRepository.Object); #endregion #region Asserts var results = deliverableService2.GetCRVendors(new List <int> { 2, 3, 5 }, deliverableId).ToList(); Assert.IsTrue(results != null); Assert.IsTrue(results.Count == 4); Assert.IsTrue(results[results.Count - 1].SapVendorNumber == null); #endregion }