From c5a59465df5712bf5eb23f7db31c405f48727a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 11 Dec 2016 17:52:42 +0300 Subject: [PATCH] Created integration test for AbpDesk --- Volo.Abp.sln | 17 +++++++++ global.json | 4 +- .../AbpDeskEntityFrameworkCoreModule.cs | 8 ++-- src/Volo.Abp.TestBase/AbpIntegratedTest.cs | 38 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 19 ++++++++++ src/Volo.Abp.TestBase/Volo.Abp.TestBase.xproj | 21 ++++++++++ src/Volo.Abp.TestBase/project.json | 14 +++++++ .../AbpDesk.Application.Tests.xproj | 23 +++++++++++ .../AbpDesk/AbpDeskApplicationTestBase.cs | 27 +++++++++++++ .../AbpDesk/AbpDeskApplicationTestModule.cs | 20 ++++++++++ .../AbpDesk/Tickets/TicketAppService_Tests.cs | 28 ++++++++++++++ .../Properties/AssemblyInfo.cs | 19 ++++++++++ .../AbpDesk.Application.Tests/project.json | 24 ++++++++++++ 13 files changed, 256 insertions(+), 6 deletions(-) create mode 100644 src/Volo.Abp.TestBase/AbpIntegratedTest.cs create mode 100644 src/Volo.Abp.TestBase/Properties/AssemblyInfo.cs create mode 100644 src/Volo.Abp.TestBase/Volo.Abp.TestBase.xproj create mode 100644 src/Volo.Abp.TestBase/project.json create mode 100644 test/AbpDesk/AbpDesk.Application.Tests/AbpDesk.Application.Tests.xproj create mode 100644 test/AbpDesk/AbpDesk.Application.Tests/AbpDesk/AbpDeskApplicationTestBase.cs create mode 100644 test/AbpDesk/AbpDesk.Application.Tests/AbpDesk/AbpDeskApplicationTestModule.cs create mode 100644 test/AbpDesk/AbpDesk.Application.Tests/AbpDesk/Tickets/TicketAppService_Tests.cs create mode 100644 test/AbpDesk/AbpDesk.Application.Tests/Properties/AssemblyInfo.cs create mode 100644 test/AbpDesk/AbpDesk.Application.Tests/project.json diff --git a/Volo.Abp.sln b/Volo.Abp.sln index 74d61636b3..edd459ab29 100644 --- a/Volo.Abp.sln +++ b/Volo.Abp.sln @@ -68,6 +68,12 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Volo.Abp.AspNetCore.Mvc", " EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Volo.Abp.ApplicationContracts", "src\Volo.Abp.ApplicationContracts\Volo.Abp.ApplicationContracts.xproj", "{69C72C98-B864-43F7-88B8-19536C7C9B43}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AbpDesk", "AbpDesk", "{61708AC8-CE70-4351-9B31-13EA8213D208}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "AbpDesk.Application.Tests", "test\AbpDesk\AbpDesk.Application.Tests\AbpDesk.Application.Tests.xproj", "{E6E2467C-184A-4A0A-929F-932D5097953E}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Volo.Abp.TestBase", "src\Volo.Abp.TestBase\Volo.Abp.TestBase.xproj", "{8CECCEAF-F0D8-4257-96BA-EACF4763AF42}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -166,6 +172,14 @@ Global {69C72C98-B864-43F7-88B8-19536C7C9B43}.Debug|Any CPU.Build.0 = Debug|Any CPU {69C72C98-B864-43F7-88B8-19536C7C9B43}.Release|Any CPU.ActiveCfg = Release|Any CPU {69C72C98-B864-43F7-88B8-19536C7C9B43}.Release|Any CPU.Build.0 = Release|Any CPU + {E6E2467C-184A-4A0A-929F-932D5097953E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E6E2467C-184A-4A0A-929F-932D5097953E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E6E2467C-184A-4A0A-929F-932D5097953E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E6E2467C-184A-4A0A-929F-932D5097953E}.Release|Any CPU.Build.0 = Release|Any CPU + {8CECCEAF-F0D8-4257-96BA-EACF4763AF42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8CECCEAF-F0D8-4257-96BA-EACF4763AF42}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8CECCEAF-F0D8-4257-96BA-EACF4763AF42}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8CECCEAF-F0D8-4257-96BA-EACF4763AF42}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -199,5 +213,8 @@ Global {1A1575D7-E57E-4A40-8113-FD01BB1753D5} = {1187F469-0063-4065-9419-A1D956C80145} {3FB342CA-23B6-4795-91EF-C664527C07B7} = {4C753F64-0C93-4D65-96C2-A40893AFC1E8} {69C72C98-B864-43F7-88B8-19536C7C9B43} = {4C753F64-0C93-4D65-96C2-A40893AFC1E8} + {61708AC8-CE70-4351-9B31-13EA8213D208} = {447C8A77-E5F0-4538-8687-7383196D04EA} + {E6E2467C-184A-4A0A-929F-932D5097953E} = {61708AC8-CE70-4351-9B31-13EA8213D208} + {8CECCEAF-F0D8-4257-96BA-EACF4763AF42} = {4C753F64-0C93-4D65-96C2-A40893AFC1E8} EndGlobalSection EndGlobal diff --git a/global.json b/global.json index 9d09ab54cb..6bdcde3b48 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ -{ - "projects": [ "src", "test" ], +{ + "projects": [ "src", "test", "src/AbpDesk" ], "sdk": { "version": "1.0.0-preview2-003131" } diff --git a/src/AbpDesk/AbpDesk.EntityFrameworkCore/AbpDesk/EntityFrameworkCore/AbpDeskEntityFrameworkCoreModule.cs b/src/AbpDesk/AbpDesk.EntityFrameworkCore/AbpDesk/EntityFrameworkCore/AbpDeskEntityFrameworkCoreModule.cs index 3d54bb4518..cc78785467 100644 --- a/src/AbpDesk/AbpDesk.EntityFrameworkCore/AbpDesk/EntityFrameworkCore/AbpDeskEntityFrameworkCoreModule.cs +++ b/src/AbpDesk/AbpDesk.EntityFrameworkCore/AbpDesk/EntityFrameworkCore/AbpDeskEntityFrameworkCoreModule.cs @@ -16,10 +16,10 @@ namespace AbpDesk.EntityFrameworkCore services.AddTransient, EfCoreRepository>(); - services.AddDbContext(options => - { - options.UseSqlServer("Server=localhost;Database=AbpDesk;Trusted_Connection=True;"); - }); + //services.AddDbContext(options => + //{ + // options.UseSqlServer("Server=localhost;Database=AbpDesk;Trusted_Connection=True;"); + //}); } } } diff --git a/src/Volo.Abp.TestBase/AbpIntegratedTest.cs b/src/Volo.Abp.TestBase/AbpIntegratedTest.cs new file mode 100644 index 0000000000..8abd66c0dd --- /dev/null +++ b/src/Volo.Abp.TestBase/AbpIntegratedTest.cs @@ -0,0 +1,38 @@ +using System; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace Volo.Abp.TestBase +{ + public class AbpIntegratedTest : IDisposable + where TStartupModule : IAbpModule + { + + protected AbpApplication Application { get; } + + protected IServiceProvider ServiceProvider => Application.ServiceProvider; + + public AbpIntegratedTest() + { + var services = CreateServiceCollection(); + Application = AbpApplication.Create(services); + var serviceProvider = CreateServiceProvider(services); + Application.Initialize(serviceProvider); + } + + protected virtual IServiceCollection CreateServiceCollection() + { + return new ServiceCollection(); + } + + protected virtual IServiceProvider CreateServiceProvider(IServiceCollection services) + { + return services.BuildServiceProvider(); + } + + public void Dispose() + { + Application.Dispose(); + } + } +} diff --git a/src/Volo.Abp.TestBase/Properties/AssemblyInfo.cs b/src/Volo.Abp.TestBase/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..57250854c9 --- /dev/null +++ b/src/Volo.Abp.TestBase/Properties/AssemblyInfo.cs @@ -0,0 +1,19 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Volo.Abp.TestBase")] +[assembly: AssemblyTrademark("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("8cecceaf-f0d8-4257-96ba-eacf4763af42")] diff --git a/src/Volo.Abp.TestBase/Volo.Abp.TestBase.xproj b/src/Volo.Abp.TestBase/Volo.Abp.TestBase.xproj new file mode 100644 index 0000000000..14b8782246 --- /dev/null +++ b/src/Volo.Abp.TestBase/Volo.Abp.TestBase.xproj @@ -0,0 +1,21 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + 8cecceaf-f0d8-4257-96ba-eacf4763af42 + Volo.Abp.TestBase + .\obj + .\bin\ + v4.6.1 + + + + 2.0 + + + diff --git a/src/Volo.Abp.TestBase/project.json b/src/Volo.Abp.TestBase/project.json new file mode 100644 index 0000000000..863659ace7 --- /dev/null +++ b/src/Volo.Abp.TestBase/project.json @@ -0,0 +1,14 @@ +{ + "version": "1.0.0-*", + + "dependencies": { + "NETStandard.Library": "1.6.1", + "Volo.Abp": "1.0.0-*" + }, + + "frameworks": { + "netstandard1.6": { + "imports": "dnxcore50" + } + } +} diff --git a/test/AbpDesk/AbpDesk.Application.Tests/AbpDesk.Application.Tests.xproj b/test/AbpDesk/AbpDesk.Application.Tests/AbpDesk.Application.Tests.xproj new file mode 100644 index 0000000000..a800374f8a --- /dev/null +++ b/test/AbpDesk/AbpDesk.Application.Tests/AbpDesk.Application.Tests.xproj @@ -0,0 +1,23 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + e6e2467c-184a-4a0a-929f-932d5097953e + + + .\obj + .\bin\ + v4.6.1 + + + 2.0 + + + + + + \ No newline at end of file diff --git a/test/AbpDesk/AbpDesk.Application.Tests/AbpDesk/AbpDeskApplicationTestBase.cs b/test/AbpDesk/AbpDesk.Application.Tests/AbpDesk/AbpDeskApplicationTestBase.cs new file mode 100644 index 0000000000..b8cc03c03a --- /dev/null +++ b/test/AbpDesk/AbpDesk.Application.Tests/AbpDesk/AbpDeskApplicationTestBase.cs @@ -0,0 +1,27 @@ +using AbpDesk.EntityFrameworkCore; +using AbpDesk.Tickets; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.TestBase; + +namespace AbpDesk +{ + public abstract class AbpDeskApplicationTestBase : AbpIntegratedTest + { + protected AbpDeskApplicationTestBase() + { + SeedTestData(); + } + + protected virtual void SeedTestData() + { + using (var scope = ServiceProvider.CreateScope()) + { + var dbContext = scope.ServiceProvider.GetRequiredService(); + + dbContext.Set().Add(new Ticket("My test ticket 1 title", "My test ticket 1 body")); + + dbContext.SaveChanges(); + } + } + } +} \ No newline at end of file diff --git a/test/AbpDesk/AbpDesk.Application.Tests/AbpDesk/AbpDeskApplicationTestModule.cs b/test/AbpDesk/AbpDesk.Application.Tests/AbpDesk/AbpDeskApplicationTestModule.cs new file mode 100644 index 0000000000..54577e5c3a --- /dev/null +++ b/test/AbpDesk/AbpDesk.Application.Tests/AbpDesk/AbpDeskApplicationTestModule.cs @@ -0,0 +1,20 @@ +using AbpDesk.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace AbpDesk +{ + [DependsOn(typeof(AbpDeskApplicationModule), typeof(AbpDeskEntityFrameworkCoreModule))] + public class AbpDeskApplicationTestModule : AbpModule + { + public override void ConfigureServices(IServiceCollection services) + { + services.AddEntityFrameworkInMemoryDatabase(); + services.AddDbContext(options => + { + options.UseInMemoryDatabase(); + }); + } + } +} diff --git a/test/AbpDesk/AbpDesk.Application.Tests/AbpDesk/Tickets/TicketAppService_Tests.cs b/test/AbpDesk/AbpDesk.Application.Tests/AbpDesk/Tickets/TicketAppService_Tests.cs new file mode 100644 index 0000000000..2f0b511529 --- /dev/null +++ b/test/AbpDesk/AbpDesk.Application.Tests/AbpDesk/Tickets/TicketAppService_Tests.cs @@ -0,0 +1,28 @@ +using Microsoft.Extensions.DependencyInjection; +using Shouldly; +using Xunit; + +namespace AbpDesk.Tickets +{ + public class TicketAppService_Tests : AbpDeskApplicationTestBase + { + private readonly ITicketAppService _ticketAppService; + + public TicketAppService_Tests() + { + _ticketAppService = ServiceProvider.GetRequiredService(); + } + + [Fact] + public void GetAll_Test() + { + //Act + + var result = _ticketAppService.GetAll(); + + //Assert + + result.Items.Count.ShouldBeGreaterThan(0); + } + } +} diff --git a/test/AbpDesk/AbpDesk.Application.Tests/Properties/AssemblyInfo.cs b/test/AbpDesk/AbpDesk.Application.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..4181c29b68 --- /dev/null +++ b/test/AbpDesk/AbpDesk.Application.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,19 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("AbpDesk.Application.Tests")] +[assembly: AssemblyTrademark("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("e6e2467c-184a-4a0a-929f-932d5097953e")] diff --git a/test/AbpDesk/AbpDesk.Application.Tests/project.json b/test/AbpDesk/AbpDesk.Application.Tests/project.json new file mode 100644 index 0000000000..4ff1d373c2 --- /dev/null +++ b/test/AbpDesk/AbpDesk.Application.Tests/project.json @@ -0,0 +1,24 @@ +{ + "version": "1.0.0-*", + + "testRunner": "xunit", + + "dependencies": { + "AbpDesk.Application": "1.0.0-*", + "AbpDesk.EntityFrameworkCore": "1.0.0-*", + "AbpTestBase": "1.0.0-*", + "Microsoft.EntityFrameworkCore.InMemory": "1.1.0", + "Volo.Abp.TestBase": "1.0.0-*" + }, + + "frameworks": { + "netcoreapp1.1": { + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.1.0" + } + } + } + } +}