Beispiel #1
0
        public void RepositoryUpdateMethodByVenueTest()
        {
            // arange
            var venueRepository  = new VenueRepositoryEF(_context);
            var layoutRepository = new TMLayoutRepositoryEF(_context);
            var areaRepository   = new AreaRepositoryEF(_context);
            var seatRepository   = new SeatRepositoryEF(_context);

            // act
            Venue venue = venueRepository.Create(
                new Venue {
                Description = "some v desc", Address = "some address", Lenght = 2, Weidth = 2, Phone = "some phone"
            });
            TMLayout layout = layoutRepository.Create(
                new TMLayout {
                Description = "some desc", VenueId = venue.Id
            });
            Area area = areaRepository.Create(
                new Area {
                Description = "area1", CoordX = 0, CoordY = 0, TMLayoutId = layout.Id
            });
            Seat seat = seatRepository.Create(
                new Seat {
                Number = 1, Row = 1, AreaId = area.Id
            });

            venue.Description  = "new v desc";
            layout.Description = "new desc";
            area.Description   = "new desc";
            seat.Number       += 1;

            venueRepository.Update(venue);
            layoutRepository.Update(layout);
            areaRepository.Update(area);
            seatRepository.Update(seat);

            // assert
            venue.Should().BeEquivalentTo(venueRepository.GetById(venue.Id));
            layout.Should().BeEquivalentTo(layoutRepository.GetById(layout.Id));
            area.Should().BeEquivalentTo(areaRepository.GetById(area.Id));
            seat.Should().BeEquivalentTo(seatRepository.GetById(seat.Id));

            seatRepository.Remove(seat);
            areaRepository.Remove(area);
            layoutRepository.Remove(layout);
            venueRepository.Remove(venue.Id);
        }
        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);
        }