示例#1
0
        public CommandRunner(CommandMode mode)
        {
            NatureRecorderDbContext context = new NatureRecorderDbContextFactory().CreateDbContext(null);

            _factory = new NatureRecorderFactory(context);
            Mode     = mode;
        }
        public void TestInitialize()
        {
            NatureRecorderDbContext context = new NatureRecorderDbContextFactory().CreateInMemoryDbContext();

            _factory = new NatureRecorderFactory(context);
            _factory.Locations.Add(EntityName, Address, City, County, Postcode, Country, Latitude, Longitude);
        }
示例#3
0
 public CommandBaseWrapper(NatureRecorderFactory factory)
 {
     _context = new CommandContext
     {
         Factory = factory
     };
 }
示例#4
0
        public void TestInitialize()
        {
            NatureRecorderDbContext context = new NatureRecorderDbContextFactory().CreateInMemoryDbContext();

            _factory = new NatureRecorderFactory(context);
            _factory.Categories.Add(EntityName);
        }
        /// <summary>
        /// Create a summary report for the specified report filters
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="locationId"></param>
        /// <param name="categoryId"></param>
        /// <param name="speciesId"></param>
        /// <param name="output"></param>
        public void Summarise(NatureRecorderFactory factory, DateTime from, DateTime to, int?locationId, int?categoryId, int?speciesId, StreamWriter output)
        {
            Summary summary = factory.Sightings.Summarise(from, to, locationId, categoryId, speciesId);

            if (summary.Sightings.Any())
            {
                output.WriteLine($"Summary of sightings from {from:dd-MMM-yyyy} to {to:dd-MMM-yyyy}:\n");

                string sightingsSuffix = (summary.Sightings.Count() > 1) ? "s" : "";
                output.WriteLine($"\t{summary.Sightings.Count()} sighting{sightingsSuffix}");
                output.WriteLine($"\t{summary.Species.Count()} species");

                string categoriesSuffix = (summary.Categories.Count() > 1) ? "ies" : "y";
                output.WriteLine($"\t{summary.Categories.Count()} categor{categoriesSuffix}");

                string locationsSuffix = (summary.Locations.Count() > 1) ? "s" : "";
                output.WriteLine($"\t{summary.Locations.Count()} location{locationsSuffix}\n");

                SightingsTable table = new SightingsTable(summary.Sightings);
                table.PrintTable(output);
            }
            else
            {
                output.WriteLine($"There were no sightings on {from.ToShortDateString()}");
                output.Flush();
            }
        }
