public void CreateEventTest() { // arange var venueRepository = new VenueRepositoryEF(_context); var layoutRepository = new TMLayoutRepositoryEF(_context); var areaRepository = new AreaRepositoryEF(_context); var seatRepository = new SeatRepositoryEF(_context); var eventRepository = new TMEventRepositoryEF(_context); var eventAreaRepository = new TMEventAreaRepositoryEF(_context); var eventSeatRepository = new TMEventSeatRepositoryEF(_context); Venue venue = venueRepository.Create( new Venue { Description = "some v desc2", Address = "some address2", Lenght = 5, Weidth = 5 }); TMLayout layout = layoutRepository.Create(new TMLayout { Description = "some desc2", VenueId = venue.Id }); List <Area> areas = new List <Area>(); areas.Add(areaRepository.Create( new Area { Description = "area12", CoordX = 0, CoordY = 0, TMLayoutId = layout.Id })); areas.Add(areaRepository.Create( new Area { Description = "area22", CoordX = 0, CoordY = 1, TMLayoutId = layout.Id })); List <Seat> seats = new List <Seat>(); for (int i = 1; i < venue.Lenght + 1; i++) { areas.ForEach(a => seats.Add(seatRepository.Create(new Seat { Number = i, Row = 1, AreaId = a.Id }))); } // act TMEvent tmevent = eventRepository.Create( new TMEvent { Name = "big event22", Description = "some event desc22", TMLayoutId = layout.Id, StartEvent = DateTime.Now.Date.AddDays(3), EndEvent = DateTime.Now.Date.AddDays(4), }); List <TMEventArea> tmeventareas = eventAreaRepository.GetAll().Where(a => a.TMEventId == tmevent.Id).ToList(); List <TMEventSeat> tmeventseats = eventSeatRepository.GetAll(). Where(s => tmeventareas.Any(a => a.Id == s.TMEventAreaId)).ToList(); TMEvent tmeventFromDB = eventRepository.GetById(tmevent.Id); eventRepository.Remove(tmevent.Id); // delete tested data seats.ForEach(s => seatRepository.Remove(s.Id)); areas.ForEach(a => areaRepository.Remove(a.Id)); layoutRepository.Remove(layout.Id); venueRepository.Remove(venue.Id); // assert tmevent.Should().BeEquivalentTo(tmeventFromDB); areas.ToList().Count.Should().Be(tmeventareas.Count); tmeventareas.ForEach(ta => ta.Id = 0); areas.ForEach(ta => ta.Id = 0); tmeventareas.Should().BeEquivalentTo(areas, options => options.ExcludingMissingMembers()); seats.Count.Should().Be(tmeventseats.Count); tmeventseats.ForEach(ta => ta.Id = 0); seats.ForEach(ta => ta.Id = 0); tmeventseats.Should().BeEquivalentTo(seats, options => options.ExcludingMissingMembers()); }
public void UpdateEventLocalFieldsTest() { // arange var venueRepository = new VenueRepositoryEF(_context); var layoutRepository = new TMLayoutRepositoryEF(_context); var areaRepository = new AreaRepositoryEF(_context); var seatRepository = new SeatRepositoryEF(_context); var eventRepository = new TMEventRepositoryEF(_context); Venue venue = venueRepository.Create( new Venue { Description = "some v desc2", Address = "some address2", Lenght = 5, Weidth = 5 }); TMLayout layout = layoutRepository.Create(new TMLayout { Description = "some desc2", VenueId = venue.Id }); List <Area> areas = new List <Area>(); areas.Add(areaRepository.Create( new Area { Description = "area12", CoordX = 0, CoordY = 0, TMLayoutId = layout.Id })); areas.Add(areaRepository.Create( new Area { Description = "area22", CoordX = 0, CoordY = 1, TMLayoutId = layout.Id })); List <Seat> seats = new List <Seat>(); for (int i = 1; i < venue.Lenght + 1; i++) { areas.ForEach(a => seats.Add(seatRepository.Create(new Seat { Number = i, Row = 1, AreaId = a.Id }))); } TMEvent tmevent = eventRepository.Create( new TMEvent { Name = "big event22", Description = "some event desc22", TMLayoutId = layout.Id, StartEvent = DateTime.Now.Date.AddDays(3), EndEvent = DateTime.Now.Date.AddDays(4), }); // was some second create // act tmevent.Description = "new desc"; tmevent.StartEvent = DateTime.Now.Date.AddDays(5); tmevent.EndEvent = DateTime.Now.Date.AddDays(6); eventRepository.Update(tmevent); TMEvent tmeventFromDB = eventRepository.GetById(tmevent.Id); // delete tested data seats.ForEach(s => seatRepository.Remove(s.Id)); areas.ForEach(a => areaRepository.Remove(a.Id)); eventRepository.Remove(tmevent.Id); layoutRepository.Remove(layout.Id); venueRepository.Remove(venue.Id); // assert tmevent.Should().BeEquivalentTo(tmeventFromDB); }