Skip to content

Commit cc298ba

Browse files
committed
add tests
1 parent bc46f05 commit cc298ba

File tree

6 files changed

+289
-0
lines changed

6 files changed

+289
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<configSections>
4+
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
5+
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
6+
</configSections>
7+
<entityFramework>
8+
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
9+
<parameters>
10+
<parameter value="mssqllocaldb" />
11+
</parameters>
12+
</defaultConnectionFactory>
13+
<providers>
14+
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
15+
</providers>
16+
</entityFramework>
17+
</configuration>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data.Entity;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace SignalRChatClient.Data.Tests
9+
{
10+
public class ChatClientTestContext : ChatClientDbContext
11+
{
12+
public ChatClientTestContext()
13+
{
14+
Database.SetInitializer<ChatClientDbContext>(new DropCreateDatabaseAlways<ChatClientDbContext>());
15+
}
16+
}
17+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("SignalRChatClient.Data.Tests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("SignalRChatClient.Data.Tests")]
13+
[assembly: AssemblyCopyright("Copyright © 2015")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("514e0037-2416-4bbf-91ea-28450a59fe10")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using Microsoft.VisualStudio.TestTools.UnitTesting;
5+
using SignalRChatClient.Domain;
6+
7+
namespace SignalRChatClient.Data.Tests
8+
{
9+
[TestClass]
10+
public class RepositoryTester
11+
{
12+
public TestContext TestContext { get; set; }
13+
private IRepository<User> _userRepository;
14+
private ChatClientDbContext _dbContext;
15+
16+
[TestInitialize]
17+
public void Initialize()
18+
{
19+
_dbContext = new ChatClientDbContext();
20+
_dbContext.Database.Create();
21+
22+
_userRepository = new EfRepository<User>(_dbContext);
23+
}
24+
25+
[TestCleanup]
26+
public void CleanUp()
27+
{
28+
_dbContext.Database.Delete();
29+
}
30+
31+
public void CreateSampleData()
32+
{
33+
_userRepository.Insert(new User
34+
{
35+
Id = Guid.NewGuid(),
36+
NickName = "test1",
37+
Username = "test1",
38+
CreatDateTime = DateTime.UtcNow
39+
});
40+
41+
_userRepository.Insert(new User
42+
{
43+
Id = Guid.NewGuid(),
44+
NickName = "test2",
45+
Username = "test2",
46+
CreatDateTime = DateTime.UtcNow
47+
});
48+
49+
_userRepository.Insert(new User
50+
{
51+
Id = Guid.NewGuid(),
52+
NickName = "test3",
53+
Username = "test3",
54+
CreatDateTime = DateTime.UtcNow
55+
});
56+
}
57+
58+
[TestMethod]
59+
public void InsertShouldCreateNewRow()
60+
{
61+
var oldCount = _userRepository.TableNoTracking.Count();
62+
63+
_userRepository.Insert(new User
64+
{
65+
Id = Guid.NewGuid(),
66+
NickName = "test",
67+
Username = "test"
68+
});
69+
70+
var newCount = _userRepository.TableNoTracking.Count();
71+
72+
Assert.IsTrue(oldCount + 1 == newCount);
73+
}
74+
75+
[TestMethod]
76+
public void InsertShouldCreateRecordWithTheSameId()
77+
{
78+
var guid = Guid.NewGuid();
79+
80+
_userRepository.Insert(new User
81+
{
82+
Id = guid,
83+
NickName = "test",
84+
Username = "test"
85+
});
86+
87+
var r = _userRepository.GetById(guid);
88+
Assert.AreEqual(r.NickName, "test");
89+
}
90+
91+
[TestMethod]
92+
public void GetWithZeroMatchesShouldReturnNull()
93+
{
94+
CreateSampleData();
95+
96+
var user = _userRepository.GetById(Guid.NewGuid());
97+
98+
Assert.IsNull(user);
99+
}
100+
}
101+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{CBFB510B-ABDF-49C4-B7A2-4A6C550CAEEB}</ProjectGuid>
7+
<OutputType>Library</OutputType>
8+
<AppDesignerFolder>Properties</AppDesignerFolder>
9+
<RootNamespace>SignalRChatClient.Data.Tests</RootNamespace>
10+
<AssemblyName>SignalRChatClient.Data.Tests</AssemblyName>
11+
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
15+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
16+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
17+
<IsCodedUITest>False</IsCodedUITest>
18+
<TestProjectType>UnitTest</TestProjectType>
19+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
20+
<RestorePackages>true</RestorePackages>
21+
</PropertyGroup>
22+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
23+
<DebugSymbols>true</DebugSymbols>
24+
<DebugType>full</DebugType>
25+
<Optimize>false</Optimize>
26+
<OutputPath>bin\Debug\</OutputPath>
27+
<DefineConstants>DEBUG;TRACE</DefineConstants>
28+
<ErrorReport>prompt</ErrorReport>
29+
<WarningLevel>4</WarningLevel>
30+
</PropertyGroup>
31+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
32+
<DebugType>pdbonly</DebugType>
33+
<Optimize>true</Optimize>
34+
<OutputPath>bin\Release\</OutputPath>
35+
<DefineConstants>TRACE</DefineConstants>
36+
<ErrorReport>prompt</ErrorReport>
37+
<WarningLevel>4</WarningLevel>
38+
</PropertyGroup>
39+
<ItemGroup>
40+
<Reference Include="EntityFramework">
41+
<HintPath>..\packages\EntityFramework.6.1.1\lib\net45\EntityFramework.dll</HintPath>
42+
</Reference>
43+
<Reference Include="EntityFramework.SqlServer">
44+
<HintPath>..\packages\EntityFramework.6.1.1\lib\net45\EntityFramework.SqlServer.dll</HintPath>
45+
</Reference>
46+
<Reference Include="System" />
47+
<Reference Include="System.ComponentModel.DataAnnotations" />
48+
</ItemGroup>
49+
<Choose>
50+
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
51+
<ItemGroup>
52+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
53+
</ItemGroup>
54+
</When>
55+
<Otherwise>
56+
<ItemGroup>
57+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
58+
</ItemGroup>
59+
</Otherwise>
60+
</Choose>
61+
<ItemGroup>
62+
<Compile Include="ChatClientTestContext.cs" />
63+
<Compile Include="RepositoryTester.cs" />
64+
<Compile Include="Properties\AssemblyInfo.cs" />
65+
</ItemGroup>
66+
<ItemGroup>
67+
<ProjectReference Include="..\src\SignalRChatClient.Data\SignalRChatClient.Data.csproj">
68+
<Project>{89d95519-a1b2-4a8b-9df6-4022f8aa0660}</Project>
69+
<Name>SignalRChatClient.Data</Name>
70+
</ProjectReference>
71+
<ProjectReference Include="..\src\SignalRChatClient.Domain\SignalRChatClient.Domain.csproj">
72+
<Project>{2c4222c0-0853-491d-a0d2-25212fd4da3b}</Project>
73+
<Name>SignalRChatClient.Domain</Name>
74+
</ProjectReference>
75+
</ItemGroup>
76+
<ItemGroup>
77+
<None Include="App.config" />
78+
<None Include="packages.config" />
79+
</ItemGroup>
80+
<Choose>
81+
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
82+
<ItemGroup>
83+
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
84+
<Private>False</Private>
85+
</Reference>
86+
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
87+
<Private>False</Private>
88+
</Reference>
89+
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
90+
<Private>False</Private>
91+
</Reference>
92+
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
93+
<Private>False</Private>
94+
</Reference>
95+
</ItemGroup>
96+
</When>
97+
</Choose>
98+
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
99+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
100+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
101+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
102+
<PropertyGroup>
103+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
104+
</PropertyGroup>
105+
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
106+
</Target>
107+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
108+
Other similar extension points exist, see Microsoft.Common.targets.
109+
<Target Name="BeforeBuild">
110+
</Target>
111+
<Target Name="AfterBuild">
112+
</Target>
113+
-->
114+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="EntityFramework" version="6.1.1" targetFramework="net451" />
4+
</packages>

0 commit comments

Comments
 (0)