public SecretCodeServiceTests() { var mockRepository = new Mock <ISecretCodeRepository>(); var mockUnitOfWork = new Mock <IUnitOfWork>(); fakeCodes = new List <SecretCode> { new SecretCode { Id = 1, Email = "*****@*****.**", Code = "1111kj" }, new SecretCode { Id = 2, Email = "*****@*****.**", Code = "2222kj" }, new SecretCode { Id = 3, Email = "*****@*****.**", Code = "3333kj" }, new SecretCode { Id = 4, Email = "*****@*****.**", Code = "4444kj" } }; mockRepository.Setup(m => m.GetAsync(It.IsAny <string>(), It.IsAny <string>())) .Returns <string, string>((code, email) => { return(Task.FromResult(fakeCodes.Single(c => c.Email == email && c.Code == code))); }); mockRepository.Setup(r => r.Add(It.IsAny <SecretCode>())) .Callback <SecretCode>(s => fakeCodes.Add(secretCode = s)); mockRepository.Setup(x => x.RemoveRange(It.IsAny <string>())) .Callback <string>((email) => fakeCodes.RemoveAll(secretCode => secretCode.Email == email)); mockRepository.Setup(y => y.Count(It.IsAny <string>())) .Returns <string>(email => fakeCodes.Count(x => x.Email == email)); mockUnitOfWork.Setup(m => m.SecretCodes).Returns(mockRepository.Object); secretCodeService = new SecretCodeService(mockUnitOfWork.Object); }
public void SendSecretCodeToUser([FromBody, SwaggerRequestBody("Email to send code", Required = true)] string email) { log.Info(nameof(SendSecretCodeToUser)); try { if (codeService.Count(email) < 3) { var secretString = SecretString.GetSecretString(); mailService.SendEmail(email, secretString, "Your personal code"); var code = new SecretCode() { Code = secretString, Email = email }; codeService.Add(code); } } catch (Exception e) { log.Error(e); } }
//public static string Root = Environment.CurrentDirectory; static void Main(string[] args) { /* 打開當前目錄下的data.unity3d */ //byte[] file = File.ReadAllBytes($@"{Root}\data.unity3d"); /* 開啟檔案 */ Console.Write("輸入檔案路徑(建議拖曳檔案) : "); string Infile = Console.ReadLine(); /* 取得檔名(不包含附檔名) */ string InfileName = Path.GetFileNameWithoutExtension(Infile); /* 取得目錄 */ string InfilePath = Path.GetDirectoryName(Infile) + '\\'; /* 取得副檔名 */ string InfileExtn = Path.GetExtension(Infile); byte[] file = File.ReadAllBytes(Infile); /* 解密檔案 */ //byte[] file = AESDecrypt(JSON_ENCRYPT_KEY, JSON_ENCRYPT_IV, file); SecretCode.Revert(file, file); /* 輸出檔案 */ InfileName += "_decrypted"; Console.WriteLine("輸出檔案 : " + InfileName + InfileExtn); File.WriteAllBytes(InfilePath + InfileName + InfileExtn, file); //File.WriteAllBytes($@"{Root}\data_decrypted.unity3d", file); Console.WriteLine("解密完成"); Console.ReadKey(true); }
public IActionResult Verify(SecretCode model) { if (!TryValidateModel(model, nameof(model))) { return(View("Code", model)); } return(View("Done")); }
public void Add(SecretCode code) { if (!secretCodeValidator.Validate(code).IsValid) { throw new ArgumentException(secretCodeValidator.Validate(code).Errors.First().ErrorMessage); } uow.SecretCodes.Add(code); uow.Save(); }
public void TestCodeLength() { using (ServiceMock mocks = new ServiceMock()) { int length = Faker.RandomNumber.Next(1, 9999); mocks.MockConfigService(length); InitializeGame sut = new InitializeGame(); SecretCode code = sut.InitializeSecretCode(); Assert.AreEqual(length, code.Values.Length); } }
public void Create_Code_ShouldFailEmailIsEmpty(string email, string code) { var sc = new SecretCode { Id = 8, Code = code, Email = email }; var exception = Assert.Throws <ArgumentException>(() => secretCodeService.Add(sc)); var expectedMessage = "Email is empty"; Assert.Equal(expectedMessage, exception.Message); }
public void NewCodeStorage() { if (Comfirm()) { //Send SecretCode key = new SecretCode(); key.Str = Str; key.Key = ComfirmKey; key.Name = Name; key.Folder = EncryCodeFolder; Send?.Invoke(this, new NewCodeStorageMessage(this) { Secret = key }); } }
public IActionResult Reset(ResetRequiredInfo model, string submit) { if (submit == "send" || submit == "have") { if (!ModelState.IsValid) { return(View()); } SecretCode modelCode = new SecretCode(); modelCode.code = modelCode.GetCode(5); return(View("Code", modelCode)); } return(View()); }
public void TestCodeBounds() { using (ServiceMock mocks = new ServiceMock()) { int min = RandomNumber.Next(1, 900); int max = min + RandomNumber.Next(9000, 999999); int length = 2000; mocks.MockConfigService(length, min, max); InitializeGame sut = new InitializeGame(); SecretCode code = sut.InitializeSecretCode(); for (int i = 0; i < length; i++) { Assert.LessOrEqual(code.Values[i], max); Assert.GreaterOrEqual(code.Values[i], min); } } }
public string CheckEntry(SecretCode code, string entry) { string result = string.Empty; for (int i = 0; i < code.Values.Length; i++) { double entryValue = Char.GetNumericValue(entry[i]); if (code.Values[i] == entryValue) { result += config.CORRECT_POSITION; } else { result += EntryInCode(code, entryValue) ? config.WRONG_POSITION.ToString() : string.Empty; } } return(result); }
public void Add(SecretCode code) { context.SecretCodes.Add(code); }
public bool EntryInCode(SecretCode code, double entry) { return(Array.Exists(code.Values, value => value == entry)); }
protected override bool CheckBusinessRules(BusinessRulesValidationMode validationMode) { // Remove any old error Codes ClearErrorCodes(); ClearErrorCodes(); if (validationMode == BusinessRulesValidationMode.INSERT || validationMode == BusinessRulesValidationMode.UPDATE) { string filteredHtml = HTML.Replace("<br>", string.Empty); if (string.IsNullOrEmpty(filteredHtml)) { AddErrorCode(new BusinessRulesValidationMessage("HTML", "Description", "You must provide an event description", BusinessRulesValidationCode.REQUIRED_FIELD)); } if (!string.IsNullOrWhiteSpace(ExternalLinkToEvent)) { if (!ExternalLinkToEvent.StartsWith("http://") && !ExternalLinkToEvent.StartsWith("https://")) { AddErrorCode(new BusinessRulesValidationMessage("ExternalLinkToEvent", "Link to more information", "The link to more information must start with http:// or https://", BusinessRulesValidationCode.FIELD_VALIDATION)); } } SecretCode = SecretCode.ToLower(); if (!string.IsNullOrEmpty(SecretCode)) { var allowdups = false; if (SecretCode.Length > 50) { AddErrorCode(new BusinessRulesValidationMessage("Secret Code", "Secret Code", "The Secret Code must be 50 characters or less.", BusinessRulesValidationCode.UNSPECIFIED)); } else if (!Regex.IsMatch(SecretCode, @"^[a-z0-9]+$")) { AddErrorCode(new BusinessRulesValidationMessage("Secret Code", "Secret Code", "The Secret Code can only contain letters and numbers.", BusinessRulesValidationCode.UNSPECIFIED)); } else if (!allowdups) { int eventsWithCode = 0; switch (validationMode) { case BusinessRulesValidationMode.UPDATE: eventsWithCode = GetEventCountByEventCode(EID, SecretCode); break; case BusinessRulesValidationMode.INSERT: eventsWithCode = GetEventCountByEventCode(SecretCode); break; } if (eventsWithCode != 0) { AddErrorCode(new BusinessRulesValidationMessage("Secret Code", "Secret Code", "The Secret Code you have chosen is already in use. Please select a different Secret Code.", BusinessRulesValidationCode.UNSPECIFIED)); } } } } return (ErrorCodes.Count == 0); //return true; }