Beispiel #1
0
        /// <summary>
        /// Controller constructor
        /// </summary>
        /// <param name="mainForm">The form to use as the main form of the application</param>
        public Controller(MainForm mainForm)
        {
            _files = new List <PixelariaFile>();

            // Initialize the factories
            FrameFactory = new DefaultFrameFactory(this);

            // Initialize the validators and exporters
            DefaultValidator defValidator = new DefaultValidator(this);

            AnimationValidator      = defValidator;
            AnimationSheetValidator = defValidator;

            DefaultImporter = new DefaultPngImporter();

            // Initialize the Settings singleton
            Settings.GetSettings(Path.GetDirectoryName(Application.LocalUserAppDataPath) + "\\settings.ini");

            CurrentRecentFileList = new RecentFileList(10);

            if (mainForm != null)
            {
                mainForm.Controller = this;
                // Initialize the basic fields
                _mainForm = mainForm;
                _mainForm.UpdateRecentFilesList();

                // Start with a new empty bundle
                ShowNewBundle();
            }
        }
Beispiel #2
0
        public async Task ValidEmailCreateNew_ExistingUser_ShouldReturnErrorListWithUniqueUserError()
        {
            // Arrange
            IUser  createdUser;
            bool   deletedUserSuccess;
            long   randomNumber = new Random().Next(0, 10000);
            string email        = $"ValidEmailCreateNewExistingUser{randomNumber}@email.com";
            string password     = "******";
            string username     = $"ValidEmailCreateNewExistingUser{randomNumber}";

            IUser createUser = new User(email, password, username);

            createdUser = await this.userService.CreateNewUserAsync(createUser);

            // Act
            var errorList = await DefaultValidator.ValidEmailCreateNewAsync(email);

            // Cleanup
            deletedUserSuccess = await this.userService.DeleteUserAsync(createdUser.Id);

            // Assert
            Assert.IsNotNull(createdUser);
            Assert.IsNotEmpty(errorList);
            Assert.IsTrue(deletedUserSuccess);
        }
        public bool VerifyPassword_DefaultValidator_IsCorrect(string password)
        {
            DefaultValidator       validator = new DefaultValidator();
            PasswordCheckerService service   = new PasswordCheckerService(new SqlRepository(), validator);

            return(service.VerifyPassword(password).Item1);
        }
Beispiel #4
0
 public void SetUp()
 {
     _configuration   = MockRepository.GenerateMock <IAntiCsrfConfiguration>();
     _nonceRepository = MockRepository.GenerateMock <IAntiCsrfNonceRepository>();
     _systemClock     = MockRepository.GenerateMock <ISystemClock>();
     _validator       = new DefaultValidator(_configuration, _nonceRepository, _systemClock);
     _request         = MockRepository.GenerateMock <HttpRequestBase>();
 }
        public void CanValidate()
        {
            DefaultValidator v = new DefaultValidator();

            Assert.True(v.CanValidate(typeof(string)));
            Assert.True(v.CanValidate(typeof(int)));
            Assert.True(v.CanValidate(typeof(object)));
        }
