public static ReturnValue Login(string username, string password = null) { if (password == null) { return(ReturnValue.WrongUserOrPassword); } HashAlgorithm hash = new SHA256Managed(); byte[] passwordBytes = Encoding.UTF8.GetBytes(password); byte[] hashBytes = hash.ComputeHash(passwordBytes); string passwordSHA256 = Convert.ToBase64String(hashBytes); string passwordSHA2562 = GetSHA256Password(password); TblPerson user = ContextMethods.GetUserFromLogin(username, password, passwordSHA256, passwordSHA2562); if (user != null) { return(ReturnValue.Successful); } return(ReturnValue.WrongUserOrPassword); }
public void CreateAccountTest() { // // Arrange // var connection = new CrmConnection("Crm"); var service = new OrganizationService(connection); var context = new OrganizationServiceContext(service); using (ShimsContext.Create()) { string accountName = "abcabcabc"; Guid actual; Guid expected = Guid.NewGuid(); int callCount = 0; Entity entity = null; var fakeContext = new Microsoft.Xrm.Sdk.Client.Fakes.ShimOrganizationServiceContext(context); fakeContext.AddObjectEntity = e => { callCount++; entity = e; }; fakeContext.SaveChanges = () => { entity.Id = expected; // SaveChangesResultCollection only has one internal constructor // so we can not create a instance outside of Microsoft.Xrm.Sdk assembly // we will use reflection to create instances of SaveChangesResultCollection and SaveChangesResult var results = CreateSaveChangesResultCollection(SaveChangesOptions.None); var request = new OrganizationRequest(); var response = new OrganizationResponse(); results.Add(CreateSaveChangesResult(request, response)); return(results); }; ContextMethods target = new ContextMethods(context); // // Act // actual = target.CreateAccount(accountName); // // Assert // Assert.AreEqual(callCount, 1); // verify OrganizationServiceContext.AddObject is called once Assert.IsNotNull(entity); // verify OrganizationServiceContext.AddObject is called with not null object Assert.AreEqual(entity.LogicalName, "account"); // verify OrganizationServiceContext.AddObject is called with entity with proper entity name Assert.AreEqual(entity.GetAttributeValue <string>("name"), accountName); // verify OrganizationServiceContext.AddObject is called with entity with proper value set on name attribute Assert.AreEqual(expected, actual); } }