public void Construct_HasAppData_ActivitySetsIncludesAllFiles()
        {
            // Arrange - use constructor to create directory with 1 file.
            new ActivityDefinitionService(_applicationName, _logger);
            // Create a couple copies of the default.
            List <string> expectedActivitySets = new List <string>
            {
                DefaultSetName,
                "AnotherSet",
                "OneMore"
            };
            DirectoryInfo applicationDirectoryInfo = ApplicationDirectoryInfo;

            foreach (string addSet in expectedActivitySets.Skip(1))
            {
                File.Copy($"{applicationDirectoryInfo.FullName}\\{DefaultSetName}.xml",
                          $"{applicationDirectoryInfo.FullName}\\{addSet}.xml");
            }

            // Act - create the activity service
            ActivityDefinitionService service = new ActivityDefinitionService(
                _applicationName, _logger);

            // Assert - activity sets should match the expected
            List <string> activitySets = new List <string>(service.GetActivitySetNames());

            Assert.That(activitySets, Is.EquivalentTo(expectedActivitySets),
                        "Activity sets on preloaded application");
        }
        public void Construct_NoAppData_CreatesAppDataWithDefaults()
        {
            // Arrange - make sure directory is gone
            RemoveApplicationData();

            // Act - construct the activity service
            ActivityDefinitionService service = new ActivityDefinitionService(_applicationName, _logger);

            // Assert - verify the directory is created
            DirectoryInfo applicationDirectoryInfo = ApplicationDirectoryInfo;

            Assert.That(applicationDirectoryInfo, Is.Not.Null,
                        "application directory info after constructor");

            // Verify the default XML is present
            FileInfo[] activityFiles = applicationDirectoryInfo.GetFiles();
            Assert.That(activityFiles, Has.Length.EqualTo(1), "Activity file set");
            Assert.That(activityFiles[0].Name, Is.EqualTo($"{DefaultSetName}.xml"), "ActivityFile");

            // Verify activity file is readable and not empty
            List <ActivityDefinition> defaultActivities = ActivityDefinition.ReadActivityDefinitions(
                activityFiles[0].FullName, _logger);

            Assert.That(defaultActivities, Has.Count.GreaterThan(0), "Number of default activities");

            // Verify the activity set contains just the default
            List <string> activitySets = new List <string>(service.GetActivitySetNames());

            Assert.That(activitySets, Is.EquivalentTo(new List <string> {
                DefaultSetName
            }),
                        "Initial activity sets");
        }
Пример #3
0
        private static void Main(string[] args)
        {
            IActivitiesManager         activitiesManager         = new ActivitiesManager(new IActivity[] { new Task1(), new Task2() });
            IActivityDefinitionService activityDefinitionService = new ActivityDefinitionService();
            IWorkflowManager           workflowManager           = new WorkflowManager(activitiesManager, activityDefinitionService);

            workflowManager.TriggerEvent("Task1", () => new Dictionary <string, object>());
        }
        protected void SetUpApplicationServices()
        {
            LoadTestCamperRequests();
            // Arrange - use constructor to create directory with 1 file.
            ILogger <ActivityDefinitionService> logger = Substitute.For <ILogger <ActivityDefinitionService> >();
            ActivityDefinitionService           activityDefinitionService = new ActivityDefinitionService(_applicationName, logger);
            // Create a couple copies of the default.
            List <string> expectedActivitySets = new List <string>
            {
                DefaultSetName,
                "AnotherSet",
                "OneMore"
            };
            List <ActivityDefinition> activityDefinitions = new List <ActivityDefinition>(
                activityDefinitionService.GetActivityDefinition(DefaultSetName));

            _expectedActivitySets.Add(DefaultSetName, new List <ActivityDefinition>(activityDefinitions));
            foreach (string addSet in expectedActivitySets.Skip(1))
            {
                activityDefinitions.RemoveAt(0);
                string content = ActivityDefinition.WriteActivityDefinitionsToString(activityDefinitions, logger);
                File.WriteAllText($"{ApplicationDirectoryInfo.FullName}\\{addSet}.xml", content);
                _expectedActivitySets.Add(addSet, new List <ActivityDefinition>(activityDefinitions));
            }

            ISchedulerService preloadScheduler = new SchedulerService(_applicationName,
                                                                      Substitute.For <ILogger <SchedulerService> >());

            using (MemoryStream camperRequestStream = new MemoryStream(_validCamperRequestsBuffer))
            {
                activityDefinitions = activityDefinitionService.GetActivityDefinition(
                    DefaultSetName).ToList();
                List <CamperRequests> camperRequests = CamperRequests.ReadCamperRequests(
                    camperRequestStream, activityDefinitions);
                preloadScheduler.CreateSchedule(PrebuiltScheduleId,
                                                camperRequests, activityDefinitions);
            }

            _schedulerService = new SchedulerService(_applicationName,
                                                     Substitute.For <ILogger <SchedulerService> >());
            _activityDefinitionService = new ActivityDefinitionService(_applicationName, logger);
        }
 public void SetupLogger()
 {
     _logger = Substitute.For <ILogger <SchedulerService> >();
     _activityDefinitionService = new ActivityDefinitionService(
         _applicationName, Substitute.For <ILogger <ActivityDefinitionService> >());
 }