Beispiel #6
0
        /// <summary>
        /// "Create" - button clicked.
        /// Validates and creates a new room.
        /// Redirect to Dashboard page if successfull.
        /// </summary>
        public async void CreateButtonClicked()
        {
            using (UserDialogs.Instance.Loading("Creating room..."))
            {
                List <IStreamingPlatform> selectedStreamingPlatforms = new List <IStreamingPlatform>();
                foreach (HelperModel selectedItem in this.SelectedHelperModels)
                {
                    selectedStreamingPlatforms.Add(selectedItem.StreamingPlatform);
                }

                // Run validation on input fields.
                string[] roomNameErrors = DefaultValidator.ValidRoomName(this.RoomName);
                bool     streamingPlatformsHasBeenSelected = selectedStreamingPlatforms.Count > 0;

                // Check for errors
                if (roomNameErrors.Length == 0 && streamingPlatformsHasBeenSelected)
                {
                    // No errors
                    // Create room
                    try
                    {
                        IUser  owner    = this._userService.CurrentUser;
                        string roomName = this.RoomName;

                        // Create room
                        await this._roomService.CreateRoomAsync(owner, roomName, selectedStreamingPlatforms);

                        // Redirect to login page
                        RedirectToMainPage();
                    }
                    catch (Exception e)
                    {
                        // An unexpected error occured, so user could not be created.
                        // Show generic error message to user.
                        ShowAlert("An error occured. Room could not be created.");
                    }
                }
                else
                {
                    // Errors in user input.
                    // Display errors.
                    string errorMessage = "Invalid room data:" + System.Environment.NewLine;

                    foreach (var error in roomNameErrors)
                    {
                        errorMessage += System.Environment.NewLine + error;
                    }

                    if (!streamingPlatformsHasBeenSelected)
                    {
                        errorMessage += System.Environment.NewLine + "No streaming service has been selected!";
                    }

                    ShowAlert(errorMessage);
                }
            }
        }
        public void Validate()
        {
            DefaultValidator v = new DefaultValidator();

            v.Validate(5);
            v.Validate(5.4);
            v.Validate("hi there");
            v.Validate(v);
        }
        /// <summary>
        /// "Create" - button clicked.
        /// Validates and creates new user.
        /// Redirect to Home page if successfull.
        /// </summary>
        public async void CreateButtonClicked()
        {
            using (UserDialogs.Instance.Loading("Creating user..."))
            {
                // Run validation on input fields.
                string[] emailErrors = await DefaultValidator.ValidEmailCreateNewAsync(this.Email);

                string[] passwordErrors = DefaultValidator.ValidPassword(this.Password);
                string[] usernameErrors = DefaultValidator.ValidUsername(this.Username);

                // Check for errors
                if (emailErrors.Length == 0 && passwordErrors.Length == 0 && usernameErrors.Length == 0)
                {
                    // No errors
                    // Create user in database
                    try
                    {
                        await this._userService.CreateNewUserAsync(Email, Password, Username);


                        // Redirect to login page
                        await Application.Current.MainPage.Navigation.PushModalAsync(new AboutPage(), true);
                    }
                    catch (Exception e)
                    {
                        // An unexpected error occured, so user could not be created.
                        // Show generic error message to user.
                        ShowAlert("An error occured. User could not be created.");
                    }
                }
                else
                {
                    // Errors in user input.
                    // Display errors.
                    string errorMessage = "Invalid user data:" + System.Environment.NewLine;

                    foreach (var error in emailErrors)
                    {
                        errorMessage += System.Environment.NewLine + error;
                    }
                    foreach (var error in passwordErrors)
                    {
                        errorMessage += System.Environment.NewLine + error;
                    }
                    foreach (var error in usernameErrors)
                    {
                        errorMessage += System.Environment.NewLine + error;
                    }

                    ShowAlert(errorMessage);

                    // Color fields with errors.
                }
            }
        }
Beispiel #9
0
        public void ValidRoomName_ValidValues_ShouldReturnEmptyErrorList(string validateString)
        {
            // Arrange
            string testString = validateString;

            // Act
            var errorList = DefaultValidator.ValidRoomName(validateString);

            // Assert
            Assert.IsEmpty(errorList);
        }
Beispiel #10
0
        public void ValidEmailCreateNew_ValidValues_ShouldReturnEmptyList(string validateString)
        {
            // Arrange
            string testString = validateString;

            // Act
            var errorList = DefaultValidator.ValidEmailCreateNew(validateString);

            // Assert
            Assert.IsEmpty(errorList);
        }
Beispiel #11
0
        private static ConfigurationValidatorBase GetValidator(MemberInfo mi)
        {
            ConfigurationValidatorBase validator = new DefaultValidator();
            var validators = mi.GetAttributes <ValidationAttribute>();

            if (validators.IsNullOrEmpty() == false)
            {
                validator = new CompositeConfigurationValidator(validators, mi.Name);
            }
            return(validator);
        }
Beispiel #12
0
        public void ValidEmailLogin_InvalidValues_ShouldReturnErrorList(string validateString)
        {
            // Arrange
            string testString = validateString;

            // Act
            var errorList = DefaultValidator.ValidEmailLogin(validateString);

            // Assert
            Assert.IsNotNull(errorList);
            Assert.IsNotEmpty(errorList);
        }
Beispiel #13
0
        public void ValidEmailLogin_LenghtUnder_ShouldReturnErrorList()
        {
            // Arrange
            string testString = new String('a', 2);

            // Act
            var errorList = DefaultValidator.ValidEmailLogin(testString);

            // Assert
            Assert.IsNotNull(errorList);
            Assert.IsNotEmpty(errorList);
        }
