Browse Source

[WebApiUtils] tests

feature/authentication-tests
Robin Thoni 9 years ago
parent
commit
de94054070

+ 9
- 5
WebAPiUtils-test/BusinessManager/ValuesBusiness.cs View File

7
 {
7
 {
8
     public class ValuesBusiness
8
     public class ValuesBusiness
9
     {
9
     {
10
-        public static OpResult<ValuesDbo> Get(long id)
10
+        public static OpResult<ValuesDboGet> Get(long id)
11
         {
11
         {
12
-            //return ValuesManager.Get(id);
13
-            return ValuesManager.GetByIdDbo(id);
12
+            return ValuesManager.GetSingleById(id);
14
         }
13
         }
15
 
14
 
16
-        public static OpResult<IEnumerable<ValuesDbo>> Contains(string text)
15
+        public static OpResult<IEnumerable<ValuesDboGet>> Contains(string text, int page, int perPage)
17
         {
16
         {
18
-            return ValuesManager.Contains(text);
17
+            return ValuesManager.Contains(text, page, perPage);
18
+        }
19
+
20
+        public static OpResult<bool> Edit(ValuesDboEdit obj, long id)
21
+        {
22
+            return ValuesManager.EditById(obj, id);
19
         }
23
         }
20
     }
24
     }
21
 }
25
 }

+ 10
- 23
WebAPiUtils-test/Controllers/ValuesController.cs View File

9
 {
9
 {
10
     public class ValuesController : ApiController
10
     public class ValuesController : ApiController
11
     {
11
     {
12
-        // GET api/values
13
-        public IEnumerable<string> Get()
14
-        {
15
-            throw new Exception("Something went wrong...");
16
-        }
17
-
18
-        // GET api/values/5
19
-        public ValuesDbo Get(int id)
12
+        [HttpGet]
13
+        [Route("api/values/{id}")]
14
+        public ValuesDboGet Get(int id)
20
         {
15
         {
21
-            return BMRHandler<ValuesDbo>.Handle(ValuesBusiness.Get(id), Request);
16
+            return BMRHandler<ValuesDboGet>.Handle(ValuesBusiness.Get(id), Request);
22
         }
17
         }
23
 
18
 
24
         [HttpGet]
19
         [HttpGet]
25
         [Route("api/values/contains")]
20
         [Route("api/values/contains")]
26
-        public IEnumerable<ValuesDbo> Contains(string text)
27
-        {
28
-            return BMRHandler<IEnumerable<ValuesDbo>>.Handle(ValuesBusiness.Contains(text), Request);
29
-        }
30
-
31
-        // POST api/values
32
-        public void Post([FromBody]MyDbo value)
33
-        {
34
-        }
35
-
36
-        // PUT api/values/5
37
-        public void Put(int id, [FromBody]string value)
21
+        public IEnumerable<ValuesDboGet> Contains(string text, int page = 0, int perPage = Int32.MaxValue)
38
         {
22
         {
23
+            return BMRHandler<IEnumerable<ValuesDboGet>>.Handle(ValuesBusiness.Contains(text, page, perPage), Request);
39
         }
24
         }
40
 
25
 
41
-        // DELETE api/values/5
42
-        public void Delete(int id)
26
+        [HttpPost]
27
+        [Route("api/values/edit/{id}")]
28
+        public bool Edit(long id, ValuesDboEdit obj)
43
         {
29
         {
30
+            return BMRHandler<bool>.Handle(ValuesBusiness.Edit(obj, id), Request);
44
         }
31
         }
45
     }
32
     }
46
 }
33
 }

+ 0
- 13
WebAPiUtils-test/DBO/MyDbo.cs View File

1
-using System.ComponentModel.DataAnnotations;
2
-
3
-namespace WebAPiUtils_test.DBO
4
-{
5
-    public class MyDbo
6
-    {
7
-        [Required]
8
-        public int MyInt { get; set; }
9
-
10
-        [MinLength(2)]
11
-        public string MyString { get; set; }
12
-    }
13
-}

