public void Put_Exception()
        {
            Guid         apiToken = new Guid("35b22f54-965c-4811-837a-feaafa728ef3");
            const string password = "******";

            var updateModel = new UserUpdateModel
            {
                EmailAddress = "*****@*****.**"
            };

            const string exceptionMessage = "exceptionMessage";

            //arrange
            _webPageHelper.Setup(x => x.UpdateUserInfo(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <UserUpdateModel>())).Throws(new Exception(exceptionMessage));

            //act
            var result = _webPageController.Put(apiToken.ToString(), password, updateModel);

            //assert
            AssertWithMessage.IsOfType(result, typeof(ObjectResult));
            var response = result as ObjectResult;

            AssertWithMessage.AreEqual(response.StatusCode, (int)HttpStatusCode.InternalServerError, "status code");
            AssertWithMessage.AreEqual(response.Value.ToString(), exceptionMessage, "exception message");
        }
        public void FindMatches_SingleMatch_EqualsSearch_Negative()
        {
            const string word         = "test";
            const byte   searchTypeId = (byte)StaticData.SearchType.Equals;
            const byte   severity     = 2;
            const byte   wordTypeId   = (byte)StaticData.WordType.Vulgarity;

            //arrange
            _badWordCache.SetupGet(x => x.Words).Returns(new List <WordModel>
            {
                new WordModel
                {
                    Word         = word,
                    SearchTypeId = searchTypeId,
                    Severity     = severity,
                    WordTypeId   = wordTypeId
                }
            });

            User user = new User();

            //act
            var result = _mainHelper.FindMatches($"we are {word}ing", user);

            //assert
            AssertWithMessage.AreEqual(result.Count(), 0, "item count");
        }
        public void FindMatches_NoMatches()
        {
            const string word         = "test";
            const string searchWord   = "foo";
            const byte   searchTypeId = (byte)StaticData.SearchType.Equals;
            const byte   severity     = 2;
            const byte   wordTypeId   = (byte)StaticData.WordType.Vulgarity;

            //arrange
            _badWordCache.SetupGet(x => x.Words).Returns(new List <WordModel>
            {
                new WordModel
                {
                    Word         = word,
                    SearchTypeId = searchTypeId,
                    Severity     = severity,
                    WordTypeId   = wordTypeId
                }
            });

            User user = new User();

            //act
            var result = _mainHelper.FindMatches($"this is a {searchWord}", user);

            //assert
            AssertWithMessage.AreEqual(result.Count(), 0, "number of matches");
        }
        public void FindMatches_SingleMatch_CaseMismatch()
        {
            const string word         = "test";
            const byte   searchTypeId = (byte)StaticData.SearchType.Equals;
            const byte   severity     = 2;
            const byte   wordTypeId   = (byte)StaticData.WordType.Vulgarity;

            //arrange
            _badWordCache.SetupGet(x => x.Words).Returns(new List <WordModel>
            {
                new WordModel
                {
                    Word         = word,
                    SearchTypeId = searchTypeId,
                    Severity     = severity,
                    WordTypeId   = wordTypeId
                }
            });

            User user = new User();

            //act
            var result = _mainHelper.FindMatches($"this is a {word.ToUpper()}", user);

            //assert
            AssertWithMessage.AreEqual(result.Count(), 1, "item count");
            var item = result.First();

            AssertWithMessage.AreEqual(item.Occurrences, 1, nameof(item.Occurrences));
            AssertWithMessage.AreEqual(item.Word, word, nameof(item.Word));
            AssertWithMessage.AreEqual(item.Severity, severity, nameof(item.Severity));
            AssertWithMessage.AreEqual(item.WordTypeId, wordTypeId, nameof(item.WordTypeId));
        }
