From 7f6ef0228d98a09da37b9718a2c3919cebeef083 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 15 Jul 2018 20:23:24 +0200 Subject: [PATCH] Added tests for GrainTagService. --- .../Tags/GrainTagServiceTests.cs | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/Squidex.Domain.Apps.Entities.Tests/Tags/GrainTagServiceTests.cs diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Tags/GrainTagServiceTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Tags/GrainTagServiceTests.cs new file mode 100644 index 000000000..f1aa0fd33 --- /dev/null +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Tags/GrainTagServiceTests.cs @@ -0,0 +1,75 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using FakeItEasy; +using Orleans; +using Xunit; + +namespace Squidex.Domain.Apps.Entities.Tags +{ + public class GrainTagServiceTests + { + private readonly IGrainFactory grainFactory = A.Fake(); + private readonly ITagGrain grain = A.Fake(); + private readonly Guid appId = Guid.NewGuid(); + private readonly GrainTagService sut; + + public GrainTagServiceTests() + { + A.CallTo(() => grainFactory.GetGrain($"{appId}_Assets", null)) + .Returns(grain); + + sut = new GrainTagService(grainFactory); + } + + [Fact] + public async Task Should_call_grain_when_retrieving_tas() + { + await sut.GetTagsAsync(appId, TagGroups.Assets); + + A.CallTo(() => grain.GetTagsAsync()) + .MustHaveHappened(); + } + + [Fact] + public async Task Should_call_grain_when_resolving_tag_ids() + { + var tagNames = new HashSet(); + + await sut.GetTagIdsAsync(appId, TagGroups.Assets, tagNames); + + A.CallTo(() => grain.GetTagIdsAsync(tagNames)) + .MustHaveHappened(); + } + + [Fact] + public async Task Should_call_grain_when_denormalizing_tags() + { + var tagIds = new HashSet(); + + await sut.DenormalizeTagsAsync(appId, TagGroups.Assets, tagIds); + + A.CallTo(() => grain.DenormalizeTagsAsync(tagIds)) + .MustHaveHappened(); + } + + [Fact] + public async Task Should_call_grain_when_normalizing_tags() + { + var tagIds = new HashSet(); + var tagNames = new HashSet(); + + await sut.NormalizeTagsAsync(appId, TagGroups.Assets, tagNames, tagIds); + + A.CallTo(() => grain.NormalizeTagsAsync(tagNames, tagIds)) + .MustHaveHappened(); + } + } +}