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 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"); }
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)); }
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"); }
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)); }
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 GeneratePassword(string password) { //arrange / act var result = _passwordHelper.GenerateSecurePassword(Encoding.ASCII.GetBytes(password)); //assert AssertWithMessage.AreEqual(result.Length, 256, "password bytes length"); }
public void GetCallsPerMonth_Free_String() { //arrange / act var result = _accountTypeHelper.GetCallsPerMonth(_free); //assert AssertWithMessage.AreEqual(result, _freeCallsPerMonth, "calls per month"); }
public void CheckAuthorization_NonGuid() { //arrange / act var result = _mainHelper.CheckAuthorization("test"); //assert AssertWithMessage.IsNull(result, "user"); }
public void GetAccountTypeBasedOnPricing_Free() { //arrange / act var result = _accountTypeHelper.GetAccountTypeBasedOnPricing(_freePricePerMonth, _freeCallsPerMonth); //assert AssertWithMessage.AreEqual(result, _free, "account type"); }
public void GetPricePerMonth_Standard_Id() { //arrange / act var result = _accountTypeHelper.GetPricePerMonth((byte)StaticData.StaticPricingTier.Standard); //assert AssertWithMessage.AreEqual(result, _standardPricePerMonth, "price per month"); }
public void GetAccountTypeBasedOnPricing_Standard() { //arrange / act var result = _accountTypeHelper.GetAccountTypeBasedOnPricing(_standardPricePerMonth, _standardCallsPerMonth); //assert AssertWithMessage.AreEqual(result, _standard, "account type"); }
public void GetAccountTypeBasedOnPricing_Premium() { //arrange / act var result = _accountTypeHelper.GetAccountTypeBasedOnPricing(_premiumPricePerMonth, _premiumCallsPerMonth); //assert AssertWithMessage.AreEqual(result, _premium, "account type"); }
public void GetCallsPerMonth_Premium_Id() { //arrange / act var result = _accountTypeHelper.GetCallsPerMonth((byte)StaticData.StaticPricingTier.Premium); //assert AssertWithMessage.AreEqual(result, _premiumCallsPerMonth, "calls per month"); }
public void Get_Default() { //arrange /act var result = _defaultController.Default(); //assert AssertWithMessage.IsOfType(result, typeof(OkResult)); }
public void GetPricePerMonth_Standard_String() { //arrange / act var result = _accountTypeHelper.GetPricePerMonth(_standard); //assert Assert.True(result == _standardPricePerMonth); AssertWithMessage.AreEqual(result, _standardPricePerMonth, "price per month"); }
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 CheckAuthorization_NonExistantGuid() { var guidString = "ab9767dd-3c56-4750-a669-76564e057f83"; var guid = new Guid(guidString); //arrange _authChecker.Setup(x => x.CheckToken(guid)).Returns(default(User)); //act var result = _mainHelper.CheckAuthorization(guidString); //assert AssertWithMessage.IsNull(result, "user"); }
public void Post_GoodPassword() { //arrange var model = new UserSignupModel { Password = "******" }; //act var result = _webPageController.Post(model); //assert AssertWithMessage.IsOfType(result, typeof(OkObjectResult)); }
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 Post_BadAuthentication() { const string authToken = "testAuthToken"; const string text = "test text"; //arrange _mainHelper.Setup(x => x.CheckAuthorization(authToken)).Returns(default(User)); _mainHelper.Setup(x => x.CheckCharacterLimit(text)).Returns(true); //act var result = _defaultController.Post(text, authToken); //assert AssertWithMessage.IsOfType(result, typeof(UnauthorizedResult)); }
public void Post_BadRequest() { const string authToken = "testAuthToken"; const string text = "test text"; //arrange _mainHelper.Setup(x => x.CheckAuthorization(authToken)).Throws(new Exception("test exception")); _mainHelper.Setup(x => x.CheckCharacterLimit(text)).Returns(true); //act var result = _defaultController.Post(text, authToken); //assert AssertWithMessage.IsOfType(result, typeof(BadRequestResult)); }
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"); }