コード例 #1
0
        public void CreateSchedule()
        {
            var booking = new BlackMaple.CSVOrders.CSVBookings();

            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()
            });

            //check status
            booking.LoadScheduledParts().Should().BeEquivalentTo(schParts);
            booking.LoadUnscheduledBookings(50).Values.Should().BeEquivalentTo(
                new Booking[] { initialBookings[2] }
                );
            Assert.Null(booking.LoadLatestBackoutId());

            var sch1 = File.ReadAllLines("scheduled-bookings/booking1.csv");
            var sch2 = File.ReadAllLines("scheduled-bookings/booking2.csv");

            sch1.Should().BeEquivalentTo(new string[] {
                "ScheduledTimeUTC,Part,Quantity,ScheduleId",
                "2016-11-05T00:00:00Z,part1,44,12345",
                "2016-11-05T00:00:00Z,part2,66,12345"
            });
            sch2.Should().BeEquivalentTo(new string[] {
                "ScheduledTimeUTC,Part,Quantity,ScheduleId",
                "2016-11-05T00:00:00Z,part1,55,12345",
                "2016-11-05T00:00:00Z,part2,77,12345"
            });
        }
コード例 #2
0
        public void BackOutOfWork()
        {
            var booking = new BlackMaple.CSVOrders.CSVBookings();

            booking.HandleBackedOutWork(new Backout()
            {
                BackoutId = 667788,
                Parts     = new List <BackedOutPart> {
                    new BackedOutPart
                    {
                        Part     = "abc",
                        Quantity = 23
                    },
                    new BackedOutPart
                    {
                        Part     = "def",
                        Quantity = 193
                    }
                }
            });

            var bookingId = "Reschedule-abc-" + DateTime.UtcNow.ToString("yyy-MM-ddTHH-mm-ssZ");

            initialBookings.Add(new Booking
            {
                BookingId = bookingId,
                DueDate   = DateTime.Today,
                Priority  = 100,
                Parts     = new List <BookingDemand> {
                    new BookingDemand
                    {
                        BookingId = bookingId,
                        Part      = "abc",
                        Quantity  = 23,
                    }
                }
            });

            bookingId = "Reschedule-def-" + DateTime.UtcNow.ToString("yyy-MM-ddTHH-mm-ssZ");
            initialBookings.Add(new Booking
            {
                BookingId = bookingId,
                DueDate   = DateTime.Today,
                Priority  = 100,
                Parts     = new List <BookingDemand> {
                    new BookingDemand
                    {
                        BookingId = bookingId,
                        Part      = "def",
                        Quantity  = 193,
                    }
                }
            });

            booking.LoadScheduledParts().Should().BeEquivalentTo(initialSchParts);
            booking.LoadUnscheduledBookings(null).Values.Should().BeEquivalentTo(initialBookings);
            Assert.Equal(667788, booking.LoadLatestBackoutId());
        }
コード例 #3
0
        public void LoadUnscheduledStatus()
        {
            var booking = new BlackMaple.CSVOrders.CSVBookings();

            booking.LoadScheduledParts().Should().BeEquivalentTo(initialSchParts);
            booking.LoadUnscheduledBookings(50).Values.Should().BeEquivalentTo(initialBookings);
            Assert.Null(booking.LoadLatestBackoutId());

            booking.LoadUnscheduledBookings(10).Values.Should().BeEquivalentTo(
                new[] { initialBookings[0] }
                );

            booking.LoadUnscheduledBookings(null).Values.Should().BeEquivalentTo(initialBookings);
        }
コード例 #4
0
        public void RecoverBadFileCopy()
        {
            File.WriteAllLines("scheduled-parts-temp-abc.csv", new string[] {
                "Part,Quantity",
                "mypart,12",
                "otherpart,17"
            });

            var booking = new BlackMaple.CSVOrders.CSVBookings();

            booking.LoadScheduledParts().Should().BeEquivalentTo(new ScheduledPartWithoutBooking[] {
                new ScheduledPartWithoutBooking {
                    Part = "mypart", Quantity = 12
                },
                new ScheduledPartWithoutBooking {
                    Part = "otherpart", Quantity = 17
                }
            });
            booking.LoadUnscheduledBookings(null).Values.Should().BeEquivalentTo(initialBookings);
            Assert.Null(booking.LoadLatestBackoutId());
        }
コード例 #5
0
        public void MissingIdColumn()
        {
            // only works with bookings which have only a single part
            initialBookings.Clear();
            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
                    },
                }
            });
            initialBookings.Add(new Booking
            {
                BookingId  = "booking2",
                Priority   = 200,
                DueDate    = DateTime.Today.AddDays(15),
                ScheduleId = null,
                Parts      = new List <BookingDemand> {
                    new BookingDemand {
                        BookingId = "booking2", Part = "part2", Quantity = 77
                    }
                }
            });
            initialBookings.Add(new Booking
            {
                BookingId  = "booking3",
                Priority   = 300,
                DueDate    = DateTime.Today.AddDays(30),
                ScheduleId = null,
                Parts      = new List <BookingDemand> {
                    new BookingDemand {
                        BookingId = "booking3", Part = "part3", Quantity = 222
                    }
                }
            });

            using (var f = File.Open("bookings.csv", FileMode.Create))
            {
                using (var s = new StreamWriter(f))
                {
                    s.WriteLine("DueDate,Priority,Part,Quantity");
                    foreach (var b in initialBookings)
                    {
                        foreach (var p in b.Parts)
                        {
                            s.WriteLine(
                                b.DueDate.ToString("yyyy-MM-dd") + ","
                                + b.Priority.ToString() + ","
                                + p.Part + "," + p.Quantity.ToString());
                        }
                    }
                }
            }

            var now    = new DateTime(2019, 04, 23, 1, 2, 3, DateTimeKind.Utc);
            var nowStr = now.ToString("yyyy-MM-dd-HH-mm-ss");


            initialBookings[0].BookingId          = "B" + nowStr + "-0";
            initialBookings[0].Parts[0].BookingId = "B" + nowStr + "-0";
            initialBookings[1].BookingId          = "B" + nowStr + "-1";
            initialBookings[1].Parts[0].BookingId = "B" + nowStr + "-1";
            initialBookings[2].BookingId          = "B" + nowStr + "-2";
            initialBookings[2].Parts[0].BookingId = "B" + nowStr + "-2";

            var booking = new BlackMaple.CSVOrders.CSVBookings();

            booking.GetUtcNow = () => now;

            booking.LoadScheduledParts().Should().BeEquivalentTo(initialSchParts);
            booking.LoadUnscheduledBookings(null).Values.Should().BeEquivalentTo(initialBookings);
            Assert.Null(booking.LoadLatestBackoutId());
        }