public void AddRecipeTest() { //Arrange var userId = Guid.NewGuid(); var recipeSteps = new List <RecipeStep> { new RecipeStep { Description = "Step 1" }, new RecipeStep { Description = "Step 2" } }; //Act Recipe recipe = _recipeService.AddRecipe("Title", "Description", recipeSteps, "Notes", userId); //Assert Assert.That(RecipeManagementContext.Recipes.Count(), Is.EqualTo(1)); Assert.That(recipe.Title, Is.EqualTo("Title")); Assert.That(recipe.Description, Is.EqualTo("Description")); Assert.That(recipe.Notes, Is.EqualTo("Notes")); Assert.That(recipe.Steps.Count, Is.EqualTo(2)); Assert.That(recipe.Steps.First().StepNumber, Is.EqualTo(1)); Assert.That(recipe.Steps.Last().StepNumber, Is.EqualTo(2)); Assert.That(recipe.CreatedById, Is.EqualTo(userId)); Assert.That(recipe.DateCreated, Is.EqualTo(DateTime.Now).Within(1).Minutes); Assert.That(recipe.DateUpdated, Is.EqualTo(DateTime.Now).Within(1).Minutes); RecipeManagementContext.VerifySave(); }
public void DeleteRecipeTest() { //Arrange var userId = Guid.NewGuid(); var recipeId = Guid.NewGuid(); var recipe = new Recipe { RecipeId = recipeId, Steps = new List <RecipeStep> { new RecipeStep { Description = "Step 1" }, new RecipeStep { Description = "Step 2" }, }, DateCreated = DateTime.Now.AddDays(-1), CreatedById = userId }; RecipeManagementContext.PrepareTestData(context => { context.Recipes.Add(recipe); }); //Act _recipeService.DeleteRecipe(recipeId, userId); //Assert Assert.That(RecipeManagementContext.Recipes.Count(), Is.EqualTo(0)); RecipeManagementContext.VerifySave(); }
public void UpdateUserTest() { //Arrange var userId = Guid.NewGuid(); var user = new User { UserId = userId, Name = "Old Name", Surname = "Old Surname", EmailAddress = "*****@*****.**", CellphoneNumber = "0720000000", DateCreated = DateTime.Now.AddDays(-1) }; RecipeManagementContext.PrepareTestData(context => { context.Users.Add(user); }); //Act _userService.UpdateUser(userId, "Name", "Surname", "*****@*****.**", "0721234567"); //Assert Assert.That(user.UserId, Is.EqualTo(userId)); Assert.That(user.Name, Is.EqualTo("Name")); Assert.That(user.Surname, Is.EqualTo("Surname")); Assert.That(user.CellphoneNumber, Is.EqualTo("0721234567")); Assert.That(user.EmailAddress, Is.EqualTo("*****@*****.**")); Assert.That(RecipeManagementContext.Users.Count(), Is.EqualTo(1)); Assert.That(user.DateCreated, Is.EqualTo(DateTime.Now.AddDays(-1)).Within(1).Minutes); Assert.That(user.DateUpdated, Is.EqualTo(DateTime.Now).Within(1).Minutes); RecipeManagementContext.VerifySave(); }
public void AddUserTest() { //Arrange _cryptographyServiceMock.Setup(service => service.CreateSalt()).Returns("salt"); _cryptographyServiceMock.Setup(service => service.CreatePasswordHash("password", "salt")) .Returns("hashedPassword"); //Act User user = _userService.AddUser("Name", "Surname", "*****@*****.**", "0721234567", "password"); //Assert Assert.That(user.UserId, Is.Not.EqualTo(Guid.Empty)); Assert.That(user.Name, Is.EqualTo("Name")); Assert.That(user.Surname, Is.EqualTo("Surname")); Assert.That(user.CellphoneNumber, Is.EqualTo("0721234567")); Assert.That(user.EmailAddress, Is.EqualTo("*****@*****.**")); Assert.That(RecipeManagementContext.Users.Count(), Is.EqualTo(1)); Assert.That(user.PasswordSalt, Is.EqualTo("salt")); Assert.That(user.Password, Is.EqualTo("hashedPassword")); Assert.That(user.DateCreated, Is.EqualTo(DateTime.Now).Within(1).Minutes); Assert.That(user.DateUpdated, Is.EqualTo(DateTime.Now).Within(1).Minutes); _cryptographyServiceMock.Verify(service => service.CreateSalt(), Times.Once()); _cryptographyServiceMock.Verify(service => service.CreatePasswordHash("password", "salt"), Times.Once()); RecipeManagementContext.VerifySave(); }
ChangePassword_Given_UserId_And_NewPassword_Then_Password_Should_Be_Changed_With_Newly_Generated_Salt() { //Arrange var userId = Guid.NewGuid(); const string oldPassword = "******"; const string newPassword = "******"; const string oldSalt = "OldSalt"; RecipeManagementContext.PrepareTestData(context => { context.Users.Add(new User { UserId = userId, Password = oldPassword, PasswordSalt = oldSalt }); }); _cryptographyServiceMock.Setup(service => service.CreateSalt()).Returns("Salt"); _cryptographyServiceMock.Setup(s => s.CreatePasswordHash(newPassword, "Salt")).Returns("PasswordHash"); //Act _userService.ChangePassword(userId, newPassword); //Assert Assert.That(RecipeManagementContext.Users.First().Password, Is.EqualTo("PasswordHash")); Assert.That(RecipeManagementContext.Users.First().PasswordSalt, Is.EqualTo("Salt")); Assert.That(RecipeManagementContext.Users.First().DateUpdated, Is.EqualTo(DateTime.Now).Within(1).Minutes); //Verify _cryptographyServiceMock.Verify(v => v.CreatePasswordHash(newPassword, "Salt")); RecipeManagementContext.VerifySave(); }
public void UpdateRecipeTest() { //Arrange var userId = Guid.NewGuid(); var recipeId = Guid.NewGuid(); var recipeSteps = new List <RecipeStep> { new RecipeStep { Description = "Step 1" }, new RecipeStep { Description = "Step 2" }, new RecipeStep { Description = "Step 3" } }; var recipe = new Recipe { RecipeId = recipeId, Steps = new List <RecipeStep> { new RecipeStep { Description = "Step 1" }, new RecipeStep { Description = "Step 2" }, }, DateCreated = DateTime.Now.AddDays(-1), CreatedById = userId }; RecipeManagementContext.PrepareTestData(context => { context.Recipes.Add(recipe); }); //Act _recipeService.UpdateRecipe(recipeId, "Title", "Description", recipeSteps, "Notes", userId); //Assert Assert.That(recipe.Title, Is.EqualTo("Title")); Assert.That(recipe.Description, Is.EqualTo("Description")); Assert.That(recipe.Notes, Is.EqualTo("Notes")); Assert.That(recipe.Steps.Count, Is.EqualTo(3)); Assert.That(recipe.Steps.First().StepNumber, Is.EqualTo(1)); Assert.That(recipe.Steps.Last().StepNumber, Is.EqualTo(3)); Assert.That(recipe.CreatedById, Is.EqualTo(userId)); Assert.That(recipe.DateCreated, Is.EqualTo(DateTime.Now.AddDays(-1)).Within(1).Minutes); Assert.That(recipe.DateUpdated, Is.EqualTo(DateTime.Now).Within(1).Minutes); RecipeManagementContext.VerifySave(); }