Exemple #5
0
        public void Signin_ValidPassword()
        {
            const string email = "email";

            byte[] enteredPassword = Encoding.ASCII.GetBytes("enteredPassword");
            byte[] storedPassword  = Encoding.ASCII.GetBytes("storedPassword");
            Guid   apiToken        = new Guid("126c85d3-d1dd-4a80-ba93-b49ea9601f01");

            //arrange
            _userManager.Setup(x => x.GetUserByEmail(email)).Returns(new User
            {
                ApiToken = apiToken,
                Password = storedPassword,
            });

            _passwordHelper.Setup(x => x.CompareSecurePasswords(enteredPassword, storedPassword)).Returns(true);

            _webPageHelper.Setup(x => x.MapUserToModel(It.IsAny <User>())).Returns(new UserReturnModel
            {
                ApiToken = apiToken
            });

            //act
            var result = _signinHelper.Signin(email, Encoding.ASCII.GetString(enteredPassword));

            //assert
            AssertWithMessage.AreEqual(result.ApiToken, apiToken, nameof(result.ApiToken));
        }
Exemple #6
0
        public void Post_Exception()
        {
            const string email         = "email";
            const string password      = "******";
            const string exceptionText = "exceptionText";

            //arrange
            var model = new SigninModel
            {
                EmailAddress = email,
                Password     = password
            };

            _signinHelper.Setup(x => x.Signin(email, password)).Throws(new Exception(exceptionText));

            //act
            var result = _signinController.Post(model);

            //assert
            AssertWithMessage.IsOfType(result, typeof(ObjectResult));

            var response = result as ObjectResult;

            AssertWithMessage.AreEqual(response.StatusCode, (int)HttpStatusCode.InternalServerError, "status code");
            AssertWithMessage.AreEqual(response.Value.ToString(), $"Unhandled exception occurred while attempting to sign in: {exceptionText}", "exception message");
        }
Exemple #7
0
        public void Post_UnauthorizedAccessException()
        {
            const string email         = "email";
            const string password      = "******";
            const string exceptionText = "exceptionText";

            //arrange
            var model = new SigninModel
            {
                EmailAddress = email,
                Password     = password
            };

            _signinHelper.Setup(x => x.Signin(email, password)).Throws(new UnauthorizedAccessException(exceptionText));

            //act
            var result = _signinController.Post(model);

            //assert
            AssertWithMessage.IsOfType(result, typeof(ObjectResult));

            var response = result as ObjectResult;

            AssertWithMessage.AreEqual(response.StatusCode, (int)HttpStatusCode.Unauthorized, "status code");
            AssertWithMessage.AreEqual(response.Value.ToString(), exceptionText, "exception message");
        }
Exemple #8
0
        public void GetPricePerMonth_Standard_Id()
        {
            //arrange / act
            var result = _accountTypeHelper.GetPricePerMonth((byte)StaticData.StaticPricingTier.Standard);

            //assert
            AssertWithMessage.AreEqual(result, _standardPricePerMonth, "price per month");
        }
Exemple #9
0
        public void GetAccountTypeBasedOnPricing_Free()
        {
            //arrange / act
            var result = _accountTypeHelper.GetAccountTypeBasedOnPricing(_freePricePerMonth, _freeCallsPerMonth);

            //assert
            AssertWithMessage.AreEqual(result, _free, "account type");
        }
Exemple #10
0
        public void GetAccountTypeBasedOnPricing_Standard()
        {
            //arrange / act
            var result = _accountTypeHelper.GetAccountTypeBasedOnPricing(_standardPricePerMonth, _standardCallsPerMonth);

            //assert
            AssertWithMessage.AreEqual(result, _standard, "account type");
        }
Exemple #11
0
        public void GetAccountTypeBasedOnPricing_Premium()
        {
            //arrange / act
            var result = _accountTypeHelper.GetAccountTypeBasedOnPricing(_premiumPricePerMonth, _premiumCallsPerMonth);

            //assert
            AssertWithMessage.AreEqual(result, _premium, "account type");
        }
