-
Notifications
You must be signed in to change notification settings - Fork 42
Creating Test Data
Hong edited this page Mar 17, 2020
·
3 revisions
To load data into the database navigate to the helpers/DevelopmentDatabaseSetup.cs
folder.
Inside the InitialiseTestDataObject()
method you can instantiate different entities.
Once you instantiate an entity, to store it in the database get the database context and call the following methods:
_database.Add(<Entity Name>);
_database.SaveChanges();
example to instantiate a user:
_bryan = new User
{
UserName = "BeboBryan",
FirstName = "Bryan",
LastName = "Ang",
DateOfBirth = new DateTime(1984, 02, 09),
PhoneNumber = "02243926392",
Email = "BryanAng@Gmail.com",
MedicalInformation = "Dementia, Lactose Intolerant",
BankAccount = "98-7654-3211234-210"
};
_bryan.HashedPassword = hasher.HashPassword(_bryan, "password");
example to instantiate a payment:
_payment1 = new Payment
{
Id = 1,
PaymentType = PaymentType.Electricity,
Amount = 175,
Fixed = false,
Frequency = Frequency.Monthly,
StartDate = new DateTime(2020, 03, 07),
EndDate = new DateTime(2020, 06, 07),
Description = "electricity"
};
A UserPayment class must be created to define the many to many relationships.
Create UserPayment class and link the Payment entity with the User entity.
_userPaymentBryan1 = new UserPayment
{
Payment = _payment1,
User = _bryan,
UserId = _bryan.Id,
PaymentId = _payment1.Id
};
Then add the UserPayment object to both the Payment entity and the User entity.
- To add more users to payments create more UserPayment objects to link the payment and user and add it to the UserPayments lists in each User and Payment object as shown below.
_payment1.UserPayments = new List<UserPayment> { _userPaymentBryan1}
_bryan.UserPayments = new List<UserPayment> { _userPaymentBryan1}
example to add a Schedule
_schedule1 = new Schedule
{
UserName = "BeboBryan",
ScheduleType = ScheduleType.Away,
StartDate = new DateTime(2020, 04, 01),
EndDate = new DateTime(2020, 05, 01)
};
_flat1 = new Flat
{
Id = 1,
Address = "50 Symonds Street",
Users = new List<User> { _bryan },
Schedules = new List<Schedule> { _schedule1 },
Payments = new List<Payment> { _payment2 }
};
- Home
- Data Model
- Architecture
- API Documentation
- Front End Documentation
- Testing
- Prototyping
- Other
- Contributing Guidelines and Etiquitte
- Labels
- License
- Admin