public void RenameTest() { Person person = new Person(); // TODO: Initialize to an appropriate value string newName = string.Empty; // TODO: Initialize to an appropriate value PersonExtensions.Rename(person, newName); // this could also be written as person.Rename(newName); Assert.AreEqual(person.Name, string.Empty); }
public async Task <IActionResult> GetPersonByCredentials([FromBody] UserModel user) { var person = await _persons.GetByCredentials(user.Username, PersonExtensions.PasswordHashing(user.Password)).ConfigureAwait(false); if (person == null) { return(NotFound()); } return(Ok(_mapper.Map <PersonModel>(person))); }
public void WhenPasswordHashingIsCalledWithSamePasswords_ThenResultIsIdentical() { // Arrange string passwordToTest = "password1234"; // Act string hashedPasswordOne = PersonExtensions.PasswordHashing(passwordToTest); string hashedPasswordTwo = PersonExtensions.PasswordHashing(passwordToTest); // Assert Assert.AreEqual(hashedPasswordOne, hashedPasswordTwo); }
public void WhenPasswordHashingIsCalledWithDifferentPasswords_ThenResultIsDifferent() { // Arrange string passwordToTest = "password1234"; string passwordToTestTwo = "password123456"; // Act string hashedPasswordOne = PersonExtensions.PasswordHashing(passwordToTest); string hashedPasswordTwo = PersonExtensions.PasswordHashing(passwordToTestTwo); // Assert Assert.AreNotEqual(hashedPasswordOne, hashedPasswordTwo); }
static void Main(string[] args) { // DEMO: Attach debugger if not already attached if (!Debugger.IsAttached) { Debugger.Launch(); } // DEMO: Break in code Debugger.Break(); // DEMO: Check if debugger is attached if (Debugger.IsAttached) { Console.WriteLine("Debugger is attached!"); } else { Console.WriteLine("Debugger is not attached"); } // DEMO: Compile for DEBUG build #if DEBUG Console.WriteLine("Is DEBUG build"); #else Console.WriteLine("Is not DEBUG build"); #endif // DEMO: Call method conditionally // This can be useful for performance measuring, logging, tracing, diagnostics // which is not needed in release builds. CallMeIfDebug(); // DEMO: DebuggerDisplay // Optimizes the debug message of objects var persons = Enumerable.Range(0, 1000) .Select(i => new Person { Id = i, Relatives = Enumerable.Range(0, 1000).Select(x => new Person { Id = x }).ToList() }) .ToList(); var person = persons.ElementAt(0); //person = null; var personRelativeIds = person.GetRelativeIds(); var ids = PersonExtensions.GetRelativeIds(person); Console.ReadKey(); }
public async Task <IActionResult> AddPerson([FromBody] CreatePersonModel user) { var userEntity = _mapper.Map <PersonEntity>(user); var res = await _persons.GetByUsername(user.Username).ConfigureAwait(false); if (res != null) { return(BadRequest()); } var ress = await _persons.GetByEmail(user.Email).ConfigureAwait(false); if (ress != null) { return(BadRequest()); } userEntity.Password = PersonExtensions.PasswordHashing(userEntity.Password); await _persons.AddAsync(userEntity).ConfigureAwait(false); var userResult = await _persons.GetByIdAsync(userEntity.Id).ConfigureAwait(false); return(CreatedAtRoute("GetPersonById", new { id = userResult.Id }, _mapper.Map <PersonEntity>(userResult))); }