Exemple #1
0
        public void CreateSampleBooking()
        {
            var bookFile = System.IO.Path.Combine("create-book-test", "bookings.csv");

            if (!System.IO.Directory.Exists("create-book-test"))
            {
                System.IO.Directory.CreateDirectory("create-book-test");
            }
            if (System.IO.File.Exists(bookFile))
            {
                System.IO.File.Delete(bookFile);
            }
            var booking = new BlackMaple.CSVOrders.CSVBookings();

            booking.CSVBasePath = "create-book-test";
            booking.LoadUnscheduledBookings(1);

            var b = File.ReadAllLines(bookFile);

            b.Should().BeEquivalentTo(new string[] {
                "Id,DueDate,Priority,Part,Quantity",
                "12345," + DateTime.Today.AddDays(10).ToString("yyyy-MM-dd") + ",100,part1,50",
                "98765," + DateTime.Today.AddDays(12).ToString("yyyy-MM-dd") + ",100,part2,77"
            });
        }
Exemple #2
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"
            });
        }
Exemple #3
0
        public void LoadsPrograms()
        {
            Directory.CreateDirectory("programs");
            File.WriteAllText(Path.Combine("programs", "prog1.EIA"), "prog1 content");
            File.WriteAllText(Path.Combine("programs", "prog2.EIA"), "prog2 content");

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

            booking.LoadPrograms().Should().BeEquivalentTo(new[] {
                new ProgramEntry()
                {
                    ProgramName        = "prog1",
                    Revision           = -1,
                    Comment            = "",
                    ProgramContentPath = Path.Combine(Environment.CurrentDirectory, "programs", "prog1.EIA")
                },
                new ProgramEntry()
                {
                    ProgramName        = "prog2",
                    Revision           = -1,
                    Comment            = "",
                    ProgramContentPath = Path.Combine(Environment.CurrentDirectory, "programs", "prog2.EIA")
                }
            });
        }
Exemple #4
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());
        }
Exemple #5
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);
        }
Exemple #6
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());
        }
Exemple #7
0
        public void LoadUnscheduledStatus()
        {
            var booking = new BlackMaple.CSVOrders.CSVBookings();
            var status  = booking.LoadUnscheduledStatus(50);

            status.ScheduledParts.ShouldAllBeEquivalentTo(initialSchParts);
            status.UnscheduledBookings.ShouldAllBeEquivalentTo(initialBookings);
            Assert.Empty(status.Castings);
            Assert.Null(status.LatestBackoutId);

            status = booking.LoadUnscheduledStatus(10);
            status.ScheduledParts.ShouldAllBeEquivalentTo(initialSchParts);
            status.UnscheduledBookings.ShouldAllBeEquivalentTo(
                new[] { initialBookings[0] }
                );
            Assert.Empty(status.Castings);
            Assert.Null(status.LatestBackoutId);

            status = booking.LoadUnscheduledStatus(-1);
            status.ScheduledParts.ShouldAllBeEquivalentTo(initialSchParts);
            status.UnscheduledBookings.ShouldAllBeEquivalentTo(initialBookings);
            Assert.Empty(status.Castings);
            Assert.Null(status.LatestBackoutId);
        }
Exemple #8
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());
        }