public void TestModel(int hid) { var ctgy = new LearnCategory(); Assert.False(ctgy.IsValid(null)); // Name ctgy.Name = "Test"; //ctgy.HomeID = hid; Assert.True(ctgy.IsValid(null)); // Parent ID ctgy.ParentID = 999; Assert.False(ctgy.IsValid(null)); ctgy.HomeID = hid; Assert.True(ctgy.IsValid(null)); var dbcontext = this.fixture.GetCurrentDataContext(); // Initialize data if (hid == DataSetupUtility.Home1ID) { fixture.InitHome1TestData(dbcontext); } else if (hid == DataSetupUtility.Home2ID) { fixture.InitHome2TestData(dbcontext); } Assert.False(ctgy.IsValid(dbcontext)); ctgy.ParentID = null; Assert.True(ctgy.IsValid(dbcontext)); ctgy.HomeID = 999; Assert.False(ctgy.IsValid(dbcontext)); }
public void TestController1(int hid, string user) { var context = this.fixture.GetCurrentDataContext(); if (hid == DataSetupUtility.Home1ID) { fixture.InitHome1TestData(context); } if (hid == DataSetupUtility.Home2ID) { fixture.InitHome2TestData(context); } if (hid == DataSetupUtility.Home3ID) { fixture.InitHome3TestData(context); } if (hid == DataSetupUtility.Home4ID) { fixture.InitHome4TestData(context); } if (hid == DataSetupUtility.Home5ID) { fixture.InitHome5TestData(context); } // 1. Prepare dta var userclaim = DataSetupUtility.GetClaimForUser(user); var httpctx = UnitTestUtility.GetDefaultHttpContext(provider, userclaim); // 2. Test it var controller = new FinanceReportByAccountsController(context); Assert.NotNull(controller); controller.ControllerContext = new ControllerContext() { HttpContext = httpctx }; var rsts = controller.Get(); var curhmemquery = (from homemem in context.HomeMembers where homemem.HomeID == hid && homemem.User == user select homemem).FirstOrDefault(); var curhmem = Assert.IsType <HomeMember>(curhmemquery); var expamt = context.FinanceAccount.Where(p => p.HomeID == hid).Count(); var actamt = rsts.ToList().Where(p => p.HomeID == hid).Count(); if (curhmem.IsChild.HasValue && curhmem.IsChild == true) { expamt = context.FinanceAccount.Where(p => p.HomeID == hid && p.Owner == user).Count(); Assert.Equal(expamt, actamt); } else { Assert.Equal(expamt, actamt); } }
public void TestController1(int hid, string user) { var context = this.fixture.GetCurrentDataContext(); if (hid == DataSetupUtility.Home1ID) { fixture.InitHome1TestData(context); } if (hid == DataSetupUtility.Home2ID) { fixture.InitHome2TestData(context); } if (hid == DataSetupUtility.Home3ID) { fixture.InitHome3TestData(context); } if (hid == DataSetupUtility.Home4ID) { fixture.InitHome4TestData(context); } if (hid == DataSetupUtility.Home5ID) { fixture.InitHome5TestData(context); } // 1. Prepare dta var userclaim = DataSetupUtility.GetClaimForUser(user); var httpctx = UnitTestUtility.GetDefaultHttpContext(provider, userclaim); // 2. Test it var controller = new FinanceReportByControlCentersController(context); Assert.NotNull(controller); controller.ControllerContext = new ControllerContext() { HttpContext = httpctx }; var rsts = controller.Get(); var expamt = context.FinanceControlCenter.Where(p => p.HomeID == hid).Count(); var actamt = rsts.ToList().Where(p => p.HomeID == hid).Count(); Assert.Equal(expamt, actamt); }
public async Task TestCase1(int hid, string currency, string user) { var context = this.fixture.GetCurrentDataContext(); // 0a. Prepare the context for other homes to test the filters var secondhid = hid; if (hid == DataSetupUtility.Home1ID) { if (user == DataSetupUtility.UserA || user == DataSetupUtility.UserB) { secondhid = DataSetupUtility.Home3ID; } else if (user == DataSetupUtility.UserC) { secondhid = DataSetupUtility.Home4ID; } else if (user == DataSetupUtility.UserD) { secondhid = DataSetupUtility.Home5ID; } } else if (hid == DataSetupUtility.Home2ID) { secondhid = DataSetupUtility.Home3ID; } if (hid == DataSetupUtility.Home1ID || secondhid == DataSetupUtility.Home1ID) { fixture.InitHome1TestData(context); } else if (hid == DataSetupUtility.Home2ID || secondhid == DataSetupUtility.Home2ID) { fixture.InitHome2TestData(context); } else if (hid == DataSetupUtility.Home3ID || secondhid == DataSetupUtility.Home3ID) { fixture.InitHome3TestData(context); } else if (hid == DataSetupUtility.Home4ID || secondhid == DataSetupUtility.Home4ID) { fixture.InitHome4TestData(context); } else if (hid == DataSetupUtility.Home5ID || secondhid == DataSetupUtility.Home5ID) { fixture.InitHome5TestData(context); } var account = context.FinanceAccount.Where(p => p.HomeID == hid && p.Status != (Byte)FinanceAccountStatus.Closed).FirstOrDefault(); var cc = context.FinanceControlCenter.Where(p => p.HomeID == hid).FirstOrDefault(); var curhmemquery = (from homemem in context.HomeMembers where homemem.HomeID == hid && homemem.User == user select homemem).FirstOrDefault(); var curhmem = Assert.IsType <HomeMember>(curhmemquery); var existamt = (from homemem in context.HomeMembers join findoc in context.FinanceDocument on new { homemem.HomeID, homemem.User } equals new { findoc.HomeID, User = user } select findoc.ID).ToList().Count(); var existamt_curhome = context.FinanceDocument.Where(p => p.HomeID == hid).Count(); // 1. Create first docs. var control = new FinanceDocumentsController(context); var userclaim = DataSetupUtility.GetClaimForUser(user); var httpctx = UnitTestUtility.GetDefaultHttpContext(provider, userclaim); control.ControllerContext = new ControllerContext() { HttpContext = httpctx }; var doc = new FinanceDocument() { HomeID = hid, DocType = FinanceDocumentType.DocType_Normal, TranCurr = currency, Desp = "Test 1" }; var item = new FinanceDocumentItem() { DocumentHeader = doc, ItemID = 1, Desp = "Item 1.1", TranType = 2, // Wage TranAmount = 10, AccountID = account.ID, ControlCenterID = cc.ID, }; doc.Items.Add(item); var rst = await control.Post(doc); Assert.NotNull(rst); var rst2 = Assert.IsType <CreatedODataResult <FinanceDocument> >(rst); Assert.Equal(rst2.Entity.TranCurr, doc.TranCurr); Assert.Equal(rst2.Entity.Desp, doc.Desp); var firstdocid = rst2.Entity.ID; documentsCreated.Add(firstdocid); Assert.True(firstdocid > 0); // 2a. Now read the whole orders (without home id) var queryUrl = "http://localhost/api/FinanceDocuments"; var req = UnitTestUtility.GetHttpRequest(httpctx, "GET", queryUrl); var odatacontext = UnitTestUtility.GetODataQueryContext <FinanceDocument>(this.model); var options = UnitTestUtility.GetODataQueryOptions <FinanceDocument>(odatacontext, req); var rst3 = control.Get(options); Assert.NotNull(rst3); //if (curhmem.IsChild.HasValue && curhmem.IsChild == true) //{ // existamt = context.FinanceDocument.Where(p => p.Createdby == user).Count(); // Assert.Equal(existamt, rst3.Cast<FinanceDocument>().Count()); //} //else //{ // Assert.Equal(existamt + 1, rst3.Cast<FinanceDocument>().Count()); //} // 2b. Now read the whole orders (with home id) queryUrl = "http://localhost/api/FinanceDocuments?$filter=HomeID eq " + hid.ToString(); req = UnitTestUtility.GetHttpRequest(httpctx, "GET", queryUrl); // odatacontext = UnitTestUtility.GetODataQueryContext<FinanceDocument>(this.model); options = UnitTestUtility.GetODataQueryOptions <FinanceDocument>(odatacontext, req); rst3 = control.Get(options); Assert.NotNull(rst3); if (curhmem.IsChild.HasValue && curhmem.IsChild == true) { existamt_curhome = context.FinanceDocument.Where(p => p.HomeID == hid && p.Createdby == user).Count(); Assert.Equal(existamt_curhome, rst3.Cast <FinanceDocument>().Count()); } else { Assert.Equal(existamt_curhome + 1, rst3.Cast <FinanceDocument>().Count()); } // 3. Now create another one! doc = new FinanceDocument() { HomeID = hid, DocType = FinanceDocumentType.DocType_Normal, TranCurr = currency, Desp = "Test 2" }; item = new FinanceDocumentItem() { DocumentHeader = doc, ItemID = 1, Desp = "Item 2.1", TranType = 2, // Wage TranAmount = 10, AccountID = account.ID, ControlCenterID = cc.ID }; doc.Items.Add(item); rst = await control.Post(doc); Assert.NotNull(rst); rst2 = Assert.IsType <CreatedODataResult <FinanceDocument> >(rst); Assert.Equal(rst2.Entity.TranCurr, doc.TranCurr); Assert.Equal(rst2.Entity.Desp, doc.Desp); // documentsCreated.Add(rst2.Entity); var seconddocid = rst2.Entity.ID; Assert.True(seconddocid > 0); // 4a. Change one document - add new document item doc.Desp = "Change Test"; doc.Items.Add(new FinanceDocumentItem { DocumentHeader = doc, ItemID = 2, Desp = "Item 2.2", TranType = 2, // Wage TranAmount = 20, AccountID = account.ID, ControlCenterID = cc.ID }); rst = await control.Put(seconddocid, doc); Assert.NotNull(rst); var rst4 = Assert.IsType <UpdatedODataResult <FinanceDocument> >(rst); Assert.Equal(doc.Desp, rst4.Entity.Desp); Assert.Equal(2, rst4.Entity.Items.Count); Assert.Equal("Item 2.1", rst4.Entity.Items.First(p => p.ItemID == 1).Desp); Assert.Equal("Item 2.2", rst4.Entity.Items.First(p => p.ItemID == 2).Desp); // 4b. Change one document - remove document item var itemidx = doc.Items.First(p => p.ItemID == 2); doc.Items.Remove(item); rst = await control.Put(seconddocid, doc); Assert.NotNull(rst); rst4 = Assert.IsType <UpdatedODataResult <FinanceDocument> >(rst); Assert.Equal(1, rst4.Entity.Items.Count); // Assert.Equal("Item 2.1", rst4.Entity.Items.First(p => p.ItemID == 1).Desp); // 5. Delete the second document var rst5 = await control.Delete(seconddocid); Assert.NotNull(rst5); var rst6 = Assert.IsType <StatusCodeResult>(rst5); Assert.Equal(204, rst6.StatusCode); Assert.Equal(0, context.FinanceDocumentItem.Where(p => p.DocID == seconddocid).Count()); // 6. Now read the whole documents rst3 = control.Get(options); Assert.NotNull(rst3); if (curhmem.IsChild.HasValue && curhmem.IsChild == true) { existamt_curhome = context.FinanceDocument.Where(p => p.HomeID == hid && p.Createdby == user).Count(); Assert.Equal(existamt_curhome, rst3.Cast <FinanceDocument>().Count()); } else { Assert.Equal(existamt_curhome + 1, rst3.Cast <FinanceDocument>().Count()); } // Last, clear all created objects CleanupCreatedEntries(); await context.SaveChangesAsync(); await context.DisposeAsync(); }
public async Task TestCase1(int hid, string currency, string user, short doctype) { var context = this.fixture.GetCurrentDataContext(); // 0. Prepare the context for current home if (hid == DataSetupUtility.Home1ID) { fixture.InitHome1TestData(context); } else if (hid == DataSetupUtility.Home2ID) { fixture.InitHome2TestData(context); } else if (hid == DataSetupUtility.Home3ID) { fixture.InitHome3TestData(context); } else if (hid == DataSetupUtility.Home4ID) { fixture.InitHome4TestData(context); } else if (hid == DataSetupUtility.Home5ID) { fixture.InitHome5TestData(context); } var account = context.FinanceAccount.Where(p => p.HomeID == hid && p.Status != (Byte)FinanceAccountStatus.Closed).FirstOrDefault(); var cc = context.FinanceControlCenter.Where(p => p.HomeID == hid).FirstOrDefault(); // 1. Create first Loan docs. var control = new FinanceDocumentsController(context); var userclaim = DataSetupUtility.GetClaimForUser(user); var httpctx = UnitTestUtility.GetDefaultHttpContext(provider, userclaim); control.ControllerContext = new ControllerContext() { HttpContext = httpctx }; // 1a. Prepare data var dpcontext = new FinanceLoanDocumentCreateContext(); dpcontext.DocumentInfo = new FinanceDocument() { HomeID = hid, DocType = doctype, TranCurr = currency, Desp = "Test 1" }; var item = new FinanceDocumentItem() { DocumentHeader = dpcontext.DocumentInfo, ItemID = 1, Desp = "Item 1.1", TranType = doctype == FinanceDocumentType.DocType_BorrowFrom ? FinanceTransactionType.TranType_BorrowFrom : FinanceTransactionType.TranType_LendTo, TranAmount = 1200, AccountID = account.ID, ControlCenterID = cc.ID, }; dpcontext.DocumentInfo.Items.Add(item); dpcontext.AccountInfo = new FinanceAccount() { HomeID = hid, Name = "Account_8" + ".1", CategoryID = doctype == FinanceDocumentType.DocType_BorrowFrom ? FinanceAccountCategory.AccountCategory_BorrowFrom : FinanceAccountCategory.AccountCategory_LendTo, Owner = user, Status = (Byte)FinanceAccountStatus.Normal, }; var startdate = new DateTime(2020, 1, 10); var enddate = new DateTime(2021, 1, 10); dpcontext.AccountInfo.ExtraLoan = new FinanceAccountExtraLoan() { StartDate = startdate, EndDate = enddate, TotalMonths = 12, RepaymentMethod = LoanRepaymentMethod.EqualPrincipal, InterestFree = false, }; var rsts = CommonUtility.WorkoutRepeatedDatesWithAmountAndInterest(new RepeatDatesWithAmountAndInterestCalInput { RepaymentMethod = dpcontext.AccountInfo.ExtraLoan.RepaymentMethod.Value, InterestFreeLoan = dpcontext.AccountInfo.ExtraLoan.InterestFree.Value, StartDate = dpcontext.AccountInfo.ExtraLoan.StartDate, TotalAmount = 12000, EndDate = dpcontext.AccountInfo.ExtraLoan.EndDate, TotalMonths = dpcontext.AccountInfo.ExtraLoan.TotalMonths.Value, FirstRepayDate = new DateTime(2020, 2, 15) }); var tmpdocid = 1; foreach (var rst in rsts) { var tmpdoc = new FinanceTmpLoanDocument { DocumentID = tmpdocid++, TransactionAmount = rst.TranAmount, InterestAmount = rst.InterestAmount, TransactionDate = rst.TranDate, HomeID = hid, ControlCenterID = item.ControlCenterID, OrderID = item.OrderID, Description = item.Desp, }; dpcontext.AccountInfo.ExtraLoan.LoanTmpDocs.Add(tmpdoc); } var resp = await control.PostLoanDocument(dpcontext); var doc = Assert.IsType <CreatedODataResult <FinanceDocument> >(resp).Entity; documentsCreated.Add(doc.ID); Assert.True(doc.Items.Count == 2); // Now check in the databse foreach (var docitem in doc.Items) { if (docitem.AccountID != account.ID) { accountsCreated.Add(docitem.AccountID); var acnt = context.FinanceAccount.Find(docitem.AccountID); Assert.NotNull(acnt); if (doctype == FinanceDocumentType.DocType_BorrowFrom) { Assert.True(acnt.CategoryID == FinanceAccountCategory.AccountCategory_BorrowFrom); } else if (doctype == FinanceDocumentType.DocType_LendTo) { Assert.True(acnt.CategoryID == FinanceAccountCategory.AccountCategory_LendTo); } var acntExtraLoan = context.FinanceAccountExtraLoan.Find(docitem.AccountID); Assert.NotNull(acntExtraLoan); Assert.True(acntExtraLoan.RefDocID == doc.ID); var tmpdocs = context.FinanceTmpLoanDocument.Where(p => p.AccountID == docitem.AccountID).OrderBy(p => p.TransactionDate).ToList(); Assert.True(rsts.Count == tmpdocs.Count); foreach (var rst in rsts) { DateTime dat = rst.TranDate; var tdoc = tmpdocs.Find(p => p.TransactionDate.Date == dat); Assert.NotNull(tdoc); Assert.True(tdoc.AccountID == acntExtraLoan.AccountID); } } } // Last, clear all created objects CleanupCreatedEntries(); await context.DisposeAsync(); }
public async Task TestCase1(int hid, string user) { var context = this.fixture.GetCurrentDataContext(); if (hid == DataSetupUtility.Home1ID) { fixture.InitHome1TestData(context); } if (hid == DataSetupUtility.Home2ID) { fixture.InitHome2TestData(context); } if (hid == DataSetupUtility.Home3ID) { fixture.InitHome3TestData(context); } if (hid == DataSetupUtility.Home4ID) { fixture.InitHome4TestData(context); } if (hid == DataSetupUtility.Home5ID) { fixture.InitHome5TestData(context); } // 1. Prepare dta var userclaim = DataSetupUtility.GetClaimForUser(user); var httpctx = UnitTestUtility.GetDefaultHttpContext(provider, userclaim); var listCCs = context.FinanceControlCenter.Where(p => p.HomeID == hid).ToList <FinanceControlCenter>(); var curhmemquery = (from homemem in context.HomeMembers where homemem.HomeID == hid && homemem.User == user select homemem).FirstOrDefault(); var curhmem = Assert.IsType <HomeMember>(curhmemquery); var existamt = (from homemem in context.HomeMembers join finord in context.FinanceOrder on new { homemem.HomeID, homemem.User } equals new { finord.HomeID, User = user } select finord.ID).ToList().Count(); var existamt_curhome = context.FinanceOrder.Where(p => p.HomeID == hid).Count(); // 2. Create order var control = new FinanceOrdersController(context); control.ControllerContext = new ControllerContext() { HttpContext = httpctx }; var ord = new FinanceOrder() { HomeID = hid, Name = "Order 1", Comment = "Comment 1" }; var srule = new FinanceOrderSRule() { Order = ord, RuleID = 1, ControlCenterID = listCCs[0].ID, Precent = 100 }; ord.SRule.Add(srule); var rst = await control.Post(ord); Assert.NotNull(rst); var rst2 = Assert.IsType <CreatedODataResult <FinanceOrder> >(rst); Assert.Equal(rst2.Entity.Name, ord.Name); var oid = rst2.Entity.ID; Assert.True(oid > 0); ordersCreated.Add(oid); // 3. Read the order out (without Home ID) var queryUrl = "http://localhost/api/FinanceOrders"; var req = UnitTestUtility.GetHttpRequest(httpctx, "GET", queryUrl); var odatacontext = UnitTestUtility.GetODataQueryContext <FinanceOrder>(this.model); var options = UnitTestUtility.GetODataQueryOptions <FinanceOrder>(odatacontext, req); var rst3 = control.Get(options); Assert.NotNull(rst3); if (curhmem.IsChild.HasValue && curhmem.IsChild == true) { existamt = context.FinanceOrder.Where(p => p.HomeID == hid).Count(); Assert.Equal(existamt + 1, rst3.Cast <FinanceOrder>().Count()); } else { Assert.Equal(existamt + 1, rst3.Cast <FinanceOrder>().Count()); } // 3a. Read the order out (with Home ID) queryUrl = "http://localhost/api/FinanceOrders?$filter=HomeID eq " + hid.ToString(); req = UnitTestUtility.GetHttpRequest(httpctx, "GET", queryUrl); //var odatacontext = UnitTestUtility.GetODataQueryContext<FinanceOrder>(this.model); options = UnitTestUtility.GetODataQueryOptions <FinanceOrder>(odatacontext, req); rst3 = control.Get(options); Assert.NotNull(rst3); Assert.Equal(existamt_curhome + 1, rst3.Cast <FinanceOrder>().Count()); // 4a. Change one order - Add new rule var norder = rst2.Entity; norder.Name = "New Order"; norder.SRule.ElementAt(0).Precent = 80; norder.SRule.Add(new FinanceOrderSRule { Order = norder, RuleID = 2, ControlCenterID = listCCs.Count > 1 ? listCCs[1].ID : listCCs[0].ID, Precent = 20 }); rst = await control.Put(norder.ID, norder); Assert.NotNull(rst); var rst4 = Assert.IsType <UpdatedODataResult <FinanceOrder> >(rst); Assert.Equal(norder.Name, rst4.Entity.Name); // Re-read the order //queryUrl = "http://localhost/api/FinanceOrders?$filter=HomeID eq " + hid.ToString() + " and ID eq " + norder.ID.ToString() + "&$expand=SRule"; //req = UnitTestUtility.GetHttpRequest(httpctx, "GET", queryUrl); //options = UnitTestUtility.GetODataQueryOptions<FinanceOrder>(odatacontext, req); //rst3 = control.Get(options); //var rst3a = rst3.Cast<FinanceOrder>(); //Assert.True(rst3a.Count() == 1); //var rst3a_elem = rst3a.ElementAt(0); //Assert.True(rst3a_elem.SRule.Count == 2); ////var rst3a = Assert.IsType<FinanceOrder>(rst3); ////Assert.True(rst3a.SRule.Count == 2); // 5. Delete an order var rst5 = await control.Delete(oid); Assert.NotNull(rst4); var rst6 = Assert.IsType <StatusCodeResult>(rst5); Assert.Equal(204, rst6.StatusCode); Assert.Equal(0, context.FinanceOrderSRule.Where(p => p.OrderID == oid).Count()); ordersCreated.Clear(); // 6. Read the order again queryUrl = "http://localhost/api/FinanceOrders?$filter=HomeID eq " + hid.ToString(); req = UnitTestUtility.GetHttpRequest(httpctx, "GET", queryUrl); options = UnitTestUtility.GetODataQueryOptions <FinanceOrder>(odatacontext, req); rst3 = control.Get(options); Assert.NotNull(rst3); Assert.Equal(existamt_curhome, rst3.Cast <FinanceOrder>().Count()); await context.DisposeAsync(); }
public async Task TestCase1_NormalAccount(int hid, string user, int ctgyid) { var context = this.fixture.GetCurrentDataContext(); var secondhid = hid; // 0. Initialize data if (hid == DataSetupUtility.Home1ID) { if (user == DataSetupUtility.UserA || user == DataSetupUtility.UserB) { secondhid = DataSetupUtility.Home3ID; } else if (user == DataSetupUtility.UserC) { secondhid = DataSetupUtility.Home4ID; } else if (user == DataSetupUtility.UserD) { secondhid = DataSetupUtility.Home5ID; } } else if (hid == DataSetupUtility.Home2ID) { secondhid = DataSetupUtility.Home3ID; } if (hid == DataSetupUtility.Home1ID || secondhid == DataSetupUtility.Home1ID) { fixture.InitHome1TestData(context); } if (hid == DataSetupUtility.Home2ID || secondhid == DataSetupUtility.Home2ID) { fixture.InitHome2TestData(context); } if (hid == DataSetupUtility.Home3ID || secondhid == DataSetupUtility.Home3ID) { fixture.InitHome3TestData(context); } if (hid == DataSetupUtility.Home4ID || secondhid == DataSetupUtility.Home4ID) { fixture.InitHome4TestData(context); } if (hid == DataSetupUtility.Home5ID || secondhid == DataSetupUtility.Home5ID) { fixture.InitHome5TestData(context); } // 0a. Prepare the context var control = new FinanceAccountsController(context); var userclaim = DataSetupUtility.GetClaimForUser(user); var httpctx = UnitTestUtility.GetDefaultHttpContext(provider, userclaim); control.ControllerContext = new ControllerContext() { HttpContext = httpctx }; var curhmemquery = (from homemem in context.HomeMembers where homemem.HomeID == hid && homemem.User == user select homemem).FirstOrDefault(); var curhmem = Assert.IsType <HomeMember>(curhmemquery); var acntamt = (from homemem in context.HomeMembers join finacnt in context.FinanceAccount on new { homemem.HomeID, homemem.User } equals new { finacnt.HomeID, User = user } select finacnt.ID).ToList().Count(); // 1. Create first account var acnt = new FinanceAccount() { HomeID = hid, Name = "Account_" + ctgyid.ToString() + ".1", CategoryID = ctgyid, Owner = user }; var rst = await control.Post(acnt); Assert.NotNull(rst); var rst2 = Assert.IsType <CreatedODataResult <FinanceAccount> >(rst); Assert.Equal(rst2.Entity.Name, acnt.Name); Assert.Equal(rst2.Entity.HomeID, acnt.HomeID); Assert.Equal(rst2.Entity.CategoryID, acnt.CategoryID); Assert.Equal(rst2.Entity.Owner, user); var firstacntid = rst2.Entity.ID; Assert.True(firstacntid > 0); accountsCreated.Add(firstacntid); // 2. Now read the whole accounts (no home ID applied) var queryUrl = "http://localhost/api/FinanceAccounts"; var req = UnitTestUtility.GetHttpRequest(httpctx, "GET", queryUrl); var odatacontext = UnitTestUtility.GetODataQueryContext <FinanceAccount>(this.model); var options = UnitTestUtility.GetODataQueryOptions <FinanceAccount>(odatacontext, req); var rst3 = control.Get(options); Assert.NotNull(rst3); if (curhmem.IsChild.HasValue && curhmem.IsChild == true) { acntamt = context.FinanceAccount.Where(p => p.Owner == curhmem.User).Count(); Assert.Equal(acntamt, rst3.Cast <FinanceAccount>().Count()); } else { Assert.Equal(acntamt + 1, rst3.Cast <FinanceAccount>().Count()); } // 2a. Read the whole accounts (with home ID applied) queryUrl = "http://localhost/api/FinanceAccounts?$filter=HomeID eq " + hid.ToString(); req = UnitTestUtility.GetHttpRequest(httpctx, "GET", queryUrl); //var odatacontext = UnitTestUtility.GetODataQueryContext<FinanceAccount>(this.model); options = UnitTestUtility.GetODataQueryOptions <FinanceAccount>(odatacontext, req); rst3 = control.Get(options); Assert.NotNull(rst3); if (curhmem.IsChild.HasValue && curhmem.IsChild == true) { acntamt = context.FinanceAccount.Where(p => p.HomeID == hid && p.Owner == curhmem.User).Count(); Assert.Equal(acntamt, rst3.Cast <FinanceAccount>().Count()); } else { acntamt = context.FinanceAccount.Where(p => p.HomeID == hid).Count(); Assert.Equal(acntamt, rst3.Cast <FinanceAccount>().Count()); } // 3. Now create another one! acnt = new FinanceAccount() { HomeID = hid, Name = "Account_" + ctgyid.ToString() + ".2", Comment = "Comment 2", CategoryID = ctgyid, Owner = user }; rst = await control.Post(acnt); Assert.NotNull(rst); rst2 = Assert.IsType <CreatedODataResult <FinanceAccount> >(rst); Assert.Equal(rst2.Entity.Name, acnt.Name); Assert.Equal(rst2.Entity.HomeID, acnt.HomeID); Assert.Equal(rst2.Entity.CategoryID, acnt.CategoryID); Assert.Equal(rst2.Entity.Owner, acnt.Owner); var secondacntid = rst2.Entity.ID; Assert.True(secondacntid > 0); accountsCreated.Add(secondacntid); // 4. Change one account acnt.Comment = "Comment 2 Updated"; rst = await control.Put(secondacntid, acnt); Assert.NotNull(rst); var rst4 = Assert.IsType <UpdatedODataResult <FinanceAccount> >(rst); Assert.Equal(rst4.Entity.Name, acnt.Name); Assert.Equal(rst4.Entity.HomeID, acnt.HomeID); Assert.Equal(rst4.Entity.Comment, acnt.Comment); // 5. Delete the second account var rst5 = await control.Delete(secondacntid); Assert.NotNull(rst5); var rst6 = Assert.IsType <StatusCodeResult>(rst5); Assert.Equal(204, rst6.StatusCode); // 6. Now read the whole accounts rst3 = control.Get(options); Assert.NotNull(rst3); if (curhmem.IsChild.HasValue && curhmem.IsChild == true) { acntamt = context.FinanceAccount.Where(p => p.HomeID == hid && p.Owner == user).Count(); Assert.Equal(acntamt, rst3.Cast <FinanceAccount>().Count()); } else { acntamt = context.FinanceAccount.Where(p => p.HomeID == hid).Count(); Assert.Equal(acntamt, rst3.Cast <FinanceAccount>().Count()); } // 7. Delete the first account rst5 = await control.Delete(firstacntid); Assert.NotNull(rst5); rst6 = Assert.IsType <StatusCodeResult>(rst5); Assert.Equal(204, rst6.StatusCode); // 8. Now read the whole accounts rst3 = control.Get(options); Assert.NotNull(rst3); if (curhmem.IsChild.HasValue && curhmem.IsChild == true) { acntamt = context.FinanceAccount.Where(p => p.HomeID == hid && p.Owner == user).Count(); Assert.Equal(acntamt, rst3.Cast <FinanceAccount>().Count()); } else { acntamt = context.FinanceAccount.Where(p => p.HomeID == hid).Count(); Assert.Equal(acntamt, rst3.Cast <FinanceAccount>().Count()); } accountsCreated.Clear(); await context.DisposeAsync(); }
public async Task TestCase1(int hid, string currency, string user, short doctype) { var context = this.fixture.GetCurrentDataContext(); // 0. Prepare the context for current home if (hid == DataSetupUtility.Home1ID) { fixture.InitHome1TestData(context); } else if (hid == DataSetupUtility.Home2ID) { fixture.InitHome2TestData(context); } else if (hid == DataSetupUtility.Home3ID) { fixture.InitHome3TestData(context); } else if (hid == DataSetupUtility.Home4ID) { fixture.InitHome4TestData(context); } else if (hid == DataSetupUtility.Home5ID) { fixture.InitHome5TestData(context); } var account = context.FinanceAccount.Where(p => p.HomeID == hid && p.Status != (Byte)FinanceAccountStatus.Closed).FirstOrDefault(); var cc = context.FinanceControlCenter.Where(p => p.HomeID == hid).FirstOrDefault(); // 1. Create DP docs. var control = new FinanceDocumentsController(context); var userclaim = DataSetupUtility.GetClaimForUser(user); var httpctx = UnitTestUtility.GetDefaultHttpContext(provider, userclaim); control.ControllerContext = new ControllerContext() { HttpContext = httpctx }; // 1a. Prepare data var dpcontext = new FinanceADPDocumentCreateContext(); dpcontext.DocumentInfo = new FinanceDocument() { HomeID = hid, DocType = doctype, TranCurr = currency, Desp = "Test 1" }; var item = new FinanceDocumentItem() { DocumentHeader = dpcontext.DocumentInfo, ItemID = 1, Desp = "Item 1.1", TranType = doctype == FinanceDocumentType.DocType_AdvancePayment ? FinanceTransactionType.TranType_AdvancePaymentOut : FinanceTransactionType.TranType_AdvanceReceiveIn, TranAmount = 1200, AccountID = account.ID, ControlCenterID = cc.ID, }; dpcontext.DocumentInfo.Items.Add(item); dpcontext.AccountInfo = new FinanceAccount() { HomeID = hid, Name = "Account_8" + ".1", CategoryID = doctype == FinanceDocumentType.DocType_AdvancePayment ? FinanceAccountCategory.AccountCategory_AdvancePayment : FinanceAccountCategory.AccountCategory_AdvanceReceive, Owner = user, Status = (Byte)FinanceAccountStatus.Normal, }; var startdate = DateTime.Today; var enddate = DateTime.Today.AddMonths(6); dpcontext.AccountInfo.ExtraDP = new FinanceAccountExtraDP() { StartDate = startdate, EndDate = enddate, RepeatType = RepeatFrequency.Month, Comment = "Test", }; var rsts = CommonUtility.WorkoutRepeatedDatesWithAmount(new RepeatDatesWithAmountCalculationInput { StartDate = startdate, EndDate = enddate, TotalAmount = item.TranAmount, RepeatType = RepeatFrequency.Month, Desp = item.Desp, }); var tmpdocid = 1; foreach (var rst in rsts) { var tmpdoc = new FinanceTmpDPDocument { DocumentID = tmpdocid++, TranAmount = rst.TranAmount, TransactionDate = rst.TranDate, HomeID = hid, TransactionType = 5, ControlCenterID = item.ControlCenterID, OrderID = item.OrderID, Description = item.Desp }; dpcontext.AccountInfo.ExtraDP.DPTmpDocs.Add(tmpdoc); } var resp = await control.PostDPDocument(dpcontext); var doc = Assert.IsType <CreatedODataResult <FinanceDocument> >(resp).Entity; documentsCreated.Add(doc.ID); Assert.True(doc.Items.Count == 2); var dpacntid = -1; foreach (var did in doc.Items) { if (did.AccountID != account.ID) { dpacntid = did.AccountID; accountsCreated.Add(dpacntid); } } // 2. Switch to second controller var tmpcontrol = new FinanceTmpDPDocumentsController(context); tmpcontrol.ControllerContext = new ControllerContext() { HttpContext = httpctx }; var tmpdocs = tmpcontrol.Get(); Assert.NotEmpty(tmpdocs); Assert.Equal(rsts.Count, tmpdocs.Count()); var dpdocs = tmpdocs.Cast <FinanceTmpDPDocument>(); // 3. Create repay document foreach (var dpdoc in dpdocs) { var dppostcontext = new FinanceTmpDPDocumentPostContext() { DocumentID = dpdoc.DocumentID, AccountID = dpdoc.AccountID, HomeID = dpdoc.HomeID, }; var repaydocresp = await tmpcontrol.PostDocument(dppostcontext); var repaydoc = Assert.IsType <CreatedODataResult <FinanceDocument> >(repaydocresp); Assert.True(repaydoc.Entity.ID > 0); documentsCreated.Add(repaydoc.Entity.ID); // Check in the database var dpdocInDB = context.FinanceTmpDPDocument.Where(p => p.DocumentID == dpdoc.DocumentID).SingleOrDefault(); Assert.NotNull(dpdocInDB); Assert.NotNull(dpdocInDB.ReferenceDocumentID); } // Check the account status var account2 = context.FinanceAccount.Where(p => p.HomeID == hid && p.ID == dpacntid).FirstOrDefault(); Assert.True(account2.Status == (Byte)FinanceAccountStatus.Closed); CleanupCreatedEntries(); await context.DisposeAsync(); }
public async Task TestCase1(int hid, string user) { var context = this.fixture.GetCurrentDataContext(); // 0. Create control centers for other homes if (hid == DataSetupUtility.Home1ID) { fixture.InitHome1TestData(context); } if (hid == DataSetupUtility.Home2ID) { fixture.InitHome2TestData(context); } if (hid == DataSetupUtility.Home3ID) { fixture.InitHome3TestData(context); } if (hid == DataSetupUtility.Home4ID) { fixture.InitHome4TestData(context); } if (hid == DataSetupUtility.Home5ID) { fixture.InitHome5TestData(context); } var curhmemquery = (from homemem in context.HomeMembers where homemem.HomeID == hid && homemem.User == user select homemem).FirstOrDefault(); var curhmem = Assert.IsType <HomeMember>(curhmemquery); var existccamt = (from homemem in context.HomeMembers join fincc in context.FinanceControlCenter on new { homemem.HomeID, homemem.User } equals new { fincc.HomeID, User = user } select fincc.ID).ToList().Count(); var existccamt_curhome = context.FinanceControlCenter.Where(p => p.HomeID == hid).Count(); // 1. Create first control center var control = new FinanceControlCentersController(context); var userclaim = DataSetupUtility.GetClaimForUser(user); var httpctx = UnitTestUtility.GetDefaultHttpContext(provider, userclaim); control.ControllerContext = new ControllerContext() { HttpContext = httpctx }; var cc = new FinanceControlCenter() { HomeID = hid, Name = "Control Center 1", Comment = "Comment 1", Owner = DataSetupUtility.UserA }; var rst = await control.Post(cc); Assert.NotNull(rst); var rst2 = Assert.IsType <CreatedODataResult <FinanceControlCenter> >(rst); Assert.Equal(rst2.Entity.Name, cc.Name); Assert.Equal(rst2.Entity.HomeID, cc.HomeID); Assert.Equal(rst2.Entity.Owner, cc.Owner); var firstccid = rst2.Entity.ID; Assert.True(firstccid > 0); ccsCreated.Add(firstccid); // 2. Now read the whole control centers (without Home ID) var queryUrl = @"http://localhost/api/FinanceControlCenters"; var req = UnitTestUtility.GetHttpRequest(httpctx, "GET", queryUrl); var odatacontext = UnitTestUtility.GetODataQueryContext <FinanceControlCenter>(this.model); var options = UnitTestUtility.GetODataQueryOptions <FinanceControlCenter>(odatacontext, req); var rst3 = control.Get(options); Assert.NotNull(rst3); if (curhmem.IsChild.HasValue && curhmem.IsChild == true) { existccamt = context.FinanceControlCenter.Where(p => p.Owner == user).Count(); Assert.Equal(existccamt, rst3.Cast <FinanceControlCenter>().Count()); } else { Assert.Equal(1 + existccamt, rst3.Cast <FinanceControlCenter>().Count()); } // 2a. Now read the whole control centers (with Home ID) queryUrl = @"http://localhost/api/FinanceControlCenters?$filter=HomeID eq " + hid.ToString(); req = UnitTestUtility.GetHttpRequest(httpctx, "GET", queryUrl); //var odatacontext = UnitTestUtility.GetODataQueryContext<FinanceControlCenter>(this.model); options = UnitTestUtility.GetODataQueryOptions <FinanceControlCenter>(odatacontext, req); rst3 = control.Get(options); Assert.NotNull(rst3); if (curhmem.IsChild.HasValue && curhmem.IsChild == true) { existccamt_curhome = context.FinanceControlCenter.Where(p => p.HomeID == hid && p.Owner == user).Count(); Assert.Equal(existccamt_curhome, rst3.Cast <FinanceControlCenter>().Count()); } else { Assert.Equal(1 + existccamt_curhome, rst3.Cast <FinanceControlCenter>().Count()); } // 3. Now create another one! cc = new FinanceControlCenter() { HomeID = hid, Name = "Control Center 2", Comment = "Comment 2", ParentID = rst2.Entity.ID, Owner = DataSetupUtility.UserA }; rst = await control.Post(cc); Assert.NotNull(rst); rst2 = Assert.IsType <CreatedODataResult <FinanceControlCenter> >(rst); Assert.Equal(rst2.Entity.Name, cc.Name); Assert.Equal(rst2.Entity.HomeID, cc.HomeID); Assert.Equal(rst2.Entity.Owner, cc.Owner); var sndccid = rst2.Entity.ID; Assert.True(sndccid > 0); ccsCreated.Add(sndccid); // 4. Change one control center cc.Owner = DataSetupUtility.UserB; rst = await control.Put(sndccid, cc); Assert.NotNull(rst); var rst4 = Assert.IsType <UpdatedODataResult <FinanceControlCenter> >(rst); Assert.Equal(rst4.Entity.Name, cc.Name); Assert.Equal(rst4.Entity.HomeID, cc.HomeID); Assert.Equal(rst4.Entity.Owner, DataSetupUtility.UserB); // 5. Delete the second control center var rst5 = await control.Delete(sndccid); Assert.NotNull(rst5); var rst6 = Assert.IsType <StatusCodeResult>(rst5); Assert.Equal(204, rst6.StatusCode); // 6. Now read the whole control centers rst3 = control.Get(options); Assert.NotNull(rst3); if (curhmem.IsChild.HasValue && curhmem.IsChild == true) { existccamt_curhome = context.FinanceControlCenter.Where(p => p.HomeID == hid && p.Owner == user).Count(); Assert.Equal(existccamt_curhome, rst3.Cast <FinanceControlCenter>().Count()); } else { Assert.Equal(1 + existccamt_curhome, rst3.Cast <FinanceControlCenter>().Count()); } // 7. Delete the first control center rst5 = await control.Delete(firstccid); Assert.NotNull(rst5); rst6 = Assert.IsType <StatusCodeResult>(rst5); Assert.Equal(204, rst6.StatusCode); // 8. Now read the whole control centers rst3 = control.Get(options); Assert.NotNull(rst3); if (curhmem.IsChild.HasValue && curhmem.IsChild == true) { existccamt_curhome = context.FinanceControlCenter.Where(p => p.HomeID == hid && p.Owner == user).Count(); Assert.Equal(existccamt_curhome, rst3.Cast <FinanceControlCenter>().Count()); } else { Assert.Equal(existccamt_curhome, rst3.Cast <FinanceControlCenter>().Count()); } ccsCreated.Clear(); context.Dispose(); }
public async Task TestCase1(int hid, string currency, string user, Boolean islegacy) { List <int> documentsCreated = new List <int>(); var context = this.fixture.GetCurrentDataContext(); // 0. Prepare the context for current home if (hid == DataSetupUtility.Home1ID) { fixture.InitHome1TestData(context); } else if (hid == DataSetupUtility.Home2ID) { fixture.InitHome2TestData(context); } else if (hid == DataSetupUtility.Home3ID) { fixture.InitHome3TestData(context); } else if (hid == DataSetupUtility.Home4ID) { fixture.InitHome4TestData(context); } else if (hid == DataSetupUtility.Home5ID) { fixture.InitHome5TestData(context); } var account = context.FinanceAccount.Where(p => p.HomeID == hid && p.Status != (Byte)FinanceAccountStatus.Closed).FirstOrDefault(); var cc = context.FinanceControlCenter.Where(p => p.HomeID == hid).FirstOrDefault(); // var orders = context.FinanceOrder.Where(p => p.HomeID == hid).ToList(); // 1. Buy an asset var control = new FinanceDocumentsController(context); var userclaim = DataSetupUtility.GetClaimForUser(user); var httpctx = UnitTestUtility.GetDefaultHttpContext(provider, userclaim); control.ControllerContext = new ControllerContext() { HttpContext = httpctx }; // 1a. Prepare data var assetbuycontext = new FinanceAssetBuyDocumentCreateContext(); assetbuycontext.AccountOwner = user; assetbuycontext.ControlCenterID = cc.ID; assetbuycontext.Desp = "Test buy in"; // assetbuycontext.ExtraAsset = assetbuycontext.HID = hid; assetbuycontext.IsLegacy = islegacy; assetbuycontext.TranAmount = 2000; assetbuycontext.TranCurr = currency; assetbuycontext.TranDate = new DateTime(2020, 1, 1); assetbuycontext.Items = new List <FinanceDocumentItem>(); if (!islegacy) { var item2 = new FinanceDocumentItem() { ItemID = 1, Desp = "Item 1.1", TranType = 3, TranAmount = 2000, AccountID = account.ID, ControlCenterID = cc.ID, }; assetbuycontext.Items.Add(item2); } assetbuycontext.ExtraAsset = new FinanceAccountExtraAS(); assetbuycontext.ExtraAsset.Name = "Asset to buy"; assetbuycontext.ExtraAsset.CategoryID = context.FinAssetCategories.ToList()[0].ID; assetbuycontext.ExtraAsset.Comment = "Test 1"; var resp = await control.PostAssetBuyDocument(assetbuycontext); var doc = Assert.IsType <CreatedODataResult <FinanceDocument> >(resp).Entity; documentsCreated.Add(doc.ID); if (islegacy) { Assert.True(doc.Items.Count == 1); } else { Assert.True(doc.Items.Count == 2); } var assetacntid = 0; if (!islegacy) { foreach (var docitem in doc.Items) { if (docitem.AccountID != account.ID) { assetacntid = docitem.AccountID; var acnt = context.FinanceAccount.Find(docitem.AccountID); Assert.NotNull(acnt); var acntExtraAsset = context.FinanceAccountExtraAS.Find(docitem.AccountID); Assert.NotNull(acntExtraAsset); Assert.True(acntExtraAsset.RefenceBuyDocumentID == doc.ID); } } } else { // The return result has no account info. var acntExtraAsset = context.FinanceAccountExtraAS.First(p => p.RefenceBuyDocumentID == doc.ID); Assert.NotNull(acntExtraAsset); assetacntid = acntExtraAsset.AccountID; } // Now check in the databse for items var ditems = context.FinanceDocumentItem.Where(p => p.AccountID == assetacntid).ToList(); Assert.True(ditems.Count == 1); // Document item view var ditemview = (from diview in context.FinanceDocumentItemView where diview.AccountID == assetacntid select new { diview.AccountID, diview.Amount, diview.IsExpense } ).ToList(); Assert.True(ditemview.Count == 1); // Check the account group with expense var acntgrpexp = context.FinanceReporAccountGroupAndExpenseView.Where(p => p.AccountID == assetacntid).First(); Assert.NotNull(acntgrpexp); // Check the balance var assetbal = context.FinanceReporAccountGroupView.Where(p => p.AccountID == assetacntid).First(); Assert.NotNull(assetbal); Assert.Equal(2000, assetbal.Balance); // Okay, now sell it var assetsellcontext = new FinanceAssetSellDocumentCreateContext(); assetsellcontext.AssetAccountID = assetacntid; assetsellcontext.ControlCenterID = cc.ID; assetsellcontext.Desp = "Test sell"; assetsellcontext.HID = hid; assetsellcontext.TranAmount = 1000; assetsellcontext.TranCurr = currency; assetsellcontext.TranDate = new DateTime(2021, 1, 1); // Account which received the money assetsellcontext.Items = new List <FinanceDocumentItem>(); var item = new FinanceDocumentItem() { ItemID = 1, Desp = "Item 2.1", TranType = FinanceTransactionType.TranType_AssetSoldoutIncome, TranAmount = 1000, AccountID = account.ID, ControlCenterID = cc.ID, }; assetsellcontext.Items.Add(item); resp = await control.PostAssetSellDocument(assetsellcontext); doc = Assert.IsType <CreatedODataResult <FinanceDocument> >(resp).Entity; documentsCreated.Add(doc.ID); // Last, clear all created objects foreach (var docid in documentsCreated) { this.fixture.DeleteFinanceDocument(context, docid); } if (assetacntid > 0) { this.fixture.DeleteFinanceAccount(context, assetacntid); } await context.SaveChangesAsync(); await context.DisposeAsync(); }
public async Task TestController(int hid, string user) { var context = this.fixture.GetCurrentDataContext(); var control = new LearnObjectsController(context); var userclaim = DataSetupUtility.GetClaimForUser(user); control.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = userclaim } }; // 0. Initialize data if (hid == DataSetupUtility.Home1ID) { fixture.InitHome1TestData(context); } else if (hid == DataSetupUtility.Home2ID) { fixture.InitHome2TestData(context); } var existamt = context.LearnObjects.Where(p => p.HomeID == hid).Count(); var ctgid = context.LearnCategories.Where(p => p.HomeID == hid || p.HomeID == null).FirstOrDefault(); var objamt = (from homemem in context.HomeMembers join lobjs in context.LearnObjects on new { homemem.HomeID, homemem.User } equals new { lobjs.HomeID, User = user } select lobjs.ID).ToList().Count(); // 1. Insert new Object var obj = new LearnObject() { HomeID = hid, Name = "Test_LOBJ_1_UT_" + hid.ToString(), CategoryID = ctgid.ID, Content = "Content 1" }; var rst1 = await control.Post(obj); Assert.NotNull(rst1); var rst2 = Assert.IsType <CreatedODataResult <LearnObject> >(rst1); Assert.Equal(obj.Name, rst2.Entity.Name); var firstordid = rst2.Entity.ID; Assert.True(firstordid > 0); objectsCreated.Add(firstordid); // 2. Now read the whole accounts (no home ID applied) var queryUrl = "http://localhost/api/LearnObjects"; var httpctx = UnitTestUtility.GetDefaultHttpContext(provider, userclaim); control.ControllerContext = new ControllerContext() { HttpContext = httpctx }; var req = UnitTestUtility.GetHttpRequest(httpctx, "GET", queryUrl); var odatacontext = UnitTestUtility.GetODataQueryContext <LearnObject>(this.model); var options = UnitTestUtility.GetODataQueryOptions <LearnObject>(odatacontext, req); var rst3 = control.Get(options); Assert.NotNull(rst3); Assert.Equal(objamt + 1, rst3.Cast <LearnObject>().Count()); // 2a. Read the whole accounts (with home ID applied) queryUrl = "http://localhost/api/LearnObjects?$filter=HomeID eq " + hid.ToString(); req = UnitTestUtility.GetHttpRequest(httpctx, "GET", queryUrl); //var odatacontext = UnitTestUtility.GetODataQueryContext<FinanceAccount>(this.model); options = UnitTestUtility.GetODataQueryOptions <LearnObject>(odatacontext, req); rst3 = control.Get(options); existamt = context.LearnObjects.Where(p => p.HomeID == hid).Count(); Assert.NotNull(rst3); Assert.Equal(existamt, rst3.Cast <LearnObject>().Count()); // 3. Change the object's name obj.Name = "Test 2"; rst1 = await control.Put(firstordid, obj); var rst3a = Assert.IsType <UpdatedODataResult <LearnObject> >(rst1); Assert.Equal(obj.Name, rst3a.Entity.Name); // 4. Delete it var rst4 = await control.Delete(firstordid); Assert.NotNull(rst4); var rst6 = Assert.IsType <StatusCodeResult>(rst4); Assert.Equal(204, rst6.StatusCode); objectsCreated.Clear(); // 5. Read all object again existamt = context.LearnObjects.Where(p => p.HomeID == hid).Count(); var rst7 = control.Get(options); Assert.Equal(existamt, rst3.Cast <LearnObject>().Count()); await context.DisposeAsync(); }
public void TestModel(int hid, string curr, FinancePlanTypeEnum pty) { var context = this.fixture.GetCurrentDataContext(); if (hid == DataSetupUtility.Home1ID) { fixture.InitHome1TestData(context); } if (hid == DataSetupUtility.Home2ID) { fixture.InitHome2TestData(context); } if (hid == DataSetupUtility.Home3ID) { fixture.InitHome3TestData(context); } if (hid == DataSetupUtility.Home4ID) { fixture.InitHome4TestData(context); } if (hid == DataSetupUtility.Home5ID) { fixture.InitHome5TestData(context); } var plan = new FinancePlan(); Assert.False(plan.IsValid(context)); plan.HomeID = hid; Assert.False(plan.IsValid(context)); plan.TranCurr = curr; Assert.False(plan.IsValid(context)); plan.Description = "test"; Assert.False(plan.IsValid(context)); plan.StartDate = DateTime.Today; plan.TargetDate = DateTime.Today; Assert.False(plan.IsValid(context)); plan.TargetDate = DateTime.Today.AddDays(100); Assert.False(plan.IsValid(context)); plan.PlanType = pty; switch (pty) { case FinancePlanTypeEnum.Account: plan.AccountID = context.FinanceAccount.Where(p => p.HomeID == hid).FirstOrDefault().ID; Assert.True(plan.IsValid(context)); break; case FinancePlanTypeEnum.AccountCategory: plan.AccountCategoryID = context.FinAccountCategories.FirstOrDefault().ID; Assert.True(plan.IsValid(context)); break; case FinancePlanTypeEnum.ControlCenter: plan.ControlCenterID = context.FinanceControlCenter.Where(p => p.HomeID == hid).FirstOrDefault().ID; Assert.True(plan.IsValid(context)); break; case FinancePlanTypeEnum.TranType: plan.TranTypeID = context.FinTransactionType.FirstOrDefault().ID; Assert.True(plan.IsValid(context)); break; default: break; } }
public async Task TestCase1_InterestFree(int hid, string currency, string user, short doctype) { var context = this.fixture.GetCurrentDataContext(); // 0. Prepare the context for current home if (hid == DataSetupUtility.Home1ID) { fixture.InitHome1TestData(context); } else if (hid == DataSetupUtility.Home2ID) { fixture.InitHome2TestData(context); } else if (hid == DataSetupUtility.Home3ID) { fixture.InitHome3TestData(context); } else if (hid == DataSetupUtility.Home4ID) { fixture.InitHome4TestData(context); } else if (hid == DataSetupUtility.Home5ID) { fixture.InitHome5TestData(context); } var account = context.FinanceAccount.Where(p => p.HomeID == hid && p.Status != (Byte)FinanceAccountStatus.Closed).FirstOrDefault(); var cc = context.FinanceControlCenter.Where(p => p.HomeID == hid).FirstOrDefault(); // 1. Create first Loan docs. var control = new FinanceDocumentsController(context); var userclaim = DataSetupUtility.GetClaimForUser(user); var httpctx = UnitTestUtility.GetDefaultHttpContext(provider, userclaim); control.ControllerContext = new ControllerContext() { HttpContext = httpctx }; // 1a. Prepare data var dpcontext = new FinanceLoanDocumentCreateContext(); dpcontext.DocumentInfo = new FinanceDocument() { HomeID = hid, DocType = doctype, TranCurr = currency, Desp = "Test 1" }; var item = new FinanceDocumentItem() { DocumentHeader = dpcontext.DocumentInfo, ItemID = 1, Desp = "Item 1.1", TranType = doctype == FinanceDocumentType.DocType_BorrowFrom ? FinanceTransactionType.TranType_BorrowFrom : FinanceTransactionType.TranType_LendTo, TranAmount = 1200, AccountID = account.ID, ControlCenterID = cc.ID, }; dpcontext.DocumentInfo.Items.Add(item); dpcontext.AccountInfo = new FinanceAccount() { HomeID = hid, Name = "Account_8" + ".1", CategoryID = doctype == FinanceDocumentType.DocType_BorrowFrom ? FinanceAccountCategory.AccountCategory_BorrowFrom : FinanceAccountCategory.AccountCategory_LendTo, Owner = user, Status = (Byte)FinanceAccountStatus.Normal, }; var startdate = new DateTime(2020, 1, 10); var enddate = new DateTime(2021, 1, 10); dpcontext.AccountInfo.ExtraLoan = new FinanceAccountExtraLoan() { StartDate = startdate, EndDate = enddate, TotalMonths = 12, RepaymentMethod = LoanRepaymentMethod.EqualPrincipal, InterestFree = true, }; var rsts = CommonUtility.WorkoutRepeatedDatesWithAmountAndInterest(new RepeatDatesWithAmountAndInterestCalInput { RepaymentMethod = dpcontext.AccountInfo.ExtraLoan.RepaymentMethod.Value, InterestFreeLoan = dpcontext.AccountInfo.ExtraLoan.InterestFree.Value, StartDate = dpcontext.AccountInfo.ExtraLoan.StartDate, TotalAmount = 1200, EndDate = dpcontext.AccountInfo.ExtraLoan.EndDate, TotalMonths = dpcontext.AccountInfo.ExtraLoan.TotalMonths.Value, FirstRepayDate = new DateTime(2020, 2, 15) }); var tmpdocid = 1; foreach (var rst in rsts) { var tmpdoc = new FinanceTmpLoanDocument { DocumentID = tmpdocid++, TransactionAmount = rst.TranAmount, InterestAmount = rst.InterestAmount, TransactionDate = rst.TranDate, HomeID = hid, ControlCenterID = item.ControlCenterID, OrderID = item.OrderID, Description = item.Desp, }; dpcontext.AccountInfo.ExtraLoan.LoanTmpDocs.Add(tmpdoc); } var resp = await control.PostLoanDocument(dpcontext); var doc = Assert.IsType <CreatedODataResult <FinanceDocument> >(resp).Entity; documentsCreated.Add(doc.ID); var loanacntid = -1; foreach (var docitem in doc.Items) { if (docitem.AccountID != account.ID) { loanacntid = docitem.AccountID; accountsCreated.Add(loanacntid); } } Assert.True(doc.Items.Count == 2); // 2. Switch to second controller var tmpcontrol = new FinanceTmpLoanDocumentsController(context); tmpcontrol.ControllerContext = new ControllerContext() { HttpContext = httpctx }; var tmpdocs = tmpcontrol.Get(); Assert.NotEmpty(tmpdocs); Assert.Equal(rsts.Count, tmpdocs.Count()); var dpdocs = tmpdocs.Cast <FinanceTmpLoanDocument>(); // 3. Create repay document foreach (var dpdoc in dpdocs) { var contxt = new FinanceLoanRepayDocumentCreateContext(); contxt.HomeID = hid; contxt.LoanTemplateDocumentID = dpdoc.DocumentID; contxt.DocumentInfo = new FinanceDocument { DocType = FinanceDocumentType.DocType_Repay, HomeID = hid, Desp = dpdoc.Description, TranCurr = currency, }; contxt.DocumentInfo.Items.Add(new FinanceDocumentItem { ItemID = 1, AccountID = dpdoc.AccountID, TranAmount = dpdoc.TransactionAmount, ControlCenterID = dpdoc.ControlCenterID, OrderID = dpdoc.OrderID, TranType = doctype == FinanceDocumentType.DocType_BorrowFrom ? FinanceTransactionType.TranType_RepaymentIn : FinanceTransactionType.TranType_RepaymentOut, }); contxt.DocumentInfo.Items.Add(new FinanceDocumentItem { ItemID = 2, AccountID = account.ID, TranAmount = dpdoc.TransactionAmount, ControlCenterID = dpdoc.ControlCenterID, OrderID = dpdoc.OrderID, TranType = doctype == FinanceDocumentType.DocType_BorrowFrom ? FinanceTransactionType.TranType_RepaymentOut : FinanceTransactionType.TranType_RepaymentIn, }); var repaydocresp = await tmpcontrol.PostRepayDocument(contxt); var repaydoc = Assert.IsType <CreatedODataResult <FinanceDocument> >(repaydocresp); Assert.True(repaydoc.Entity.ID > 0); documentsCreated.Add(repaydoc.Entity.ID); // Check in the database var dpdocInDB = context.FinanceTmpLoanDocument.Where(p => p.DocumentID == dpdoc.DocumentID).SingleOrDefault(); Assert.NotNull(dpdocInDB); Assert.NotNull(dpdocInDB.ReferenceDocumentID); } // 4. Now the account shall be closed automatically var account2 = context.FinanceAccount.Where(p => p.HomeID == hid && p.ID == loanacntid).FirstOrDefault(); Assert.True(account2.Status == (Byte)FinanceAccountStatus.Closed); // Last, clear all created objects CleanupCreatedEntries(); await context.DisposeAsync(); }