Permalink
Browse files

updated controllers to di tgimbaservice, added controller tests and s…

…ome other things
  • Loading branch information...
ehelin committed Jun 16, 2018
1 parent 51e26d8 commit 35e35c0d33ae0764ae1032a72a68ac78621897df
@@ -24,7 +24,7 @@ public class MembershipSql
+ " select 0 ";
public const string ADD_USER_TOKEN = "UPDATE [Bucket].[User] SET [Token] = @Token WHERE UserName = @UserName";
public const string DELETE_USER = "delete from [Bucket].[User] where UserName = @userName and [PassWord] = @passWord and Email = @email";
public const string DELETE_USER = "delete from [Bucket].[User] where UserName = @userName and Email = @email";
public const string LOG_ACTION = "INSERT INTO [Bucket].[Log] select @LogMessage, getdate()";
}
}
@@ -169,7 +169,8 @@ public bool DeleteUser(string userName, string passWord, string email)
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.Add(new SqlParameter("@userName", userName));
cmd.Parameters.Add(new SqlParameter("@passWord", passWord));
// TODO - either work in getting the encrypted password or remove from here
//cmd.Parameters.Add(new SqlParameter("@passWord", passWord));
cmd.Parameters.Add(new SqlParameter("@email", email));
cmd.Connection.Open();
@@ -39,6 +39,9 @@ public void GetDashboardTest()
[TestMethod]
public void RunApiIntegrationTest()
{
//clean up in case these tests get our of sync
DeleteUser(user, email, password);
ProcessUserRegistrationTest();
string token = ProcessUserTest();
UpsertBucketListItemTest(token, "list item name");
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Text;
using Shared.interfaces;
using Moq;
namespace TestTgimbaNetCoreWeb
{
public class BaseTest
{
protected Mock<ITgimbaService> mockITgimbaService { get; set; }
public BaseTest()
{
mockITgimbaService = new Mock<ITgimbaService>();
//add each method as tests are implemented
SetupGetDashboard();
}
private void SetupGetDashboard()
{
string[] data = new string[]
{
"result 1", "result 2", "result 3", "result 4", "result 5",
"result 6", "result 7", "result 8", "result 9", "result 10"
};
mockITgimbaService.Setup(x => x.GetDashboard()).Returns(data);
}
}
}
@@ -0,0 +1,21 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TgimbaNetCoreWeb.Controllers;
using Microsoft.AspNetCore.Mvc;
using Shared.interfaces;
namespace TestTgimbaNetCoreWeb
{
[TestClass]
public class HomeControllerTest : BaseTest
{
[TestMethod]
public void TestHomeControllerIndex()
{
HomeController homeController = new HomeController(this.mockITgimbaService.Object);
IActionResult result = homeController.Index();
ViewResult view = (ViewResult)result;
Assert.IsNotNull(view);
}
}
}
@@ -0,0 +1,22 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TgimbaNetCoreWeb.Controllers;
using TgimbaNetCoreWeb.Models;
using Microsoft.AspNetCore.Mvc;
namespace TestTgimbaNetCoreWeb
{
[TestClass]
public class WelcomeControllerTest : BaseTest
{
[TestMethod]
public void TestWelcomeControllerIndex()
{
WelcomeController welcomeController = new WelcomeController(this.mockITgimbaService.Object);
IActionResult result = welcomeController.Index();
ViewResult view = (ViewResult)result;
Assert.IsNotNull(view);
Assert.IsNotNull(view.Model);
}
}
}
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0" />
<PackageReference Include="Moq" Version="4.8.3" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
<ProjectReference Include="..\TgimbaNetCoreWeb\TgimbaNetCoreWeb.csproj" />
</ItemGroup>
</Project>
@@ -1,6 +1,7 @@
using Shared.interfaces;
using DAL.providers;
using Shared;
using Shared.misc;
namespace TestsDAL
{
@@ -11,9 +12,8 @@ public class BaseTest
public BaseTest()
{
// NOTE: Credentials is a local file that needs to be added
//bdb = new BucketListData(Credentials.GetDbConnection());
//mdb = new MemberShipData(Credentials.GetDbConnection());
bdb = new BucketListData(Utilities.GetDbSetting());
mdb = new MemberShipData(Utilities.GetDbSetting());
}
protected string GetBucketListItemDbId(string singleLineBucketListItem)
@@ -10,13 +10,18 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestsDAL", "TestsDAL\TestsDAL.csproj", "{7AEC3ADE-D43E-4758-8B57-10125D2CDC87}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4584033D-F538-457D-AB20-588B537A7865}"
ProjectSection(SolutionItems) = preProject
Todo.txt = Todo.txt
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API", "API\API.csproj", "{7E8FA25C-A969-4229-BC9F-36BA4BD71187}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestAPI", "TestAPI\TestAPI.csproj", "{BA8F2896-10F0-41B8-B345-36C33983708B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TgimbaNetCoreWeb", "TgimbaNetCoreWeb\TgimbaNetCoreWeb.csproj", "{CF678192-CA9C-4ACD-B859-828F35EA5F8B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestTgimbaNetCoreWeb", "TestTgimbaNetCoreWeb\TestTgimbaNetCoreWeb.csproj", "{BCE35BDF-40CC-4ACE-9E2C-BF8C412A0C8E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -47,6 +52,10 @@ Global
{CF678192-CA9C-4ACD-B859-828F35EA5F8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF678192-CA9C-4ACD-B859-828F35EA5F8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF678192-CA9C-4ACD-B859-828F35EA5F8B}.Release|Any CPU.Build.0 = Release|Any CPU
{BCE35BDF-40CC-4ACE-9E2C-BF8C412A0C8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BCE35BDF-40CC-4ACE-9E2C-BF8C412A0C8E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BCE35BDF-40CC-4ACE-9E2C-BF8C412A0C8E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BCE35BDF-40CC-4ACE-9E2C-BF8C412A0C8E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -8,9 +8,9 @@ public class BaseController : Controller
{
protected ITgimbaService service = null;
public BaseController()
public BaseController(ITgimbaService service)
{
service = new TgimbaService();
this.service = service;
}
}
}
@@ -1,10 +1,14 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Shared.interfaces;
namespace TgimbaNetCoreWeb.Controllers
{
public class HomeController : BaseController
{
{
public HomeController(ITgimbaService service)
: base(service) { }
public IActionResult Index()
{
return View();
@@ -1,10 +1,14 @@
using Microsoft.AspNetCore.Mvc;
using TgimbaNetCoreWeb.Models;
using Shared.interfaces;
namespace TgimbaNetCoreWeb.Controllers
{
public class WelcomeController : BaseController
{
public WelcomeController(ITgimbaService service)
: base(service) { }
public IActionResult Index()
{
WelcomeModel model = new WelcomeModel(this.service);
@@ -7,6 +7,8 @@
using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Shared.interfaces;
using API;
namespace TgimbaNetCoreWeb
{
@@ -22,12 +24,26 @@ public Startup(IConfiguration configuration)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<ITgimbaService>(new TgimbaService());
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
//if (env.IsDevelopment())
//{
// app.UseDeveloperExceptionPage();
// app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
// {
// HotModuleReplacement = true
// });
//}
//else
//{
// app.UseExceptionHandler("/Home/Error");
//}
//app.UseStaticFiles();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
@@ -36,11 +52,8 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
HotModuleReplacement = true
});
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseMvc(routes =>
@@ -0,0 +1,2 @@
-Add .Net core web.config equivalent that forces SSL
-Automate build so you can get a copy of nuget/npm modules that don't require an update unless you want one

0 comments on commit 35e35c0

Please sign in to comment.