protected virtual async Task ProvideTestData(ParkSharkDbContext context) { await context.Divisions.AddAsync(new Division("First", "First", "Mr Test")); await context.SaveChangesAsync(); await context.Divisions.AddAsync(new Division("Second", "Second", "Mr Test2")); await context.SaveChangesAsync(); await context.Set <BuildingType>().AddAsync(new BuildingType(nameof(BuildingTypes.Underground))); await context.SaveChangesAsync(); await context.Set <BuildingType>().AddAsync(new BuildingType(nameof(BuildingTypes.Aboveground))); await context.SaveChangesAsync(); await context.Set <MemberShipLevel>().AddAsync(new MemberShipLevel(MemberShipLevel.Level.Bronze, 0, 0, 240)); await context.Set <MemberShipLevel>().AddAsync(new MemberShipLevel(MemberShipLevel.Level.Silver, 10, 20, 360)); await context.Set <MemberShipLevel>().AddAsync(new MemberShipLevel(MemberShipLevel.Level.Gold, 40, 30, 1440)); await context.SaveChangesAsync(); }
public void GivenGetAllParkingLots_WhenRequestingAllParkingLots_ThenReturnListOfAllParkingLots() { using (var context = new ParkSharkDbContext(CreateNewInMemoryDatabase())) { var city = City.CreateCity(2050, "Antwerpen", "Belgium"); var parkingLot1 = ParkingLotBuilder.CreateNewParkingLot() .WithName("test") .WithAddress(Address.CreateAddress("Parkinglotstraat", "20a", city)) .WithContactPerson(ContactPerson.CreateNewContactPerson("Bas", "Adriaans", Address.CreateAddress("Contactpersoonstraat", "30", city), "*****@*****.**", "000000", "")) .WithCapacity(20) .WithDivision(Guid.NewGuid()) .WithPricePerHour(4.5m) .Build(); var parkingLot2 = ParkingLotBuilder.CreateNewParkingLot() .WithName("test2") .WithAddress(Address.CreateAddress("Parkinglotstraat", "20a", city)) .WithContactPerson(ContactPerson.CreateNewContactPerson("Bas", "Adriaans", Address.CreateAddress("Contactpersoonstraat", "30", city), "*****@*****.**", "000000", "")) .WithCapacity(20) .WithDivision(Guid.NewGuid()) .WithPricePerHour(4.5m) .Build(); context.Set <ParkingLot>().Add(parkingLot1); context.Set <ParkingLot>().Add(parkingLot2); context.SaveChanges(); var service = new ParkingLotService(context); var result = context.ParkingLots.CountAsync(); Assert.Equal(2, result.Result); } }
private MembershipLevel AssignMembershipLevelFromDummyMember(DummyMemberObject dummyMember) { return(_parkSharkDBContext //Usage of Set for entities you don't want to expose, good job! .Set <MembershipLevel>() .FirstOrDefault(x => x.MemberShipLevelId == dummyMember.MembershipLevel)); }
public async Task <IEnumerable <Member> > GetAllMembers() { return(await context.Set <Member>() .Include(m => m.Contact) .Include(m => m.RelatedMemberShipLevel) .AsNoTracking() .ToListAsync()); }
public void GivenGetAllDivisions_WhenRequestingAllDivisions_ThenReturnListOfAllDivisions() { using (var context = new ParkSharkDbContext(CreateNewInMemoryDatabase())) { context.Set <Division>().Add(Division.CreateNewDivision("test", "testorg", "lars")); context.Set <Division>().Add(Division.CreateNewDivision("test2", "testorg2", "lars")); context.SaveChanges(); var divisionService = new DivisionService(context); var result = divisionService.GetAllDivisions().Count; Assert.Equal(2, result); } }
public void GivenGetSingleParkingLot_WhenRequestingSingleParkingLot_ReturnRequestedParkingLot() { using (var context = new ParkSharkDbContext(CreateNewInMemoryDatabase())) { var city = City.CreateCity(2050, "Antwerpen", "Belgium"); var service = new ParkingLotService(context); var parkingLot = ParkingLotBuilder.CreateNewParkingLot() .WithName("test") .WithAddress(Address.CreateAddress("Parkinglotstraat", "20a", city)) .WithContactPerson(ContactPerson.CreateNewContactPerson("Bas", "Adriaans", Address.CreateAddress("Contactpersoonstraat", "30", city), "*****@*****.**", "000000", "")) .WithCapacity(20) .WithDivision(Guid.NewGuid()) .WithPricePerHour(4.5m) .Build(); context.Set <ParkingLot>().Add(parkingLot); var id = parkingLot.ParkingLotID; context.SaveChanges(); var result = service.GetSingleParkingLot(id); Assert.IsType <ParkingLot>(result); Assert.Equal(id, result.ParkingLotID); Assert.Equal("test", result.Name); } }
public void GivenGetAllMembers_WhenRequestingAllMembers_ThenReturnListOfAllMembers() { using (var context = new ParkSharkDbContext(CreateNewInMemoryDatabase())) { var memberShipLevel = new MembershipLevel(); var city = City.CreateCity(2050, "Antwerpen", "Belgium"); context.Set <Member>().Add(Member.CreateMember("lars", "Peelman", Address.CreateAddress("test", "5", city), MembershipLevelEnum.Bronze, memberShipLevel)); context.Set <Member>().Add(Member.CreateMember("laeeers", "ee", Address.CreateAddress("test", "5", city), MembershipLevelEnum.Bronze, memberShipLevel)); context.SaveChanges(); var service = new MemberService(context); var result = service.GetAllMembers().Count; Assert.Equal(2, result); } }
public List <ParkingLot> GetAllParkingLots() { var parkingLotList = new List <ParkingLot>(); var ParkingLotDbSet = _context.Set <ParkingLot>() .Include(pl => pl.Address) .ThenInclude(a => a.City) .Include(a => a.ContactPerson) .ThenInclude(c => c.Address) .ThenInclude(c => c.City) .Include(pl => pl.Division); foreach (var member in ParkingLotDbSet) { parkingLotList.Add(member); } return(parkingLotList); }
public void GivenGetSingledivisionUnHappyPath_WhenRequestingSingleDivision_ReturnNull() { using (var context = new ParkSharkDbContext(CreateNewInMemoryDatabase())) { var divisionService = new DivisionService(context); var division = Division.CreateNewDivision("test", "testorg", "lars"); context.Set <Division>().Add(division); var fakeID = Guid.NewGuid(); context.SaveChanges(); var result = divisionService.GetSingleDivision(fakeID); Assert.Null(result); } }
public void GivenGetSingleMemberUnHappyPath_WhenRequestingSingleMember_ReturnNull() { using (var context = new ParkSharkDbContext(CreateNewInMemoryDatabase())) { var service = new MemberService(context); var memberShipLevel = new MembershipLevel(); var city = City.CreateCity(2050, "Antwerpen", "Belgium"); var member = Member.CreateMember("lars", "Peelman", Address.CreateAddress("test", "5", city), MembershipLevelEnum.Gold, memberShipLevel); context.Set <Member>().Add(member); context.SaveChanges(); var fakeID = Guid.NewGuid(); var result = service.GetMember(fakeID); Assert.Null(result); } }
public void GivenGetSingledivision_WhenRequestingSingleDivision_ReturnRequestedDivision() { using (var context = new ParkSharkDbContext(CreateNewInMemoryDatabase())) { var divisionService = new DivisionService(context); var division = Division.CreateNewDivision("test", "testorg", "lars"); context.Set <Division>().Add(division); var divsionID = division.DivisionID; context.SaveChanges(); var result = divisionService.GetSingleDivision(divsionID); Assert.IsType <Division>(result); Assert.Equal(divsionID, result.DivisionID); Assert.Equal("test", result.Name); Assert.Equal("testorg", result.OriginalName); } }
public void GivenGetSingleMember_WhenRequestingSingleMember_ReturnRequestedMember() { using (var context = new ParkSharkDbContext(CreateNewInMemoryDatabase())) { var service = new MemberService(context); var memberShipLevel = new MembershipLevel(); var city = City.CreateCity(2050, "Antwerpen", "Belgium"); var member = Member.CreateMember("lars", "Peelman", Address.CreateAddress("test", "5", city), MembershipLevelEnum.Gold, memberShipLevel); context.Set <Member>().Add(member); context.SaveChanges(); var id = member.MemberId; var result = service.GetMember(id); Assert.IsType <Member>(result); Assert.Equal(id, result.MemberId); Assert.Equal("lars", result.FirstName); Assert.Equal("Peelman", result.LastName); } }
public void GivenHappyPath2_WhenAddingNewMemberToDb_ObjectIsAddedToDb() { using (var context = new ParkSharkDbContext(CreateNewInMemoryDatabase())) { context.Set <MembershipLevel>().Add(new MembershipLevel() { MemberShipLevelId = 0, Name = "Bronze", MonthlyCost = 0, PSAPriceReductionPercentage = 0, PSAMaxTimeInHours = new TimeSpan(4, 0, 0) }); context.SaveChanges(); var city = City.CreateCity(2050, "Antwerpen", "Belgium"); var member = new DummyMemberObject() { FirstName = "lars", LastName = "Peelman", Address = Address.CreateAddress("test", "5", city), MembershipLevel = MembershipLevelEnum.Bronze }; var service = new MemberService(context); var result = service.CreateNewMember(member); Assert.Single(service.GetAllMembers()); } }
private MembershipLevel AssignMembershipLevelFromDummyMember(DummyMemberObject dummyMember) { return(_parkSharkDBContext .Set <MembershipLevel>() .FirstOrDefault(x => x.MemberShipLevelId == dummyMember.MembershipLevel)); }
private static void PurgeDbAndAddTestDataFromFile(ParkSharkDbContext context) { List <Division> divisions = null; List <BuildingType> buildingTypes = null; List <ParkingLot> parkingLots = null; List <MemberShipLevel> memberShipLevels = null; List <Member> members = null; using (StreamReader reader = new StreamReader(@"testdata.json")) { string json = reader.ReadToEnd(); var testData = JsonConvert.DeserializeObject <TestData>(json); divisions = testData.Divisions; buildingTypes = testData.BuildingTypes; parkingLots = testData.ParkingLots; memberShipLevels = testData.MemberShipLevels; members = testData.Members; } context.Divisions.RemoveRange(context.Divisions); context.Set <BuildingType>().RemoveRange(context.Set <BuildingType>()); context.Contacts.RemoveRange(context.Contacts); context.ParkingLots.RemoveRange(context.ParkingLots); context.Set <MemberShipLevel>().RemoveRange(context.Set <MemberShipLevel>()); context.Members.RemoveRange(context.Members); context.SaveChanges(); ReseedIdentity(context, "Divisions"); ReseedIdentity(context, "BuildingTypes"); ReseedIdentity(context, "Contacts"); ReseedIdentity(context, "ParkingLots"); ReseedIdentity(context, "Members"); if (divisions != null) { foreach (var division in divisions.OrderBy(d => d.Name)) { context.Divisions.Add(division); context.SaveChanges(); } } if (buildingTypes != null) { foreach (var buildingType in buildingTypes) { context.Set <BuildingType>().Add(buildingType); context.SaveChanges(); } } if (parkingLots != null) { foreach (var parkingLot in parkingLots.OrderBy(p => p.Name)) { context.ParkingLots.Add(parkingLot); context.SaveChanges(); } } if (memberShipLevels != null) { foreach (var memberShipLevel in memberShipLevels.OrderBy(p => (int)p.Name)) { context.Set <MemberShipLevel>().Add(memberShipLevel); context.SaveChanges(); } } if (members != null) { foreach (var member in members.OrderBy(p => p.Contact.Name)) { context.Members.Add(member); context.SaveChanges(); } } }