using System.Collections.Generic; using System.Linq; using Centron.BusinessLogic; using Centron.BusinessLogic.Administration.Rights; using Centron.BusinessLogic.WebServices.Accounts; using Centron.Interfaces.Accounts; using Centron.Interfaces.BL; using Centron.Tests.EndToEnd.Infrastructure; using CentronSoftware.Centron.WebServices.Entities.Accounts; using Xunit; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.Tests.Account.AccountAddresses { public class AccountAddressTests : EndToEndTest { public AccountAddressTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { this.Verifier.Settings.IgnoreProperty(f => f.CreatedVersion); this.Verifier.Settings.IgnoreProperty(f => f.ChangedVersion); this.Verifier.Settings.IgnoreProperty(f => f.CreatedVersion); this.Verifier.Settings.IgnoreProperty(f => f.ChangedVersion); } public override void Execute() { TestLoadWithContacts(); GetSingleAccountAddressWithContacts(); GetDefaultAddressForAccount(); TestUserHasNoShowRightsForAccounts(); PrepareUserWithSpecialRights(); TestUserHasRightOnlyToSeeOwnAccountsSuccessful(); TestUserHasRightOnlyToSeeOwnAccountsFailed(); } private void TestUserHasRightOnlyToSeeOwnAccountsFailed() { using var session = new BLSession(); var result = session.GetBL().GetAccountAddresses(GetLoggedInUser(16), new GetAccountAddressesFilter() { IsDefault = true, AccountI3Ds = new List() { 5, 11 } }); Assert.True(result.Status == ResultStatus.Error, "Expected error, because user should have no show rights"); Assert.True(result.MessageCode == DefaultMessageCodes.RightCheckFailed, "Expected right check failed message code"); Assert.True(result.Data == null || !result.Data.Any(), "Expected empty result list"); } private void TestUserHasRightOnlyToSeeOwnAccountsSuccessful() { using var session = new BLSession(); var result = session.GetBL().GetAccountAddresses(GetLoggedInUser(16), new GetAccountAddressesFilter() { IsDefault = true, AccountI3Ds = new List() { 5 } }); Assert.True(result.Status == ResultStatus.Success, result.Message); Assert.True(result.Data.Count == 1, "Expected 1 address"); } private void PrepareUserWithSpecialRights() { using var session = new BLSession(); session.GetBL().AddRightToRightGroup( UserRightsConst.Sales.Customer.CustomerCommon.SHOW_ONLY_OWN_CUSTOMER, 40, GetLoggedInUser().User); } private void TestUserHasNoShowRightsForAccounts() { using var session = new BLSession(); var result = session.GetBL().GetAccountAddresses(GetLoggedInUser(18), new GetAccountAddressesFilter() { IsDefault = true, AccountI3Ds = new List() { 10, 16 } }); Assert.True(result.Status == ResultStatus.Error, "Expected error, because user should have no show rights"); Assert.True(result.MessageCode == DefaultMessageCodes.RightCheckFailed, "Expected right check failed message code"); Assert.True(result.Data == null || !result.Data.Any(), "Expected empty result list"); } private void GetDefaultAddressForAccount() { using var session = new BLSession(); var result = session.GetBL().GetAccountAddresses(GetLoggedInUser(), new GetAccountAddressesFilter() { IsDefault = true, AccountI3Ds = new List() { 10, 16 } }); Assert.True(result.Status == ResultStatus.Success, result.Message); Assert.True(result.Data.Count == 2, "Expected 2 addresses"); Assert.True(result.Data.All(f => f.IsDefault), "Expected only default addresses"); Assert.True(result.Data.All(f => f.Contacts == null || !f.Contacts.Any()), "Expected empty contact list"); } private void GetSingleAccountAddressWithContacts() { using var session = new BLSession(); var result = session.GetBL().GetAccountAddresses(GetLoggedInUser(), new GetAccountAddressesFilter() { AddressI3Ds = new List() { 25 }, IncludeContacts = true }); Assert.True(result.Status == ResultStatus.Success, result.Message); Assert.True(result.Data.Count == 1 && result.Data.All(f => f.I3D == 25), "Expected 1 item with I3D = 25"); Assert.True(result.Data.First().Contacts.Any(), "Expected a contact list for account address"); } public void TestLoadWithContacts() { var result = this.WithSession(s => s.GetBL().GetAccountAddresses(this.GetLoggedInUser(), new GetAccountAddressesFilter { AccountI3Ds = new List { 10, 16 }, IncludeClosedAddresses = true, IncludeContacts = true })).ThrowIfError(); this.Verifier.Verify("AddressesWithContacts", result); } } }