feature/18-model-user merged on dev
continuous-integration/drone/push Build is failing Details

pull/44/head^2
Roxane ROSSETTO 2 years ago
commit 190e35b54b

@ -1,16 +1,16 @@
// See https://aka.ms/new-console-template for more information
// See https://aka.ms/new-console-template for more information
using ConsoleApp;
using ConsoleApp.Menu;
using DataPersistence;
using Model;
using Model;
using System.Linq;
using System.Text;
Console.WriteLine("Hello, World!\n\n");
// TESTS:
Console.WriteLine("Hello, World!\n\n");
// TESTS:
DataManager dataMgr = new DataManager(new Stubs());
//DataManager dataMgr = new DataManager(new DataContractXML(xmlFolderPath: "../../../../DataPersistence/data"));
//DataManager dataMgr = new DataManager(new DataContractJSON());
@ -22,14 +22,23 @@ dataMgr.Serializer = new DataContractJSON();
// /!\ here is an absolute path I put for testing purpose. It will only work on my computer so don't forget to change it whene you test.
//dataMgr.Export(rc[2], "C:\\Users\\alex6\\Downloads\\recipe2.json");
//dataMgr.Import<Recipe>("C:\\Users\\alex6\\Downloads\\recipe2.json");
Stub stub = new Stub();
PasswordManager passwordManager = new PasswordManager();
RecipeCollection rc = new RecipeCollection("All recipes", dataMgr.Data[nameof(Recipe)].Cast<Recipe>().ToArray());
dataMgr.Save();
MenuManager menuMgr = new MenuManager(dataMgr);
menuMgr.Loop();
foreach (RecipeCollection r in recipeCollections)
Console.WriteLine(r);
List<User> users = stub.ConstrucList();
foreach (User u in users)
Console.WriteLine(u);
// press any key to quit
//Console.ReadKey();
bool isPassCorrect = stub.VerifPass();
Console.WriteLine(isPassCorrect);

@ -0,0 +1,79 @@
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp
{
internal struct Stub
{
private IPasswordManager passwordManager = new PasswordManager();
public List<Recipe> LoadRecipes()
{
List<Recipe> stub = new List<Recipe>();
stub.AddRange(new[]
{
new Recipe(),
new Recipe("Cookies"),
new Recipe("Cookies", 23),
new Recipe("Cookies", null),
new Recipe("", null),
new Recipe("", 24),
new Recipe("Cookies", 24,
new PreparationStep(1)),
new Recipe("Cookies", 26,
new PreparationStep(1),
new PreparationStep(2, "Faire cuire."))
});
return stub;
}
public List<RecipeCollection> LoadRecipeCollection()
{
List<RecipeCollection> stub = new List<RecipeCollection>();
stub.AddRange(new[]
{
new RecipeCollection("All", LoadRecipes().ToArray()),
new RecipeCollection("Starters", LoadRecipes().FindAll(x => x.Id.Equals(23)).ToArray()),
new RecipeCollection("Dishies", LoadRecipes().FindAll(x => x.Id.Equals(24)).ToArray()),
new RecipeCollection("Desserts", LoadRecipes().FindAll(x => x.Id.Equals(26)).ToArray()),
});
return stub;
}
public List<User> ConstrucList()
{
List<User> Users = new List<User>();
User Roger = new User("Roger", "Rabbit", "carotte@mail.fr",passwordManager.HashPassword("password"));
User Dylan = new User("d", "r", "dr@mail.fr", passwordManager.HashPassword("dede"));
User Val = new User("V", "entin", "Valentin@mail.fr", passwordManager.HashPassword("valentin"));
Users.Add(Roger);
Users.Add(Dylan);
Users.Add(Val);
return Users;
}
public bool VerifPass()
{
User John = new User("John", "Doe", "JD@gmail.com", passwordManager.HashPassword("GIJD"));
string entryPass = "GIJD";
User Val = new User("V", "entin", "Valentin@mail.fr", passwordManager.HashPassword("valentin"));
Val.Password = passwordManager.HashPassword("jeChange");
bool isPasswordCorrect = passwordManager.VerifyPassword(John.Password, entryPass);
return isPasswordCorrect;
}
public Stub()
{
}
}
}

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Ingredient
{
internal class Ingredient
{
}
}

