public void UserIsNotValid() { // Arrange var user = new User(); // Act bool isValid = user.IsValid; // Assert Assert.IsFalse(isValid); }
private Guid Create() { // Arrange User user = new User(); user.Username = USERNAME; user.Password = new EncryptedString(PASSWORD); // Act _repository.Add(user); // Assert Assert.AreNotEqual(Guid.Empty, user.ID, "Creating new record does not return id"); return user.ID; }
public void UserWithEmptyPasswordIsNotValid() { // Arrange var encryptionService = new Mock<IEncryptionService>(); encryptionService.Setup(e => e.Encrypt(It.IsAny<string>())).Returns(new byte[]{}); var user = new User(); user.Username = "******"; user.Password = EncryptedString.Create(string.Empty, encryptionService.Object); // Act bool isValid = user.IsValid; // Assert Assert.IsFalse(isValid); }
public void UserIsValid() { // Arrange var encryptionService = new Mock<IEncryptionService>(); encryptionService.Setup(e => e.Encrypt(It.IsAny<string>())).Returns(new byte[] { 1, 2, 3, 4 }); var user = new User(); user.Username = "******"; user.Password = EncryptedString.Create("password", encryptionService.Object); // Act bool isValid = user.IsValid; // Assert Assert.IsTrue(isValid); }
// POST users public HttpResponseMessage Post(CreateUserItem item) { var user = new User() { Username = item.Username, Password = EncryptedString.Create(item.Password, _encryptionService) }; if (user.IsValid) { _userRepository.Add(user); UserItem createdItem = _mapper.Map<User, UserItem>(user); return CreatedHttpResponse(createdItem.ID, createdItem); } return Request.CreateResponse(HttpStatusCode.BadRequest, user.ValidationErrors); }
private Guid GetNewUserID() { var user = new User() { Username = StringExtensions.GetRandomString(10), Password = new EncryptedString(Encoding.UTF8.GetBytes(StringExtensions.GetRandomString(10))) }; _userRepository.Add(user); return user.ID; }
/// <summary> /// The post. /// </summary> /// <param name="item"> /// The item. /// </param> /// <returns> /// The <see cref="HttpResponseMessage"/>. /// </returns> /// <remarks> /// POST users /// </remarks> public HttpResponseMessage Post(PostUser item) { var user = new User() { Username = item.Username, Password = EncryptedString.Create(item.Password, _encryptionService) }; if (user.IsValid) { _userDataMapper.Insert(user); GetUser createdItem = _mapper.Map<User, GetUser>(user); return CreatedHttpResponse(createdItem.ID, createdItem); } return Request.CreateResponse(HttpStatusCode.BadRequest, user.ValidationErrors); }