Exemple #12
0
        public void GetCallsPerMonth_Premium_Id()
        {
            //arrange / act
            var result = _accountTypeHelper.GetCallsPerMonth((byte)StaticData.StaticPricingTier.Premium);

            //assert
            AssertWithMessage.AreEqual(result, _premiumCallsPerMonth, "calls per month");
        }
Exemple #13
0
        public void GeneratePassword(string password)
        {
            //arrange / act
            var result = _passwordHelper.GenerateSecurePassword(Encoding.ASCII.GetBytes(password));

            //assert
            AssertWithMessage.AreEqual(result.Length, 256, "password bytes length");
        }
Exemple #14
0
        public void GetCallsPerMonth_Free_String()
        {
            //arrange / act
            var result = _accountTypeHelper.GetCallsPerMonth(_free);

            //assert
            AssertWithMessage.AreEqual(result, _freeCallsPerMonth, "calls per month");
        }
Exemple #15
0
        public void GetPricePerMonth_Standard_String()
        {
            //arrange / act
            var result = _accountTypeHelper.GetPricePerMonth(_standard);

            //assert
            Assert.True(result == _standardPricePerMonth);
            AssertWithMessage.AreEqual(result, _standardPricePerMonth, "price per month");
        }
Exemple #16
0
        public void GetPricePerMonth_Premium_String()
        {
            //arrange / act
            var result = _accountTypeHelper.GetPricePerMonth(_premium);

            //assert
            Assert.True(result == _premiumPricePerMonth);
            AssertWithMessage.AreEqual(result, _premiumPricePerMonth, "price per month");
        }
        public void RemovePunctuationAndSymbols_NoPunctuation()
        {
            //arrange
            const string test = "this is a test string";

            //act
            var result = test.RemovePunctuationAndSymbols();

            //assert
            AssertWithMessage.AreEqual(result, test, "string");
        }
        public void Options_Ok()
        {
            //arrange / act
            var result = _webPageController.Options();

            //assert

            AssertWithMessage.IsOfType(result, typeof(OkResult));
            var response = result as OkResult;

            AssertWithMessage.AreEqual(response.StatusCode, (int)HttpStatusCode.OK);
        }
        public void RemovePunctuationAndSymbols_Punctuation()
        {
            //arrange
            const string test           = @"~`!@#$%^&*()_+test-={}|[]<\>?,./;':""";
            const string expectedResult = "test";

            //act
            var result = test.RemovePunctuationAndSymbols();

            //assert
            AssertWithMessage.AreEqual(result, expectedResult, "string");
        }
        public void Post_Ok()
        {
            const string authToken  = "testAuthToken";
            const string text       = "text";
            const int    occurances = 1;
            const byte   severity   = 2;
            const string word       = "word";
            const string wordType   = "wordType";
            const byte   wordTypeId = 3;


            User user = new User
            {
                CanCallApi = true
            };

            //arrange
            _mainHelper.Setup(x => x.CheckAuthorization(authToken)).Returns(user);
            _mainHelper.Setup(x => x.CheckCharacterLimit(text)).Returns(true);
            _mainHelper.Setup(x => x.FindMatches(text, user)).Returns(new List <ReturnModel>
            {
                new ReturnModel
                {
                    Occurrences = occurances,
                    Severity    = severity,
                    Word        = word,
                    WordType    = wordType,
                    WordTypeId  = wordTypeId
                }
            });

            //act
            var result = _defaultController.Post(text, authToken);

            //assert
            AssertWithMessage.IsOfType(result, typeof(OkObjectResult));
            var response = result as OkObjectResult;

            AssertWithMessage.IsOfType(response.Value, typeof(List <ReturnModel>));
            var list = response.Value as List <ReturnModel>;

            AssertWithMessage.AreEqual(list.Count, 1, "number of items in return model");

            var value = ((result as OkObjectResult).Value as List <ReturnModel>).First();

            AssertWithMessage.AreEqual(value.Occurrences, occurances, nameof(value.Occurrences));
            AssertWithMessage.AreEqual(value.Severity, severity, nameof(value.Severity));
            AssertWithMessage.AreEqual(value.Word, word, nameof(value.Word));
            AssertWithMessage.AreEqual(value.WordType, wordType, nameof(value.WordType));
            AssertWithMessage.AreEqual(value.WordTypeId, wordTypeId, nameof(value.WordTypeId));
        }
        public void Get_BadApiToken()
        {
            const string apiToken = "badGuid";

            //arrange / act
            var result = _webPageController.Get(apiToken);

            //assert
            AssertWithMessage.IsOfType(result, typeof(ObjectResult));
            var response = result as ObjectResult;

            AssertWithMessage.AreEqual(response.StatusCode, (int)HttpStatusCode.BadRequest);
            AssertWithMessage.AreEqual(response.Value.ToString(), $"Could not parse API token passed in into a GUID.  API token: {apiToken}", "exception message");
        }
        public void UpdateUserInfo_NullUserManager()
        {
            Guid         apiToken = new Guid("d2ab6d8a-d8b3-42a6-9dd4-a36a8a9b1f79");
            const string password = "******";

            //arrange
            var userUpdateModel = new UserUpdateModel();

            _userManager.Setup(x => x.GetUserByApiToken(apiToken)).Returns(default(User));

            //act / assert
            var ex = Assert.Throws <UserNotFoundException>(() => _webPageHelper.UpdateUserInfo(apiToken, password, userUpdateModel));

            AssertWithMessage.AreEqual(ex.Message, $"User could not be found where API token is {apiToken}", "exception message");
        }
        public void SignUp_NoCreditCardWithNonFreeAccount()
        {
            const string user = "******";

            //arrange
            var signupModel = new UserSignupModel
            {
                CreditCardNumber = null,
                PricingTierId    = (byte)StaticData.StaticPricingTier.Standard
            };

            //act / assert
            var ex = Assert.Throws <UserInputException>(() => _webPageHelper.SignUp(signupModel, user));

            AssertWithMessage.AreEqual(ex.Message, "Credit card information must be provided for any non-free account", "exception message");
        }
        public void Post_BadPassword()
        {
            //arrange
            var model = new UserSignupModel
            {
                Password = "******"
            };

            //act
            var result = _webPageController.Post(model);

            //assert
            AssertWithMessage.IsOfType(result, typeof(ObjectResult));
            var response = result as ObjectResult;

            AssertWithMessage.AreEqual(response.StatusCode, (int)HttpStatusCode.NotAcceptable, "status code");
            AssertWithMessage.AreEqual(response.Value.ToString(), "Password must be at least 8 characters", "exception message");
        }
        public void CheckCharacterLimit_OverLimit()
        {
            const int characterLimit = 5;
            var       word           = string.Empty;

            for (int i = 0; i < characterLimit + 1; i++)
            {
                word += "a";
            }

            //arrange
            _appSettings.Setup(x => x.CharacterLimit).Returns(characterLimit);

            //act
            var result = _mainHelper.CheckCharacterLimit(word);

            //assert
            AssertWithMessage.AreEqual(result, false, "character limit");
        }
        public void SignUp_ExistingPricingTier()
        {
            const string user = "******";

            //arrange
            var signupModel = new UserSignupModel
            {
                CreditCardNumber = null,
                PricingTierId    = (byte)StaticData.StaticPricingTier.Free
            };

            _userManager.Setup(x => x.GetUserByEmail(signupModel.EmailAddress)).Returns(default(User));
            _standardPricingTierManager.Setup(x => x.GetStandardPricingTier(signupModel.PricingTierId)).Returns(default(StandardPricingTier));

            //act / assert
            var ex = Assert.Throws <UserInputException>(() => _webPageHelper.SignUp(signupModel, user));

            AssertWithMessage.AreEqual(ex.Message, $"Could not find AccountTypeId {signupModel.PricingTierId}", "exception message");
        }
        public void Post_OverCharacterLimit()
        {
            const string text           = "test text";
            const int    characterLimit = 5;

            //arrange
            _mainHelper.Setup(x => x.CheckCharacterLimit(text)).Returns(false);
            _appSettings.SetupGet(x => x.CharacterLimit).Returns(characterLimit);

            //act
            var result = _defaultController.Post(text, string.Empty);

            AssertWithMessage.IsOfType(result, typeof(BadRequestObjectResult));

            var response = result as BadRequestObjectResult;

            //assert
            AssertWithMessage.AreEqual(response.Value.ToString(), $"Text passed in is longer than the {characterLimit} character limit.  Text length: {text.Length}.", "response value");
        }
        public void Get_Ok()
        {
            const bool    accountLocked = false;
            const string  accountType   = "accountType";
            Guid          apiToken      = new Guid("35b22f54-965c-4811-837a-feaafa728ef3");
            const int     callsPerMonth = 100;
            const string  email         = "email";
            const string  firstName     = "firstName";
            const string  lastName      = "lastName";
            const decimal pricePerMonth = 150;

            //arrange
            _webPageHelper.Setup(x => x.GetUserInfo(apiToken)).Returns(new UserReturnModel
            {
                AccountLocked = accountLocked,
                AccountType   = accountType,
                ApiToken      = apiToken,
                CallsPerMonth = callsPerMonth,
                Email         = email,
                FirstName     = firstName,
                LastName      = lastName,
                PricePerMonth = pricePerMonth
            });

            //act
            var result = _webPageController.Get(apiToken.ToString());

            //assert
            AssertWithMessage.IsOfType(result, typeof(OkObjectResult));
            var response = result as OkObjectResult;

            AssertWithMessage.IsOfType(response.Value, typeof(UserReturnModel));
            var value = response.Value as UserReturnModel;

            AssertWithMessage.AreEqual(value.AccountLocked, accountLocked, nameof(value.AccountLocked));
            AssertWithMessage.AreEqual(value.AccountType, accountType, nameof(value.AccountType));
            AssertWithMessage.AreEqual(value.ApiToken, apiToken, nameof(value.ApiToken));
            AssertWithMessage.AreEqual(value.CallsPerMonth, callsPerMonth, nameof(value.CallsPerMonth));
            AssertWithMessage.AreEqual(value.Email, email, nameof(value.Email));
            AssertWithMessage.AreEqual(value.FirstName, firstName, nameof(value.FirstName));
            AssertWithMessage.AreEqual(value.LastName, lastName, nameof(value.LastName));
            AssertWithMessage.AreEqual(value.PricePerMonth, pricePerMonth, nameof(value.PricePerMonth));
        }
        public void SignUp_ExistingEmail()
        {
            const string user         = "******";
            const string emailAddress = "emailAddress";

            //arrange
            var signupModel = new UserSignupModel
            {
                CreditCardNumber = null,
                EmailAddress     = emailAddress,
                PricingTierId    = (byte)StaticData.StaticPricingTier.Free
            };

            _userManager.Setup(x => x.GetUserByEmail(signupModel.EmailAddress)).Returns(new User());

            //act / assert
            var ex = Assert.Throws <UserInputException>(() => _webPageHelper.SignUp(signupModel, user));

            AssertWithMessage.AreEqual(ex.Message, $"Account already exists for email address '{signupModel.EmailAddress}'", "exception message");
        }
        public void Put_BadApiToken()
        {
            const string apiToken = "badGuid";
            const string password = "******";

            var updateModel = new UserUpdateModel
            {
                EmailAddress = "*****@*****.**"
            };

            //arrange / act
            var result = _webPageController.Put(apiToken, password, updateModel);

            //assert
            AssertWithMessage.IsOfType(result, typeof(ObjectResult));
            var response = result as ObjectResult;

            AssertWithMessage.AreEqual(response.StatusCode, (int)HttpStatusCode.BadRequest, "status code");
            AssertWithMessage.AreEqual(response.Value.ToString(), $"Could not parse API token passed in into a GUID.  API token: {apiToken}", "exception message");
        }