using Bit.Core.Entities; using Bit.Core.Enums; using Bit.Core.OrganizationFeatures.OrganizationCollections; using Bit.Core.Repositories; using Bit.Core.Services; using Bit.Core.Test.AutoFixture.OrganizationFixtures; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; using NSubstitute; using Xunit; namespace Bit.Core.Test.OrganizationFeatures.OrganizationConnections; [SutProviderCustomize] public class DeleteCollectionCommandTests { [Theory, BitAutoData] [OrganizationCustomize] public async Task DeleteAsync_DeletesCollection(Collection collection, SutProvider sutProvider) { // Act await sutProvider.Sut.DeleteAsync(collection); // Assert await sutProvider.GetDependency().Received().DeleteAsync(collection); await sutProvider.GetDependency().Received().LogCollectionEventAsync(collection, EventType.Collection_Deleted, Arg.Any()); } [Theory, BitAutoData] [OrganizationCustomize] public async Task DeleteManyAsync_DeletesManyCollections(Collection collection, Collection collection2, SutProvider sutProvider) { // Arrange var collectionIds = new[] { collection.Id, collection2.Id }; sutProvider.GetDependency() .GetManyByManyIdsAsync(collectionIds) .Returns(new List { collection, collection2 }); // Act await sutProvider.Sut.DeleteManyAsync(collectionIds); // Assert await sutProvider.GetDependency().Received() .DeleteManyAsync(Arg.Is>(ids => ids.SequenceEqual(collectionIds))); await sutProvider.GetDependency().Received().LogCollectionEventsAsync( Arg.Is>(a => a.All(c => collectionIds.Contains(c.Item1.Id) && c.Item2 == EventType.Collection_Deleted))); } }