Pārlūkot izejas kodu

[WebApiUtils] tests

feature/authentication-tests
Robin Thoni 9 gadus atpakaļ
vecāks
revīzija
de94054070

+ 9
- 5
WebAPiUtils-test/BusinessManager/ValuesBusiness.cs Parādīt failu

@@ -7,15 +7,19 @@ namespace WebAPiUtils_test.BusinessManager
7 7
 {
8 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 Parādīt failu

@@ -9,38 +9,25 @@ namespace WebAPiUtils_test.Controllers
9 9
 {
10 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 19
         [HttpGet]
25 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 Parādīt failu

@@ -1,13 +0,0 @@
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 Parādīt failu

@@ -0,0 +1,7 @@
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 Parādīt failu

@@ -1,12 +1,12 @@
1 1
 
2 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 6
         public string MyString { get; set; }
9 7
 
10 8
         public int MyInt { get; set; }
9
+
10
+        public long TextId { get; set; }
11 11
     }
12 12
 }

+ 10
- 0
WebAPiUtils-test/DBO/ValuesDboGet.cs Parādīt failu

@@ -0,0 +1,10 @@
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 Parādīt failu

@@ -26,5 +26,6 @@ namespace WebAPiUtils_test.DataAccess
26 26
         }
27 27
     
28 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 Parādīt failu

@@ -12,9 +12,34 @@
12 12
           <Property Name="id" Type="bigint" StoreGeneratedPattern="Identity" Nullable="false" />
13 13
           <Property Name="my_string" Type="varchar" MaxLength="50" Nullable="false" />
14 14
           <Property Name="my_int" Type="int" Nullable="false" />
15
+          <Property Name="text" Type="bigint" Nullable="false" />
15 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 36
         <EntityContainer Name="ModelStoreContainer">
17 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 43
         </EntityContainer>
19 44
       </Schema></edmx:StorageModels>
20 45
     <!-- CSDL content -->
@@ -22,6 +47,11 @@
22 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 48
         <EntityContainer Name="SqlServerManagerEntities" annotation:LazyLoadingEnabled="true">
24 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 55
         </EntityContainer>
26 56
         <EntityType Name="T_SqlManager">
27 57
           <Key>
@@ -30,7 +60,29 @@
30 60
           <Property Name="id" Type="Int64" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
31 61
           <Property Name="my_string" Type="String" Nullable="false" MaxLength="50" FixedLength="false" Unicode="false" />
32 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 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 86
       </Schema>
35 87
     </edmx:ConceptualModels>
36 88
     <!-- C-S mapping content -->
@@ -40,12 +92,21 @@
40 92
           <EntitySetMapping Name="T_SqlManager">
41 93
             <EntityTypeMapping TypeName="Model.T_SqlManager">
42 94
               <MappingFragment StoreEntitySet="T_SqlManager">
95
+                <ScalarProperty Name="text" ColumnName="text" />
43 96
                 <ScalarProperty Name="my_int" ColumnName="my_int" />
44 97
                 <ScalarProperty Name="my_string" ColumnName="my_string" />
45 98
                 <ScalarProperty Name="id" ColumnName="id" />
46 99
               </MappingFragment>
47 100
             </EntityTypeMapping>
48 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 110
         </EntityContainerMapping>
50 111
       </Mapping>
51 112
     </edmx:Mappings>

+ 3
- 1
WebAPiUtils-test/DataAccess/SqlServerManager.edmx.diagram Parādīt failu

@@ -5,7 +5,9 @@
5 5
     <!-- Diagram content (shape and connector positions) -->
6 6
     <edmx:Diagrams>
7 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 11
       </Diagram>
10 12
     </edmx:Diagrams>
11 13
   </edmx:Designer>

+ 3
- 0
WebAPiUtils-test/DataAccess/T_SqlManager.cs Parādīt failu

@@ -17,5 +17,8 @@ namespace WebAPiUtils_test.DataAccess
17 17
         public long id { get; set; }
18 18
         public string my_string { get; set; }
19 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 Parādīt failu

@@ -0,0 +1,27 @@
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 Parādīt failu

@@ -1,42 +1,54 @@
1 1
 using System.Collections.Generic;
2 2
 using System.Data.Entity;
3
-using System.Security;
4 3
 using iiie.Logs.DBO;
5 4
 using iiie.WebApiUtils.BusinessManager;
6 5
 using WebAPiUtils_test.DBO;
7 6
 
8 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 11
         public override DbSet<T_SqlManager> GetTable(SqlServerManagerEntities db)
13 12
         {
14 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 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 Parādīt failu

@@ -48,7 +48,7 @@
48 48
       <Private>True</Private>
49 49
     </Reference>
50 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 52
       <Private>True</Private>
53 53
     </Reference>
54 54
     <Reference Include="Microsoft.CSharp" />
@@ -187,9 +187,13 @@
187 187
     <Compile Include="DataAccess\T_SqlManager.cs">
188 188
       <DependentUpon>SqlServerManager.tt</DependentUpon>
189 189
     </Compile>
190
+    <Compile Include="DataAccess\T_Text.cs">
191
+      <DependentUpon>SqlServerManager.tt</DependentUpon>
192
+    </Compile>
190 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 197
     <Compile Include="Global.asax.cs">
194 198
       <DependentUpon>Global.asax</DependentUpon>
195 199
     </Compile>

+ 1
- 1
WebAPiUtils-test/packages.config Parādīt failu

@@ -8,7 +8,7 @@
8 8
   <package id="EnterpriseLibrary.Logging.Database" version="6.0.1304.0" targetFramework="net45" />
9 9
   <package id="EntityFramework" version="6.1.3" targetFramework="net45" />
10 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 12
   <package id="Microsoft.AspNet.Mvc" version="5.0.0" targetFramework="net45" />
13 13
   <package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net45" />
14 14
   <package id="Microsoft.AspNet.Web.Optimization" version="1.1.1" targetFramework="net45" />

+ 1
- 1
WebApiUtils/WebApiUtils.nuspec Parādīt failu

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

Notiek ielāde…
Atcelt
Saglabāt