@ -8,9 +8,8 @@ namespace Model
{
public interface IPasswordManager
{
public void changePassword(User user, string newPassword);
public string HashPassword(User user);
public bool VerifyPassword(string hashedPassword);
public int HashPassword(string password);
public bool VerifyPassword(int hashedPassword,string password);
}
}

@ -8,19 +8,20 @@ namespace Model
{
public class PasswordManager : IPasswordManager
{
public void changePassword(User user, string newPassword)
{
throw new NotImplementedException();
}
public string HashPassword(User user)
public int HashPassword(string password)
{
throw new NotImplementedException();
int hashedPassword = password.GetHashCode();
return hashedPassword;
}
public bool VerifyPassword(string hashedPassword)
public bool VerifyPassword(int hashedPassword, string passwordEntered )
{
throw new NotImplementedException();
int passwordEnteredHashed = passwordEntered.GetHashCode();
if ( passwordEnteredHashed == hashedPassword)
return true;
else return false;
}
}
}

@ -5,6 +5,7 @@ using System.Collections.ObjectModel;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using System.Text;
namespace Model
{
@ -20,8 +21,7 @@ namespace Model
private string surname="";
private string mail = "";
private string picture = "";
private string password = "";
//private string defaultUserSavePath = "";
private int password ;
private List<Priority> priorities;
#endregion
@ -79,16 +79,14 @@ namespace Model
}
}
///<summary>
/// Property to initiate password, change it, and
/// </summary>
public string Password
public int Password
{
get { return password; }
set { password = value; }
get => password;
set => password = value;
}
/// <summary>
/// For now, we define the ProfilPict as a string which is "PhotoParDefaut"
/// when the value is null.
@ -111,19 +109,20 @@ namespace Model
set=> priorities = value;
}
public override bool Equals(object? obj)
public override bool Equals(object? other)
{
if (obj == null) return false;
if (obj == this) return true;
return Equals(obj);
}
public bool Equals(User? other)
if (other == null) return false;
if (other == this) return true;
return Equals(other);
}
public bool Equals(User? other)
{
if (other == null ) return false;
if (other == null) return false;
return Name.Equals(other.Name) && Surname.Equals(other.Surname) && Mail.Equals(other.Mail);
}
#endregion
@ -135,11 +134,12 @@ namespace Model
/// <param name="name">The name of the user</param>
/// <param name="surname">The surname of the user</param>
/// <param name="mail">The user needs an email to login. </param>
public User(string name, string surname, string mail)
public User(string name, string surname, string mail, int password)
{
Name = name;
Surname = surname;
Mail = mail;
Password = password;
priorities = new List<Priority> {
Priority.Gourmet,
Priority.Economic,

@ -0,0 +1,31 @@
<<<<<<< HEAD
<Project Sdk="Microsoft.NET.Sdk">
=======
<Project Sdk="Microsoft.NET.Sdk">
>>>>>>> feature/18-model-user
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<Configurations>Debug;Release;CI</Configurations>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Model\Model.csproj" />
<ProjectReference Include="..\..\DataPersistence\DataPersistence.csproj" />
</ItemGroup>
</Project>

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>

@ -12,8 +12,13 @@ namespace Model_UnitTests
[Fact]
public void TestConstructUser()
{
User? user = new User("Bob","Dylan", "bd@gmail.com");
Assert.NotNull(user);
PasswordManager passwordManager = new PasswordManager();
User user = new User("Bob", "Dylan", "bd@gmail.com", passwordManager.HashPassword("bobby"));
Assert.Equal("Bob", user.Name);
Assert.Equal("Dylan", user.Surname);
Assert.Equal("bd@gmail.com", user.Mail);
Assert.Equal(passwordManager.HashPassword("bobby"), user.Password);
Assert.NotNull(user.Priorities);
}
}
}

Loading…
Cancel
Save