+ 7
- 0
WebAPiUtils-test/DBO/ValuesDboAdd.cs View File

1
+
2
+namespace WebAPiUtils_test.DBO
3
+{
4
+    public class ValuesDboAdd : ValuesDboEdit
5
+    {
6
+    }
7
+}

WebAPiUtils-test/DBO/ValuesDbo.cs → WebAPiUtils-test/DBO/ValuesDboEdit.cs View File

1
 
1
 
2
 namespace WebAPiUtils_test.DBO
2
 namespace WebAPiUtils_test.DBO
3
 {
3
 {
4
-    public class ValuesDbo
4
+    public class ValuesDboEdit
5
     {
5
     {
6
-        public long Id { get; set; }
7
-
8
         public string MyString { get; set; }
6
         public string MyString { get; set; }
9
 
7
 
10
         public int MyInt { get; set; }
8
         public int MyInt { get; set; }
9
+
10
+        public long TextId { get; set; }
11
     }
11
     }
12
 }
12
 }

+ 10
- 0
WebAPiUtils-test/DBO/ValuesDboGet.cs View File

1
+
2
+namespace WebAPiUtils_test.DBO
3
+{
4
+    public class ValuesDboGet : ValuesDboAdd
5
+    {
6
+        public long Id { get; set; }
7
+
8
+        public string Text { get; set; }
9
+    }
10
+}

+ 1
- 0
WebAPiUtils-test/DataAccess/SqlServerManager.Context.cs View File

26
         }
26
         }
27
     
27
     
28
         public virtual DbSet<T_SqlManager> T_SqlManager { get; set; }
28
         public virtual DbSet<T_SqlManager> T_SqlManager { get; set; }
29
+        public virtual DbSet<T_Text> T_Text { get; set; }
29
     }
30
     }
30
 }
31
 }

+ 61
- 0
WebAPiUtils-test/DataAccess/SqlServerManager.edmx View File

12
           <Property Name="id" Type="bigint" StoreGeneratedPattern="Identity" Nullable="false" />
12
           <Property Name="id" Type="bigint" StoreGeneratedPattern="Identity" Nullable="false" />
13
           <Property Name="my_string" Type="varchar" MaxLength="50" Nullable="false" />
13
           <Property Name="my_string" Type="varchar" MaxLength="50" Nullable="false" />
14
           <Property Name="my_int" Type="int" Nullable="false" />
14
           <Property Name="my_int" Type="int" Nullable="false" />
15
+          <Property Name="text" Type="bigint" Nullable="false" />
15
         </EntityType>
16
         </EntityType>
17
+        <EntityType Name="T_Text">
18
+          <Key>
19
+            <PropertyRef Name="id" />
20
+          </Key>
21
+          <Property Name="id" Type="bigint" StoreGeneratedPattern="Identity" Nullable="false" />
22
+          <Property Name="text" Type="varchar" MaxLength="50" Nullable="false" />
23
+        </EntityType>
24
+        <Association Name="FK_T_SqlManager_T_Text">
25
+          <End Role="T_Text" Type="Self.T_Text" Multiplicity="1" />
26
+          <End Role="T_SqlManager" Type="Self.T_SqlManager" Multiplicity="*" />
27
+          <ReferentialConstraint>
28
+            <Principal Role="T_Text">
29
+              <PropertyRef Name="id" />
30
+            </Principal>
31
+            <Dependent Role="T_SqlManager">
32
+              <PropertyRef Name="text" />
33
+            </Dependent>
34
+          </ReferentialConstraint>
35
+        </Association>
16
         <EntityContainer Name="ModelStoreContainer">
36
         <EntityContainer Name="ModelStoreContainer">
17
           <EntitySet Name="T_SqlManager" EntityType="Self.T_SqlManager" Schema="dbo" store:Type="Tables" />
