using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationConnections; using Bit.Core.Entities; using Bit.Core.Exceptions; using Bit.Core.Models.Data.Organizations.OrganizationConnections; using Bit.Core.Models.OrganizationConnectionConfigs; using Bit.Core.Repositories; using Bit.Test.Common.AutoFixture; using Bit.Test.Common.AutoFixture.Attributes; using Bit.Test.Common.Helpers; using NSubstitute; using Xunit; namespace Bit.Core.Test.AdminConsole.OrganizationFeatures.OrganizationConnections; [SutProviderCustomize] public class UpdateOrganizationConnectionCommandTests { [Theory] [BitAutoData] public async Task UpdateAsync_NoId_Fails(OrganizationConnectionData data, SutProvider sutProvider) { data.Id = null; var exception = await Assert.ThrowsAsync(() => sutProvider.Sut.UpdateAsync(data)); Assert.Contains("Cannot update connection, Connection does not exist.", exception.Message); await sutProvider.GetDependency().DidNotReceiveWithAnyArgs() .UpsertAsync(default); } [Theory] [BitAutoData] public async Task UpdateAsync_ConnectionDoesNotExist_ThrowsNotFound( OrganizationConnectionData data, SutProvider sutProvider) { var exception = await Assert.ThrowsAsync(() => sutProvider.Sut.UpdateAsync(data)); await sutProvider.GetDependency().DidNotReceiveWithAnyArgs() .UpsertAsync(default); } [Theory] [BitAutoData] public async Task UpdateAsync_CallsUpsert(OrganizationConnectionData data, OrganizationConnection existing, SutProvider sutProvider) { data.Id = existing.Id; sutProvider.GetDependency().GetByIdAsync(data.Id.Value).Returns(existing); await sutProvider.Sut.UpdateAsync(data); await sutProvider.GetDependency().Received(1) .UpsertAsync(Arg.Is(AssertHelper.AssertPropertyEqual(data.ToEntity()))); } }