示例#6
0
        public void TestInitialize()
        {
            NatureRecorderDbContext context = new NatureRecorderDbContextFactory().CreateInMemoryDbContext();

            _factory = new NatureRecorderFactory(context);

            _currentFolder = Path.GetDirectoryName(Assembly.GetAssembly(typeof(DataMaintenanceCommandTest)).Location);
        }
        public void TestInitialize()
        {
            NatureRecorderDbContext context = new NatureRecorderDbContextFactory().CreateInMemoryDbContext();

            _factory  = new NatureRecorderFactory(context);
            _schemeId = _factory.StatusSchemes.Add(SchemeName).Id;
            _ratingId = _factory.StatusRatings.Add(RatingName, SchemeName).Id;
        }
        public void TestInitialize()
        {
            NatureRecorderDbContext context = new NatureRecorderDbContextFactory().CreateInMemoryDbContext();

            _factory = new NatureRecorderFactory(context);

            _currentFolder = Path.GetDirectoryName(Assembly.GetAssembly(typeof(SightingsImportExportManagerTest)).Location);
        }
        public void TestInitialize()
        {
            NatureRecorderDbContext context = new NatureRecorderDbContextFactory().CreateInMemoryDbContext();

            _factory = new NatureRecorderFactory(context);

            User user = _factory.Users.AddUser(UserName, Password);

            _factory.Context.SaveChanges();
            _userId = user.Id;
        }
        public void TestInitialize()
        {
            NatureRecorderDbContext context = new NatureRecorderDbContextFactory().CreateInMemoryDbContext();

            _factory = new NatureRecorderFactory(context);
            Location location = _factory.Locations.Add(LocationName, Address, City, County, Postcode, Country, Latitude, Longitude);

            _factory.Categories.Add(CategoryName);
            Species species = _factory.Species.Add(SpeciesName, CategoryName);

            _sightingId = _factory.Sightings.Add(0, Gender.Unknown, false, DateTime.Now, location.Id, species.Id).Id;
        }
        public void TestInitialize()
        {
            NatureRecorderDbContext context = new NatureRecorderDbContextFactory().CreateInMemoryDbContext();

            _factory = new NatureRecorderFactory(context);
            _factory.Categories.Add(CategoryName);
            _factory.Species.Add(SpeciesName, CategoryName);

            _factory.StatusSchemes.Add(SchemeName);
            _factory.StatusRatings.Add(RatingName, SchemeName);

            _factory.SpeciesStatusRatings.SetRating(SpeciesName, RatingName, SchemeName);
        }
        /// <summary>
        /// Summarise the conservation ratings for a specified species and scheme
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="speciesName"></param>
        /// <param name="schemeName"></param>
        /// <param name="atDate"></param>
        /// <param name="output"></param>
        public void SummariseConservationStatus(NatureRecorderFactory factory, string speciesName, string schemeName, DateTime?atDate, StreamWriter output)
        {
            Expression <Func <SpeciesStatusRating, bool> > predicate;
            string title;
            string noMatchesMessage;

            // Construct the messages and filtering predicate based on the arguments
            if (schemeName == null)
            {
                // Summary of conservation status for species against all schemes
                predicate        = r => (r.Species.Name == speciesName);
                title            = $"Conservation status summary for {speciesName}";
                noMatchesMessage = $"There are no ratings for species {speciesName}";
            }
            else if (atDate == null)
            {
                // Summary of conservation status for species against a specific scheme
                predicate        = r => (r.Species.Name == speciesName) && (r.Rating.Scheme.Name == schemeName);
                title            = $"Conservation status summary for {speciesName} using scheme {schemeName}";
                noMatchesMessage = $"There are no ratings for species {speciesName} using scheme {schemeName}";
            }
            else
            {
                // Summary of conservation status for species against a specific scheme at a given date
                predicate = r => (r.Species.Name == speciesName) &&
                            (r.Rating.Scheme.Name == schemeName) &&
                            ((r.Start == null) || (r.Start <= atDate)) &&
                            ((r.End == null) || (r.End >= atDate));
                title            = $"Conservation status summary for {speciesName} using scheme {schemeName} at {(atDate ?? DateTime.Now).ToString("dd-MMM-yyyy")}";
                noMatchesMessage = $"There are no ratings for species {speciesName} using scheme {schemeName}";
            }

            IEnumerable <SpeciesStatusRating> ratings = factory.SpeciesStatusRatings
                                                        .List(predicate, 1, int.MaxValue);

            if (ratings.Any())
            {
                output.WriteLine($"{title}:\n");
                SpeciesStatusRatingTable table = new SpeciesStatusRatingTable(ratings);
                table.PrintTable(output);
            }
            else
            {
                output.WriteLine(noMatchesMessage);
                output.Flush();
            }
        }
示例#13
0
        public void TestInitialize()
        {
            NatureRecorderDbContext context = new NatureRecorderDbContextFactory().CreateInMemoryDbContext();

            _factory  = new NatureRecorderFactory(context);
            _schemeId = _factory.StatusSchemes.Add(EntityName).Id;
            _factory.Context.StatusRatings.Add(new StatusRating {
                Name = "Red", StatusSchemeId = _schemeId
            });
            _factory.Context.StatusRatings.Add(new StatusRating {
                Name = "Amber", StatusSchemeId = _schemeId
            });
            _factory.Context.StatusRatings.Add(new StatusRating {
                Name = "Green", StatusSchemeId = _schemeId
            });
            _factory.Context.SaveChanges();
        }