37
           <EntitySet Name="T_SqlManager" EntityType="Self.T_SqlManager" Schema="dbo" store:Type="Tables" />
38
+          <EntitySet Name="T_Text" EntityType="Self.T_Text" Schema="dbo" store:Type="Tables" />
39
+          <AssociationSet Name="FK_T_SqlManager_T_Text" Association="Self.FK_T_SqlManager_T_Text">
40
+            <End Role="T_Text" EntitySet="T_Text" />
41
+            <End Role="T_SqlManager" EntitySet="T_SqlManager" />
42
+          </AssociationSet>
18
         </EntityContainer>
43
         </EntityContainer>
19
       </Schema></edmx:StorageModels>
44
       </Schema></edmx:StorageModels>
20
     <!-- CSDL content -->
45
     <!-- CSDL content -->
22
       <Schema Namespace="Model" Alias="Self" annotation:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
47
       <Schema Namespace="Model" Alias="Self" annotation:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
23
         <EntityContainer Name="SqlServerManagerEntities" annotation:LazyLoadingEnabled="true">
48
         <EntityContainer Name="SqlServerManagerEntities" annotation:LazyLoadingEnabled="true">
24
           <EntitySet Name="T_SqlManager" EntityType="Model.T_SqlManager" />
49
           <EntitySet Name="T_SqlManager" EntityType="Model.T_SqlManager" />
50
+          <EntitySet Name="T_Text" EntityType="Model.T_Text" />
51
+          <AssociationSet Name="FK_T_SqlManager_T_Text" Association="Model.FK_T_SqlManager_T_Text">
52
+            <End Role="T_Text" EntitySet="T_Text" />
53
+            <End Role="T_SqlManager" EntitySet="T_SqlManager" />
54
+          </AssociationSet>
25
         </EntityContainer>
55
         </EntityContainer>
26
         <EntityType Name="T_SqlManager">
56
         <EntityType Name="T_SqlManager">
27
           <Key>
57
           <Key>
30
           <Property Name="id" Type="Int64" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
60
           <Property Name="id" Type="Int64" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
31
           <Property Name="my_string" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="false" />
61
           <Property Name="my_string" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="false" />
32
           <Property Name="my_int" Type="Int32" Nullable="false" />
62
           <Property Name="my_int" Type="Int32" Nullable="false" />
63
+          <Property Name="text" Type="Int64" Nullable="false" />
64
+          <NavigationProperty Name="T_Text" Relationship="Model.FK_T_SqlManager_T_Text" FromRole="T_SqlManager" ToRole="T_Text" />
65
+        </EntityType>
66
+        <EntityType Name="T_Text">
67
+          <Key>
68
+            <PropertyRef Name="id" />
69
+          </Key>
70
+          <Property Name="id" Type="Int64" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
71
+          <Property Name="text" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="false" />
72
+          <NavigationProperty Name="T_SqlManager" Relationship="Model.FK_T_SqlManager_T_Text" FromRole="T_Text" ToRole="T_SqlManager" />
33
         </EntityType>
73
         </EntityType>
74
+        <Association Name="FK_T_SqlManager_T_Text">
75
+          <End Type="Model.T_Text" Role="T_Text" Multiplicity="1" />
76
+          <End Type="Model.T_SqlManager" Role="T_SqlManager" Multiplicity="*" />
77
+          <ReferentialConstraint>
78
+            <Principal Role="T_Text">
79
+              <PropertyRef Name="id" />
80
+            </Principal>
81
+            <Dependent Role="T_SqlManager">
82
+              <PropertyRef Name="text" />
83
+            </Dependent>
84
+          </ReferentialConstraint>
85
+        </Association>
34
       </Schema>
86
       </Schema>
35
     </edmx:ConceptualModels>
87
     </edmx:ConceptualModels>
36
     <!-- C-S mapping content -->
88
     <!-- C-S mapping content -->
40
           <EntitySetMapping Name="T_SqlManager">
92
           <EntitySetMapping Name="T_SqlManager">
