DocSpace-buildtools/common/ASC.Core.Common/Tests/TopSubscriptionProviderTest.cs

147 lines
6.8 KiB
C#
Raw Normal View History

2019-05-15 14:56:09 +00:00
/*
*
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
#if DEBUG
using System;
2019-08-15 12:04:42 +00:00
using System.Linq;
2019-05-15 14:56:09 +00:00
using ASC.Core.Notify;
using ASC.Notify.Model;
2019-08-15 12:04:42 +00:00
using ASC.Notify.Recipients;
using NUnit.Framework;
2019-09-09 12:56:33 +00:00
using Microsoft.Extensions.DependencyInjection;
2019-05-15 14:56:09 +00:00
namespace ASC.Core.Common.Tests
{
[TestFixture]
2019-05-15 14:56:09 +00:00
class TopSubscriptionProviderTest
{
private TopSubscriptionProvider subProvider;
private RecipientProviderImpl recProvider;
private Tenants.Tenant tenant;
private string sourceId;
private string actionId;
private string objectId;
private string rndObj;
private string rndObj2;
2019-08-15 13:16:39 +00:00
private IRecipient everyone = new RecipientsGroup(string.Empty, string.Empty);
private IRecipient otdel = new RecipientsGroup(string.Empty, string.Empty);
2019-05-15 14:56:09 +00:00
private IRecipient testRec;
private IRecipient testRec2;
private NotifyAction nAction;
2019-09-09 12:56:33 +00:00
private IServiceProvider serviceProvider;
2019-05-15 14:56:09 +00:00
[OneTimeSetUp]
2019-05-15 14:56:09 +00:00
public void CreateProviders()
2019-09-18 13:33:01 +00:00
{
using var scope = serviceProvider.CreateScope();
var tenantManager = scope.ServiceProvider.GetService<TenantManager>();
2019-09-19 13:43:28 +00:00
var subscriptionManager = scope.ServiceProvider.GetService<SubscriptionManager>();
2019-09-18 13:33:01 +00:00
tenantManager.SetCurrentTenant(tenant);
2019-05-15 14:56:09 +00:00
tenant = new Tenants.Tenant(0, "teamlab");
sourceId = "6045b68c-2c2e-42db-9e53-c272e814c4ad";
actionId = "NewCommentForTask";
objectId = "Task_5946_457";
nAction = new NotifyAction(actionId, actionId);
testRec = new DirectRecipient("ff0c4e13-1831-43c2-91ce-7b7beb56179b", null); //Oliver Khan
2019-09-09 12:56:33 +00:00
testRec2 = new DirectRecipient("0017794f-aeb7-49a5-8817-9e870e02bd3f", null); //Якутова Юлия
2019-05-15 14:56:09 +00:00
2019-09-18 13:33:01 +00:00
recProvider = scope.ServiceProvider.GetService<RecipientProviderImpl>();
2019-09-19 13:43:28 +00:00
var directSubProvider = new DirectSubscriptionProvider(sourceId, subscriptionManager, recProvider);
2019-05-15 14:56:09 +00:00
subProvider = new TopSubscriptionProvider(recProvider, directSubProvider);
}
[Test]
2019-05-15 14:56:09 +00:00
public void TopSubProviderTest()
{
try
{
//0017794f-aeb7-49a5-8817-9e870e02bd3f - Якутова Юлия
//ff0c4e13-1831-43c2-91ce-7b7beb56179b - Oliver Khan
//cc8eea30-1260-427e-83c4-ff9e9680edba - Отдел интернет-приложений!!!;)
IRecipient[] res;
//GetRecipients
res = subProvider.GetRecipients(nAction, objectId);
2019-05-15 14:56:09 +00:00
var cnt = res.Count();
//Subscribe
subProvider.Subscribe(nAction, objectId, testRec);
res = subProvider.GetRecipients(nAction, objectId);
2019-05-15 14:56:09 +00:00
Assert.AreEqual(cnt + 1, res.Count());
//UnSubscribe
subProvider.UnSubscribe(nAction, testRec);
res = subProvider.GetRecipients(nAction, objectId);
2019-05-15 14:56:09 +00:00
Assert.AreEqual(cnt, res.Count());
2019-08-15 13:16:39 +00:00
string[] objs;
2019-05-15 14:56:09 +00:00
//GetSubscribtions
//Получаем подписки юзера
//for (int i = 0; i < 6; i++) subProvider.Subscribe(nAction, new Random().Next().ToString(), testRec2);
objs = subProvider.GetSubscriptions(nAction, testRec2);
2019-05-15 14:56:09 +00:00
Assert.AreNotEqual(0, objs.Count());
CollectionAssert.AllItemsAreUnique(objs);
//Получаем список групп к которым он принадлежит
var parents = recProvider.GetGroups(testRec2);
2019-05-15 14:56:09 +00:00
Assert.AreNotEqual(0, parents.Count());
otdel = parents.First();
everyone = parents.Last();
var objsGroup = subProvider.GetSubscriptions(nAction, otdel);
2019-05-15 14:56:09 +00:00
CollectionAssert.AllItemsAreUnique(objsGroup);
//Подписываем весь отдел на объект
2019-08-15 13:16:39 +00:00
rndObj = string.Concat("TestObject#", new Random().Next().ToString());
2019-05-15 14:56:09 +00:00
subProvider.Subscribe(nAction, rndObj, otdel);
//Проверяем подписался ли юзер вместе со всем отделом двумя способами.
Assert.AreEqual(objsGroup.Count() + 1, subProvider.GetSubscriptions(nAction, otdel).Count());
Assert.AreEqual(objs.Count() + 1, subProvider.GetSubscriptions(nAction, testRec2).Count());
Assert.AreEqual(true, subProvider.IsSubscribed(nAction, testRec2, rndObj));
2019-05-15 14:56:09 +00:00
//Подписываем Everybody
2019-08-15 13:16:39 +00:00
rndObj2 = string.Concat("TestObject#", new Random().Next().ToString());
objs = subProvider.GetSubscriptions(nAction, testRec2);
2019-05-15 14:56:09 +00:00
subProvider.Subscribe(nAction, rndObj2, everyone);
//Проверяем подписался ли user двумя способами.
Assert.AreEqual(objs.Count() + 1, subProvider.GetSubscriptions(nAction, testRec2).Count());
Assert.AreEqual(true, subProvider.IsSubscribed(nAction, testRec2, rndObj2));
2019-05-15 14:56:09 +00:00
}
finally
{
subProvider.UnSubscribe(nAction, objectId, testRec);
subProvider.UnSubscribe(nAction, rndObj, otdel);
subProvider.UnSubscribe(nAction, rndObj2, everyone);
}
}
}
2019-08-15 12:04:42 +00:00
}
2019-05-15 14:56:09 +00:00
#endif