Beispiel #14
0
        public void TestDefaultValidatorValidatesCharactersAllAllowed()
        {
            var validator = new DefaultValidator {
                IllegalCharacters = new[] { 'a' }
            };
            var fileToTest = new ImportFile
            {
                Name = "b.xml"
            };
            var result = validator.Validate(fileToTest);

            Assert.IsTrue(result.IsValid);
        }
Beispiel #15
0
        public void TestDefaultValidatorValidatesFileNameLengthEqualToMax()
        {
            var validator = new DefaultValidator {
                MaximumFileNameLength = 5
            };
            var fileToTest = new ImportFile
            {
                Name = "e.xml"
            };
            var result = validator.Validate(fileToTest);

            Assert.IsTrue(result.IsValid);
        }
Beispiel #16
0
        public void TestValidatorDefaults()
        {
            var validator  = new DefaultValidator();
            var fileToTest = new ImportFile
            {
                Name = "test.xml",
                Size = 0
            };

            var result = validator.Validate(fileToTest);

            Assert.IsTrue(result.IsValid);
        }
        /// <summary>
        /// Enter room by room key.
        /// </summary>
        private async void EnterRoomButtonClicked()
        {
            // Redirect to login page
            using (UserDialogs.Instance.Loading("Entering room..."))
            {
                string[] roomKeyErrors = DefaultValidator.ValidRoomKey(this.EnterRoomCode);

                // Check for errors
                if (roomKeyErrors.Length == 0)
                {
                    // No errors
                    // Check if room key mathces
                    try
                    {
                        IRoom matchingRoom = null;
                        matchingRoom = await this._roomService.GetRoomByRoomKeyAsync(this.EnterRoomCode);

                        if (matchingRoom != null)
                        {
                            // A mathing room was found
                            await Application.Current.MainPage.Navigation.PushModalAsync(new RoomPage(matchingRoom), true);
                        }

                        if (matchingRoom == null)
                        {
                            // No mathing room found
                            ShowAlert("A room matching this room key could not be found.");
                        }
                    }
                    catch (Exception e)
                    {
                        // An unexpected error occured, so user could not be created.
                        // Show generic error message to user.
                        ShowAlert("An error occured. Room could not be entered.");
                    }
                }
                else
                {
                    // Errors in user input.
                    // Display errors.
                    string errorMessage = "Invalid room key:" + System.Environment.NewLine;

                    foreach (var error in roomKeyErrors)
                    {
                        errorMessage += System.Environment.NewLine + error;
                    }

                    ShowAlert(errorMessage);
                }
            }
        }
Beispiel #18
0
        public void TestDefaultValidatorValidatesInvalidExtension()
        {
            var validator = new DefaultValidator();

            validator.BlockedFileExtensions.Add(".xml");
            var fileToTest = new ImportFile
            {
                Name = "test.xml",
            };

            var result = validator.Validate(fileToTest);

            Assert.IsFalse(result.IsValid);
        }
Beispiel #19
0
        public void TestDefaultValidatorValidatesCharacters()
        {
            var validator = new DefaultValidator {
                IllegalCharacters = new[] { 'a' }
            };
            var fileToTest = new ImportFile
            {
                Name = "a.xml"
            };
            var result = validator.Validate(fileToTest);

            Assert.IsTrue(result.IsValid);
            Assert.That(result.Warnings.Count == 1);
        }
Beispiel #20
0
        public void TestDefaultValidatorValidatesFileNameLengthTooLong()
        {
            var validator = new DefaultValidator {
                MaximumFileNameLength = 120
            };
            var fileToTest = new ImportFile
            {
                Name = new string('a', 120) + ".xml"
            };
            var result = validator.Validate(fileToTest);

            Assert.IsTrue(result.IsValid);
            Assert.That(result.Warnings.Count == 1);
        }
Beispiel #21
0
        public void TestDefaultValidatorValidatesSmallerFileSize()
        {
            var size      = 120;
            var validator = new DefaultValidator {
                MaximumFileSize = size
            };
            var fileToTest = new ImportFile
            {
                Name = "test.xml",
                Size = size - 1
            };

            var result = validator.Validate(fileToTest);

            Assert.IsTrue(result.IsValid);
        }