41
             <EntityTypeMapping TypeName="Model.T_SqlManager">
93
             <EntityTypeMapping TypeName="Model.T_SqlManager">
42
               <MappingFragment StoreEntitySet="T_SqlManager">
94
               <MappingFragment StoreEntitySet="T_SqlManager">
95
+                <ScalarProperty Name="text" ColumnName="text" />
43
                 <ScalarProperty Name="my_int" ColumnName="my_int" />
96
                 <ScalarProperty Name="my_int" ColumnName="my_int" />
44
                 <ScalarProperty Name="my_string" ColumnName="my_string" />
97
                 <ScalarProperty Name="my_string" ColumnName="my_string" />
45
                 <ScalarProperty Name="id" ColumnName="id" />
98
                 <ScalarProperty Name="id" ColumnName="id" />
46
               </MappingFragment>
99
               </MappingFragment>
47
             </EntityTypeMapping>
100
             </EntityTypeMapping>
48
           </EntitySetMapping>
101
           </EntitySetMapping>
102
+          <EntitySetMapping Name="T_Text">
103
+            <EntityTypeMapping TypeName="Model.T_Text">
104
+              <MappingFragment StoreEntitySet="T_Text">
105
+                <ScalarProperty Name="text" ColumnName="text" />
106
+                <ScalarProperty Name="id" ColumnName="id" />
107
+              </MappingFragment>
108
+            </EntityTypeMapping>
109
+          </EntitySetMapping>
49
         </EntityContainerMapping>
110
         </EntityContainerMapping>
50
       </Mapping>
111
       </Mapping>
51
     </edmx:Mappings>
112
     </edmx:Mappings>

+ 3
- 1
WebAPiUtils-test/DataAccess/SqlServerManager.edmx.diagram View File

5
     <!-- Diagram content (shape and connector positions) -->
5
     <!-- Diagram content (shape and connector positions) -->
6
     <edmx:Diagrams>
6
     <edmx:Diagrams>
7
       <Diagram DiagramId="08dc5c61470647c385ff700da7502692" Name="Diagram1">
7
       <Diagram DiagramId="08dc5c61470647c385ff700da7502692" Name="Diagram1">
8
-        <EntityTypeShape EntityType="Model.T_SqlManager" Width="1.5" PointX="0.75" PointY="0.75" />
8
+        <EntityTypeShape EntityType="Model.T_SqlManager" Width="1.5" PointX="3" PointY="0.875" />
9
+        <EntityTypeShape EntityType="Model.T_Text" Width="1.5" PointX="0.75" PointY="1.125" />
10
+        <AssociationConnector Association="Model.FK_T_SqlManager_T_Text" />
9
       </Diagram>
11
       </Diagram>
10
     </edmx:Diagrams>
12
     </edmx:Diagrams>
11
   </edmx:Designer>
13
   </edmx:Designer>

+ 3
- 0
WebAPiUtils-test/DataAccess/T_SqlManager.cs View File

17
         public long id { get; set; }
17
         public long id { get; set; }
18
         public string my_string { get; set; }
18
         public string my_string { get; set; }
19
         public int my_int { get; set; }
19
         public int my_int { get; set; }
20
+        public long text { get; set; }
21
+    
22
+        public virtual T_Text T_Text { get; set; }
20
     }
23
     }
21
 }
24
 }

+ 27
- 0
WebAPiUtils-test/DataAccess/T_Text.cs View File

1
+//------------------------------------------------------------------------------
2
+// <auto-generated>
3
+//     This code was generated from a template.
4
+//
5
+//     Manual changes to this file may cause unexpected behavior in your application.
6
+//     Manual changes to this file will be overwritten if the code is regenerated.
7
+// </auto-generated>
8
+//------------------------------------------------------------------------------
9
+
10
+namespace WebAPiUtils_test.DataAccess
11
+{
12
+    using System;
13
+    using System.Collections.Generic;
14
+    
15
+    public partial class T_Text
16
+    {
17
+        public T_Text()
18
+        {
19
+            this.T_SqlManager = new HashSet<T_SqlManager>();
20
+        }
21
+    
22
+        public long id { get; set; }
23
+        public string text { get; set; }
24
+    
25
+        public virtual ICollection<T_SqlManager> T_SqlManager { get; set; }
26
+    }
27
+}

