Commit 9dc365e3 authored by JeanCharlesNeboit's avatar JeanCharlesNeboit
Browse files

ServiceWeb

Add UnitsTest
Update Web and WebAPI
parent 221d35da
using EntitiesLayer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StubDataAccessLayer
{
public class Features
{
private int _pv;
private CharacterType _type;
private int _bravoury;
private int _crazyness;
public int Pv
{
get
{
return _pv;
}
set
{
_pv = value;
}
}
public Features(int pv, CharacterType type, int bravoury, int crazyness)
{
Pv = pv;
Type = type;
Bravoury = bravoury;
Crazyness = crazyness;
}
public CharacterType Type
{
get
{
return _type;
}
set
{
_type = value;
}
}
public int Bravoury
{
get
{
return _bravoury;
}
set
{
_bravoury = value;
}
}
public int Crazyness
{
get
{
return _crazyness;
}
set
{
_crazyness = value;
}
}
}
public class DalManager
{
private static DalManager _instance;
private static readonly object padlock = new object();
private DataBaseBridge dataBaseBridge;
private DalManager()
{
dataBaseBridge = new SqlServer();
}
public static DalManager Instance
{
get
{
if (_instance == null)
{
lock (padlock)
{
if (_instance == null)
{
_instance = new DalManager();
}
}
}
return _instance;
}
}
public List<Character> GetAllCharacters()
{
return null;
}
public List<House> HousesMoreThan200()
{
List<House> houses = null;
return houses;
}
public List<Features> CharactersFeatures()
{
List<Features> features = null;
return features;
}
}
}
using EntitiesLayer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StubDataAccessLayer
{
interface DataBaseBridge
{
List<Character> GetAllCharacters();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StubDataAccessLayer
{
interface Interface1
{
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Les informations générales relatives à un assembly dépendent de
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
// associées à un assembly.
[assembly: AssemblyTitle("StubDataAccessLayer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StubDataAccessLayer")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly
// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de
// COM, affectez la valeur true à l'attribut ComVisible sur ce type.
[assembly: ComVisible(false)]
// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
[assembly: Guid("94f34892-5ad6-401d-9b86-490b3d74a7a0")]
// Les informations de version pour un assembly se composent des quatre valeurs suivantes :
//
// Version principale
// Version secondaire
// Numéro de build
// Révision
//
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EntitiesLayer;
using System.Data.SqlClient;
namespace StubDataAccessLayer
{
class SqlServer : DataBaseBridge
{
private string connection = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=\"H:\\Documents\\ThronesTournamentConsole\\Base de donnée\\db.mdf\";Integrated Security=True;Connect Timeout=30";
public List<Character> GetAllCharacters()
{
List<Character> characters = new List<Character>();
using (SqlConnection sqlConnection = new SqlConnection(connection))
{
SqlCommand sqlCommand = new SqlCommand("SELECT * FROM Character", sqlConnection);
sqlConnection.Open();
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
while (sqlDataReader.Read())
{
/*Character character = new Character(sqlDataReader.GetInt64(0), sqlDataReader.GetString(1), sqlDataReader.GetString(2), sqlDataReader.GetInt64(3), sqlDataReader.GetInt64(4), sqlDataReader.GetInt64(5), sqlDataReader.GetInt64(6));
characters.Add()*/
}
sqlConnection.Close();
}
return characters;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{94F34892-5AD6-401D-9B86-490B3D74A7A0}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>StubDataAccessLayer</RootNamespace>
<AssemblyName>StubDataAccessLayer</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DalManager.cs" />
<Compile Include="DataBaseBridge.cs" />
<Compile Include="Interface1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SqlServer.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EntitiesLayer\EntitiesLayer.csproj">
<Project>{ba250fbe-da3e-43ef-b626-1c10c5d06d98}</Project>
<Name>EntitiesLayer</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
......@@ -28,22 +28,37 @@ namespace BusinessLayer
{
return DalManager.HousesList(sup);
}
public List<Fight> FightsList()
{
return DalManager.FightsList();
}
public War getWarById(int id)
public Character getCharacterById(int id)
{
return DalManager.getWarById(id);
return DalManager.getCharacterById(id);
}
public House getHouseById(int id)
{
return DalManager.getHouseById(id);
}
public Character getCharacterById(int id)
public War getWarById(int id)
{
return DalManager.getCharacterById(id);
return DalManager.getWarById(id);
}
public Territory getTerritoryById(int id)
{
return DalManager.getTerritoryById(id);
}
public Fight getFightById(int id)
{
return DalManager.getFightById(id);
}
public List<Characteristics> CharactersCharacteristicsList()
{
return DalManager.CharactersCharacteristicsList();
......@@ -58,6 +73,7 @@ namespace BusinessLayer
{
return DalManager.CharactersList().Where(c => c.Characteristics.Bravoury > BravourySup && c.Characteristics.PV > PVSup).ToList();
}
public List<Territory> TerritoryList()
{
return DalManager.TerritoriesList();
......@@ -67,58 +83,72 @@ namespace BusinessLayer
{
return DalManager.addCharacter(c);
}
public void deleteCharacater(int id)
{
DalManager.deleteCharacter(id);
}
public void updateCharacter(Character c)
{
DalManager.updateCharacter(c);
}
public int addHouse(House h)
{
return DalManager.addHouse(h);
}
public void deleteHouse(int id)
{
DalManager.deleteHouse(id);
}
public void updateHouse(House h)
{
DalManager.updateHouse(h);
}
public int addFight(Fight f)
{
return DalManager.addFight(f);
}
public void deleteFight(int id)
{
DalManager.deleteFight(id);
}
public void updateFight(Fight f)
{
DalManager.updateFight(f);
}
public int addTerritory(Territory t)
{
return DalManager.addTerritory(t);
}
public void deleteTerritory(int id)
{
DalManager.deleteTerritory(id);
}
public void updateTerritory(Territory t)
{
DalManager.updateTerritory(t);
}
public int addWar(War w)
{
return DalManager.addWar(w);
}
public void deleteWar(int id)
{
DalManager.deleteWar(id);
}
public void updateWar(War w)
{
DalManager.updateWar(w);
......
......@@ -52,19 +52,31 @@ namespace DataAccessLayer
return dataBaseBridge.FightsList();
}
public War getWarById(int id)
public Character getCharacterById(int id)
{
return dataBaseBridge.getWarById(id);
return dataBaseBridge.getCharacterById(id);
}
public House getHouseById(int id)
{
return dataBaseBridge.getHouseById(id);
}
public Character getCharacterById(int id)
public War getWarById(int id)
{
return dataBaseBridge.getCharacterById(id);
return dataBaseBridge.getWarById(id);
}
public Territory getTerritoryById(int id)
{
return dataBaseBridge.getTerritoryById(id);
}
public Fight getFightById(int id)
{
return dataBaseBridge.getFightById(id);
}
public List<Characteristics> CharactersCharacteristicsList()
{
return dataBaseBridge.CharactersCharacteristicsList();
......@@ -109,6 +121,7 @@ namespace DataAccessLayer
{
dataBaseBridge.updateHouse(house);
}
public int addFight(Fight fight)
{
return dataBaseBridge.addFight(fight);
......@@ -123,6 +136,7 @@ namespace DataAccessLayer
{
dataBaseBridge.updateFight(fight);
}
public int addTerritory(Territory territory)
{
return dataBaseBridge.addTerritory(territory);
......@@ -137,6 +151,7 @@ namespace DataAccessLayer
{
dataBaseBridge.updateTerritory(territory);
}
public int addWar(War war)
{
return dataBaseBridge.addWar(war);
......
......@@ -11,26 +11,33 @@ namespace DataAccessLayer
{
List<House> HousesList();
List<House> HousesList(int sup);
War getWarById(int id);
House getHouseById(int id);
Character getCharacterById(int id);
List<Character> CharactersList();
List<Characteristics> CharactersCharacteristicsList();
List<Territory> TerritoriesList();
List<Fight> FightsList();
Character getCharacterById(int id);
House getHouseById(int id);
War getWarById(int id);
Territory getTerritoryById(int id);
Fight getFightById(int id);
int addCharacter(Character character);
void deleteCharacter(int id);
void updateCharacter(Character character);
int addHouse(House house);
void deleteHouse(int id);
void updateHouse(House house);
int addFight(Fight house);
void deleteFight(int id);
void updateFight(Fight fight);
int addTerritory(Territory territory);
void deleteTerritory(int id);
void updateTerritory(Territory territory);
int addWar(War war);
void deleteWar(int id);
void updateWar(War war);
......
......@@ -6,13 +6,15 @@ using System.Threading.Tasks;
using EntitiesLayer;
using System.Data.SqlClient;
using System.Data;
using System.IO;
namespace DataAccessLayer
{
class SqlServer : DataBaseBridge
{
private string _connectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=H:\\Documents\\ThronesTournamentConsole\\Database\\db.mdf;Integrated Security=True;Connect Timeout=30";
//private string _connectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=H:\\Documents\\ThronesTournamentConsole\\Database\\db.mdf;Integrated Security=True;Connect Timeout=30";
private string _connectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\NEBOIT\\Documents\\GitHub\\ServiceWeb\\Database\\db.mdf;Integrated Security=True;Connect Timeout=30";
private void LogException(Exception e)
{
Console.WriteLine("Exception: " + e.Message + ", Source" + e.Source);
......@@ -21,7 +23,6 @@ namespace DataAccessLayer
private DataTable SelectByDataAdapter(string request)
{
DataTable results = new DataTable();
using (SqlConnection sqlConnection = new SqlConnection(_connectionString))
{
try
......@@ -35,14 +36,12 @@ namespace DataAccessLayer
LogException(e);
}
}
return results;
}
private int UpdateByCommandBuilder(string request, DataTable table)
{
int result = 0;
using (SqlConnection sqlConnection = new SqlConnection(_connectionString))
{
try
......@@ -65,14 +64,12 @@ namespace DataAccessLayer
LogException(e);
}
}
return result;
}
public List<Character> CharactersList()
{
List<Character> res = new List<Character>();
try
{
DataTable dataTable = SelectByDataAdapter("Select * From Character");
......@@ -89,14 +86,12 @@ namespace DataAccessLayer
{
LogException(e);
}
return res;
}
public List<Characteristics> CharactersCharacteristicsList()
{
List<Characteristics> res = new List<Characteristics>();
try
{
DataTable dataTable = SelectByDataAdapter("Select * From Character");
......@@ -111,7 +106,6 @@ namespace DataAccessLayer
{
LogException(e);
}
return res;
}
......@@ -119,7 +113,6 @@ namespace DataAccessLayer
public List<Fight> FightsList()
{
List<Fight> res = new List<Fight>();
try
{
DataTable dataTable = SelectByDataAdapter("Select * From Fight");
......@@ -145,51 +138,30 @@ namespace DataAccessLayer
{
LogException(e);
}
return res;
}
public List<House> HousesList()
{
List<House> res = new List<House>();
try
DataTable dataTable = SelectByDataAdapter("Select * From House");
foreach (DataRow row in dataTable.Rows)
{
DataTable dataTable = SelectByDataAdapter("Select * From House");
foreach (DataRow row in dataTable.Rows)
{
House house = new House(Convert.ToInt32(row["Id"]), row["name"].ToString(), Convert.ToInt32(row["nbUnits"]));
res.Add(house);
}
House house = new House(Convert.ToInt32(row["Id"]), row["name"].ToString(), Convert.ToInt32(row["nbUnits"]));
res.Add(house);
}
catch (Exception e)
{
LogException(e);
}
return res;
}