using Bit.Api.Controllers; using Bit.Core.Entities; using Bit.Core.SecretManagerFeatures.Projects.Interfaces; using Bit.Core.Services; using Bit.Core.Test.AutoFixture.ProjectsFixture; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; using NSubstitute; using Xunit; namespace Bit.Api.Test.Controllers; [ControllerCustomize(typeof(ProjectsController))] [SutProviderCustomize] [ProjectCustomize] [JsonDocumentCustomize] public class ProjectsControllerTests { [Theory] [BitAutoData] public async void BulkDeleteProjects_Success(SutProvider sutProvider, List data) { sutProvider.GetDependency().GetProperUserId(default).ReturnsForAnyArgs(Guid.NewGuid()); var ids = data.Select(project => project.Id)?.ToList(); var mockResult = new List>(); foreach (var project in data) { mockResult.Add(new Tuple(project, "")); } sutProvider.GetDependency().DeleteProjects(ids, default).ReturnsForAnyArgs(mockResult); var results = await sutProvider.Sut.BulkDeleteProjectsAsync(ids); await sutProvider.GetDependency().Received(1) .DeleteProjects(Arg.Is(ids), Arg.Any()); Assert.Equal(data.Count, results.Data.Count()); } [Theory] [BitAutoData] public async void BulkDeleteProjects_NoGuids_ThrowsArgumentNullException(SutProvider sutProvider) { sutProvider.GetDependency().GetProperUserId(default).ReturnsForAnyArgs(Guid.NewGuid()); await Assert.ThrowsAsync(() => sutProvider.Sut.BulkDeleteProjectsAsync(new List())); } }