示例#14
0
 internal SightingManager(NatureRecorderFactory factory)
 {
     _factory = factory;
 }
 internal StatusSchemeSchemeManager(NatureRecorderFactory factory)
 {
     _factory = factory;
 }
示例#16
0
        /// <summary>
        /// Run a command and return the output as a string, optionally comparing
        /// it to a comparison file containing expected output. Input to the command
        /// is taken from an (optional) input file containing one entry per line
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="arguments"></param>
        /// <param name="command"></param>
        /// <param name="mode"></param>
        /// <param name="historyFile"></param>
        /// <param name="settingsFile"></param>
        /// <param name="inputFile"></param>
        /// <param name="comparisonFile"></param>
        /// <param name="skipLines"></param>
        /// <returns></returns>
        public static string RunCommand(NatureRecorderFactory factory,
                                        string[] arguments,
                                        CommandBase command,
                                        CommandMode mode,
                                        string historyFile,
                                        string settingsFile,
                                        string inputFile,
                                        string comparisonFile,
                                        int skipLines)
        {
            string       data;
            StreamReader input = null;

            // Open the input file, if specified
            if (!string.IsNullOrEmpty(inputFile))
            {
                string commandFilePath = Path.Combine(_currentFolder, "Content", inputFile);
                input = new StreamReader(commandFilePath);
            }

            // Run the command, capturing the output
            using (MemoryStream stream = new MemoryStream())
            {
                using (StreamWriter output = new StreamWriter(stream))
                {
                    // Load user settings, if required
                    UserSettings settings = null;
                    if (!string.IsNullOrEmpty(settingsFile))
                    {
                        settings = new UserSettings(settingsFile);
                        settings.Load();
                    }

                    //  Run the command
                    command.Run(new CommandContext
                    {
                        Factory   = factory,
                        Mode      = mode,
                        Arguments = arguments ?? new string[] { },
                        Reader    = (input != null) ? new StreamCommandReader(input) : null,
                        Output    = output,
                        History   = (!string.IsNullOrEmpty(historyFile)) ? new CommandHistory(historyFile) : null,
                        Settings  = settings
                    });

                    data = TestHelpers.ReadStream(stream);
                }
            }

            // Close the input file
            if (input != null)
            {
                input.Dispose();
            }

            // Compare the output to the comparison file, if specified
            if (!string.IsNullOrEmpty(comparisonFile))
            {
                TestHelpers.CompareOutput(data, comparisonFile, skipLines);
            }

            return(data);
        }
示例#17
0
 /// <summary>
 /// Run an export command to export data using the specified arguments
 /// </summary>
 /// <param name="exportFile"></param>
 /// <param name="from"></param>
 /// <param name="to"></param>
 public static void ExportData(NatureRecorderFactory factory, string[] arguments)
 {
     RunCommand(factory, arguments, new ExportCommand(), CommandMode.Interactive, null, null, null, null, 0);
 }
示例#18
0
        public void TestInitialize()
        {
            NatureRecorderDbContext context = new NatureRecorderDbContextFactory().CreateInMemoryDbContext();

            _factory = new NatureRecorderFactory(context);
        }
示例#19
0
 internal LocationManager(NatureRecorderFactory factory)
 {
     _factory = factory;
 }
 internal CategoryManager(NatureRecorderFactory factory)
 {
     _factory = factory;
 }
 internal SpeciesManager(NatureRecorderFactory factory)
 {
     _factory = factory;
 }
 public SightingsImportManager(NatureRecorderFactory factory)
 {
     _factory = factory;
 }
 internal SpeciesStatusRatingManager(NatureRecorderFactory factory)
 {
     _factory = factory;
 }
 public SpeciesStatusImportManager(NatureRecorderFactory factory)
 {
     _factory = factory;
 }