From 3be9542cce59e28cc003bbe6468fbccff23cc2eb Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 9 Jan 2019 12:31:07 -0500 Subject: [PATCH] Core.Test with example test using nsub and xunit --- bitwarden-core.sln | 2 +- .../Core.Test.csproj} | 4 ++ test/Core.Test/Services/DeviceServiceTests.cs | 37 +++++++++++++++++++ test/Core/UnitTest1.cs | 14 ------- 4 files changed, 42 insertions(+), 15 deletions(-) rename test/{Core/Core.csproj => Core.Test/Core.Test.csproj} (87%) create mode 100644 test/Core.Test/Services/DeviceServiceTests.cs delete mode 100644 test/Core/UnitTest1.cs diff --git a/bitwarden-core.sln b/bitwarden-core.sln index 58905abee..becd58e82 100644 --- a/bitwarden-core.sln +++ b/bitwarden-core.sln @@ -45,7 +45,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Admin", "src\Admin\Admin.cs EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notifications", "src\Notifications\Notifications.csproj", "{28635027-20E5-42FA-B218-B6C878DE5350}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "test\Core\Core.csproj", "{8EF31E6C-400A-4174-8BE3-502B08FB10B5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Test", "test\Core.Test\Core.Test.csproj", "{8EF31E6C-400A-4174-8BE3-502B08FB10B5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/test/Core/Core.csproj b/test/Core.Test/Core.Test.csproj similarity index 87% rename from test/Core/Core.csproj rename to test/Core.Test/Core.Test.csproj index 1c8537508..0b9ad16ac 100644 --- a/test/Core/Core.csproj +++ b/test/Core.Test/Core.Test.csproj @@ -16,4 +16,8 @@ + + + + diff --git a/test/Core.Test/Services/DeviceServiceTests.cs b/test/Core.Test/Services/DeviceServiceTests.cs new file mode 100644 index 000000000..00617d4c2 --- /dev/null +++ b/test/Core.Test/Services/DeviceServiceTests.cs @@ -0,0 +1,37 @@ +using System; +using System.Threading.Tasks; +using Bit.Core.Repositories; +using Bit.Core.Services; +using NSubstitute; +using Xunit; + +namespace Bit.Core.Test.Services +{ + public class DeviceServiceTests + { + [Fact] + public async Task DeviceSaveShouldUpdateRevisionDateAndPushRegistration() + { + var deviceRepo = Substitute.For(); + var pushRepo = Substitute.For(); + var deviceService = new DeviceService(deviceRepo, pushRepo); + + var id = Guid.NewGuid(); + var userId = Guid.NewGuid(); + var device = new Models.Table.Device + { + Id = id, + Name = "test device", + Type = Enums.DeviceType.Android, + UserId = userId, + PushToken = "testtoken", + Identifier = "testid" + }; + await deviceService.SaveAsync(device); + + Assert.True(device.RevisionDate - DateTime.UtcNow < TimeSpan.FromSeconds(1)); + await pushRepo.Received().CreateOrUpdateRegistrationAsync("testtoken", id.ToString(), + userId.ToString(), "testid", Enums.DeviceType.Android); + } + } +} diff --git a/test/Core/UnitTest1.cs b/test/Core/UnitTest1.cs deleted file mode 100644 index 869e0e732..000000000 --- a/test/Core/UnitTest1.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using Xunit; - -namespace Bit.Core.Test -{ - public class UnitTest1 - { - [Fact] - public void Test1() - { - Assert.True(true); - } - } -}