private Person CreateSamplePerson() { var newPerson = new Person { Salutation = "", FirstName = "Jane", MiddleName = "Anne", LastName = "TestLastName", Suffix = "", DateOfBirth = new DateTime(1943, 2, 5), HairColorId = 1, EyeColorId = 1 }; var creditTypeRepo = new CreditTypeRepository(); var creditTypes = creditTypeRepo.Fetch(null).ToList(); var showRepo = new ShowRepository(); var shows = showRepo.Fetch(null).ToList(); Credit crd1 = new Credit { ShowId = shows[0].Id, CreditTypeId = creditTypes[0].Id, Character = "Henry" }; newPerson.Credits.Add(crd1); return(newPerson); }
public CreditTypesView() { InitializeComponent(); var repo = new CreditTypeRepository(); DataContext = new DomainViewModel <CreditType>(repo); }
public void CreditTypeRepository_FetchNull_ReturnsAll() { // Arrange var repo = new CreditTypeRepository(); var list = repo.Fetch(); Assert.IsNotNull(list); Assert.IsTrue(list.Any()); }
public void Initialize() { _showRepo = new ShowRepository(); _ratingRepo = new MpaaRatingRepository(); _creditTypeRepo = new CreditTypeRepository(); _personRepo = new PersonRepository(); _ratings = _ratingRepo.Fetch().ToList(); _creditTypes = _creditTypeRepo.Fetch().ToList(); _shows = _showRepo.Fetch().ToList(); }
public void Initialize() { _showRepo = new ShowRepository(); _genreRepo = new GenreRepository(); _creditTypeRepo = new CreditTypeRepository(); _personRepo = new PersonRepository(); _genres = _genreRepo.Fetch().ToList(); _creditTypes = _creditTypeRepo.Fetch().ToList(); _people = _personRepo.Fetch().ToList(); }
public void CreditTypeRepository_FetchOne_ReturnsData() { // Arrange var repo = new CreditTypeRepository(); // Act var results = repo.Fetch(3); // Assert Assert.IsTrue(results != null); Assert.IsTrue(results.Any()); Assert.IsTrue(results.Count() == 1); Assert.IsTrue(results.Single().CreditTypeId == 3); }
public void CreditTypeRepository_FetchAll_ReturnsData() { // Arrange var repo = new CreditTypeRepository(); // Act var results = repo.Fetch(); // Assert Assert.IsTrue(results != null); Assert.IsTrue(results.Any()); Assert.IsTrue(results.Count() == 5); Assert.IsTrue(results.ToList()[4].Name == "Writer"); }
public void CreditTypeRepository_InsertUpdateDelete_Works() { // Arrange var repo = new CreditTypeRepository(); var testItem = new CreditType { Name = "TestItem", Code = "TestItemCode", IsInactive = true, DisplayOrder = 99 }; // Act - Insert var insertedItem = repo.Persist(testItem); var newId = insertedItem.CreditTypeId; // Assert for Insert Assert.IsTrue(newId > 0); var existingItem = repo.Fetch(newId).Single(); Assert.IsTrue(existingItem.Name == "TestItem"); Assert.IsTrue(existingItem.Code == "TestItemCode"); Assert.IsTrue(existingItem.IsInactive == true); Assert.IsTrue(existingItem.DisplayOrder == 99); // Act - Update existingItem.Name = "TestItem1"; existingItem.Code = "TestItemCode1"; existingItem.IsInactive = false; existingItem.DisplayOrder = 10; repo.Persist(existingItem); // Assert for Update var updatedItem = repo.Fetch(newId).Single(); Assert.IsTrue(updatedItem.Name == "TestItem1"); Assert.IsTrue(updatedItem.Code == "TestItemCode1"); Assert.IsTrue(updatedItem.IsInactive == false); Assert.IsTrue(updatedItem.DisplayOrder == 10); // Act - Delete updatedItem.IsMarkedForDeletion = true; var deletedItem = repo.Persist(updatedItem); // Assert for Delete Assert.IsNull(deletedItem); var emptyResult = repo.Fetch(newId); Assert.IsFalse(emptyResult.Any()); }
public void CreditTypeRepository_Delete_Deletes() { // Arrange var repo = new CreditTypeRepository(); var existingItem = repo.Fetch(3).Single(); // Act existingItem.IsMarkedForDeletion = true; var deletedItem = repo.Persist(existingItem); // Assert for Delete Assert.IsNull(deletedItem); var emptyResult = repo.Fetch(3); Assert.IsFalse(emptyResult.Any()); }
public void CreditTypeRepository_FetchOne_ReturnsOne() { // Arrange var repo = new CreditTypeRepository(); var all = repo.Fetch(null).ToList(); var creditTypeId = all[0].Id; var name = all[0].Name; var item = repo.Fetch(creditTypeId).Single(); Assert.IsNotNull(item); Assert.IsTrue(item.Id == creditTypeId); Assert.IsTrue(item.Name == name); Assert.IsFalse(item.IsMarkedForDeletion); Assert.IsFalse(item.IsDirty); }
public void CreditTypeRepository_InsertUpdateDelete() { // Arrange var repo = new CreditTypeRepository(); var newItem = new CreditType { Code = "TestCode", Name = "TestName", IsInactive = false, DisplayOrder = 99 }; var item = repo.Persist(newItem); var newId = item.Id; // Act for Update item.Name = "XYZ"; item.Code = "ABC"; item.IsInactive = true; item.DisplayOrder = 999; item.IsDirty = true; var updatedItem = repo.Persist(item); Assert.IsTrue(updatedItem.IsDirty == false); Assert.IsTrue(updatedItem.Name == "XYZ"); Assert.IsTrue(updatedItem.Code == "ABC"); Assert.IsTrue(updatedItem.IsInactive); Assert.IsTrue(updatedItem.DisplayOrder == 999); // Assert for Update var refetch = repo.Fetch(newId).First(); Assert.IsTrue(refetch.Name == "XYZ"); // Clean-up (Act for Delete) item.IsMarkedForDeletion = true; repo.Persist(item); // Assert for Delete var result = repo.Fetch(newId); Assert.IsFalse(result.Any()); }
public void CreditTypeRepository_InsertDelete() { // Arrange var repo = new CreditTypeRepository(); var newItem = new CreditType { Code = "TestCode", Name = "TestName", IsInactive = false, DisplayOrder = 99 }; // Act for Insert var item = repo.Persist(newItem); var newId = item.Id; // Assert for Insert - Make sure local object is updated Assert.IsTrue(item.Id > 0); Assert.IsFalse(item.IsMarkedForDeletion); Assert.IsFalse(item.IsDirty); // Assert for Insert - Make sure refetched object is correct var refetch = repo.Fetch(newId).First(); Assert.IsTrue(refetch.Id == newId); Assert.IsFalse(refetch.IsMarkedForDeletion); Assert.IsFalse(refetch.IsDirty); Assert.IsTrue(refetch.Code == "TestCode"); Assert.IsTrue(refetch.Name == "TestName"); Assert.IsTrue(refetch.IsInactive == false); Assert.IsTrue(refetch.DisplayOrder == 99); // Clean-up (Act for Delete) item.IsMarkedForDeletion = true; repo.Persist(item); // Assert for Delete var result = repo.Fetch(newId); Assert.IsFalse(result.Any()); }
public void PersonRepository_CreditDirty_SetsGraphDirty() { // Arrange var repo = new PersonRepository(); var all = repo.Fetch(null).ToList(); var personId = all[0].PersonId; var fullName = all[0].FullName; var item = repo.Fetch(personId).Single(); // Add one Credit to change a leaf // of the object graph var creditTypeRepository = new CreditTypeRepository(); var ct = creditTypeRepository.Fetch().First(); var showRepository = new ShowRepository(); var s = showRepository.Fetch().First(); var c = new Credit() { CreditTypeId = ct.CreditTypeId, ShowId = s.ShowId }; item.Credits.Add(c); Assert.IsNotNull(item); Assert.IsTrue(item.PersonId == personId); Assert.IsTrue(item.FullName == fullName); Assert.IsFalse(item.IsMarkedForDeletion); // The IsDirty flag should be false Assert.IsFalse(item.IsDirty); // The HasChanges property should // be true, indicating the change to ShowGenres Assert.IsTrue(item.IsGraphDirty); }
private Person CreateSamplePerson() { var newPerson = new Person { Salutation = "", FirstName = "Jane", MiddleName = "Anne", LastName = "TestLastName", Suffix = "", StageName = "", Weight = 120.5, DateOfBirth = new DateTime(1943, 2, 5), HairColorId = 1, EyeColorId = 1 }; var creditTypeRepo = new CreditTypeRepository(); var creditTypes = creditTypeRepo.Fetch(null).ToList(); var showRepo = new ShowRepository(); var shows = showRepo.Fetch(null).ToList(); Credit crd1 = new Credit { ShowId = shows[0].ShowId, CreditTypeId = creditTypes[0].CreditTypeId, Character = "Henry" }; newPerson.Credits.Add(crd1); return newPerson; }
public static void FillDb() { using (var context = new BankDbContext()) { Console.WriteLine("ConnectionString\n" + context.Database.Connection.ConnectionString); Console.WriteLine("DataSource\n" + context.Database.Connection.DataSource); Console.WriteLine("ConnectionString\n" + context.Database.Connection.Database); // CLEARS ALL DATA !!! Console.WriteLine("ALL DATA WILL BE DELETED FROM DB NOW!!! ([ENTER] TO PROCEED)"); Console.ReadLine(); //if (!context.Database.Exists()) //{ context.Database.Delete(); context.Database.Create(); //} context.Database.Initialize(true);// Console.WriteLine("Db initialized"); Console.ReadLine(); context.Accounts.RemoveRange(context.Accounts); ///Console.WriteLine("I've successfully completed first db action!"); ///Console.ReadLine(); context.Clients.RemoveRange(context.Clients); context.Credits.RemoveRange(context.Credits); context.CreditTypes.RemoveRange(context.CreditTypes); context.Payments.RemoveRange(context.Payments); context.Requests.RemoveRange(context.Requests); //context.RequestStatuses.RemoveRange(context.RequestStatuses); context.Users.RemoveRange(context.Users); context.SaveChanges(); // CLEARS ALL DATA !!! //var statusRepo = new RequestStatusRepository(context); //var statusCreated = new RequestStatus { Status = "Created" }; //var statusConfirmedByOperator = new RequestStatus { Status = "statusConfirmedByOperator" }; //var statusConfirmedBySse = new RequestStatus { Status = "statusConfirmedBySecurityServiceEmployee" }; ////var statusConfirmed = new RequestStatus { Status = "ConfirmedBy" }; //var statusCreditProvided = new RequestStatus { Status = "statusCreditProvided" }; //var statusDenied = new RequestStatus { Status = "Denied" }; //statusRepo.Add(statusCreated, statusConfirmedByOperator, statusConfirmedByOperator, statusCreditProvided,statusDenied); // context.SaveChanges(); // var confirmedByOperatorStatusId = statusCreditProvided.RequestStatusId; // var createdStatusId = statusCreated.RequestStatusId; // var deinedStatusId = statusDenied.RequestStatusId; var creditShort = new CreditType { Name = "Easy Money", //Type = "" WTF IS TYPE????? TimeMonths = 12, PercentPerYear = 20.0m, Currency = "USD", FinePercent = 40.0m, MinAmount = 200, MaxAmount = 2000, IsAvailable = true }; var creditMedium = new CreditType { Name = "Not So Easy Money", //Type = "" WTF IS TYPE????? TimeMonths = 12 * 2, PercentPerYear = 25.0m, Currency = "USD", FinePercent = 50.0m, MinAmount = 200, MaxAmount = 5000, IsAvailable = true }; var creditLong = new CreditType { Name = "Still Money", //Type = "" WTF IS TYPE????? TimeMonths = 12 * 4, PercentPerYear = 30.0m, Currency = "USD", FinePercent = 60.0m, MinAmount = 200, MaxAmount = 5000, IsAvailable = true }; var creditTypeRepo = new CreditTypeRepository(context); creditTypeRepo.Add(creditShort, creditLong, creditMedium); context.SaveChanges(); var creditEasyId = creditShort.CreditTypeId; var creditMediumId = creditMedium.CreditTypeId; var creditLongId = creditLong.CreditTypeId; var admin = new User { Login = "******", Password = "******", Role = UserRole.Admin, IsActive = true }; var ss = new User // security service employee { Login = "******", Password = "******", Role = UserRole.SecurityServiceEmployee, IsActive = true }; var operator1 = new User // { Login = "******", Password = "******", Role = UserRole.Operator, IsActive = true }; var operator2 = new User // { Login = "******", Password = "******", Role = UserRole.Operator, IsActive = true }; var client1 = new User { Login = "******", Password = "******", Role = UserRole.Client }; var client2 = new User { Login = "******", Password = "******", Role = UserRole.Client }; var client3 = new User { Login = "******", Password = "******", Role = UserRole.Client }; var userRepo = new UserRepository(context); userRepo.Add(admin, ss, operator1, operator2, client1, client2, client3); context.SaveChanges(); var client1Id = client1.UserId; var client2Id = client2.UserId; var client3Id = client3.UserId; var client1Info = new Client { UserId = client1.UserId, Name = "Clientone", LastName = "Clientov", Patronymic = "Clientovich", Birthday = new DateTime(1990, 1, 1), Mobile = "+375441234567", Email = "*****@*****.**", PassportNo = "AB1234567", PassportIdentificationNo = "4123456B124PB7", PassportAuthority = "Ministry of internal affairs", PassportExpirationDate = DateTime.Now.AddYears(6), PlaceOfResidence = "Pushkina st.1 app.18", RegistrationAddress = "Pushkina st.1 app.18" }; var client2Info = new Client { UserId = client2.UserId, Name = "Clienttwo", LastName = "Clientov", Patronymic = "Clientovich", Birthday = new DateTime(1982, 2, 2), Mobile = "+375251234567", Email = "*****@*****.**", PassportNo = "AB1234123", PassportIdentificationNo = "4125552B124PB7", PassportAuthority = "Ministry of internal affairs", PassportExpirationDate = DateTime.Now.AddYears(1), PlaceOfResidence = "Pushkina st.2 app.7", RegistrationAddress = "Pushkina st.2 app.7" }; var client3Info = new Client { UserId = client3.UserId, Name = "Clientthree", LastName = "Clientov", Patronymic = "Clientovich", Birthday = new DateTime(1973, 3, 3), Mobile = "+375291234567", Email = "*****@*****.**", PassportNo = "AB1223331", PassportIdentificationNo = "4129332B124PB3", PassportAuthority = "Ministry of internal affairs", PassportExpirationDate = DateTime.Now.AddYears(6), PlaceOfResidence = "Pushkina st.3 app.24", RegistrationAddress = "Pushkina st.3 app.24" }; var clientRepo = new ClientRepository(context); clientRepo.Add(client1Info, client2Info, client3Info); context.SaveChanges(); var request1client1 = new Request { ClientId = client1Info.ClientId, //RequestStatusId = createdStatusId, Status = RequestStatus.Created, CreditTypeId = creditEasyId, AmountOfCredit = 1000, Salary = 500 }; var request2client1 = new Request { ClientId = client1Info.ClientId, //RequestStatusId = createdStatusId, Status = RequestStatus.Created, OperatorId = operator1.UserId, CreditTypeId = creditMediumId, AmountOfCredit = 1200, Salary = 500 }; var request3client1 = new Request { ClientId = client1Info.ClientId, //RequestStatusId = confirmedByOperatorStatusId, Status = RequestStatus.ConfirmedByOperator, OperatorId = operator1.UserId, CreditTypeId = creditLongId, AmountOfCredit = 1000, Salary = 500 }; var request4client1 = new Request { ClientId = client1Info.ClientId, Status = RequestStatus.ConfirmedByOperator, // createdStatusId, OperatorId = operator1.UserId, CreditTypeId = creditMediumId, AmountOfCredit = 1100, Salary = 500 }; var request5client1 = new Request { ClientId = client1Info.ClientId, //RequestStatusId = createdStatusId, Status = RequestStatus.CreditProvided, OperatorId = operator1.UserId, CreditTypeId = creditLongId, AmountOfCredit = 1300, Salary = 500 }; var request6client1 = new Request { ClientId = client1Info.ClientId, //RequestStatusId = confirmedByOperatorStatusId, Status = RequestStatus.CreditProvided, OperatorId = operator1.UserId, CreditTypeId = creditLongId, AmountOfCredit = 900, Salary = 500 }; var request7client1 = new Request { ClientId = client1Info.ClientId, Status = RequestStatus.ConfirmedBySecurityOfficer, // createdStatusId, OperatorId = operator1.UserId, CreditTypeId = creditLongId, AmountOfCredit = 800, Salary = 500 }; var request8client1 = new Request { ClientId = client1Info.ClientId, //RequestStatusId = confirmedByOperatorStatusId, Status = RequestStatus.CreditProvided, OperatorId = operator1.UserId, CreditTypeId = creditMediumId, AmountOfCredit = 900, Salary = 500 }; var requestRepo = new RequestRepository(context); requestRepo.Add( request1client1, request2client1, request3client1, request4client1, request5client1, request6client1, request7client1, request8client1); context.SaveChanges(); //var acc1 = new Account //Bank Account //{ // ClientId = null, // Balance = 40*1000*1000 //}; var bankAccount = new BankAccount //Bank Account { Balance = 40 * 1000 * 1000, Currency = "USD" }; context.BankAccount = bankAccount; context.SaveChanges(); var acc2 = new Account { ClientId = client1Info.ClientId, Balance = request2client1.AmountOfCredit }; var accountRepo = new AccountRepository(context); accountRepo.Add(/*acc1,*/ acc2); context.SaveChanges(); DateTime dt1 = DateTime.Now.AddDays(-(30 * 4 + 5)); var credit1Client1 = new Credit { AccountId = acc2.AccountId, CreditTypeId = creditLong.CreditTypeId, //ContractNo = 123123, //random RequestId = request5client1.RequestId, //AllreadyPaid = 0, AmountOfPaymentPerMonth = (request5client1.AmountOfCredit / creditLong.TimeMonths) * (1 + creditLong.PercentPerYear / 100 * creditLong.TimeMonths / 12), StartDate = dt1, IsRepaid = false, HasDelays = false, CountFineFromThisDate = dt1.AddDays(30),//DateTime.UtcNow.AddDays(30), //!!! hard-coded!!! AmountToCountFineFromForFirstDelayedMonth = (request5client1.AmountOfCredit / creditLong.TimeMonths) * (1 + creditLong.PercentPerYear / 100 * creditLong.TimeMonths / 12), PaidForFine = 0 }; DateTime dt2 = DateTime.UtcNow.AddDays(-(30 * 50 + 7)); var credit2Client1 = new Credit { AccountId = acc2.AccountId, CreditTypeId = creditLong.CreditTypeId, //ContractNo = 123123, //random RequestId = request6client1.RequestId, //AllreadyPaid = 0, AmountOfPaymentPerMonth = (request6client1.AmountOfCredit / creditLong.TimeMonths) * (1 + creditLong.PercentPerYear / 100 * creditLong.TimeMonths / 12), StartDate = dt2, IsRepaid = true, HasDelays = true, CountFineFromThisDate = dt2.AddDays(30), //!!! hard-coded!!! AmountToCountFineFromForFirstDelayedMonth = (request6client1.AmountOfCredit / creditLong.TimeMonths) * (1 + creditLong.PercentPerYear / 100 * creditLong.TimeMonths / 12), PaidForFine = 0 }; var credit3Client1 = new Credit { AccountId = acc2.AccountId, CreditTypeId = creditMedium.CreditTypeId, //ContractNo = 123123, //random RequestId = request8client1.RequestId, //AllreadyPaid = 0, AmountOfPaymentPerMonth = (request8client1.AmountOfCredit / creditMedium.TimeMonths) * (1 + creditMedium.PercentPerYear / 100 * creditMedium.TimeMonths / 12), StartDate = DateTime.Now, IsRepaid = false, HasDelays = true, CountFineFromThisDate = DateTime.Now.AddDays(30), //!!! hard-coded!!! AmountToCountFineFromForFirstDelayedMonth = (request8client1.AmountOfCredit / creditMedium.TimeMonths) * (1 + creditMedium.PercentPerYear / 100 * creditMedium.TimeMonths / 12), PaidForFine = 0 }; request5client1.Credit = credit1Client1; // IMPORTANT do this for 1-1 relationship (exception otherwise) request6client1.Credit = credit2Client1; // IMPORTANT do this for 1-1 relationship (exception otherwise) request8client1.Credit = credit3Client1; // IMPORTANT do this for 1-1 relationship (exception otherwise) var creditRepo = new CreditRepository(context); creditRepo.Add(credit1Client1, credit2Client1, credit3Client1); context.SaveChanges(); /* var payment = new Payment * { * OperatorId = operator1.UserId, * CreditId = credit1Client1.CreditId, * //ContractNo = credit1Client1.ContractNo, * Amount = 75, * Date = credit1Client1.StartDate.AddDays(15) * }; * //var credit * * var payRepo = new PaymentRepository(context); * payRepo.Add(payment); */ var test = context.BankAccount; //context.RequestStatuses.Where(x => x.Status.Contains("Created")).FirstOrDefault(); //context.RequestStatuses.Add(new RequestStatus { Status = "Created" }); context.SaveChanges(); } }
public void CreditTypeRepository_Insert_Insertss() { // Arrange var repo = new CreditTypeRepository(); var testItem = new CreditType { Name = "TestItem", Code = "TestItemCode", IsInactive = true, DisplayOrder = 99 }; // Act var insertedItem = repo.Persist(testItem); var newId = insertedItem.CreditTypeId; // Assert Assert.IsTrue(newId > 0); var existingItem = repo.Fetch(newId).Single(); Assert.IsTrue(existingItem.Name == "TestItem"); Assert.IsTrue(existingItem.Code == "TestItemCode"); Assert.IsTrue(existingItem.IsInactive == true); Assert.IsTrue(existingItem.DisplayOrder == 99); }
public static void FillDb() { using (var context = new BankDbContext()) { Console.WriteLine("ConnectionString\n" + context.Database.Connection.ConnectionString); Console.WriteLine("DataSource\n" + context.Database.Connection.DataSource); Console.WriteLine("ConnectionString\n" + context.Database.Connection.Database); // CLEARS ALL DATA !!! Console.WriteLine("ALL DATA WILL BE DELETED FROM DB NOW!!! ([ENTER] TO PROCEED)"); Console.ReadLine(); //if (!context.Database.Exists()) //{ context.Database.Delete(); context.Database.Create(); //} context.Database.Initialize(true);// Console.WriteLine("Db initialized"); Console.ReadLine(); context.Accounts.RemoveRange(context.Accounts); ///Console.WriteLine("I've successfully completed first db action!"); ///Console.ReadLine(); context.Clients.RemoveRange(context.Clients); context.Credits.RemoveRange(context.Credits); context.CreditTypes.RemoveRange(context.CreditTypes); context.Payments.RemoveRange(context.Payments); context.Requests.RemoveRange(context.Requests); //context.RequestStatuses.RemoveRange(context.RequestStatuses); context.Users.RemoveRange(context.Users); context.SaveChanges(); // CLEARS ALL DATA !!! //var statusRepo = new RequestStatusRepository(context); //var statusCreated = new RequestStatus { Status = "Created" }; //var statusConfirmedByOperator = new RequestStatus { Status = "statusConfirmedByOperator" }; //var statusConfirmedBySse = new RequestStatus { Status = "statusConfirmedBySecurityServiceEmployee" }; ////var statusConfirmed = new RequestStatus { Status = "ConfirmedBy" }; //var statusCreditProvided = new RequestStatus { Status = "statusCreditProvided" }; //var statusDenied = new RequestStatus { Status = "Denied" }; //statusRepo.Add(statusCreated, statusConfirmedByOperator, statusConfirmedByOperator, statusCreditProvided,statusDenied); // context.SaveChanges(); // var confirmedByOperatorStatusId = statusCreditProvided.RequestStatusId; // var createdStatusId = statusCreated.RequestStatusId; // var deinedStatusId = statusDenied.RequestStatusId; var creditShort = new CreditType { Name = "Easy Money", //Type = "" WTF IS TYPE????? TimeMonths = 12, PercentPerYear = 20.0m, Currency = "USD", FinePercent = 40.0m, MinAmount = 200, MaxAmount = 2000, IsAvailable = true }; var creditMedium = new CreditType { Name = "Not So Easy Money", //Type = "" WTF IS TYPE????? TimeMonths = 12 * 2, PercentPerYear = 25.0m, Currency = "USD", FinePercent = 50.0m, MinAmount = 200, MaxAmount = 5000, IsAvailable = true }; var creditLong = new CreditType { Name = "Still Money", //Type = "" WTF IS TYPE????? TimeMonths = 12 * 4, PercentPerYear = 30.0m, Currency = "USD", FinePercent = 60.0m, MinAmount = 200, MaxAmount = 5000, IsAvailable = true }; var creditTypeRepo = new CreditTypeRepository(context); creditTypeRepo.Add(creditShort, creditLong, creditMedium); context.SaveChanges(); var creditEasyId = creditShort.CreditTypeId; var creditMediumId = creditMedium.CreditTypeId; var creditLongId = creditLong.CreditTypeId; var admin = new User { Login = "******", Password = "******", Role = UserRole.Admin, IsActive = true }; var ss = new User // security service employee { Login = "******", Password = "******", Role = UserRole.SecurityServiceEmployee, IsActive = true }; var operator1 = new User // { Login = "******", Password = "******", Role = UserRole.Operator, IsActive = true }; var operator2 = new User // { Login = "******", Password = "******", Role = UserRole.Operator, IsActive = true }; var client1 = new User { Login = "******", Password = "******", Role = UserRole.Client }; var client2 = new User { Login = "******", Password = "******", Role = UserRole.Client }; var client3 = new User { Login = "******", Password = "******", Role = UserRole.Client }; var userRepo = new UserRepository(context); userRepo.Add(admin, ss, operator1, operator2, client1, client2, client3); context.SaveChanges(); var client1Id = client1.UserId; var client2Id = client2.UserId; var client3Id = client3.UserId; var client1Info = new Client { UserId = client1.UserId, Name = "Clientone", LastName = "Clientov", Patronymic = "Clientovich", Birthday = new DateTime(1990, 1, 1), Mobile = "+375441234567", Email = "*****@*****.**", PassportNo = "AB1234567", PassportIdentificationNo = "4123456B124PB7", PassportAuthority = "Ministry of internal affairs", PassportExpirationDate = DateTime.Now.AddYears(6), PlaceOfResidence = "Pushkina st.1 app.18", RegistrationAddress = "Pushkina st.1 app.18" }; var client2Info = new Client { UserId = client2.UserId, Name = "Clienttwo", LastName = "Clientov", Patronymic = "Clientovich", Birthday = new DateTime(1982, 2, 2), Mobile = "+375251234567", Email = "*****@*****.**", PassportNo = "AB1234123", PassportIdentificationNo = "4125552B124PB7", PassportAuthority = "Ministry of internal affairs", PassportExpirationDate = DateTime.Now.AddYears(1), PlaceOfResidence = "Pushkina st.2 app.7", RegistrationAddress = "Pushkina st.2 app.7" }; var client3Info = new Client { UserId = client3.UserId, Name = "Clientthree", LastName = "Clientov", Patronymic = "Clientovich", Birthday = new DateTime(1973, 3, 3), Mobile = "+375291234567", Email = "*****@*****.**", PassportNo = "AB1223331", PassportIdentificationNo = "4129332B124PB3", PassportAuthority = "Ministry of internal affairs", PassportExpirationDate = DateTime.Now.AddYears(6), PlaceOfResidence = "Pushkina st.3 app.24", RegistrationAddress = "Pushkina st.3 app.24" }; var clientRepo = new ClientRepository(context); clientRepo.Add(client1Info, client2Info, client3Info); context.SaveChanges(); var request1client1 = new Request { ClientId = client1Info.ClientId, //RequestStatusId = createdStatusId, Status = RequestStatus.Created, CreditTypeId = creditEasyId, AmountOfCredit = 1000, Salary = 500 }; var request2client1 = new Request { ClientId = client1Info.ClientId, //RequestStatusId = createdStatusId, Status = RequestStatus.Created, OperatorId = operator1.UserId, CreditTypeId = creditMediumId, AmountOfCredit = 1200, Salary = 500 }; var request3client1 = new Request { ClientId = client1Info.ClientId, //RequestStatusId = confirmedByOperatorStatusId, Status = RequestStatus.ConfirmedByOperator, OperatorId = operator1.UserId, CreditTypeId = creditLongId, AmountOfCredit = 1000, Salary = 500 }; var request4client1 = new Request { ClientId = client1Info.ClientId, Status = RequestStatus.ConfirmedByOperator, // createdStatusId, OperatorId = operator1.UserId, CreditTypeId = creditMediumId, AmountOfCredit = 1100, Salary = 500 }; var request5client1 = new Request { ClientId = client1Info.ClientId, //RequestStatusId = createdStatusId, Status = RequestStatus.CreditProvided, OperatorId = operator1.UserId, CreditTypeId = creditLongId, AmountOfCredit = 1300, Salary = 500 }; var request6client1 = new Request { ClientId = client1Info.ClientId, //RequestStatusId = confirmedByOperatorStatusId, Status = RequestStatus.CreditProvided, OperatorId = operator1.UserId, CreditTypeId = creditLongId, AmountOfCredit = 900, Salary = 500 }; var request7client1 = new Request { ClientId = client1Info.ClientId, Status = RequestStatus.ConfirmedBySecurityOfficer, // createdStatusId, OperatorId = operator1.UserId, CreditTypeId = creditLongId, AmountOfCredit = 800, Salary = 500 }; var request8client1 = new Request { ClientId = client1Info.ClientId, //RequestStatusId = confirmedByOperatorStatusId, Status = RequestStatus.CreditProvided, OperatorId = operator1.UserId, CreditTypeId = creditMediumId, AmountOfCredit = 900, Salary = 500 }; var requestRepo = new RequestRepository(context); requestRepo.Add( request1client1, request2client1, request3client1, request4client1, request5client1, request6client1, request7client1, request8client1); context.SaveChanges(); //var acc1 = new Account //Bank Account //{ // ClientId = null, // Balance = 40*1000*1000 //}; var bankAccount = new BankAccount //Bank Account { Balance = 40 * 1000 * 1000, Currency = "USD" }; context.BankAccount = bankAccount; context.SaveChanges(); var acc2 = new Account { ClientId = client1Info.ClientId, Balance = request2client1.AmountOfCredit }; var accountRepo = new AccountRepository(context); accountRepo.Add( /*acc1,*/ acc2); context.SaveChanges(); DateTime dt1 = DateTime.Now.AddDays(-(30 * 4 + 5)); var credit1Client1 = new Credit { AccountId = acc2.AccountId, CreditTypeId = creditLong.CreditTypeId, //ContractNo = 123123, //random RequestId = request5client1.RequestId, //AllreadyPaid = 0, AmountOfPaymentPerMonth = (request5client1.AmountOfCredit / creditLong.TimeMonths) * (1 + creditLong.PercentPerYear / 100 * creditLong.TimeMonths / 12), StartDate = dt1, IsRepaid = false, HasDelays = false, CountFineFromThisDate = dt1.AddDays(30),//DateTime.UtcNow.AddDays(30), //!!! hard-coded!!! AmountToCountFineFromForFirstDelayedMonth = (request5client1.AmountOfCredit / creditLong.TimeMonths) * (1 + creditLong.PercentPerYear / 100 * creditLong.TimeMonths / 12), PaidForFine = 0 }; DateTime dt2 = DateTime.UtcNow.AddDays(-(30 * 50 + 7)); var credit2Client1 = new Credit { AccountId = acc2.AccountId, CreditTypeId = creditLong.CreditTypeId, //ContractNo = 123123, //random RequestId = request6client1.RequestId, //AllreadyPaid = 0, AmountOfPaymentPerMonth = (request6client1.AmountOfCredit / creditLong.TimeMonths) * (1 + creditLong.PercentPerYear / 100 * creditLong.TimeMonths/12), StartDate = dt2, IsRepaid = true, HasDelays = true, CountFineFromThisDate = dt2.AddDays(30), //!!! hard-coded!!! AmountToCountFineFromForFirstDelayedMonth = (request6client1.AmountOfCredit / creditLong.TimeMonths) * (1 + creditLong.PercentPerYear / 100 * creditLong.TimeMonths / 12), PaidForFine = 0 }; var credit3Client1 = new Credit { AccountId = acc2.AccountId, CreditTypeId = creditMedium.CreditTypeId, //ContractNo = 123123, //random RequestId = request8client1.RequestId, //AllreadyPaid = 0, AmountOfPaymentPerMonth = (request8client1.AmountOfCredit / creditMedium.TimeMonths) * (1 + creditMedium.PercentPerYear / 100 * creditMedium.TimeMonths / 12), StartDate = DateTime.Now, IsRepaid = false, HasDelays = true, CountFineFromThisDate = DateTime.Now.AddDays(30), //!!! hard-coded!!! AmountToCountFineFromForFirstDelayedMonth = (request8client1.AmountOfCredit / creditMedium.TimeMonths) * (1 + creditMedium.PercentPerYear / 100 * creditMedium.TimeMonths / 12), PaidForFine = 0 }; request5client1.Credit = credit1Client1; // IMPORTANT do this for 1-1 relationship (exception otherwise) request6client1.Credit = credit2Client1; // IMPORTANT do this for 1-1 relationship (exception otherwise) request8client1.Credit = credit3Client1; // IMPORTANT do this for 1-1 relationship (exception otherwise) var creditRepo = new CreditRepository(context); creditRepo.Add(credit1Client1, credit2Client1, credit3Client1); context.SaveChanges(); /* var payment = new Payment { OperatorId = operator1.UserId, CreditId = credit1Client1.CreditId, //ContractNo = credit1Client1.ContractNo, Amount = 75, Date = credit1Client1.StartDate.AddDays(15) }; //var credit var payRepo = new PaymentRepository(context); payRepo.Add(payment); */ var test = context.BankAccount; //context.RequestStatuses.Where(x => x.Status.Contains("Created")).FirstOrDefault(); //context.RequestStatuses.Add(new RequestStatus { Status = "Created" }); context.SaveChanges(); } }
public void CreditTypeRepository_Update_Updates() { // Arrange var repo = new CreditTypeRepository(); var existingItem = repo.Fetch(2).Single(); // Act - Update existingItem.Name = "TestItem1"; existingItem.Code = "TestItemCode1"; existingItem.IsInactive = false; existingItem.DisplayOrder = 10; repo.Persist(existingItem); // Assert for Update var updatedItem = repo.Fetch(2).Single(); Assert.IsTrue(updatedItem.Name == "TestItem1"); Assert.IsTrue(updatedItem.Code == "TestItemCode1"); Assert.IsTrue(updatedItem.IsInactive == false); Assert.IsTrue(updatedItem.DisplayOrder == 10); }