Пример #1
0
 private IEnumerable <Booking> LoadScheduledBookings()
 {
     using (var context = new ExampleOrderIntegration.BookingContext())
     {
         return(context.Bookings
                .Where(x => x.ScheduleId != null)
                .Include(x => x.Parts)
                .AsNoTracking()
                .ToList());
     }
 }
Пример #2
0
        public SqliteBookingTest()
        {
            using (var context = new ExampleOrderIntegration.BookingContext())
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
            }

            initialBookings = new List <Booking>();
            initialSchParts = new List <ScheduledPartWithoutBooking>();
            initialCastings = new List <Casting>();

            using (var context = new ExampleOrderIntegration.BookingContext())
            {
                initialBookings.Add(new Booking
                {
                    BookingId  = "booking1",
                    Priority   = 100,
                    DueDate    = DateTime.Today.AddDays(5),
                    ScheduleId = null,
                    Parts      = new List <BookingDemand> {
                        new BookingDemand {
                            BookingId = "booking1", Part = "part1", Quantity = 44, CastingId = "abc"
                        },
                        new BookingDemand {
                            BookingId = "booking1", Part = "part2", Quantity = 66, CastingId = null
                        }
                    }
                });
                initialBookings.Add(new Booking
                {
                    BookingId  = "booking2",
                    Priority   = 200,
                    DueDate    = DateTime.Today.AddDays(15),
                    ScheduleId = null,
                    Parts      = new List <BookingDemand> {
                        new BookingDemand {
                            BookingId = "booking2", Part = "part1", Quantity = 55, CastingId = "xyz"
                        },
                        new BookingDemand {
                            BookingId = "booking2", Part = "part2", Quantity = 77, CastingId = "jjj"
                        }
                    }
                });
                initialBookings.Add(new Booking
                {
                    BookingId  = "booking3",
                    Priority   = 300,
                    DueDate    = DateTime.Today.AddDays(30),
                    ScheduleId = null,
                    Parts      = new List <BookingDemand> {
                        new BookingDemand {
                            BookingId = "booking3", Part = "part1", Quantity = 111, CastingId = "abc"
                        },
                        new BookingDemand {
                            BookingId = "booking3", Part = "part3", Quantity = 222, CastingId = "zzz"
                        }
                    }
                });

                foreach (var b in initialBookings)
                {
                    context.Bookings.Add(b);
                }

                initialSchParts.Add(new ScheduledPartWithoutBooking
                {
                    Part     = "part1",
                    Quantity = 1
                });
                initialSchParts.Add(new ScheduledPartWithoutBooking
                {
                    Part     = "part3",
                    Quantity = 4
                });

                foreach (var p in initialSchParts)
                {
                    context.ExtraParts.Add(p);
                }

                initialCastings.Add(new Casting {
                    CastingId = "abc", Quantity = 15
                });
                initialCastings.Add(new Casting {
                    CastingId = "xyz", Quantity = 10
                });
                initialCastings.Add(new Casting {
                    CastingId = "jjj", Quantity = 0
                });
                initialCastings.Add(new Casting {
                    CastingId = "zzz", Quantity = 177
                });

                foreach (var c in initialCastings)
                {
                    context.Castings.Add(c);
                }

                context.SaveChanges();
            }
        }
Пример #3
0
        public void CreateSchedule()
        {
            var booking = new ExampleOrderIntegration.ExampleBookingDatabase();

            var schParts = new ScheduledPartWithoutBooking[] {
                new ScheduledPartWithoutBooking {
                    Part = "part1", Quantity = 12
                },
                new ScheduledPartWithoutBooking {
                    Part = "part2", Quantity = 52
                },
                new ScheduledPartWithoutBooking {
                    Part = "part4", Quantity = 9876
                }
            };

            var downParts = new DownloadedPart[] {
                new DownloadedPart {
                    ScheduleId = "12345", Part = "part1", Quantity = 155
                },
                new DownloadedPart {
                    ScheduleId = "12345", Part = "part2", Quantity = 166
                }
            };

            booking.CreateSchedule(
                new NewSchedule
            {
                ScheduleId       = "12345",
                ScheduledTimeUTC = new DateTime(2016, 11, 05),
                ScheduledHorizon = TimeSpan.FromMinutes(155),
                BookingIds       = new List <string> {
                    "booking1", "booking2"
                },
                DownloadedParts = downParts.ToList(),
                ScheduledParts  = schParts.ToList()
            });

            using (var ctx = new ExampleOrderIntegration.BookingContext())
            {
                Assert.Equal(
                    ctx.Bookings.Single(b => b.BookingId == "booking1").ScheduleId,
                    "12345"
                    );
                Assert.Equal(
                    ctx.Bookings.Single(b => b.BookingId == "booking1").ScheduleId,
                    "12345"
                    );

                ctx.ExtraParts.ToList().ShouldAllBeEquivalentTo(schParts);
            }

            //check status
            var status = booking.LoadUnscheduledStatus(50);

            status.ScheduledParts.ShouldAllBeEquivalentTo(schParts);
            status.UnscheduledBookings.ShouldAllBeEquivalentTo(
                new Booking[] { initialBookings[2] }
                );
            Assert.Null(status.LatestBackoutId);

            initialBookings[0].ScheduleId = "12345";
            initialBookings[1].ScheduleId = "12345";

            LoadScheduledBookings().ShouldAllBeEquivalentTo(
                new Booking[] { initialBookings[0], initialBookings[1] }
                );
        }