public void RunSchedule_ScheduleValidFile_GeneratesSchedule()
        {
            // Arrange
            RenderedComponent <RunScheduler> component =
                _host.AddComponent <RunScheduler>();
            MemoryStream   camperRequestStream = new MemoryStream(_validCamperRequestsBuffer);
            IFileReference camperRequestFile   = Substitute.For <IFileReference>();

            camperRequestFile.OpenReadAsync().Returns(camperRequestStream);
            IFileReaderRef fileReaderRef = Substitute.For <IFileReaderRef>();

            fileReaderRef.EnumerateFilesAsync().Returns(new IFileReference[] { camperRequestFile });
            _fileReaderService.CreateReference(Arg.Any <ElementReference>()).Returns(fileReaderRef);

            // Act - execute scheduler
            HtmlAgilityPack.HtmlNode runSchedulerButton = component.Find("button");
            runSchedulerButton.Click();

            // Assert file is loaded
            Assert.That(component.Instance.Output, Contains.Substring("Loaded 9 activity definitions from DefaultActivities"),
                        "Messages after scheduling");
            Assert.That(component.Instance.Output, Contains.Substring("Loaded 98 camper requests"),
                        "Messages after scheduling");
            Assert.That(component.Instance.Output, Contains.Substring("98 campers scheduled"),
                        "Messages after scheduling");
        }
        public void RunSchedule_ScheduleOversubscribed_OutputsUnhappyCampers()
        {
            // Arrange
            RenderedComponent <RunScheduler> component =
                _host.AddComponent <RunScheduler>();
            MemoryStream   camperRequestStream = new MemoryStream(_overSubscribedCamperRequestsBuffer);
            IFileReference camperRequestFile   = Substitute.For <IFileReference>();

            camperRequestFile.OpenReadAsync().Returns(camperRequestStream);
            IFileReaderRef fileReaderRef = Substitute.For <IFileReaderRef>();

            fileReaderRef.EnumerateFilesAsync().Returns(new IFileReference[] { camperRequestFile });
            _fileReaderService.CreateReference(Arg.Any <ElementReference>()).Returns(fileReaderRef);

            // Act - execute scheduler
            HtmlAgilityPack.HtmlNode runSchedulerButton = component.Find("button");
            runSchedulerButton.Click();

            // Assert file is loaded
            Assert.That(component.Instance.Output, Contains.Substring("3 campers could not be scheduled"),
                        "Messages after scheduling");
        }
        public void RunSchedule_ScheduleMissingActivityFile_IndicatesUnknownActivity()
        {
            // Arrange
            RenderedComponent <RunScheduler> component =
                _host.AddComponent <RunScheduler>();
            MemoryStream   camperRequestStream = new MemoryStream(_missingActivityCamperRequestsBuffer);
            IFileReference camperRequestFile   = Substitute.For <IFileReference>();

            camperRequestFile.OpenReadAsync().Returns(camperRequestStream);
            IFileReaderRef fileReaderRef = Substitute.For <IFileReaderRef>();

            fileReaderRef.EnumerateFilesAsync().Returns(new IFileReference[] { camperRequestFile });
            _fileReaderService.CreateReference(Arg.Any <ElementReference>()).Returns(fileReaderRef);

            // Act - execute scheduler
            HtmlAgilityPack.HtmlNode runSchedulerButton = component.Find("button");
            runSchedulerButton.Click();

            // Assert error message
            Assert.That(component.Instance.Output,
                        Contains.Substring("requested unknown activity: 'Horseplay'"),
                        "Messages after scheduling");
        }