+ 25
- 13
WebAPiUtils-test/DataAccess/ValuesManager.cs View File

1
 using System.Collections.Generic;
1
 using System.Collections.Generic;
2
 using System.Data.Entity;
2
 using System.Data.Entity;
3
-using System.Security;
4
 using iiie.Logs.DBO;
3
 using iiie.Logs.DBO;
5
 using iiie.WebApiUtils.BusinessManager;
4
 using iiie.WebApiUtils.BusinessManager;
6
 using WebAPiUtils_test.DBO;
5
 using WebAPiUtils_test.DBO;
7
 
6
 
8
 namespace WebAPiUtils_test.DataAccess
7
 namespace WebAPiUtils_test.DataAccess
9
 {
8
 {
10
-    public class ValuesManager : SqlServerManager<T_SqlManager, ValuesDbo, SqlServerManagerEntities, ValuesManager>
9
+    public class ValuesManager : SqlServerManager<T_SqlManager, ValuesDboGet, ValuesDboAdd, ValuesDboEdit, SqlServerManagerEntities, ValuesManager>
11
     {
10
     {
12
         public override DbSet<T_SqlManager> GetTable(SqlServerManagerEntities db)
11
         public override DbSet<T_SqlManager> GetTable(SqlServerManagerEntities db)
13
         {
12
         {
14
             return db.T_SqlManager;
13
             return db.T_SqlManager;
15
         }
14
         }
16
 
15
 
17
-        public override ValuesDbo DbToDbo(T_SqlManager o)
16
+        public override ValuesDboGet DbToDboGet(T_SqlManager obj)
18
         {
17
         {
19
-            return new ValuesDbo
18
+            return new ValuesDboGet
20
             {
19
             {
21
-                Id = o.id,
22
-                MyInt = o.my_int,
23
-                MyString = o.my_string
20
+                Id = obj.id,
21
+                MyInt = obj.my_int,
22
+                MyString = obj.my_string,
23
+                Text = obj.T_Text.text,
24
+                TextId = obj.text
24
             };
25
             };
25
         }
26
         }
26
 
27
 
27
-        public override T_SqlManager DboToDb(ValuesDbo o)
28
+        public override T_SqlManager DboAddToDb(ValuesDboAdd obj)
28
         {
29
         {
29
             return new T_SqlManager
30
             return new T_SqlManager
30
             {
31
             {
31
-                id = o.Id,
32
-                my_int = o.MyInt,
33
-                my_string = o.MyString
32
+                my_string = obj.MyString,
33
+                my_int = obj.MyInt,
34
+                text = obj.TextId
34
             };
35
             };
35
         }
36
         }
36
 
37
 
37
-        public static OpResult<IEnumerable<ValuesDbo>> Contains(string text)
38
+        public override T_SqlManager DboEditToDb(ValuesDboEdit obj, T_SqlManager edit)
38
         {
39
         {
39
-            return GetMultipleDbo(x => x.my_string.Contains(text));
40
+            return new T_SqlManager
41
+            {
42
+                id = edit.id,
43
+                my_string = obj.MyString,
44
+                my_int = obj.MyInt,
45
+                text = obj.TextId
46
+            };
47
+        }
48
+
49
+        public static OpResult<IEnumerable<ValuesDboGet>> Contains(string text, int page, int perPage)
50
+        {
51
+            return GetMultiple(x => x.my_string.Contains(text), x => x.id, page, perPage);
40
         }
52
         }
41
     }
53
     }
42
 }
54
 }

