Ejemplo n.º 1
0
        public Notification <Statement> Load()
        {
            var settingsResult = _applicationSettingsService.Load();

            if (settingsResult.HasErrors)
            {
                return(settingsResult.ToNotification <Statement>());
            }

            ApplicationSettings settings = settingsResult;
            var path = settings.StatementPath;

            if (path.IsNullOrEmpty())
            {
                return(Notification.ErrorFor(InitializationErrorMessageText, typeof(Statement).GetSingularUIDescription()).ToNotification <Statement>());
            }

            var statement = _serializationService.DeserializeFromFile <Statement>(path);

            if (statement.HasErrors)
            {
                return(Notification.ErrorFor(DeserializationErrorMessageText, typeof(Statement).GetSingularUIDescription(), path, Environment.NewLine, statement.Errors).ToNotification <Statement>());
            }
            return(statement);
        }
                public void Should_return_an_error_notification()
                {
                    var result = _service.DeserializeFromFile <TestObject>(@"x:\test.settings");

                    result.HasErrors.ShouldBeTrue();
                    result.Errors.ShouldContain("pretend");
                    Regex.IsMatch(result.Errors, SerializationService.DeserializationErrorMessageText.MessageTextToRegex()).ShouldBeTrue();
                }
Ejemplo n.º 3
0
        public Notification <ApplicationSettings> Load()
        {
            var settingsPath = GetSettingsPath();
            var settings     = _serializationService.DeserializeFromFile <ApplicationSettings>(settingsPath);

            if (settings.HasErrors)
            {
                if (_fileSystemService.FileExists(settingsPath))
                {
                    return(Notification.ErrorFor(DamagedSettingsFileMessageText, typeof(ApplicationSettings).GetSingularUIDescription(), settingsPath, Environment.NewLine, settings.Errors).ToNotification <ApplicationSettings>());
                }
                return(Notification.WarningFor(MissingSettingsFileMessageText, typeof(ApplicationSettings).GetSingularUIDescription(), typeof(Statement).GetSingularUIDescription(), settingsPath).ToNotification(new ApplicationSettings()));
            }
            return(settings);
        }
                public void Should_return_a_success_notification()
                {
                    var result = _service.DeserializeFromFile <TestObject>(@"x:\test.settings");

                    result.HasErrors.ShouldBeFalse();
                }