Beispiel #22
0
        public void ValidEmailLogin_ExistingUser_ShouldReturnEmptyErrorList()
        {
            // Arrange
            Random random = new Random();
            IUser  user   = new User()
            {
                Email    = "testemail" + random.Next(0, 10000),
                Username = "******" + random.Next(0, 10000),
                Password = "******" + random.Next(0, 10000)
            };

            // Act
            user = userService.CreateNewUser(user);

            var errorList = DefaultValidator.ValidEmailLogin(user.Email);

            // Cleanup
            userService.DeleteUser(user.Id);

            // Assert
            Assert.IsNotNull(errorList);
            Assert.IsEmpty(errorList);
        }
        /// <summary>
        /// Login button click event.
        /// </summary>
        public async void LoginButtonClicked()
        {
            using (UserDialogs.Instance.Loading("Validating..."))
            {
                string[] emailErrors    = DefaultValidator.ValidEmailLogin(this.Email);
                string[] passwordErrors = DefaultValidator.ValidPassword(this.Password);

                if (emailErrors.Length == 0 && passwordErrors.Length == 0)
                {
                    using (UserDialogs.Instance.Loading("Logging in..."))
                    {
                        try
                        {
                            // Login values are valid
                            // Proceed to login validation
                            bool loginSucceed = await this._userService.LoginUserAsync(this.Email, this.Password);

                            if (loginSucceed)
                            {
                                // User login was successfull
                                // Save user data to local DB, for login after app shutdown.
                                await App.LocalUserDatabase.SaveLocalUserDataAsync(new Models.UserLocal(Email, Password));

                                // Redirect to main page
                                this.RedirectToMainPage();
                            }
                            else
                            {
                                // User login was not successfull
                                // Empty input fields and display error

                                this.Email    = "";
                                this.Password = "";

                                ShowAlert("Wrong email or password.");
                            }
                        }
                        catch
                        {
                            ShowAlert("An unkown error occured. Please try again.");
                        }
                    }
                }
                else
                {
                    // Login values are not valid
                    // Display error message
                    string errorMessage = "An error occured during login" + System.Environment.NewLine;

                    foreach (var error in emailErrors)
                    {
                        errorMessage += System.Environment.NewLine + error;
                    }
                    foreach (var error in passwordErrors)
                    {
                        errorMessage += System.Environment.NewLine + error;
                    }

                    ShowAlert(errorMessage);
                }
            }
        }
Beispiel #24
0
 public static bool ValidMessage(Message pMessage)
 {
     return(DefaultValidator.ValidObject <Message>(pMessage));
 }
Beispiel #25
0
 public void TestDefault(AvroSchema schema, string defaultValue)
 {
     Assert.DoesNotThrow(() => DefaultValidator.ValidateString(schema, defaultValue));
 }
Beispiel #26
0
 public void TestDefaultError(AvroSchema schema, string defaultValue)
 {
     Assert.Throws <AvroParseException>(() => DefaultValidator.ValidateString(schema, defaultValue));
 }
Beispiel #27
0
 public static bool ValidUser(User pUser)
 {
     return(DefaultValidator.ValidObject <User>(pUser));
 }
Beispiel #28
0
        /// <summary>
        /// Validacia s default validatorom a defaultnym setom pravidiel
        /// </summary>
        /// <param name="path"></param>
        private void Validate(string path)
        {
            Log("Reading input file.. ");
            var kv = KVDPH.LoadFromFile(path);
            LogLn("OK", false);

            Log("Creating validation rules set.. ");
            var rules = new DefaultValidationSetFactory().ValidationSet;
            LogLn("OK", false);
            LogLn("Number of rules: " + rules.Count);

            LogLn("Validating..");
            var validator = new DefaultValidator();
            validator.AddObserver(this);
            var result = validator.Validate(kv, rules);
            LogLn("Validating completed.");
            if (result.Count == 0)
            {
                LogLn("Validation passed with no problems or warnings.");
                return;
            }
            else
            {
                LogLn("Number of problems: " + result.Count);
                foreach (var problem in result)
                    HandleProblem(problem);
                Log(Environment.NewLine, false);
            }
        }
 public void SetUp()
 {
     _defaultValidator = new DefaultValidator();
 }