+ 7
- 3
WebAPiUtils-test/WebAPiUtils-test.csproj View File

48
       <Private>True</Private>
48
       <Private>True</Private>
49
     </Reference>
49
     </Reference>
50
     <Reference Include="Logs, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
50
     <Reference Include="Logs, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
51
-      <HintPath>..\packages\Logs.dll.1.2.1\lib\net45\Logs.dll</HintPath>
51
+      <HintPath>..\packages\Logs.dll.1.2.2\lib\net45\Logs.dll</HintPath>
52
       <Private>True</Private>
52
       <Private>True</Private>
53
     </Reference>
53
     </Reference>
54
     <Reference Include="Microsoft.CSharp" />
54
     <Reference Include="Microsoft.CSharp" />
187
     <Compile Include="DataAccess\T_SqlManager.cs">
187
     <Compile Include="DataAccess\T_SqlManager.cs">
188
       <DependentUpon>SqlServerManager.tt</DependentUpon>
188
       <DependentUpon>SqlServerManager.tt</DependentUpon>
189
     </Compile>
189
     </Compile>
190
+    <Compile Include="DataAccess\T_Text.cs">
191
+      <DependentUpon>SqlServerManager.tt</DependentUpon>
192
+    </Compile>
190
     <Compile Include="DataAccess\ValuesManager.cs" />
193
     <Compile Include="DataAccess\ValuesManager.cs" />
191
-    <Compile Include="DBO\MyDbo.cs" />
192
-    <Compile Include="DBO\ValuesDbo.cs" />
194
+    <Compile Include="DBO\ValuesDboAdd.cs" />
195
+    <Compile Include="DBO\ValuesDboEdit.cs" />
196
+    <Compile Include="DBO\ValuesDboGet.cs" />
193
     <Compile Include="Global.asax.cs">
197
     <Compile Include="Global.asax.cs">
194
       <DependentUpon>Global.asax</DependentUpon>
198
       <DependentUpon>Global.asax</DependentUpon>
195
     </Compile>
199
     </Compile>

+ 1
- 1
WebAPiUtils-test/packages.config View File

8
   <package id="EnterpriseLibrary.Logging.Database" version="6.0.1304.0" targetFramework="net45" />
8
   <package id="EnterpriseLibrary.Logging.Database" version="6.0.1304.0" targetFramework="net45" />
9
   <package id="EntityFramework" version="6.1.3" targetFramework="net45" />
9
   <package id="EntityFramework" version="6.1.3" targetFramework="net45" />
10
   <package id="jQuery" version="1.10.2" targetFramework="net45" />
10
   <package id="jQuery" version="1.10.2" targetFramework="net45" />
11
-  <package id="Logs.dll" version="1.2.1" targetFramework="net45" />
11
+  <package id="Logs.dll" version="1.2.2" targetFramework="net45" />
12
   <package id="Microsoft.AspNet.Mvc" version="5.0.0" targetFramework="net45" />
12
   <package id="Microsoft.AspNet.Mvc" version="5.0.0" targetFramework="net45" />
13
   <package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net45" />
13
   <package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net45" />
14
   <package id="Microsoft.AspNet.Web.Optimization" version="1.1.1" targetFramework="net45" />
14
   <package id="Microsoft.AspNet.Web.Optimization" version="1.1.1" targetFramework="net45" />

+ 1
- 1
WebApiUtils/WebApiUtils.nuspec View File

2
 <package >
2
 <package >
3
   <metadata>
3
   <metadata>
4
     <id>3ieWebApiUtils.dll</id>
4
     <id>3ieWebApiUtils.dll</id>
5
-    <version>1.2.0</version>
5
+    <version>2.0.0</version>
6
     <title>Web Api Utils</title>
6
     <title>Web Api Utils</title>
7
     <authors>robin.thoni</authors>
7
     <authors>robin.thoni</authors>
8
     <owners>robin.thoni</owners>
8
     <owners>robin.thoni</owners>

Loading…
Cancel
Save